【问题标题】:Is there a better way to do this ?有一个更好的方法吗 ?
【发布时间】:2013-05-03 00:45:30
【问题描述】:

就这样吧。我有一个工作正常的数据集模型,它从数据库中导入数据并将其提供给水晶报表。这个解决方案有效,但它非常耗时,我想知道是否有其他方法可以做到这一点......

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Oracle.DataAccess.Client;
using System.Data;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;


namespace WebApplication1
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            string connetionString = null;
            OracleConnection connection;
            OracleDataAdapter OracleAdapter;
            DataSet ds = new DataSet();
            string firstSql = null;


            connetionString = "datasoruce";

            connection = new OracleConnection(connetionString);
               string secondSql = "select statementnumber from erocks.statement_data_domestic";
                connection.Open();
                //OracleAdapter = new OracleDataAdapter(firstSql, connection);
                //OracleAdapter.Fill(ds, "domestic");
                OracleAdapter = new OracleDataAdapter(secondSql, connection);
                OracleAdapter.Fill(ds, "statement");
                connection.Close();
                ReportDocument reportDoc = new ReportDocument();
                reportDoc.Load(@"c:\users\desktop\statement.rpt");


            DataTable stmt = ds.Tables["statement"];

            string stmtnumber="";
            for (int i = 0; i < stmt.Rows.Count - 1; i++)
            {
                stmtnumber = stmt.Rows[i][0].ToString();

                firstSql = @"SELECT DISTINCT statement_header.statementnumber,
                     statement_details.invoicedate,
                     statement_details.invoicenumber,
                     statement_details.invoicetotal,
                     statement_details.doc_type,
                     statement_header.statementtotal,
                     statement_details.bunumber_ru,
                     statement_details.bunumber,
                     statement_details.description,
                     statement_details.reference_number,
                     statement_header.remto_zip,
                     statement_header.remto_city,
                     statement_header.remto_state,
                     statement_header.remto_mailname,
                     statement_header.remto_addr1,
                     statement_header.remto_addr2,
                     statement_header.remto_addr3,
                     statement_header.soldto_city,
                     statement_header.soldto_state,
                     statement_header.soldto_zip,
                     statement_header.soldto_addr1,
                     statement_header.soldto_addr2,
                     statement_header.soldto_addr3,
                     statement_header.balance_forward,
                     statement_header.statementdate,
                     statement_header.custid,
                     statement_header.custname,
                     statement_header.phone_prefix,
                     statement_header.phone_number,
                     statement_details.purchases,
                     statement_details.payments,
                     statement_details.misc_credit2,
                     statement_details.misc_credit1,
                     statement_header.company_number,
                     statement_header.statementpurchases,
                     statement_header.statementpayments,
                     statement_header.statementmisc_credit1,
                     statement_header.statementmisc_credit2,
                     statement_header.nomailnoprint,
                     statement_header.SOLDTOCOUNTRYCODE,
                     statement_header.SOLDTOCOUNTRYNAME,
                     statement_header.CREDITZEROFLAG
       FROM STATEMENT_DATA_DOMESTIC statement_header
            INNER JOIN STATEMENT_DATA_DETAILS statement_details
               ON statement_header.statementnumber =
                     statement_details.statementnumber
                        where statement_header.statementnumber="+stmtnumber;
                connection.Open();
                OracleAdapter = new OracleDataAdapter(firstSql, connection);
                OracleAdapter.Fill(ds, "domestic");

                OracleAdapter.Dispose();
                connection.Close();
                reportDoc.SetDataSource(ds.Tables["domestic"]);
                ExportOptions CrExportOptions;
                DiskFileDestinationOptions CrDiskFileDestinationOptions = new DiskFileDestinationOptions();
                PdfRtfWordFormatOptions CrFormatTypeOptions = new PdfRtfWordFormatOptions();
                CrDiskFileDestinationOptions.DiskFileName = @"d:\pdf\"+ stmtnumber + ".pdf";
                CrExportOptions = reportDoc.ExportOptions;
                {
                    CrExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
                    CrExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;
                    CrExportOptions.DestinationOptions = CrDiskFileDestinationOptions;
                    CrExportOptions.FormatOptions = CrFormatTypeOptions;

                }
                reportDoc.Export();
                ds.Tables["domestic"].Clear();
            }
                }
            }

        }

【问题讨论】:

  • 这有什么耗时的?你有没有通过代码?有很多数据吗?究竟是什么问题?
  • 大量数据处理时间过长,逐条记录我也与数据库的连接正在打开和关闭。我在想有没有一种方法可以让我获取数据表中的所有数据以及如何复制确切的数据
  • 例如用数据库中的所有数据填充 ds.Tables["domestic "],用所有语句编号填充 ds.tables ["statement"]。与数据库的紧密连接。现在解析 ds.tables["statement"] 中的每条记录,仅从国内获取该语句编号的所有相关数据,并将其放入数据表中,然后将其提供给 Crystalreport。

标签: c# batch-file crystal-reports datatable dataset


【解决方案1】:

如果你检索所有报表的数据,在报表中按statementID分组,然后按这个分组突发报表,会更快。 Bursting 将为每个组生成一个单独的文件。通过这种方式,您将能够通过一次调用数据库来生成所有文件。

【讨论】:

  • 我是水晶报表的新手。 .我怎么爆破..你可以分享任何例子吗?
猜你喜欢
  • 2011-06-30
  • 1970-01-01
  • 2021-01-03
  • 2023-01-31
  • 1970-01-01
  • 2017-03-24
  • 1970-01-01
相关资源
最近更新 更多