|
@@ -21,59 +21,47 @@ namespace MTWorkHR.Infrastructure.Reports
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
- // Parse the string with the report name and parameter values.
|
|
|
string[] parts = url.Split('?');
|
|
|
string reportName = parts[0];
|
|
|
- string parametersQueryString = parts.Length > 1 ? parts[1] : String.Empty;
|
|
|
+ string parametersQueryString = parts.Length > 1 ? parts[1] : string.Empty;
|
|
|
|
|
|
- // Create a report instance.
|
|
|
-
|
|
|
- XtraReport report= getReport(reportName);
|
|
|
-
|
|
|
- if (report != null)
|
|
|
+ XtraReport report = getReport(reportName);
|
|
|
+ if (report == null)
|
|
|
{
|
|
|
- // Apply the parameter values to the report.
|
|
|
- var parameters = HttpUtility.ParseQueryString(parametersQueryString);
|
|
|
-
|
|
|
- foreach (string parameterName in parameters.AllKeys)
|
|
|
- {
|
|
|
- if (parameters.Get(parameterName) != "null"&& parameters.Get(parameterName) != null)
|
|
|
- {
|
|
|
- report.Parameters[parameterName].Value = Convert.ChangeType(
|
|
|
- parameters.Get(parameterName), report.Parameters[parameterName].Type);
|
|
|
- }
|
|
|
- }
|
|
|
+ throw new DevExpress.XtraReports.Web.ClientControls.FaultException($"Could not find report '{url}'.");
|
|
|
+ }
|
|
|
|
|
|
- // Disable the Visible property for all report parameters
|
|
|
- // to hide the Parameters Panel in the viewer.
|
|
|
- foreach (var parameter in report.Parameters)
|
|
|
+ // Apply report parameters
|
|
|
+ var parameters = HttpUtility.ParseQueryString(parametersQueryString);
|
|
|
+ foreach (string parameterName in parameters.AllKeys)
|
|
|
+ {
|
|
|
+ if (!string.IsNullOrEmpty(parameters.Get(parameterName)) && parameters.Get(parameterName) != "null")
|
|
|
{
|
|
|
- parameter.Visible = false;
|
|
|
+ report.Parameters[parameterName].Value = Convert.ChangeType(parameters.Get(parameterName), report.Parameters[parameterName].Type);
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- // If you do not hide the panel, disable the report's RequestParameters property.
|
|
|
- // report.RequestParameters = false;
|
|
|
+ report.CreateDocument(); // Ensure the report document is created
|
|
|
|
|
|
- using (MemoryStream ms = new MemoryStream())
|
|
|
- {
|
|
|
- report.SaveLayoutToXml(ms);
|
|
|
- return ms.ToArray();
|
|
|
- }
|
|
|
+ using (MemoryStream ms = new MemoryStream())
|
|
|
+ {
|
|
|
+ report.ExportToPdf(ms); // Export to PDF
|
|
|
+ return ms.ToArray();
|
|
|
}
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
- throw new DevExpress.XtraReports.Web.ClientControls.FaultException(
|
|
|
- "Could not get report data.", ex);
|
|
|
+ throw new DevExpress.XtraReports.Web.ClientControls.FaultException($"Error generating report '{url}': {ex.Message}", ex);
|
|
|
}
|
|
|
- throw new DevExpress.XtraReports.Web.ClientControls.FaultException(
|
|
|
- string.Format("Could not find report '{0}'.", url));
|
|
|
}
|
|
|
+
|
|
|
private XtraReport getReport(string reportName)
|
|
|
{
|
|
|
switch (reportName)
|
|
|
{
|
|
|
case "ContractReport":
|
|
|
+ case "contractreport":
|
|
|
+ case "contractReport":
|
|
|
return new ContractReport();
|
|
|
case "ContractAllowance":
|
|
|
return new ContractAllowances();
|