Esempio n. 1
0
    private bool ClientFileToServerTemp()
    {
        #region

        bool bResult = false;

        try
        {
            if (FileUpload1.FileName == "") return bResult = false;

            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;

            ALOModel.ImportStoreOrderItem BCO = new ALOModel.ImportStoreOrderItem(ConnectionDB);

            #region 上傳檔案到AP端


            //取得要上傳的路徑
            s_UploadPath = Server.MapPath(System.Configuration.ConfigurationManager.AppSettings["UploadPath"]).Replace("ALO\\", "") + "\\ALO\\";
            s_LoginUser = Session["UID"].ToString();

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

            #endregion

            if (arl_FileUpload_Return[0].ToString() == "FALSE")//檔案上傳至AP端錯誤
            {
                #region
                bResult = false;//檔案上傳至AP端錯誤,後面直接不做了
                #endregion
            }
            else if (arl_FileUpload_Return[0].ToString() == "TRUE")//檔案上傳至AP端正常
            {
                #region

                #region 讀取 Excel 資料

                DataSet ds_Excel = BCO.ReadDataFromExcel(arl_FileUpload_Return[1].ToString());

                #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 = BCO.FileToTmp(ds_Excel, d_CreateDate, s_LoginUser, s_AP_FileName, PageTimeStamp.Value);

                #endregion

                if (arl_FileToTmp_Return[0].ToString() == "FALSE")
                {
                    this.but_Temp_To_DB.Enabled = false;
                    bResult = false;
                    ErrorMsgLabel.Text = arl_FileToTmp_Return[1].ToString();

                    //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
                    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 = Server.MapPath(System.Configuration.ConfigurationManager.AppSettings["BackPath"]).Replace("ALO\\", "") + "\\ALO\\";

                    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;

                    iProcessingCounts = ((int)arl_FileToTmp_Return[2]);

                    #endregion

                    this.but_Unusual_Report.Enabled = true;
                    #endregion

                    if ((int)arl_FileToTmp_Return[4] == 0)
                    {
                        bResult = true;
                    }
                    else
                    {
                        bResult = false;
                    }
                }

                return bResult;

                #endregion
            }
        }
        catch (Exception ex)
        {
            this.ErrorMsgLabel.Text = ex.Message;
            return bResult = false;
        }

        return bResult;

        #endregion
    }