Example #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
    
    }
Example #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 { }
    }
Example #3
0
    private void ClientFileToServerTemp()
    {
        string s_AP_FileName;
        ErrorMsgLabel.Text = "";
        if (FileUpload1.FileName != "")
        {
            try
            {
                //設定頁面狀態
                this.ErrorMsgLabel.Text = "";

                string s_UploadPath = string.Empty;
                string s_BackPath = string.Empty;

                ArrayList arl_FileUpload_Return = null;
                ArrayList arl_FileToTmp_Return = null;
                System.Text.StringBuilder sb = new System.Text.StringBuilder();
                CGDModel.CGD42_BCO BCO = new CGDModel.CGD42_BCO(ConntionDB);

                //上傳檔案到AP端
                //取得要上傳的路徑
                s_UploadPath = Server.MapPath("..\\") + System.Configuration.ConfigurationManager.AppSettings["UploadPath"] + "\\CGD\\";

                string strOrg_FileName = FileUpload1.FileName;//原始的檔名

                arl_FileUpload_Return = BCO.FileUpload(s_UploadPath, this.FileUpload1, Session["UID"].ToString());


                if (arl_FileUpload_Return[0].ToString() == "FALSE")//檔案上傳至AP端錯誤
                {
                    sb.Append("檔案上傳至AP端錯誤<br/>");

                    this.ErrorMsgLabel.Text = sb.ToString();

                    //清空 UploadStatusPanel 的值

                    //上傳結果
                    this.UploadStatusPanel1.UploadSum = 0;
                    this.UploadStatusPanel1.UploadOK = 0;
                    this.UploadStatusPanel1.UploadNG = 0;

                    //匯入結果
                    this.UploadStatusPanel1.ImportSum = 0;
                    this.UploadStatusPanel1.ImportOK = 0;
                    this.UploadStatusPanel1.ImportNG = 0;

                    return;
                }
                else if (arl_FileUpload_Return[0].ToString() == "TRUE")//檔案上傳至AP端正常
                {
                    // 讀取 Excel 資料
                    OleDbConnection oleConnection = null;
                    DataSet ds_Excel = new DataSet();

                    try
                    {
                        String connString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + arl_FileUpload_Return[1].ToString() + ";Extended Properties='Excel 8.0;HDR=Yes;IMEX=1;'";
                        oleConnection = new OleDbConnection(connString);
                        oleConnection.Open();
                        OleDbCommand oleCommand = new OleDbCommand("SELECT * FROM [Sheet1$]", oleConnection);
                        OleDbDataAdapter oleAdapter = new OleDbDataAdapter(oleCommand);
                        oleAdapter.Fill(ds_Excel);

                        //請注意如果EXCEL檔欄位有值,但到DB卻沒有資料
                        //請修改,機碼 HKEY_LOCAL_MACHINE\Software\Microsoft\Jet\4.0\Engines\Excel\TypeGuessRows 值
                        //預設是 8, 表示會先讀取前 8 列來決定每一個欄位的型態, 所以如果前 8 列的資料都是數字, 到了第 9 列以後出現的文字資料都會變成 null
                        //如果要解決這個問題, 只要把 TypeGuessRows 機碼值改成 0

                    }
                    catch (Exception ex)
                    {
                        this.ErrorMsgLabel.Text = ex.Message;
                    }
                    finally
                    {
                        if (oleConnection != null)
                        {
                            oleConnection.Close();
                            oleConnection.Dispose();
                        }
                    }

                    //將檔案匯入TmpTable
                    DateTime d_CreateDate = Convert.ToDateTime(arl_FileUpload_Return[2]);
                    s_AP_FileName = string.Empty;
                    s_AP_FileName = arl_FileUpload_Return[3].ToString();

                    arl_FileToTmp_Return = BCO.FileToTmp(ds_Excel, d_CreateDate, Session["UID"].ToString(), ConntionDB, strOrg_FileName);


                    if (arl_FileToTmp_Return[0].ToString() == "FALSE")
                    {
                        ErrorMsgLabel.Text = arl_FileToTmp_Return[1].ToString();
                        this.btn_Temp_To_DB.Enabled = false;
                    }
                    else if (arl_FileToTmp_Return[0].ToString() == "TRUE")
                    {
                        // 將資料從 UploadPath 移至 BackPath
                        s_BackPath = Server.MapPath("..\\") + System.Configuration.ConfigurationManager.AppSettings["BackPath"] + "\\CAA\\";

                        // 檢查檔案路徑是否存在,如不存在新增相關路徑
                        if (Directory.Exists(s_BackPath) == false)
                        {
                            try
                            {
                                Directory.CreateDirectory(s_BackPath);
                            }
                            catch (Exception except)
                            {
                                throw new System.Exception(String.Format("不能建立文件目錄{0},錯誤訊息為{1}", s_BackPath, except.Message));
                            }
                        }

                        s_UploadPath += s_AP_FileName;
                        s_BackPath += s_AP_FileName;
                        System.IO.File.Copy(s_UploadPath, s_BackPath);
                        System.IO.File.Delete(s_UploadPath);

                        this.btn_Temp_To_DB.Enabled = false;
                        this.btn_Unusual_Report.Enabled = false;

                        // 將結果顯示在 UploadStatusPanel 中
                        //上傳結果
                        this.UploadStatusPanel1.UploadSum = ((int)arl_FileToTmp_Return[1]);
                        this.UploadStatusPanel1.UploadOK = ((int)arl_FileToTmp_Return[2]);
                        this.UploadStatusPanel1.UploadNG = ((int)arl_FileToTmp_Return[3]);
                        if ((int)arl_FileToTmp_Return[1] == 0)
                        {
                            ErrorMsgLabel.Text = "[匯入]失敗,請檢查匯入檔案是否為空檔!";
                            this.btn_Temp_To_DB.Enabled = false;
                            this.btn_Unusual_Report.Enabled = false;
                        }
                        else if ((int)arl_FileToTmp_Return[1] == (int)arl_FileToTmp_Return[2])
                        {
                            ErrorMsgLabel.Text = "[匯入]成功,請繼續[執行匯入]的功能。";
                            this.btn_Temp_To_DB.Enabled = true;
                            this.btn_Unusual_Report.Enabled = false;
                        }
                        else if ((int)arl_FileToTmp_Return[1] != (int)arl_FileToTmp_Return[2])
                        {
                            ErrorMsgLabel.Text = "[匯入]失敗,請檢視異常!";
                            this.btn_Temp_To_DB.Enabled = false;
                            this.btn_Unusual_Report.Enabled = true;
                        }
                    }

                }

            }
            catch (Exception ex)
            {
                this.ErrorMsgLabel.Text = ex.Message;
            }
        }
    }
