Exemple #1
0
        private void btSave_Click(object sender, EventArgs e)
        {
            try
            {
                // 1.构建采购订单表
                // 1.1 采购订单号
                purchaseBillinfo.BillCode = txPurchaseNumber.Text;
                // 1.2 供应商编号
                purchaseBillinfo.SupplierCode = cbSupplierNumber.Text;
                // 1.3 采购员工号
                purchaseBillinfo.BuyerCode = cbEmployeeNumber.Text;
                // 1.4 下单日期
                purchaseBillinfo.BillDate = dateOrder.Value;
                // 1.5 要货日期
                purchaseBillinfo.DeadLine = dateReceive.Value;
                // 1.6 订单金额
                purchaseBillinfo.TotalPayment = Convert.ToSingle(txTotalPay.Text);
                // 1.7订单状态
                purchaseBillinfo.Status = "待入库";

                // 2.构建采购订单明细表
                // 2.1 检查每条明细数据是否合格
                for (int i = 0; i < dtPurchaseDetail.RowCount - 1; i++)
                {
                    if (Convert.ToInt32(dtPurchaseDetail[4, i].Value) <= 0)
                    {
                        MessageBox.Show("第 " + Convert.ToString(i) + " 条明细数量错误!", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }

                    if (Convert.ToSingle(dtPurchaseDetail[5, i].Value) <= 0)
                    {
                        MessageBox.Show("第 " + Convert.ToString(i) + " 条明细单价错误!", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                }
                // 2.2
                DataSet dsPurchaseDetail = baseinfo.GetAllBill("tb_purchase_details");
                int     rowCount         = dsPurchaseDetail.Tables[0].Rows.Count;
                for (int i = 0; i < dtPurchaseDetail.RowCount - 1; i++)
                {
                    // 2.2.0 自动增长明细编号
                    //// 2.2.1 明细流水号
                    //purchaseBillinfo.SerialNumber = Convert.ToString(rowCount + i);
                    // 2.2.2 明细编号
                    purchaseBillinfo.PurchaseDetaildCode = Convert.ToString(700000001 + rowCount + i);
                    // 2.2.3 采购订单号
                    purchaseBillinfo.BillCode = txPurchaseNumber.Text;
                    // 2.2.4 商品编号
                    purchaseBillinfo.goodsCode = cbGoodsNumber.Text;
                    // 2.2.5 商品数量
                    purchaseBillinfo.Qty = Convert.ToSingle(dtPurchaseDetail[4, i].Value);
                    // 2.2.6 商品单价
                    purchaseBillinfo.goodsPrice = Convert.ToSingle(dtPurchaseDetail[5, i].Value);
                    // 2.2.7 商品单位
                    purchaseBillinfo.goodsUnit = Convert.ToString(dtPurchaseDetail[3, i].Value);
                    // 2.2.8 保存明细表
                    baseinfo.AddTablePurchaseDetail(purchaseBillinfo, "tb_purchase_details");

                    // 2.2.9 增加明细表 row 数,在缓存中
                    rowCount += i;
                }
                // 3.保存采购订单
                baseinfo.AddTablePurchase(purchaseBillinfo, "tb_purchase");
                MessageBox.Show("采购单--过账成功!", "成功提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (System.Exception ex)
            {
                MessageBox.Show("非法数据!", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            this.Close();
        }