gpt4 book ai didi

c# - 带有链接子报表的 Crystal 报表仅适用于报表预览

转载 作者:太空狗 更新时间:2023-10-29 21:53:15 26 4
gpt4 key购买 nike

我在我的主报告中使用了带有 sql 参数的存储过程。

enter image description here

我的主要报告的存储过程 enter image description here

然后我尝试使用以下存储过程在工作报告中添加子报告

enter image description here

然后将 Subreport 字段参数链接到我的 Main

enter image description here

如果子报表正常工作,我检查了主报表预览

enter image description here

然后我运行报告,但我只看到这个 enter image description here它只是停留在这条消息中并继续运行,我什至等待了几个小时并检查任务管理器是否挂起报告,但是没有..它也没有任何错误消息。但是为了关闭正在运行的报告,我必须在任务管理器中“结束进程”。

所以我尝试从子报告和链接中删除字段参数并重新运行报告。

enter image description here

它可以工作,但是如果不从主报告传递值就拥有报告是没有用的。因为我有日期范围。似乎是什么问题?为什么当我链接参数时它只是卡在加载报告?

有关详细信息,我正在使用 SAP Crystal Report 服务包 16 和 IDE 作为 Visual Studio 2015

这是我用于在主报告上获取/设置参数值的代码

 private void SalesByRangeReport_Load(object sender, EventArgs e)
{

FormBorderStyle = FormBorderStyle.Sizable;

WindowState = FormWindowState.Maximized;

TopMost = true;

DataTable dtSalesByRangeReport = GetData();

showReport(dtSalesByRangeReport);
}

private void showReport(DataTable dtSalesByRangeReport)
{
ReportDocument rdoc = new ReportDocument();

//rdoc.Load(@"Report\SalesByRangeReport.rpt");

rdoc.Load(AppDomain.CurrentDomain.BaseDirectory + @"Report\SalesByRangeReport.rpt");
rdoc.SetDataSource(dtSalesByRangeReport);

TextObject txt;
if (rdoc.ReportDefinition.ReportObjects["test"] != null)
{
txt = (TextObject)rdoc.ReportDefinition.ReportObjects["test"];
txt.Text = "From :" + StartDate.ToString(" MMMM dd yyyy hh :mm") + " To :" + EndDate.ToString(" MMMM dd yyyy hh :mm");
}

SalesByRangeCystalReport.ReportSource = rdoc;
}


private DataTable GetData()
{
DataTable dtData = new DataTable();

using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["CSPOSWare.Reports.Properties.Settings.fpos_chaplinConnectionString"].ConnectionString))
{

//TODO Mark and Reni : Create a Stored Procedure, Saved in SalesByRangeReport.txt

using (SqlCommand cmd = new SqlCommand("usp_ReportShowSalesRangeDateTime", conn))
{
cmd.CommandType = CommandType.StoredProcedure;

conn.Open();

//cmd.Parameters.AddWithValue("@TopInt", this.TopInt);
cmd.Parameters.AddWithValue("@SortType", this.SortType);
cmd.Parameters.AddWithValue("@StartDate", this.StartDate);
cmd.Parameters.AddWithValue("@EndDate", this.EndDate);
cmd.Parameters.AddWithValue("@DeptGroup", this.DeptGroup);
cmd.Parameters.AddWithValue("@DateType", this.DateType);

//Console.WriteLine("Start Date" + StartDate);

SqlDataReader rdr = cmd.ExecuteReader();

dtData.Load(rdr);
}

}


return dtData;
}

我的两个报告都具有这些属性:

Build Action: Compile
Copy to Output Directory: Copy Always
Custom Tool:
Custom Tool Name:

所以我尝试在我的主 SP 和子 SP 上添加针对未知的优化主要:

  ALTER PROCEDURE[dbo].[usp_ReportShowSalesRangeDateTime]
