public DataTable GetSourcetData(ArrayList ParameterList,DbTransaction RootDBT) { bool IsRootTranscation = false; try { #region 啟動交易或指定RootTranscation if (IsRootTranscation) { //獨立呼叫啟動Transcation Conn = USEDB.CreateConnection(); Conn.Open(); DBT = Conn.BeginTransaction(); } else { DBT = RootDBT; } #endregion DBO.MaintainAcceptDBO dbo = new DBO.MaintainAcceptDBO(ref USEDB); string ChanTransNo = ParameterList[0].ToString(); string UserID = ParameterList[1].ToString(); ArrayList DelList = new ArrayList(); DelList.Add(ChanTransNo); DelList.Add(UserID); dbo.DeleteDataTransTemp(DelList, RootDBT); DataTable dtResult = dbo.GetSourcetData(ParameterList); #region 交易成功 if (IsRootTranscation) { //獨立呼叫Transcation成立 DBT.Commit(); } #endregion return dtResult; } 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 } }
public void DelDataTransTemp(ArrayList ParameterList, DbTransaction RootDBT) { bool IsRootTranscation = false; try { //判斷是否有傳入Root Transcation IsRootTranscation = (RootDBT == null) ? true : false; #region 啟動交易或指定RootTranscation if (IsRootTranscation) { //獨立呼叫啟動Transcation Conn = USEDB.CreateConnection(); Conn.Open(); DBT = Conn.BeginTransaction(); } else { DBT = RootDBT; } DBO.MaintainAcceptDBO dbo = new DBO.MaintainAcceptDBO(ref USEDB); #endregion dbo.DeleteDataTransTemp(ParameterList, RootDBT); #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 } }
//0.ChanTransNo,1.CreateID,2.CreateDate //Datatable 欄位 0.item,1.period public bool CreateTransIn(string ChanTransNo,string PurchaseNo, string CreateID, string CreateDate, DataTable dtTransIn, DbTransaction RootDBT,out DataTable dtItem,out DataTable dtGift) { dtItem = null; dtGift = null; bool IsRootTranscation = false; int PID = -1; string TranNum = ""; ArrayList ParameterList = new ArrayList(); //取得並UPDATE DATATABLE的內容 dtItem = MaterDetl(); dtGift = GIftDetl(); try { DBO.MaintainAcceptDBO dbo = new DBO.MaintainAcceptDBO(ref USEDB); DBO.MaintainAccept bco = new DBO.MaintainAccept(strConn); //判斷是否有傳入Root Transcation IsRootTranscation = (RootDBT == null) ? true : false; #region 啟動交易或指定RootTranscation if (IsRootTranscation) { //獨立呼叫啟動Transcation Conn = USEDB.CreateConnection(); Conn.Open(); DBT = Conn.BeginTransaction(); } else { DBT = RootDBT; } #endregion //寫入LOG檔 //LOG 主檔 ParameterList.Clear(); ParameterList.Add(ChanTransNo); ParameterList.Add(dtTransIn.Rows[0][0].ToString()); ParameterList.Add(dtTransIn.Rows[0][1].ToString()); ParameterList.Add(CreateID); ParameterList.Add(CreateDate); ParameterList.Add(dtTransIn.Rows.Count); ParameterList.Add(dtTransIn.Rows[0][2].ToString()); dbo.CreateDataTransMain(ParameterList, DBT, out PID, out TranNum); for (int i = 0; i < dtTransIn.Rows.Count; i++) { ParameterList.Clear(); ParameterList.Add(PID); ParameterList.Add(ChanTransNo); ParameterList.Add(dtTransIn.Rows[i][0].ToString()); ParameterList.Add(dtTransIn.Rows[i][1].ToString()); ParameterList.Add(CreateID); ParameterList.Add(CreateDate); ParameterList.Add(dtTransIn.Rows[i][2].ToString()); dbo.CreateDataTransDetl(ParameterList, DBT); } ParameterList.Clear(); ParameterList.Add(ChanTransNo); ParameterList.Add(CreateID); DataTable dtTemp = dbo.GetTempSourceData(ParameterList); for (int i = 0; i < dtTemp.Rows.Count; i++) { bool haveData = false; for (int j = 0; j < dtTransIn.Rows.Count; j++) { string InItem = dtTransIn.Rows[j][0].ToString(); string InPeriod = dtTransIn.Rows[j][1].ToString(); string InChanSourceNo = dtTransIn.Rows[j][2].ToString(); if (InItem == dtTemp.Rows[i]["item"].ToString() && InPeriod == dtTemp.Rows[i]["period"].ToString() && InChanSourceNo == dtTemp.Rows[i]["chan_source_no"].ToString()) { haveData = true; } } if (haveData == true) { string BarCode = dtTemp.Rows[i]["barcode"].ToString(); string ItemCode = dtTemp.Rows[i]["ItemCode"].ToString(); string PeriodCode = dtTemp.Rows[i]["PeriodCode"].ToString(); string Item = dtTemp.Rows[i]["item"].ToString(); string period = dtTemp.Rows[i]["period"].ToString(); string Acc_Qty = dtTemp.Rows[i]["trans_qty"].ToString(); string ItemName = dtTemp.Rows[i]["ItemName"].ToString(); string package_unit = dtTemp.Rows[i]["package_unit"].ToString(); string s_Weight = dtTemp.Rows[i]["s_Weight"].ToString(); string s_length = dtTemp.Rows[i]["s_length"].ToString(); string s_width = dtTemp.Rows[i]["s_width"].ToString(); string s_height = dtTemp.Rows[i]["s_height"].ToString(); string p_weight = dtTemp.Rows[i]["p_weight"].ToString(); string p_length = dtTemp.Rows[i]["p_length"].ToString(); string p_width = dtTemp.Rows[i]["p_width"].ToString(); string p_height = dtTemp.Rows[i]["p_height"].ToString(); string Product_Source = dtTemp.Rows[i]["Product_Source"].ToString(); string Produce_Date = dtTemp.Rows[i]["Produce_Date"].ToString(); string Reserved_Period = dtTemp.Rows[i]["Reserved_Period"].ToString(); string Valid_Date = dtTemp.Rows[i]["Valid_Date"].ToString(); string AllowAccept_Date = dtTemp.Rows[i]["AllowAccept_Date"].ToString(); string Pitem = ""; string Pperiod = ""; string Cost = ""; string Price = ""; string TaxType = ""; string PurchaseQty = ""; string PlantAcceptDate = ""; string AcceptyQty = ""; string Qty = ""; string DisQty = ""; //if (BarCode.Length == 8 || BarCode.Length == 13) //{ // ItemCode = BarCode; // PeriodCode = "0000000000000"; //} //else if (BarCode.Length == 15) //{ // ItemCode = BarCode.Substring(0, 13); // PeriodCode = BarCode.Substring(13, 2); //} //else if (BarCode.Length == 18) //{ // ItemCode = BarCode.Substring(0, 13); // PeriodCode = BarCode.Substring(13, 5); //} bco.QueryItemData(ItemCode, PeriodCode, PurchaseNo, out Pitem, out Pperiod, out Cost, out Price, out TaxType, out PurchaseQty, out PlantAcceptDate, out AcceptyQty, out Qty, out DisQty); DataRow drItem = dtItem.NewRow(); drItem["barcode"] = BarCode; drItem["ItemCode"] = ItemCode; drItem["PeriodCode"] = PeriodCode; //2 drItem["item"] = Item; //品號 drItem["period"] = period; //期別 drItem["ItemName"] = ItemName; //5 drItem["purchase_Qty"] = PurchaseQty; //採購數量 drItem["In_Date"] = PlantAcceptDate; //預進日期 drItem["TAcc_Qty"] = Qty; //總驗收數 drItem["Acc_Qty"] = Acc_Qty; //驗收數量 drItem["Cost"] = Cost; //成本價 drItem["Price"] = Price; //零售價 drItem["TaxType"] = TaxType; //12 稅別 drItem["Package_Unit"] = package_unit; //1包裝數 drItem["S_Weight"] = s_Weight; //單品重量 drItem["S_Length"] = s_length; //單品長度 drItem["S_Width"] = s_width; //單品寬度 drItem["S_Height"] = s_height; //單品高度 drItem["P_Weight"] = p_weight; //包裝重量 drItem["P_Length"] = p_length; //包裝長度 drItem["P_Width"] = p_width; //包裝寬度 drItem["P_Height"] = p_height; //包裝高度 drItem["Product_Source"] = Product_Source; //商品來源 drItem["Produce_Date"] = Produce_Date; //製造日期 drItem["Reserved_Period"] = Reserved_Period; //保存期限 drItem["Valid_Date"] = Valid_Date; //有效日期 drItem["AllowAccept_Date"] = AllowAccept_Date; //允收日期 dtItem.Rows.Add(drItem); DataTable dtGiftTemp = bco.QueryGift(Item, period, PurchaseNo); for (int x = 0; x < dtGiftTemp.Rows.Count; x++) { DataRow drGift = dtGift.NewRow(); drGift["GiftName"] = dtGiftTemp.Rows[x]["GiftName"].ToString(); drGift["Barcode"] = BarCode; //0商品條碼 drGift["Item"] = Item; //1.品號 drGift["Period"] = period; //2.期別 drGift["Virtual_Code"] = dtGiftTemp.Rows[x]["VIRTUAL_CODE"].ToString(); //3.虛擬品號 drGift["purchase_Qty"] = dtGiftTemp.Rows[x]["PURCHASE_QTY"].ToString(); //4.採購數量 drGift["TAcc_Qty"] = dtGiftTemp.Rows[x]["accept_accqty"].ToString(); //X總驗收數 drGift["Accept_Qty"] = "0"; //5.驗收數量 drGift["Package_Unit"] = "0"; //6.1包裝數 drGift["S_Weight"] = "0"; //7.單品重量 drGift["S_Length"] = "0"; //8.單品長度 drGift["S_Width"] = "0";//9.單品寬度 drGift["S_Height"] = "0";//10.單品高度 drGift["P_Weight"] = "0"; //11.包裝重量 drGift["P_Length"] = "0"; //12.包裝長度 drGift["P_Width"] = "0";//13.包裝寬度 drGift["P_Height"] = "0"; //14.包裝高度 } } } //刪除暫存資料 ParameterList.Clear(); ParameterList.Add(ChanTransNo); ParameterList.Add(CreateID); dbo.DeleteDataTransTemp(ParameterList, DBT); #region 交易成功 if (IsRootTranscation) { //獨立呼叫Transcation成立 DBT.Commit(); } #endregion return true; } 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 } }