Example #1
0
        /// <summary>
        /// 进货单保存
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSave_Click(object sender, EventArgs e)
        {
            Dong.BLL.InGoods     bInGoods   = new Dong.BLL.InGoods();
            Dong.Model.InGoods   mInGoods   = new Dong.Model.InGoods();
            Dong.BLL.GoodsInfo   bGoodsInfo = new Dong.BLL.GoodsInfo();
            Dong.Model.GoodsInfo mGoodsInfo = new Dong.Model.GoodsInfo();
            for (int i = 0; i < dGV.Rows.Count; i++)
            {
                //添加进货信息
                mGoodsInfo         = bGoodsInfo.GetModel(dGV.Rows[i].Cells[1].Value.ToString());
                mInGoods.PCode     = lblCode.Text;
                mInGoods.GoodsCode = dGV.Rows[i].Cells[1].Value.ToString();
                mInGoods.Price     = double.Parse(dGV.Rows[i].Cells[3].Value.ToString());
                mInGoods.Counts    = int.Parse(dGV.Rows[i].Cells[4].Value.ToString());
                mInGoods.IDate     = DateTime.Now.Date;
                mInGoods.Oper      = txtOper.Text;
                mInGoods.Supplier  = mGoodsInfo.Supplier;
                mInGoods.Remark    = "";
                bInGoods.Add(mInGoods);

                //修改商品信息
                //进货价格
                double oldPrice1 = (double)mGoodsInfo.Price1;
                mGoodsInfo.Price1 = double.Parse(dGV.Rows[i].Cells[3].Value.ToString());

                //数量
                mGoodsInfo.Counts = mGoodsInfo.Counts + int.Parse(dGV.Rows[i].Cells[4].Value.ToString());

                //成本价
                int    totalCount = (int)mGoodsInfo.Counts + int.Parse(dGV.Rows[i].Cells[4].Value.ToString());
                double totalPrice = (oldPrice1 * (int)mGoodsInfo.Counts) + (double.Parse(dGV.Rows[i].Cells[3].Value.ToString()) * int.Parse(dGV.Rows[i].Cells[4].Value.ToString()));
                double cbPrice    = totalPrice / totalCount;
                mGoodsInfo.Price2 = cbPrice;
                bGoodsInfo.Update(mGoodsInfo);
            }

            frmInput frm = (frmInput)this.Owner;

            frm.refreshData();
            this.Close();
        }
Example #2
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            //验证商品编号

            if (tbCode.Text.Trim() == "")
            {
                MessageBoxEx.Show("请输入商品商品!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                tbCode.Focus();
                return;
            }

            //验证商品名称
            if (tbName.Text.Trim() == "")
            {
                MessageBoxEx.Show("请输入商品名称!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                tbName.Focus();
                return;
            }
            if (tbFactory.Text.Trim() == "")
            {
                MessageBoxEx.Show("请输入商品生产厂家!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                tbFactory.Focus();
                return;
            }

            if (txtPrice0.Text.Trim() == "")
            {
                MessageBoxEx.Show("请输入零售价!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtPrice0.Focus();
                return;
            }
            double price0;

            if (!double.TryParse(txtPrice0.Text, out price0))
            {
                MessageBoxEx.Show("零售价必须为数字!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtPrice0.Focus();
                return;
            }


            if (txtPrice1.Text.Trim() == "")
            {
                MessageBoxEx.Show("请输入进货价!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtPrice1.Focus();
                return;
            }
            double price1;

            if (!double.TryParse(txtPrice1.Text, out price1))
            {
                MessageBoxEx.Show("进货价必须为数字!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtPrice1.Focus();
                return;
            }

            if (txtPrice2.Text.Trim() == "")
            {
                MessageBoxEx.Show("请输入成本价!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtPrice2.Focus();
                return;
            }
            double price2;

            if (!double.TryParse(txtPrice2.Text, out price2))
            {
                MessageBoxEx.Show("成本价必须为数字!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtPrice2.Focus();
                return;
            }

            Dong.BLL.GoodsInfo   bll   = new Dong.BLL.GoodsInfo();
            Dong.Model.GoodsInfo model = new Dong.Model.GoodsInfo();
            model           = bll.GetModel(tbCode.Text);
            model.Id        = int.Parse(this.Tag.ToString());
            model.Code      = tbCode.Text;
            model.GoodsName = tbName.Text;
            if (ddlCategory.SelectedValue != null && !string.IsNullOrEmpty(ddlCategory.SelectedValue.ToString()))
            {
                model.Category     = Int32.Parse(ddlCategory.SelectedValue.ToString());
                model.CategoryName = ddlCategory.Text;
            }
            else
            {
                model.CategoryName = "";
            }
            if (ddlUnit.SelectedValue != null && !string.IsNullOrEmpty(ddlUnit.SelectedValue.ToString()))
            {
                model.Unit     = Int32.Parse(ddlUnit.SelectedValue.ToString());
                model.UnitName = ddlUnit.Text;
            }
            else
            {
                model.UnitName = "";
            }

            if (ddlSupper.SelectedValue != null && !string.IsNullOrEmpty(ddlSupper.SelectedValue.ToString()))
            {
                model.Supplier     = Int32.Parse(ddlSupper.SelectedValue.ToString());
                model.SupplierName = ddlSupper.Text;
            }
            else
            {
                model.SupplierName = "";
            }
            model.Factory = tbFactory.Text;
            model.Counts  = model.Counts;
            model.Price0  = price0;
            model.Price1  = price1;
            model.Price2  = price2;
            if (bll.Update(model))
            {
                MessageBoxEx.Show("修改成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                frmGoods frm = (frmGoods)this.Owner;
                frm.refreshData();
                this.Close();
            }
            else
            {
                MessageBoxEx.Show("修改失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }