//執行匯入 protected void but_Temp_To_DB_Click(object sender, EventArgs e) { try { ArrayList arl_Return = null; string s_LoginUser = string.Empty; string s_UploadPath_File = string.Empty; string s_BackPath_File = string.Empty; s_LoginUser = Session["UID"].ToString();//登入人員 BCO.ImportStoreGift BCO = new BCO.ImportStoreGift(ConnectionDB); if (s_AP_FileName != string.Empty) { //將資料由 TEMP TABLE 新增至正式 TABLE BCO.TempDataToDataBase(s_LoginUser, null); #region 設定 UploadStatusPanel 的值 //匯入結果 UploadStatusPanel1.ImportSum = iProcessingCounts; UploadStatusPanel1.ImportOK = iProcessingCounts; UploadStatusPanel1.ImportNG = 0; #endregion } else { Response.Write("請重新匯入 EXCEL 檔"); } but_Temp_To_DB.Enabled = false; but_File_To_Temp.Enabled = true; btn_Back.Enabled = true; ErrorMsgLabel.Text = "執行匯入完成"; } catch (Exception ex) { ErrorMsgLabel.Text = ex.Message; } }
private bool ClientFileToServerTemp() { 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; BCO.ImportStoreGift BCO = new BCO.ImportStoreGift(ConnectionDB); #region 上傳檔案到AP端 //取得要上傳的路徑 s_UploadPath = Server.MapPath(System.Configuration.ConfigurationManager.AppSettings["UploadPath"]).Replace("MKT\\", "") + "\\MKT\\"; s_LoginUser = Session["UID"].ToString(); arl_FileUpload_Return = BCO.FileUpload(s_UploadPath, FileUpload1, s_LoginUser); #endregion if (arl_FileUpload_Return[0].ToString() == "FALSE")//檔案上傳至AP端錯誤 { bResult = false;//檔案上傳至AP端錯誤,後面直接不做了 ErrorMsgLabel.Text = arl_FileUpload_Return[1].ToString(); } else if (arl_FileUpload_Return[0].ToString() == "TRUE")//檔案上傳至AP端正常 { #region // 讀取 Excel 資料 DataSet ds_Excel = ReadDataFromExcelXml(arl_FileUpload_Return[1].ToString()); //檢核是否已有相同通路、門市、品號、期別 Added by Tony 2010/1/5 BCO.MaintainStoreGift bco = new BCO.MaintainStoreGift(ConnectionDB); ArrayList ar = new ArrayList(); foreach (System.Data.DataRow dr in ds_Excel.Tables[0].Rows) { ar.Clear(); ar.Add(dr["ITEM"]); ar.Add(dr["PERIOD"]); ar.Add(dr["CHAN_NO"]); ar.Add(dr["STORE"]); ar.Add(System.DBNull.Value); //虛擬品號 DataTable dt = bco.QueryExistPk(ar); if(dt.Rows.Count>0) { ErrorMsgLabel.Text = "品號「" + dr["ITEM"].ToString() + "」、期別「" + dr["PERIOD"].ToString() + "」、通路「" + dr["CHAN_NO"].ToString() + "」、門市「" + dr["STORE"].ToString() + "」資料已存在"; return bResult = false; } } #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,chkDis.Checked); #endregion if (arl_FileToTmp_Return[0].ToString() == "FALSE") { but_Temp_To_DB.Enabled = false; bResult = false; ErrorMsgLabel.Text = arl_FileToTmp_Return[1].ToString(); return bResult = false; } 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 = Server.MapPath(System.Configuration.ConfigurationManager.AppSettings["BackPath"]).Replace("MKT\\", "") + "\\MKT\\"; 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 if ((int)arl_FileToTmp_Return[4] == 0) //異常筆數 = 0 { if ((int)arl_FileToTmp_Return[2] == 0) //處理總筆數 = 0 { ErrorMsgLabel.Text = "無資料匯入 !!"; but_Temp_To_DB.Enabled = false; } else { ErrorMsgLabel.Text = "檔案已匯入成功,請確認無誤後,按「執行匯入」鈕,將資料匯入到資料庫"; but_Temp_To_DB.Enabled = true; } but_Unusual_Report.Enabled = false; //檢視異常報表鈕 ButtonQuery.Enabled = false; //查詢鈕 } else { if ((int)arl_FileToTmp_Return[2] == 0) //處理總筆數 = 0 { ErrorMsgLabel.Text = "無資料匯入 !!"; but_Unusual_Report.Enabled = false; //檢視異常報表鈕 ButtonQuery.Enabled = false; //查詢鈕 } else { but_Unusual_Report.Enabled = true; //檢視異常報表鈕 ButtonQuery.Enabled = true; //查詢鈕 } but_Temp_To_DB.Enabled = false; //執行匯入鈕 } if ((int)arl_FileToTmp_Return[4] == 0) bResult = true; else bResult = false; } return bResult; #endregion } } catch (Exception ex) { ErrorMsgLabel.Text = ex.Message; return bResult = false; } return bResult; }