Exemplo n.º 1
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            //往来单位和经手人不能为空
            if (txtHandle.Text == string.Empty || txtUnits.Text == string.Empty)
            {
                MessageBox.Show("供货单位和经手人为必填项!", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            //列表中数据不能为空
            if (Convert.ToString(dgvStockList[3, 0].Value) == string.Empty || Convert.ToString(dgvStockList[4, 0].Value) == string.Empty || Convert.ToString(dgvStockList[5, 0].Value) == string.Empty)
            {
                MessageBox.Show("请核实列表中数据:‘数量’、‘单价’、‘金额’不能为空!", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            //应付金额不能为空
            if (txtFullPayment.Text.Trim() == "0")
            {
                MessageBox.Show("应付金额不能为‘0’!", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            //向进货表(主表)录入商品单据信息
            billinfo.BillCode    = txtBillCode.Text;
            billinfo.Handle      = txtHandle.Text;
            billinfo.Units       = txtUnits.Text;
            billinfo.Summary     = txtSummary.Text;
            billinfo.FullPayment = Convert.ToSingle(txtFullPayment.Text);
            billinfo.Payment     = Convert.ToSingle(txtpayment.Text);
            //执行添加操作
            baseinfo.AddTableMainWarehouse(billinfo, "tb_warehouse_main");
            //向进货(明细表)中录入商品单据信息
            for (int i = 0; i < dgvStockList.RowCount - 1; i++)
            {
                billinfo.BillCode  = txtBillCode.Text;
                billinfo.TradeCode = dgvStockList[0, i].Value.ToString();
                billinfo.FullName  = dgvStockList[1, i].Value.ToString();
                billinfo.TradeUnit = dgvStockList[2, i].Value.ToString();
                billinfo.Qty       = Convert.ToSingle(dgvStockList[3, i].Value.ToString());
                billinfo.Price     = Convert.ToSingle(dgvStockList[4, i].Value.ToString());
                billinfo.TSum      = Convert.ToSingle(dgvStockList[5, i].Value.ToString());
                //执行多行录入数据(添加到明细表中)
                baseinfo.AddTableDetailedWarehouse(billinfo, "tb_warehouse_detailed");
                //更改库存数量和加权平均价格
                DataSet ds = null;//创建数据集对象
                stockinfo.TradeCode = dgvStockList[0, i].Value.ToString();
                ds                     = baseinfo.GetStockByTradeCode(stockinfo, "tb_stock");
                stockinfo.Qty          = Convert.ToSingle(ds.Tables[0].Rows[0]["qty"]);
                stockinfo.Price        = Convert.ToSingle(ds.Tables[0].Rows[0]["price"]);
                stockinfo.AveragePrice = Convert.ToSingle(ds.Tables[0].Rows[0]["averageprice"]);
                //处理--加权平均价格
                if (stockinfo.Price == 0)
                {
                    stockinfo.AveragePrice = billinfo.Price; //第一次进货时,加权平均价格等于进货价格
                    stockinfo.Price        = billinfo.Price; //获取单价
                }
                else
                {
                    //加权平均价格=(加权平均价*库存总数量+本次进货价格*本次进货数量)/(库存总数量+本次进货数量)
                    stockinfo.AveragePrice = ((stockinfo.AveragePrice * stockinfo.Qty + billinfo.Price * billinfo.Qty) / (stockinfo.Qty + billinfo.Qty));
                }
                //更新--商品库存数量
                stockinfo.Qty = stockinfo.Qty + billinfo.Qty;
                int d = baseinfo.UpdateStock_QtyAndAveragerprice(stockinfo);//执行更新操作
            }
            //向往来单位明细表--录入数据--这样一来为分析
            currentAccount.BillCode            = txtBillCode.Text;
            currentAccount.ReduceGathering     = Convert.ToSingle(txtFullPayment.Text);
            currentAccount.FactReduceGathering = Convert.ToSingle(txtpayment.Text);
            currentAccount.Balance             = Convert.ToSingle(txtBalance.Text);
            currentAccount.Units = txtUnits.Text;
            //执行添加操作
            int ca = baseinfo.AddCurrentAccount(currentAccount);

            MessageBox.Show("进货单--过账成功!", "成功提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            this.Close();//关闭当前窗体
        }
Exemplo n.º 2
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            //往来单位和经手人不能为空!
            if (txtHandle.Text == string.Empty || txtUnits.Text == string.Empty)
            {
                MessageBox.Show("供货单位和经手人为必填项!", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            //列表中数据不能为空
            if (Convert.ToString(dgvStockList[3, 0].Value) == string.Empty || Convert.ToString(dgvStockList[4, 0].Value) == string.Empty || Convert.ToString(dgvStockList[5, 0].Value) == string.Empty)
            {
                MessageBox.Show("请核实列表中数据:‘数量’、‘单价’、‘金额’不能为空!", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            //应付金额不能为空
            if (txtFullPayment.Text.Trim() == "0")
            {
                MessageBox.Show("应付金额不能为‘0’!", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            //向销售表(主表)录入商品单据信息
            billinfo.BillCode    = txtBillCode.Text;
            billinfo.Handle      = txtHandle.Text;
            billinfo.Units       = txtUnits.Text;
            billinfo.Summary     = txtSummary.Text;
            billinfo.FullPayment = Convert.ToSingle(txtFullPayment.Text);
            billinfo.Payment     = Convert.ToSingle(txtpayment.Text);
            //执行添加
            baseinfo.AddTableMainSellhouse(billinfo, "tb_sell_main");

            //向销售(明细表)中录入商品单据信息
            for (int i = 0; i < dgvStockList.RowCount - 1; i++)
            {
                billinfo.BillCode  = txtBillCode.Text;
                billinfo.TradeCode = dgvStockList[0, i].Value.ToString();
                billinfo.FullName  = dgvStockList[1, i].Value.ToString();
                billinfo.TradeUnit = dgvStockList[2, i].Value.ToString();
                billinfo.Qty       = Convert.ToSingle(dgvStockList[3, i].Value.ToString());
                billinfo.Price     = Convert.ToSingle(dgvStockList[4, i].Value.ToString());
                billinfo.TSum      = Convert.ToSingle(dgvStockList[5, i].Value.ToString());
                //执行多行录入数据(添加到明细表中)
                baseinfo.AddTableDetailedWarehouse(billinfo, "tb_sell_detailed");
                //更改库存数量
                DataSet ds = null;
                stockinfo.TradeCode = dgvStockList[0, i].Value.ToString();
                ds            = baseinfo.GetStockByTradeCode(stockinfo, "tb_Stock");
                stockinfo.Qty = Convert.ToSingle(ds.Tables[0].Rows[0]["qty"]);

                stockinfo.Qty = stockinfo.Qty - billinfo.Qty;
                int d = baseinfo.UpdateSaleStock_Qty(stockinfo);
            }
            //向往来单位明细表--录入数据--这样以来为分析
            currentAccount.BillCode     = txtBillCode.Text;
            currentAccount.AddGathering = Convert.ToSingle(txtFullPayment.Text);
            currentAccount.FactAddFee   = Convert.ToSingle(txtpayment.Text);
            currentAccount.Balance      = Convert.ToSingle(txtBalance.Text);
            currentAccount.Units        = txtUnits.Text;
            //执行添加
            int ca = baseinfo.AddCurrentAccount(currentAccount);

            MessageBox.Show("销售单--过账成功!", "成功提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            this.Close();
        }