示例#1
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="ParameterList">0.V_UID.1.V_UpdateDate,2.V_AcceptNo,3.V_AcceptDate4.V_PurchaseNo,5.V_WayBillNo,6.V_InvoiceNo,7.V_TaxAmt,8.V_UtaxAmt,9.V_Tax,10.out V_ID,11.out V_Result,12. out V_Err_Msg</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>
        /// <returns></returns>
        public bool UpdateAccept(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;

            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();
                InsertParameter.Clear();
                InsertParameter.Add(UserID);//0
                InsertParameter.Add(UpdateDate);//1
                InsertParameter.Add(AcceptNo);//2
                InsertParameter.Add(PurchaseNo);//3
                InsertParameter.Add(WaybillNo);//4
                InsertParameter.Add(InvoiceNo);//5
                InsertParameter.Add(TaxAmt);//6
                InsertParameter.Add(UtaxAmt);//7
                InsertParameter.Add(Tax);//8
                InsertParameter.Add(ParameterList[10]);//9 OLD UPDATEDATE 
                InsertParameter.Add(ParameterList[11]);//10 OLD UPDATEUID

                VGIDBO.UpdateAcceptMain(InsertParameter, DBT, out ID, out Result, out ErrMsg);

                if (Result == "0")
                {
                    return false;
                }

                //新增明細

                DataTable dtStockIn = new DataTable();
                dtStockIn.Columns.Add("LocateNo");
                dtStockIn.Columns.Add("LocateSec");
                dtStockIn.Columns.Add("Item");
                dtStockIn.Columns.Add("Period");
                dtStockIn.Columns.Add("Old_Qty");
                dtStockIn.Columns.Add("New_Qty");

                //取得入庫暫存儲區、儲格
                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 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;

                    //取得入庫單調整明細資料
                    DataRow drStockIn = dtStockIn.NewRow();
                    drStockIn["LocateNo"] = LocateNo;
                    drStockIn["LocateSec"] = LocateSec;
                    drStockIn["Item"] = Item;
                    drStockIn["Period"] = Period;
                    drStockIn["Old_Qty"] = OLDQty;
                    drStockIn["New_Qty"] = AcceptQty;
                    dtStockIn.Rows.Add(drStockIn);

                    //寫入明細檔資料,逐筆寫入
                    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
                    //24 OldQty
                    VGIDBO.UpdateAcceptDetl(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(OLDQty) + int.Parse(AcceptQty) >= int.Parse(PurchaseQty))
                    {
                        InsertParameter.Clear();
                        InsertParameter.Add(UserID);
                        InsertParameter.Add(PurchaseNo);
                        InsertParameter.Add(Item);
                        InsertParameter.Add(Period);
                        InsertParameter.Add(Item);//VirtualCode = Item
                        ClosePurchaseOrderDetail(InsertParameter, DBT);
                    }
                    else
                    {
                        PIC.VDS2G.BSM.PUR.MaintainPurchaseOrder bco = new PIC.VDS2G.BSM.PUR.MaintainPurchaseOrder(strConn);
                        InsertParameter.Clear();
                        InsertParameter.Add(PurchaseNo);
                        InsertParameter.Add(Item);
                        InsertParameter.Add(Period);
                        InsertParameter.Add(Item);//VirtualCode = Item
                        bco.OpenPurchaseOrderDetail(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); //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(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(Convert.ToString(int.Parse(AcceptQty) - int.Parse(OLDQty)));
                    PURDB.UpdateGoodsInTrainsitByGoodsReceive(InsertParameter, DBT);

                    #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(InsertParameter, DBT);

                                if (GFlag == "U")
                                {
                                    //若該贈品品項的[@總驗收數]+[@驗收數量]>=[採購數量],則呼叫[MaintainPurchaseOrder.ClosePurchaseOrderDetail]
                                    if (int.Parse(GiftTotalAcceptQty) - int.Parse(GiftAcceptQty_Old) + int.Parse(GiftAcceptQty) >= int.Parse(GiftPurchaseQty))
                                    {
                                        InsertParameter.Clear();
                                        InsertParameter.Add(UserID);                                    //0
                                        InsertParameter.Add(PurchaseNo);                                //1
                                        InsertParameter.Add(dtGifts.Rows[x]["Item"].ToString());        //2
                                        InsertParameter.Add(dtGifts.Rows[x]["Period"].ToString());      //3
                                        InsertParameter.Add(dtGifts.Rows[x]["Virtual_Code"].ToString());//4

                                        ClosePurchaseOrderDetail(InsertParameter, DBT);
                                    }
                                    else
                                    {
                                        PIC.VDS2G.BSM.PUR.MaintainPurchaseOrder bco = new PIC.VDS2G.BSM.PUR.MaintainPurchaseOrder(strConn);
                                        InsertParameter.Clear();
                                        InsertParameter.Add(PurchaseNo);                                //0
                                        InsertParameter.Add(dtGifts.Rows[x]["Item"].ToString());        //1
                                        InsertParameter.Add(dtGifts.Rows[x]["Period"].ToString());      //2
                                        InsertParameter.Add(dtGifts.Rows[x]["Virtual_Code"].ToString());//3
                                        bco.OpenPurchaseOrderDetail(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 accept_qty
                                    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) - int.Parse(GiftAcceptQty_Old)));         //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(ParameterList);

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

                #region 更新稅額

                InsertParameter.Clear();
                InsertParameter.Add(AcceptNo);
                InsertParameter.Add(UserID);
                InsertParameter.Add(UpdateDate);

                VGIDBO.CalculateTax(InsertParameter, DBT);

                #endregion

                #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(AcceptNo);
                InsertParameter.Add(UserID);
                IVMDB.UpdStockIn(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
            }

        }