Esempio n. 1
0
    /// <summary>
    /// 利用 CrystalReport 列印報表
    /// </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, DataTable dt_Source, string reportFormatType)
    {
        CrystalDecisions.CrystalReports.Engine.ReportDocument report = new CrystalDecisions.CrystalReports.Engine.ReportDocument();

        report.Load(s_rptFilePath);
        report.SetDataSource(dt_Source);


        #region 取得各輸入值

        string s_par_Program_ID = string.Empty;
        string s_par_LoginUser = string.Empty;
        string s_par_ST_Accept_Date = string.Empty;
        string s_par_Trans_No_S = string.Empty;
        string s_par_Trans_No_E = string.Empty;
        string s_par_Trans_Vendor_S = string.Empty;
        string s_par_Trans_Vendor_E = string.Empty;
        string s_par_Route_S = string.Empty;
        string s_par_Route_E = string.Empty;
        string s_par_StoreChain_S = string.Empty;
        string s_par_StoreChain_E = string.Empty;
        string s_par_Note = string.Empty;


        s_par_Program_ID = this.PageCode;
        s_par_LoginUser = Session["UID"].ToString();
        s_par_ST_Accept_Date = SLP_SLPDate.Text;
        s_par_Trans_No_S = SLP_Trans_No_S.Text + " " + ((DropDownList)SLP_Trans_No_S.FindControl("D1")).SelectedItem.Text;
        s_par_Trans_No_E = SLP_Trans_No_E.Text + " " + ((DropDownList)SLP_Trans_No_E.FindControl("D1")).SelectedItem.Text;
        s_par_Trans_Vendor_S = SLP_Trans_Vendor_S.Text + " " + ((DropDownList)SLP_Trans_Vendor_S.FindControl("D1")).SelectedItem.Text;
        s_par_Trans_Vendor_E = SLP_Trans_Vendor_E.Text + " " + ((DropDownList)SLP_Trans_Vendor_E.FindControl("D1")).SelectedItem.Text;

        if (((TextBox)SLP_Route_S.FindControl("TextBoxCode")).Text != "")
        {
            s_par_Route_S = ((TextBox)SLP_Route_S.FindControl("TextBoxCode")).Text + " " + Request[SLP_Route_S.TextBox_Name.UniqueID].ToString();
        }
        else
        {
            s_par_Route_S = "";
        }

        if (((TextBox)SLP_Route_E.FindControl("TextBoxCode")).Text != "")
        {
            s_par_Route_E = ((TextBox)SLP_Route_E.FindControl("TextBoxCode")).Text + " " + Request[SLP_Route_E.TextBox_Name.UniqueID].ToString();
        }
        else
        {
            s_par_Route_E = "";
        }

        if (((TextBox)SLP_StoreChain_S.FindControl("TextBoxCode")).Text != "")
        {
            s_par_StoreChain_S = ((TextBox)SLP_StoreChain_S.FindControl("TextBoxCode")).Text + " " + Request[SLP_StoreChain_S.TextBox_Name.UniqueID].ToString();
        }
        else
        {
            s_par_StoreChain_S = "";
        }

        if (((TextBox)SLP_StoreChain_E.FindControl("TextBoxCode")).Text != "")
        {
            s_par_StoreChain_E = ((TextBox)SLP_StoreChain_E.FindControl("TextBoxCode")).Text + " " + Request[SLP_StoreChain_E.TextBox_Name.UniqueID].ToString();
        }
        else
        {
            s_par_StoreChain_E = "";
        }


        BCO.PrintTransAndDriver bco = new BCO.PrintTransAndDriver(ConntionDB);

        DataTable Dt = null;

        ParameterList.Clear();
        ParameterList.Add(SLP_SLPDate.Text.Trim());

        Dt = bco.GetMessage(ParameterList);

        if (Dt.Rows.Count != 0)
            s_par_Note = Dt.Rows[0]["MESSAGE"].ToString();

        report.SetParameterValue("par_Program_ID", s_par_Program_ID);
        report.SetParameterValue("par_LoginUser", s_par_LoginUser);
        report.SetParameterValue("par_ST_Accept_Date", s_par_ST_Accept_Date);
        report.SetParameterValue("par_Trans_No", s_par_Trans_No_S + " ~ " + s_par_Trans_No_E);
        report.SetParameterValue("par_Trans_Vendor", s_par_Trans_Vendor_S + " ~ " + s_par_Trans_Vendor_E);
        report.SetParameterValue("par_Routee", s_par_Route_S + " ~ " + s_par_Route_E);
        report.SetParameterValue("par_StoreChain", s_par_StoreChain_S + " ~ " + s_par_StoreChain_E);
        report.SetParameterValue("par_Note", s_par_Note);

        #endregion


        #region 判斷輸出檔案型態並輸出


        switch (reportFormatType)
        {
            case "EXCEL":

                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;


        #endregion

        }

        report.Close();

    }
