Пример #1
0
    //檢視異常報表
    protected void btn_Unusual_Report_Click(object sender, EventArgs e)
    {
        #region
        try
        {
            DataTable dt_Return = new DataTable();
            ArrayList ParameterList = new ArrayList();

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

            STMModel.ImportPurchaseOrder br = new STMModel.ImportPurchaseOrder(ConnectionDB);
            dt_Return = br.QueryTempErrorByFind(ParameterList);

            if (dt_Return.Rows.Count > 0)
            {
                Session["PUR023_" + PageTimeStamp.Value] = dt_Return;
                this.gv_ErrorData.DataSource = dt_Return.DefaultView;

                //頁面顯示初始狀態設定
                this.gv_ErrorData.PageSize = 10;//設定檢視異常報表每頁幾筆資料
                this.gv_ErrorData.PageIndex = 0;
                this.gv_ErrorData.DataBind();
            }
            else
            {
                this.gv_ErrorData.DataSource = dt_Return.DefaultView;
                this.gv_ErrorData.DataBind();
                ShowErrorMessage("查無資料!");
            }
        }
        catch (Exception ex)
        {
            this.ErrorMsgLabel.Text = ex.Message;
        }
        finally { }
        #endregion
    }
Пример #2
0
    private void ClientFileToServerTemp()
    {
        #region
        ErrorMsgLabel.Text = "";
        if (FileUpload1.FileName != "")
        {
            try
            {
                //設定頁面狀態
                this.ErrorMsgLabel.Text = "";
                this.up_ErrorMsg.Update();
                this.hid_FrmStatus.Value = "fmFileToTmp";
                //LockPage();
                System.Threading.Thread.Sleep(2000);
                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();
                STMModel.ImportPurchaseOrder bcoA = new STMModel.ImportPurchaseOrder(ConnectionDB);

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

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

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

                if (arl_FileUpload_Return[0].ToString() == "FALSE")//檔案上傳至AP端錯誤
                {
                    sb.Append("檔案上傳至AP端錯誤<br/>");
                    this.ErrorMsgLabel.Text = sb.ToString();
                    #region 清空 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;
                    #endregion
                    return;
                }
                else if (arl_FileUpload_Return[0].ToString() == "TRUE")//檔案上傳至AP端正常
                {
                    #region
                    #region 讀取 Excel 資料
                    OleDbConnection oleConnection = null;
                    //DataTable dtFile = new DataTable();
                    DataSet ds_Excel = new DataSet();

                    try
                    {

                        //String connString = "Provider=Microsoft.ACE.OLEDB.12.0;Extended Properties='Excel 12.0;HDR=YES';data source=" + arl_FileUpload_Return[1].ToString();                        
                        //"Provider=Microsoft.JET.OLEDB.12.0;Data Source =" + arl_FileUpload_Return[1].ToString() + ";Extended Properties=Excel 8.0;";
                        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);

                        #region 請注意如果EXCEL檔欄位有值,但到DB卻沒有資料
                        //請修改,機碼 HKEY_LOCAL_MACHINE\Software\Microsoft\Jet\4.0\Engines\Excel\TypeGuessRows 值
                        //預設是 8, 表示會先讀取前 8 列來決定每一個欄位的型態, 所以如果前 8 列的資料都是數字, 到了第 9 列以後出現的文字資料都會變成 null
                        //如果要解決這個問題, 只要把 TypeGuessRows 機碼值改成 0
                        #endregion
                    }
                    catch (Exception ex)
                    {
                        this.ErrorMsgLabel.Text = ex.Message;
                    }
                    finally
                    {
                        if (oleConnection != null)
                        {
                            oleConnection.Close();
                            oleConnection.Dispose();
                        }
                    }
                    #endregion

                    #region 將檔案匯入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 = bcoA.FileToTmp(ds_Excel, d_CreateDate, Session["UID"].ToString(), this.SLP_Vendor.Text, ConnectionDB, arl_FileUpload_Return[3].ToString());
                    arl_FileToTmp_Return = bcoA.FileToTmp(ds_Excel, d_CreateDate, Session["UID"].ToString(), this.SLP_Vendor.Text, ConnectionDB, strOrg_FileName);
                    //arl_FileToTmp_Return = bcoA.FileToTmp(ds_Excel, d_CreateDate);                      

                    if (arl_FileToTmp_Return[0].ToString() == "FALSE")
                    {
                        this.btn_Temp_To_DB.Enabled = false;
                        //System.Web.UI.ScriptManager.RegisterStartupScript(this.but_File_To_Temp, this.GetType(), "TO_ALO064.aspx", "alert('" + arl_FileToTmp_Return[1].ToString() + "')", true);
                    }
                    else if (arl_FileToTmp_Return[0].ToString() == "TRUE")
                    {
                        #region
                        #region 將資料從 UploadPath 移至 BackPath
                        s_BackPath = Server.MapPath("..\\") + System.Configuration.ConfigurationManager.AppSettings["BackPath"] + "\\PUR\\";

                        # region 檢查檔案路徑是否存在,如不存在新增相關路徑
                        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));
                            }
                        }
                        #endregion

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

                        this.btn_Unusual_Report.Enabled = true;

                        if ((int)arl_FileToTmp_Return[3] == 0)
                        { this.btn_Temp_To_DB.Enabled = true; }
                        else
                        { this.btn_Temp_To_DB.Enabled = false; }
                        #endregion
                    }
                    #endregion
                    #endregion
                }
                #region 將結果顯示在 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;
                }
                else if ((int)arl_FileToTmp_Return[1] == (int)arl_FileToTmp_Return[2])
                {
                    ErrorMsgLabel.Text = "[匯入]成功,請繼續[執行匯入]的功能。";
                }
                else if ((int)arl_FileToTmp_Return[1] != (int)arl_FileToTmp_Return[2])
                {
                    ErrorMsgLabel.Text = "[匯入]失敗,請檢視異常報表!";
                    this.btn_Temp_To_DB.Enabled = false;
                }
                #endregion

                this.hid_FrmStatus.Value = "fmBroswe";
            }
            catch (Exception ex)
            {
                this.ErrorMsgLabel.Text = ex.Message;
                this.hid_FrmStatus.Value = "fmBroswe";
            }
        }
        #endregion
    }