(
@SortType Varchar(50),
@StartDate DATETIME,
@EndDate DATETIME,
@DeptGroup Varchar(50),
@DateType Varchar(50)
)
AS
BEGIN
Declare @SQLQuery NVARCHAR(max)
Declare @ReportCriteria NVARCHAR(max)
If (LEN(@DeptGroup) > 0)
Set @ReportCriteria = ' AND B.Department = ''' + @DeptGroup + '''';
If (LEN(@DeptGroup) = 0)
Set @ReportCriteria = ' ';

WITH SalesRange AS(
Select A.EndDate as [Log Date], A.StoreDate as [Store Date], B.Department as [Department], B.Quantity as [Quantity],
isnull(C.Amount,0) as [Discount], B.AmountDue as [AmountDue],round(B.BasePrice*1.12,4) as [Gross Sales],
B.BasePrice + isnull(vsa.Tax,0) as [BasePrice],
case when vsa.type = 0 then isnull(vsa.Amount,0) else 0.0000 end As [VAT Sales Amount],
case when vsa.type = 1 then isnull(vsa.Amount,0) else 0.0000 end As [VAT Exempt Sales Amount],
B.ServiceCharge as [ServiceCharge], isnull(vsa.Tax,0) As [VAT Sales Tax],
case when D.[Type] = 0 Then D.Tax Else 0 End As [Tax],
case when T.MediaIndex = 4 then T.Amount else 0 End As [GiftCert],
case when T.MediaIndex = 4 then 1 else 0 End As [GCCount]
FROM CSSaleItem B WITH(NOLOCK)
LEFT JOIN CSSaleItemDiscount C WITH(NOLOCK) ON B.CSSaleItemID = C.CSSaleItemID
LEFT JOIN CSSale A WITH(NOLOCK) ON A.CSSaleID = B.CSSaleID
LEFT JOIN CSSaleItemTax D WITH(NOLOCK) ON B.CSSaleItemID = D.CSSaleItemID
LEFT JOIN (Select CSSaleItemID, Amount, Tax, [Type] From CSSaleItemTax WITH(NOLOCK) Where [Type] = 0) As vsa ON vsa.CSSaleItemID = B.CSSaleItemID
LEFT JOIN CSSaleTender T WITH(NOLOCK) ON T.CSSaleID = A.CSSaleID
Where StoreDate BETWEEN convert(VARCHAR,@StartDate) AND convert(VARCHAR,@EndDate) and a.RefundStoreDate IS NULL
)
SELECT [Department], sum([Quantity]) as [Quantity], SUM([Tax]) as [Tax] , sum([Discount]) as [Discount],
sum(([Gross Sales]+[ServiceCharge])) as [Gross Sales], sum(([BasePrice]+[ServiceCharge]-[Discount])) As [Net Sales],
sum(([BasePrice]+[ServiceCharge]-[Discount]))/
(Select sum(NetSales) FROM CSSale B LEFT JOIN (select csSaleID, Department from CSSaleItem WITH(NOLOCK) group by Department, CSSALEID ) AS A On A.CSSaleID = B. CSSaleID
Where StoreDate BETWEEN convert(VARCHAR,@StartDate) AND convert(VARCHAR,@EndDate) and RefundStoreDate IS NULL )*100 as [% Total],
sum([GiftCert]) as [Gift Cert Total], sum([ServiceCharge]) as [Service Charge], sum([GCCount]) as [GCCountTotal]
From SalesRange
Group By [Department]
Order By [Department] desc
OPTION (OPTIMIZE FOR (@StartDate UNKNOWN, @EndDate UNKNOWN))
END

子报告:

    ALTER PROCEDURE[dbo].[usp_ReportShowMedia](
@StartDate2 DATETIME,
@EndDate2 DATETIME
)
As
BEGIN


Select isnull(M.MediaName,'Other') As [Media],
COUNT(T.MediaIndex) As [Count],
isnull(sum(T.Amount),0) As [Sales Amount],
isnull(sum(case when S.EndDate IS NOT NULL and DateRefunded IS NULL Then S.NetSales Else 0 End),0) As [Total Sales],
isnull(sum(case when S.EndDate IS NULL then S.NetSales else 0 end),0) as [Cancelled Sales],
isnull(sum(case when S.DateRefunded IS NOT NULL then S.NetSales else 0 end),0) as [Refunded Sales]
FROM CSSale S WITH(NOLOCK)
LEFT JOIN (Select CSSaleID, Department from CSSaleItem WITH(NOLOCK) group by CSSaleID,Department) As I ON I.CSSaleID = S.CSSaleID
LEFT JOIN CSSaleTender T WITH(NOLOCK) On S.CSSaleID = T.CSSaleID
LEFT JOIN Media M WITH(NOLOCK) ON M.MediaIndex = T.MediaIndex
Where StoreDate BETWEEN convert(VARCHAR,@StartDate2) AND convert(VARCHAR,@EndDate2)
group by M.MediaName
order by M.MediaName
OPTION (OPTIMIZE FOR (@StartDate2 UNKNOWN, @EndDate2 UNKNOWN))
END

相同的结果,我认为来自主报告的结果没有通过子报告,因为它总是只在预览上工作,但在运行时只是停留在加载上。

我试过 sp_who2 Active 来检查是否被阻止。 enter image description here

顺便说一句,如果这有帮助的话,我正在我的 App.config 上使用这个连接..

 <?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<probing privatePath="lib" />
</assemblyBinding>
</runtime>
<connectionStrings>
<add name="CSPOS.Reports.Properties.Settings.chaplinConnectionString" connectionString="Data Source=RENZ\SQLEXPRESS;Initial Catalog=erika;Integrated Security=True" providerName="System.Data.SqlClient"/>
</connectionStrings>
</configuration>

我检查了 master 上的数据库权限

enter image description here

最佳答案

有一天我遇到了这样的情况。主要问题是存储过程中不同参数的执行计划不正确。

它可以通过OPTION (OPTIMIZE FOR (@param UNKNOWN) 修复。您可以在 here 中阅读所有相关内容。

第二种:查询中可以有一些读锁。如果报告数据不是那么敏感,您可以使用标准的 WITH(NOLOCK) 提示(READ UNCOMMITTED 隔离级别)。

尝试修改您的查询,使其看起来像这样并检查结果。

SELECT 
...
FROM CSSale S WITH(NOLOCK)
LEFT JOIN (... FROM CSSaleItem WITH(NOLOCK) ...)
LEFT JOIN CSSaleTender T WITH(NOLOCK) ...
LEFT JOIN Media M WITH(NOLOCK)
ORDER BY M.MediaName
OPTION (OPTIMIZE FOR (@StartDate2 UNKNOWN, @EndDate2 UNKNOWN))

您还需要检查用于主查询的存储过程是否存在相同问题。

附言无论如何检查 SQL Profiler 是否有传出查询。

关于c# - 带有链接子报表的 Crystal 报表仅适用于报表预览,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37695479/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com