Exemplo n.º 1
0
    private void Export_Txt(ArrayList ParameterList)
    {
        try
        {
            DataTable dt_Return = new DataTable();
            BCO.VAM19_BCO bco = new BCO.VAM19_BCO(ConntionDB);

            if (this.rblReportSource.SelectedValue == "4")
            {
                dt_Return = bco.QueryExportTrace_SKU(ParameterList);
            }
            else if (this.rblReportSource.SelectedValue == "5")
            {
                dt_Return = bco.QueryExportTrace_AGM(ParameterList);
            }


            if (dt_Return.Rows.Count == 0)
            {
                this.ErrorMsgLabel.Text = "查無資料";
                return;
            }
            else
            {
                StringBuilder sbData = new StringBuilder();


                foreach (DataRow dr in dt_Return.Rows)
                {
                    sbData.Append(dr[0].ToString() + "\r\n");
                }

                string strFileName = string.Empty;
                if (this.rblReportSource.SelectedValue == "5")
                    strFileName = "合約交易補收";
                else 
                    strFileName = "商品交易補收";

                byte[] buffer = System.Text.Encoding.Default.GetBytes(sbData.ToString());
                Response.ClearContent();
                Response.ClearHeaders();
                Response.AddHeader("content-disposition", "attachment;filename=" + HttpUtility.UrlEncode(strFileName + ".txt", System.Text.Encoding.UTF8));//匯出檔名  
                Response.ContentType = "application/xls";
                Response.OutputStream.Write(buffer, 0, buffer.Length);
                Response.Flush();
                Response.Close();
            }
        }
        catch (Exception ex)
        {
            this.ErrorMsgLabel.Text = ex.ToString();
        }
        finally { }
    }
Exemplo n.º 2
0
    private void Export_Excel(ArrayList ParameterList)
    {
        try
        {

            BCO.VAM19_BCO BCO = new BCO.VAM19_BCO(ConntionDB);
            // 讀取 Excel 資料    

            DataTable dt;
            if (this.rblReportSource.SelectedValue == "1")
            {
                dt = BCO.QueryExportTrace(ParameterList);
            }
            else if (this.rblReportSource.SelectedValue == "2")
            {
                dt = BCO.QueryVamAgmTrace(ParameterList);
            }
            else
            {
                dt = BCO.QueryVamSKUTrace(ParameterList);
            }

            if (dt.Rows.Count == 0)
            {
                ErrorMsgLabel.Text = "查無資料";
                return;
            }
            ExcelXmlWorkbook book = new ExcelXmlWorkbook();

            Worksheet sheet0 = book[0];

            string s_Name;


            if (this.rblReportSource.SelectedValue == "1")
            {
                s_Name = "補收帳款匯出";
                AddSheetData(ref sheet0, s_Name, dt);
            }
            else if (this.rblReportSource.SelectedValue == "2")
            {
                s_Name = "各項扣款彙總表(補收)";
                AddSheetDataTrace(ref sheet0, s_Name, dt);
            }
            else
            {
                s_Name = "商品交易補收彙總表";
                AddSheetDataTrace_SKU(ref sheet0, s_Name, dt);
            }

           

            //設定輸出檔名
            string s_FileName =
            s_FileName = HttpUtility.UrlEncode("VAM191_" + s_Name + "_" + ParameterList[0].ToString() 
            + "_" + ParameterList[1].ToString() + ".XLS", System.Text.Encoding.UTF8);

            //File download
            Response.Charset = "big5";
            Response.ContentType = "application/x-excel;charset='utf-8'";
            Response.AddHeader("content-disposition", "attachment; filename=" + s_FileName);//excel檔名
            System.IO.MemoryStream stream = new System.IO.MemoryStream();
            book.Export(stream);
            string producedExcel = GetStringFromMemoryStream(stream);
            stream.Close();
            Response.Write(producedExcel);
            Response.Flush();
            Response.End();
        }
        catch (Exception ex)
        {
            this.ErrorMsgLabel.Text = ex.ToString();
        }
        finally { }
    }
