2017-02-03 8 views
2

c#.netのCrystalレポートを使用して、異なるデータの印刷状況に応じて複数のレポートを同時に印刷したい。 EXのために:私の仕事では、印刷状態の5種類があり、すなわちc#.netのcrystal sapレポートを使用して、同時に異なる条件で異なるデータで複数のレポートを印刷する

  1. オリジナル
  2. 重複
  3. 三重
  4. Choblicate
  5. この5つのステータスは、チェックボックスオプションにあったすべての

。ここで、いずれかの人がオリジナルと同様に複製オプションを選択し、その時点でボタンをクリックした場合、選択されたチェックボックス状態レポートが表示されたがっている、すなわち元の状態と異なる状態の複製されたレポートが表示された。

ステータスが異なる:元のレポートには元のステータスが表示され、重複したレポートには重複したステータスが表示されます。

他の人がその時点ですべてのオプションをチェックしているのと同じように、レポートのページ全体が同時に異なるステータスで表示されるようにしたいのと同じです。

これは、その時点の1つのレポートステータスに対してのみ実行できますが、複数のステータスについては何も分かりません。

レポートステータスのいずれかのコードです。

private void btn_previewdocument_Click(object sender, EventArgs e) 
     { 
      try 
      { 
       string mtmptbl = "TmpRetailInvoicePrint"; 
       RetailInvoicePrint frm = new RetailInvoicePrint(); 
       Cursor = Cursors.WaitCursor; 
       timer1.Enabled = true; 

       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 distinct Client.clientname as ClientName, " + System.Environment.NewLine; 
       qryPreviewDocument += " RetailInvoice.invoiceno as InvoiceNo, " + System.Environment.NewLine; 
       qryPreviewDocument += " RetailInvoice.pono as PoNO, RetailInvoice.issuedate as IssueDate, RetailInvoice.duedate as DueDate, " + System.Environment.NewLine; 
       qryPreviewDocument += " RetailInvoice.discount as Discount, RetailInvoice.shipping as Shipping, RetailInvoice.tax as Tax, RetailInvoice.vat as Vat, " + System.Environment.NewLine; 
       qryPreviewDocument += " RetailInvoice.sese as Sese, RetailInvoice.paymenttype as PaymentType, RetailInvoice.chequeno as Chequeno, RetailInvoice.totalamt as TotalAmt, " + System.Environment.NewLine; 
       qryPreviewDocument += " RetailInvoice.description as Description, RetailInvoice.paymentpaid as PaymentPaid, RetailInvoice.subtotal as Subtotal, " + System.Environment.NewLine; 

       qryPreviewDocument += " RetailInvoicePayment.productid as ProductName, RetailInvoicePayment.uom as Uom, " + System.Environment.NewLine; 
       qryPreviewDocument += " RetailInvoicePayment.quantity as Quantity, RetailInvoicePayment.price as Price " + System.Environment.NewLine; 

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

       qryPreviewDocument += " from tbl_retailinvoice RetailInvoice LEFT OUTER JOIN tbl_retailinvoicepayment RetailInvoicePayment " + System.Environment.NewLine; 
       qryPreviewDocument += " ON RetailInvoice.invoiceno = RetailInvoicePayment.invoiceno " + System.Environment.NewLine; 
       qryPreviewDocument += " LEFT OUTER JOIN tbl_clientdetail Client ON RetailInvoice.clientid = Client.clientid " + System.Environment.NewLine; 

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

       qryPreviewDocument += " and RetailInvoicePayment.BranchID = " + lbl_branchid.Text + " " + System.Environment.NewLine; 
       qryPreviewDocument += " and RetailInvoicePayment.YearID = " + lbl_yearid.Text + " " + System.Environment.NewLine; 
       qryPreviewDocument += " and RetailInvoicePayment.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(); 
       cn.Close(); 

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

       cryRpt.Load(crReportPath + "\\RptRetailInvoice.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); 
      } 
     } 

このコード私はbtn_previewdocumentクリックイベントの下で行っています。したがって、このイベントが発生した時点でレポートが生成されます。

Advance In Thanks。

+0

あなたのコードの中で、 dupへのオリジナル、旅行など。 – BugFinder

+0

ヤ。このコードは、1つのレポートと複数のレポートを出力するためのものです。なぜなら、複数のコードが実行される場所を混乱させるからです。 –

+0

印刷を意味しますか?プリンタ自体で表示するか、複数のレポートを画面に表示するだけですか? –

答えて

0

「オリジナル」、「複製」などと表示されたレポートの領域を見つけようとしましたが、私の助言はそのほとんどを取り込み、それを "printreport"この方法は、変数と、それはあなたが当然のその文字列を変更することができ

if selected_original then printreport("original") 
if selected_duplicate then printreport("dupliate") 
... 
if selected_all then 
    printreport("original") 
& printreport("dupliate") 
& ... 

以下の擬似コードのようなコードに何かそしてだろうが、レポート内で使用される、必要に応じて指定するには、あなたの場合には、その後、その状態を表し、その状態(あなたがあなたのコードでそれをやっている様子を見なかったので、私はあなたにそれを残さなければならない)

+0

私のコードでは、この行に水晶 "reportcryRpt.Load(crReportPath +" \\ RptRetailInvoice.rpt ");"がロードされます。だから私はどのようにこのような行に複数のレポートを実装実装することができます。 –

+0

あなたはいない、同じことを繰り返す.....か、x個のコピーを印刷する – BugFinder

関連する問題