public bool GetStockQtyByLocateSec(string Item, string Period, string LocateSec, out int OnHd_Qty)
        {
            try
            {
                ArrayList ParameterList = new ArrayList();
                ParameterList.Clear();
                DBOINV.MaintainStockStatement dboINV = new DBOINV.MaintainStockStatement(strConn);
                DBOINV.SQLHelper.SQLWhere(ref ParameterList, DbType.String, "LOCATE_SECTION", LocateSec, "=", "and");
                DBOINV.SQLHelper.SQLWhere(ref ParameterList, DbType.String, "ITEM", Item, "=", "and");
                DBOINV.SQLHelper.SQLWhere(ref ParameterList, DbType.String, "PERIOD", Period, "=", "and");
                DataTable dtResult = dboINV.QueryStockStatementByFind_1(ParameterList);

                if (dtResult.Rows.Count > 0)
                {
                    OnHd_Qty = int.Parse(dtResult.Rows[0]["onhd_qty"].ToString());
                    if (OnHd_Qty == 0)
                    {
                        return false;
                    }
                }
                else
                {
                    OnHd_Qty = 0;
                    return false;
                }
                return true;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public bool GetBarCodeData(string FullBarCode, string LocateSection, out string Item, out string Period, out string Vendor, out int OnHd_Qty, out int Price, out Double Cost, out string TaxType)
        {
            bool HasData = false;
            Item = "";
            Period = "";
            Vendor = "";
            OnHd_Qty = 0;
            Price = 0;
            Cost = 0;
            TaxType = "";
            try
            {
                DBO.QueryItem dbo = new QueryItem(ref USEDB);
                INVDBO.MaintainStockStatement dboINV = new INVDBO.MaintainStockStatement(strConn);
                CGRDBO.CheckPClass dboCGR = new PIC.VDS2G.BSM.CGR.CheckPClass(ref USEDB);

                HasData = dboCGR.GetItemByBarCode(FullBarCode, out  Item, out  Period, out  Cost);

                if (HasData == true)
                {
                    HasData = dbo.GetItemPeriodMain(Item, Period, out Vendor, out Price, out Cost, out TaxType);
                    ArrayList ParameterList = new ArrayList();
                    ParameterList.Clear();
                    INVDBO.MaintainStockStatement dbINV = new INVDBO.MaintainStockStatement(strConn);
                    INVDBO.SQLHelper.SQLWhere(ref ParameterList, DbType.String, "LOCATE_SECTION", LocateSection, "=", "and");
                    INVDBO.SQLHelper.SQLWhere(ref ParameterList, DbType.String, "ITEM", Item, "=", "and");
                    INVDBO.SQLHelper.SQLWhere(ref ParameterList, DbType.String, "PERIOD", Period, "=", "and");
                    DataTable dtResult = dboINV.QueryStockStatementByFind_1(ParameterList);
                    if (dtResult.Rows.Count > 0)
                    {
                        OnHd_Qty = int.Parse(dtResult.Rows[0]["onhd_qty"].ToString());
                    }
                    else
                    {
                        OnHd_Qty = 0;
                    }
                    return true;
                }
                else
                {
                    return false;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
 public DataTable GetStockQtyByItem(string Item, string Period)
 {
     try
     {
         ArrayList ParameterList = new ArrayList();
         ParameterList.Clear();
         DBOINV.MaintainStockStatement dboINV = new DBOINV.MaintainStockStatement(strConn);
         DBOINV.SQLHelper.SQLWhere(ref ParameterList, DbType.String, "ITEM", Item, "=", "and");
         DBOINV.SQLHelper.SQLWhere(ref ParameterList, DbType.String, "PERIOD", Period, "=", "and");
         DataTable dtResult = dboINV.QueryStockStatementByFind_1(ParameterList);
         return dtResult;
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
示例#4
0
    private void InsertDetail()
    {
        ErrorMsgLabel.Text = "";
        UpdatePanel6.Update();

        string SessionIDName = "IVM10_DTL_" + PageTimeStamp.Value;

        hid_Bill_Ini.Value = "1";

        TextBox txtOutNo = (TextBox)this.SLP_Out.FindControl("TextBoxCode");
        TextBox txtOutSection = (TextBox)this.SLP_Out.FindControl("TextBoxCode2");
        TextBox txtOutSectionName = (TextBox)this.SLP_Out.FindControl("TextBoxName");

        TextBox txtInNo = (TextBox)this.SLP_In.FindControl("TextBoxCode");
        TextBox txtInSection = (TextBox)this.SLP_In.FindControl("TextBoxCode2");
        TextBox txtInSectionName = (TextBox)this.SLP_In.FindControl("TextBoxName");

        #region 檢查輸入值

        string strErr = "";

        string SugLocate = "";

        IVMModel.MaintainRemoveDataDetail BCO = new IVMModel.MaintainRemoveDataDetail(ConntionDB);

        int Qty = 0;

        if (txtOutNo.Text == string.Empty && txtOutSection.Text == string.Empty)
        {
            strErr = "請輸入移出儲位 ";
            ScriptManager.RegisterStartupScript(this.UpdatePanel1, typeof(UpdatePanel), "IVM102", "showErr('" + strErr + "');", true);
            return;
        }

        if (txtInNo.Text == string.Empty)
        {
            strErr = "請輸入移入儲區 ";
            ScriptManager.RegisterStartupScript(this.UpdatePanel1, typeof(UpdatePanel), "IVM102", "showErr('" + strErr + "');", true);
            return;
        }

        if (SLP_Out.Text == SLP_In.Text)
        {
            strErr = "移入移出儲位不得相同  ";
            SLP_In.Text = "";
            ScriptManager.RegisterStartupScript(this.UpdatePanel1, typeof(UpdatePanel), "IVM102", "showErr('" + strErr + "');", true);
            return;
        }

        if (chkEnable.Checked == false && txtInSection.Text == string.Empty)
        {
            strErr = "請輸入移入儲位或勾選建議儲位 ";
            ScriptManager.RegisterStartupScript(this.UpdatePanel1, typeof(UpdatePanel), "IVM102", "showErr('" + strErr + "');", true);
            return;
        }

        if (int.TryParse(this.txtQty.Text, out Qty) == false)
        {
            strErr = "請輸入正確數值格式 ";
            ScriptManager.RegisterStartupScript(this.UpdatePanel1, typeof(UpdatePanel), "IVM102", "showErr('" + strErr + "');", true);
            return;
        }
        else
        {
            if (Qty <= 0)
            {
                strErr = "請輸入正整數 ";
                ScriptManager.RegisterStartupScript(this.UpdatePanel1, typeof(UpdatePanel), "IVM102", "showErr('" + strErr + "');", true);
                return;
            }
        }

        if (SLP_Item.Text == string.Empty)
        {
            strErr = "請輸入品號 ";
            ScriptManager.RegisterStartupScript(this.UpdatePanel1, typeof(UpdatePanel), "IVM102", "showErr('" + strErr + "');", true);
            return;
        }

        if (SLP_Period.Text == string.Empty)
        {
            strErr = "請輸入期別 ";
            ScriptManager.RegisterStartupScript(this.UpdatePanel1, typeof(UpdatePanel), "IVM102", "showErr('" + strErr + "');", true);
            return;
        }

        if (txtQty.Text == string.Empty)
        {
            strErr = "請輸入移轉數量 ";
            ScriptManager.RegisterStartupScript(this.UpdatePanel1, typeof(UpdatePanel), "IVM102", "showErr('" + strErr + "');", true);
            return;
        }
        else
        {
            int i = 0;
            bool Result = int.TryParse(txtQty.Text, out i);
            if (Result = false)
            {
                strErr = "請輸入正確數值 ";
                ScriptManager.RegisterStartupScript(this.UpdatePanel1, typeof(UpdatePanel), "IVM102", "showErr('" + strErr + "');", true);
                return;
            }
            else
            {
                if (int.Parse(txtQty.Text) == 0)
                {
                    strErr = "請輸入有效移轉數量 ";
                    ScriptManager.RegisterStartupScript(this.UpdatePanel1, typeof(UpdatePanel), "IVM102", "showErr('" + strErr + "');", true);
                    return;
                }
            }
        }

        //判斷是否有建議儲格
        if (chkEnable.Checked == true && txtInSection.Text == string.Empty)
        {
            IVMModel.MaintainRemoveData BCOMain = new IVMModel.MaintainRemoveData(ConntionDB);
            SugLocate = BCOMain.GetSugLocate(txtOutNo.Text + txtOutSection.Text, SLP_Item.Text, SLP_Period.Text);

            if (SugLocate == string.Empty)
            {
                strErr = "此商品無可建議儲格,請手動輸入移入儲格 ";
                ScriptManager.RegisterStartupScript(this.UpdatePanel1, typeof(UpdatePanel), "IVM102", "showErr('" + strErr + "');", true);
                return;
            }
            else
            {
                txtInNo.Text = SugLocate.Substring(0, 1);
                txtInSection.Text = SugLocate.Substring(1, 5);
                lblSugSec.Text = SugLocate.Substring(1, 5);
            }
        }

        #endregion

        #region 如果沒有資料取得空DATASET

        //DataTable Dt = null;
        //DataSet Ds = new DataSet();

        //if (MasterOLDData.InnerHtml != "")
        //{
        //    System.IO.StringReader sr = new System.IO.StringReader(MasterOLDData.InnerHtml);
        //    Ds.ReadXml(sr);
        //}

        DataTable Dt = (DataTable)Session[SessionIDName];

        try
        {
            //string SessionIDName = "IVM10_DTL_" + PageTimeStamp.Value;

            if (Dt == null)
            {
                //從DB讀取一空table回來

                ParameterList.Clear();
                Dt = BCO.QueryRemoveDetlEmpty();
            }
            //else
            //{
            //    Dt = Ds.Tables[0];
            //}

            #region 取得庫存數

            int NowOnhdQty = 0;

            if (txtBarCode.Text == "")
            {
                ParameterList.Clear();

                INVModel.MaintainStockStatement dbo = new INVModel.MaintainStockStatement(ConntionDB);
                INVModel.SQLHelper.SQLWhere(ref ParameterList, DbType.String, "LOCATE_NO", txtOutNo.Text, "=", "and");
                INVModel.SQLHelper.SQLWhere(ref ParameterList, DbType.String, "LOCATE_SECTION", txtOutNo.Text + txtOutSection.Text, "=", "and");
                INVModel.SQLHelper.SQLWhere(ref ParameterList, DbType.String, "ITEM", SLP_Item.Text, "=", "and");
                INVModel.SQLHelper.SQLWhere(ref ParameterList, DbType.String, "PERIOD", SLP_Period.Text, "=", "and");
                DataTable dtResult = dbo.QueryStockStatementByFind_1(ParameterList);

                if (dtResult.Rows.Count != 1)
                {
                    if (chkEnable.Checked == true)
                        txtInSection.Text = "";
                    txtBarCode.Text = "";
                    //SLP_Item.Text = "";
                    //SLP_Period.Text = "";
                    strErr = "移出儲位的庫存數已不足! ";
                    ScriptManager.RegisterStartupScript(this.UpdatePanel1, typeof(UpdatePanel), "IVM102", "showErr('" + strErr + "');", true);
                    return;
                }
                else
                {
                    NowOnhdQty = int.Parse(dtResult.Rows[0]["onhd_qty"].ToString());
                }
            }
            else
            {
                NowOnhdQty = int.Parse(this.hid_StockQty.Value);
            }
            #endregion

            tempID = 0;

            DataView tempDT = new DataView();
            tempDT.Table = Dt.Copy();
            tempDT.Sort = "ID ASC";
            if (Dt.Rows.Count != 0)
            {
                tempID = Convert.ToInt32(tempDT[Dt.Rows.Count - 1]["ID"].ToString());
            }

            if (NowOnhdQty - int.Parse(txtQty.Text) < 0)
            {
                if (chkEnable.Checked == true)
                    txtInSection.Text = "";
                txtBarCode.Text = "";
                //SLP_Item.Text = "";
                //SLP_Period.Text = "";
                strErr = "移出儲位的庫存數已不足 ";
                ScriptManager.RegisterStartupScript(this.UpdatePanel1, typeof(UpdatePanel), "IVM102", "showErr('" + strErr + "');", true);
                return;
            }

            //如果出入庫儲位不相同需要取得入庫暫存儲位
            //if(txtOutNo.Text != txtInNo.Text)
            //{
            //    IVMModel.MaintainRemoveByPick BCOStock = new IVMModel.MaintainRemoveByPick(ConntionDB);
            //    ParameterList.Clear();
            //    ParameterList.Add(txtInNo.Text);
            //    ParameterList.Add("1");
            //    string InLocateSec = BCOStock.GetLocateSecByAttr(ParameterList);
            //    txtInNo.Text = InLocateSec.Substring(0, 1);
            //    txtInSection.Text = InLocateSec.Substring(1,5);
            //}

            //檢查是否有重複的品項、期別、儲位,重複的數量必須要加總(既有+新輸入的值)
            bool HaveData = false;

            for (int i = 0; i <= Dt.Rows.Count - 1; i++)
            {
                if ((Dt.Rows[i]["item"].ToString() == SLP_Item.Text) &&
                    (Dt.Rows[i]["period"].ToString() == SLP_Period.Text) &&
                    (Dt.Rows[i]["out_locate_section"].ToString() == txtOutNo.Text + txtOutSection.Text) &&
                    (Dt.Rows[i]["in_locate_section"].ToString() == txtInNo.Text + txtInSection.Text))
                {
                    //明細已存在加總
                    int NewOnhdQty = int.Parse(Dt.Rows[i]["remove_qty"].ToString()) + int.Parse(txtQty.Text);

                    if (NowOnhdQty - NewOnhdQty < 0)
                    {
                        if (chkEnable.Checked == true)
                            txtInSection.Text = "";
                        txtBarCode.Text = "";
                        //SLP_Item.Text = "";
                        //SLP_Period.Text = "";
                        strErr = "移出儲位的庫存數已不足 ";
                        ScriptManager.RegisterStartupScript(this.UpdatePanel1, typeof(UpdatePanel), "IVM102", "showErr('" + strErr + "');", true);
                        return;
                    }

                    Dt.Rows[i]["remove_qty"] = NewOnhdQty;
                    HaveData = true;
                }
            }

            if (HaveData == false)
            {
                IVMModel.MaintainRemoveDataDetail dboIVM = new IVMModel.MaintainRemoveDataDetail(ConntionDB);

                DataRow dRow = Dt.NewRow();

                //ID和CODE暫自訂, 真正寫入CO時會重取
                int v_ID = tempID + 1;
                int v_CODE = tempID + 1;

                dRow["item"] = SLP_Item.Text;
                dRow["period"] = SLP_Period.Text;
                if (txtBarCode.Text != string.Empty)
                {

                    string ItemName = dboIVM.GetItemName(SLP_Item.Text);
                    dRow["item_name"] = ItemName;
                }
                else
                {
                    dRow["item_name"] = SLP_Item.Name;
                }
                dRow["Out_locate_no"] = SLP_Out.Text1;
                dRow["Out_locate_section"] = SLP_Out.Text;
                dRow["Out_Locate_Name"] = SLP_Out.Text + " " + SLP_Out.Name;
                dRow["In_locate_no"] = SLP_In.Text1;
                dRow["In_locate_section"] = SLP_In.Text;
                dRow["In_Locate_Name"] = SLP_In.Text + " " + SLP_In.Name;
                dRow["onhd_qty"] = NowOnhdQty;
                dRow["remove_qty"] = int.Parse(txtQty.Text);
                if (hidCost.Value != "")
                {
                    dRow["cost"] = hidCost.Value;
                }
                else
                {
                    //手動輸入需要取得成本資料
                    double Cost = 0;
                    bool haveData = dboIVM.GetItemPeriodCost(SLP_Item.Text, SLP_Period.Text, out Cost);
                    if (haveData == false)
                    {
                        ErrorMsgLabel.Text = "查無該商品成本資料";
                        UpdatePanel6.Update();
                        return;
                    }
                    else
                    {
                        hidCost.Value = Cost.ToString();
                        dRow["cost"] = Cost.ToString();
                    }
                }
                dRow["ID"] = v_ID;

                Dt.Rows.Add(dRow);

            }

            if (this.chkEnable.Checked == true)
            {
                txtInSection.Text = "";
                this.chkEnable.Checked = true;
            }
            else
            {
                lblSugSec.Text = "";
                this.txtBarCode.Text = "";
                this.chkEnable.Checked = false;
            }

            this.SLP_Item.Text = "";
            this.SLP_Period.Text = "";
            this.txtQty.Text = "";
            this.hidCost.Value = "";
            this.txtBarCode.Text = "";

            #region 使用XML放置到前端資料

            //MasterOLDData.InnerHtml = Dt.DataSet.GetXml();

            #endregion

            GridView1.DataSource = Dt;
            GridView1.DataBind();

            Session[SessionIDName] = Dt;

            CalcuTotalRemove(Dt);

            this.txtQty.Text = "1";
        }
        catch (Exception ex)
        {
            ErrorMsgLabel.Text = ex.Message;
            UpdatePanel6.Update();
        }

        #endregion
    }
        //重新計算庫存量並更新調整數量
        /// <summary>
        /// 回傳經調整之退貨單明細
        /// </summary>
        /// <param name="LocateSection">退貨儲區</param>
        /// <param name="Dt">未更新明細資料</param>
        /// <param name="IsAdj">是否經調整 1.調整 0.未調整</param>
        /// <returns>DataTable 處理完成TABLE</returns>
        public DataTable CheckAdjustQty(string LocateSection, DataTable Dt, out string IsAdj)
        {
            try
            {
                IsAdj = "";

                ArrayList ParameterList = new ArrayList();

                for (int i = 0; i < Dt.Rows.Count; i++)
                {

                    int OnHd_Qty = 0;
                    string Item = Dt.Rows[i]["item"].ToString();
                    string Period = Dt.Rows[i]["period"].ToString();
                    int Return_Qty = int.Parse(Dt.Rows[i]["return_qty"].ToString());
                    int Remain_Qty = 0;

                    //取得庫存量OnHd_Qty
                    ParameterList.Clear();
                    INVDBO.MaintainStockStatement dboINV = new INVDBO.MaintainStockStatement(strConn);
                    INVDBO.SQLHelper.SQLWhere(ref ParameterList, DbType.String, "LOCATE_SECTION", LocateSection, "=", "and");
                    INVDBO.SQLHelper.SQLWhere(ref ParameterList, DbType.String, "ITEM", Item, "=", "and");
                    INVDBO.SQLHelper.SQLWhere(ref ParameterList, DbType.String, "PERIOD", Period, "=", "and");
                    DataTable dtResult = dboINV.QueryStockStatementByFind_1(ParameterList);
                    if (dtResult.Rows.Count > 0)
                    {
                        OnHd_Qty = int.Parse(dtResult.Rows[0]["onhd_qty"].ToString());
                    }
                    else
                    {
                        OnHd_Qty = 0;
                    }

                    Remain_Qty = OnHd_Qty - Return_Qty;
                    if (Remain_Qty < 0)
                    {
                        Dt.Rows[i]["adjust_qty"] = Remain_Qty * -1;
                        IsAdj = "1";
                    }
                    else
                    {
                        Dt.Rows[i]["adjust_qty"] = 0;
                    }
                }

                return Dt;

            }
            catch (Exception ex)
            {
                throw ex;
            }
        }