コード例 #1
0
        private void dealButton_Click(object sender, EventArgs e)
        {
            float    amount     = SqlManage.amountQuery(orderId);
            Order    order      = SqlManage.orderQuery(orderId);
            int      customerId = order.CustomerId;
            Customer customer   = SqlManage.customerQuery(customerId);

            order.IsDealed = true;
            if (amount < customer.Balance + customer.CustomerCreditLimit)
            {
                Bill     bill          = null;
                DateTime payDate       = DateTime.Now;
                float    amountPayable = amount;
                float    payAmount;
                int      billId = SqlManage.queryMaxBillId() + 1;
                if (customer.Balance < amount)
                {
                    payAmount = customer.Balance;
                }
                else
                {
                    payAmount = amount;
                }
                bill = new Bill(billId, orderId, amountPayable, payDate, payAmount);
                SqlManage.insertBill(bill);

                customer.Balance -= amount;
                if (SqlManage.updateCustomer(customer) &&
                    SqlManage.updateOrder(order))
                {
                    //更新库存
                    for (int i = 0; i < myDataGridView.RowCount - 1; i++)
                    {
                        int   goodsId  = Convert.ToInt32(myDataGridView[0, i].Value);
                        Goods goods    = SqlManage.goodsQuery(goodsId);
                        int   goodsNum = Convert.ToInt32(myDataGridView[1, i].Value);
                        goods.ActualStorage -= goodsNum;
                        SqlManage.updateGoods(goods);
                    }
                    MessageBox.Show("支付成功!");
                }
            }
            else
            {
                MessageBox.Show("已超出最大赊购限额!");
            }
        }