private void TempDataToDataBase() { #region ErrorMsgLabel.Text = ""; try { ArrayList arl_Return = null; CAAModel.CAA38_BCO BCO = new CAAModel.CAA38_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; //解除CAA11鎖定 DeleteControlChk(ViewState["LockID"].ToString(), Session["UID"].ToString(), ViewState["LockTime"].ToString()); } #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("2"); #endregion #region 連結資料庫 CAAModel.CAA38_BCO BCO = new CAAModel.CAA38_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 { } }
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(); CAAModel.CAA38_BCO BCO = new CAAModel.CAA38_BCO(ConntionDB); //上傳檔案到AP端 //取得要上傳的路徑 s_UploadPath = Server.MapPath("..\\") + System.Configuration.ConfigurationManager.AppSettings["UploadPath"] + "\\CAA\\"; 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; } } }