Example #1
0
    /// <summary>
    /// 验证指定发货明细里指定行号填写的发货数量是否超过可发货数量,并保存发货数量
    /// </summary>
    /// <param name="Rowindex">行号</param>
    /// <returns>true:可以发货 false:不可发货</returns>
    private bool VerifyDeliveryQuantity(int Rowindex)
    {
        int applydetailid = (int)gv_OrderList.DataKeys[Rowindex]["ApplyDetailID"];

        ORD_OrderApplyDetail m       = new ORD_OrderApplyBLL().GetDetailModel(applydetailid);
        PDT_Product          product = new PDT_ProductBLL(m.Product).Model;

        int ApplyQuantity = m.BookQuantity + m.AdjustQuantity - m.DeliveryQuantity;

        TextBox tbx_DeliveryQuantity_T = (TextBox)gv_OrderList.Rows[Rowindex].FindControl("tbx_DeliveryQuantity_T");
        TextBox tbx_DeliveryQuantity   = (TextBox)gv_OrderList.Rows[Rowindex].FindControl("tbx_DeliveryQuantity");
        int     DeliveryQuantity       = (int.Parse(tbx_DeliveryQuantity_T.Text) * product.ConvertFactor + int.Parse(tbx_DeliveryQuantity.Text));

        if (DeliveryQuantity <= ApplyQuantity)
        {
            ListTable <ORD_OrderDeliveryDetail> _details = ViewState["Details"] as ListTable <ORD_OrderDeliveryDetail>;
            ORD_OrderDeliveryDetail             d        = _details[applydetailid.ToString()];
            d.DeliveryQuantity = DeliveryQuantity;
            d.SignInQuantity   = d.DeliveryQuantity;    //签收数量默认为实发数量
            _details.Update(d);
            return(true);
        }
        else
        {
            MessageBox.Show(this, "对不起,产品:" + product.FullName + "最多只允许发放" + GetQuantityString(m.Product, ApplyQuantity));
            return(false);
        }
    }
    protected void bt_Decrease_Click(object sender, EventArgs e)
    {
        string name = (string)gv_List.DataKeys[((GridViewRow)((Button)sender).Parent.Parent).RowIndex][0];
        ListTable <EWF_Flow_DataObject> lt = (ListTable <EWF_Flow_DataObject>)ViewState["ListTable"];

        lt[name].SortID--;
        lt.Update(lt[name]);
        //UD_Panel_ModelFieldsBLL bll = new UD_Panel_ModelFieldsBLL(id);
        //if (bll.Model.SortID > 0) bll.Model.SortID--;
        //bll.Update();

        BindGrid();
    }
Example #3
0
    protected void tbx_LostQuantity_TextChanged(object sender, EventArgs e)
    {
        TextBox tbx_sender = (TextBox)sender;
        int     Quantity   = 0;

        if (int.TryParse(tbx_sender.Text, out Quantity))
        {
            int rowindex  = ((GridViewRow)tbx_sender.Parent.Parent).RowIndex;
            int productid = (int)gv_OrderList.DataKeys[rowindex]["Product"];

            PDT_Product product = new PDT_ProductBLL(productid).Model;

            TextBox tbx_LostQuantity_T = (TextBox)gv_OrderList.Rows[rowindex].FindControl("tbx_LostQuantity_T");
            TextBox tbx_LostQuantity   = (TextBox)gv_OrderList.Rows[rowindex].FindControl("tbx_LostQuantity");

            Quantity = int.Parse(tbx_LostQuantity_T.Text) * product.ConvertFactor + int.Parse(tbx_LostQuantity.Text);
            ListTable <ORD_OrderDeliveryDetail> _details = ViewState["Details"] as ListTable <ORD_OrderDeliveryDetail>;
            ORD_OrderDeliveryDetail             detail   = _details[productid.ToString()];

            if (detail.DeliveryQuantity < detail.SignInQuantity + detail.BadQuantity + Quantity)
            {
                if (detail.DeliveryQuantity < detail.BadQuantity + Quantity)
                {
                    tbx_sender.Text = "0";
                    MessageBox.Show(this, "签收总数不能大于发货数量!");
                    return;
                }
                else
                {
                    detail.SignInQuantity = detail.DeliveryQuantity - detail.BadQuantity - Quantity;
                    detail.LostQuantity   = Quantity;
                }
            }
            else
            {
                detail.LostQuantity = Quantity;
            }

            _details.Update(detail);

            bNoSignIn = true;
            BindGrid();
        }
        else
        {
            tbx_sender.Text = "0";
        }
    }
Example #4
0
    protected void bt_SignInAll_Click(object sender, EventArgs e)
    {
        ListTable <ORD_OrderDeliveryDetail> _details = ViewState["Details"] as ListTable <ORD_OrderDeliveryDetail>;

        foreach (GridViewRow row in gv_OrderList.Rows)
        {
            int productid = (int)gv_OrderList.DataKeys[row.RowIndex]["Product"];
            ORD_OrderDeliveryDetail detail = _details[productid.ToString()];

            detail.SignInQuantity = detail.DeliveryQuantity;
            detail.BadQuantity    = 0;
            detail.LostQuantity   = 0;
            _details.Update(detail);
        }
        bNoSignIn = true;
        BindGrid();
    }
Example #5
0
    protected void btn_Save_Recipients_Click(object sender, EventArgs e)
    {
        ListTable <EWF_Flow_ProcessJointDecision_Recipients> items = (ListTable <EWF_Flow_ProcessJointDecision_Recipients>)ViewState["Details"];
        EWF_Flow_ProcessJointDecision_Recipients             m;

        if (ViewState["SelectedRecipientRole"] == null)
        {
            m = new EWF_Flow_ProcessJointDecision_Recipients();
        }
        else
        {
            m = items[ViewState["SelectedRecipientRole"].ToString()];
        }

        m.Process       = (Guid)ViewState["ProcessID"];
        m.RecipientRole = new Guid(ddl_RecipientRole_Decision.SelectedValue);
        m.DataObject    = new Guid(ddl_DataObject_Decision.SelectedValue);
        m.Remark        = tbx_Recipients_Remark.Text;

        if (m.RecipientRole == Guid.Empty)
        {
            MessageBox.Show(this, "请正确选择参与会审人员角色!");
            return;
        }

        if (ddl_DataObject_Decision.Enabled && m.DataObject == Guid.Empty)
        {
            MessageBox.Show(this, "请正确选择参与会审人员角色关联的数据对象!");
            return;
        }

        if (ViewState["SelectedRecipientRole"] == null)
        {
            items.Add(m);
        }
        else
        {
            items.Update(m);
            ViewState["SelectedRecipientRole"] = null;
            btn_Save_Recipients.Text           = "添加会审角色";
        }
        BindGrid();
    }
    protected void tbx_DeliveryQuantity_TextChanged(object sender, EventArgs e)
    {
        TextBox tbx_sender = (TextBox)sender;
        int     Quantity   = 0;

        if (int.TryParse(tbx_sender.Text, out Quantity))
        {
            int rowindex  = ((GridViewRow)tbx_sender.Parent.Parent).RowIndex;
            int productid = (int)gv_OrderList.DataKeys[rowindex]["Product"];

            PDT_Product product = new PDT_ProductBLL(productid).Model;

            TextBox tbx_DeliveryQuantity_T = (TextBox)gv_OrderList.Rows[rowindex].FindControl("tbx_DeliveryQuantity_T");
            TextBox tbx_DeliveryQuantity   = (TextBox)gv_OrderList.Rows[rowindex].FindControl("tbx_DeliveryQuantity");

            ListTable <ORD_OrderDeliveryDetail> _details = ViewState["Details"] as ListTable <ORD_OrderDeliveryDetail>;
            ORD_OrderDeliveryDetail             detail   = _details[productid.ToString()];
            detail.DeliveryQuantity = int.Parse(tbx_DeliveryQuantity_T.Text) * product.ConvertFactor + int.Parse(tbx_DeliveryQuantity.Text);

            _details.Update(detail);

            Label lb_FactoryValue = (Label)((GridViewRow)tbx_sender.Parent.Parent).FindControl("lb_FactoryValue");
            if (lb_FactoryValue != null)
            {
                lb_FactoryValue.Text = (detail.FactoryPrice * detail.DeliveryQuantity).ToString("0.##");
            }

            Label lb_SalesValue = (Label)((GridViewRow)tbx_sender.Parent.Parent).FindControl("lb_SalesValue");
            if (lb_SalesValue != null)
            {
                lb_SalesValue.Text = (detail.Price * detail.DeliveryQuantity).ToString("0.##");
            }

            lb_TotalFactoryValue.Text = _details.GetListItem().Sum(p => p.DeliveryQuantity * p.FactoryPrice).ToString("0.##");
            lb_TotalSalesValue.Text   = _details.GetListItem().Sum(p => p.DeliveryQuantity * p.Price).ToString("0.##");
        }
        else
        {
            tbx_sender.Text = "0";
        }
    }
