Template Report içerisinde Dinamik veri kullanma
This commit is contained in:
parent
a9f43ca320
commit
9b1ce9f512
3 changed files with 103 additions and 7 deletions
|
|
@ -1,4 +1,6 @@
|
||||||
namespace Erp.Reports.PredefinedReports
|
using DevExpress.XtraReports.UI;
|
||||||
|
|
||||||
|
namespace Erp.Reports.PredefinedReports
|
||||||
{
|
{
|
||||||
partial class TemplateReport
|
partial class TemplateReport
|
||||||
{
|
{
|
||||||
|
|
@ -95,8 +97,8 @@
|
||||||
this.xrRichText1.LocationFloat = new DevExpress.Utils.PointFloat(0F, 0F);
|
this.xrRichText1.LocationFloat = new DevExpress.Utils.PointFloat(0F, 0F);
|
||||||
this.xrRichText1.Name = "xrRichText1";
|
this.xrRichText1.Name = "xrRichText1";
|
||||||
this.xrRichText1.SizeF = new System.Drawing.SizeF(650F, 200F);
|
this.xrRichText1.SizeF = new System.Drawing.SizeF(650F, 200F);
|
||||||
this.xrRichText1.DataBindings.AddRange(new DevExpress.XtraReports.UI.XRBinding[] {
|
xrRichText1.ExpressionBindings.Clear();
|
||||||
new DevExpress.XtraReports.UI.XRBinding("Html", null, "Sas_T_ReportTemplate.HtmlContent")});
|
xrRichText1.ExpressionBindings.Add(new ExpressionBinding("BeforePrint", "Html", "[HtmlContent]"));
|
||||||
//
|
//
|
||||||
// sqlDataSource1
|
// sqlDataSource1
|
||||||
//
|
//
|
||||||
|
|
|
||||||
|
|
@ -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<string, string> _parameters;
|
||||||
|
private static IServiceProvider _serviceProvider;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Uygulama başlangıcında bir kez set edilmeli (Program.cs'de)
|
||||||
|
/// </summary>
|
||||||
|
public static void SetServiceProvider(IServiceProvider serviceProvider)
|
||||||
|
{
|
||||||
|
_serviceProvider = serviceProvider;
|
||||||
|
}
|
||||||
|
|
||||||
public TemplateReport()
|
public TemplateReport()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
|
||||||
|
// A4 kağıt ayarları
|
||||||
|
this.PageHeight = 1169;
|
||||||
|
this.PageWidth = 827;
|
||||||
|
this.Landscape = false;
|
||||||
|
|
||||||
|
_parameters = new Dictionary<string, string>();
|
||||||
|
|
||||||
|
// 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<PlatformDbContext>();
|
||||||
|
|
||||||
|
var language = dbContext.Set<Language>()
|
||||||
|
.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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System;
|
using System;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
|
||||||
namespace Erp.Platform.ReportServices;
|
namespace Erp.Platform.ReportServices;
|
||||||
|
|
||||||
|
|
@ -12,16 +13,28 @@ public class CustomReportStorageWebExtension : DevExpress.XtraReports.Web.Extens
|
||||||
{
|
{
|
||||||
readonly string reportDirectory = "PredefinedReports\\Reports";
|
readonly string reportDirectory = "PredefinedReports\\Reports";
|
||||||
const string FileExtension = ".repx";
|
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))
|
if (!Directory.Exists(reportDirectory))
|
||||||
{
|
{
|
||||||
Directory.CreateDirectory(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))
|
if (!Directory.Exists(reportDirectory))
|
||||||
{
|
{
|
||||||
Directory.CreateDirectory(reportDirectory);
|
Directory.CreateDirectory(reportDirectory);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue