Ejemplo n.º 1
0
    //執行載入
    protected void but_Temp_To_DB_Click(object sender, EventArgs e)
    {
        try
        {
            //設定頁面狀態
            this.hid_FrmStatus.Value = "fmBroswe";

            //System.Threading.Thread.Sleep(5000);
            ArrayList arl_Return = null;
            string s_LoginUser = string.Empty;
            string s_DBConnString = string.Empty;
            string s_UploadPath_File = string.Empty;
            string s_BackPath_File = string.Empty;

            s_LoginUser = Session["UID"].ToString();//登入人員
            s_DBConnString = ConntionDB;

            Bridge.ImportSTDImport br = new Bridge.ImportSTDImport();

            if (s_AP_FileName != string.Empty)
            { arl_Return = br.TmpToDB(s_LoginUser, s_DBConnString, s_AP_FileName); }
            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

                //設定頁面狀態
            }
            else if (arl_Return[0].ToString() == "CHECKDATA 不正確")
            {
                #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
            }

            this.but_Temp_To_DB.Enabled = false;
            this.but_File_To_Temp.Enabled = true;
            this.but_Unusual_Report.Enabled = true;
            this.ButtonQuery.Enabled = true;
        }
        catch (Exception ex)
        {
            this.ErrorMsgLabel.Text = ex.Message;
        }
    }
Ejemplo n.º 2
0
    //查詢
    protected void ButtonQuery_Click(object sender, EventArgs e)
    {
        try
        {
            string s_LoginUser = string.Empty;
            string s_DBConnString = string.Empty;
            DataTable dt_Return = new DataTable();
            ArrayList ParameterList = new ArrayList();

            s_LoginUser = Session["UID"].ToString();//登入人員
            s_DBConnString = ConntionDB;

            ParameterList.Clear();
            ParameterList.Add(this.txt_User.Text.Trim());
            ParameterList.Add(this.txt_Date.Text.Trim());
            ParameterList.Add(Session["UID"].ToString());
            ParameterList.Add(DateTime.Now);

            Bridge.ImportSTDImport br = new Bridge.ImportSTDImport();
            dt_Return = br.QueryErrorByFind(ParameterList, s_DBConnString);

            if (dt_Return.Rows.Count > 0)
            {
                string SessionIDName = "STD071_" + PageTimeStamp.Value;
                Session["SessionID"] = SessionIDName;
                Session[SessionIDName] = 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
            {
                System.Web.UI.ScriptManager.RegisterStartupScript(this.up_GridView, this.GetType(), "TO_STD071.aspx", "alert('查無資料')", true);
            }

        }
        catch (Exception ex)
        {
            this.ErrorMsgLabel.Text = ex.Message;
        }
        finally { }
    }
Ejemplo n.º 3
0
    //匯入
    protected void but_File_To_Temp_Click(object sender, EventArgs e)
    {
        try
        {
            //設定頁面狀態
            this.hid_FrmStatus.Value = "fmBroswe";

            System.Threading.Thread.Sleep(2000);
            string s_UploadPath = string.Empty;
            string s_BackPath = string.Empty;
            string s_LoginUser = string.Empty;
            ArrayList arl_FileUpload_Return = null;
            ArrayList arl_FileToTmp_Return = null;

            Bridge.ImportSTDImport br = new Bridge.ImportSTDImport();

            #region 上傳檔案到AP端

            //取得要上傳的路徑
            s_UploadPath = System.Configuration.ConfigurationManager.AppSettings["UploadPath"];
            s_LoginUser = Session["UID"].ToString();

            arl_FileUpload_Return = br.FileUpload(s_UploadPath, this.FileUpload1, s_LoginUser);

            #endregion

            if (arl_FileUpload_Return[0].ToString() == "FALSE")//檔案上傳至AP端錯誤
            {
                //System.Web.UI.ScriptManager.RegisterStartupScript(this.up_File_To_Temp, this.GetType(), "TO_STD071.aspx", "alert('" + arl_FileUpload_Return[1].ToString() + "')", true);
                return;//檔案上傳至AP端錯誤,後面直接不做了
            }
            else if (arl_FileUpload_Return[0].ToString() == "TRUE")//檔案上傳至AP端正常
            {

                #region 讀取 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;";
                    oleConnection = new OleDbConnection(connString);
                    oleConnection.Open();
                    OleDbCommand oleCommand = new OleDbCommand("SELECT * FROM [Sheet_Name$]", 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.Response.Write(ex.Message);
                }
                finally
                {
                    if (oleConnection != null)
                    {
                        oleConnection.Close();
                        oleConnection.Dispose();
                    }
                }

                #endregion

                #region 將檔案匯入TmpTable

                string s_DBConnString = ConntionDB;
                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 = br.FileToTmp(ds_Excel, d_CreateDate, s_LoginUser, s_DBConnString, s_AP_FileName);

                #endregion

                if (arl_FileToTmp_Return[0].ToString() == "FALSE")
                {
                    this.but_Temp_To_DB.Enabled = false;
                    System.Web.UI.ScriptManager.RegisterStartupScript(this.but_File_To_Temp, this.GetType(), "TO_STD071.aspx", "alert('" + arl_FileToTmp_Return[1].ToString() + "')", true);
                }
                else if (arl_FileToTmp_Return[0].ToString() == "TRUE")
                {
                    if (((bool)arl_FileToTmp_Return[1]) == false)
                    { this.but_Temp_To_DB.Enabled = false; }//代表內容邏輯不正確
                    else
                    { this.but_Temp_To_DB.Enabled = true; }

                    #region 將資料從 UploadPath 移至 BackPath

                    s_BackPath = System.Configuration.ConfigurationManager.AppSettings["BackPath"];

                    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

                    #region 將結果顯示在 UploadStatusPanel 中

                    //上傳結果
                    this.UploadStatusPanel1.UploadSum = ((int)arl_FileToTmp_Return[2]);
                    this.UploadStatusPanel1.UploadOK = ((int)arl_FileToTmp_Return[3]);
                    this.UploadStatusPanel1.UploadNG = ((int)arl_FileToTmp_Return[4]);
                    //匯入結果
                    this.UploadStatusPanel1.ImportSum = 0;
                    this.UploadStatusPanel1.ImportOK = 0;
                    this.UploadStatusPanel1.ImportNG = 0;

                    #endregion

                    this.but_Unusual_Report.Enabled = true;
                }
            }
        }
        catch (Exception ex)
        {
            this.ErrorMsgLabel.Text = ex.Message;
        }
    }