diff --git a/api/src/Erp.Platform.HttpApi.Host/PredefinedReports/TemplateReport.Designer.cs b/api/src/Erp.Platform.HttpApi.Host/PredefinedReports/TemplateReport.Designer.cs index 50452f6b..dd8966b9 100644 --- a/api/src/Erp.Platform.HttpApi.Host/PredefinedReports/TemplateReport.Designer.cs +++ b/api/src/Erp.Platform.HttpApi.Host/PredefinedReports/TemplateReport.Designer.cs @@ -1,4 +1,6 @@ -namespace Erp.Reports.PredefinedReports +using DevExpress.XtraReports.UI; + +namespace Erp.Reports.PredefinedReports { partial class TemplateReport { @@ -95,8 +97,8 @@ this.xrRichText1.LocationFloat = new DevExpress.Utils.PointFloat(0F, 0F); this.xrRichText1.Name = "xrRichText1"; this.xrRichText1.SizeF = new System.Drawing.SizeF(650F, 200F); - this.xrRichText1.DataBindings.AddRange(new DevExpress.XtraReports.UI.XRBinding[] { - new DevExpress.XtraReports.UI.XRBinding("Html", null, "Sas_T_ReportTemplate.HtmlContent")}); + xrRichText1.ExpressionBindings.Clear(); + xrRichText1.ExpressionBindings.Add(new ExpressionBinding("BeforePrint", "Html", "[HtmlContent]")); // // sqlDataSource1 // diff --git a/api/src/Erp.Platform.HttpApi.Host/PredefinedReports/TemplateReport.cs b/api/src/Erp.Platform.HttpApi.Host/PredefinedReports/TemplateReport.cs index 475339c5..85334df0 100644 --- a/api/src/Erp.Platform.HttpApi.Host/PredefinedReports/TemplateReport.cs +++ b/api/src/Erp.Platform.HttpApi.Host/PredefinedReports/TemplateReport.cs @@ -1,9 +1,90 @@ -namespace Erp.Reports.PredefinedReports; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using DevExpress.XtraReports.UI; +using Erp.Languages.Entities; +using Erp.Platform.EntityFrameworkCore; +using Microsoft.Extensions.DependencyInjection; -public partial class TemplateReport : DevExpress.XtraReports.UI.XtraReport +namespace Erp.Reports.PredefinedReports; + +public partial class TemplateReport : XtraReport { + private Dictionary _parameters; + private static IServiceProvider _serviceProvider; + + /// + /// Uygulama başlangıcında bir kez set edilmeli (Program.cs'de) + /// + public static void SetServiceProvider(IServiceProvider serviceProvider) + { + _serviceProvider = serviceProvider; + } + public TemplateReport() { InitializeComponent(); + + // A4 kağıt ayarları + this.PageHeight = 1169; + this.PageWidth = 827; + this.Landscape = false; + + _parameters = new Dictionary(); + + // Language verilerini yükle + LoadLanguageParameters(); + + xrRichText1.BeforePrint += XrRichText1_BeforePrint; + } + + private void LoadLanguageParameters() + { + try + { + if (_serviceProvider == null) + return; + + using var scope = _serviceProvider.CreateScope(); + var dbContext = scope.ServiceProvider.GetRequiredService(); + + var language = dbContext.Set() + .FirstOrDefault(l => l.DisplayName == "Türkçe"); + + if (language != null) + { + SetParameter("id", language.Id.ToString()); + SetParameter("name", language.DisplayName); + } + + SetParameter("date", DateTime.Now.ToString("dd.MM.yyyy")); + } + catch + { + SetParameter("date", DateTime.Now.ToString("dd.MM.yyyy")); + } + } + + private void XrRichText1_BeforePrint(object sender, CancelEventArgs e) + { + var rt = (XRRichText)sender; + + var rawObj = GetCurrentColumnValue("HtmlContent"); + var html = rawObj?.ToString(); + + if (string.IsNullOrWhiteSpace(html)) + return; + + foreach (var p in _parameters) + html = html.Replace($"@@{p.Key}", p.Value); + + rt.Html = html; + } + + public void SetParameter(string key, string value) + { + _parameters ??= []; + _parameters[key] = value; } } diff --git a/api/src/Erp.Platform.HttpApi.Host/ReportServices/CustomReportStorageWebExtension.cs b/api/src/Erp.Platform.HttpApi.Host/ReportServices/CustomReportStorageWebExtension.cs index 50ed4c00..880e2779 100644 --- a/api/src/Erp.Platform.HttpApi.Host/ReportServices/CustomReportStorageWebExtension.cs +++ b/api/src/Erp.Platform.HttpApi.Host/ReportServices/CustomReportStorageWebExtension.cs @@ -3,6 +3,7 @@ using System.IO; using System.Linq; using System; using System.Reflection; +using Microsoft.Extensions.DependencyInjection; namespace Erp.Platform.ReportServices; @@ -12,16 +13,28 @@ public class CustomReportStorageWebExtension : DevExpress.XtraReports.Web.Extens { readonly string reportDirectory = "PredefinedReports\\Reports"; const string FileExtension = ".repx"; + private readonly IServiceProvider _serviceProvider; - public CustomReportStorageWebExtension() + public CustomReportStorageWebExtension(IServiceProvider serviceProvider) { + _serviceProvider = serviceProvider; + + // TemplateReport için ServiceProvider'ı set et + Erp.Reports.PredefinedReports.TemplateReport.SetServiceProvider(serviceProvider); + if (!Directory.Exists(reportDirectory)) { Directory.CreateDirectory(reportDirectory); } } - public CustomReportStorageWebExtension(string reportDirectory) + + public CustomReportStorageWebExtension(IServiceProvider serviceProvider, string reportDirectory) { + _serviceProvider = serviceProvider; + + // TemplateReport için ServiceProvider'ı set et + Erp.Reports.PredefinedReports.TemplateReport.SetServiceProvider(serviceProvider); + if (!Directory.Exists(reportDirectory)) { Directory.CreateDirectory(reportDirectory);