XtraReport filtreli şekilde aç
This commit is contained in:
parent
7738a34a55
commit
30e099d3ef
9 changed files with 129 additions and 94 deletions
|
|
@ -5999,7 +5999,7 @@ public class ListFormSeeder_Administration : IDataSeedContributor, ITransientDep
|
||||||
Text ="View",
|
Text ="View",
|
||||||
UrlTarget="_blank",
|
UrlTarget="_blank",
|
||||||
AuthName = listFormName,
|
AuthName = listFormName,
|
||||||
Url=$"/admin/reports/@Id/view",
|
Url=$"/admin/reports/TemplateReport/view?name=@Id",
|
||||||
IsVisible = true,
|
IsVisible = true,
|
||||||
},
|
},
|
||||||
new() {
|
new() {
|
||||||
|
|
@ -6007,7 +6007,7 @@ public class ListFormSeeder_Administration : IDataSeedContributor, ITransientDep
|
||||||
Text ="Design",
|
Text ="Design",
|
||||||
UrlTarget="_blank",
|
UrlTarget="_blank",
|
||||||
AuthName = listFormName + ".Update",
|
AuthName = listFormName + ".Update",
|
||||||
Url=$"/admin/reports/@Id/design",
|
Url=$"/admin/reports/TemplateReport/design?name=@Id",
|
||||||
IsVisible = true,
|
IsVisible = true,
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
|
|
||||||
|
|
@ -1,13 +0,0 @@
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using DevExpress.XtraReports.UI;
|
|
||||||
|
|
||||||
namespace Erp.Reports.PredefinedReports;
|
|
||||||
|
|
||||||
public static class ReportsFactory
|
|
||||||
{
|
|
||||||
public static Dictionary<string, Func<XtraReport>> Reports = new Dictionary<string, Func<XtraReport>>()
|
|
||||||
{
|
|
||||||
["TestReport"] = () => new TestReport()
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
namespace Erp.Reports.PredefinedReports
|
namespace Erp.Reports.PredefinedReports
|
||||||
{
|
{
|
||||||
partial class TestReport
|
partial class TemplateReport
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Required designer variable.
|
/// Required designer variable.
|
||||||
|
|
@ -32,7 +32,7 @@
|
||||||
DevExpress.DataAccess.Sql.Table table1 = new DevExpress.DataAccess.Sql.Table();
|
DevExpress.DataAccess.Sql.Table table1 = new DevExpress.DataAccess.Sql.Table();
|
||||||
DevExpress.DataAccess.Sql.Column column2 = new DevExpress.DataAccess.Sql.Column();
|
DevExpress.DataAccess.Sql.Column column2 = new DevExpress.DataAccess.Sql.Column();
|
||||||
DevExpress.DataAccess.Sql.ColumnExpression columnExpression2 = new DevExpress.DataAccess.Sql.ColumnExpression();
|
DevExpress.DataAccess.Sql.ColumnExpression columnExpression2 = new DevExpress.DataAccess.Sql.ColumnExpression();
|
||||||
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(TestReport));
|
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(TemplateReport));
|
||||||
this.TopMargin = new DevExpress.XtraReports.UI.TopMarginBand();
|
this.TopMargin = new DevExpress.XtraReports.UI.TopMarginBand();
|
||||||
this.BottomMargin = new DevExpress.XtraReports.UI.BottomMarginBand();
|
this.BottomMargin = new DevExpress.XtraReports.UI.BottomMarginBand();
|
||||||
this.pageInfo1 = new DevExpress.XtraReports.UI.XRPageInfo();
|
this.pageInfo1 = new DevExpress.XtraReports.UI.XRPageInfo();
|
||||||
|
|
@ -0,0 +1,9 @@
|
||||||
|
namespace Erp.Reports.PredefinedReports;
|
||||||
|
|
||||||
|
public partial class TemplateReport : DevExpress.XtraReports.UI.XtraReport
|
||||||
|
{
|
||||||
|
public TemplateReport()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,9 +0,0 @@
|
||||||
namespace Erp.Reports.PredefinedReports;
|
|
||||||
|
|
||||||
public partial class TestReport : DevExpress.XtraReports.UI.XtraReport
|
|
||||||
{
|
|
||||||
public TestReport()
|
|
||||||
{
|
|
||||||
InitializeComponent();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System;
|
using System;
|
||||||
using Erp.Reports.PredefinedReports;
|
using System.Reflection;
|
||||||
|
|
||||||
namespace Erp.Platform.ReportServices;
|
namespace Erp.Platform.ReportServices;
|
||||||
|
|
||||||
|
|
@ -52,7 +52,9 @@ public class CustomReportStorageWebExtension : DevExpress.XtraReports.Web.Extens
|
||||||
// Implement your own logic to prohibit URLs that contain spaces or other specific characters.
|
// Implement your own logic to prohibit URLs that contain spaces or other specific characters.
|
||||||
// Return **true** if no validation is required.
|
// Return **true** if no validation is required.
|
||||||
|
|
||||||
return Path.GetFileName(url) == url;
|
// Query string varsa sadece rapor adını kontrol et
|
||||||
|
string reportName = url.Contains("?") ? url.Split('?')[0] : url;
|
||||||
|
return Path.GetFileName(reportName) == reportName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override byte[] GetData(string url)
|
public override byte[] GetData(string url)
|
||||||
|
|
@ -63,18 +65,97 @@ public class CustomReportStorageWebExtension : DevExpress.XtraReports.Web.Extens
|
||||||
// if the parameters are included in the report URL's query string.
|
// if the parameters are included in the report URL's query string.
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (Directory.EnumerateFiles(reportDirectory).Select(Path.GetFileNameWithoutExtension).Contains(url))
|
// URL'den rapor adını ve parametreleri ayır
|
||||||
|
string reportName = url;
|
||||||
|
Dictionary<string, string> parameters = new Dictionary<string, string>();
|
||||||
|
|
||||||
|
if (url.Contains("?"))
|
||||||
{
|
{
|
||||||
return File.ReadAllBytes(Path.Combine(reportDirectory, url + FileExtension));
|
var parts = url.Split('?');
|
||||||
}
|
reportName = parts[0];
|
||||||
if (ReportsFactory.Reports.ContainsKey(url))
|
|
||||||
{
|
// Query string parametrelerini parse et
|
||||||
using (MemoryStream ms = new MemoryStream())
|
var queryString = parts[1];
|
||||||
|
var paramPairs = queryString.Split('&');
|
||||||
|
foreach (var pair in paramPairs)
|
||||||
{
|
{
|
||||||
ReportsFactory.Reports[url]().SaveLayoutToXml(ms);
|
var keyValue = pair.Split('=');
|
||||||
return ms.ToArray();
|
if (keyValue.Length == 2)
|
||||||
|
{
|
||||||
|
parameters[keyValue[0]] = Uri.UnescapeDataString(keyValue[1]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Önce Reports klasöründen yüklemeyi dene
|
||||||
|
if (Directory.EnumerateFiles(reportDirectory).Select(Path.GetFileNameWithoutExtension).Contains(reportName))
|
||||||
|
{
|
||||||
|
var report = XtraReport.FromFile(Path.Combine(reportDirectory, reportName + FileExtension));
|
||||||
|
|
||||||
|
// SQL DataSource'daki filtreyi güncelle
|
||||||
|
if (parameters.Count > 0)
|
||||||
|
{
|
||||||
|
var sqlDataSource = report.ComponentStorage.OfType<DevExpress.DataAccess.Sql.SqlDataSource>().FirstOrDefault();
|
||||||
|
if (sqlDataSource != null && sqlDataSource.Queries.Count > 0)
|
||||||
|
{
|
||||||
|
var query = sqlDataSource.Queries[0] as DevExpress.DataAccess.Sql.SelectQuery;
|
||||||
|
if (query != null)
|
||||||
|
{
|
||||||
|
// FilterString'i oluştur - sadece kolon adını kullan
|
||||||
|
var filters = new List<string>();
|
||||||
|
foreach (var param in parameters)
|
||||||
|
{
|
||||||
|
// Capitalize first letter for column name matching (Name, Id, etc.)
|
||||||
|
var columnName = char.ToUpper(param.Key[0]) + param.Key.Substring(1);
|
||||||
|
filters.Add($"[{columnName}] = '{param.Value.Replace("'", "''")}'");
|
||||||
|
}
|
||||||
|
query.FilterString = string.Join(" AND ", filters);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
using MemoryStream ms = new MemoryStream();
|
||||||
|
report.SaveLayoutToXml(ms);
|
||||||
|
return ms.ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reports klasöründe yoksa PredefinedReports namespace'inden yükle
|
||||||
|
var reportType = Assembly.GetExecutingAssembly()
|
||||||
|
.GetTypes()
|
||||||
|
.FirstOrDefault(t => t.Namespace == "Erp.Reports.PredefinedReports" &&
|
||||||
|
t.Name == reportName &&
|
||||||
|
typeof(XtraReport).IsAssignableFrom(t));
|
||||||
|
|
||||||
|
if (reportType != null)
|
||||||
|
{
|
||||||
|
var report = (XtraReport)Activator.CreateInstance(reportType);
|
||||||
|
|
||||||
|
// SQL DataSource'daki filtreyi güncelle
|
||||||
|
if (parameters.Count > 0)
|
||||||
|
{
|
||||||
|
var sqlDataSource = report.ComponentStorage.OfType<DevExpress.DataAccess.Sql.SqlDataSource>().FirstOrDefault();
|
||||||
|
if (sqlDataSource != null && sqlDataSource.Queries.Count > 0)
|
||||||
|
{
|
||||||
|
var query = sqlDataSource.Queries[0] as DevExpress.DataAccess.Sql.SelectQuery;
|
||||||
|
if (query != null)
|
||||||
|
{
|
||||||
|
// FilterString'i oluştur - sadece kolon adını kullan
|
||||||
|
var filters = new List<string>();
|
||||||
|
foreach (var param in parameters)
|
||||||
|
{
|
||||||
|
// Capitalize first letter for column name matching (Name, Id, etc.)
|
||||||
|
var columnName = char.ToUpper(param.Key[0]) + param.Key.Substring(1);
|
||||||
|
filters.Add($"[{columnName}] = '{param.Value.Replace("'", "''")}'");
|
||||||
|
}
|
||||||
|
query.FilterString = string.Join(" AND ", filters);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
using MemoryStream ms = new MemoryStream();
|
||||||
|
report.SaveLayoutToXml(ms);
|
||||||
|
return ms.ToArray();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
|
|
@ -88,10 +169,18 @@ public class CustomReportStorageWebExtension : DevExpress.XtraReports.Web.Extens
|
||||||
// Returns a dictionary that contains the report names (URLs) and display names.
|
// Returns a dictionary that contains the report names (URLs) and display names.
|
||||||
// The Report Designer uses this method to populate the Open Report and Save Report dialogs.
|
// The Report Designer uses this method to populate the Open Report and Save Report dialogs.
|
||||||
|
|
||||||
return Directory.GetFiles(reportDirectory, "*" + FileExtension)
|
var reportsFromFiles = Directory.GetFiles(reportDirectory, "*" + FileExtension)
|
||||||
.Select(Path.GetFileNameWithoutExtension)
|
.Select(Path.GetFileNameWithoutExtension);
|
||||||
.Union(ReportsFactory.Reports.Select(x => x.Key))
|
|
||||||
.ToDictionary<string, string>(x => x);
|
var reportsFromCode = Assembly.GetExecutingAssembly()
|
||||||
|
.GetTypes()
|
||||||
|
.Where(t => t.Namespace == "Erp.Reports.PredefinedReports" &&
|
||||||
|
typeof(XtraReport).IsAssignableFrom(t) &&
|
||||||
|
!t.IsAbstract)
|
||||||
|
.Select(t => t.Name);
|
||||||
|
|
||||||
|
return reportsFromFiles.Union(reportsFromCode)
|
||||||
|
.ToDictionary<string, string>(x => x);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void SetData(XtraReport report, string url)
|
public override void SetData(XtraReport report, string url)
|
||||||
|
|
|
||||||
|
|
@ -1,50 +0,0 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<XtraReportsLayoutSerializer SerializerVersion="25.1.7.0" Ref="1" ControlType="Erp.Reports.PredefinedReports.TestReport, Erp.Platform.HttpApi.Host, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" Name="Report" PageWidthF="850" PageHeightF="1100" Version="25.1" DataMember="Sas_T_Sector" DataSource="#Ref-0" Font="Arial, 9.75pt">
|
|
||||||
<Bands>
|
|
||||||
<Item1 Ref="2" ControlType="TopMarginBand" Name="TopMargin" />
|
|
||||||
<Item2 Ref="3" ControlType="ReportHeaderBand" Name="ReportHeader" HeightF="60">
|
|
||||||
<Controls>
|
|
||||||
<Item1 Ref="4" ControlType="XRLabel" Name="label1" Text="Sector Report" SizeF="650,24.19433" LocationFloat="0,0" StyleName="Title" />
|
|
||||||
</Controls>
|
|
||||||
</Item2>
|
|
||||||
<Item3 Ref="5" ControlType="DetailBand" Name="Detail" HeightF="25">
|
|
||||||
<Controls>
|
|
||||||
<Item1 Ref="6" ControlType="XRTable" Name="table2" SizeF="650,25" LocationFloat="0,0" OddStyleName="DetailData3_Odd">
|
|
||||||
<Rows>
|
|
||||||
<Item1 Ref="7" ControlType="XRTableRow" Name="tableRow1" Weight="1">
|
|
||||||
<Cells>
|
|
||||||
<Item1 Ref="8" ControlType="XRTableCell" Name="tableCell1" Weight="0.3" Text="Id" StyleName="DetailData1" Borders="None">
|
|
||||||
<ExpressionBindings>
|
|
||||||
<Item1 Ref="9" EventName="BeforePrint" PropertyName="Text" Expression="[Id]" />
|
|
||||||
</ExpressionBindings>
|
|
||||||
<StylePriority Ref="10" UseBorders="false" />
|
|
||||||
</Item1>
|
|
||||||
<Item2 Ref="11" ControlType="XRTableCell" Name="tableCell2" Weight="0.7" Text="Name" StyleName="DetailData1">
|
|
||||||
<ExpressionBindings>
|
|
||||||
<Item1 Ref="12" EventName="BeforePrint" PropertyName="Text" Expression="[Name]" />
|
|
||||||
</ExpressionBindings>
|
|
||||||
</Item2>
|
|
||||||
</Cells>
|
|
||||||
</Item1>
|
|
||||||
</Rows>
|
|
||||||
</Item1>
|
|
||||||
</Controls>
|
|
||||||
</Item3>
|
|
||||||
<Item4 Ref="13" ControlType="BottomMarginBand" Name="BottomMargin">
|
|
||||||
<Controls>
|
|
||||||
<Item1 Ref="14" ControlType="XRPageInfo" Name="pageInfo1" PageInfo="DateTime" SizeF="325,23" LocationFloat="0,0" StyleName="PageInfo" />
|
|
||||||
<Item2 Ref="15" ControlType="XRPageInfo" Name="pageInfo2" TextFormatString="Page {0} of {1}" TextAlignment="TopRight" SizeF="325,23" LocationFloat="325,0" StyleName="PageInfo" />
|
|
||||||
</Controls>
|
|
||||||
</Item4>
|
|
||||||
</Bands>
|
|
||||||
<StyleSheet>
|
|
||||||
<Item1 Ref="16" Name="Title" BorderStyle="Inset" Padding="6,6,0,0,100" Font="Arial, 14.25pt" ForeColor="255,64,70,80" BackColor="Transparent" BorderColor="Black" Sides="None" StringFormat="Near;Near;0;None;Character;Default" BorderWidthSerializable="1" />
|
|
||||||
<Item2 Ref="17" Name="DetailCaption1" BorderStyle="Inset" Padding="6,6,0,0,100" Font="Arial, 8.25pt, style=Bold" ForeColor="255,64,70,80" BackColor="255,181,211,142" BorderColor="White" Sides="Left" StringFormat="Near;Center;0;None;Character;Default" TextAlignment="MiddleLeft" BorderWidthSerializable="2" />
|
|
||||||
<Item3 Ref="18" Name="DetailData1" BorderStyle="Inset" Padding="6,6,0,0,100" Font="Arial, 8.25pt" ForeColor="Black" BorderColor="Transparent" Sides="Left" StringFormat="Near;Center;0;None;Character;Default" TextAlignment="MiddleLeft" BorderWidthSerializable="2" />
|
|
||||||
<Item4 Ref="19" Name="DetailData3_Odd" BorderStyle="Inset" Padding="6,6,0,0,100" Font="Arial, 8.25pt" ForeColor="Black" BackColor="255,243,245,248" BorderColor="Transparent" Sides="None" StringFormat="Near;Center;0;None;Character;Default" TextAlignment="MiddleLeft" BorderWidthSerializable="1" />
|
|
||||||
<Item5 Ref="20" Name="PageInfo" BorderStyle="Inset" Padding="6,6,0,0,100" Font="Arial, 8.25pt, style=Bold" ForeColor="255,64,70,80" StringFormat="Near;Near;0;None;Character;Default" />
|
|
||||||
</StyleSheet>
|
|
||||||
<ComponentStorage>
|
|
||||||
<Item1 Ref="0" ObjectType="DevExpress.DataAccess.Sql.SqlDataSource,DevExpress.DataAccess.v25.1" Name="sqlDataSource1" Base64="PFNxbERhdGFTb3VyY2UgTmFtZT0ic3FsRGF0YVNvdXJjZTEiPjxDb25uZWN0aW9uIE5hbWU9IlNxbFNlcnZlciIgRnJvbUFwcENvbmZpZz0idHJ1ZSIgLz48UXVlcnkgVHlwZT0iU2VsZWN0UXVlcnkiIE5hbWU9IlNhc19UX1NlY3RvciI+PFRhYmxlcz48VGFibGUgTmFtZT0iU2FzX1RfU2VjdG9yIiAvPjwvVGFibGVzPjxDb2x1bW5zPjxDb2x1bW4gVGFibGU9IlNhc19UX1NlY3RvciIgTmFtZT0iSWQiIC8+PENvbHVtbiBUYWJsZT0iU2FzX1RfU2VjdG9yIiBOYW1lPSJOYW1lIiAvPjwvQ29sdW1ucz48L1F1ZXJ5PjxSZXN1bHRTY2hlbWE+PERhdGFTZXQgTmFtZT0ic3FsRGF0YVNvdXJjZTEiPjxWaWV3IE5hbWU9IlNhc19UX1NlY3RvciI+PEZpZWxkIE5hbWU9IklkIiBUeXBlPSJTdHJpbmciIC8+PEZpZWxkIE5hbWU9Ik5hbWUiIFR5cGU9IlN0cmluZyIgLz48L1ZpZXc+PC9EYXRhU2V0PjwvUmVzdWx0U2NoZW1hPjxDb25uZWN0aW9uT3B0aW9ucyBDbG9zZUNvbm5lY3Rpb249InRydWUiIC8+PC9TcWxEYXRhU291cmNlPg==" />
|
|
||||||
</ComponentStorage>
|
|
||||||
</XtraReportsLayoutSerializer>
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import React from 'react'
|
import React, { useMemo } from 'react'
|
||||||
import { Container } from '@/components/shared'
|
import { Container } from '@/components/shared'
|
||||||
import { Helmet } from 'react-helmet'
|
import { Helmet } from 'react-helmet'
|
||||||
import ReportViewer, { RequestOptions } from 'devexpress-reporting-react/dx-report-viewer'
|
import ReportViewer, { RequestOptions } from 'devexpress-reporting-react/dx-report-viewer'
|
||||||
|
|
@ -7,11 +7,20 @@ import 'devextreme/dist/css/dx.light.css'
|
||||||
import '@devexpress/analytics-core/dist/css/dx-analytics.common.css'
|
import '@devexpress/analytics-core/dist/css/dx-analytics.common.css'
|
||||||
import '@devexpress/analytics-core/dist/css/dx-analytics.light.css'
|
import '@devexpress/analytics-core/dist/css/dx-analytics.light.css'
|
||||||
import 'devexpress-reporting/dist/css/dx-webdocumentviewer.css'
|
import 'devexpress-reporting/dist/css/dx-webdocumentviewer.css'
|
||||||
import { useParams } from 'react-router-dom'
|
import { useParams, useLocation } from 'react-router-dom'
|
||||||
|
|
||||||
const DevexpressReportViewer: React.FC = () => {
|
const DevexpressReportViewer: React.FC = () => {
|
||||||
const { translate } = useLocalization()
|
const { translate } = useLocalization()
|
||||||
const { id } = useParams<{ id: string }>()
|
const { id } = useParams<{ id: string }>()
|
||||||
|
const location = useLocation()
|
||||||
|
|
||||||
|
// Query string parametrelerini reportUrl'e ekle
|
||||||
|
const reportUrlWithParams = useMemo(() => {
|
||||||
|
if (location.search) {
|
||||||
|
return `${id}${location.search}`
|
||||||
|
}
|
||||||
|
return id
|
||||||
|
}, [id, location.search])
|
||||||
|
|
||||||
if (!id) {
|
if (!id) {
|
||||||
return null
|
return null
|
||||||
|
|
@ -25,7 +34,7 @@ const DevexpressReportViewer: React.FC = () => {
|
||||||
defaultTitle="Erp Platform"
|
defaultTitle="Erp Platform"
|
||||||
></Helmet>
|
></Helmet>
|
||||||
|
|
||||||
<ReportViewer reportUrl={id}>
|
<ReportViewer reportUrl={reportUrlWithParams}>
|
||||||
<RequestOptions host={`${import.meta.env.VITE_API_URL}/`} invokeAction="DXXRDV" />
|
<RequestOptions host={`${import.meta.env.VITE_API_URL}/`} invokeAction="DXXRDV" />
|
||||||
</ReportViewer>
|
</ReportViewer>
|
||||||
</Container>
|
</Container>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue