简体   繁体   English

Crystal Reports使用两个传入的参数以编程方式进行排序

[英]Crystal Reports Programatically sort using two passed in parameters

I am pretty new to Crystal Reports and I am probably not using the latest. 我对Crystal Reports相当陌生,可能不使用最新版本。 We are using VS2010/ASP.NET as our main programming environment but we use the integrated Crystal Reports 2008 designer in VS2008, so I need to switch to 2008 when designing reports. 我们将VS2010 / ASP.NET用作主要的编程环境,但是我们在VS2008中使用集成的Crystal Reports 2008设计器,因此在设计报表时我需要切换到2008。 I have been passing in paramaters to reports by defining the Parameter Field in the IDE and then passing them in. We have ASP.NET screens with GridViews that are sortable. 我一直在通过在IDE中定义“参数字段”,然后将它们传递给报表,以将参数传递给报表。我们拥有带有可排序GridView的ASP.NET屏幕。 The data is displayed on the Crystal Report but I have to match how it is sorted. 数据显示在Crystal Report上,但我必须匹配其排序方式。 I looked things up on Google and found this and this article . 我看着东西在谷歌,发现这篇文章 I can't figure out how to use these code snippets. 我不知道如何使用这些代码段。 Our best bet seems to be our "Report Controller" classes which is the only place in C# where the Crystal Reports objects are available. 最好的选择似乎是“ Report Controller”类,它是C#中唯一可以使用Crystal Reports对象的地方。 A class looks like the following: 一个类如下所示:

public class CRMOCContactsController : ReportingBase
    {
        public CRMOCContactsController(DataSet reportData, NameValueCollection reportParams)
        {
            // Create an instance of the Crystal Report.
            this.Report = new Reports.CRMOCContacts();

            // Get the data 
            this.ReportData = reportData;

            foreach (string s in reportParams.AllKeys)
            {
                CRHelper.SetCurrentValuesForParameterField(this.Report.ParameterFields, s, reportParams[s]);
            }
        }

        protected override void SetDataSource()
        {
            this.Report.Database.Tables["ContactRecord"].SetDataSource(this.ReportData.Tables["ContactRecord"]);
            this.Report.Database.Tables["ContactSearchCriteria"].SetDataSource(this.ReportData.Tables["ContactSearchCriteria"]);
            this.Report.Database.Tables["SSIFields"].SetDataSource(this.ReportData.Tables["SSIFields"]);
        }

Does anyone see how I could use these type of classes to do this? 有人看到我如何使用这些类型的类来做到这一点吗? one parameter would be the field to sort and another would be the direction. 一个参数是要排序的字段,另一个参数是方向。 Thanks. 谢谢。 Showing me in code really helps. 向我展示代码确实有帮助。

Tiago, my browser is locked down and doesn't let me add a comment. Tiago,我的浏览器被锁定了,不允许我添加评论。 The only place there is Crystal code is in autogenerated C# classes that go with each report. Crystal代码的唯一位置是每个报表都附带的自动生成的C#类中。 For instance, the Reports.CRMOCContacts() class referenced above. 例如,上面引用的Reports.CRMOCContacts()类。 That is autogenerated by a tool and can't be modified: //------------------------------------------------------------------------------ // // This code was generated by a tool. 那是由工具自动生成的,无法修改:// ----------------------------------- ------------------------------------------- // //这段代码是由工具生成。 // Runtime Version:2.0.50727.3603 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. //运行时版本:2.0.50727.3603 // //对该文件所做的更改可能会导致错误的行为,并且如果重新生成代码,则会丢失//。 // //------------------------------------------------------------------------------ // // ---------------------------------------------- --------------------------------

There is the only reference to ReportDocument I see: public virtual CrystalDecisions.CrystalReports.Engine.ReportDocument CreateReport() { CRMOCContacts rpt = new CRMOCContacts(); 我只看到对ReportDocument的引用:公共虚拟CrystalDecisions.CrystalReports.Engine.ReportDocument CreateReport(){CRMOCContacts rpt = new CRMOCContacts(); rpt.Site = this.Site; rpt.Site = this.Site; return rpt; 返回rpt; } }

I figured something out. 我知道了。 The code in CRMOCContactsController can be Crystal code if I treat this.Report as a ReportDocument and add these libraries: using CrystalDecisions.Shared; 如果将this.Report视为ReportDocument并添加以下库,则CRMOCContactsController中的代码可以为Crystal代码:using CrystalDecisions.Shared; using CrystalDecisions.ReportSource; 使用CrystalDecisions.ReportSource; using CrystalDecisions.CrystalReports.Engine; 使用CrystalDecisions.CrystalReports.Engine;

Then I could do: FieldDefinition FieldDef = null;; 然后我可以做:FieldDefinition FieldDef = null ;; FieldDef = this.Report.Database.Tables[0].Fields[]; FieldDef = this.Report.Database.Tables [0] .Fields []; this.Report.DataDefinition.SortFields[0].Field = FieldDef; this.Report.DataDefinition.SortFields [0] .Field = FieldDef; this.Report.DataDefinition.SortFields[0].SortDirection = CrystalDecisions.Shared.SortDirection.AscendingOrder; this.Report.DataDefinition.SortFields [0] .SortDirection = CrystalDecisions.Shared.SortDirection.AscendingOrder;

I just don't know how to pass in the sortField? 我只是不知道如何在sortField中传递? What format? 什么格式?

ReportDocument objReport = new ReportDocument();
objReport.Load("Your report path");
FieldDefinition FieldDef;
FieldDef = objReport .Database.Tables[0].Fields[sortField];
objReport.DataDefinition.SortFields[0].Field = FieldDef;
objReport.DataDefinition.SortFields[0].SortDirection = CrystalDecisions.Shared.SortDirection.DescendingOrder;

Sam, I couldn't figure out how your helper classes are working. 山姆,我不知道您的助手课程是如何进行的。 It looks like you are passing a dataset to the ReportDocument, right? 看起来您正在将数据集传递给ReportDocument,对吧? If this the case, you can pass to the ReportDocument sorted datatables, and it will keep the order of lines. 在这种情况下,您可以传递给ReportDocument排序的数据表,它将保持行的顺序。

Here, I am passing a dataset to my report, created from a stored procedures that receives the order by as a parameter. 在这里,我将数据集传递给我的报表,该报表是由存储过程创建的,该存储过程将按顺序接收订单。 The dataset comes sorted, so the report shows the information sorted as well. 数据集已排序,因此报告也显示排序的信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM