Beispiel #1
0
    //新增明細
    protected void btnAdd_Click(object sender, EventArgs e)
    {
        ErrorMsgLabel.Text = "";

        string SessionIDName = "VGR01_DTL_" + PageTimeStamp.Value;
        //宣告殘餘數量
        int Remain_Qty = 0;
        
        //調整數量
        int Adjust_Qty = 0;

        #region 檢查輸入值

        string strErr = "";

        string SugLocate = "";

        string strTaxType = "";

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

        if (SLP_Period.Text == string.Empty)
        {
            strErr = "請輸入期間 ";
            //this.ErrorMsgLabel.Text = strErr;
            ScriptManager.RegisterStartupScript(this.UpdatePanel1, typeof(UpdatePanel), "VGR012", "alert('" + strErr + "');", true);
            return;
        }

        if (SLP_ReturnQty.Text == string.Empty)
        {
            strErr = "請輸入退貨數量 ";
            //this.ErrorMsgLabel.Text = strErr;
            //ScriptManager.RegisterStartupScript(this.UpdatePanel1, typeof(UpdatePanel), "隨便寫", "document.getElementById('" + this.SLP_ReturnQty.FindControl("TextBoxCode").ClientID + "').focus();", true);   
            ScriptManager.RegisterStartupScript(this.UpdatePanel1, typeof(UpdatePanel), "VGR012", "alert('" + strErr + "');", true);
            return;
        }
        //else
        //{
        //    if (int.Parse(SLP_ReturnQty.Text) < 1)
        //    {
        //        strErr = "[退貨數量]欄必須為正整數 ";
        //        this.ErrorMsgLabel.Text = strErr;
        //        SLP_ReturnQty.Text = "";
        //        return;
        //    }
        //}

        if (txtOnHDQty.Text == "")
        {
            txtOnHDQty.Text = "0";
        }

        #endregion

        #region 判斷新增的資料

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

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

        try
        {
            IVMModel.MaintainRemoveDataDetail dboIVM = new IVMModel.MaintainRemoveDataDetail(ConntionDB);
            VGRModel.MaintainReturnData BCOVGR = new VGRModel.MaintainReturnData(ConntionDB);

            //變更DATATABLE 資料內容
            for (int i = 0; i < GridView1.Rows.Count; i++)
            {
                Label lblItem = (Label)GridView1.Rows[i].FindControl("lblItem");
                Label lblPeriod = (Label)GridView1.Rows[i].FindControl("lblPeriod");
                Label lblOnhdQty = (Label)GridView1.Rows[i].FindControl("lblOnhdQty");
                Label lblRemainQty = (Label)GridView1.Rows[i].FindControl("lblRemainQty");
                TextBox txtReturnQty = (TextBox)GridView1.Rows[i].FindControl("txtReturnQty");
                

                for (int x = 0; x < Ds.Tables[0].Rows.Count; x++)
                {
                    string Item = Ds.Tables[0].Rows[x]["item"].ToString();
                    string Period = Ds.Tables[0].Rows[x]["period"].ToString();

                    if (lblItem.Text == Item && lblPeriod.Text == Period)
                    {
                        if (int.Parse(txtReturnQty.Text) + int.Parse(lblOnhdQty.Text) >= 0)
                        {
                            Ds.Tables[0].Rows[x]["return_qty"] = txtReturnQty.Text;
                            Ds.Tables[0].Rows[x]["remain_qty"] = (int.Parse(lblOnhdQty.Text) - int.Parse(txtReturnQty.Text)).ToString();

                            if(int.Parse(lblOnhdQty.Text) - int.Parse(txtReturnQty.Text) > 0)
                            {
                                Ds.Tables[0].Rows[x]["adjust_qty"] = "0";
                            }
                            else
                            {
                                Ds.Tables[0].Rows[x]["adjust_qty"] = ((int.Parse(lblOnhdQty.Text) - int.Parse(txtReturnQty.Text)) * -1).ToString();
                            }

                            break;

                        }
                        else
                        {
                            ScriptManager.RegisterStartupScript(this.UpdatePanel1, typeof(UpdatePanel), "隨便寫", "document.getElementById('" + txtReturnQty.ClientID + "').focus();", true);
                            return;
                        }
                    }
                }
            }

            if (Ds.Tables.Count == 0)
            {
                //從DB讀取一空table回來
   
                ParameterList.Clear();
                Dt = BCOVGR.QueryReturnDetlEmpty();
            }
            else
            {
                Dt = Ds.Tables[0];
            }

            //如果不是使用BARCODE輸入,取得商品資料
            if(txtBarCode.Text == "")
            {
                string Vendor = "";
                int Onhd_Qty = 0;
                int Price = 0;
                Double Cost = 0;
                string TaxType = "";
                VGRModel.MaintainReturnData BCO = new VGRModel.MaintainReturnData(ConntionDB);
                bool HaveData = BCO.GetItemData(SLP_Item.Text, SLP_Period.Text, hid_LocateSection.Value.ToString(), out Vendor, out Onhd_Qty, out Price, out Cost, out TaxType);
                hid_Vendor_Temp.Value = Vendor.ToString();
                hid_Price.Value = Price.ToString();
                hid_Cost.Value = Cost.ToString();
                hid_Tax_Type.Value = TaxType.ToString() ;
                if (HaveData == true)
                    txtOnHDQty.Text = Onhd_Qty.ToString();
                else
                    txtOnHDQty.Text = "0";
            }

            //檢查是否有重複的品項、期別、儲位
            bool haveData = false;

            ArrayList TaxList = new ArrayList();

            TaxList = TaxTypeList;

            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))
                {
                    Remain_Qty = int.Parse(this.txtOnHDQty.Text) - int.Parse(SLP_ReturnQty.Text);
                    if (Remain_Qty < 0)
                    {
                        Adjust_Qty = Remain_Qty * -1;
                    }
                    else
                    {
                        Adjust_Qty = 0;
                    }
                    haveData = true;
                    Dt.Rows[i]["return_qty"] =int.Parse(SLP_ReturnQty.Text);
                    Dt.Rows[i]["old_return_qty"] = int.Parse(SLP_ReturnQty.Text);
                    Dt.Rows[i]["adjust_qty"] = Adjust_Qty;
                    Dt.Rows[i]["remain_qty"] = Remain_Qty;
                    Dt.Rows[i]["isChange"] = "N";
                }
            }

            strTaxType = hid_Tax_Type.Value;

            bool InList = false;

            //紀錄TaxType類型   
            for (int j = 0; j < TaxList.Count; j++)
            {
                if (strTaxType == TaxList[j].ToString())
                {
                    InList = true;
                }
            }

            if (InList == false)
            {
                TaxList.Add(strTaxType);
            }

            TaxTypeList = TaxList;

            if(haveData == false)
            {
                if ((SLP_Vendor.Text != string.Empty && this.hid_CurrentVendor.Value == "")||(SLP_Vendor.Text == string.Empty && this.hid_CurrentVendor.Value == "") || (this.hid_CurrentVendor.Value == this.hid_Vendor_Temp.Value && this.hid_CurrentVendor.Value == this.SLP_Vendor.Text))
                {
                    
                    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());
                    }

                    DataRow dRow = Dt.NewRow();

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

                    Remain_Qty = int.Parse(this.txtOnHDQty.Text) - int.Parse(SLP_ReturnQty.Text);
                    if (Remain_Qty < 0)
                    {
                        Adjust_Qty = Remain_Qty * -1;
                    }
                    else
                    {
                        Adjust_Qty = 0;
                    }

                    dRow["item"] = SLP_Item.Text;
                    dRow["period"] = SLP_Period.Text;
                    if (SLP_Item.Name != "")
                    {
                        dRow["item_name"] = SLP_Item.Name;
                    }
                    else
                    {
                        string ItemName = dboIVM.GetItemName(SLP_Item.Text);
                        dRow["item_name"] = ItemName;
                    }
                    dRow["price"] = hid_Price.Value;
                    dRow["onhd_qty"] = txtOnHDQty.Text;
                    dRow["return_qty"] = SLP_ReturnQty.Text;
                    dRow["old_return_qty"] = SLP_ReturnQty.Text;
                    dRow["remain_qty"] = Remain_Qty;
                    dRow["adjust_qty"] = Adjust_Qty;
                    dRow["cost"] = hid_Cost.Value;
                    dRow["tax_type"] = hid_Tax_Type.Value;
                    dRow["ID"] = v_ID;
                    dRow["isChange"] = "N";
                    Dt.Rows.Add(dRow);

                    if (this.SLP_Vendor.Text == string.Empty)
                    {
                        SLP_Vendor.Text = hid_Vendor_Temp.Value;
                    }

                    if (this.hid_CurrentVendor.Value == "")
                    {
                        this.hid_CurrentVendor.Value = SLP_Vendor.Text;
                    }
                    
                }
                else
                {
                    strErr = "不為此供應商品項 ";
                    txtBarCode.Text = "";
                    this.hid_Vendor_Temp.Value = "";
                    //this.ErrorMsgLabel.Text = strErr;
                    //ScriptManager.RegisterStartupScript(this.UpdatePanel1, typeof(UpdatePanel), "隨便寫", "document.getElementById('" + this.txtBarCode.ClientID + "').focus();", true);
                    ScriptManager.RegisterStartupScript(this.UpdatePanel1, typeof(UpdatePanel), "VGR012", "alert('" + strErr + "');", true);
                    return;
                }
            }

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

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

            #endregion
            Session[SessionIDName] = Dt;
            GridView1.DataSource = Dt;
            GridView1.DataBind();

            CalcuTotalRemove(Dt);

            //改由db計算
            //CalcuTotalTax(Dt);

            this.SLP_Item.Text = string.Empty;
            this.SLP_Period.Text = string.Empty;
            this.txtOnHDQty.Text = string.Empty;
            this.SLP_ReturnQty.Text = string.Empty;

            //this.hid_Tax_Total_Amt.Value = string.Empty;
            //this.hid_UnTax_Total_Amt.Value = string.Empty;
            //this.hid_Tax_ReMain_Amt.Value = string.Empty;
            //this.hid_UnTax_ReMain_Amt.Value = string.Empty;
            //this.hid_Tax_Amt.Value = string.Empty;

            for (int i = 0; i < GridView1.Rows.Count; i++)
            {
                TextBox txtReturnQty = (TextBox)GridView1.Rows[i].FindControl("txtReturnQty");
                Label lblReturnQty = (Label)GridView1.Rows[i].FindControl("lblReturnQty");
                txtReturnQty.Visible = true;
                lblReturnQty.Visible = false;
            }

            if (this.hid_Page_Status.Value == "INSERT")
            {
                GridView1.Columns[8].Visible = false;
                GridView1.Columns[9].Visible = false;
            }
            else if (this.hid_Page_Status.Value == "UPDATE")
            {
                GridView1.Columns[8].Visible = false;
                GridView1.Columns[9].Visible = false;
                GridView1.Columns[11].Visible = false;
            }

            txtBarCode.Text = "";

            ScriptManager.RegisterStartupScript(this.UpdatePanel1, typeof(UpdatePanel), "隨便寫", "document.getElementById('" + this.txtBarCode.ClientID + "').focus();", true);

        }
        catch (Exception ex)
        {
            ErrorMsgLabel.Text = ex.Message;
        }

        #endregion
    }
Beispiel #2
0
    public static string GetItemInfo(string Item,string Period, string LocateSection)
    {
        bool HaveData = false;
        string vendor = string.Empty;
        int OnHd_Qty = 0;
        int Price = 0;
        double Cost = 0;
        string TaxType = string.Empty;

        VGRModel.MaintainReturnData BCO = new VGRModel.MaintainReturnData(ConntionDB);
        HaveData = BCO.GetItemData(Item, Period, LocateSection, out vendor, out OnHd_Qty, out Price, out Cost, out TaxType);

        if (HaveData == true)
            return vendor + "," + OnHd_Qty.ToString() + "," + Price + "," + Cost.ToString() + "," + TaxType;
        else
            return vendor + "," + "0" + "," + Price + "," + Cost.ToString() + "," + TaxType;
    }