Пример #3
0
    private void TempDataToDataBase()
    {
        #region
        ErrorMsgLabel.Text = "";
        try
        {
            //設定頁面狀態
            this.hid_FrmStatus.Value = "fmTmpToDB";
            ArrayList arl_Return = null;
            STMModel.ImportPurchaseOrder br = new STMModel.ImportPurchaseOrder(ConnectionDB);

            if (s_AP_FileName != string.Empty)
            {
                arl_Return = br.TmpToDB(Session["UID"].ToString(),this.txtMAIL_ADDR.Text, ConnectionDB);
            }
            else
            {
                this.Response.Write("請重新匯入 EXCEL 檔");
            }

            if (arl_Return[0].ToString() == "TEMPTODB 正確")
            {
                #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
                if ((int)arl_Return[1] == (int)arl_Return[2])
                {
                    ErrorMsgLabel.Text = "[執行匯入]成功,資料已匯入採購單。";
                }
                else if ((int)arl_Return[1] != (int)arl_Return[2])
                {
                    ErrorMsgLabel.Text = "[執行匯入]失敗,請檢視異常報表!";
                }
            }
        }
        catch (Exception ex)
        {
            this.ErrorMsgLabel.Text = ex.Message;
        }
        finally
        {
            this.btn_Temp_To_DB.Enabled = false;
            this.btn_File_To_Temp.Enabled = true;
            this.btn_Unusual_Report.Enabled = true;
            this.btnQuery.Enabled = true;
            //this.btn_Exit.Enabled = true;
        }
        #endregion
    }
Пример #4
0
    private void databind()
    {
        DataTable dt_Return = new DataTable();
        ArrayList ParameterList = new ArrayList();
        string strWhere = "";
        strWhere = this.getQuerySqlStatement();

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

        STMModel.ImportPurchaseOrder br = new STMModel.ImportPurchaseOrder(ConnectionDB);

        dt_Return = br.QueryTempErrorByFind2(ParameterList);

        if (dt_Return.Rows.Count > 0)
        {
            Session["PUR023_" + PageTimeStamp.Value] = dt_Return;
            this.gv_ErrorData.DataSource = dt_Return.DefaultView;
            //頁面顯示初始狀態設定
            this.gv_ErrorData.PageSize = int.Parse(this.TextBoxPagesize.Text);//設定檢視異常報表每頁幾筆資料
            this.gv_ErrorData.PageIndex = 0;
            this.gv_ErrorData.DataBind();
        }
        else
        {
            this.gv_ErrorData.DataBind();
            ShowErrorMessage("查無資料!");
        }
    }