Example #7
0
    protected void tbx_WriteOffCost_TextChanged(object sender, EventArgs e)
    {
        ListTable <FNA_FeeWriteOffDetail> _details = Session["FeeWriteOffDetails"] as ListTable <FNA_FeeWriteOffDetail>;

        TextBox tb_WriteOffCost = (TextBox)sender;
        int     id = (int)gv_List.DataKeys[((GridViewRow)tb_WriteOffCost.Parent.Parent).RowIndex]["ID"];

        FNA_FeeWriteOffDetail m = _details[id.ToString()];

        decimal writeoffcost = 0;

        if (decimal.TryParse(tb_WriteOffCost.Text, out writeoffcost))
        {
            int overpercent = 0;
            int.TryParse(new AC_AccountTitleBLL(m.AccountTitle).Model["OverPercent"], out overpercent);

            if (writeoffcost > (m.ApplyCost * (100 + overpercent) / 100))
            {
                tb_WriteOffCost.Text = m.ApplyCost.ToString("0.###");
                MessageBox.Show(this, "超可报销金额,本科目最多可超申请金额的 " + overpercent + "% 报销,最大报销金额为 " + (m.ApplyCost * (100 + overpercent) / 100).ToString() + "元");
                return;
            }

            lb_TotalCost.Text = (decimal.Parse(lb_TotalCost.Text) - m.WriteOffCost).ToString("0.###");

            m.WriteOffCost = writeoffcost;
            _details.Update(m);

            lb_TotalCost.Text = (decimal.Parse(lb_TotalCost.Text) + m.WriteOffCost).ToString("0.###");

            //DropDownList ddl_BalanceMode = (DropDownList)(((GridViewRow)tb_WriteOffCost.Parent.Parent).FindControl("ddl_BalanceMode"));
            //ddl_BalanceMode.Enabled = writeoffcost < m.ApplyCost;
        }
        else
        {
            tb_WriteOffCost.Text = m.ApplyCost.ToString("0.###");
            MessageBox.Show(this, "填写格式必需为数值型!");
        }
    }
Example #8
0
    protected void bt_SaveAdjust_Click(object sender, EventArgs e)
    {
        if ((int)ViewState["ID"] != 0)
        {
            ListTable <ORD_OrderApplyDetail> _details = ViewState["Details"] as ListTable <ORD_OrderApplyDetail>;

            foreach (GridViewRow row in gv_ProductList.Rows)
            {
                int productid = (int)gv_ProductList.DataKeys[row.RowIndex]["Product"];

                ORD_OrderApplyDetail m       = _details[productid.ToString()];
                PDT_Product          product = new PDT_ProductBLL(m.Product).Model;

                TextBox tbx_AdjustQuantity_T = (TextBox)row.FindControl("tbx_AdjustQuantity_T");
                TextBox tbx_AdjustQuantity   = (TextBox)row.FindControl("tbx_AdjustQuantity");

                int quantity = int.Parse(tbx_AdjustQuantity_T.Text) * product.ConvertFactor + int.Parse(tbx_AdjustQuantity.Text);
                if (m.BookQuantity + quantity < 0)
                {
                    MessageBox.Show(this, "对不起,扣减的调整数量不能大于定货数量!");
                    return;
                }
                m.AdjustQuantity = quantity;
                m.AdjustReason   = ((TextBox)row.FindControl("tbx_AdjustReason")).Text;

                _details.Update(m);
            }

            ORD_OrderApplyBLL bll = new ORD_OrderApplyBLL((int)ViewState["ID"]);
            bll.Items = _details.GetListItem(ItemState.Modified);

            bll.UpdateDetail();

            BindGrid();
        }
    }
Example #9
0
    protected void bt_ConfirmSignIn_Click(object sender, EventArgs e)
    {
        if ((int)ViewState["ID"] != 0)
        {
            ORD_OrderDeliveryBLL bll = new ORD_OrderDeliveryBLL((int)ViewState["ID"]);
            pn_OrderDelivery.GetData(bll.Model);
            if (bll.Model["SignInTime"] == "1900-01-01")
            {
                MessageBox.Show(this, "请选择实际到货日期!");
                return;
            }
            if (DateTime.Parse(bll.Model["SignInTime"]) > DateTime.Now)
            {
                MessageBox.Show(this, "实际到货日期不能大于今天!");
                return;
            }

            if (new CM_ClientBLL(bll.Model.Client).Model.ClientType == 2 && SVM_InventoryBLL.GetModelList("Client=" + bll.Model.Client.ToString() + " AND AccountMonth=" + bll.Model.AccountMonth.ToString() + " AND ApproveFlag=2").Count > 0)
            {
                MessageBox.ShowAndRedirect(this, "该经销商本月还有未审核库存,请先审核库存再作此操作。", "InventoryList.aspx?ClientID=" + bll.Model.Client.ToString());
                return;
            }

            ListTable <ORD_OrderDeliveryDetail> _details = ViewState["Details"] as ListTable <ORD_OrderDeliveryDetail>;

            #region 判断签收数量是否大于发放数量
            for (int i = 0; i < gv_OrderList.Rows.Count; i++)
            {
                int id = (int)gv_OrderList.DataKeys[i]["ID"];

                ORD_OrderDeliveryDetail m       = new ORD_OrderDeliveryBLL().GetDetailModel(id);
                PDT_Product             product = new PDT_ProductBLL(m.Product).Model;


                TextBox tbx_SignInQuantity_T = (TextBox)gv_OrderList.Rows[i].FindControl("tbx_SignInQuantity_T");
                TextBox tbx_SignInQuantity   = (TextBox)gv_OrderList.Rows[i].FindControl("tbx_SignInQuantity");

                TextBox tbx_BadQuantity_T = (TextBox)gv_OrderList.Rows[i].FindControl("tbx_BadQuantity_T");
                TextBox tbx_BadQuantity   = (TextBox)gv_OrderList.Rows[i].FindControl("tbx_BadQuantity");

                TextBox tbx_LostQuantity_T = (TextBox)gv_OrderList.Rows[i].FindControl("tbx_LostQuantity_T");
                TextBox tbx_LostQuantity   = (TextBox)gv_OrderList.Rows[i].FindControl("tbx_LostQuantity");

                int SignInQuantity = (int.Parse(tbx_SignInQuantity_T.Text) * product.ConvertFactor + int.Parse(tbx_SignInQuantity.Text));
                int BadQuantity    = (int.Parse(tbx_BadQuantity_T.Text) * product.ConvertFactor + int.Parse(tbx_BadQuantity.Text));
                int LostQuantity   = (int.Parse(tbx_LostQuantity_T.Text) * product.ConvertFactor + int.Parse(tbx_LostQuantity.Text));

                if (SignInQuantity < 0 || BadQuantity < 0 || LostQuantity < 0)
                {
                    MessageBox.Show(this, "对不起,产品:" + product.FullName + "签收、丢失、破损的数量不能小于0");
                    return;
                }
                if (SignInQuantity + BadQuantity + LostQuantity != m.DeliveryQuantity)
                {
                    MessageBox.Show(this, "对不起,产品:" + product.FullName + "签收、丢失、破损的数量必需等于实发数量" + GetQuantityString(m.Product, m.DeliveryQuantity));
                    return;
                }

                m.SignInQuantity = SignInQuantity;
                m.BadQuantity    = BadQuantity;
                m.LostQuantity   = LostQuantity;

                _details.Update(m);
            }
            #endregion


            bll.Model["SignInStaff"] = Session["UserID"].ToString();
            bll.Model.State          = 3; //已签收

            bll.Update();

            bll.Items = _details.GetListItem(ItemState.Modified);
            bll.UpdateDetail();

            MessageBox.ShowAndRedirect(this, "发货单签收成功!", "OrderDeliveryList.aspx");
        }
    }