Esempio n. 2
0
    public static string SendReportMessage(string SLP_SLPDateControl,
                                           string PrintType,//1 單品多包裝-轉運聯繫單 2 單品多包裝-配送參閱明細表
                                           string DataSource,//1 橫列格式 2 直列格式
                                           string DataSource2,//1 原始版本 2 圖漫箱單統計
                                           string SLP_Trans_No_SControl,
                                           string SLP_Trans_No_EControl,
                                           string SLP_Trans_Vendor_SControl,
                                           string SLP_Trans_Vendor_EControl,
                                           string SLP_Route_SControl,
                                           string SLP_Route_EControl,
                                           string SLP_StoreChain_SControl,
                                           string SLP_StoreChain_EControl,
                                           string N_SLP_Trans_No_SControl,
                                           string N_SLP_Trans_No_EControl,
                                           string N_SLP_Trans_Vendor_SControl,
                                           string N_SLP_Trans_Vendor_EControl,
                                           string N_SLP_Route_SControl,
                                           string N_SLP_Route_EControl,
                                           string N_SLP_StoreChain_SControl,
                                           string N_SLP_StoreChain_EControl,
                                           string UserIdControl,
                                           string src  //src:1->匯出、2->列印
                                           )
    {
        string ReportCode = string.Empty;
        TRN_TRN071 TRNRPTPage = new TRN_TRN071();
        string ProcessLogFile = string.Empty;
        string strStatus = string.Empty;

        ReportParameter[] DBParameter = new ReportParameter[9];
        ReportParameter[] CryReportParameter = new ReportParameter[8];

        string strFileName = string.Empty;
        string s_par_Note = string.Empty;

        #region

        BCO.PrintTransAndDriver bco = new BCO.PrintTransAndDriver(ConntionDB);

        DataTable Dt = null;

        ParameterList.Clear();
        ParameterList.Add(SLP_SLPDateControl);

        Dt = bco.GetMessage(ParameterList);

        if (Dt.Rows.Count != 0)
            s_par_Note = Dt.Rows[0]["MESSAGE"].ToString();

        #endregion

        //DB需要的變數
        DBParameter[0].ParameterName = "門市進貨日";
        DBParameter[0].ParameterValue = SLP_SLPDateControl;
        DBParameter[1].ParameterName = "轉運站(起)";
        DBParameter[1].ParameterValue = SLP_Trans_No_SControl;
        DBParameter[2].ParameterName = "轉運站(迄)";
        DBParameter[2].ParameterValue = SLP_Trans_No_EControl;
        DBParameter[3].ParameterName = "區配商(起)";
        DBParameter[3].ParameterValue = SLP_Trans_Vendor_SControl;
        DBParameter[4].ParameterName = "區配商(迄)";
        DBParameter[4].ParameterValue = SLP_Trans_Vendor_EControl;
        DBParameter[5].ParameterName = "路線(起)";
        DBParameter[5].ParameterValue = SLP_Route_SControl;
        DBParameter[6].ParameterName = "路線(迄)";
        DBParameter[6].ParameterValue = SLP_Route_EControl;
        DBParameter[7].ParameterName = "通路(起)";
        DBParameter[7].ParameterValue = SLP_StoreChain_SControl;
        DBParameter[8].ParameterName = "通路(迄)";
        DBParameter[8].ParameterValue = SLP_StoreChain_EControl;

        //報表變數 送出產生報表
        CryReportParameter[0].ParameterName = "par_Program_ID";
        CryReportParameter[0].ParameterValue = "TRN071";
        CryReportParameter[1].ParameterName = "par_LoginUser";
        CryReportParameter[1].ParameterValue = UserIdControl;
        CryReportParameter[2].ParameterName = "par_ST_Accept_Date";
        CryReportParameter[2].ParameterValue = SLP_SLPDateControl;
        CryReportParameter[3].ParameterName = "par_Trans_No";
        CryReportParameter[3].ParameterValue = N_SLP_Trans_No_SControl + " ~ " + N_SLP_Trans_No_EControl;
        CryReportParameter[4].ParameterName = "par_Trans_Vendor";
        CryReportParameter[4].ParameterValue = N_SLP_Trans_Vendor_SControl + " ~ " + N_SLP_Trans_Vendor_EControl;
        CryReportParameter[5].ParameterName = "par_Routee";
        CryReportParameter[5].ParameterValue = N_SLP_Route_SControl + " ~ " + N_SLP_Route_EControl;
        CryReportParameter[6].ParameterName = "par_StoreChain";
        CryReportParameter[6].ParameterValue = N_SLP_StoreChain_SControl + " ~ " + N_SLP_StoreChain_EControl;
        CryReportParameter[7].ParameterName = "par_Note";
        CryReportParameter[7].ParameterValue = s_par_Note;

        switch (src)
        {
            case "1"://匯出
                switch (PrintType)
                {
                    #region 單品多包裝-轉運聯繫單

                    case "1"://單品多包裝-轉運聯繫單
                        if (DataSource2 == "2")
                            ReportCode = "TRN07_4";
                        else
                            ReportCode = "TRN07_1";
                        strFileName = "單品多包裝-轉運聯繫單";

                        TRNRPTPage.GenerReportConfigXML("TRN",
                                "TRN071.aspx",
                                ReportCode,
                                TRNRPTPage.Server.MapPath("REPORT\\TRN071\\TRN071_Export_1.rpt"),
                                DBParameter,
                                CryReportParameter,
                                ReportOutputFormat.EXCEL,
                                strFileName,
                                ref ProcessLogFile
                                );
                        break;
                    #endregion

                    #region 單品多包裝-配送參閱明細表

                    case "2"://單品多包裝-配送參閱明細表
                        if (DataSource2 == "2")
                            ReportCode = "TRN07_5";
                        else
                            ReportCode = "TRN07_2";
                        strFileName = "單品多包裝-配送參閱明細表";

                        TRNRPTPage.GenerReportConfigXML("TRN",
                                "TRN071.aspx",
                                ReportCode,
                                TRNRPTPage.Server.MapPath("REPORT\\TRN071\\TRN071_Export_2.rpt"),
                                DBParameter,
                                CryReportParameter,
                                ReportOutputFormat.EXCEL,
                                strFileName,
                                ref ProcessLogFile
                                );
                        break;

                    #endregion

                    #region 圖書館配送參閱明細表

                    case "3"://圖書館配送參閱明細表
                        ReportCode = "TRN07_3";
                        strFileName = "圖書館配送參閱明細表";

                        TRNRPTPage.GenerReportConfigXML("TRN",
                                "TRN071.aspx",
                                ReportCode,
                                TRNRPTPage.Server.MapPath("REPORT\\TRN071\\TRN071_Export_3.rpt"),
                                DBParameter,
                                CryReportParameter,
                                ReportOutputFormat.EXCEL,
                                strFileName,
                                ref ProcessLogFile
                                );
                        break;

                    #endregion


                }
                break;
            case "2"://列印明細表
                switch (PrintType)
                {
                    #region 單品多包裝-轉運聯繫單

                    case "1"://單品多包裝-轉運聯繫單
                        switch (DataSource)
                        {
                            case "1":
                                if (DataSource2 == "2")
                                    ReportCode = "TRN07_4";
                                else
                                    ReportCode = "TRN07_1";
                                strFileName = "單品多包裝-轉運聯繫單";

                                TRNRPTPage.GenerReportConfigXML("TRN",
                                 "TRN071.aspx",
                                 ReportCode,
                                 TRNRPTPage.Server.MapPath("REPORT\\TRN071\\TRN071_Trans_1.rpt"),
                                 DBParameter,
                                 CryReportParameter,
                                 ReportOutputFormat.PDF,
                                 strFileName,
                                 ref ProcessLogFile
                                 );
                                break;
                            case "2":
                                if (DataSource2 == "2")
                                    ReportCode = "TRN07_4";
                                else
                                    ReportCode = "TRN07_1";
                                strFileName = "單品多包裝-轉運聯繫單";

                                TRNRPTPage.GenerReportConfigXML("TRN",
                                 "TRN071.aspx",
                                 ReportCode,
                                 TRNRPTPage.Server.MapPath("REPORT\\TRN071\\TRN071_Trans_2.rpt"),
                                 DBParameter,
                                 CryReportParameter,
                                 ReportOutputFormat.PDF,
                                 strFileName,
                                 ref ProcessLogFile
                                 );
                                break;
                        }
                        break;
                    #endregion

                    #region 單品多包裝-配送參閱明細表

                    case "2"://單品多包裝-配送參閱明細表
                        switch (DataSource)
                        {
                            case "1":
                                if (DataSource2 == "2")
                                    ReportCode = "TRN07_5";
                                else
                                    ReportCode = "TRN07_2";
                                strFileName = "單品多包裝-配送參閱明細表";

                                TRNRPTPage.GenerReportConfigXML("TRN",
                                 "TRN071.aspx",
                                 ReportCode,
                                 TRNRPTPage.Server.MapPath("REPORT\\TRN071\\TRN071_Driver_1.rpt"),
                                 DBParameter,
                                 CryReportParameter,
                                 ReportOutputFormat.PDF,
                                 strFileName,
                                 ref ProcessLogFile
                                 );
                                break;
                            case "2":
                                if (DataSource2 == "2")
                                    ReportCode = "TRN07_5";
                                else
                                    ReportCode = "TRN07_2";
                                strFileName = "單品多包裝-配送參閱明細表";

                                TRNRPTPage.GenerReportConfigXML("TRN",
                                 "TRN071.aspx",
                                 ReportCode,
                                 TRNRPTPage.Server.MapPath("REPORT\\TRN071\\TRN071_Driver_2.rpt"),
                                 DBParameter,
                                 CryReportParameter,
                                 ReportOutputFormat.PDF,
                                 strFileName,
                                 ref ProcessLogFile
                                 );
                                break;
                        }
                        break;

                    #endregion

                    #region 圖書館配送參閱明細表

                    case "3"://圖書館配送參閱明細表
                        ReportCode = "TRN07_3";
                        strFileName = "圖書館配送參閱明細表";

                        TRNRPTPage.GenerReportConfigXML("TRN",
                         "TRN071.aspx",
                         ReportCode,
                         TRNRPTPage.Server.MapPath("REPORT\\TRN071\\TRN071_Library_1.rpt"),
                         DBParameter,
                         CryReportParameter,
                         ReportOutputFormat.PDF,
                         strFileName,
                         ref ProcessLogFile
                         );
                        break;

                    #endregion

                }
                break;
        }

        TRNRPTPage.Dispose();

        return ProcessLogFile;
    }
