/// <summary> /// 將資料由 TEMP TABLE 新增至正式 TABLE /// </summary> /// <param name="ParameterList">V_CREATEUID</param> /// <param name="RootDBT">是否有主交易,無主交易輸入null</param> /// <returns>None</returns> public void TempDataToDataBase(string strLoginUser, DbTransaction RootDBT) { #region bool IsRootTranscation = false; try { MaintainStoreGiftTmp BCO = new MaintainStoreGiftTmp(ConnectionDB); //判斷是否有傳入Root Transcation IsRootTranscation = (RootDBT == null) ? true : false; #region 啟動交易或指定RootTranscation if (IsRootTranscation) { //獨立呼叫啟動Transcation Conn = USEDB.CreateConnection(); Conn.Open(); DBT = Conn.BeginTransaction(); } else { DBT = RootDBT; } #endregion #region 新增通路門市贈品檔 From TMP檔 ParameterList.Clear(); ParameterList.Add(strLoginUser); BCO.TempDataToDataBase(ParameterList, DBT); #endregion #region 交易成功 if (IsRootTranscation) { //獨立呼叫Transcation成立 DBT.Commit(); } #endregion } catch (Exception ex) { #region 交易失敗 if (IsRootTranscation) { //獨立呼叫Transcation失敗 DBT.Rollback(); } #endregion throw ex; } finally { #region 判斷是否關閉交易連線 if (IsRootTranscation) { //獨立呼叫Transcation,關閉連線 if (Conn.State == ConnectionState.Connecting) { Conn.Close(); } } #endregion } #endregion }
/// <summary> ///1.目的:將上傳檔案內容,存入暫存檔 ///2.傳入參數:@處理檔名、@使用者 /// 回傳參數:@處理筆數、@正確筆數、@錯誤筆數、@錯誤訊息 ///3.處理表格:VDS_MKT_STOREGIFT_TMP(T) ///4.處理邏輯: /// 4.1) 先清除前一次,同一使用者執行的匯入暫存資訊與錯誤資訊。 /// 相關Table:VDS_MKT_STOREGIFT_TMP /// 4.2) 讀取匯入檔案到暫存資料集。 /// 4.3) 檢查匯入檔案格式內容是否正確,如有任何錯誤,則停止上傳流程,並回傳錯誤訊息。 /// 『XX檔案,檔案內容錯誤:@錯誤說明』 (格式請參考資料庫Table Shcema) /// * 日期:檢查日期格式。 /// * 數字:檢查內容是否為數字。 /// * 文字:檢查長度是否溢位。 /// * 檔案欄位數是否不足。 /// * 檢查必填欄位是否有值 /// * 工作表匯入內容有任一筆錯,皆視為錯誤,整批放棄。 /// * 匯入表格細節說明請參考:Excel文件 /// 4.4) 格式檢查正確無誤後 /// a) 暫存檔中的[狀態]欄位調整為1:FILE TO TMP /// b) 呼叫 [CheckData] ,檢查資料內容邏輯正確性 /// 4.5) 無論CheckData()檢查結果是否為True, /// 皆將上傳檔案內容新增到資料庫Tmp Table:, /// 並記錄錯誤原因、匯入者、匯入日期、處理檔案名稱=上傳檔名。 ///5. 回傳處理結果(@處理筆數、@正確筆數、@錯誤筆數、@錯誤訊息(無錯誤時=null) ) /// </summary> public ArrayList FileToTmp(DataSet ds_Excel, DateTime d_CreateDate, string s_LoginUser, string s_AP_FileName,bool bCheckDis) { #region int iErrCounts = 0; int i_newTable_Count = 0; ArrayList arl_Return = new ArrayList(); int i_FileToTemp_Total_count = 0; int i_FileToTemp_Right_count = 0; int i_FileToTemp_Wrong_count = 0; bool b_Check_Logic = true; ArrayList paramTemp = new ArrayList(); Hashtable htTemp = new Hashtable(); DataTable dtTemp = new DataTable(); string strErrMsg = ""; string strErrMsgDataFormat = ""; Int32 iErrCount = 0; try { ParameterList.Clear(); MaintainStoreGiftTmp BCO = new MaintainStoreGiftTmp(ConnectionDB); MaintainGift BCO_ChkDis = new MaintainGift(ConnectionDB); DataTable dt_MKT_IMPORT_TMP = BCO.GetStoreGift_TmpSchema(); //刪除VDS_MKT_STOREGIFT_TMP資料 BY CREATEUID ParameterList.Clear(); ParameterList.Add(s_LoginUser); BCO.DeleteStoreGiftTmp(ParameterList, null); foreach (System.Data.DataRow dRow in ds_Excel.Tables[0].Rows) { iErrCount = 0; strErrMsg = ""; if (!CheckRequiredField(dRow, iAryRequiredColumnsCheck, out strErrMsgDataFormat))//檢查必填欄位 { #region 檢查資料格式正確性 arl_Return.Add("FALSE"); arl_Return.Add(strErrMsgDataFormat); return arl_Return; } else { string strCHAN_NO = dRow[0].ToString().Trim(); string strSTORE = dRow[2].ToString().Trim(); string strITEM = dRow[4].ToString().Trim(); string strPERIOD = dRow[6].ToString().Trim(); string strVIRTUAL_CODE = dRow[7].ToString().Trim(); #region 檢查資料邏輯正確性 #region 將資料寫入 TEMP TABLE DataRow dRow_Temp = dt_MKT_IMPORT_TMP.NewRow(); dRow_Temp["CREATEDATE"] = d_CreateDate; dRow_Temp["CREATEUID"] = s_LoginUser; dRow_Temp["CHAN_NO"] = strCHAN_NO; dRow_Temp["CHAIN_NAME"] = dRow[1].ToString().Trim(); dRow_Temp["STORE"] = strSTORE; dRow_Temp["STORE_NAME"] = dRow[3].ToString().Trim(); dRow_Temp["ITEM"] = strITEM; dRow_Temp["ITEM_NAME"] = dRow[5].ToString().Trim(); dRow_Temp["PERIOD"] = strPERIOD; dRow_Temp["VIRTUAL_CODE"] = strVIRTUAL_CODE; dRow_Temp["VIRTUAL_NAME"] = dRow[8].ToString().Trim(); dRow_Temp["STATUS"] = 1; //1:FILE TO TMP 2:TMP TO DB dRow_Temp["DATASOURCE"] = s_AP_FileName; #endregion #region 判斷是否可新增 ParameterList.Clear(); ParameterList.Add(strCHAN_NO); ParameterList.Add(strSTORE); ParameterList.Add(strITEM); ParameterList.Add(strPERIOD); ParameterList.Add(strVIRTUAL_CODE); DataTable dtImportCheck = BCO.CheckImportStoreGiftTmp(ParameterList); #region ArrayList arrList = new ArrayList(); STMModel.MaintainStoreUnique STM_BCO = new STMModel.MaintainStoreUnique(ConnectionDB); arrList.Clear(); arrList.Add(strSTORE); arrList.Add(strCHAN_NO); DataTable dt = STM_BCO.QueryForSLP(arrList); if(dt.Rows.Count==0) { strErrMsg += "此門市不屬於此通路,"; iErrCounts++; } if (dtImportCheck != null && dtImportCheck.Rows.Count > 0) { //是否存在於通路主檔 if (dtImportCheck.Rows[0][0].ToString().Trim() == "0") { strErrMsg += "通路不存在,"; iErrCounts++; } //是否存在於門市主檔 if (dtImportCheck.Rows[0][1].ToString().Trim() == "0") { strErrMsg += "門市不存在,"; iErrCounts++; } //是否存在於品號主檔 if (dtImportCheck.Rows[0][2].ToString().Trim() == "0") { strErrMsg += "品號不存在,"; iErrCounts++; } else if (dtImportCheck.Rows[0][3].ToString().Trim() == "0") //是否存在於期別主檔 { strErrMsg += "期別不存在,"; iErrCounts++; } else if (dtImportCheck.Rows[0][4].ToString().Trim() == "0") //是否存在於贈品主檔 { strErrMsg += "虛擬品號不存在,"; iErrCounts++; } else { if (bCheckDis == false) //是否檢查配本已確認 { ParameterList.Clear(); ParameterList.Add(strITEM); ParameterList.Add(strVIRTUAL_CODE); ParameterList.Add(strPERIOD); if (BCO_ChkDis.ChkDis(ParameterList) == 1) { strErrMsg += "配本以確認,"; iErrCounts++; } } } //是否存在於通路門市贈品檔 //取消此項檢核,若資料已存在通路門市贈品檔,則改成Update寫入 2009/11/4 //if (strErrMsg == "" && dtImportCheck.Rows[0][5].ToString().Trim() == "1") //{ // strErrMsg += "資料已存在通路門市贈品檔,"; // iErrCounts++; //} } #endregion #endregion #region 針對ERROR_MEMO是否為空字串做檢查 if (strErrMsg.Trim() == string.Empty) { dRow_Temp["ERROR_MEMO"] = System.DBNull.Value; } else { if (strErrMsg.Trim().Length > 0) { if (strErrMsg.Trim().Substring(strErrMsg.Trim().Length - 1) == ",") { strErrMsg = strErrMsg.Trim().Substring(0, strErrMsg.Trim().Length - 1); } } dRow_Temp["ERROR_MEMO"] = strErrMsg; iErrCount++; } if (iErrCount != 0) { i_FileToTemp_Wrong_count += 1; dRow_Temp["DATATYPE"] = 2; b_Check_Logic = false; } else { i_FileToTemp_Right_count += 1; dRow_Temp["DATATYPE"] = 1; } #endregion dt_MKT_IMPORT_TMP.Rows.Add(dRow_Temp); i_newTable_Count += 1; #endregion } i_FileToTemp_Total_count += 1; #endregion } #region 先清除前一次,同一使用者執行的匯入暫存資訊與錯誤資訊,並將 Excel 資料匯入 TEMP TABLE ParameterList.Clear(); ParameterList.Add(s_LoginUser); INSERT_TEMP_TABLE(ParameterList, null, dt_MKT_IMPORT_TMP); #endregion arl_Return.Add("TRUE"); arl_Return.Add(b_Check_Logic); arl_Return.Add(i_FileToTemp_Total_count); arl_Return.Add(i_FileToTemp_Right_count); arl_Return.Add(i_FileToTemp_Wrong_count); } catch (Exception ex) { arl_Return.Add("FALSE"); arl_Return.Add(ex.Message); } return arl_Return; #endregion }
/// <summary> /// 將 EXCEL 中新資料匯入 VDS_MKT_STOREGIFT_TMP /// </summary> /// <param name="ParameterList">刪除變數</param> /// <param name="RootDBT">是否有主交易,無主交易輸入null</param> /// <returns>None</returns> public void INSERT_TEMP_TABLE(ArrayList ParameterList, DbTransaction RootDBT, DataTable dt_MKT_IMPORT_TMP) { #region bool IsRootTranscation = false; try { MaintainStoreGiftTmp BCO = new MaintainStoreGiftTmp(ConnectionDB); //判斷是否有傳入Root Transcation IsRootTranscation = (RootDBT == null) ? true : false; #region 啟動交易或指定RootTranscation if (IsRootTranscation) { //獨立呼叫啟動Transcation Conn = USEDB.CreateConnection(); Conn.Open(); DBT = Conn.BeginTransaction(); } else { DBT = RootDBT; } #endregion #region 逐筆新增匯入通路門市贈品TMP檔(VDS_MKT_STOREGIFT_TMP) foreach (DataRow dRow in dt_MKT_IMPORT_TMP.Rows) { ParameterList.Clear(); ParameterList.Add(dRow["CHAN_NO"]); ParameterList.Add(dRow["CHAIN_NAME"]); ParameterList.Add(dRow["STORE"]); ParameterList.Add(dRow["STORE_NAME"]); ParameterList.Add(dRow["ITEM"]); ParameterList.Add(dRow["ITEM_NAME"]); ParameterList.Add(dRow["PERIOD"]); ParameterList.Add(dRow["VIRTUAL_CODE"]); ParameterList.Add(dRow["VIRTUAL_NAME"]); ParameterList.Add(dRow["ERROR_MEMO"]); ParameterList.Add(dRow["CREATEUID"]); ParameterList.Add(dRow["CREATEDATE"]); ParameterList.Add(dRow["DATASOURCE"]); ParameterList.Add(dRow["STATUS"]); ParameterList.Add(dRow["DATATYPE"]); BCO.CreateStoreGiftTmp(ParameterList, DBT); } #endregion #region 交易成功 if (IsRootTranscation) { //獨立呼叫Transcation成立 DBT.Commit(); } #endregion } catch (Exception ex) { #region 交易失敗 if (IsRootTranscation) { //獨立呼叫Transcation失敗 DBT.Rollback(); } #endregion throw ex; } finally { #region 判斷是否關閉交易連線 if (IsRootTranscation) { //獨立呼叫Transcation,關閉連線 if (Conn.State == ConnectionState.Connecting) { Conn.Close(); } } #endregion } #endregion }
private void QueryData(string strDATATYPE) //strDATATYPE = 2 -> 檢視異常報表,strDATATYPE = null -> 查詢 { #region string s_LoginUser = string.Empty; DataTable dt_Return = new DataTable(); ArrayList ParameterList = new ArrayList(); s_LoginUser = Session["UID"].ToString();//登入人員 ParameterList.Clear(); if (strDATATYPE.Trim() == string.Empty) { ParameterList.Add(txt_User.Text.Trim()); ParameterList.Add(txt_Date.Text.Trim()); ParameterList.Add(System.DBNull.Value); } else { ParameterList.Add(s_LoginUser); ParameterList.Add(DateTime.Today); ParameterList.Add(int.Parse(strDATATYPE.Trim())); } Int32 iTopRowNum; Int32.TryParse(TextBoxRowCountLimit.Text.Trim(), out iTopRowNum); ParameterList.Add(iTopRowNum); BCO.MaintainStoreGiftTmp BCO = new BCO.MaintainStoreGiftTmp(ConnectionDB); dt_Return = BCO.QueryStoreGiftTmp(ParameterList); if (dt_Return.Rows.Count > 0) { string SessionIDName = string.Format("{0}_{1}", PAGE_DT_01, PageTimeStamp.Value); Session["SessionID"] = SessionIDName; Session[SessionIDName] = dt_Return; gv_ErrorData.DataSource = dt_Return.DefaultView; gv_ErrorData.PageSize = (TextBoxPagesize.Text == "") ? 10 : (int.Parse(TextBoxPagesize.Text) <= 0) ? 10 : int.Parse(TextBoxPagesize.Text); gv_ErrorData.PageIndex = 0; gv_ErrorData.DataBind(); } else { gv_ErrorData.DataBind(); ErrorMsgLabel.Text = "查無資料"; } #endregion }