2023-03-16 13:57:04 +01:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
2023-03-27 17:41:58 +02:00
|
|
|
|
using System.Data;
|
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Net;
|
2023-03-16 13:57:04 +01:00
|
|
|
|
using System.Web.Mvc;
|
2023-03-27 17:41:58 +02:00
|
|
|
|
using BeWo.Service.Security;
|
2023-03-16 13:57:04 +01:00
|
|
|
|
using BeWoPlanerMobil.Models;
|
|
|
|
|
|
using BeWoPlanerMobil.Service;
|
|
|
|
|
|
using BeWoPlanerMobil.Util;
|
|
|
|
|
|
using BS.Shared;
|
2023-03-27 17:41:58 +02:00
|
|
|
|
using BS.Shared.Core;
|
|
|
|
|
|
using BS.Shared.DataContracts;
|
|
|
|
|
|
using DevExpress.CodeParser;
|
|
|
|
|
|
using DevExpress.XtraReports.UI;
|
2023-03-16 13:57:04 +01:00
|
|
|
|
|
|
|
|
|
|
namespace BeWoPlanerMobil.Controllers
|
|
|
|
|
|
{
|
|
|
|
|
|
public class ReportViewerController : AbstractBaseController
|
|
|
|
|
|
{
|
2023-03-27 17:41:58 +02:00
|
|
|
|
|
|
|
|
|
|
|
2023-03-16 13:57:04 +01:00
|
|
|
|
private ReportViewerModel _Model;
|
|
|
|
|
|
|
|
|
|
|
|
public ReportViewerModel Model
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
if(!MobileSessionFacade.IsUserLoggedIn())
|
|
|
|
|
|
{
|
|
|
|
|
|
RedirectToActionPermanent("Index", "Login");
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(((ReportViewerModel)Session[ModelSessionConstants.ReportViewerModelKey])?.Employee is null)
|
|
|
|
|
|
{
|
|
|
|
|
|
_Model = new ReportViewerModel { Employee = MobileSessionFacade.LoggedInEmployee };
|
|
|
|
|
|
Session[ModelSessionConstants.ReportViewerModelKey] = _Model;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
_Model = (ReportViewerModel)Session[ModelSessionConstants.ReportViewerModelKey];
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return _Model;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public ActionResult ReportViewer()
|
|
|
|
|
|
{
|
|
|
|
|
|
var month = DateTime.Today.Month;
|
|
|
|
|
|
var year = DateTime.Today.Year;
|
|
|
|
|
|
var first = new DateTime(year, month, 1).AddMonths(-1);
|
|
|
|
|
|
|
|
|
|
|
|
Model.SelectedYear = Model.SelectedYear ?? first.Year;
|
|
|
|
|
|
Model.SelectedMonth = Model.SelectedMonth ?? first.Month;
|
|
|
|
|
|
|
|
|
|
|
|
Model.AllEmployees = EmployeeService.GetActiveCompactEmployeesForEmployee(MobileSessionFacade.LoggedInCompactEmployee.EmployeeOid);
|
|
|
|
|
|
Model.AllTeams = EmployeeService.GetAllActiveCompactTeamsForEmployee(MobileSessionFacade.LoggedInEmployee.EmployeeOid);
|
|
|
|
|
|
|
|
|
|
|
|
Model.ReportTypes = new List<SelectListItem>
|
|
|
|
|
|
{
|
|
|
|
|
|
new SelectListItem
|
|
|
|
|
|
{
|
|
|
|
|
|
Text = "Berichte",
|
|
|
|
|
|
Value = "0"
|
|
|
|
|
|
},
|
|
|
|
|
|
new SelectListItem
|
|
|
|
|
|
{
|
|
|
|
|
|
Text = "Mitarbeiterstundenkonto",
|
|
|
|
|
|
Value = "1"
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
Model.SelectedReportType = ReportType.Berichte;
|
|
|
|
|
|
|
|
|
|
|
|
Model.Queries = QueryService.GetAllQueriesOfType(QueryType.Public);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return View(Model);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[Authorize]
|
2023-03-27 17:41:58 +02:00
|
|
|
|
public ActionResult DocumentWebViewerPartial()
|
2023-03-16 13:57:04 +01:00
|
|
|
|
{
|
|
|
|
|
|
return PartialView("DocumentWebViewerPartial", Model);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[Authorize]
|
|
|
|
|
|
public ActionResult ExportDocumentViewer()
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new NotImplementedException("Service dafür implementieren!");
|
|
|
|
|
|
}
|
2023-03-27 17:41:58 +02:00
|
|
|
|
|
|
|
|
|
|
[Authorize]
|
|
|
|
|
|
public ActionResult LoadCustomReport(long? reportOid)
|
|
|
|
|
|
{
|
|
|
|
|
|
if(Model?.Employee?.EmployeeOid is null || reportOid is null)
|
|
|
|
|
|
{
|
|
|
|
|
|
return Logout();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var selectedQuery = Model.Queries.FirstOrDefault(query => query.Oid.Equals(reportOid.Value));
|
|
|
|
|
|
|
|
|
|
|
|
if(selectedQuery is null)
|
|
|
|
|
|
{
|
|
|
|
|
|
Model.Report = null;
|
|
|
|
|
|
return PartialView("DocumentWebViewerPartial", Model);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var queryReportUri = GetQueryReportUrl(selectedQuery);
|
|
|
|
|
|
var baseUri = SecurityUtils.RemoveAuthenticationInfoFromUri(queryReportUri);
|
|
|
|
|
|
|
|
|
|
|
|
var test = QueryService.ExecuteQuery(selectedQuery.Oid, null);
|
|
|
|
|
|
|
|
|
|
|
|
if(test is null)
|
|
|
|
|
|
{
|
|
|
|
|
|
return PartialView("DocumentWebViewerPartial", Model);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QueryService.PrepareQueryReport(test, $"{MobileSessionFacade.Tenant}queryeoid{Model.Employee.EmployeeOid.Value}");
|
|
|
|
|
|
|
|
|
|
|
|
var tempToken = DownloadService.CreateTemporaryToken(baseUri, false);
|
|
|
|
|
|
|
|
|
|
|
|
var addChar = baseUri.Contains("?") ? "&" : "?";
|
|
|
|
|
|
var finalUri = $"{baseUri}{addChar}token={tempToken}";
|
|
|
|
|
|
|
|
|
|
|
|
var webClient = new WebClient();
|
|
|
|
|
|
|
|
|
|
|
|
var data = webClient.DownloadData(finalUri);
|
|
|
|
|
|
|
|
|
|
|
|
var report = new XtraReport();
|
|
|
|
|
|
|
|
|
|
|
|
using(var memoryStream = new MemoryStream(data))
|
|
|
|
|
|
{
|
|
|
|
|
|
report.PrintingSystem.LoadDocument(memoryStream);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Model.Report = report;
|
|
|
|
|
|
|
|
|
|
|
|
return PartialView("DocumentWebViewerPartial", Model);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[Authorize]
|
|
|
|
|
|
private string GetQueryReportUrl(QueryDC query)
|
|
|
|
|
|
{
|
|
|
|
|
|
var url = Request?.Url;
|
|
|
|
|
|
|
|
|
|
|
|
if(Model?.Employee?.EmployeeOid is null || url is null || query is null)
|
|
|
|
|
|
{
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//DEBUG: http://localhost:3777/service
|
|
|
|
|
|
//RELEASE: https://app4.bewoplaner.de/service
|
|
|
|
|
|
// http://localhost:3777/Host/ReportView.aspx?dcid=demoqueryeoid372&qoid=1304&type=QueryReport
|
|
|
|
|
|
|
|
|
|
|
|
var urlSuffix = $"/ReportView.aspx?dcid={MobileSessionFacade.Tenant}queryeoid{Model.Employee.EmployeeOid.Value}&qoid={query.Oid}&type={Utils.EnumName(ReportTypes.QueryReport)}";
|
|
|
|
|
|
|
|
|
|
|
|
#if DEBUG
|
|
|
|
|
|
return $"http://localhost:3777/Host{urlSuffix}";
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
return $"{url.Scheme}//{url.Host}{urlSuffix}";
|
|
|
|
|
|
}
|
2023-03-16 13:57:04 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|