/// <summary> /// CGR05報表 /// </summary> /// <param name="ParameterList">變數清單</param> /// <returns>回傳查詢結果</returns> public DataTable VGR01_0(ArrayList ParameterList, string ReportOutputFormat, ref ReportList.ExcelOtherType EOT ) { VGRModel.MaintainReturnData bco = new VGRModel.MaintainReturnData(ConntionDB); DataTable Dt = bco.GetPrintRpt01Detl(ParameterList); if (Dt.Rows.Count == 0) { throw new Exception("查無資料"); } else { //取得筆數資料,筆數未滿10的倍數,塞假資料補成10的倍數(因為套表是10筆1張) int j = Dt.Rows.Count % 10; if (j != 0) { for (int i = 0; i < 10 - j; i++) { DataRow drNew = Dt.NewRow(); drNew["Item"] = "XXXXXXXXXX"; //只要ITEM是XXXXXXXXXX就抑制顯示 drNew["Item_Name"] = ""; drNew["Period"] = ""; drNew["Return_Qty"] = 0; drNew["Price"] = 0; drNew["Cost"] = 0; Dt.Rows.Add(drNew); } } return Dt; } }
/// <summary> /// 利用 CrystalReport 列印 Excel 報表 /// </summary> /// <param name="s_FileName">Excel報表的檔名</param> /// <param name="s_rptFilePath">rpt檔的路徑</param> /// <param name="dt_Source">要列印的資料</param> /// /// <param name="reportFormatType">檔案型態</param> private void LoadCrystalReport(string s_FileName, string s_rptFilePath, string reportFormatType) { try { VGRModel.MaintainReturnData BCOVGR = new VGRModel.MaintainReturnData(ConntionDB); CrystalDecisions.CrystalReports.Engine.ReportDocument report = new CrystalDecisions.CrystalReports.Engine.ReportDocument(); report.Load(s_rptFilePath); //report.Load(Server.MapPath("./REPORT/VGR01/VGR01R01.rptt")); ArrayList DBParameterList = new ArrayList(); DBParameterList.Add(hiddenID.Value); DataTable dtResult = BCOVGR.GetPrintRpt01Detl(DBParameterList); int j = dtResult.Rows.Count % 10; if (j != 0) { for (int i = 0; i < 10 - j ; i++) { DataRow drNew = dtResult.NewRow(); drNew["Item"] = "XXXXXXXXXX"; drNew["Item_Name"] = ""; drNew["Period"] = ""; drNew["Return_Qty"]=0; drNew["Price"]=0; drNew["Cost"] = 0; dtResult.Rows.Add(drNew); } } report.SetDataSource(dtResult); DataTable dtMainData = BCOVGR.GetPrintRpt01Main(Request.QueryString["ID"].ToString()); if (dtMainData.Rows.Count > 0) { report.SetParameterValue("paraBusiness_Contact1", dtMainData.Rows[0]["Business_Contact"].ToString()); report.SetParameterValue("paraBusiness_Fax", dtMainData.Rows[0]["Business_Fax"].ToString()); report.SetParameterValue("paraReturn_Date", dtMainData.Rows[0]["Return_Date"].ToString()); report.SetParameterValue("paraVendor_Name", dtMainData.Rows[0]["Vendor_Name"].ToString()); report.SetParameterValue("paraVendor", dtMainData.Rows[0]["Vendor"].ToString()); report.SetParameterValue("paraReturn_No", dtMainData.Rows[0]["Return_No"].ToString()); report.SetParameterValue("paraTax_Total_Amt", dtMainData.Rows[0]["Tax_Total_Amt"].ToString()); report.SetParameterValue("paraUnTax_Total_Amt", dtMainData.Rows[0]["UnTax_Total_Amt"].ToString()); report.SetParameterValue("paraTax_Amt", dtMainData.Rows[0]["Tax_Amt"].ToString()); //ParameterFields par1 = new ParameterFields(); //AddParameter("paraBusiness_Contact1", dtMainData.Rows[0]["Business_Contact1"].ToString(), par1); //ParameterFields par2 = new ParameterFields(); //AddParameter("paraBusiness_Fax", dtMainData.Rows[0]["Business_Fax"].ToString(), par2); //ParameterFields par3 = new ParameterFields(); //AddParameter("paraReturn_Date", dtMainData.Rows[0]["Return_Date"].ToString(), par3); //ParameterFields par4 = new ParameterFields(); //AddParameter("paraVendor_Name", dtMainData.Rows[0]["Vendor_Name"].ToString(), par4); //ParameterFields par5 = new ParameterFields(); //AddParameter("paraVendor", dtMainData.Rows[0]["Vendor"].ToString(), par5); //ParameterFields par6 = new ParameterFields(); //AddParameter("paraReturn_No", dtMainData.Rows[0]["Return_No"].ToString(), par6); //ParameterFields par7 = new ParameterFields(); //AddParameter("paraTax_Total_Amt", dtMainData.Rows[0]["Tax_Total_Amt"].ToString(), par7); //ParameterFields par8 = new ParameterFields(); //AddParameter("paraUnTax_Total_Amt", dtMainData.Rows[0]["UnTax_Total_Amt"].ToString(), par8); //ParameterFields par9 = new ParameterFields(); //AddParameter("paraTax_Amt", dtMainData.Rows[0]["Tax_Amt"].ToString(), par9); } else { string strErr = "查無資料"; this.ErrorMsgLabel.Text = strErr; return; } switch (reportFormatType) { case "EXCEL": System.IO.Stream streamXLS = report.ExportToStream(CrystalDecisions.Shared.ExportFormatType.Excel); byte[] bytesXLS = new byte[streamXLS.Length]; streamXLS.Read(bytesXLS, 0, bytesXLS.Length); streamXLS.Seek(0, System.IO.SeekOrigin.Begin); //export file Response.ClearContent(); Response.ClearHeaders(); Response.AddHeader("content-disposition", "attachment;filename=" + s_FileName);//excel檔名 Response.ContentType = "application/vnd.ms-excel"; Response.OutputStream.Write(bytesXLS, 0, bytesXLS.Length); Response.Flush(); Response.Close(); break; case "PDF": System.IO.Stream streamPDF = report.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat); byte[] bytesPDF = new byte[streamPDF.Length]; streamPDF.Read(bytesPDF, 0, bytesPDF.Length); streamPDF.Seek(0, System.IO.SeekOrigin.Begin); //export file Response.ClearContent(); Response.ClearHeaders(); Response.AddHeader("content-disposition", "attachment;filename=" + s_FileName);//excel檔名 Response.ContentType = "application/pdf"; Response.OutputStream.Write(bytesPDF, 0, bytesPDF.Length); Response.Flush(); Response.Close(); break; default: break; } report.Close(); } catch (Exception ex) { ErrorMsgLabel.Text = ex.Message; } }
private void ShowReport() { try { VGRModel.MaintainReturnData BCOVGR = new VGRModel.MaintainReturnData(ConntionDB); ReportDocument report = new ReportDocument(); report.Load(Server.MapPath("./REPORT/VGR01/VGR01R01.rpt")); ArrayList DBParameterList = new ArrayList(); DBParameterList.Add(Request.QueryString["ID"].ToString()); DataTable dtResult = BCOVGR.GetPrintRpt01Detl(DBParameterList); report.SetDataSource(dtResult); DataTable dtMainData = BCOVGR.GetPrintRpt01Main(Request.QueryString["ID"].ToString()); if (dtMainData.Rows.Count > 0) { ParameterFields par1 = new ParameterFields(); AddParameter("paraBusiness_Contact1", dtMainData.Rows[0]["Business_Contact"].ToString(),par1); ParameterFields par2 = new ParameterFields(); AddParameter("paraBusiness_Fax", dtMainData.Rows[0]["Business_Fax"].ToString(), par2); ParameterFields par3 = new ParameterFields(); AddParameter("paraReturn_Date", dtMainData.Rows[0]["Return_Date"].ToString(), par3); ParameterFields par4 = new ParameterFields(); AddParameter("paraVendor_Name", dtMainData.Rows[0]["Vendor_Name"].ToString(), par4); ParameterFields par5 = new ParameterFields(); AddParameter("paraVendor", dtMainData.Rows[0]["Vendor"].ToString(), par5); ParameterFields par6 = new ParameterFields(); AddParameter("paraReturn_No", dtMainData.Rows[0]["Return_No"].ToString(), par6); ParameterFields par7 = new ParameterFields(); AddParameter("paraTax_Total_Amt", dtMainData.Rows[0]["Tax_Total_Amt"].ToString(), par7); ParameterFields par8 = new ParameterFields(); AddParameter("paraUnTax_Total_Amt", dtMainData.Rows[0]["UnTax_Total_Amt"].ToString(), par8); ParameterFields par9 = new ParameterFields(); AddParameter("paraTax_Amt", dtMainData.Rows[0]["Tax_Amt"].ToString(), par9); //this.CryView.ReportSource = null; //this.CryView.ParameterFieldInfo.Add(par1[0]); //this.CryView.ParameterFieldInfo.Add(par2[0]); //this.CryView.ParameterFieldInfo.Add(par3[0]); //this.CryView.ParameterFieldInfo.Add(par4[0]); //this.CryView.ParameterFieldInfo.Add(par5[0]); //this.CryView.ParameterFieldInfo.Add(par6[0]); //this.CryView.ParameterFieldInfo.Add(par7[0]); //this.CryView.ParameterFieldInfo.Add(par8[0]); //this.CryView.ParameterFieldInfo.Add(par9[0]); //this.CryView.ReportSource = report; } else { string strErr = "尚未更新資料,請先更新資料"; ScriptManager.RegisterStartupScript(this.UpdatePanel1, typeof(UpdatePanel), "VGR012", "alert('" + strErr + "');", true); return; } } catch (Exception ex) { ErrorMsgLabel.Text = ex.Message; } }