Example #10
0
    private bool SaveGrid()
    {
        ListTable <FNA_FeeWriteOffDetail> _details = ViewState["Details"] as ListTable <FNA_FeeWriteOffDetail>;

        foreach (GridViewRow gr in gv_List.Rows)
        {
            int id = (int)gv_List.DataKeys[gr.RowIndex]["ID"];
            FNA_FeeWriteOffDetail item = _details.GetListItem().FirstOrDefault(p => p.ID == id);
            if (item == null)
            {
                item    = new FNA_FeeWriteOffDetail();
                item.ID = id;
            }

            item.AccountTitle = int.Parse(((DropDownList)gr.FindControl("ddl_AccountTitle")).SelectedValue);

            //忽略手工直填的电话费及手机费,必须通过专用面板加入报销信息
            if (item.AccountTitle == ConfigHelper.GetConfigInt("TeleCostACTitle") ||
                item.AccountTitle == ConfigHelper.GetConfigInt("MobileCostACTitle"))
            {
                if (((TextBox)gr.FindControl("tbx_WriteOffCost")).Enabled)
                {
                    _details.Remove(item);
                }
                continue;
            }

            if (((TextBox)gr.FindControl("tbx_WriteOffCost")).Text.Trim() != "")
            {
                item.WriteOffCost = decimal.Parse(((TextBox)gr.FindControl("tbx_WriteOffCost")).Text.Trim());
            }

            if (item.AccountTitle > 1 && item.WriteOffCost != 0)
            {
                #region 获取选择的会计月
                if (gr.FindControl("ddl_BeginMonth") != null &&
                    item.BeginMonth.ToString() != ((DropDownList)gr.FindControl("ddl_BeginMonth")).SelectedValue)
                {
                    item.BeginMonth = int.Parse(((DropDownList)gr.FindControl("ddl_BeginMonth")).SelectedValue);
                    item.EndMonth   = item.BeginMonth;

                    AC_AccountMonth month = new AC_AccountMonthBLL(item.BeginMonth).Model;
                    item.BeginDate = month.BeginDate;
                    item.EndDate   = month.EndDate;
                }
                #endregion

                item.Remark = ((TextBox)gr.FindControl("tbx_Remark")).Text;

                if (item.Remark == "")
                {
                    MessageBox.Show(this, "备注必填");
                    return(false);
                }
                _details.Update(item);
            }
            else
            {
                _details.Remove(item);
            }
        }

        return(true);
    }
Example #11
0
    protected void bt_AddProduct_Click(object sender, EventArgs e)
    {
        #region 验证必填项
        if (ViewState["Product"] == null || (int)ViewState["Product"] == 0)
        {
            lb_ProductName.Text      = "产品必填!";
            lb_ProductName.ForeColor = System.Drawing.Color.Red;
            return;
        }
        #endregion

        ListTable <PDT_ProductCost> _details = (ListTable <PDT_ProductCost>)ViewState["Details"];

        PDT_ProductCost item;
        #region 产品存在与否判断
        if (ViewState["Selected"] == null)
        {
            //新增产品
            if (_details.Contains(ViewState["Product"].ToString()))
            {
                lb_ProductName.Text = "该产品已添加!";
                return;
            }

            item              = new PDT_ProductCost();
            item.Product      = (int)ViewState["Product"];
            item.OrganizeCity = int.Parse(tr_OrganizeCity.SelectValue);
        }
        else
        {
            //修改科目
            if (!_details.Contains(ViewState["Product"].ToString()))
            {
                lb_ProductName.Text = "要修改的产品不存在!";
                return;
            }
            item = _details[ViewState["Selected"].ToString()];

            select_ProductCode.Enabled = true;
            gv_List.SelectedIndex      = -1;
        }
        #endregion

        item["CostPrice"]      = tbx_CostPrice.Text == "" ? "0" : tbx_CostPrice.Text;
        item["CostPrice2"]     = tbx_CostPrice2.Text == "" ? "0" : tbx_CostPrice2.Text;
        item["CostPrice3"]     = tbx_CostPrice3.Text == "" ? "0" : tbx_CostPrice3.Text;
        item["QuantityFactor"] = tbx_QuantityFactor.Text;


        if (ViewState["Selected"] == null)
        {
            _details.Add(item);             //新增产品
        }
        else
        {
            _details.Update(item);          //更新产品
        }
        BindGrid();

        lb_ProductName.ForeColor      = System.Drawing.Color.Black;
        select_ProductCode.SelectText = "";
        tbx_CostPrice.Text            = "0";
        tbx_CostPrice2.Text           = "0";
        tbx_CostPrice3.Text           = "0";
        tbx_QuantityFactor.Text       = "1";
        ViewState["Selected"]         = null;
        bt_AddProduct.Text            = "增加";
    }