Esempio n. 3
0
    /// <summary>
    /// 注意事項維護鈕
    /// </summary>
    protected void Btn_Note_Click(object sender, EventArgs e)
    {
        //讀取該門市進貨日的注意事項
        BCO.PrintTransAndDriver bco = new BCO.PrintTransAndDriver(ConntionDB);

        DataTable Dt = null;

        ParameterList.Clear();
        ParameterList.Add(SLP_SLPDate.Text.Trim());

        Dt = bco.GetMessage(ParameterList);

        if (Dt.Rows.Count != 0)
            txtNote.Text = Dt.Rows[0]["MESSAGE"].ToString();


        //關閉上方各控制項
        SLP_SLPDate.ReadOnly = true;
        rblPrintType.Enabled = false;
        rblDataSource.Enabled = false;
        rblDataSource2.Enabled = false;
        SLP_Trans_No_S.ReadOnly = true;
        SLP_Trans_No_E.ReadOnly = true;
        SLP_Trans_Vendor_S.ReadOnly = true;
        SLP_Trans_Vendor_E.ReadOnly = true;
        SLP_Route_S.ReadOnly = true;
        SLP_Route_E.ReadOnly = true;
        SLP_StoreChain_S.ReadOnly = true;
        SLP_StoreChain_E.ReadOnly = true;
        Btn_Print.Enabled = false;
        Btn_Export.Enabled = false;
        Btn_Note.Enabled = false;

        //開啟注意事項視窗
        panel_Note.Visible = true;
    }