Exemplo n.º 3
0
    protected void btnExport_Click(object sender, EventArgs e)
    {
        try
        {
            this.ErrorMsgLabel.Text = "";

            ParameterList.Clear();
            ParameterList.Add(this.SLP_YearMonth1.Text.Trim());
            ParameterList.Add("");
            DataTable dt_Return = new DataTable();
            BCO.VAM19_BCO bco = new BCO.VAM19_BCO(ConntionDB);

            if (this.rdoType1.Checked)
            {
                dt_Return = bco.QueryExportFile(ParameterList);
            }
            else if (this.rdoType2.Checked)
            {
                dt_Return = bco.QuerySubsidy_TAX(ParameterList);
            }
            else if (this.rdoType6.Checked)
            {
                dt_Return = bco.QuerySubsidy_UTAX(ParameterList);
            }
            else if (this.rdoType3.Checked)
            {
                dt_Return = bco.QuerySales(ParameterList);
            }
            else if (this.rdoType4.Checked)
            {
                dt_Return = bco.QueryVdsVamSalesItem(ParameterList);
            }
            else if (this.rdoType5.Checked)
            {
                dt_Return = bco.QueryVdsVamSalesClear(ParameterList);
            }
            else if (this.rdoType7.Checked)
            {
                dt_Return = bco.QueryVdsVamSubsidy_Oil(ParameterList);
            }
            else if (this.rdoType8.Checked)
            {
                dt_Return = bco.QueryVdsVamSubsidy_Island(ParameterList);
            }
            else
            {
                this.ErrorMsgLabel.Text = "尚未選擇";
                return;
            }

            if (dt_Return.Rows.Count == 0)
            {
                this.ErrorMsgLabel.Text = "查無資料";
                return;
            }
            else
            {
                StringBuilder sbData = new StringBuilder();
                if ((rdoType1.Checked == true) || (rdoType2.Checked == true) || (rdoType6.Checked == true)||
                    (rdoType7.Checked == true) || (rdoType8.Checked == true))
                {
                    foreach (DataRow dr in dt_Return.Rows)
                    {
                        sbData.Append(dr[0].ToString() + "\r\n");
                    }
                }
                else
                {
                    foreach (DataRow dr in dt_Return.Rows)
                    {
                        if (sbData.Length > 0)
                            sbData.Append("\r\n");
                        sbData.Append(dr[0].ToString() + "," + dr[1].ToString() + "," + dr[2].ToString() + "," + dr[3].ToString());
                    }
                }

                string strFileName = string.Empty;
                if (rdoType1.Checked == true)
                    strFileName = "一般月結帳款";
                else if (this.rdoType2.Checked)
                    strFileName = "轉出折扣補貼(應稅)";
                else if (this.rdoType6.Checked)
                    strFileName = "轉出折扣補貼(免稅)";
                else if (this.rdoType3.Checked)
                    strFileName = SLP_YearMonth1.Text.Trim() + "單品結帳付款檔";
                else if (this.rdoType4.Checked)
                    strFileName = SLP_YearMonth1.Text.Trim() + "實銷結帳付款檔";
                else if (this.rdoType5.Checked)
                    strFileName = SLP_YearMonth1.Text.Trim() + "實銷結帳-結清付款檔";
                else if (this.rdoType7.Checked)
                    strFileName = SLP_YearMonth1.Text.Trim() + "-油價補貼";
                else if (this.rdoType8.Checked)
                    strFileName = SLP_YearMonth1.Text.Trim() + "-離島配送費";
                
                byte[] buffer = System.Text.Encoding.Default.GetBytes(sbData.ToString());
                Response.ClearContent();
                Response.ClearHeaders();
                Response.AddHeader("content-disposition", "attachment;filename=" + HttpUtility.UrlEncode(strFileName + ".txt", System.Text.Encoding.UTF8));//匯出檔名  
                Response.ContentType = "application/xls";
                Response.OutputStream.Write(buffer, 0, buffer.Length);
                Response.Flush();
                Response.Close();
            }
        }
        catch (Exception ex)
        {
            this.ErrorMsgLabel.Text = ex.ToString();
        }
        finally { }
    }