Exemple #1
0
        private void btOK_Click(object sender, EventArgs e)
        {
            try
            {
                //先检查数据是否合法,检查出库明细是否合法
                for (int i = 0; i < dgvList.RowCount - 1; i++)
                {
                    if (Convert.ToInt32(dgvList[3, i].Value) <= 0 ||
                        Convert.ToInt32(dgvList[3, i].Value) > Convert.ToInt32(dgvList[6, i].Value))
                    {
                        MessageBox.Show("第 " + Convert.ToString(i) + " 条明细数量错误,无法出库!", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                }

                //0.访问出库单表,构建出库单号
                DataSet dsOutStock = baseinfo.GetAllBill("tb_out_stock");
                int     tb_out_row = dsOutStock.Tables[0].Rows.Count;

                // 1.构建出库单表
                //出库单号
                out_billinfo.EnOutCode = Convert.ToString(700000001 + tb_out_row);
                //销售单号
                out_billinfo.OrdersCode = SalesCode;
                //仓管员号
                out_billinfo.StaffCode = cbEmployeeNumber.Text;
                //出库日期
                out_billinfo.BillDate = dateTimeOutStock.Value;

                // 2.构建入库单明细表
                // 2.2
                DataSet dsOutDetail = baseinfo.GetAllBill("tb_out_stock_details");
                int     rowCount    = dsOutDetail.Tables[0].Rows.Count;
                //先把库存表读取出来
                DataSet dsStock = null;//baseinfo.GetAllBill("tb_stock");

                //把销售明细读出来,以便获取商品编号
                DataSet dsSalesDetail = baseinfo.GetTableDateByFiled("tb_sales_details", "sales_number", SalesCode);

                for (int i = 0; i < dgvList.RowCount - 1; i++)
                {
                    // 2.2.0 自动增长明细编号
                    // 2.2.2 明细编号
                    out_billinfo.EnOutDetailCode = Convert.ToString(700000001 + rowCount + i);

                    // 2.2.3 入库单号
                    out_billinfo.EnOutCode = Convert.ToString(700000001 + tb_out_row);
                    // 2.2.4 商品编号
                    out_billinfo.GoodCode = dsSalesDetail.Tables[0].Rows[i]["goods_number"].ToString();
                    // 2.2.5 商品数量
                    out_billinfo.Qty = Convert.ToInt32(dgvList[3, i].Value);

                    // 2.2.8 保存出库明细表
                    baseinfo.AddTableOutStockDetail(out_billinfo, "tb_out_stock_details");

                    //2.2.9 更新库存(减库存)
                    stockinfo.TradeCode = out_billinfo.GoodCode;
                    dsStock             = baseinfo.GetTableDateByFiled("tb_stock", "goods_number", out_billinfo.GoodCode);
                    stockinfo.TradeCode = out_billinfo.GoodCode;
                    stockinfo.Qty       = Convert.ToSingle(dsStock.Tables[0].Rows[0]["stock"].ToString()) - out_billinfo.Qty;
                    baseinfo.UpdateStockQty(stockinfo);
                    // 2.2.9 增加明细表 row 数,在缓存中
                    rowCount += i;
                }
                // 3.保存出库单
                baseinfo.AddTableOutStock(out_billinfo, "tb_out_stock");
                MessageBox.Show("出库单--过账成功!", "成功提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                //4.更新销售单状态
                saleinfo.BillCode = SalesCode;
                saleinfo.Status   = "已出库";
                baseinfo.UpdateSalesStatu(saleinfo);
                MessageBox.Show("销售单状态更新成功!", "成功提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.Close();
            }
            catch (System.Exception ex)
            {
                MessageBox.Show("数据错误,出库失败!", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                //return;
            }
        }