Example #12
0
    private bool SaveGrid()
    {
        #region 获取关联品牌明细
        string relatebrands = "";
        foreach (ListItem item in cbl_Brand.Items)
        {
            if (item.Selected)
            {
                relatebrands += item.Value + ",";
            }
        }
        if (relatebrands.EndsWith(","))
        {
            relatebrands = relatebrands.Substring(0, relatebrands.Length - 1);
        }
        #endregion

        ListTable <FNA_FeeApplyDetail> _details = ViewState["Details"] as ListTable <FNA_FeeApplyDetail>;
        foreach (GridViewRow gr in gv_List.Rows)
        {
            FNA_FeeApplyDetail item = new FNA_FeeApplyDetail();
            item.ID = (int)gv_List.DataKeys[gr.RowIndex]["ID"];
            if (select_Client.SelectValue != "")
            {
                item.Client           = int.Parse(select_Client.SelectValue);
                item["RelateLinkMan"] = ddl_LinkMan.SelectedValue;
                item.SalesForcast     = decimal.Parse(tbx_SalesForcast.Text);
            }
            item.AccountTitle = int.Parse(((DropDownList)gr.FindControl("ddl_AccountTitle")).SelectedValue);
            if (((TextBox)gr.FindControl("tbx_ApplyCost")).Text.Trim() != "")
            {
                item.ApplyCost = decimal.Parse(((TextBox)gr.FindControl("tbx_ApplyCost")).Text.Trim());
            }
            if (((TextBox)gr.FindControl("tbx_DICost")).Text.Trim() != "")
            {
                item.DICost = decimal.Parse(((TextBox)gr.FindControl("tbx_DICost")).Text.Trim());
            }

            if (item.AccountTitle > 1 && item.ApplyCost != 0)
            {
                #region 获取费用的开始及截止日期
                TextBox tbx_BeginDate = (TextBox)gr.FindControl("tbx_BeginDate");
                TextBox tbx_EndDate   = (TextBox)gr.FindControl("tbx_EndDate");

                if (tbx_BeginDate != null && !string.IsNullOrEmpty(tbx_BeginDate.Text))
                {
                    item.BeginDate  = DateTime.Parse(tbx_BeginDate.Text);
                    item.BeginMonth = AC_AccountMonthBLL.GetMonthByDate(item.BeginDate);
                }
                else
                {
                    item.BeginDate  = _details[item.ID.ToString()].BeginDate;
                    item.BeginMonth = _details[item.ID.ToString()].BeginMonth;
                }

                if (tbx_EndDate != null && !string.IsNullOrEmpty(tbx_EndDate.Text))
                {
                    item.EndDate  = DateTime.Parse(tbx_EndDate.Text);
                    item.EndMonth = AC_AccountMonthBLL.GetMonthByDate(item.EndDate);
                }
                else
                {
                    item.EndDate  = _details[item.ID.ToString()].EndDate;
                    item.EndMonth = _details[item.ID.ToString()].EndMonth;
                }

                if (item.BeginDate > item.EndDate)
                {
                    MessageBox.Show(this, "费用发生范围的开始时间不能大于截止时间");
                    return(false);
                }
                #endregion
                item.LastWriteOffMonth = int.Parse(ddl_LastWriteOffMonth.SelectedValue);
                item.Remark            = ((TextBox)gr.FindControl("tbx_Remark")).Text;

                if (item.Remark == "")
                {
                    MessageBox.Show(this, "费用说明必填");
                    return(false);
                }

                if (TreeTableBLL.GetChild("MCS_PUB.dbo.AC_AccountTitle", "ID", "SuperID", item.AccountTitle).Rows.Count > 0)
                {
                    MessageBox.Show(this, "费用科目必须选择最底级会计科目!" + ((DropDownList)gr.FindControl("ddl_AccountTitle")).SelectedItem.Text);
                    return(false);
                }
                item.Flag = 1;      //未报销

                item.RelateBrands = relatebrands;
                _details.Update(item);
            }
            else
            {
                _details.Remove(item);
            }
        }

        return(true);
    }
Example #13
0
    protected void bt_AddDetail_Click(object sender, EventArgs e)
    {
        if ((int)ViewState["ID"] == 0)
        {
            return;
        }
        PBM_DeliveryBLL _bll = new PBM_DeliveryBLL((int)ViewState["ID"]);

        if (ViewState["Details"] == null)
        {
            return;
        }
        ListTable <PBM_DeliveryDetail> Details = (ListTable <PBM_DeliveryDetail>)ViewState["Details"];

        int product = 0;

        int.TryParse(select_Product.SelectValue, out product);
        //int.TryParse(RadComboBox1.SelectedValue, out product);
        if (product != 0)
        {
            PDT_ProductBLL productbll = new PDT_ProductBLL(product, true);
            if (productbll.Model == null)
            {
                return;
            }
            if (productbll.Model.ConvertFactor == 0)
            {
                productbll.Model.ConvertFactor = 1;
                productbll.Update();
            }

            string   lotnumber   = "";
            int      quantity    = 0;
            decimal  price       = 0;
            DateTime producedate = new DateTime(1900, 1, 1);


            int.TryParse(tbx_Quantity.Text, out quantity);
            decimal.TryParse(tbx_Price.Text, out price);
            DateTime.TryParse(tbx_ProductDate.Text, out producedate);
            if (producedate.Year < 1900)
            {
                producedate = new DateTime(1900, 1, 1);
            }

            if (ddl_Unit.SelectedValue == "T")
            {
                //整件单位
                quantity = quantity * productbll.Model.ConvertFactor;
                price    = price / productbll.Model.ConvertFactor;
            }

            if (quantity == 0)
            {
                //MessageBox.Show(this, "请选择采购数量!");
                return;
            }

            lotnumber = rbl_ln.SelectedValue == "N" ? tbx_LotNumber.Text : ddl_LotNumber.SelectedValue;

            if (lotnumber == "" && producedate.Year > 1900)
            {
                lotnumber = producedate.ToString("yyyyMMdd");
            }

            if ((int)ViewState["Classify"] == 12)
            {
                #region 判断库存数量是否够退货
                int inv_quantity = INV_InventoryBLL.GetProductQuantity((int)ViewState["WareHouse"], product, lotnumber);
                if (quantity > inv_quantity)
                {
                    MessageBox.Show(this, "库存不足,不可采购退货!");
                    return;
                }
                #endregion
            }
            PBM_DeliveryDetail d = null;

            if (ViewState["SelectedDetail"] != null)
            {
                d = (PBM_DeliveryDetail)ViewState["SelectedDetail"];
            }
            else
            {
                d            = new PBM_DeliveryDetail();
                d.DeliveryID = (int)ViewState["ID"];

                if (Details.GetListItem().Count == 0)
                {
                    d.ID = 1;
                }
                else
                {
                    d.ID = Details.GetListItem().Max(p => p.ID) + 1;
                }
            }

            decimal discountrate = 100;
            decimal.TryParse(tbx_DiscountRate.Text, out discountrate);

            d.Product          = product;
            d.LotNumber        = lotnumber;
            d.ProductDate      = producedate.Year < 1900 ? new DateTime(1900, 1, 1) : producedate;
            d.CostPrice        = price;
            d.Price            = d.CostPrice;
            d.DiscountRate     = discountrate / 100; //默认100为全价
            d.ConvertFactor    = productbll.Model.ConvertFactor;
            d.DeliveryQuantity = quantity;
            d.SignInQuantity   = d.DeliveryQuantity;
            d.LostQuantity     = 0;
            d.BadQuantity      = 0;
            d.SalesMode        = int.Parse(ddl_SalesMode.SelectedValue);
            if (d.SalesMode == 2)
            {
                d.Price = 0;
            }                                           //赠送模式采购价自动设为0

            if (ViewState["SelectedDetail"] != null)
            {
                Details.Update(d);
                ViewState["SelectedDetail"] = null;
                bt_AddDetail.Text           = "新 增";
                gv_List.SelectedIndex       = -1;
            }
            else
            {
                Details.Add(d);
                //_bll.AddDetail(d);
            }
            tbx_LotNumber.Text = "";
            tbx_Quantity.Text  = "0";

            BindGrid();
        }
    }
