Beispiel #1
0
        //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
            }
        }
Beispiel #2
0
    private void GetDetlData(object sender)
    {
        try
        {
            VGIModel.MaintainAccept dbo = new VGIModel.MaintainAccept(ConntionDB);
            LinkButton lbtnEdit = (LinkButton)sender;
            Label lblBarcode = (Label)lbtnEdit.Parent.FindControl("lblBarcode");

            string ItemCode = string.Empty;
            string PeriodCode = string.Empty;
            string Item = string.Empty;
            string Period = string.Empty;
            string Cost = string.Empty;
            string Price = string.Empty;
            string TaxType = string.Empty;
            string PURCHASE_QTY = string.Empty;
            string PLAN_ACCEPT_DATE = string.Empty;
            string accept_qty = string.Empty;
            string Qty = string.Empty;
            string DIS_Qty = string.Empty;

            #region 根據不同BARCODE長度,取得ITEMCODE

            switch (lblBarcode.Text.Length)
            {
                case 8:
                    ItemCode = lblBarcode.Text;
                    break;
                case 13:
                    ItemCode = lblBarcode.Text;
                    break;
                case 15:
                    ItemCode = lblBarcode.Text.Substring(0, 13);
                    break;
                case 18:
                    ItemCode = lblBarcode.Text.Substring(0, 13);
                    break;
                case 10:
                    ItemCode = lblBarcode.Text.Substring(0, 8);
                    break;
                case 12:
                    ItemCode = lblBarcode.Text;
                    break;
                case 26:
                    ItemCode = lblBarcode.Text.Substring(0, 13);
                    break;
            }

            #endregion

            PeriodCode = GetPeriodCode(lblBarcode.Text);

            DataTable dt = null;
            DataTable dtGift = null;

            if (Session["MasterOLDData_" + PageTimeStamp.Value] != null)
            {
                dt = (DataTable)Session["MasterOLDData_" + PageTimeStamp.Value];
            }

            if (Session["GiftOLDData_" + PageTimeStamp.Value] != null)
            {
                dtGift = (DataTable)Session["GiftOLDData_" + PageTimeStamp.Value];
            }
            else
            {
                dtGift = GIftDetl();
            }

            Session["GiftOLDData_" + PageTimeStamp.Value] = dtGift;

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                if (dt.Rows[i]["barcode"].ToString() == lblBarcode.Text)
                {
                    this.txtBarCode.Text = lblBarcode.Text;
                    this.txtItemCode.Text = ItemCode;
                    this.txtPeriodCode.Text = dt.Rows[i]["PeriodCode"].ToString();
                    this.SLP_SKU.Text = dt.Rows[i]["Item"].ToString();
                    this.txtPeriod.Text = dt.Rows[i]["Period"].ToString();
                    this.txtPurQty.Text = dt.Rows[i]["purchase_qty"].ToString();
                    if (dt.Rows[i]["In_Date"] == "NULL")
                        this.SLP_InDate.Text = "";
                    else
                        this.SLP_InDate.Text = dt.Rows[i]["In_Date"].ToString();
                    this.txtSellPrice.Text = dt.Rows[i]["price"].ToString();
                    this.SLPAcceNum.Text = dt.Rows[i]["Acc_Qty"].ToString();
                    this.AcceNum_Old.Value = dt.Rows[i]["Acc_Qty"].ToString();

                    this.SLP_SWeight.Text = dt.Rows[i]["s_weight"].ToString();
                    this.SLP_SLength.Text = dt.Rows[i]["s_length"].ToString();
                    this.SLP_SWidth.Text = dt.Rows[i]["s_width"].ToString();
                    this.SLP_SHeigh.Text = dt.Rows[i]["s_height"].ToString();

                    this.SLP_PackNum.Text = dt.Rows[i]["package_unit"].ToString();

                    this.SLP_PWeight.Text = dt.Rows[i]["p_weight"].ToString();
                    this.SLP_PLength.Text = dt.Rows[i]["p_length"].ToString();
                    this.SLP_PWidth.Text = dt.Rows[i]["p_width"].ToString();
                    this.SLP_PHeigh.Text = dt.Rows[i]["p_height"].ToString();
                    if (dt.Rows[i]["product_source"].ToString() != "")
                    {
                        this.rbtSource.SelectedValue = dt.Rows[i]["product_source"].ToString();
                    }
                    RadioButtonList rbtReceive = (RadioButtonList)SLP_Receive.FindControl("R1");
                    rbtReceive.SelectedIndex = 0;
                    this.SLP_ReceiveDate.Text = dt.Rows[i]["allowaccept_date"].ToString();
                    this.SLP_MadeDate.Text = dt.Rows[i]["produce_date"].ToString();
                    this.SLP_Days.Text = dt.Rows[i]["reserved_period"].ToString();
                    this.SLP_EndDate.Text = dt.Rows[i]["valid_date"].ToString();

                    dbo.QueryItemData(this.txtItemCode.Text, this.txtPeriodCode.Text, this.txtPurNo.Text, out Item, out Period, out Cost,
                         out Price, out TaxType, out PURCHASE_QTY, out PLAN_ACCEPT_DATE, out accept_qty,
                         out Qty, out DIS_Qty);

                    //取得累積總驗收數和
                    if (accept_qty == "")
                    {
                        accept_qty = "0";
                    }

                    if (Qty == "")
                    {
                        Qty = "0";
                    }

                    if (DIS_Qty == "")
                    {
                        DIS_Qty = "0";
                    }
                    this.hid_TaxType.Value = TaxType;
                    if (Cost == "")
                    {
                        Cost = "0";
                    }
                    this.hid_Cost.Value = Cost;
                    this.txtTAccQty.Text = accept_qty;
                    this.txtTQty.Text = Qty;
                    this.txtDisQty.Text = DIS_Qty;
                    if (txtPurQty.Text == "")
                    {
                        txtPurQty.Text = "0";
                    }
                    this.txtTSQty.Text = (int.Parse(txtPurQty.Text) - int.Parse(txtTAccQty.Text)).ToString();

                    if (txtDisQty.Text == "")
                    {
                        txtDisQty.Text = "0";
                    }
                    this.txtLessQty.Text = (int.Parse(txtTQty.Text) - int.Parse(txtDisQty.Text)).ToString();
                }
            }

            string expression = "Item ='" + Item + "' AND period='" + Period + "'";
            DataTable dtTemp = dtGift.Clone();
            DataRow[] drs = dtGift.Select(expression);

            for (int i = 0; i < drs.Length; i++)
            {
                DataRow drtemp = dtTemp.NewRow();
                for (int j = 0; j < drs[i].ItemArray.Length; j++)
                {
                    drtemp[j] = drs[i][j];
                }
                dtTemp.Rows.Add(drtemp);
            }

            dtTemp.DefaultView.Sort = "VIRTUAL_CODE asc";
            dlGift.DataSource = dtTemp.DefaultView;
            dlGift.DataBind();

            for (int i = 0; i < dlGift.Items.Count; i++)
            {
                Label lblItem = (Label)dlGift.Items[i].FindControl("lblItem");
                Label lblPeriod = (Label)dlGift.Items[i].FindControl("lblPeriod");
                Label lblVirtualCode = (Label)dlGift.Items[i].FindControl("lblVirtualCode");
                Label lblGiftAccQty = (Label)dlGift.Items[i].FindControl("lblGiftAccQty");
                Label lblPurchase_Qty = (Label)dlGift.Items[i].FindControl("lblPurchase_Qty");
                Label lblGiftSQty = (Label)dlGift.Items[i].FindControl("lblGiftSQty");
                TextBox txtAccQty = (TextBox)dlGift.Items[i].FindControl("SLP_GiftAccQty").FindControl("TextBoxCode");
                TextBox txtPackUnit = (TextBox)dlGift.Items[i].FindControl("txt_GiftPack");

                Button btnS = (Button)dlGift.Items[i].FindControl("btnGiftS");
                TextBox txtSWe = (TextBox)dlGift.Items[i].FindControl("txt_GiftSWe");
                TextBox txtSL = (TextBox)dlGift.Items[i].FindControl("txt_GiftSL");
                TextBox txtSWi = (TextBox)dlGift.Items[i].FindControl("txt_GiftSWi");
                TextBox txtSH = (TextBox)dlGift.Items[i].FindControl("txt_GiftSH");

                Button btnP = (Button)dlGift.Items[i].FindControl("btnGiftP");
                TextBox txtPWe = (TextBox)dlGift.Items[i].FindControl("txt_GiftPWe");
                TextBox txtPL = (TextBox)dlGift.Items[i].FindControl("txt_GiftPL");
                TextBox txtPWi = (TextBox)dlGift.Items[i].FindControl("txt_GiftPWi");
                TextBox txtPH = (TextBox)dlGift.Items[i].FindControl("txt_GiftPH");

                #region 取得贈品總驗收量

                ParameterList.Clear();
                ParameterList.Add(lblItem.Text);
                ParameterList.Add(lblPeriod.Text);
                ParameterList.Add(lblVirtualCode.Text);
                ParameterList.Add(txtPurNo.Text);
                DataTable Dt_temp = dbo.GetTotalGiftPurQty(ParameterList);
                lblGiftAccQty.Text = Dt_temp.Rows[0]["accept_qty"].ToString();

                #endregion

                #region 取得贈品短缺數

                lblGiftSQty.Text = Convert.ToString(int.Parse(lblPurchase_Qty.Text) - int.Parse(lblGiftAccQty.Text));

                #endregion

                for (int j = 0; j < dtTemp.Rows.Count; j++)
                {
                    if (lblVirtualCode.Text == dtTemp.Rows[j]["VIRTUAL_CODE"].ToString())
                    {
                        txtAccQty.Text = dtTemp.Rows[j]["accept_qty"].ToString();
                        ((HiddenField)dlGift.Items[i].FindControl("GiftAccQty_Old")).Value = dtTemp.Rows[j]["Old_Qty"].ToString();
                        txtPackUnit.Text = dtTemp.Rows[j]["package_unit"].ToString();

                        txtSWe.Text = dtTemp.Rows[j]["s_weight"].ToString();
                        txtSL.Text = dtTemp.Rows[j]["s_length"].ToString();
                        txtSWi.Text = dtTemp.Rows[j]["s_width"].ToString();
                        txtSH.Text = dtTemp.Rows[j]["s_height"].ToString();

                        txtPWe.Text = dtTemp.Rows[j]["p_weight"].ToString();
                        txtPL.Text = dtTemp.Rows[j]["p_length"].ToString();
                        txtPWi.Text = dtTemp.Rows[j]["p_width"].ToString();
                        txtPH.Text = dtTemp.Rows[j]["p_height"].ToString();
                    }
                }

                if (PageMode == "0")
                {
                    txtAccQty.ReadOnly = true;
                    txtAccQty.CssClass = "readtxtbox";
                    txtPackUnit.ReadOnly = true;
                    txtPackUnit.CssClass = "readtxtbox";

                    txtSWe.ReadOnly = true;
                    txtSWe.CssClass = "readtxtbox";
                    txtSL.ReadOnly = true;
                    txtSL.CssClass = "readtxtbox";
                    txtSWi.ReadOnly = true;
                    txtSWi.CssClass = "readtxtbox";
                    txtSH.ReadOnly = true;
                    txtSH.CssClass = "readtxtbox";

                    txtPWe.ReadOnly = true;
                    txtPWe.CssClass = "readtxtbox";
                    txtPL.ReadOnly = true;
                    txtPL.CssClass = "readtxtbox";
                    txtPWi.ReadOnly = true;
                    txtPWi.CssClass = "readtxtbox";
                    txtPH.ReadOnly = true;
                    txtPH.CssClass = "readtxtbox";
                }

                string strAcceptDate = SLP_AccDate.Text.Substring(0, 4) + SLP_AccDate.Text.Substring(5, 2) + SLP_AccDate.Text.Substring(8, 2);
                string strNow = DateTime.Now.ToString("yyyyMMdd");

                if (int.Parse(strNow) > int.Parse(strAcceptDate))
                {
                    txtAccQty.ReadOnly = true;
                    txtAccQty.CssClass = "readtxtbox";

                    //btnS.Enabled = false;
                    //btnP.Enabled = false;
                }
                else
                {
                    //btnS.Enabled = true;
                    //btnP.Enabled = true;
                }
            }
        }
        catch (Exception ex)
        {
            ErrorMsgLabel.Text = ex.Message;
        }
    }
