public string CreateData(string strUID, string strDate, DataTable dtData) { Int32 PID = 0; string[] sID_NO; string vID_NO; string sTemp = ""; string sPurchaseNo = ""; string strResult = string.Empty; try { ArrayList ParameterList = new ArrayList(); //獨立呼叫啟動Transcation Conn = USEDB.CreateConnection(); Conn.Open(); DBT = Conn.BeginTransaction(); MaintainPurchaseOrder PUR02_BCO = new MaintainPurchaseOrder(strConn); DataTable dtMANUFACTURE = dtData.DefaultView.ToTable(true, new string[] { "MANUFACTURE" }); for (int i = 0; i < dtMANUFACTURE.Rows.Count; i++) { ParameterList.Clear(); ParameterList.Add(strDate); //0.採購單日期 ParameterList.Add(strUID); //1.採購人員 ParameterList.Add(dtMANUFACTURE.Rows[i]["MANUFACTURE"].ToString()); //2.廠商編號 ParameterList.Add("25"); //3.CloseCase ParameterList.Add(strUID); //4.UID //寫入 Master Table vID_NO = PUR02_BCO.CreatePurchaseOrder(ParameterList, DBT); sID_NO = vID_NO.Split(new Char[] { ';' }); PID = int.Parse(sID_NO[0].ToString()); sPurchaseNo = sID_NO[1].ToString(); strResult += sPurchaseNo + ";"; ParameterList.Add(sPurchaseNo); ParameterList.Add(PID); DataTable DetailData = FilterDetail(dtData, dtMANUFACTURE.Rows[i]["MANUFACTURE"].ToString()); #region 新增明細資料與更新 VDS_MKT_PURCARD_MAIN.PUR_NO(雜誌採購卡) 或 VDS_MKT_BPURCARD_MAIN.PUR_NO(圖書採購卡) foreach (DataRow dRow in DetailData.Rows) { PUR02_BCO.CreatePurchaseOrderDetail(PID, ParameterList, dRow, DBT); //更新期別屬性檔(VDS_ITM_PERIOD_PROFILE)中,該品號期別的交貨日期、採購日、採購量與採購單號 PUR02_BCO.UpdatePeriodProfile(dRow["ITEM"].ToString().Trim(), dRow["PERIOD"].ToString().Trim(), dRow["PLAN_ACCEPT_DATE"].ToString().Trim(), ParameterList[0].ToString().Trim(), dRow["PURCHASE_QTY"].ToString().Trim(), sPurchaseNo, ParameterList[4].ToString().Trim(), DBT); //更新圖書採購卡或雜誌採購卡採購單號 if (dRow["PERIOD"].ToString().Trim() == "000000") //在圖書裡其period值絕對是000000 { PUR02_BCO.Update_B_PURCARD(sPurchaseNo, dRow["ITEM"].ToString().Trim(), ParameterList[4].ToString().Trim(), DBT); } else { PUR02_BCO.Update_PURCARD(sPurchaseNo, dRow["ITEM"].ToString().Trim(), dRow["PERIOD"].ToString().Trim(), ParameterList[4].ToString().Trim(), DBT); } } #endregion DataTable GiftData = Add_Gift(DetailData); #region 新增明細贈品資料 if (GiftData != null) { foreach (DataRow gRow in GiftData.Rows) { PUR02_BCO.CreatePurchaseOrderDetail(PID, ParameterList, gRow, DBT); //更新贈品屬性檔(VDS_MKT_GIFT_PROFILE)資料中,該品號期別的交貨日期、採購日、採購量與採購單號 PUR02_BCO.UpdateGiftProfile(gRow["ITEM"].ToString().Trim(), gRow["PERIOD"].ToString().Trim(), gRow["VIRTUAL_CODE"].ToString().Trim(), gRow["PLAN_ACCEPT_DATE"].ToString().Trim(), ParameterList[0].ToString().Trim(), gRow["PURCHASE_QTY"].ToString().Trim(), sPurchaseNo, ParameterList[4].ToString().Trim(), DBT); } } #endregion } DBT.Commit(); } catch (Exception ex) { if (DBT != null) DBT.Rollback(); throw ex; } finally { //獨立呼叫Transcation,關閉連線 if (Conn.State == ConnectionState.Connecting) Conn.Close(); } return strResult; }
/// <summary> ///1.目的:將暫存檔中的待處理資料,匯入正式表單 ///2.傳入參數:@處理檔名、@使用者 /// 回傳參數:@處理筆數、@正確筆數、@錯誤筆數、@錯誤訊息 ///3.處理表格:VDS_PUR_PURCHASEORDER_TMP(T)、VDS_PUR_PURCHASE_MAIN(M)、VDS_PUR_PURCHASE_ITEM(D) ///4.將暫存檔中的[狀態]欄位調整為2:TMP TO DB ///5.匯入處理完成後,回傳匯入處理結果:處理總筆數、成功筆數、失敗筆數、@錯誤訊息(成功時=null) /// </summary> public ArrayList TmpToDB(string s_LoginUser,string MAIL_ADDR, string ConnectionDB) { #region ArrayList arl_Return = new ArrayList(); try { string strPURCHASE_NO = string.Empty; ParameterList.Clear(); ParameterList.Add(s_LoginUser); ParameterList.Add(MAIL_ADDR); int iResult = TMP_To_Purchase_Order(ParameterList, out strPURCHASE_NO, null); PUR_PurchaseOrderDBO dbo = new PUR_PurchaseOrderDBO(ref USEDB); ParameterList.Clear(); ParameterList.Add(strPURCHASE_NO); DataTable dtPur = dbo.doQueryPurData(ParameterList); ; MaintainPurchaseOrder po = new MaintainPurchaseOrder(ConnectionDB); #region 更新期別屬性檔&圖書採購卡或雜誌採購卡採購單號 DataRow[] DetailRows = dtPur.Select("ITEM=VIRTUAL_CODE"); foreach (DataRow dRow in DetailRows) { //更新期別屬性檔(VDS_ITM_PERIOD_PROFILE)中,該品號期別的交貨日期、採購日、採購量與採購單號 po.UpdatePeriodProfile(dRow["ITEM"].ToString().Trim(), dRow["PERIOD"].ToString().Trim(), dRow["PLAN_ACCEPT_DATE"].ToString().Trim(), dRow["PURCHSE_DATE"].ToString().Trim(), dRow["PURCHASE_QTY"].ToString().Trim(), dRow["PURCHASE_NO"].ToString().Trim(), s_LoginUser, null); //更新圖書採購卡或雜誌採購卡採購單號 if (dRow["PERIOD"].ToString().Trim() == "000000") //在圖書裡其period值絕對是000000 { po.Update_B_PURCARD(dRow["PURCHASE_NO"].ToString().Trim(), dRow["ITEM"].ToString().Trim(), s_LoginUser, null); } else { po.Update_PURCARD(dRow["PURCHASE_NO"].ToString().Trim(), dRow["ITEM"].ToString().Trim(), dRow["PERIOD"].ToString().Trim(), s_LoginUser, null); } } #endregion #region 更新贈品屬性檔 DataRow[] GiftRows = dtPur.Select("ITEM<>VIRTUAL_CODE"); foreach (DataRow gRow in GiftRows) { //更新贈品屬性檔(VDS_MKT_GIFT_PROFILE)資料中,該品號期別的交貨日期、採購日、採購量與採購單號 po.UpdateGiftProfile(gRow["ITEM"].ToString().Trim(), gRow["PERIOD"].ToString().Trim(), gRow["VIRTUAL_CODE"].ToString().Trim(), gRow["PLAN_ACCEPT_DATE"].ToString().Trim(), gRow["PURCHSE_DATE"].ToString().Trim(), gRow["PURCHASE_QTY"].ToString().Trim(), gRow["PURCHASE_NO"].ToString().Trim(), s_LoginUser, null); } #endregion if (iResult > 0) { arl_Return.Add("TEMPTODB 正確"); arl_Return.Add(iResult); arl_Return.Add(iResult); arl_Return.Add(0); } } catch (Exception ex) { arl_Return.Add("程式錯誤"); arl_Return.Add(ex.Message); } finally { } return arl_Return; #endregion }