示例#1
0
        ///新增驗收單
        /// *表頭參數:
        //(0)[@UserID]
        //(1)[@CreateDate]
        //(2)[@驗收日期]
        //(3)[@驗收時間]
        //(4)[@採購單號]
        //(5)[@廠商送貨單號]
        //(6)[@發票號碼]
        //(7)[@供應商]
        //(8)[@應稅總額]
        //(9)[@未稅總額]
        //(10)[@稅額]
        //*明細資料集參數:
        //(0)[@商品條碼]
        //(1)[@品號]
        //(2)[@期別]
        //(3)[@採購數量]
        //(4)[@預進日期]
        //(5)[@總驗收數]
        //(6)[@驗收數量]
        //(7)[@成本價]
        //(8)[@零售價]
        //(9)[@1包裝數]
        //(10)[@單品重量]
        //(11)[@單品長度]
        //(12)[@單品寬度]
        //(13)[@單品高度]
        //(14)[@包裝重量]
        //(15)[@包裝長度]
        //(16)[@包裝寬度]
        //(17)[@包裝高度]  
        //(18)[@商品來源]
        //(19)[@製造日期]
        //(20)[@保存期限]
        //(21)[@有效日期]
        //(22)[@允收日期]
        //*品質檢驗資料集
        //(1)[@品號]
        //(2)[@期別]
        //(3)[@檢查項目]
        //(4)[@是否正常]
        //(5)[@異常說明]
        //*贈品明細資料集參數:
        //(1)[@商品條碼]
        //(2)[@品號]
        //(3)[@期別]
        //(4)[@虛擬品號]
        //(5)[@採購數量]
        //(6)[@總驗收數]
        //(7)[@驗收數量]
        //(8)[@1包裝數]
        //(9)[@單品重量]
        //(10)[@單品長度]
        //(11)[@單品寬度]
        //(12)[@單品高度]
        //(13)[@包裝重量]
        //(14)[@包裝長度]
        //(15)[@包裝寬度]
        //(16)[@包裝高度] 
        /// <summary>
        /// 建立驗收單
        /// </summary>
        /// <param name="ParameterList"></param>
        /// <param name="dtDetls"></param>
        /// <param name="dtGifts"></param>
        /// <param name="RootDBT"></param>
        /// <param name="AcceptNo"></param>
        /// <param name="Statue"></param>
        /// <param name="ErrorItem"></param>
        public bool CreateAccept(ArrayList ParameterList, DataTable dtDetls, DataTable dtGifts, DbTransaction RootDBT, out string AcceptNo, out string Statue, out string ErrorItem)
        {
            bool IsRootTranscation = false;

            //檢查商品和贈品是不是都驗收了,未驗收結案才能繼續
            ErrorItem = string.Empty;
            AcceptNo = string.Empty;
            Statue = string.Empty;

            int PID = -1;

            try
            {
                string UserID = ParameterList[0].ToString();
                string UpdateDate = ParameterList[1].ToString();
                string AcceptDate = ParameterList[2].ToString();
                string AcceptTime = ParameterList[3].ToString();
                string PurchaseNo = ParameterList[4].ToString();
                string WaybillNo = ParameterList[5].ToString();
                string InvoiceNo = ParameterList[6].ToString();
                string Vender = ParameterList[7].ToString();
                string TaxAmt = ParameterList[8].ToString();
                string UtaxAmt = ParameterList[9].ToString();
                string Tax = ParameterList[10].ToString();



                DBO.MaintainAcceptDBO VGIDBO = new DBO.MaintainAcceptDBO(ref USEDB);
                DBO.MaintainAcceptQualityCheck VGIQC = new DBO.MaintainAcceptQualityCheck(strConn);
                PURDBO.MaintainGoodsInTransit PURDB = new PURDBO.MaintainGoodsInTransit(strConn);
                IVMDBO.MaintainStockInOut IVMDB = new IVMDBO.MaintainStockInOut(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

                //新增主檔
                ArrayList InsertParameter = new ArrayList();
                InsertParameter.Clear();
                InsertParameter.Add(UserID);
                InsertParameter.Add(UpdateDate);
                InsertParameter.Add(AcceptDate);
                InsertParameter.Add(AcceptTime);
                InsertParameter.Add(PurchaseNo);
                InsertParameter.Add(WaybillNo);
                InsertParameter.Add(InvoiceNo);
                InsertParameter.Add(Vender);
                InsertParameter.Add(TaxAmt);
                InsertParameter.Add(UtaxAmt);
                InsertParameter.Add(Tax);

                VGIDBO.CreateAcceptMain(InsertParameter, DBT, out PID, out AcceptNo);

                //新增明細

                DataTable dtStockIn = new DataTable();
                dtStockIn.Columns.Add("LocateNo");
                dtStockIn.Columns.Add("LocateSec");
                dtStockIn.Columns.Add("Item");
                dtStockIn.Columns.Add("Period");
                dtStockIn.Columns.Add("In_Qty");
                dtStockIn.Columns.Add("Cost");

                //取得入庫暫存儲區、儲格
                string LocateNo = "";
                string LocateSec = "";

                LocateSec = VGIDBO.GetStockInTempLocateSec();

                if (LocateSec == string.Empty)
                {
                    throw new Exception("無法取得入庫暫存儲區或儲位");
                }
                else
                {
                    LocateNo = LocateSec.Substring(0, 1);
                }

                #region 商品明細
                //barcode
                //item
                //period
                //purchase_Qty
                //In_Date
                //TAcc_Qty
                //Acc_Qty
                //Cost
                //Price
                //Package_Unit
                //S_Weight
                //S_Length
                //S_Width
                //S_Height
                //P_Weight
                //P_Length
                //P_Width
                //P_Height
                //Product_Source
                //Produce_Date
                //Reserved_Period
                //Valid_Date
                //AllowAccept_Date
                //Old_Qty
                //RowState

                for (int i = 0; i < dtDetls.Rows.Count; i++)
                {
                    int DetlID = -1;

                    string Barcode = dtDetls.Rows[i]["barcode"].ToString();
                    string Item = dtDetls.Rows[i]["item"].ToString();
                    string Period = dtDetls.Rows[i]["period"].ToString();
                    string PurchaseQty = dtDetls.Rows[i]["purchase_Qty"].ToString();
                    string In_Date = dtDetls.Rows[i]["In_Date"].ToString();
                    string TotalAcceptQty = dtDetls.Rows[i]["TAcc_Qty"].ToString();
                    string AcceptQty = dtDetls.Rows[i]["Acc_Qty"].ToString();

                    int accept_days = -1;
                    int out_days = -1;

                    //取得入庫單明細資料
                    DataRow drStockIn = dtStockIn.NewRow();
                    drStockIn["LocateNo"] = LocateNo;
                    drStockIn["LocateSec"] = LocateSec;
                    drStockIn["Item"] = Item;
                    drStockIn["Period"] = Period;
                    drStockIn["In_Qty"] = AcceptQty;
                    drStockIn["Cost"] = dtDetls.Rows[i]["Cost"].ToString();
                    dtStockIn.Rows.Add(drStockIn);

                    //寫入明細檔資料,逐筆寫入
                    InsertParameter.Clear();
                    InsertParameter.Add(UserID);
                    InsertParameter.Add(UpdateDate);
                    InsertParameter.Add(PID);
                    InsertParameter.Add(AcceptNo);
                    InsertParameter.Add(Barcode);                                       //BarCode
                    InsertParameter.Add(Item);                                          //Item
                    InsertParameter.Add(Period);                                        //Period
                    InsertParameter.Add(AcceptQty);                                     //AcceptQty
                    InsertParameter.Add(dtDetls.Rows[i]["Cost"].ToString());            //Cost
                    InsertParameter.Add(dtDetls.Rows[i]["Price"].ToString());           //Price
                    InsertParameter.Add(dtDetls.Rows[i]["Package_Unit"].ToString());    //Package_Unit
                    InsertParameter.Add(dtDetls.Rows[i]["S_Weight"].ToString());        //S_Weight
                    InsertParameter.Add(dtDetls.Rows[i]["S_Length"].ToString());        //S_Length
                    InsertParameter.Add(dtDetls.Rows[i]["S_Width"].ToString());         //S_Width
                    InsertParameter.Add(dtDetls.Rows[i]["S_Height"].ToString());        //S_Height
                    InsertParameter.Add(dtDetls.Rows[i]["P_Weight"].ToString());        //P_Weight
                    InsertParameter.Add(dtDetls.Rows[i]["P_Length"].ToString());        //P_Length
                    InsertParameter.Add(dtDetls.Rows[i]["P_Width"].ToString());         //P_Width
                    InsertParameter.Add(dtDetls.Rows[i]["P_Height"].ToString());        //P_Height
                    InsertParameter.Add(dtDetls.Rows[i]["Product_Source"]);             //Product_Source
                    InsertParameter.Add(dtDetls.Rows[i]["Produce_Date"]);               //Produce_Date
                    InsertParameter.Add(dtDetls.Rows[i]["Reserved_Period"]);            //Reserved_Period
                    InsertParameter.Add(dtDetls.Rows[i]["Valid_Date"]);                 //Valid_Date
                    InsertParameter.Add(dtDetls.Rows[i]["AllowAccept_Date"]);           //AllowAccept_Date

                    VGIDBO.CreateAcceptDetl(InsertParameter, DBT, out DetlID);

                    //寫入商品檢驗結果
                    InsertParameter.Clear();
                    InsertParameter.Add(UserID);
                    InsertParameter.Add(UpdateDate);
                    InsertParameter.Add(DetlID);
                    InsertParameter.Add(AcceptNo);
                    InsertParameter.Add(Item);
                    InsertParameter.Add(Period);

                    VGIQC.CreateQualityCheck(InsertParameter, DBT);

                    //若該商品品項的[@總驗收數]+[@驗收數量]>=[採購數量],則呼叫[MaintainPurchaseOrder.ClosePurchaseOrderDetail]
                    if (int.Parse(TotalAcceptQty) + int.Parse(AcceptQty) >= int.Parse(PurchaseQty))
                    {
                        InsertParameter.Clear();
                        InsertParameter.Add(UserID);
                        InsertParameter.Add(PurchaseNo);
                        InsertParameter.Add(Item);
                        InsertParameter.Add(Period);
                        //VirtualCode = Item
                        InsertParameter.Add(Item);
                        ClosePurchaseOrderDetail(InsertParameter, DBT);
                    }

                    //依傳入的明細資料集參數,將正常品資料回寫生效中(enable=1)的商品屬性檔(VDS_ITM_PERIOD_PROFILE)的下列欄位
                    InsertParameter.Clear();
                    InsertParameter.Add(Item);
                    InsertParameter.Add(Period);
                    InsertParameter.Add(dtDetls.Rows[i]["Package_Unit"].ToString());    //Package_Unit
                    InsertParameter.Add(dtDetls.Rows[i]["S_Weight"].ToString());        //S_Weight
                    InsertParameter.Add(dtDetls.Rows[i]["S_Length"].ToString());        //S_Length
                    InsertParameter.Add(dtDetls.Rows[i]["S_Width"].ToString());         //S_Width
                    InsertParameter.Add(dtDetls.Rows[i]["S_Height"].ToString());        //S_Height
                    InsertParameter.Add(dtDetls.Rows[i]["P_Weight"].ToString());        //P_Weight
                    InsertParameter.Add(dtDetls.Rows[i]["P_Length"].ToString());        //P_Length
                    InsertParameter.Add(dtDetls.Rows[i]["P_Width"].ToString());         //P_Width
                    InsertParameter.Add(dtDetls.Rows[i]["P_Height"].ToString());        //P_Height
                    InsertParameter.Add(AcceptDate);
                    InsertParameter.Add(AcceptQty);
                    InsertParameter.Add(dtDetls.Rows[i]["Valid_Date"].ToString());      //Valid_Date
                    InsertParameter.Add(dtDetls.Rows[i]["AllowAccept_Date"].ToString());//AllowAccept_Date
                    UpdateItmPeriodProfile(UserID, UpdateDate, InsertParameter, DBT, out accept_days, out out_days);

                    //呼叫[MaintainGoodsInTransit.UpdateGoodsInTrainsitByGoodsReceive],傳入[@品號],[@期別],[@虛擬品號],[@採購單號],[@驗收量](若品項為正常品,則[@虛擬品號]=[@品號]),更新在途量,若未找到相對應的在途單資料,表示未開立在途單,不需更新
                    InsertParameter.Clear();
                    InsertParameter.Add(PurchaseNo);
                    InsertParameter.Add(Item);
                    InsertParameter.Add(Period);
                    InsertParameter.Add(Item);
                    InsertParameter.Add(AcceptQty);
                    PURDB.UpdateGoodsInTrainsitByGoodsReceive(InsertParameter, DBT);

                    #region 贈品明細

                    //Barcode           商品條碼
                    //Item              品號
                    //Period            期別
                    //Virtual_Code      虛擬品號
                    //purchase_Qty      採購數量
                    //TAcc_Qty          總驗收數
                    //Accept_Qty        驗收數量
                    //accept_accqty
                    //Old_Qty           驗收數量(原始
                    //Package_Unit      1包裝數
                    //S_Weight          單品重量
                    //S_Length          單品長度
                    //S_Width           單品寬度
                    //S_Height          單品高度
                    //P_Weight          包裝重量
                    //P_Length          包裝長度
                    //P_Width           包裝寬度
                    //P_Height          包裝高度
                    //RowState          包裝高度

                    //寫入贈品明細
                    for (int x = 0; x < dtGifts.Rows.Count; x++)
                    {
                        string GiftBarcode = dtGifts.Rows[x]["Barcode"].ToString();
                        string GiftItem = dtGifts.Rows[x]["Item"].ToString();
                        string GiftPeriod = dtGifts.Rows[x]["Period"].ToString();
                        string GiftVirtualCode = dtGifts.Rows[x]["Virtual_Code"].ToString();
                        string GiftTotalAcceptQty = dtGifts.Rows[x]["accept_accqty"].ToString(); //總驗收量
                        string GiftAcceptQty = dtGifts.Rows[x]["Accept_Qty"].ToString();         //驗收數量
                        string GiftAcceptQty_Old = dtGifts.Rows[x]["Old_Qty"].ToString();
                        string GiftPurchaseQty = dtGifts.Rows[x]["purchase_Qty"].ToString();     //採購數量

                        if (Barcode == GiftBarcode && Item == GiftItem && Period == GiftPeriod)
                        {
                            InsertParameter.Clear();
                            InsertParameter.Add(UserID);                                        //0
                            InsertParameter.Add(UpdateDate);                                    //1
                            InsertParameter.Add(DetlID);                                        //2
                            InsertParameter.Add(dtGifts.Rows[x][0].ToString());                 //3  Barcode
                            InsertParameter.Add(GiftItem);                                      //4  Item
                            InsertParameter.Add(GiftPeriod);                                    //5  Period
                            InsertParameter.Add(GiftVirtualCode);                               //6  VirtualCode
                            InsertParameter.Add(AcceptNo);                                      //7
                            InsertParameter.Add(dtGifts.Rows[x]["purchase_Qty"].ToString());    //8  PurchaseQty
                            InsertParameter.Add(dtGifts.Rows[x]["Accept_Qty"].ToString());      //9  AcceptQty
                            InsertParameter.Add(dtGifts.Rows[x]["Package_Unit"].ToString());    //10 PackageUnit
                            InsertParameter.Add(dtGifts.Rows[x]["S_Weight"].ToString());        //11 SWeight
                            InsertParameter.Add(dtGifts.Rows[x]["S_Length"].ToString());        //12 SLength
                            InsertParameter.Add(dtGifts.Rows[x]["S_Width"].ToString());         //13 SWidth
                            InsertParameter.Add(dtGifts.Rows[x]["S_Height"].ToString());        //14 SHeigh
                            InsertParameter.Add(dtGifts.Rows[x]["P_Weight"].ToString());        //15 PWeight
                            InsertParameter.Add(dtGifts.Rows[x]["P_Length"].ToString());        //16 PLength
                            InsertParameter.Add(dtGifts.Rows[x]["P_Width"].ToString());         //17 PWidth
                            InsertParameter.Add(dtGifts.Rows[x]["P_Height"].ToString());        //18 PHeigh

                            VGIDBO.CreateAcceptGift(InsertParameter, DBT);

                            //若該贈品品項的[@總驗收數]+[@驗收數量]>=[採購數量],則呼叫[MaintainPurchaseOrder.ClosePurchaseOrderDetail]
                            if (int.Parse(GiftTotalAcceptQty) + int.Parse(GiftAcceptQty) >= int.Parse(GiftPurchaseQty))
                            {
                                InsertParameter.Clear();
                                InsertParameter.Add(UserID);            //0
                                InsertParameter.Add(PurchaseNo);        //1
                                InsertParameter.Add(GiftItem);          //2
                                InsertParameter.Add(GiftPeriod);        //3
                                InsertParameter.Add(GiftVirtualCode);   //4

                                ClosePurchaseOrderDetail(InsertParameter, DBT);
                            }

                            //依傳入的贈品明細資料集參數,將贈品資料回寫贈品屬性檔(VDS_MKT_GIFT_PROFILE)的下列欄位
                            InsertParameter.Clear();
                            InsertParameter.Add(UserID);                                        //0
                            InsertParameter.Add(UpdateDate);                                    //1
                            InsertParameter.Add(GiftItem);                                      //2  Item
                            InsertParameter.Add(GiftPeriod);                                    //3  Period
                            InsertParameter.Add(GiftVirtualCode);                               //4  VirtualCode
                            InsertParameter.Add(dtGifts.Rows[x]["Package_Unit"].ToString());    //5  PackageUnit
                            InsertParameter.Add(dtGifts.Rows[x]["S_Weight"].ToString());        //6  SWeight
                            InsertParameter.Add(dtGifts.Rows[x]["S_Length"].ToString());        //7  SLength
                            InsertParameter.Add(dtGifts.Rows[x]["S_Width"].ToString());         //8  SWidth
                            InsertParameter.Add(dtGifts.Rows[x]["S_Height"].ToString());        //9  SHeigh
                            InsertParameter.Add(dtGifts.Rows[x]["P_Weight"].ToString());        //10 PWeight
                            InsertParameter.Add(dtGifts.Rows[x]["P_Length"].ToString());        //11 PLength
                            InsertParameter.Add(dtGifts.Rows[x]["P_Width"].ToString());         //12 PWidth
                            InsertParameter.Add(dtGifts.Rows[x]["P_Height"].ToString());        //13 PHeigh
                            InsertParameter.Add(AcceptDate);                                    //14
                            InsertParameter.Add(dtGifts.Rows[x]["Accept_Qty"].ToString());      //15
                            InsertParameter.Add(accept_days);                                   //16
                            InsertParameter.Add(out_days);                                      //17

                            //UpdateGiftProfile(UserID, UpdateDate, accept_days, out_days, InsertParameter,DBT);

                            DBO.MaintainAcceptDBO dbo = new DBO.MaintainAcceptDBO(ref USEDB);
                            dbo.UpdateMktGiftProfile(InsertParameter, DBT);

                            //呼叫[MaintainGoodsInTransit.UpdateGoodsInTrainsitByGoodsReceive],傳入[@品號],[@期別],[@虛擬品號],[@採購單號],[@驗收量](若品項為正常品,則[@虛擬品號]=[@品號]),更新在途量,若未找到相對應的在途單資料,表示未開立在途單,不需更新
                            InsertParameter.Clear();
                            InsertParameter.Add(PurchaseNo);            //0
                            InsertParameter.Add(GiftItem);              //1
                            InsertParameter.Add(GiftPeriod);            //2
                            InsertParameter.Add(GiftVirtualCode);       //3
                            InsertParameter.Add(Convert.ToString(int.Parse(GiftAcceptQty_Old) - int.Parse(GiftAcceptQty)));         //4
                            PURDB.UpdateGoodsInTrainsitByGoodsReceive(InsertParameter, DBT);
                        }


                    }

                    #endregion

                    //判斷該品項是否需產生新的期別
                    //(1)該品項的期別(period)若不為[000000]且定期出刊(select attribute from vds_itm_item where item=[@item] , attribute的值為=1表示定期出刊),則需需產生下一期別資料
                    //(2)產生新期別的步驟如下:
                    //*檢查該品項期別是否已產生下一期期別資料(select count(*) from vds_itm_period_main where item=@item and period=lpad(to_char(to_number(@period) +(select period_step from vds_itm_item where item=@item)),6,'0')),若尚未產生,則呼叫[MaintainSKUPeriod.ProcessAddNextPeriod]產生新的期別資料,傳入資料參數如[新增下一期別.doc]文件所述
                    InsertParameter.Clear();
                    InsertParameter.Add(Item);
                    InsertParameter.Add(Period);
                    string V_Next = VGIDBO.CheckNextPeriod(InsertParameter);

                    if (V_Next == "1")
                    {
                        string Msg = "";
                        string Result = "";
                        InsertParameter.Clear();
                        InsertParameter.Add(AcceptNo);
                        InsertParameter.Add(UserID);
                        InsertParameter.Add(DateTime.Now);
                        VGIDBO.AddNextPeriod(InsertParameter, DBT, out Msg, out Result);
                        if (Result != "1")
                        {
                            throw new Exception("新增下一期別發生錯誤" + Msg);
                        }
                    }
                }

                #endregion

                //建立入庫單
                //取得入庫單主檔資料 >輸入變數 0.CheckFreeze_Flag(預設1) 1.ReasonNo 2.ADJNo 3.SourceNo 4.UserID
                //(0)Flag
                //(1)出入庫原因 (InOut_Reason_No)=S1
                //(2)調整單號 (Adjust_No)=null
                //(3)來源單號 (Source_No)=[@驗收單號]
                //(4)使用者
                InsertParameter.Clear();
                InsertParameter.Add("1");
                InsertParameter.Add("S1");
                InsertParameter.Add("");
                InsertParameter.Add(AcceptNo);
                InsertParameter.Add(UserID);
                IVMDB.CreateStockIn(InsertParameter, dtStockIn, 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
            }

        }
示例#2
0
        public bool UpdateAccept_2(ArrayList ParameterList, DataTable dtDetls, DataTable dtGifts, DbTransaction RootDBT, out string Statue, out string ErrorItem, out string ErrMsg)
        {
            bool IsRootTranscation = false;

            ErrorItem = string.Empty;
            Statue = string.Empty;
            ErrMsg = string.Empty;

            int ID = -1;
            int PID = -1;
            string Result = "";

            try
            {
                string UserID = ParameterList[0].ToString();
                string UpdateDate = ParameterList[1].ToString();
                string AcceptNo = ParameterList[2].ToString();
                string AcceptDate = ParameterList[3].ToString();
                string PurchaseNo = ParameterList[4].ToString();
                string WaybillNo = ParameterList[5].ToString();
                string InvoiceNo = ParameterList[6].ToString();
                string TaxAmt = ParameterList[7].ToString();
                string UtaxAmt = ParameterList[8].ToString();
                string Tax = ParameterList[9].ToString();

                DBO.MaintainAcceptDBO VGIDBO = new DBO.MaintainAcceptDBO(ref USEDB);
                DBO.MaintainAcceptQualityCheck VGIQC = new DBO.MaintainAcceptQualityCheck(strConn);
                PURDBO.MaintainGoodsInTransit PURDB = new PURDBO.MaintainGoodsInTransit(strConn);
                IVMDBO.MaintainStockInOut IVMDB = new IVMDBO.MaintainStockInOut(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

                ArrayList InsertParameter = new ArrayList();

                #region 商品明細
                //barcode
                //item
                //period
                //purchase_Qty
                //In_Date
                //TAcc_Qty
                //Acc_Qty
                //Cost
                //Price
                //Package_Unit
                //S_Weight
                //S_Length
                //S_Width
                //S_Height
                //P_Weight
                //P_Length
                //P_Width
                //P_Height
                //Product_Source
                //Produce_Date
                //Reserved_Period
                //Valid_Date
                //AllowAccept_Date
                //Old_Qty
                //RowState

                for (int i = 0; i < dtDetls.Rows.Count; i++)
                {
                    int DetlID = -1;

                    string Barcode = dtDetls.Rows[i]["barcode"].ToString();
                    string Item = dtDetls.Rows[i]["item"].ToString();
                    string Period = dtDetls.Rows[i]["period"].ToString();
                    string In_Date = dtDetls.Rows[i]["In_Date"].ToString();
                    string PurchaseQty = dtDetls.Rows[i]["purchase_Qty"].ToString();
                    string TotalAcceptQty = dtDetls.Rows[i]["TAcc_Qty"].ToString();
                    string AcceptQty = dtDetls.Rows[i]["Acc_Qty"].ToString();
                    string OLDQty = dtDetls.Rows[i]["Old_Qty"].ToString();
                    string DFlag = dtDetls.Rows[i]["RowState"].ToString();

                    int accept_days = -1;
                    int out_days = -1;

                    //寫入明細檔資料,逐筆寫入
                    InsertParameter.Clear();
                    InsertParameter.Add(UserID);
                    InsertParameter.Add(UpdateDate);
                    InsertParameter.Add(AcceptNo);
                    InsertParameter.Add(Barcode); //BarCode
                    InsertParameter.Add(Item); //Item
                    InsertParameter.Add(Period); //Period
                    InsertParameter.Add(AcceptQty); //NewQty
                    InsertParameter.Add(dtDetls.Rows[i]["Cost"].ToString());            //Cost
                    InsertParameter.Add(dtDetls.Rows[i]["Price"].ToString());           //Price
                    InsertParameter.Add(dtDetls.Rows[i]["Package_Unit"].ToString());    //Package_Unit
                    InsertParameter.Add(dtDetls.Rows[i]["S_Weight"].ToString());        //S_Weight
                    InsertParameter.Add(dtDetls.Rows[i]["S_Length"].ToString());        //S_Length
                    InsertParameter.Add(dtDetls.Rows[i]["S_Width"].ToString());         //S_Width
                    InsertParameter.Add(dtDetls.Rows[i]["S_Height"].ToString());        //S_Height
                    InsertParameter.Add(dtDetls.Rows[i]["P_Weight"].ToString());        //P_Weight
                    InsertParameter.Add(dtDetls.Rows[i]["P_Length"].ToString());        //P_Length
                    InsertParameter.Add(dtDetls.Rows[i]["P_Width"].ToString());         //P_Width
                    InsertParameter.Add(dtDetls.Rows[i]["P_Height"].ToString());        //P_Height
                    InsertParameter.Add(dtDetls.Rows[i]["Product_Source"].ToString());  //Product_Source
                    InsertParameter.Add(dtDetls.Rows[i]["Produce_Date"].ToString());    //Produce_Date
                    InsertParameter.Add(dtDetls.Rows[i]["Reserved_Period"].ToString()); //Reserved_Period
                    InsertParameter.Add(dtDetls.Rows[i]["Valid_Date"].ToString());      //Valid_Date
                    InsertParameter.Add(dtDetls.Rows[i]["AllowAccept_Date"].ToString());//AllowAccept_Date
                    InsertParameter.Add(DFlag); //23.FLAG 
                    InsertParameter.Add(dtDetls.Rows[i]["UPDATEDATE"]);                 //OLD UPDATEDATE
                    InsertParameter.Add(dtDetls.Rows[i]["UPDATEUID"]);                  //OLD UPDATEUID

                    VGIDBO.UpdateAcceptDetl_2(InsertParameter, DBT, out DetlID);

                    //依傳入的明細資料集參數,將正常品資料回寫生效中(enable=1)的商品屬性檔(VDS_ITM_PERIOD_PROFILE)的下列欄位
                    InsertParameter.Clear();
                    InsertParameter.Add(Item);
                    InsertParameter.Add(Period);
                    InsertParameter.Add(dtDetls.Rows[i]["Package_Unit"].ToString());    //Package_Unit
                    InsertParameter.Add(dtDetls.Rows[i]["S_Weight"].ToString());        //S_Weight
                    InsertParameter.Add(dtDetls.Rows[i]["S_Length"].ToString());        //S_Length
                    InsertParameter.Add(dtDetls.Rows[i]["S_Width"].ToString());         //S_Width
                    InsertParameter.Add(dtDetls.Rows[i]["S_Height"].ToString());        //S_Height
                    InsertParameter.Add(dtDetls.Rows[i]["P_Weight"].ToString());        //P_Weight
                    InsertParameter.Add(dtDetls.Rows[i]["P_Length"].ToString());        //P_Length
                    InsertParameter.Add(dtDetls.Rows[i]["P_Width"].ToString());         //P_Width
                    InsertParameter.Add(dtDetls.Rows[i]["P_Height"].ToString());        //P_Height
                    InsertParameter.Add(AcceptDate);
                    InsertParameter.Add(AcceptQty); //NewQty
                    InsertParameter.Add(dtDetls.Rows[i]["Valid_Date"].ToString());      //Valid_Date
                    InsertParameter.Add(dtDetls.Rows[i]["AllowAccept_Date"].ToString());//AllowAccept_Date
                    //23.FLAG 
                    //24 OldQty
                    UpdateItmPeriodProfile_2(UserID, UpdateDate, InsertParameter, DBT, out accept_days, out out_days);

                    #region 贈品明細

                    //Barcode           商品條碼        
                    //Item              品號               
                    //Period            期別             
                    //Virtual_Code      虛擬品號   
                    //purchase_Qty      採購數量   
                    //GiftName                  
                    //Accept_Qty        驗收數量     
                    //accept_accqty     總驗收數   
                    //Old_Qty           驗收數量(原始)
                    //SQty              剩餘數量           
                    //Package_Unit      1包裝數    
                    //S_Weight          單品重量       
                    //S_Length          單品長度       
                    //S_Width           單品寬度        
                    //S_Height          單品高度       
                    //P_Weight          包裝重量       
                    //P_Length          包裝長度       
                    //P_Width           包裝寬度        
                    //P_Height          包裝高度       
                    //UPDATEUID                 
                    //UPDATEDATE                
                    //RowState          "U";               

                    if (DFlag == "U")
                    {
                        //更新贈品明細
                        for (int x = 0; x < dtGifts.Rows.Count; x++)
                        {
                            string GiftBarcode = dtGifts.Rows[x]["Barcode"].ToString();
                            string GiftItem = dtGifts.Rows[x]["Item"].ToString();
                            string GiftPeriod = dtGifts.Rows[x]["Period"].ToString();
                            string GiftVirtualCode = dtGifts.Rows[x]["Virtual_Code"].ToString();
                            string GFlag = dtGifts.Rows[x]["RowState"].ToString();
                            string GiftTotalAcceptQty = dtGifts.Rows[x]["accept_accqty"].ToString();
                            string GiftAcceptQty = dtGifts.Rows[x]["Accept_Qty"].ToString();
                            string GiftAcceptQty_Old = dtGifts.Rows[x]["Old_Qty"].ToString();
                            string GiftPurchaseQty = dtGifts.Rows[x]["purchase_Qty"].ToString();

                            if (Barcode == GiftBarcode && Item == GiftItem && Period == GiftPeriod)
                            {
                                InsertParameter.Clear();
                                InsertParameter.Add(UserID);                                    //0
                                InsertParameter.Add(UpdateDate);                                //1
                                InsertParameter.Add(DetlID);                                    //2
                                InsertParameter.Add(dtGifts.Rows[x]["Barcode"].ToString());     //3  Barcode
                                InsertParameter.Add(GiftItem);                                  //4  Item
                                InsertParameter.Add(GiftPeriod);                                //5  Period
                                InsertParameter.Add(GiftVirtualCode);                           //6  VirtualCode
                                InsertParameter.Add(AcceptNo);                                  //7
                                InsertParameter.Add(dtGifts.Rows[x]["purchase_Qty"].ToString());//8  PurchaseQty
                                InsertParameter.Add(dtGifts.Rows[x]["Accept_Qty"].ToString());  //9  AcceptQty
                                InsertParameter.Add(dtGifts.Rows[x]["Package_Unit"].ToString());//10 PackageUnit
                                InsertParameter.Add(dtGifts.Rows[x]["S_Weight"].ToString());    //11 SWeight
                                InsertParameter.Add(dtGifts.Rows[x]["S_Length"].ToString());    //12 SLength
                                InsertParameter.Add(dtGifts.Rows[x]["S_Width"].ToString());     //13 SWidth
                                InsertParameter.Add(dtGifts.Rows[x]["S_Height"].ToString());    //14 SHeigh
                                InsertParameter.Add(dtGifts.Rows[x]["P_Weight"].ToString());    //15 PWeight
                                InsertParameter.Add(dtGifts.Rows[x]["P_Length"].ToString());    //16 PLength
                                InsertParameter.Add(dtGifts.Rows[x]["P_Width"].ToString());     //17 PWidth
                                InsertParameter.Add(dtGifts.Rows[x]["P_Height"].ToString());    //18 PHeigh
                                InsertParameter.Add(dtGifts.Rows[x]["RowState"].ToString());    //19 RowState
                                InsertParameter.Add(dtGifts.Rows[x]["UPDATEDATE"]);             //20 OLD UPDATEDATE
                                InsertParameter.Add(dtGifts.Rows[x]["UPDATEUID"]);              //21 OLD UPDATEUID

                                VGIDBO.UpdateAcceptGift_2(InsertParameter, DBT);

                                if (GFlag == "U")
                                {
                                    //依傳入的贈品明細資料集參數,將贈品資料回寫贈品屬性檔(VDS_MKT_GIFT_PROFILE)的下列欄位
                                    InsertParameter.Clear();
                                    InsertParameter.Add(UserID);                                    //0
                                    InsertParameter.Add(UpdateDate);                                //1
                                    InsertParameter.Add(GiftItem);                                  //2  Item
                                    InsertParameter.Add(GiftPeriod);                                //3  Period
                                    InsertParameter.Add(GiftVirtualCode);                           //4  VirtualCode
                                    InsertParameter.Add(dtGifts.Rows[x]["Package_Unit"].ToString());//5  PackageUnit
                                    InsertParameter.Add(dtGifts.Rows[x]["S_Weight"].ToString());    //6  SWeight
                                    InsertParameter.Add(dtGifts.Rows[x]["S_Length"].ToString());    //7  SLength
                                    InsertParameter.Add(dtGifts.Rows[x]["S_Width"].ToString());     //8  SWidth
                                    InsertParameter.Add(dtGifts.Rows[x]["S_Height"].ToString());    //9  SHeigh
                                    InsertParameter.Add(dtGifts.Rows[x]["P_Weight"].ToString());    //10 PWeight
                                    InsertParameter.Add(dtGifts.Rows[x]["P_Length"].ToString());    //11 PLength
                                    InsertParameter.Add(dtGifts.Rows[x]["P_Width"].ToString());     //12 PWidth
                                    InsertParameter.Add(dtGifts.Rows[x]["P_Height"].ToString());    //13 PHeigh
                                    InsertParameter.Add(AcceptDate);                                //14
                                    InsertParameter.Add(dtGifts.Rows[x]["Accept_Qty"].ToString());  //15 accept_qty
                                    InsertParameter.Add(accept_days);                               //16
                                    InsertParameter.Add(out_days);                                  //17

                                    DBO.MaintainAcceptDBO dbo = new DBO.MaintainAcceptDBO(ref USEDB);
                                    dbo.UpdateMktGiftProfile_2(InsertParameter, DBT);
                                }
                            }
                        }
                    }

                    #endregion
                }

                #endregion

                #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
            }
        }