Example #14
0
    private bool SaveGrid()
    {
        ListTable <FNA_FeeWriteOffDetail> _details = Session["FeeWriteOffDetails"] as ListTable <FNA_FeeWriteOffDetail>;

        foreach (GridViewRow row in gv_List.Rows)
        {
            int id                  = (int)gv_List.DataKeys[row.RowIndex]["ID"];
            int applydetailid       = (int)gv_List.DataKeys[row.RowIndex]["ApplyDetailID"];
            FNA_FeeWriteOffDetail m = _details[id.ToString()];

            #region 保存核销开始日期
            TextBox tbx_BeginDate = (TextBox)row.FindControl("tbx_BeginDate");
            if (tbx_BeginDate != null && tbx_BeginDate.Text != "")
            {
                DateTime begin = new DateTime(1900, 1, 1);

                if (DateTime.TryParse(tbx_BeginDate.Text, out begin))
                {
                    FNA_FeeApplyDetail apply = new FNA_FeeApplyBLL().GetDetailModel(applydetailid);
                    if (begin >= apply.BeginDate && begin <= apply.EndDate && begin <= m.EndDate)
                    {
                        m.BeginDate  = begin;
                        m.BeginMonth = AC_AccountMonthBLL.GetMonthByDate(begin);
                        _details.Update(m);
                    }
                    else
                    {
                        tbx_BeginDate.Text = m.BeginDate.ToString("yyyy-MM-dd");
                        MessageBox.Show(this, "第" + (row.RowIndex + 1).ToString() + "行,报销开始日期必须在该费用申请时指定的日期范围之内!" +
                                        apply.BeginDate.ToString("yyyy-MM-dd") + " — " + apply.EndDate.ToString("yyyy-MM-dd"));
                        return(false);
                    }
                }
                else
                {
                    tbx_BeginDate.Text = m.BeginDate.ToString("yyyy-MM-dd");
                    MessageBox.Show(this, "开始日期填写格式必需为日期型!");
                    return(false);
                }
            }
            #endregion

            #region 保存核销截止日期
            TextBox tbx_EndDate = (TextBox)row.FindControl("tbx_EndDate");
            if (tbx_EndDate != null && tbx_EndDate.Text != "")
            {
                DateTime end = new DateTime(1900, 1, 1);
                if (DateTime.TryParse(tbx_EndDate.Text, out end))
                {
                    FNA_FeeApplyDetail apply = new FNA_FeeApplyBLL().GetDetailModel(applydetailid);
                    if (end >= apply.BeginDate && end <= apply.EndDate && end >= m.BeginDate)
                    {
                        m.EndDate  = end;
                        m.EndMonth = AC_AccountMonthBLL.GetMonthByDate(end);
                        _details.Update(m);
                    }
                    else
                    {
                        tbx_EndDate.Text = m.EndDate.ToString("yyyy-MM-dd");
                        MessageBox.Show(this, "第" + (row.RowIndex + 1).ToString() + "行,报销截止日期必须在该费用申请时指定的日期范围之内!" +
                                        apply.BeginDate.ToString("yyyy-MM-dd") + " — " + apply.EndDate.ToString("yyyy-MM-dd"));
                        return(false);
                    }
                }
                else
                {
                    tbx_EndDate.Text = m.BeginDate.ToString("yyyy-MM-dd");
                    MessageBox.Show(this, "截止日期填写格式必需为日期型!");
                    return(false);
                }
            }
            #endregion
            m["DiscountRate"] = "0";
            m["RebateRate"]   = "0";
            //m["VATInvoiceNO"] = "";
            m["AcceptanceNO"] = "";
            m["InvoiceDate"]  = "";
            m["DeductReason"] = "";
            #region 结余方式
            //if (m.WriteOffCost < m.ApplyCost)
            //{
            //    DropDownList ddl_BalanceMode = (DropDownList)row.FindControl("ddl_BalanceMode");
            //    m.BalanceMode = int.Parse(ddl_BalanceMode.SelectedValue);
            //}
            //else
            m.BalanceMode = 2;//不允许多次核销
            #endregion

            #region  保存备注
            TextBox tbx_Remark = (TextBox)row.FindControl("tbx_Remark");
            m.Remark = tbx_Remark.Text;
            _details.Update(m);
            #endregion
        }

        return(true);
    }
Example #15
0
    protected void bt_Add_Click(object sender, EventArgs e)
    {
        #region 验证必填项
        decimal costPrice = 0;
        if (ddl_Brand.SelectedValue == "0" || ddl_Brand.SelectedValue == "")
        {
            MessageBox.Show(this, "产品品牌必选!");
            return;
        }
        else if (ddl_GiftCostClassify.SelectedValue == "0" || ddl_GiftCostClassify.SelectedValue == "")
        {
            MessageBox.Show(this, "赠品费用类别必选!");
            return;
        }
        else if (!decimal.TryParse(tbx_CostPrice.Text, out costPrice))
        {
            MessageBox.Show(this, "赠品费率必须是小数或整数!");
            return;
        }
        #endregion

        ListTable <PDT_ClassifyGiftCostRate> _details = (ListTable <PDT_ClassifyGiftCostRate>)ViewState["Details"];

        PDT_ClassifyGiftCostRate item;
        #region 产品存在与否判断
        if (ViewState["Selected"] == null)
        {
            item = new PDT_ClassifyGiftCostRate();
            if (select_Client.SelectValue == "" || select_Client.SelectValue == "0")
            {
                item.OrganizeCity = int.Parse(tr_OrganizeCity.SelectValue);
            }
            else
            {
                item.Client       = int.Parse(select_Client.SelectValue.ToString());
                item.OrganizeCity = new CM_ClientBLL(item.Client).Model.OrganizeCity;
            }
            item["InsertStaff"] = Session["UserID"].ToString();
            ViewState["MAXID"]  = ((int)ViewState["MAXID"]) + 1;
            item.ID             = (int)ViewState["MAXID"];
        }
        else
        {
            //修改科目
            if (!_details.Contains(ViewState["Selected"].ToString()))
            {
                MessageBox.Show(this, "要修改的产品不存在!");
                return;
            }
            item = _details[ViewState["Selected"].ToString()];
            item["UpdateStaff"]   = Session["UserID"].ToString();
            gv_List.SelectedIndex = -1;
        }
        #endregion

        item["PDTBrand"] = ddl_Brand.SelectedValue;

        item["GiftCostClassify"] = ddl_GiftCostClassify.SelectedValue;
        item["Enabled"]          = ddl_Enabled.SelectedValue;

        item["GiftCostRate"] = tbx_CostPrice.Text;
        item["UpdateStaff"]  = Session["UserID"].ToString();
        item.BeginMonth      = int.Parse(ddl_BeginMonth.SelectedValue);
        int cycle = 0;
        if (int.TryParse(txt_Cycle.Text.Trim(), out cycle))
        {
            item.Cycle = cycle;
        }
        item.Remark = tbx_Remark.Text.Trim();

        if (ViewState["Selected"] == null)
        {
            foreach (PDT_ClassifyGiftCostRate p in _details.GetListItem())
            {
                if (p.PDTBrand == item.PDTBrand && p.GiftCostClassify == item.GiftCostClassify)
                {
                    MessageBox.Show(this, "已存在该分类的数据!");
                    return;
                }
            }

            _details.Add(item);
        }
        else
        {
            _details.Update(item);          //更新产品
        }


        BindGrid();
        ddl_Brand.SelectedValue            = "0";
        ddl_GiftCostClassify.SelectedValue = "0";
        ddl_Brand.Enabled            = true;
        ddl_GiftCostClassify.Enabled = true;
        tbx_CostPrice.Text           = "";
        tbx_Remark.Text       = "";
        ViewState["Selected"] = null;
        bt_Add.Text           = "增加";
    }
