Beispiel #1
0
    protected void DataBind()
    {
        #region 傳入參數

        ParameterList.Clear();
        ParameterList.Add(txt_STATION_NO_S.Text.Trim());
        ParameterList.Add(txt_STATION_NO_E.Text.Trim());
        ParameterList.Add(rdb_INTERFLOW_LOCATE.SelectedValue);
        ParameterList.Add(rdb_SHELF.SelectedValue);
        ParameterList.Add(txt_LOCATE_NO_S.Text.Trim());
        ParameterList.Add(txt_LOCATE_NO_E.Text.Trim());
        ParameterList.Add((txt_STATION_ORDER_S.Text.Trim()==string.Empty)? 0:Convert.ToInt32(txt_STATION_ORDER_S.Text.Trim()));
        ParameterList.Add((txt_STATION_ORDER_E.Text.Trim()==string.Empty)? 99999:Convert.ToInt32(txt_STATION_ORDER_E.Text.Trim()));
        ParameterList.Add((txt_PICK_ORDER_S.Text.Trim() == string.Empty) ? 0 : Convert.ToInt32(txt_PICK_ORDER_S.Text.Trim()));
        ParameterList.Add((txt_PICK_ORDER_E.Text.Trim() == string.Empty) ? 99999 : Convert.ToInt32(txt_PICK_ORDER_E.Text.Trim()));
        ParameterList.Add((this.txt_RowCountLimit.Text == string.Empty) ? "999" : (int.Parse(this.txt_RowCountLimit.Text) < 0) ? "999" : this.txt_RowCountLimit.Text);//[筆數]

        #endregion

        #region 連結資料庫

        DataTable dt_Return = new DataTable();
        CGDModel.CGD42_BCO bco = new CGDModel.CGD42_BCO(ConntionDB);
        dt_Return = bco.QueryData(ParameterList);

        #endregion

        #region 資料與GridView繫結

        //抓取本頁初次登記的時間
        string SessionIDName = "CGD421_" + PageTimeStamp.Value;

        Session["SessionID"] = SessionIDName;
        Session[SessionIDName] = dt_Return;

        this.gv_QueryResult.DataSource = dt_Return;
        this.gv_QueryResult.PageSize = (this.txt_Pagesize.Text == string.Empty) ? 20 : (int.Parse(this.txt_Pagesize.Text) < 0) ? 20 : int.Parse(this.txt_Pagesize.Text);
        this.gv_QueryResult.PageIndex = 0;
        this.gv_QueryResult.DataBind();

        #endregion


        #region 檢查回傳資料

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

        #endregion
    
    }
Beispiel #2
0
    private void Export_Excel(ArrayList ParameterList)
    {
        try
        {

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

            DataTable dt = BCO.QueryData(ParameterList);
            if (dt.Rows.Count == 0)
            {
                lblError.Text = "查無資料";
                return;
            }
            ExcelXmlWorkbook book = new ExcelXmlWorkbook();

            Worksheet sheet0 = book[0];

            AddSheetData(ref sheet0, "sheet1", dt);

            //設定輸出檔名
            string s_FileName =
            s_FileName = HttpUtility.UrlEncode("CGD42_" + PageTimeStamp.Value + ".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.lblError.Text = ex.ToString();
        }
        finally { }
    }