如何使用sap crystal report在c#.net中打印多个不同发票号的多个新页面

时间:2017-03-28 06:42:15

标签: c# crystal-reports

我想根据发票号码打印多个页面。例如,有两个选项用于打印的帐单,这意味着发票号到发票编号即我要打印发票号码6到10,对于不同的发票号码,将打印不同的页面。从我的下面的代码显示多页,但不是根据数据显示的发票号码[即。当一个页面上的数据已满时,它会显示第二页]。但我不想要这个。

这是我的代码,

try
{
    string mtmptbl = "TmpTaxInvoicePrint";
    RetailInvoicePrint frm = new RetailInvoicePrint();
    Cursor = Cursors.WaitCursor;

    ReportDocument cryRpt = new ReportDocument();
    SqlCommand MyCommand = new SqlCommand();
    SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder(cn.ConnectionString);
    ConnectionInfo crConnectionInfo = new ConnectionInfo();
    TableLogOnInfo crtableLogoninfo = new TableLogOnInfo();

    string qryPreviewDocument = " SELECT Company.companyname, Company.address, Company.city, Company.state, Company.phono, Company.gtin as CompanyGTinNo, Company.ctin as CompanyCTinNo, Company.gtindate as CompanyGTinDate, " + System.Environment.NewLine;
    qryPreviewDocument += " Client.clientname, Client.contactname, Client.billingaddrtess, Client.GTin as ClientGTinNo, Client.CTin as ClientCTinNo, Client.gtindate as ClientGTinDate, Client.ctindate as ClientCTinDate, " + System.Environment.NewLine;
    qryPreviewDocument += " TaxInvoice.invoiceno, TaxInvoice.pono, TaxInvoice.pono2, TaxInvoice.pono3, TaxInvoice.pono4, " + System.Environment.NewLine;
    qryPreviewDocument += " TaxInvoice.issuedate as IssueDate, " + System.Environment.NewLine;
    qryPreviewDocument += " TaxInvoice.discount as Discount, TaxInvoice.shipping as Shipping, TaxInvoice.tax as Tax, TaxInvoice.vat as Vat, " + System.Environment.NewLine;
    qryPreviewDocument += " TaxInvoice.sese as Sese, TaxInvoice.paymenttype as PaymentType, TaxInvoice.chequeno as Chequeno, TaxInvoice.totalamt as TotalAmt, " + System.Environment.NewLine;
    qryPreviewDocument += " TaxInvoice.description as Description, TaxInvoice.paymentpaid as PaymentPaid, TaxInvoice.subtotal as Subtotal, " + System.Environment.NewLine;

    qryPreviewDocument += " Product.productname as ProductName, TaxInvoiceProductDetail.uom as Uom, " + System.Environment.NewLine;
    qryPreviewDocument += " TaxInvoiceProductDetail.quantity as Quantity, TaxInvoiceProductDetail.price as Price, " + System.Environment.NewLine;
    qryPreviewDocument += " TaxInvoiceProductDetail.challanno as ChallanNo, TaxInvoiceProductDetail.issuedate as ChallanDate " + System.Environment.NewLine;

    qryPreviewDocument += " into " + mtmptbl + " " + System.Environment.NewLine;

    qryPreviewDocument += " from tbl_TaxInvoice TaxInvoice " + System.Environment.NewLine;
    qryPreviewDocument += " LEFT OUTER JOIN tbl_TaxInvoiceProductDetail TaxInvoiceProductDetail ON TaxInvoice.invoiceno = TaxInvoiceProductDetail.invoiceno " + System.Environment.NewLine;
    qryPreviewDocument += " LEFT OUTER JOIN tbl_clientdetail Client ON TaxInvoice.clientid = Client.clientid " + System.Environment.NewLine;
    qryPreviewDocument += " LEFT OUTER JOIN tbl_companydetail Company ON TaxInvoice.BranchID = Company.companyid " + System.Environment.NewLine;
    qryPreviewDocument += " LEFT OUTER JOIN tbl_product Product ON TaxInvoiceProductDetail.productid = Product.productid " + System.Environment.NewLine;

    qryPreviewDocument += " where TaxInvoice.BranchID = " + lbl_branchid.Text + " " + System.Environment.NewLine;
    qryPreviewDocument += " and TaxInvoice.YearID = " + lbl_yearid.Text + " " + System.Environment.NewLine;
    qryPreviewDocument += " and TaxInvoice.invoiceno = " + txt_invoice.Text + "";

    qryPreviewDocument += " and TaxInvoiceProductDetail.BranchID = " + lbl_branchid.Text + " " + System.Environment.NewLine;
    qryPreviewDocument += " and TaxInvoiceProductDetail.YearID = " + lbl_yearid.Text + " " + System.Environment.NewLine;
    qryPreviewDocument += " and TaxInvoiceProductDetail.invoiceno = " + txt_invoice.Text + "";

    string SQL = "select upper(name) as TABLE_NAME FROM sysobjects WHERE type = 'U' and name = '" + mtmptbl + "' order by name";
    DataTable dt = new DataTable();
    SqlDataAdapter da = new SqlDataAdapter(SQL, cn);
    da.Fill(dt);
    if (dt.Rows.Count > 0)
    {
        string qrydrop = "drop table " + mtmptbl + "";
        SqlCommand cmd = new SqlCommand(qrydrop, cn);
        cn.Open();
        cmd.ExecuteNonQuery();
        cn.Close();
    }

    MyCommand = new SqlCommand(qryPreviewDocument, cn);
    MyCommand.CommandType = CommandType.Text;
    cn.Open();
    MyCommand.ExecuteNonQuery();

    //Add BillType field to the tmptable
    using (MyCommand = new SqlCommand("alter table [" + mtmptbl + "] add [billtype] varchar(20) NULL", cn))
    {
        MyCommand.CommandType = CommandType.Text;
        MyCommand.ExecuteNonQuery();
    }
    cn.Close();

    string crReportPath = Application.StartupPath.Replace("bin\\Debug", "") + "\\Print";

    cryRpt.Load(crReportPath + "\\RptTaxInvoicePrint.rpt");

    builder.ConnectionString = System.Configuration.ConfigurationSettings.AppSettings["con"];
    string dbName = builder.InitialCatalog;
    string dbDataSource = builder.DataSource;
    string userID = builder.UserID;
    string pass = builder.Password;

    crConnectionInfo.ServerName = dbDataSource;
    crConnectionInfo.DatabaseName = dbName;
    crConnectionInfo.UserID = userID;
    crConnectionInfo.Password = pass;

    Tables Crtables;
    Crtables = cryRpt.Database.Tables;

    foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in Crtables)
    {
        crtableLogoninfo = CrTable.LogOnInfo;
        crtableLogoninfo.ConnectionInfo = crConnectionInfo;
        CrTable.ApplyLogOnInfo(crtableLogoninfo);
    }

    frm.crystalReportViewer1.ReportSource = cryRpt;
    frm.crystalReportViewer1.RefreshReport();

    Cursor = Cursors.Arrow;
    frm.Show();
    btn_reset.Focus();
}
catch (Exception ex)
{
    MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}

提前致谢

1 个答案:

答案 0 :(得分:1)

这可以通过将groupheadersection添加到发票号

来完成