Example #16
0
    protected void bt_AddDetail_Click(object sender, EventArgs e)
    {
        if ((int)ViewState["ID"] == 0)
        {
            return;
        }
        PBM_DeliveryBLL _bll = new PBM_DeliveryBLL((int)ViewState["ID"]);

        if (ViewState["Details"] == null)
        {
            return;
        }
        ListTable <PBM_DeliveryDetail> Details = (ListTable <PBM_DeliveryDetail>)ViewState["Details"];

        int product = 0;

        int.TryParse(select_Product.SelectValue, out product);
        //int.TryParse(RadComboBox1.SelectedValue, out product);
        if (product != 0)
        {
            PDT_ProductBLL productbll = new PDT_ProductBLL(product, true);
            if (productbll.Model == null)
            {
                return;
            }
            if (productbll.Model.ConvertFactor == 0)
            {
                productbll.Model.ConvertFactor = 1;
                productbll.Update();
            }

            int     quantity = 0;
            decimal price    = 0;

            int.TryParse(tbx_Quantity.Text, out quantity);
            decimal.TryParse(tbx_Price.Text, out price);

            if (ddl_Unit.SelectedValue == "T")
            {
                //整件单位
                quantity = quantity * productbll.Model.ConvertFactor;
                price    = price / productbll.Model.ConvertFactor;
            }

            if (quantity == 0)
            {
                MessageBox.Show(this, "请填写数量!");
                return;
            }

            if ((int)ViewState["Classify"] != 2)
            {
                #region 销售时判断库存数量是否够退货
                int inv_quantity = INV_InventoryBLL.GetProductQuantity((int)ViewState["WareHouse"], product, ddl_LotNumber.SelectedValue);
                if (quantity > inv_quantity)
                {
                    MessageBox.Show(this, "库存不足,不可销售出库!");
                    return;
                }
                #endregion
            }

            INV_Inventory inv = INV_InventoryBLL.GetInventoryByProductAndLotNumber((int)ViewState["WareHouse"],
                                                                                   product, ddl_LotNumber.SelectedValue);
            if (inv == null)
            {
                MessageBox.Show(this, "请正确选择销售批号!");
                return;
            }

            PBM_DeliveryDetail d = null;

            if (ViewState["SelectedDetail"] != null)
            {
                d = (PBM_DeliveryDetail)ViewState["SelectedDetail"];
            }
            else
            {
                d            = new PBM_DeliveryDetail();
                d.DeliveryID = (int)ViewState["ID"];

                if (Details.GetListItem().Count == 0)
                {
                    d.ID = 1;
                }
                else
                {
                    d.ID = Details.GetListItem().Max(p => p.ID) + 1;
                }
            }

            d.Product          = product;
            d.LotNumber        = ddl_LotNumber.SelectedValue;
            d.CostPrice        = inv.Price;     //成本价取当前库存表的价格
            d.Price            = price;         //实际销售价
            d.ConvertFactor    = productbll.Model.ConvertFactor;
            d.DiscountRate     = 1;             //默认全价
            d.DeliveryQuantity = quantity;
            d.SignInQuantity   = d.DeliveryQuantity;
            d.LostQuantity     = 0;
            d.BadQuantity      = 0;
            d.SalesMode        = 1;
            if (d.SalesMode == 2)
            {
                d.Price = 0;
            }

            if (ViewState["SelectedDetail"] != null)
            {
                Details.Update(d);
                //_bll.UpdateDetail(d);
                ViewState["SelectedDetail"] = null;
                bt_AddDetail.Text           = "新 增";
                gv_List.SelectedIndex       = -1;
            }
            else
            {
                Details.Add(d);
                //_bll.AddDetail(d);
            }

            tbx_Quantity.Text = "0";

            BindGrid();
        }
    }
Example #17
0
    protected void bt_AddProduct_Click(object sender, EventArgs e)
    {
        #region 验证必填项
        if (ViewState["Product"] == null || (int)ViewState["Product"] == 0)
        {
            lb_ErrInfo1.Text = "产品必填!";
            return;
        }

        #endregion

        ListTable <PDT_ProductPrice_Detail> _details = ViewState["Details"] as ListTable <PDT_ProductPrice_Detail>;

        PDT_ProductPrice_Detail item;

        #region 产品存在与否判断
        if (ViewState["Selected"] == null)
        {
            //新增产品
            if (_details.Contains(ViewState["Product"].ToString()))
            {
                lb_ErrInfo1.Text = "该产品已添加!";
                return;
            }

            item         = new PDT_ProductPrice_Detail();
            item.Product = (int)ViewState["Product"];
        }
        else
        {
            //修改科目
            if (!_details.Contains(ViewState["Product"].ToString()))
            {
                lb_ErrInfo1.Text = "要修改的产品不存在!";
                return;
            }
            item = _details[ViewState["Selected"].ToString()];

            select_ProductCode.Enabled = true;
            gv_List.SelectedIndex      = -1;
        }
        #endregion

        lb_ProductName.ForeColor = System.Drawing.Color.Black;

        item.BuyingPrice = tbx_BuyingPrice.Text == "" ? 0 : decimal.Parse(tbx_BuyingPrice.Text);
        item.SalesPrice  = tbx_SalesPrice.Text == "" ? 0 : decimal.Parse(tbx_SalesPrice.Text);

        if (ViewState["Selected"] == null)
        {
            _details.Add(item);             //新增产品
        }
        else
        {
            _details.Update(item);          //更新产品
        }
        BindGrid();

        lb_ErrInfo1.Text     = "";
        tbx_BuyingPrice.Text = "";
        tbx_SalesPrice.Text  = "";

        ViewState["Selected"] = null;
    }
