使用c #windows窗体应用程序将过滤后的数据从水晶报告导出为pdf

时间:2016-06-27 07:44:04

标签: c# mysql filter crystal-reports export

我在c#windows form application中使用crystal report是新手。我将我的水晶报告连接到mysql服务器" 11.0.65.185"。

我的水晶报告中有这个6列(EmpName,EmpId,DOB,DOJ,地址,城市)。然后我在报告中添加一个参数(fromdate和todate)

这个链接帮助我通过stackoverflow过滤DOJ列http://stackoverflow.com/questions/37391112/filter-data-in-crystal-report-using-datetimepicker/37525275#37525275

但是我在导出选项中遇到了问题。我有最多1000个数据。当我在DOJ中使用Datetimepicker1过滤数据时,将fromdate和Datetimepicker2作为todate,我将数据存储到我的报告中。

我只需要导出过滤数据。但是当我搜索谷歌搜索时,我得到了一个代码来导出我的数据库表中存在的完整数据。

CrystalReport1 crys = new CrystalReport1();
crys.ExportToDisk(ExportFormatType.PortableDocFormat, "C:\\Users\\Downloads\\ReportAsPDF.pdf");
                MessageBox.Show("Report Export Into PDF File");

此代码帮助我在c#crystal report中导出整个数据。请朋友帮助我将过滤后的数据导出为PDF格式。

感谢您的帮助。

1 个答案:

答案 0 :(得分:2)

尝试此操作与报告

中的过滤数据相同
                TableLogOnInfos crtableLogoninfos = new TableLogOnInfos();
                TableLogOnInfo crtableLogoninfo = new TableLogOnInfo();
                ConnectionInfo crConnectionInfo = new ConnectionInfo();
                Tables CrTables;

                ParameterFieldDefinitions crParameterFieldDefinitions;
                ParameterFieldDefinition crParameterFieldDefinition;
                ParameterValues crParameterValues = new ParameterValues();
                ParameterDiscreteValue crParameterDiscreteValue = new ParameterDiscreteValue();

                crParameterDiscreteValue.Value = dateTimePicker1.Text;
                crParameterFieldDefinitions = crys.DataDefinition.ParameterFields;
                crParameterFieldDefinition = crParameterFieldDefinitions["fromdate"];
                crParameterValues = crParameterFieldDefinition.CurrentValues;

                crParameterValues.Clear();
                crParameterValues.Add(crParameterDiscreteValue);
                crParameterFieldDefinition.ApplyCurrentValues(crParameterValues);

                crParameterDiscreteValue.Value = dateTimePicker2.Text;
                crParameterFieldDefinitions = crys.DataDefinition.ParameterFields;
                crParameterFieldDefinition = crParameterFieldDefinitions["todate"];
                crParameterValues = crParameterFieldDefinition.CurrentValues;



                crParameterValues.Add(crParameterDiscreteValue);
                crParameterFieldDefinition.ApplyCurrentValues(crParameterValues);


                crParameterValues.Add(crParameterDiscreteValue);
                crParameterFieldDefinition.ApplyCurrentValues(crParameterValues);

                crConnectionInfo.ServerName = "****";
                crConnectionInfo.DatabaseName = "****"; ;
                crConnectionInfo.UserID = "root";
                crConnectionInfo.Password = "******";

                CrTables = crys.Database.Tables;
                foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in CrTables)
                {
                    crtableLogoninfo = CrTable.LogOnInfo;

                    CrTable.ApplyLogOnInfo(crtableLogoninfo);
                }
                DateTime date = DateTime.Now;
                int t = date.Hour;
                int t1 = date.Minute;
                int t2 = date.Second;
                int m = date.Month;
                int d = date.Day;
                int y = date.Year;

                crys.ExportToDisk(ExportFormatType.PortableDocFormat, "C:\\Downloads\\ReportAsPDF Time" + t + " - " + t1 + " - " + t2 + " Date " + d + " - " + m + " - " + y + ".pdf");
                MessageBox.Show("Export Successfully");