Пример #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.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();
        }