Example #18
0
    protected void bt_Save_Click(object sender, EventArgs e)
    {
        ORD_OrderCartBLL cart = null;

        if (Session["LogisticsOrderApplyDetail"] != null)
        {
            cart = (ORD_OrderCartBLL)Session["LogisticsOrderApplyDetail"];
        }

        ListTable <ORD_OrderApplyDetail> _details = ViewState["Details"] as ListTable <ORD_OrderApplyDetail>;
        ORD_OrderApplyBLL bll;

        if ((int)ViewState["ID"] == 0)
        {
            bll = new ORD_OrderApplyBLL();
        }
        else
        {
            bll = new ORD_OrderApplyBLL((int)ViewState["ID"]);
        }

        pn_OrderApply.GetData(bll.Model);

        #region 保存明细
        foreach (GridViewRow row in gv_ProductList.Rows)
        {
            int productid = (int)gv_ProductList.DataKeys[row.RowIndex]["Product"];

            ORD_OrderApplyDetail m       = _details[productid.ToString()];
            PDT_Product          product = new PDT_ProductBLL(m.Product).Model;

            TextBox tbx_price          = (TextBox)row.FindControl("tbx_Price");
            TextBox tbx_BookQuantity_T = (TextBox)row.FindControl("tbx_BookQuantity_T");
            TextBox tbx_BookQuantity   = (TextBox)row.FindControl("tbx_BookQuantity");

            int quantity = int.Parse(tbx_BookQuantity_T.Text) * product.ConvertFactor + int.Parse(tbx_BookQuantity.Text);

            m.BookQuantity = quantity;
            m.Price        = decimal.Parse(tbx_price.Text);

            _details.Update(m);
        }
        #endregion

        if ((int)ViewState["ID"] == 0)
        {
            double DelayDays = Convert.ToDouble(System.Configuration.ConfigurationManager.AppSettings["OrderDelayDays"]);
            bll.Model.OrganizeCity    = cart.OrganizeCity;
            bll.Model.Client          = cart.Client;
            bll.Model.PublishID       = cart.Publish;
            bll.Model.AccountMonth    = AC_AccountMonthBLL.GetMonthByDate(DateTime.Now.AddDays(-DelayDays));
            bll.Model.SheetCode       = ORD_OrderApplyBLL.GenerateSheetCode(bll.Model.OrganizeCity, bll.Model.AccountMonth); //自动产生备案号
            bll.Model.ApproveFlag     = 2;
            bll.Model.State           = 1;
            bll.Model.InsertStaff     = (int)Session["UserID"];
            bll.Model["IsSpecial"]    = cart.IsSpecial.ToString();
            bll.Model.Type            = cart.Type;
            bll.Model["ProductBrand"] = cart.Brand.ToString();
            bll.Model["ProductType"]  = cart.OrderType.ToString();
            bll.Items = _details.GetListItem();

            ViewState["ID"] = bll.Add();
        }
        else
        {
            bll.Model.UpdateStaff = (int)Session["UserID"];
            bll.Update();

            #region 修改明细

            bll.Items = _details.GetListItem(ItemState.Modified);
            bll.UpdateDetail();

            #endregion
        }

        if (sender != null)
        {
            Response.Redirect("OrderProductApplyDetail.aspx?ID=" + ViewState["ID"].ToString());
        }
    }
    protected void bt_AddDetail_Click(object sender, EventArgs e)
    {
        ListTable <CM_ContractDetail> _details = ViewState["Details"] as ListTable <CM_ContractDetail>;

        DateTime begindate     = new DateTime();
        DateTime enddate       = new DateTime();
        TextBox  tbx_BeginDate = pl_detail.FindControl("CM_Contract_BeginDate") == null ? null : (TextBox)pl_detail.FindControl("CM_Contract_BeginDate");
        TextBox  tbx_EndDate   = pl_detail.FindControl("CM_Contract_EndDate") == null ? null : (TextBox)pl_detail.FindControl("CM_Contract_EndDate");

        if (tbx_BeginDate != null && tbx_EndDate != null)
        {
            DateTime.TryParse(tbx_BeginDate.Text, out begindate);
            DateTime.TryParse(tbx_EndDate.Text, out enddate);
            if (enddate < begindate)
            {
                MessageBox.Show(this, "协议终止日期不能小于起始日期。");
                return;
            }
        }

        if (ddl_PayMode.SelectedValue == "0")
        {
            MessageBox.Show(this, "付款周期必选!");
            return;
        }


        CM_ContractDetail item;

        if (ViewState["Selected"] == null)
        {
            //新增科目
            if (_details.Contains(ddl_AccountTitle.SelectedValue))
            {
                MessageBox.Show(this, "该科目已添加!");
                return;
            }

            item = new CM_ContractDetail();
            item.AccountTitle = int.Parse(ddl_AccountTitle.SelectedValue);
            if (TreeTableBLL.GetChild("MCS_PUB.dbo.AC_AccountTitle", "ID", "SuperID", item.AccountTitle).Rows.Count > 0)
            {
                MessageBox.Show(this, "费用科目必须选择最底级会计科目!" + ddl_AccountTitle.SelectedItem.Text);
                return;
            }
        }
        else
        {//修改科目
            if (!_details.Contains(ddl_AccountTitle.SelectedValue))
            {
                MessageBox.Show(this, "要修改的项目不存在!");
                return;
            }
            item = _details[ViewState["Selected"].ToString()];
        }
        item.ApplyLimit = decimal.Parse(tbx_ApplyLimit.Text);
        if (item.ApplyLimit == 0)
        {
            MessageBox.Show(this, "对不起,月费用金额不能为0!");
            return;
        }
        item.PayMode = int.Parse(ddl_PayMode.SelectedValue);

        if (ViewState["Selected"] == null)
        {
            _details.Add(item);
        }
        else
        {
            _details.Update(item);
        }

        BindGrid();

        tbx_ApplyLimit.Text   = "0";
        bt_AddDetail.Text     = "新增";
        ViewState["Selected"] = null;
    }