Beispiel #3
0
    //確認條碼資料
    protected void btnCheck_Click(object sender, EventArgs e)
    {
        ErrorMsgLabel.Text = "";
        string PurchaseNo = string.Empty;
        string Vendor = string.Empty;
        string Item = string.Empty;
        string Period = string.Empty;
        string Cost = string.Empty;
        string Price = string.Empty;
        string TaxType = string.Empty;
        string PURCHASE_QTY = string.Empty;
        string PLAN_ACCEPT_DATE = string.Empty;
        string accept_qty = string.Empty;
        string Qty = string.Empty;
        string DIS_Qty = string.Empty;

        this.SLP_SKU.Text = string.Empty;
        this.txtPeriod.Text = string.Empty;
        this.txtPurQty.Text = string.Empty;
        this.hid_Cost.Value = string.Empty;
        this.hid_TaxType.Value = string.Empty;
        this.SLP_InDate.Text = string.Empty;
        this.txtSellPrice.Text = string.Empty;
        this.txtTAccQty.Text = string.Empty;
        this.txtTQty.Text = string.Empty;
        this.txtDisQty.Text = string.Empty;
        this.txtTSQty.Text = string.Empty;
        this.txtLessQty.Text = string.Empty;

        bool ISOK = false;

        try
        {
            VGIModel.MaintainAccept dbo = new VGIModel.MaintainAccept(ConntionDB);

            ISOK = dbo.QueryPurchaseMaster(Request[txtItemCode.UniqueID], Request[txtPeriodCode.UniqueID], out PurchaseNo, out Vendor);

            if (this.txtPurNo.Text == string.Empty && this.SLP_Vendor.Text == string.Empty)
            {
                if (ISOK == false)
                {
                    this.ErrorMsgLabel.Text = "驗收品項資料未開立採購單";
                    this.hid_Bill_Ini.Value = "0";
                    SetClinetFocus(txtBarCode.ClientID);
                    return;
                }
                else
                {
                    this.txtPurNo.Text = PurchaseNo;
                    this.SLP_Vendor.Text = Vendor;
                }
            }
            else
            {
                if (ISOK == false)
                {
                    this.ErrorMsgLabel.Text = "驗收品項資料未開立採購單";
                    this.hid_Bill_Ini.Value = "0";
                    SetClinetFocus(txtBarCode.ClientID);
                    return;
                }
                else
                {
                    if (IsSamePurchaseNo(PurchaseNo, txtItemCode.Text, txtPeriodCode.Text) == false)
                    {
                        this.ErrorMsgLabel.Text = "驗收品項的採購單號不同,請另開驗收單進行驗收";
                        return;
                    }
                }
            }

            ISOK = dbo.QueryItemData(this.txtItemCode.Text, this.txtPeriodCode.Text, this.txtPurNo.Text, out Item, out Period, out Cost,
                                     out Price, out TaxType, out PURCHASE_QTY, out PLAN_ACCEPT_DATE, out accept_qty,
                                     out Qty, out DIS_Qty);

            if (ISOK == false)
            {
                ErrorMsgLabel.Text = "驗收品項資料未開立採購單";
                this.hid_Bill_Ini.Value = "0";
                SetClinetFocus(txtBarCode.ClientID);
                return;
            }

            string Flag = dbo.CheckItemApprove(Item, Period);

            if (Flag != "0")
            {
                if (Flag == "1")
                {
                    ErrorMsgLabel.Text = "品號" + Item + "主檔資料未審核,請先審核再進行驗收作業";
                }
                else
                {
                    ErrorMsgLabel.Text = "品號" + Item + "已過期別結束日,不可進行驗收作業";
                }

                hid_Bill_Ini.Value = "0";
                SetClinetFocus(txtBarCode.ClientID);
                return;
            }

            hid_Bill_Ini.Value = "1";
            this.SLP_SKU.Text = Item;
            this.txtPeriod.Text = Period;
            this.txtPurQty.Text = PURCHASE_QTY;
            this.hid_Cost.Value = Cost;
            this.hid_TaxType.Value = TaxType;
            this.SLP_InDate.Text = PLAN_ACCEPT_DATE;
            this.txtSellPrice.Text = Price;
            this.txtTAccQty.Text = accept_qty;
            this.txtTQty.Text = Qty;
            this.txtDisQty.Text = DIS_Qty;

            if (accept_qty == "")
            {
                txtTAccQty.Text = "0";
            }

            if (Qty == "")
            {
                txtTQty.Text = "0";
            }

            if (DIS_Qty == "")
            {
                txtDisQty.Text = "0";
            }

            this.txtTSQty.Text = (int.Parse(txtPurQty.Text) - int.Parse(txtTAccQty.Text)).ToString();
            this.txtLessQty.Text = (int.Parse(txtTQty.Text) - int.Parse(txtDisQty.Text)).ToString();

            SLP_PackNum.Text = "1";

            ParameterList.Clear();
            ParameterList.Add(Item);
            ParameterList.Add(Period);
            ParameterList.Add(DateTime.Now.ToString("yyyy/MM/dd"));
            DataTable Dt_Item = dbo.GetItemDetail(ParameterList);

            if (Dt_Item.Rows.Count > 0)
            {
                SLP_SWeight.Text = Dt_Item.Rows[0]["s_weight"].ToString();
                SLP_SLength.Text = Dt_Item.Rows[0]["s_length"].ToString();
                SLP_SWidth.Text = Dt_Item.Rows[0]["s_width"].ToString();
                SLP_SHeigh.Text = Dt_Item.Rows[0]["s_height"].ToString();
                SLP_PackNum.Text = Dt_Item.Rows[0]["package_unit"].ToString();
                SLP_PWeight.Text = Dt_Item.Rows[0]["p_weight"].ToString();
                SLP_PLength.Text = Dt_Item.Rows[0]["p_length"].ToString();
                SLP_PWidth.Text = Dt_Item.Rows[0]["p_Width"].ToString();
                SLP_PHeigh.Text = Dt_Item.Rows[0]["p_height"].ToString();
            }
            else
            {
                SLP_SWeight.Text = "0";
                SLP_SLength.Text = "0";
                SLP_SWidth.Text = "0";
                SLP_SHeigh.Text = "0";
                SLP_PackNum.Text = "0";
                SLP_PWeight.Text = "0";
                SLP_PLength.Text = "0";
                SLP_PWidth.Text = "0";
                SLP_PHeigh.Text = "0";
            }

            GiftBind();

            SetClinetFocus(SLPAcceNum.FindControl("TextBoxCode").ClientID);
        }
        catch (Exception ex)
        {
            ErrorMsgLabel.Text = ex.Message;
        }

    }
