Parcourir la source

ContractAll : start/end

zinab_elgendy il y a 2 mois
Parent
commit
57e397848b

+ 25 - 0
MTWorkHR.API/Program.cs

@@ -25,6 +25,8 @@ using MTWorkHR.Infrastructure.Reports;
 using MTWorkHR.API.Chat;
 using Microsoft.AspNetCore.SignalR;
 using MTWorkHR.Application.Services.Payment;
+using Microsoft.AspNetCore.Diagnostics;
+using DevExpress.DataAccess.Native.Web;
 
 var builder = WebApplication.CreateBuilder(args);
 
@@ -95,6 +97,10 @@ builder.Services.AddSingleton<MatchMoveService>();
 //Reporting
 
 
+
+
+
+
 builder.Services.AddScoped<ReportStorageWebExtension, CustomReportStorageWebExtension>();
 
 builder.Services.ConfigureReportingServices(configurator => {
@@ -173,6 +179,25 @@ var app = builder.Build();
 // if (app.Environment.IsDevelopment())
 // {
 app.UseDevExpressControls(); // Required for DevExpress Reporting
+
+
+app.UseExceptionHandler(errorApp =>
+{
+    errorApp.Run(async context =>
+    {
+        var exceptionHandlerPathFeature = context.Features.Get<IExceptionHandlerPathFeature>();
+        if (exceptionHandlerPathFeature?.Error is FaultException faultException)
+        {
+            var logger = context.RequestServices.GetRequiredService<ILogger<Program>>();
+            logger.LogError("DevExpress Report Error: {Message}", faultException.Message);
+        }
+
+        context.Response.StatusCode = 500;
+        await context.Response.WriteAsync("An error occurred while generating the report.");
+    });
+});
+
+
 app.UseSwagger();
 //app.UseSwaggerUI();
 app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "MTWorkHR.API v1"));

+ 1 - 1
MTWorkHR.API/Reports/ContractReport.Designer.cs

@@ -1053,7 +1053,7 @@
             // 
             // sqlDataSource1
             // 
-            this.sqlDataSource1.ConnectionName = "LocalConnectionString";
+            this.sqlDataSource1.ConnectionName = "MTWorkHRConnectionString";
             this.sqlDataSource1.Name = "sqlDataSource1";
             columnExpression1.ColumnName = "CompanyName";
             table1.MetaSerializable = "<Meta X=\"185\" Y=\"30\" Width=\"125\" Height=\"385\" />";

+ 21 - 33
MTWorkHR.API/Reports/ReportStorageWebExtension.cs

@@ -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();

+ 2 - 0
MTWorkHR.Application/Dtos/Contract/ContractAllHRDto.cs

@@ -18,6 +18,8 @@ namespace MTWorkHR.Application.Models
         public ContractTypeEnum ContractTypeId { get; set; }
         public ContractStatusEnum ContractStatusId { get; set; }
         public TypeOfWork? TypeOfWork { get; set; } //: :   اختيار: عقد بدوام كامل -  عقد دوام جزئي   
+        public DateTime? StartDate { get; set; }
+        public DateTime? EndDate { get; set; }
 
         public long CompanyId { get; set; }