Example #20
0
    protected void bt_AddDetail_Click(object sender, EventArgs e)
    {
        if ((int)ViewState["ID"] == 0)
        {
            return;
        }
        PBM_OrderBLL _bll = new PBM_OrderBLL((int)ViewState["ID"]);

        if (ViewState["Details"] == null)
        {
            return;
        }
        ListTable <PBM_OrderDetail> Details = (ListTable <PBM_OrderDetail>)ViewState["Details"];

        int product = 0;

        int.TryParse(select_Product.SelectValue, out product);
        //int.TryParse(RadComboBox1.SelectedValue, out product);
        if (product != 0)
        {
            PDT_ProductBLL productbll = new PDT_ProductBLL(product, true);
            if (productbll.Model == null)
            {
                return;
            }
            if (productbll.Model.ConvertFactor == 0)
            {
                productbll.Model.ConvertFactor = 1;
                productbll.Update();
            }

            int     quantity = 0;
            decimal price    = 0;

            int.TryParse(tbx_Quantity.Text, out quantity);
            decimal.TryParse(tbx_Price.Text, out price);

            if (ddl_Unit.SelectedValue == "T")
            {
                //整件单位
                quantity = quantity * productbll.Model.ConvertFactor;
                price    = price / productbll.Model.ConvertFactor;
            }

            if (quantity == 0)
            {
                MessageBox.Show(this, "请填写数量!");
                return;
            }

            PBM_OrderDetail d = null;

            if (ViewState["SelectedDetail"] != null)
            {
                d = (PBM_OrderDetail)ViewState["SelectedDetail"];
            }
            else
            {
                d         = new PBM_OrderDetail();
                d.OrderID = (int)ViewState["ID"];

                if (Details.GetListItem().Count == 0)
                {
                    d.ID = 1;
                }
                else
                {
                    d.ID = Details.GetListItem().Max(p => p.ID) + 1;
                }
            }

            d.Product           = product;
            d.Price             = price;        //实际销售价
            d.DiscountRate      = 1;            //默认全价
            d.ConvertFactor     = productbll.Model.ConvertFactor;
            d.BookQuantity      = quantity;
            d.ConfirmQuantity   = quantity;
            d.DeliveredQuantity = 0;
            d.SalesMode         = int.Parse(ddl_SalesMode.SelectedValue);
            if (d.SalesMode == 2)
            {
                d.Price = 0;
            }

            if (ViewState["SelectedDetail"] != null)
            {
                Details.Update(d);
                ViewState["SelectedDetail"] = null;
                bt_AddDetail.Text           = "新 增";
                gv_List.SelectedIndex       = -1;
            }
            else
            {
                Details.Add(d);
            }

            tbx_Quantity.Text = "0";

            BindGrid();
        }
    }
    private bool Save()
    {
        if (ViewState["Details"] == null)
        {
            return(false);
        }
        ListTable <PBM_DeliveryDetail> Details = (ListTable <PBM_DeliveryDetail>)ViewState["Details"];

        PBM_DeliveryBLL _bll = new PBM_DeliveryBLL((int)ViewState["ID"]);

        pl_detail.GetData(_bll.Model);

        #region 判断必填项
        if (_bll.Model.Supplier == 0)
        {
            MessageBox.Show(this, "请正确选择供货商!");
            return(false);
        }

        if (_bll.Model.SupplierWareHouse == 0)
        {
            MessageBox.Show(this, "请正确选择盘点仓库!");
            return(false);
        }
        #endregion

        #region 循环设置盘点调整数量
        foreach (GridViewRow row in gv_List.Rows)
        {
            int _id = (int)gv_List.DataKeys[row.RowIndex]["ID"];
            PBM_DeliveryDetail d = Details[_id.ToString()];

            if (d == null)
            {
                continue;
            }
            int     quantity       = 0;
            TextBox tbx_Quantity_T = (TextBox)row.FindControl("tbx_Quantity_T");
            TextBox tbx_Quantity_P = (TextBox)row.FindControl("tbx_Quantity_P");

            if (tbx_Quantity_T != null)
            {
                int.TryParse(tbx_Quantity_T.Text, out quantity);
                d.DeliveryQuantity = quantity * d.ConvertFactor;
            }

            if (tbx_Quantity_P != null)
            {
                int.TryParse(tbx_Quantity_P.Text, out quantity);
                d.DeliveryQuantity += quantity;
            }

            DropDownList ddl_Mode = (DropDownList)row.FindControl("ddl_Mode");
            if (ddl_Mode != null && ddl_Mode.SelectedValue == "D")
            {
                int inv_quantity = 0;
                int.TryParse(d["PreInventoryQuantity"], out inv_quantity);
                if (inv_quantity < d.DeliveryQuantity)
                {
                    MessageBox.Show(this, "盘亏数量不能大于当前库存!");
                    return(false);
                }

                d.DeliveryQuantity = -1 * d.DeliveryQuantity;
                d.SignInQuantity   = d.DeliveryQuantity;
            }

            Details.Update(d);
        }
        #endregion

        _bll.Model.DiscountAmount = 0;
        _bll.Model.WipeAmount     = 0;

        //实际成交价
        _bll.Model.ActAmount = Math.Round(Details.GetListItem().Sum(p => Math.Round(p.Price * p.ConvertFactor, 2) * p.DeliveryQuantity / p.ConvertFactor), 2);

        if ((int)ViewState["ID"] != 0)
        {
            //修改
            _bll.Model.UpdateStaff = (int)Session["UserID"];

            #region 保存明细
            foreach (PBM_DeliveryDetail d in Details.GetListItem(ItemState.Modified))
            {
                _bll.UpdateDetail(d);
            }
            #endregion

            if (_bll.Update() == 0)
            {
                return(true);
            }
        }

        return(false);
    }
    //新增
    protected void bt_Add_Click(object sender, EventArgs e)
    {
        ListTable <EWF_Flow_DataObject> lt = (ListTable <EWF_Flow_DataObject>)ViewState["ListTable"];

        if (ViewState["SelectedName"] == null)
        {
            if (!lt.Contains(tbx_Name.Text))
            {
                #region 新增数据字段
                EWF_Flow_DataObject item = new EWF_Flow_DataObject();
                item["App"]               = ViewState["AppID"].ToString();
                item["Name"]              = tbx_Name.Text;
                item["DisplayName"]       = tbx_DisplayName.Text;
                item["DataType"]          = ddl_DataType.SelectedValue;
                item["ReadOnly"]          = rbl_ReadOnly.SelectedValue;
                item["Enable"]            = rbl_Enable.SelectedValue;
                item["Visible"]           = rbl_Visible.SelectedValue;
                item["ControlType"]       = ddl_ControlType.SelectedValue;
                item["ControlWidth"]      = tbx_ControlWidth.Text;
                item["ControlHeight"]     = tbx_ControlHeight.Text;
                item["ControlStyle"]      = tbx_ControlStyle.Text;
                item["ColSpan"]           = tbx_ColSpan.Text;
                item["SortID"]            = tbx_SortID.Text;
                item["IsRequireField"]    = rbl_IsRequireField.SelectedValue;
                item["RegularExpression"] = tbx_RegularExpression.Text;
                item["FormatString"]      = tbx_FormatString.Text;
                item["Description"]       = tbx_Description.Text;
                item["RelationType"]      = rbl_RelationType.SelectedValue;

                if (item["RelationType"] != "3")
                {
                    item["RelationTableName"] = ddl_RelationTableName.SelectedValue;
                    if (item["RelationType"] == "2")
                    {
                        item["RelationValueField"] = ddl_RelationValueField.SelectedValue;
                        item["RelationTextField"]  = ddl_RelationTextField.SelectedValue;
                    }
                }
                item["SearchPageURL"] = tbx_SearchPageURL.Text;
                lt.Add(item);
                #endregion
            }
        }
        else
        {
            if (lt.Contains((string)ViewState["SelectedName"]))
            {
                #region 修改数据字段
                EWF_Flow_DataObject item = lt[(string)ViewState["SelectedName"]];

                item["App"]               = ViewState["AppID"].ToString();
                item["Name"]              = tbx_Name.Text;
                item["DisplayName"]       = tbx_DisplayName.Text;
                item["DataType"]          = ddl_DataType.SelectedValue;
                item["ReadOnly"]          = rbl_ReadOnly.SelectedValue;
                item["Enable"]            = rbl_Enable.SelectedValue;
                item["Visible"]           = rbl_Visible.SelectedValue;
                item["ControlType"]       = ddl_ControlType.SelectedValue;
                item["ControlWidth"]      = tbx_ControlWidth.Text;
                item["ControlHeight"]     = tbx_ControlHeight.Text;
                item["ControlStyle"]      = tbx_ControlStyle.Text;
                item["ColSpan"]           = tbx_ColSpan.Text;
                item["SortID"]            = tbx_SortID.Text;
                item["IsRequireField"]    = rbl_IsRequireField.SelectedValue;
                item["RegularExpression"] = tbx_RegularExpression.Text;
                item["FormatString"]      = tbx_FormatString.Text;
                item["Description"]       = tbx_Description.Text;
                item["RelationType"]      = rbl_RelationType.SelectedValue;
                if (item["RelationType"] != "3")
                {
                    item["RelationTableName"] = ddl_RelationTableName.SelectedValue;
                    if (item["RelationType"] == "2")
                    {
                        item["RelationValueField"] = ddl_RelationValueField.SelectedValue;
                        item["RelationTextField"]  = ddl_RelationTextField.SelectedValue;
                    }
                }
                item["SearchPageURL"] = tbx_SearchPageURL.Text;
                lt.Update(item);
                #endregion
            }

            ViewState["SelectedName"] = null;
        }

        bt_Add.Text           = "新 增";
        gv_List.SelectedIndex = -1;

        tbx_DisplayName.Text = "";
        tbx_Name.Text        = "";
        tbx_SortID.Text      = (int.Parse(tbx_SortID.Text) + 1).ToString();
        BindGrid();
    }