/// <summary> /// FileToTmp 效能提升版 /// </summary> /// <param name="ds_Excel"></param> /// <param name="d_CreateDate"></param> /// <param name="s_LoginUser"></param> /// <param name="s_AP_FileName"></param> /// <param name="strST_ACCEPT_DATE"></param> /// <param name="V_SESSION_ID"></param> /// <returns></returns> public ArrayList FileToTmp2(DataSet ds_Excel, DateTime d_CreateDate, string s_LoginUser, string s_AP_FileName, string strST_ACCEPT_DATE, string V_SESSION_ID) { #region int i_newTable_Count = 0; ArrayList arl_Return = new ArrayList(); ArrayList arr_CheckData_Table = new ArrayList(); ArrayList arr_CheckData = 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(); DataTable dtTemp = new DataTable(); string strErrMsg = ""; string strErrMsgDataFormat = ""; Int32 iErrCount = 0; Int32 iPKCount = 0; try { ParameterList.Clear(); DataTable dt_ALO_IMPORT_TMP = QuerySwitch(QueryType.GetPOSOURCE_NO_TmpSchema, ParameterList); VDS_ALO_POSOURCE_NO_TMP_DBO ALO_POSOURCE_NO_TMP = new VDS_ALO_POSOURCE_NO_TMP_DBO(ref USEDB); MaintainStoreOrderItem ALOM = new MaintainStoreOrderItem(ConnectionDB); MaintainChainPO BCO = new MaintainChainPO(ConnectionDB); MaintainChainPOSetting BCO2 = new MaintainChainPOSetting(ConnectionDB); string s_ROOT_NO = ""; string s_PMA = ""; string s_ChanNo = ""; string s_Store = ""; string s_Item = ""; string s_Period = ""; string s_StAcceptDate = ""; string s_PoSourceNo = ""; bool bResultMultiPO = true; //20090626 added VDS_ALO_POSOURCE_NO_TMP_DBO DBO = new VDS_ALO_POSOURCE_NO_TMP_DBO(ref USEDB); ParameterList2.Clear(); ParameterList2.Add(s_LoginUser); ParameterList2.Add(V_SESSION_ID); DBO.doDelete_POSOURCE_NO_TMP(ParameterList2, null); foreach (System.Data.DataRow dRow in ds_Excel.Tables[0].Rows) { #region iErrCount = 0; iPKCount = 0; strErrMsg = ""; s_ROOT_NO = ""; s_PMA = ""; s_ChanNo = dRow[1].ToString().Trim(); s_Store = dRow[2].ToString().Trim(); s_Item = dRow[3].ToString().Trim(); s_Period = dRow[4].ToString().Trim(); s_StAcceptDate = strST_ACCEPT_DATE; s_PoSourceNo = dRow[0].ToString().Trim(); bResultMultiPO = true; if (!CheckRequiredField(dRow, iAryRequiredColumnsCheck, out strErrMsgDataFormat))//檢查必填欄位 { #region 檢查資料格式正確性 arl_Return.Add("FALSE"); arl_Return.Add(strErrMsgDataFormat); return arl_Return; } else if (!CheckOverFlow(dRow, iAryOverflowColumnsCheck, out strErrMsgDataFormat))//檢查是否為溢位 { arl_Return.Add("FALSE"); arl_Return.Add(strErrMsgDataFormat); return arl_Return; } else if (!CheckInputValueIsInt32(dRow, iAryRequiredColumnsCheck, out strErrMsgDataFormat))//檢查是否為數值 { arl_Return.Add("FALSE"); arl_Return.Add(strErrMsgDataFormat); return arl_Return; #endregion } else { #region 將資料寫入 TEMP TABLE DataRow dRow_Temp = dt_ALO_IMPORT_TMP.NewRow(); dRow_Temp["CREATEDATE"] = d_CreateDate; dRow_Temp["CREATEUID"] = s_LoginUser; dRow_Temp["ID"] = i_newTable_Count; dRow_Temp["UPDATEDATE"] = d_CreateDate; dRow_Temp["UPDATEUID"] = s_LoginUser; dRow_Temp["CHAN_NO"] = dRow[1].ToString().Trim(); dRow_Temp["STORE"] = dRow[2].ToString().Trim(); dRow_Temp["ITEM"] = dRow[3].ToString().Trim(); dRow_Temp["PERIOD"] = dRow[4].ToString().Trim(); dRow_Temp["PO_SOURCE_NO"] = dRow[0].ToString().Trim(); dRow_Temp["ST_ACCEPT_DATE"] = strST_ACCEPT_DATE; dRow_Temp["SESSION_ID"] = V_SESSION_ID; dRow_Temp["DATASOURCE"] = s_AP_FileName; //------------------------------------- #endregion dt_ALO_IMPORT_TMP.Rows.Add(dRow_Temp); i_newTable_Count += 1; } i_FileToTemp_Total_count += 1; #endregion } #region 先清除前一次,同一使用者執行的匯入暫存資訊與錯誤資訊,並將 Excel 資料匯入 TEMP TABLE ParameterList.Clear(); ParameterList.Add(s_LoginUser); ParameterList.Add(V_SESSION_ID); DELETE_AND_INSERT_TEMP_TABLE(ParameterList, null, dt_ALO_IMPORT_TMP); #endregion //效能提升版的地方---------------------------------------------------------------------------------- #region 檢查資料邏輯正確性 #region 4.1 驗證新增資料之主檔欄位正確性。 //paramTemp.Clear(); //paramTemp.Add(dRow[1].ToString().Trim()); //paramTemp.Add(dRow[2].ToString().Trim()); //paramTemp.Add(dRow[3].ToString().Trim()); //paramTemp.Add(dRow[4].ToString().Trim()); //DataTable dtCheckMaster = ALO_POSOURCE_NO_TMP.doCheckCurrentMasterStatus(paramTemp); //if (dtCheckMaster.Rows[0][0].ToString().Trim() != "1") //{ // strErrMsg += dtCheckMaster.Rows[0][1].ToString().Trim(); //} #endregion #region 4.2 驗證主檔是否不存在對應通路,且Type_No=2 (By單店/單項)之資料[@C_1]。 //paramTemp.Clear(); //paramTemp.Add(s_LoginUser); //DataTable dtCheckException = ALO_POSOURCE_NO_TMP.doCheckExceptionChanStatus(paramTemp); //if (!(dtCheckException == null || dtCheckException.Rows.Count <= 0)) //{ // strErrMsg += "通路單號主檔未建立,"; //} #endregion #region 4.3 檢查是否有PK重複之資料 ////a) 檢查暫存檔本身是否有PK重複資料 ////b) 檢查與正式表單有是否有PK重複資料 //paramTemp.Clear(); //paramTemp.Add(dRow[1].ToString().Trim()); //paramTemp.Add(dRow[2].ToString().Trim()); //paramTemp.Add(dRow[3].ToString().Trim()); //paramTemp.Add(dRow[4].ToString().Trim()); //paramTemp.Add(strST_ACCEPT_DATE); //paramTemp.Add(s_LoginUser); //paramTemp.Add(V_SESSION_ID); //for (Int32 x = 0; x <= ds_Excel.Tables[0].Rows.Count - 1; x++) //{ // if (s_Store == ds_Excel.Tables[0].Rows[x][2].ToString().Trim() && // s_Item == ds_Excel.Tables[0].Rows[x][3].ToString().Trim() && // s_Period == ds_Excel.Tables[0].Rows[x][4].ToString().Trim() && // s_StAcceptDate == strST_ACCEPT_DATE && // s_PoSourceNo == ds_Excel.Tables[0].Rows[x][0].ToString().Trim()) // { // iPKCount++; // } // if (iPKCount > 1) // { // strErrMsg += "匯入檔中(同進貨日/門市/品號/期別/PO單)不可重複,"; // break; // } //} //DataTable dtCheckPKConflict = ALO_POSOURCE_NO_TMP.doCheckPOSourcePKConflict(paramTemp); //if (dtCheckPKConflict != null && dtCheckPKConflict.Rows.Count > 0) //{ // if (dtCheckPKConflict.Rows[0][0].ToString().Trim() != "0") // { // strErrMsg += "匯入檔中(同進貨日/門市/品號/期別/PO單)不可重複,"; // break; // } // if (dtCheckPKConflict.Rows[0][1].ToString().Trim() != "0") // { // strErrMsg += "與通路單號明細檔(同進貨日/門市/品號/期別/PO單)PK重複,"; // } //} #endregion #region 4.4 通路PO控制檔檢查 //#region 依照品號取得所屬[群分類]、[大分類] //paramTemp.Clear(); //BCO_ITM.SQLHelper.SQLWhere(ref paramTemp, DbType.String, "MA.ITEM", s_Item, "=", "and"); //BCO_ITM.MaintainSKU bco_itm = new BCO_ITM.MaintainSKU(ConnectionDB); //DataTable dt_Return = bco_itm.QuerySKUByFind_1(paramTemp); //if (dt_Return != null && dt_Return.Rows.Count != 0) //{ // s_PMA = dt_Return.Rows[0]["PMA"].ToString();//大分類 // s_ROOT_NO = dt_Return.Rows[0]["ROOT_NO"].ToString();//群分類 //} //#endregion //#region 判斷 is_dis_bypo & is_multipo //paramTemp.Clear(); //paramTemp.Add(s_ChanNo); //paramTemp.Add(s_Store); //DataTable dtTempPOSetting = BCO2.QueryStorPOSettingByFind(paramTemp); //if (dtTempPOSetting != null && dtTempPOSetting.Rows.Count > 0) //{ // for (Int32 i = 0; i <= dtTempPOSetting.Rows.Count - 1; i++) // { // if (s_ROOT_NO == dtTempPOSetting.Rows[i]["root_no"].ToString().Trim() && s_PMA == dtTempPOSetting.Rows[i]["pma"].ToString().Trim()) // { // if (dtTempPOSetting.Rows[i]["is_dis_bypo"].ToString().Trim() == "0") // { // //1.IS_DIS_BYPO=否者 // //=>代表該通路(或該門市)在某一[群分類+大分類]設定下的品項,不可帶入通路PO單號 // if (s_PoSourceNo != "") // { // #region // strErrMsg += string.Format("(通路,門市,群分類,大分類)=({0},{1},{2},{3})不可匯入通路單號", s_ChanNo, s_Store, s_ROOT_NO, s_PMA); // break; // #endregion // } // } // else if (dtTempPOSetting.Rows[i]["is_dis_bypo"].ToString().Trim() == "1" && dtTempPOSetting.Rows[i]["is_multipo"].ToString().Trim() == "0") // { // //2.IS_DIS_BYPO=是,且IS_MULTIPO=否者 // //=>代表該通路(或該門市)在某一[群分類+大分類]設定下的品項,一定要帶入通路PO單號, // //但同門市、同進貨日、同品號、同期別的狀況下,不允許有不同PO單號 // #region // for (Int32 x = 0; x <= ds_Excel.Tables[0].Rows.Count - 1; x++) // { // if (s_Store == ds_Excel.Tables[0].Rows[x][2].ToString().Trim() && // s_Item == ds_Excel.Tables[0].Rows[x][3].ToString().Trim() && // s_Period == ds_Excel.Tables[0].Rows[x][4].ToString().Trim() && // s_StAcceptDate == strST_ACCEPT_DATE && // s_PoSourceNo != ds_Excel.Tables[0].Rows[x][0].ToString().Trim()) // { // iPKCount++; // } // if (iPKCount >= 1) // { // strErrMsg = string.Format("『(通路,門市,群分類,大分類)=({0},{1},{2},{3})時不允許多重PO。』", s_ChanNo, s_Store, s_ROOT_NO, s_PMA); // bResultMultiPO = false; // break; // } // } // #endregion // #region // if (bResultMultiPO) // { // paramTemp.Clear(); // paramTemp.Add(s_ChanNo); // paramTemp.Add(s_Store); // paramTemp.Add(s_Item); // paramTemp.Add(s_Period); // paramTemp.Add(s_StAcceptDate); // paramTemp.Add(null); // DataTable dtTempPoDetl = BCO.QueryChainPODetlByFind(paramTemp); // if (dtTempPoDetl != null && dtTempPoDetl.Rows.Count > 0) // { // for (Int32 j = 0; j <= dtTempPoDetl.Rows.Count - 1; j++) // { // if (dtTempPoDetl.Rows[j]["po_source_no"].ToString().Trim() != s_PoSourceNo) // { // strErrMsg = string.Format("『(通路,門市,群分類,大分類)=({0},{1},{2},{3})時不允許多重PO。』", s_ChanNo, s_Store, s_ROOT_NO, s_PMA); // break; // } // } // } // } // #endregion // } // } // } //} //#endregion #endregion #region 4.5 針對MEMO是否為空字串做檢查 //if (strErrMsg.Trim() == string.Empty) //{ // dRow_Temp["MEMO"] = System.DBNull.Value; // dRow_Temp["DATASOURCE"] = s_AP_FileName; //} //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["MEMO"] = strErrMsg; // dRow_Temp["DATASOURCE"] = s_AP_FileName; // 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 bool bResult = Check_TmpData(s_LoginUser, V_SESSION_ID, out i_FileToTemp_Total_count, out i_FileToTemp_Right_count, out i_FileToTemp_Wrong_count); #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(GetNewException(ex).Message); } return arl_Return; #endregion }
private void QueryData() { #region LabelQueryRecordCount.Text = ""; string SessionIDName = string.Format("{0}_{1}", PAGE_DT_01, PageTimeStamp.Value); ALOModel.MaintainChainPO BCO = new ALOModel.MaintainChainPO(ConnectionDB); //DataTable dtMain = null; DataTable Dt = null; try { #region 取得主檔 2009-07-17 cyhsu add ArrayList ParameterList = new ArrayList();//20091113 ParameterList.Clear(); ParameterList.Add(SLP_StoreChain1.Text.Trim() == "" ? null : SLP_StoreChain1.Text.Trim()); //通路 dtMain = BCO.QueryPOSourceNoMainByFind(ParameterList); if (dtMain == null || (dtMain != null && dtMain.Rows.Count <= 0)) { ResultMsgLabel.Text = "通路主檔查無資料"; hdCanAddMain.Value = "1"; //可新增主檔 return; } hdCanAddMain.Value = "0"; //不可新增主檔 #endregion #region 取得明細 2009-07-17 cyhsu add // Dt = BCO.QueryChainPOByFind(GetInputValues()); Dt = BCO.QueryChainPODetlByFind2(GetDetlCondition()); #endregion Session[SessionIDName] = Dt; dtForMasterAndDetail = Dt; SmartGridView1.Visible = true; SmartGridView1.PageSize = (TextBoxPagesize.Text == "") ? 10 : (int.Parse(TextBoxPagesize.Text) <= 0) ? 10 : int.Parse(TextBoxPagesize.Text); SmartGridView1.PageIndex = 0; SmartGridView1.DataSource = Dt; SmartGridView1.DataBind(); LabelQueryRecordCount.Text = string.Format(" {0} Rows ", Dt.Rows.Count.ToString()); if (Dt == null || (Dt != null && Dt.Rows.Count <= 0)) { SmartGridView1.Visible = false; ResultMsgLabel.Text = "明細檔查無資料"; } //20090722 modified BindingMasterDetailData(0); LastPageMode = PageCurrentMode.Query; CurrentPageMode = PageCurrentMode.Readonly; } catch (Exception ex) { ErrorMsgLabel.Text = ex.Message; } #endregion }
private bool CheckPOSourceNO(string s_ChanNo, string s_Store, string s_StAcceptDate, string s_PoSourceNo, TextBox txt_POSourceNo, out string strErrMsg) { #region bool bResult = true; strErrMsg = ""; try { DataTable dtTemp = dtStorePOSetting; ALOModel.MaintainChainPO BCO = new ALOModel.MaintainChainPO(ConnectionDB); ALOModel.QueryALOCommon BCO2 = new ALOModel.QueryALOCommon(ConnectionDB); ArrayList ParameterList1 = new ArrayList(); if (dtTemp != null && dtTemp.Rows.Count > 0) { #region for (Int32 i = 0; i <= dtTemp.Rows.Count - 1; i++) { //1.根據[DI.群分類+大分類],由[dtStorePOSetting]過濾取得對應通路PO單號控制資訊。 if (s_ROOT_NO == dtTemp.Rows[i]["root_no"].ToString().Trim() && s_PMA == dtTemp.Rows[i]["pma"].ToString().Trim()) { if (dtTemp.Rows[i]["is_dis_bypo"].ToString().Trim() == "0") { if (s_PoSourceNo != "")//2.若查詢之IS_DIS_BYPO=否,則PO單號必須為空白,清空PO單號,並顯示訊息提示使用者。 { #region 不可輸入PO單號 strErrMsg = string.Format("『(通路,門市,群分類,大分類)=({0},{1},{2},{3})時不可輸入通路單號。』", s_ChanNo, s_Store, s_ROOT_NO, s_PMA); txt_POSourceNo.Text = ""; bResult = false; break; #endregion } } else if (dtTemp.Rows[i]["is_dis_bypo"].ToString().Trim() == "1") { if (s_PoSourceNo == "")//3.若IS_DIS_BYPO=是 =>PO單號為必填欄位,檢查是否正確輸入。異常則顯示錯誤訊息,提示使用者。 { #region PO單號為必填 strErrMsg = string.Format("『請輸入通路單號。』"); bResult = false; break; #endregion } #region old //if (dtTemp.Rows[i]["is_multipo"].ToString().Trim() == "0")//4.若IS_DIS_BYPO=是,且IS_MULTIPO=否,=>檢查同品號/期別/門市進貨日/門市是否存在不同PO,若存在則顯示錯誤訊息,不允許更新。 //{ // #region // if (bResult) // { // DataTable dtTempMD = dtDisStore; // for (Int32 k = 0; k <= dtTempMD.Rows.Count - 1; k++) // { // if (dtTempMD.Rows[k]["chan_no"].ToString().Trim() == s_ChanNo && // dtTempMD.Rows[k]["store"].ToString().Trim() == s_Store && // dtTempMD.Rows[k]["item"].ToString().Trim() == s_ITEM && // dtTempMD.Rows[k]["period"].ToString().Trim() == s_PERIOD && // //dtTempMD.Rows[k]["st_accept_date"].ToString().Trim() == s_StAcceptDate &&//todo need to check // dtTempMD.Rows[k]["po_source_no"].ToString().Trim() != s_PoSourceNo && // k != i_CurrentIndexInDisStore) // { // strErrMsg = string.Format("『(通路,門市,群分類,大分類)=({0},{1},{2},{3})時不允許多重PO。』", s_ChanNo, s_Store, s_ROOT_NO, s_PMA); // bResult = false; // break; // } // } // } // #endregion // #region // if (bResult) // { // ParameterList1.Clear(); // ParameterList1.Add(s_ChanNo); // ParameterList1.Add(s_Store); // ParameterList1.Add(s_ITEM); // ParameterList1.Add(s_PERIOD); // ParameterList1.Add(s_StAcceptDate); // ParameterList1.Add(null); // DataTable dtTempPoDetl = BCO.QueryChainPODetlByFind(ParameterList1); // if (dtTempPoDetl != null && dtTempPoDetl.Rows.Count > 0) // { // for (Int32 j = 0; j <= dtTempPoDetl.Rows.Count - 1; j++) // { // if (dtTempPoDetl.Rows[j]["po_source_no"].ToString().Trim() != s_PoSourceNo) // { // strErrMsg = string.Format("『(通路,門市,群分類,大分類)=({0},{1},{2},{3})時不允許多重PO。』", s_ChanNo, s_Store, s_ROOT_NO, s_PMA); // bResult = false; // break; // } // } // } // } // #endregion //} #endregion if (bResult) { #region DataTable dtTempMD = dtDisStore; for (Int32 k = 0; k <= dtTempMD.Rows.Count - 1; k++) { if (dtTempMD.Rows[k]["chan_no"].ToString().Trim() == s_ChanNo && dtTempMD.Rows[k]["store"].ToString().Trim() == s_Store && dtTempMD.Rows[k]["item"].ToString().Trim() == s_ITEM && dtTempMD.Rows[k]["period"].ToString().Trim() == s_PERIOD && dtTempMD.Rows[k]["po_source_no"].ToString().Trim() != s_PoSourceNo && k != i_CurrentIndexInDisStore) { ParameterList1.Clear(); ParameterList1.Add(s_StAcceptDate); ParameterList1.Add(dtTemp.Rows[i]["is_dis_bypo"].ToString().Trim()); ParameterList1.Add(dtTemp.Rows[i]["is_multipo"].ToString().Trim()); ParameterList1.Add(s_ROOT_NO); ParameterList1.Add(s_PMA); ParameterList1.Add(s_ITEM); ParameterList1.Add(s_PERIOD); ParameterList1.Add(s_ChanNo); ParameterList1.Add(s_Store); ParameterList1.Add(s_PoSourceNo); ParameterList1.Add(Session["UID"].ToString()); bResult = BCO2.CheckPODuplicate(ParameterList1, out strErrMsg); if (!bResult) break; } } #endregion } } } } #endregion } #region #region if (bResult) { DataTable dtTempMD = dtDisStore; for (Int32 k = 0; k <= dtTempMD.Rows.Count - 1; k++) { if (dtTempMD.Rows[k]["chan_no", DataRowVersion.Current].ToString().Trim() == s_ChanNo && dtTempMD.Rows[k]["store", DataRowVersion.Current].ToString().Trim() == s_Store && dtTempMD.Rows[k]["item", DataRowVersion.Current].ToString().Trim() == s_ITEM && dtTempMD.Rows[k]["period", DataRowVersion.Current].ToString().Trim() == s_PERIOD && //dtTempMD.Rows[k]["st_accept_date"].ToString().Trim() == s_StAcceptDate &&//todo need to check dtTempMD.Rows[k]["po_source_no", DataRowVersion.Current].ToString().Trim() == s_PoSourceNo && k != i_CurrentIndexInDisStore) { strErrMsg = string.Format("『PK重複(通路,門市,群分類,大分類,進貨日,PO單號)=({0},{1},{2},{3},{4},{5})。』", s_ChanNo, s_Store, s_ROOT_NO, s_PMA, s_StAcceptDate, s_PoSourceNo); bResult = false; break; } } } #endregion #region if (bResult) { ParameterList1.Clear(); ParameterList1.Add(s_ChanNo); ParameterList1.Add(s_Store); ParameterList1.Add(s_ITEM); ParameterList1.Add(s_PERIOD); ParameterList1.Add(s_StAcceptDate); ParameterList1.Add(s_PoSourceNo); bool bTemp = BCO.CheckChainPODetlIsExistedByFind(ParameterList1); if (bTemp) { strErrMsg = string.Format("『PK重複(通路,門市,群分類,大分類,進貨日,PO單號)=({0},{1},{2},{3},{4},{5})。』", s_ChanNo, s_Store, s_ROOT_NO, s_PMA, s_StAcceptDate, s_PoSourceNo); bResult = false; } } #endregion #endregion } catch (Exception ex) { ErrorMsgLabel.Text = ex.Message; } return bResult; #endregion }
protected void btn_DeleteToDB_Click(object sender, EventArgs e) { #region try { bool bResult = false; #region 取得畫面元件的值 DateTime processtime = DateTime.Now; #endregion #region 取得刪除前舊值 DataTable dtTemp = dtMain;//20090722 modified:dtForMasterAndDetail if (dtTemp == null || dtTemp.Rows.Count == 0) { throw new Exception("抓取不到舊值,更新失敗!"); } #endregion #region 加入更新條件 //master htParams.Clear(); //舊值 htParams.Add("ID", dtTemp.Rows[0]["ID"]); htParams.Add("CODE", dtTemp.Rows[0]["CODE"]); htParams.Add("CREATEDATE", dtTemp.Rows[0]["CREATEDATE"]); htParams.Add("CREATEUID", dtTemp.Rows[0]["CREATEUID"]); htParams.Add("UPDATEDATE", dtTemp.Rows[0]["UPDATEDATE"]); htParams.Add("UPDATEUID", dtTemp.Rows[0]["UPDATEUID"]); htParams.Add("ENABLE", dtTemp.Rows[0]["ENABLE"]); htParams.Add("TYPE_RULE", dtTemp.Rows[0]["TYPE_RULE"]); htParams.Add("CHAN_NO", dtTemp.Rows[0]["CHAN_NO"]); htParams.Add("TRACK", dtTemp.Rows[0]["TRACK"]); htParams.Add("TYPE_NO", dtTemp.Rows[0]["TYPE_NO"]); htParams.Add("PO_SOURCE_NO_ST", dtTemp.Rows[0]["PO_SOURCE_NO_ST"]); htParams.Add("PO_SOURCE_NO_END", dtTemp.Rows[0]["PO_SOURCE_NO_END"]); htParams.Add("SEQ_NO", dtTemp.Rows[0]["SEQ_NO"]); htParams.Add("ROOT_NO", dtTemp.Rows[0]["ROOT_NO"]); //需要更新值 htParams.Add("NEW_UPDATEDATE", processtime); htParams.Add("NEW_UPDATEUID", Session["UID"].ToString()); //detail htParams2.Clear(); htParams2.Add("PIDForLog", dtTemp.Rows[0]["ID"]); htParams2.Add("UIDForLog", dtTemp.Rows[0]["CREATEUID"]); #endregion ALOModel.MaintainChainPO BCO = new ALOModel.MaintainChainPO(ConnectionDB); bResult = BCO.DeleteMasterAndDetail(htParams, htParams2, null); CurrentPageMode = PageCurrentMode.Query; ResultMsgLabel.Text = "刪除完成"; } catch (Exception ex) { ErrorMsgLabel.Text = ex.Message; } #endregion }
private void MakeDataTableForMaster() { #region DataTable dtM = new DataTable(); ALOModel.MaintainChainPO BCO = new ALOModel.MaintainChainPO(ConnectionDB); dtM = BCO.GetPOSourceNOSchema(); dtForMasterAndDetail = dtM; #endregion }
protected void btn_SaveToDB_Click(object sender, EventArgs e) { #region if (CurrentPageMode == PageCurrentMode.Edit) { #region bool bResult = false; try { #region 取得畫面元件的值 DateTime processtime = DateTime.Now; #endregion DataTable dtForUpdate = dtForMasterAndDetail.GetChanges(); DataTable dtMaster = dtMain;//20090717 modified string strUID = Session["UID"].ToString(); #region Master htParams.Clear(); for (Int32 i = 0; i <= dtMaster.Rows.Count - 1; i++) { #region //舊的資料 htParams.Add("ID", dtMaster.Rows[i]["ID", DataRowVersion.Original]); htParams.Add("CODE", dtMaster.Rows[i]["CODE", DataRowVersion.Original]); htParams.Add("NAME", dtMaster.Rows[i]["NAME", DataRowVersion.Original]); htParams.Add("CREATEDATE", dtMaster.Rows[i]["CREATEDATE", DataRowVersion.Original]); htParams.Add("CREATEUID", dtMaster.Rows[i]["CREATEUID", DataRowVersion.Original]); htParams.Add("UPDATEDATE", dtMaster.Rows[i]["UPDATEDATE", DataRowVersion.Original]); htParams.Add("UPDATEUID", dtMaster.Rows[i]["UPDATEUID", DataRowVersion.Original]); htParams.Add("ENABLE", dtMaster.Rows[i]["ENABLE", DataRowVersion.Original]); htParams.Add("TYPE_RULE", dtMaster.Rows[i]["TYPE_RULE", DataRowVersion.Original]); htParams.Add("CHAN_NO", dtMaster.Rows[i]["CHAN_NO", DataRowVersion.Original]); htParams.Add("TRACK", dtMaster.Rows[i]["TRACK", DataRowVersion.Original]); htParams.Add("TYPE_NO", dtMaster.Rows[i]["TYPE_NO", DataRowVersion.Original]); htParams.Add("PO_SOURCE_NO_ST", dtMaster.Rows[i]["PO_SOURCE_NO_ST", DataRowVersion.Original]); htParams.Add("PO_SOURCE_NO_END", dtMaster.Rows[i]["PO_SOURCE_NO_END", DataRowVersion.Original]); htParams.Add("SEQ_NO", dtMaster.Rows[i]["SEQ_NO", DataRowVersion.Original]); htParams.Add("ROOT_NO", dtMaster.Rows[i]["ROOT_NO", DataRowVersion.Original]); //新的資料 htParams.Add("NEW_UPDATEDATE", processtime); htParams.Add("NEW_UPDATEUID", strUID); htParams.Add("NEW_TYPE_RULE", ddl_GetNumberRule.SelectedValue.ToString().Trim()); htParams.Add("NEW_TRACK", txt_track.Text.Trim() == "" ? null : txt_track.Text.Trim()); htParams.Add("NEW_TYPE_NO", SLP_EnumBase1.Text); htParams.Add("NEW_PO_SOURCE_NO_ST", txt_PoSource_St.Text.Trim() == "" ? null : txt_PoSource_St.Text.Trim()); htParams.Add("NEW_PO_SOURCE_NO_END", txt_PoSource_End.Text.Trim() == "" ? null : txt_PoSource_End.Text.Trim()); htParams.Add("NEW_SEQ_NO", txt_PoSource_Final.Text.Trim() == "" ? null : txt_PoSource_Final.Text.Trim()); break; #endregion } #endregion ALOModel.MaintainChainPO BCO = new ALOModel.MaintainChainPO(ConnectionDB); bResult = BCO.UpdateMasterAndDetail(htParams, dtForUpdate, strUID, dtForDetailDeleted, null); if (!bResult) { throw new Exception("更新0筆資料!"); } else { QueryData(); CurrentPageMode = PageCurrentMode.Readonly; ResultMsgLabel.Text = "更改完成"; } } catch (Exception ex) { ErrorMsgLabel.Text = ex.Message; } #endregion } else if (CurrentPageMode == PageCurrentMode.Insert) { #region Int32 iResult = 0; DateTime processtime = DateTime.Now; try { #region DataTable dtForUpdate = dtForMasterAndDetail.GetChanges(DataRowState.Added); #region Master string strCode = string.Format("{0}", SLP_StoreChain1.Text.Trim()); htParams.Clear(); htParams.Add("CODE", strCode); htParams.Add("NAME", "");//todo 20080222 htParams.Add("CREATEDATE", processtime); htParams.Add("CREATEUID", Session["UID"].ToString()); htParams.Add("UPDATEDATE", processtime); htParams.Add("UPDATEUID", Session["UID"].ToString()); htParams.Add("TYPE_RULE", ddl_GetNumberRule.SelectedValue.ToString().Trim()); htParams.Add("CHAN_NO", SLP_StoreChain1.Text); htParams.Add("TRACK", txt_track.Text.Trim()); htParams.Add("TYPE_NO", SLP_EnumBase1.Text); htParams.Add("PO_SOURCE_NO_ST", txt_PoSource_St.Text.Trim() == "" ? null : txt_PoSource_St.Text.Trim()); htParams.Add("PO_SOURCE_NO_END", txt_PoSource_End.Text.Trim() == "" ? null : txt_PoSource_End.Text.Trim()); htParams.Add("SEQ_NO", txt_PoSource_Final.Text.Trim() == "" ? null : txt_PoSource_Final.Text.Trim()); htParams.Add("ROOT_NO", s_ROOT_NO); #endregion ALOModel.MaintainChainPO BCO = new ALOModel.MaintainChainPO(ConnectionDB); iResult = BCO.CreateMasterAndDetail(htParams, dtForUpdate, null); if (iResult == 0) { throw new Exception("新增0筆資料!"); } else { QueryData(); CurrentPageMode = PageCurrentMode.Readonly; ResultMsgLabel.Text = "新增完成"; } #endregion } catch (Exception ex) { if (ex.Message.IndexOf("新增資料失敗") != -1) { ErrorMsgLabel.Text = string.Format("輸入通路:{0},主檔已存在,請查詢後編輯。", SLP_StoreChain1.Text); } else { ErrorMsgLabel.Text = ex.Message; } } #endregion } #endregion }
private bool CheckCanAddMain(string strChanNo) { bool bResult = true; if (hdCanAddMain.Value == "0") { bResult = false; } else { if (CurrentPageMode == PageCurrentMode.Insert && strChanNo != string.Empty) { #region 取得主檔 ArrayList ParameterList = new ArrayList();//20091113 ParameterList.Clear(); ParameterList.Add(strChanNo); //通路 ALOModel.MaintainChainPO BCO = new ALOModel.MaintainChainPO(ConnectionDB); DataTable dtTmp = BCO.QueryPOSourceNoMainByFind(ParameterList); if (dtTmp == null || (dtTmp != null && dtTmp.Rows.Count == 0)) { hdCanAddMain.Value = "1"; //可新增主檔 } else { bResult = false; hdCanAddMain.Value = "0"; //不可新增主檔 } BCO = null; dtTmp.Dispose(); #endregion } } return bResult; }
private bool CheckPOSourceNO(ref string strErrMsg) { #region bool bResult = true; s_ChanNo = SLP_StoreChain1.Text; s_Store = SLP_Store2.Text; s_Item = SLP_SKU2.Text; s_Period = SLP_ItemPeriod1.Text; s_StAcceptDate = SLP_SLPDate2.Text; s_PoSourceNo = txt_POSourceNo.Text.Trim(); ArrayList ParameterList = new ArrayList();//20091113 ArrayList ParameterList1 = new ArrayList();//20091113 #region 比對是否 PK重複 #region 先比對頁面資料 DataTable dtTempMD = dtForMasterAndDetail; dtTempMD.PrimaryKey = new DataColumn[] { dtTempMD.Columns["chan_no"], dtTempMD.Columns["store"], dtTempMD.Columns["item"], dtTempMD.Columns["period"], dtTempMD.Columns["st_accept_date_show"], dtTempMD.Columns["data_source"] //,dtTempMD.Columns["po_source_no"] }; DataRow drFind_1 = dtTempMD.Rows.Find(new object[] { s_ChanNo, s_Store, s_Item, s_Period, s_StAcceptDate, 1 //,s_PoSourceNo }); DataRow drFind_4 = dtTempMD.Rows.Find(new object[] { s_ChanNo, s_Store, s_Item, s_Period, s_StAcceptDate, 4 //,s_PoSourceNo }); if (drFind_1 != null || drFind_4 != null) { //strErrMsg = string.Format("『PK重複,資料已存在於頁面(通路,門市,群分類,大分類,進貨日,PO單號)=({0},{1},{2},{3},{4},{5})。』", // s_ChanNo, s_Store, s_ROOT_NO, s_PMA, s_StAcceptDate, s_PoSourceNo); strErrMsg = string.Format("『PK重複,手動匯入或通路單號匯入資料已存在於頁面(通路,門市,品號,期別進貨日)=({0},{1},{2},{3},{4})。』", s_ChanNo, s_Store, s_Item, s_Period, s_StAcceptDate); bResult = false; return bResult; } #endregion #region 比對待新增明細與實體資料庫 ALOModel.MaintainChainPO BCO = new ALOModel.MaintainChainPO(ConnectionDB); ParameterList1.Clear(); ParameterList1.Add(s_ChanNo); ParameterList1.Add(s_Store); ParameterList1.Add(s_Item); ParameterList1.Add(s_Period); ParameterList1.Add(s_StAcceptDate); ParameterList1.Add(s_PoSourceNo); bool bDataExist = BCO.CheckChainPODetlIsExistedByFind(ParameterList1); if (bDataExist) { strErrMsg = string.Format("『PK重複,資料已存在於實體資料表(通路,門市,品號,期別,進貨日,PO單號)=({0},{1},{2},{3},{4},{5})。』", s_ChanNo, s_Store, s_Item, s_Period, s_StAcceptDate, s_PoSourceNo); bResult = false; return bResult; } #region 只檢查單店/品項/進貨日 ParameterList1.Clear(); ParameterList1.Add(s_ChanNo); ParameterList1.Add(s_Store); ParameterList1.Add(s_Item); ParameterList1.Add(s_Period); ParameterList1.Add(s_StAcceptDate); ParameterList1.Add(""); bDataExist = BCO.CheckChainPODetlIsExistedByFind(ParameterList1); if (bDataExist) { strErrMsg = string.Format("『PK重複,資料已存在於實體資料表(通路,門市,品號,期別,進貨日)=({0},{1},{2},{3},{4})。』", s_ChanNo, s_Store, s_Item, s_Period, s_StAcceptDate); bResult = false; return bResult; } #endregion #endregion #endregion ALOModel.MaintainChainPOSetting BCO2 = new ALOModel.MaintainChainPOSetting(ConnectionDB); #region 依照品號取得所屬[群分類]、[大分類] ParameterList.Clear(); BCO_ITM.SQLHelper.SQLWhere(ref ParameterList, DbType.String, "MA.ITEM", s_Item, "=", "and"); BCO_ITM.MaintainSKU bco_itm = new BCO_ITM.MaintainSKU(ConnectionDB); DataTable dt_Return = bco_itm.QuerySKUByFind_1(ParameterList); if (dt_Return != null && dt_Return.Rows.Count > 0) { s_PMA = dt_Return.Rows[0]["PMA"].ToString();//大分類 s_ROOT_NO = dt_Return.Rows[0]["ROOT_NO"].ToString();//群分類 } #endregion #region 判斷 is_dis_bypo & is_multipo ParameterList1.Clear(); ParameterList1.Add(s_ChanNo); ParameterList1.Add(s_Store); DataTable dtChainPOSetting = BCO2.QueryStorPOSettingByFind(ParameterList1); if (dtChainPOSetting != null && dtChainPOSetting.Rows.Count > 0) { for (Int32 i = 0; i <= dtChainPOSetting.Rows.Count - 1; i++) { if (s_ROOT_NO == dtChainPOSetting.Rows[i]["root_no"].ToString().Trim() && s_PMA == dtChainPOSetting.Rows[i]["pma"].ToString().Trim()) { if (dtChainPOSetting.Rows[i]["is_dis_bypo"].ToString().Trim() == "0") { if (s_PoSourceNo != "")//1.當[IS_DIS_BYPO]=否時,PO單號應不可輸入。 { #region strErrMsg = string.Format("『(通路,門市,群分類,大分類)=({0},{1},{2},{3})時不可輸入通路單號。』", s_ChanNo, s_Store, s_ROOT_NO, s_PMA); bResult = false; rfv_POSourceNo.Enabled = false; break; #endregion } } else if (dtChainPOSetting.Rows[i]["is_dis_bypo"].ToString().Trim() == "1") { if (s_PoSourceNo == "")//2.當[IS_DIS_BYPO]=是時,允許輸入PO單號為必填欄位,應不可為空白。 { #region strErrMsg = string.Format("『請輸入通路單號。』"); bResult = false; break; #endregion } if (dtChainPOSetting.Rows[i]["is_multipo"].ToString().Trim() == "0")//3.當[IS_DIS_BYPO]=是且[IS_MULTIPO]=否時,代表(同門市/品號期別/門市進貨日)下,只能輸入一個PO單號。 { #region if (bResult) { //20090716 modified if (!bDetailEditing)//如果不是編輯狀態 { //檢查頁面暫存檔 //DataTable dtTempMD = dtForMasterAndDetail; DataRow[] dRows = dtTempMD.Select(string.Format("chan_no='{0}' and store='{1}' and item='{2}' and period = '{3}' and st_accept_date_show='{4}' ", s_ChanNo, s_Store, s_Item, s_Period, s_StAcceptDate)); if (dRows.Length > 0) { strErrMsg = string.Format("『(通路,門市,群分類,大分類)=({0},{1},{2},{3})時,只能輸入一個PO單號』", s_ChanNo, s_Store, s_ROOT_NO, s_PMA); bResult = false; } //檢查資料庫 ParameterList1.Clear(); ParameterList1.Add(s_ChanNo); ParameterList1.Add(s_Store); ParameterList1.Add(s_Item); ParameterList1.Add(s_Period); ParameterList1.Add(s_StAcceptDate); ParameterList1.Add(null); bool bTemp = BCO.CheckChainPODetlIsExistedByFind(ParameterList1); if (bTemp) { strErrMsg = string.Format("『(通路,門市,群分類,大分類,進貨日)=({0},{1},{2},{3},{4})時,只能輸入一個PO單號』", s_ChanNo, s_Store, s_ROOT_NO, s_PMA, s_StAcceptDate); bResult = false; } } } #endregion } else if (dtChainPOSetting.Rows[i]["is_multipo"].ToString().Trim() == "1")//3.當[IS_DIS_BYPO]=是且[IS_MULTIPO]=是時,代表(同門市/品號期別/門市進貨日)下,允許多重PO。 { #region if (bResult) { ParameterList1.Clear(); ParameterList1.Add(s_ChanNo); ParameterList1.Add(s_Store); ParameterList1.Add(s_Item); ParameterList1.Add(s_Period); ParameterList1.Add(s_StAcceptDate); ParameterList1.Add(s_PoSourceNo); DataTable dtTempPoDetl = BCO.QueryChainPODetlByFind(ParameterList1); if (dtTempPoDetl != null && dtTempPoDetl.Rows.Count > 0) { for (Int32 j = 0; j <= dtTempPoDetl.Rows.Count - 1; j++) { if (dtTempPoDetl.Rows[j]["po_source_no"].ToString().Trim() != s_PoSourceNo) { strErrMsg = string.Format("『(通路,門市,群分類,大分類)=({0},{1},{2},{3})時不允許多重PO。』", s_ChanNo, s_Store, s_ROOT_NO, s_PMA); bResult = false; break; } } } } #endregion } } } } } #endregion return bResult; #endregion }
/// <summary> /// FileToTmp 效能提升版 /// </summary> /// <param name="ds_Excel"></param> /// <param name="d_CreateDate"></param> /// <param name="s_LoginUser"></param> /// <param name="s_AP_FileName"></param> /// <param name="strDIS_DATE"></param> /// <param name="strST_ACCEPT_DATE"></param> /// <param name="iImportType"></param> /// <param name="V_SESSION_ID"></param> /// <returns></returns> public ArrayList FileToTmp2(DataSet ds_Excel, DateTime d_CreateDate, string s_LoginUser, string s_AP_FileName, string strDIS_DATE, string strST_ACCEPT_DATE, Int32 iImportType, string V_SESSION_ID) { #region int i_newTable_Count = 0; ArrayList arl_Return = new ArrayList(); ArrayList arr_CheckData_Table = new ArrayList(); ArrayList arr_CheckData = 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(); DataTable dtTemp = new DataTable(); string strErrMsg = ""; Int32 iErrCount = 0; Int32 iPKCount = 0; try { ParameterList.Clear(); DataTable dt_ALO_IMPORT_TMP = QuerySwitch(QueryType.GetDISRECORD_TmpSchema, ParameterList); VDS_ALO_DISRECORD_TMP_DBO ALO_DISRECORD_TMP = new VDS_ALO_DISRECORD_TMP_DBO(ref USEDB); MaintainChainPO BCO = new MaintainChainPO(ConnectionDB); MaintainChainPOSetting BCO2 = new MaintainChainPOSetting(ConnectionDB); string s_ROOT_NO = ""; string s_PMA = ""; string s_ChanNo = ""; string s_Store = ""; string s_Item = ""; string s_Period = ""; string s_StAcceptDate = ""; string s_PoSourceNo = ""; bool bResultMultiPO = true; string strErrMsgDataFormat = ""; Int32 iTaxType; VDS_ALO_DISRECORD_TMP_DBO DBO = new VDS_ALO_DISRECORD_TMP_DBO(ref USEDB); ParameterList.Clear(); ParameterList.Add(s_LoginUser); ParameterList.Add(V_SESSION_ID); DBO.doDelete_DISRECORD_TMP2(ParameterList, null); foreach (System.Data.DataRow dRow in ds_Excel.Tables[0].Rows) { #region iErrCount = 0; iPKCount = 0; strErrMsg = ""; s_ROOT_NO = ""; s_PMA = ""; s_ChanNo = dRow[1].ToString().Trim(); s_Store = dRow[2].ToString().Trim(); s_Item = dRow[3].ToString().Trim(); s_Period = dRow[4].ToString().Trim(); s_StAcceptDate = strST_ACCEPT_DATE; s_PoSourceNo = dRow[0].ToString().Trim(); bResultMultiPO = true; if (!CheckRequiredField(dRow, iAryRequiredColumnsCheck, out strErrMsgDataFormat))//檢查必填欄位 { #region 檢查資料格式正確性 arl_Return.Add("FALSE"); arl_Return.Add(strErrMsgDataFormat); return arl_Return; }// 2009-05-10 iAryNeedToCheckColumns -> iAryLengthCheckColumns 原只檢查必填,新增多檢查PO單號。 else if (!CheckOverFlow(dRow, iAryOverflowColumnsCheck, out strErrMsgDataFormat))//檢查是否為溢位 { arl_Return.Add("FALSE"); arl_Return.Add(strErrMsgDataFormat); return arl_Return; } else if (!CheckInputValueIsInt32(dRow, iAryRequiredColumnsCheck, out strErrMsgDataFormat))//檢查是否為數值 { arl_Return.Add("FALSE"); arl_Return.Add(strErrMsgDataFormat); return arl_Return; #endregion } else { #region 將資料寫入 TEMP TABLE DataRow dRow_Temp = dt_ALO_IMPORT_TMP.NewRow(); dRow_Temp["CREATEDATE"] = d_CreateDate; dRow_Temp["CREATEUID"] = s_LoginUser; dRow_Temp["ID"] = i_newTable_Count; dRow_Temp["UPDATEDATE"] = d_CreateDate; dRow_Temp["UPDATEUID"] = s_LoginUser; dRow_Temp["CHAN_NO"] = dRow[1].ToString().Trim(); dRow_Temp["STORE"] = dRow[2].ToString().Trim(); dRow_Temp["ITEM"] = dRow[3].ToString().Trim(); dRow_Temp["PERIOD"] = dRow[4].ToString().Trim(); dRow_Temp["PO_SOURCE_NO"] = dRow[0].ToString().Trim(); dRow_Temp["ST_ACCEPT_DATE"] = strST_ACCEPT_DATE; dRow_Temp["dis_date"] = strDIS_DATE; dRow_Temp["dis_qty"] = dRow[5].ToString().Trim(); dRow_Temp["dis_no"] = ""; dRow_Temp["imp_type"] = iImportType; dRow_Temp["SESSION_ID"] = V_SESSION_ID; dRow_Temp["DATASOURCE"] = s_AP_FileName; //------------------------------------- #endregion dt_ALO_IMPORT_TMP.Rows.Add(dRow_Temp); i_newTable_Count += 1; } i_FileToTemp_Total_count += 1; #endregion } #region 先清除前一次,同一使用者執行的匯入暫存資訊與錯誤資訊,並將 Excel 資料匯入 TEMP TABLE ParameterList.Clear(); ParameterList.Add(s_LoginUser); ParameterList.Add(V_SESSION_ID); DELETE_AND_INSERT_TEMP_TABLE(ParameterList, null, dt_ALO_IMPORT_TMP); #endregion //效能提升版的地方---------------------------------------------------------------------------------- #region 檢查資料邏輯正確性 bool bResult = Check_TmpData(s_LoginUser, V_SESSION_ID, out i_FileToTemp_Total_count, out i_FileToTemp_Right_count, out i_FileToTemp_Wrong_count); #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(GetNewException(ex).Message); } return arl_Return; #endregion }
/// <summary> ///1.目的:將上傳檔案內容,存入暫存檔 ///2.傳入參數:@處理檔名、@使用者 /// 回傳參數:@處理筆數、@正確筆數、@錯誤筆數、@錯誤訊息 ///3.處理表格:VDS_ALO_STORESPEC_TMP(T) ///4.處理邏輯: /// 4.1) 先清除前一次,同一使用者執行的匯入暫存資訊與錯誤資訊。 /// 相關Table:VDS_ALO_STORESPEC_TM /// 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, string strDIS_DATE, string strST_ACCEPT_DATE, Int32 iImportType, string V_SESSION_ID) { #region int i_newTable_Count = 0; ArrayList arl_Return = new ArrayList(); ArrayList arr_CheckData_Table = new ArrayList(); ArrayList arr_CheckData = 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(); DataTable dtTemp = new DataTable(); string strErrMsg = ""; Int32 iErrCount = 0; Int32 iPKCount = 0; try { ParameterList.Clear(); DataTable dt_ALO_IMPORT_TMP = QuerySwitch(QueryType.GetDISRECORD_TmpSchema, ParameterList); VDS_ALO_DISRECORD_TMP_DBO ALO_DISRECORD_TMP = new VDS_ALO_DISRECORD_TMP_DBO(ref USEDB); MaintainChainPO BCO = new MaintainChainPO(ConnectionDB); MaintainChainPOSetting BCO2 = new MaintainChainPOSetting(ConnectionDB); string s_ROOT_NO = ""; string s_PMA = ""; string s_ChanNo = ""; string s_Store = ""; string s_Item = ""; string s_Period = ""; string s_StAcceptDate = ""; string s_PoSourceNo = ""; bool bResultMultiPO = true; string strErrMsgDataFormat = ""; Int32 iTaxType; //20090728 added VDS_ALO_DISRECORD_TMP_DBO DBO = new VDS_ALO_DISRECORD_TMP_DBO(ref USEDB); ParameterList.Clear(); ParameterList.Add(s_LoginUser); ParameterList.Add(V_SESSION_ID); DBO.doDelete_DISRECORD_TMP2(ParameterList, null); foreach (System.Data.DataRow dRow in ds_Excel.Tables[0].Rows) { #region iErrCount = 0; iPKCount = 0; strErrMsg = ""; s_ROOT_NO = ""; s_PMA = ""; s_ChanNo = dRow[1].ToString().Trim(); s_Store = dRow[2].ToString().Trim(); s_Item = dRow[3].ToString().Trim(); s_Period = dRow[4].ToString().Trim(); s_StAcceptDate = strST_ACCEPT_DATE; s_PoSourceNo = dRow[0].ToString().Trim(); bResultMultiPO = true; if (!CheckRequiredField(dRow, iAryRequiredColumnsCheck, out strErrMsgDataFormat))//檢查必填欄位 { #region 檢查資料格式正確性 arl_Return.Add("FALSE"); arl_Return.Add(strErrMsgDataFormat); return arl_Return; }// 2009-05-10 iAryNeedToCheckColumns -> iAryLengthCheckColumns 原只檢查必填,新增多檢查PO單號。 else if (!CheckOverFlow(dRow, iAryOverflowColumnsCheck, out strErrMsgDataFormat))//檢查是否為溢位 { arl_Return.Add("FALSE"); arl_Return.Add(strErrMsgDataFormat); return arl_Return; } else if (!CheckInputValueIsInt32(dRow, iAryRequiredColumnsCheck, out strErrMsgDataFormat))//檢查是否為數值 { arl_Return.Add("FALSE"); arl_Return.Add(strErrMsgDataFormat); return arl_Return; #endregion } else { #region 檢查資料邏輯正確性 #region 將資料寫入 TEMP TABLE DataRow dRow_Temp = dt_ALO_IMPORT_TMP.NewRow(); dRow_Temp["CREATEDATE"] = d_CreateDate; dRow_Temp["CREATEUID"] = s_LoginUser; dRow_Temp["ID"] = i_newTable_Count; dRow_Temp["UPDATEDATE"] = d_CreateDate; dRow_Temp["UPDATEUID"] = s_LoginUser; dRow_Temp["CHAN_NO"] = dRow[1].ToString().Trim(); dRow_Temp["STORE"] = dRow[2].ToString().Trim(); dRow_Temp["ITEM"] = dRow[3].ToString().Trim(); dRow_Temp["PERIOD"] = dRow[4].ToString().Trim(); dRow_Temp["PO_SOURCE_NO"] = dRow[0].ToString().Trim(); dRow_Temp["ST_ACCEPT_DATE"] = strST_ACCEPT_DATE; dRow_Temp["dis_date"] = strDIS_DATE; dRow_Temp["dis_qty"] = dRow[5].ToString().Trim(); dRow_Temp["dis_no"] = ""; dRow_Temp["imp_type"] = iImportType; dRow_Temp["SESSION_ID"] = V_SESSION_ID; //------------------------------------- #endregion #region 4.1 驗證新增資料之主檔欄位正確性。 paramTemp.Clear(); paramTemp.Add(dRow[1].ToString().Trim()); paramTemp.Add(dRow[2].ToString().Trim()); paramTemp.Add(dRow[3].ToString().Trim()); paramTemp.Add(dRow[4].ToString().Trim()); DataTable dtCheckMaster = ALO_DISRECORD_TMP.doCheckCurrentMasterStatus(paramTemp); if (dtCheckMaster.Rows[0][0].ToString().Trim() != "1") { strErrMsg += dtCheckMaster.Rows[0][1].ToString().Trim(); } dRow_Temp["root_no"] = dtCheckMaster.Rows[0]["ROOT_NO"].ToString().Trim(); dRow_Temp["pma"] = dtCheckMaster.Rows[0]["PMA"].ToString().Trim(); dRow_Temp["pattern_no"] = dtCheckMaster.Rows[0]["PATTERN_NO"].ToString().Trim(); Int32.TryParse(dtCheckMaster.Rows[0]["TAX_TYPE"].ToString().Trim(), out iTaxType); dRow_Temp["tax_type"] = iTaxType; #endregion #region 4.2 檢查門市是否可配送。 paramTemp.Clear(); paramTemp.Add(s_ChanNo); paramTemp.Add(s_Store); paramTemp.Add(s_StAcceptDate); DataTable dtCheckDisAvaliable = ALO_DISRECORD_TMP.doCheckIsDisAvailbale(paramTemp); if (!(dtCheckDisAvaliable == null || dtCheckDisAvaliable.Rows[0][0].ToString().Trim() != "0")) { strErrMsg += "主檔設定不可配送,"; } #endregion #region 4.3 通路PO控制檔檢查 if (s_PoSourceNo != "") { #region 依照品號取得所屬[群分類]、[大分類] paramTemp.Clear(); BCO_ITM.SQLHelper.SQLWhere(ref paramTemp, DbType.String, "MA.ITEM", s_Item, "=", "and"); BCO_ITM.MaintainSKU bco_itm = new BCO_ITM.MaintainSKU(ConnectionDB); DataTable dt_Return = bco_itm.QuerySKUByFind_1(paramTemp); if (dt_Return != null && dt_Return.Rows.Count != 0) { s_PMA = dt_Return.Rows[0]["PMA"].ToString();//大分類 s_ROOT_NO = dt_Return.Rows[0]["ROOT_NO"].ToString();//群分類 } #endregion #region 判斷 is_dis_bypo & is_multipo paramTemp.Clear(); paramTemp.Add(s_ChanNo); paramTemp.Add(s_Store); DataTable dtTempPOSetting = BCO2.QueryStorPOSettingByFind(paramTemp); if (dtTempPOSetting != null && dtTempPOSetting.Rows.Count > 0) { for (Int32 i = 0; i <= dtTempPOSetting.Rows.Count - 1; i++) { if (s_ROOT_NO == dtTempPOSetting.Rows[i]["root_no"].ToString().Trim() && s_PMA == dtTempPOSetting.Rows[i]["pma"].ToString().Trim()) { if (dtTempPOSetting.Rows[i]["is_dis_bypo"].ToString().Trim() == "0") { //1.IS_DIS_BYPO=否者 //=>代表該通路(或該門市)在某一[群分類+大分類]設定下的品項,不可帶入通路PO單號 if (s_PoSourceNo != "") { #region strErrMsg += string.Format("(通路,門市,群分類,大分類)=({0},{1},{2},{3})不可匯入通路單號", s_ChanNo, s_Store, s_ROOT_NO, s_PMA); break; #endregion } } else if (dtTempPOSetting.Rows[i]["is_dis_bypo"].ToString().Trim() == "1" && dtTempPOSetting.Rows[i]["is_multipo"].ToString().Trim() == "0") { //2.IS_DIS_BYPO=是,且IS_MULTIPO=否者 //=>代表該通路(或該門市)在某一[群分類+大分類]設定下的品項,一定要帶入通路PO單號, //但同門市、同進貨日、同品號、同期別的狀況下,不允許有不同PO單號 #region for (Int32 x = 0; x <= ds_Excel.Tables[0].Rows.Count - 1; x++) { if (s_Store == ds_Excel.Tables[0].Rows[x][2].ToString().Trim() && s_Item == ds_Excel.Tables[0].Rows[x][3].ToString().Trim() && s_Period == ds_Excel.Tables[0].Rows[x][4].ToString().Trim() && s_StAcceptDate == strST_ACCEPT_DATE && s_PoSourceNo != ds_Excel.Tables[0].Rows[x][0].ToString().Trim()) { iPKCount++; } if (iPKCount >= 1) { strErrMsg = string.Format("『(通路,門市,群分類,大分類)=({0},{1},{2},{3})時不允許多重PO。』", s_ChanNo, s_Store, s_ROOT_NO, s_PMA); bResultMultiPO = false; break; } } #endregion #region if (bResultMultiPO) { paramTemp.Clear(); paramTemp.Add(s_ChanNo); paramTemp.Add(s_Store); paramTemp.Add(s_Item); paramTemp.Add(s_Period); paramTemp.Add(s_StAcceptDate); paramTemp.Add(null); DataTable dtTempPoDetl = BCO.QueryChainPODetlByFind(paramTemp); if (dtTempPoDetl != null && dtTempPoDetl.Rows.Count > 0) { for (Int32 j = 0; j <= dtTempPoDetl.Rows.Count - 1; j++) { if (dtTempPoDetl.Rows[j]["po_source_no"].ToString().Trim() != s_PoSourceNo) { strErrMsg = string.Format("『(通路,門市,群分類,大分類)=({0},{1},{2},{3})時不允許多重PO。』", s_ChanNo, s_Store, s_ROOT_NO, s_PMA); break; } } } } #endregion } } } } #endregion } #endregion #region 4.4 檢查是否有PK重複之資料 //a) 檢查暫存檔本身是否有PK重複資料 //b) 檢查與正式表單有是否有PK重複資料 paramTemp.Clear(); paramTemp.Add(dRow[1].ToString().Trim()); paramTemp.Add(dRow[2].ToString().Trim()); paramTemp.Add(dRow[3].ToString().Trim()); paramTemp.Add(dRow[4].ToString().Trim()); paramTemp.Add(strST_ACCEPT_DATE); paramTemp.Add(s_LoginUser); paramTemp.Add(V_SESSION_ID); for (Int32 x = 0; x <= ds_Excel.Tables[0].Rows.Count - 1; x++) { if (s_Store == ds_Excel.Tables[0].Rows[x][2].ToString().Trim() && s_Item == ds_Excel.Tables[0].Rows[x][3].ToString().Trim() && s_Period == ds_Excel.Tables[0].Rows[x][4].ToString().Trim() && s_StAcceptDate == strST_ACCEPT_DATE && s_PoSourceNo == ds_Excel.Tables[0].Rows[x][0].ToString().Trim()) { iPKCount++; } if (iPKCount > 1) { strErrMsg += "匯入檔中(同進貨日/門市/品號/期別/PO單)不可重複,"; break; } } DataTable dtCheckPKConflict = ALO_DISRECORD_TMP.doCheckDISRecordPKConflict2(paramTemp); if (dtCheckPKConflict != null && dtCheckPKConflict.Rows.Count > 0) { if (dtCheckPKConflict.Rows[0][0].ToString().Trim() != "0") { strErrMsg += "匯入檔中(同進貨日/門市/品號/期別/PO單)不可重複,"; break; } if (dtCheckPKConflict.Rows[0][1].ToString().Trim() != "0") { strErrMsg += "與通路單號明細檔(同進貨日/門市/品號/期別/PO單)PK重複,"; } } #endregion #region 4.5 針對MEMO是否為空字串做檢查 if (strErrMsg.Trim() == string.Empty) { dRow_Temp["MEMO"] = System.DBNull.Value; dRow_Temp["DATASOURCE"] = s_AP_FileName; } 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["MEMO"] = strErrMsg; dRow_Temp["DATASOURCE"] = s_AP_FileName; 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_ALO_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); ParameterList.Add(V_SESSION_ID); DELETE_AND_INSERT_TEMP_TABLE(ParameterList, null, dt_ALO_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(GetNewException(ex).Message); } return arl_Return; #endregion }