Exemple #1
0
        private void btOK_Click(object sender, EventArgs e)
        {
            try
            {
                //0.访问入库单表,构建入库单号
                DataSet dsEntry      = baseinfo.GetAllBill("tb_entry_stock");
                int     tb_entry_row = dsEntry.Tables[0].Rows.Count;

                // 1.构建入库单表
                //入库单号
                entry_billinfo.EnOutCode = Convert.ToString(700000001 + tb_entry_row);
                //采购单号
                entry_billinfo.PurchaseCode = PurchaseCode;
                //仓管员号
                entry_billinfo.StaffCode = cbEmployeeNumber.Text;
                //入库日期
                entry_billinfo.BillDate = dateEntry.Value;

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

                DataSet dsPurchaseDetail = baseinfo.GetTableDateByFiled("tb_purchase_details", "purchase_number", PurchaseCode);

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

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

                    // 2.2.8 保存明细表
                    baseinfo.AddTableEntryStockDetail(entry_billinfo, "tb_entry_stock_details");

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