Beispiel #4
0
    //更新明細及贈品資料
    protected void btnUpdate_Click(object sender, EventArgs e)
    {
        try
        {
            bool IsOK = false;

            IsOK = CheckFill();

            if (IsOK == false)
            {
                return;
            }

            DataTable Dt = null;
            DataTable DtGift = null;

            if (Session["MasterOLDData_" + PageTimeStamp.Value] != null)
            {
                Dt = (DataTable)Session["MasterOLDData_" + PageTimeStamp.Value];
            }
            else
            {
                Dt = MaterDetl();
            }

            if (Session["GiftOLDData_" + PageTimeStamp.Value] != null)
            {
                DtGift = (DataTable)Session["GiftOLDData_" + PageTimeStamp.Value];
            }
            else
            {
                DtGift = GIftDetl();
            }

            //判斷商品有沒有重複的資料列

            bool haveData = false;
            double dblNum = 0;
            int intNum = 0;
            int U = -1;
            VGIModel.MaintainAccept dbo = new VGIModel.MaintainAccept(ConntionDB);

            for (int i = 0; i < Dt.Rows.Count; i++)
            {
                string Item = string.Empty;
                string Period = string.Empty;
                string Cost = string.Empty;
                string Price = string.Empty;
                string TaxType = string.Empty;
                string PURCHASE_QTY = string.Empty;
                string PLAN_ACCEPT_DATE = string.Empty;
                string accept_qty = string.Empty;
                string Qty = string.Empty;
                string DIS_Qty = string.Empty;

                //更新資料
                if (SLP_SKU.Text == Dt.Rows[i]["item"].ToString() && txtPeriod.Text == Dt.Rows[i]["period"].ToString())
                {
                    //取編輯品項的COST TAX_TYPE
                    dbo.QueryItemData(Dt.Rows[i]["ItemCode"].ToString(), Dt.Rows[i]["PeriodCode"].ToString(), this.txtPurNo.Text, out Item, out Period, out Cost,
                                out Price, out TaxType, out PURCHASE_QTY, out PLAN_ACCEPT_DATE, out accept_qty,
                                out Qty, out DIS_Qty);

                    Dt.Rows[i]["ItemCode"] = txtItemCode.Text;
                    Dt.Rows[i]["PeriodCode"] = txtPeriodCode.Text;
                    Dt.Rows[i]["item"] = SLP_SKU.Text;
                    Dt.Rows[i]["period"] = txtPeriod.Text;
                    Dt.Rows[i]["ItemName"] = SLP_SKU.TextBox_Name.Text;
                    Dt.Rows[i]["purchase_Qty"] = txtPurQty.Text;
                    Dt.Rows[i]["In_Date"] = SLP_InDate.Text;
                    Dt.Rows[i]["TAcc_Qty"] = txtTAccQty.Text;
                    Dt.Rows[i]["Acc_Qty"] = SLPAcceNum.Text;
                    Dt.Rows[i]["Cost"] = Cost;
                    //Dt.Rows[i]["Cost"] = this.hid_Cost.Value;
                    Dt.Rows[i]["Price"] = txtSellPrice.Text;
                    //Dt.Rows[i]["TaxType"] = this.hid_TaxType.Value;
                    Dt.Rows[i]["TaxType"] = TaxType;
                    Dt.Rows[i]["Package_Unit"] = int.TryParse(SLP_PackNum.Text, out intNum) ? int.Parse(SLP_PackNum.Text) : 0; //1包裝數
                    Dt.Rows[i]["S_Weight"] = double.TryParse(SLP_SWeight.Text, out dblNum) ? double.Parse(SLP_SWeight.Text) : 0; //單品重量
                    Dt.Rows[i]["S_Length"] = double.TryParse(SLP_SLength.Text, out dblNum) ? double.Parse(SLP_SLength.Text) : 0; //單品寬度
                    Dt.Rows[i]["S_Width"] = double.TryParse(SLP_SWidth.Text, out dblNum) ? double.Parse(SLP_SWidth.Text) : 0; //單品高度
                    Dt.Rows[i]["S_Height"] = double.TryParse(SLP_SHeigh.Text, out dblNum) ? double.Parse(SLP_SHeigh.Text) : 0; //包裝重量
                    Dt.Rows[i]["P_Weight"] = double.TryParse(SLP_PWeight.Text, out dblNum) ? double.Parse(SLP_PWeight.Text) : 0; //包裝重量
                    Dt.Rows[i]["P_Length"] = double.TryParse(SLP_PLength.Text, out dblNum) ? double.Parse(SLP_PLength.Text) : 0; //包裝長度
                    Dt.Rows[i]["P_Width"] = double.TryParse(SLP_PWidth.Text, out dblNum) ? double.Parse(SLP_PWidth.Text) : 0; //包裝寬度
                    Dt.Rows[i]["P_Height"] = double.TryParse(SLP_PHeigh.Text, out dblNum) ? double.Parse(SLP_PHeigh.Text) : 0; //包裝高度

                    if (rbtSource.Items[0].Selected || rbtSource.Items[1].Selected)
                    {
                        Dt.Rows[i]["Product_Source"] = rbtSource.SelectedValue;
                    }
                    if (SLP_MadeDate.Text != "")
                    {
                        Dt.Rows[i]["Produce_Date"] = SLP_MadeDate.Text;
                    }
                    if (SLP_Days.Text != "")
                    {
                        Dt.Rows[i]["Reserved_Period"] = SLP_Days.Text;
                    }
                    if (SLP_EndDate.Text != "")
                    {
                        Dt.Rows[i]["Valid_Date"] = SLP_EndDate.Text;
                    }
                    if (SLP_ReceiveDate.Text != "")
                    {
                        Dt.Rows[i]["AllowAccept_Date"] = SLP_ReceiveDate.Text;
                    }
                    Dt.Rows[i]["RowState"] = "U";

                    Session["MasterOLDData_" + PageTimeStamp.Value] = Dt;
                }
                else
                {
                    //非編輯品項 也要放入Session["MasterOLDData_" + PageTimeStamp.Value]
                    dbo.QueryItemData(Dt.Rows[i]["ItemCode"].ToString(), Dt.Rows[i]["PeriodCode"].ToString(), this.txtPurNo.Text, out Item, out Period, out Cost,
                               out Price, out TaxType, out PURCHASE_QTY, out PLAN_ACCEPT_DATE, out accept_qty,
                               out Qty, out DIS_Qty);

                    Dt.Rows[i]["Cost"] = Cost;
                    Dt.Rows[i]["TaxType"] = TaxType;

                    Dt.Rows[i]["RowState"] = "U";
                    Session["MasterOLDData_" + PageTimeStamp.Value] = Dt;
                }
            }

            string strUID = string.Empty;
            DateTime dtUpdatedate = DateTime.Now;

            //刪除贈品資料
            for (int i = DtGift.Rows.Count - 1; i >= 0; i--)
            {
                if (DtGift.Rows[i]["Item"].ToString() == SLP_SKU.Text && DtGift.Rows[i]["Period"].ToString() == txtPeriod.Text)
                {
                    strUID = DtGift.Rows[i]["UPDATEUID"].ToString();
                    dtUpdatedate = DateTime.Parse(DtGift.Rows[i]["UPDATEDATE"].ToString());

                    DtGift.Rows.RemoveAt(i);
                }
            }

            //插入贈品資料
            for (int i = 0; i < dlGift.Items.Count; i++)
            {
                Label lblVirtualCode = (Label)dlGift.Items[i].FindControl("lblVirtualCode");
                Label lblItem = (Label)dlGift.Items[i].FindControl("lblItem");
                Label lblPeriod = (Label)dlGift.Items[i].FindControl("lblPeriod");
                Label lblPurchase_Qty = (Label)dlGift.Items[i].FindControl("lblPurchase_Qty");
                Label lblGiftAccQty = (Label)dlGift.Items[i].FindControl("lblGiftAccQty");
                Label lblGiftItem = (Label)dlGift.Items[i].FindControl("lblGiftItem");
                TextBox txtGiftAccQty = (TextBox)dlGift.Items[i].FindControl("SLP_GiftAccQty").FindControl("TextBoxCode");
                TextBox txtGiftPack = (TextBox)dlGift.Items[i].FindControl("txt_GiftPack");
                TextBox txtGiftSWe = (TextBox)dlGift.Items[i].FindControl("txt_GiftSWe");
                TextBox txtGiftSL = (TextBox)dlGift.Items[i].FindControl("txt_GiftSL");
                TextBox txtGiftSWi = (TextBox)dlGift.Items[i].FindControl("txt_GiftSWi");
                TextBox txtGiftSH = (TextBox)dlGift.Items[i].FindControl("txt_GiftSH");
                TextBox txtGiftPWe = (TextBox)dlGift.Items[i].FindControl("txt_GiftPWe");
                TextBox txtGiftPL = (TextBox)dlGift.Items[i].FindControl("txt_GiftPL");
                TextBox txtGiftPWi = (TextBox)dlGift.Items[i].FindControl("txt_GiftPWi");
                TextBox txtGiftPH = (TextBox)dlGift.Items[i].FindControl("txt_GiftPH");
                HiddenField GiftAccQty_Old = (HiddenField)dlGift.Items[i].FindControl("GiftAccQty_Old");

                DataRow drGift = DtGift.NewRow();

                int intGiftAccQty;
                string strGiftAccQty;
                if (int.TryParse(txtGiftAccQty.Text, out intGiftAccQty))
                {
                    strGiftAccQty = txtGiftAccQty.Text;
                }
                else
                {
                    strGiftAccQty = "0";
                }

                drGift["Barcode"] = txtBarCode.Text; //商品條碼
                drGift["Item"] = lblItem.Text; //品號
                drGift["Period"] = lblPeriod.Text; //期別
                drGift["Virtual_Code"] = lblVirtualCode.Text; //虛擬品號
                drGift["purchase_Qty"] = lblPurchase_Qty.Text; //採購數量
                drGift["GiftName"] = lblGiftItem.Text;
                drGift["Accept_Qty"] = strGiftAccQty; //驗收數量
                drGift["accept_accqty"] = lblGiftAccQty.Text; //總驗收數
                drGift["Old_Qty"] = double.TryParse(GiftAccQty_Old.Value, out dblNum) ? double.Parse(GiftAccQty_Old.Value) : 0;
                drGift["SQty"] = (int.Parse(lblPurchase_Qty.Text) - int.Parse(strGiftAccQty)).ToString(); //剩餘數量
                drGift["Package_Unit"] = int.TryParse(txtGiftPack.Text, out intNum) ? int.Parse(txtGiftPack.Text) : 0; //1包裝數
                drGift["S_Weight"] = double.TryParse(txtGiftSWe.Text, out dblNum) ? double.Parse(txtGiftSWe.Text) : 0; //單品重量
                drGift["S_Length"] = double.TryParse(txtGiftSL.Text, out dblNum) ? double.Parse(txtGiftSL.Text) : 0; //單品長度
                drGift["S_Width"] = double.TryParse(txtGiftSWi.Text, out dblNum) ? double.Parse(txtGiftSWi.Text) : 0; //單品寬度
                drGift["S_Height"] = double.TryParse(txtGiftSH.Text, out dblNum) ? double.Parse(txtGiftSH.Text) : 0; //單品高度
                drGift["P_Weight"] = double.TryParse(txtGiftPWe.Text, out dblNum) ? double.Parse(txtGiftPWe.Text) : 0; //包裝重量
                drGift["P_Length"] = double.TryParse(txtGiftPL.Text, out dblNum) ? double.Parse(txtGiftPL.Text) : 0; //包裝長度
                drGift["P_Width"] = double.TryParse(txtGiftPWi.Text, out dblNum) ? double.Parse(txtGiftPWi.Text) : 0; //包裝寬度
                drGift["P_Height"] = double.TryParse(txtGiftPH.Text, out dblNum) ? double.Parse(txtGiftPH.Text) : 0; //包裝高度
                drGift["UPDATEUID"] = strUID;
                drGift["UPDATEDATE"] = dtUpdatedate;
                drGift["RowState"] = "U";

                DtGift.Rows.Add(drGift);

            }

            //檢查贈品驗收總數量需小於等於該商品驗收數量
            CheckQty(Dt, DtGift);

            //檢查材積
            //CheckSize(Dt, DtGift);

            Session["GiftOLDData_" + PageTimeStamp.Value] = DtGift;
            Session["VGI012Detl"] = Dt;
            GridView1.DataSource = Dt;
            GridView1.DataBind();

            UnfillData();

            SetClinetFocus(txtBarCode.ClientID);
        }
        catch (Exception ex)
        {
            ErrorMsgLabel.Text = ex.Message;
            ErrorDisableButton();
        }
    }