Example #4
0
    private void TempDataToDataBase()
    {
        #region
        ErrorMsgLabel.Text = "";
        try
        {
            ArrayList arl_Return = null;

            CGDModel.CGD42_BCO BCO = new CGDModel.CGD42_BCO(ConntionDB);

            arl_Return = BCO.TmpToDB(Session["UID"].ToString(), ConntionDB);

            if (arl_Return[0].ToString() == "TRUE")
            {
                #region 設定 UploadStatusPanel 的值
                //上傳結果
                //this.UploadStatusPanel1.UploadSum = 0;
                //this.UploadStatusPanel1.UploadOK = 0;
                //this.UploadStatusPanel1.UploadNG = 0;
                //匯入結果
                this.UploadStatusPanel1.ImportSum = int.Parse(arl_Return[1].ToString());
                this.UploadStatusPanel1.ImportOK = int.Parse(arl_Return[2].ToString());
                this.UploadStatusPanel1.ImportNG = int.Parse(arl_Return[3].ToString());
                #endregion
                btn_Unusual_Report.Enabled = false;
                if ((int)arl_Return[1] == (int)arl_Return[2])
                {
                    ErrorMsgLabel.Text = "[確定匯入]成功,資料已匯入完成。";

                }
                else if ((int)arl_Return[1] != (int)arl_Return[2])
                {
                    ErrorMsgLabel.Text = "[確定匯入]失敗,請檢視異常!";
                    btn_Unusual_Report.Enabled = true;
                }
            }
            else
            {
                ErrorMsgLabel.Text = "[確定匯入]發生錯誤!" + arl_Return[1].ToString();
                btn_Unusual_Report.Enabled = false;
            }
        }
        catch (Exception ex)
        {
            this.ErrorMsgLabel.Text = ex.Message;
            btn_Unusual_Report.Enabled = false;
        }
        finally
        {
            this.btn_File_To_Temp.Enabled = true;
            this.btn_Temp_To_DB.Enabled = false;
      
        }
        #endregion
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            #region 清空Message

            this.ErrorMsgLabel.Text = string.Empty;
            this.RightMsgLabel.Text = string.Empty;

            #endregion

            if (!IsPostBack)
            {
                #region Attributes

                this.but_Close.Attributes["onclick"] += "window.close();";

                #endregion

                #region 取得異常資料

                #region 傳入參數

                ParameterList.Clear();
                ParameterList.Add(Session["UID"].ToString());
                ParameterList.Add("");
                ParameterList.Add("2");

                #endregion

                #region 連結資料庫

                CGDModel.CGD42_BCO BCO = new CGDModel.CGD42_BCO(ConntionDB);
                DataTable dt_Return = BCO.QueryTmp(ParameterList);

                #endregion

                #region 檢查回傳資料

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

                #endregion

                #endregion
            }
        }
        catch (Exception ex)
        {
            WaringLogProcess(ex.Message);
            this.ErrorMsgLabel.Text = ex.Message;
        }
        finally { }
    }