/// <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 bindMain() { try { if (this.hid_Page_Status.Value == "VIEW")//Model:檢視 { VGRModel.MaintainReturnData BCOVGR = new VGRModel.MaintainReturnData(ConntionDB); //將報表列印所需要的報表欄位參數加入HiddenField DataTable dtHidField = BCOVGR.GetPrintRpt01Main(Request.QueryString["ID"].ToString()); if (dtHidField.Rows.Count > 0) { this.hidContract.Value=dtHidField.Rows[0]["Business_Contact"].ToString(); this.hidFax.Value = dtHidField.Rows[0]["Business_Fax"].ToString(); this.hidReturnDate.Value = dtHidField.Rows[0]["Return_Date"].ToString(); this.hid_Tax_Total_Amt.Value = dtHidField.Rows[0]["Tax_Total_Amt"].ToString(); this.hid_UnTax_Total_Amt.Value = dtHidField.Rows[0]["UnTax_Total_Amt"].ToString(); this.hid_Tax_Amt.Value = dtHidField.Rows[0]["Tax_Amt"].ToString(); } DataTable dtResult = BCOVGR.QueryMainByID(Request.QueryString["ID"].ToString()); if (dtResult.Rows.Count == 1) { this.txtRemoveNo.Text = dtResult.Rows[0]["return_no"].ToString(); this.txtAdjNo.Text = dtResult.Rows[0]["adjust_no"].ToString(); this.txtSum.Text = dtResult.Rows[0]["sum_qty"].ToString(); this.SLP_Date.Text = dtResult.Rows[0]["return_date"].ToString(); this.SLP_Vendor.Text = dtResult.Rows[0]["vendor"].ToString(); this.lblCretaeDate.Text = dtResult.Rows[0]["createdate"].ToString(); this.SLP_CUser.Text = dtResult.Rows[0]["createuid"].ToString(); this.lblMaintainDate.Text = dtResult.Rows[0]["UpdateDate"].ToString(); this.SLP_MUser.Text = dtResult.Rows[0]["updateuid"].ToString(); this.hid_UpdateTime.Value = dtResult.Rows[0]["UpdateTime"].ToString(); VGRModel.GetSysData BCOSysData = new VGRModel.GetSysData(ConntionDB); string Apl_Date = BCOSysData.GetBUSDate(); if (Apl_Date == string.Empty) { ScriptManager.RegisterStartupScript(this.UpdatePanel1, typeof(UpdatePanel), "VGR01", "alert('未取得檢核日期 ');", true); return; } string VAMClosed = BCOSysData.CheckVAMClosedYN(Apl_Date); this.btnEdit.Enabled = VAMClosed == "N"; this.btnSave.Enabled = false; this.btnCancel.Enabled = false; } else { ScriptManager.RegisterStartupScript(this.UpdatePanel1, typeof(UpdatePanel), "VGR01", "alert('無資料可供查詢 ');", true); return; } } else if (this.hid_Page_Status.Value == "UPDATE")//Model:編輯(更新) { //取得TARGET LOCATE SECTION ParameterList.Clear(); ParameterList.Add("B"); VGRModel.MaintainReturnData BCOVGR = new VGRModel.MaintainReturnData(ConntionDB); string strReturnLocateNo = ""; string strReturnLocateSection = ""; BCOVGR.QueryTargetLocate(ParameterList, out strReturnLocateNo, out strReturnLocateSection); ReturnLocateNo = strReturnLocateNo; ReturnLocateSection = strReturnLocateSection; hid_LocateSection.Value = ReturnLocateSection; if (ReturnLocateSection == string.Empty) { ClientScript.RegisterStartupScript(typeof(Page), "MessagePopUp", "alert('廠退作業尚未設定對應儲格'); window.location.href = 'VGR011.aspx';", true); } DataTable dtResult = BCOVGR.QueryMainByID(Request.QueryString["ID"].ToString()); if (dtResult.Rows.Count == 1) { this.txtRemoveNo.Text = dtResult.Rows[0]["return_no"].ToString(); this.txtAdjNo.Text = dtResult.Rows[0]["adjust_no"].ToString(); this.txtSum.Text = dtResult.Rows[0]["sum_qty"].ToString(); this.SLP_Date.Text = dtResult.Rows[0]["return_date"].ToString(); this.SLP_Vendor.Text = dtResult.Rows[0]["vendor"].ToString(); this.lblCretaeDate.Text = dtResult.Rows[0]["createdate"].ToString(); this.SLP_CUser.Text = dtResult.Rows[0]["createuid"].ToString(); this.lblMaintainDate.Text = dtResult.Rows[0]["UpdateDate"].ToString(); this.SLP_MUser.Text = dtResult.Rows[0]["updateuid"].ToString(); this.hid_UpdateTime.Value = dtResult.Rows[0]["UpdateTime"].ToString(); this.btnEdit.Visible = false; this.btnAddDetail.Enabled = false; } } else if (this.hid_Page_Status.Value == "INSERT")//Model:新增 { //取得TARGET LOCATE SECTION ParameterList.Clear(); ParameterList.Add("B"); VGRModel.MaintainReturnData BCOVGR = new VGRModel.MaintainReturnData(ConntionDB); string strReturnLocateNo = ""; string strReturnLocateSection = ""; BCOVGR.QueryTargetLocate(ParameterList, out strReturnLocateNo, out strReturnLocateSection); ReturnLocateNo = strReturnLocateNo; ReturnLocateSection = strReturnLocateSection; hid_LocateSection.Value = ReturnLocateSection; if (ReturnLocateSection == string.Empty) { ClientScript.RegisterStartupScript(typeof(Page), "MessagePopUp", "alert('廠退作業尚未設定對應儲格'); window.location.href = 'VGR011.aspx';", true); } this.SLP_Date.Text = strToday; this.SLP_CDate.Text = strToday; this.SLP_CUser.Text = Session["UID"].ToString(); this.SLP_MDate.Text = strToday; this.SLP_MUser.Text = Session["UID"].ToString(); } } 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; } }