欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

点击结账.

程序员文章站 2022-07-13 23:10:09
...

.Xaml中:给上一个按钮

.Cs中
结账命令
public RelayCommand ButtonClickCommand { get; set; }

/// 3.3 普通结账
///
/// 当前窗口
private void ButtonClick(Window window)
{
if (MessageBox.Show(“是否结账?”, “系统提示”, MessageBoxButton.OKCancel, MessageBoxImage.Question) == MessageBoxResult.OK)
{
using (TransactionScope scope = new TransactionScope())
{
//(1)修改订单信息
B_Order pW_Order = (from tbOrder in myModels.B_Order
where tbOrder.orderID == OrderID
select tbOrder).SingleOrDefault();
pW_Order.cutOffTime = DateTime.Now;//修改结账时间
myModels.Entry(pW_Order).State = System.Data.Entity.EntityState.Modified;

                //(2)修改餐桌(修改状态)
                S_DiningTable sYS_DiningTable = (from tbDining in myModels.S_DiningTable
                                                 where tbDining.orderID == OrderID
                                                 select tbDining).SingleOrDefault();
                sYS_DiningTable.orderID = null;
                sYS_DiningTable.status = "已付款";
                sYS_DiningTable.totalMoney = 0;
                myModels.Entry(sYS_DiningTable).State = System.Data.Entity.EntityState.Modified;

                //(3)修改账号表(修改总金额,和可用余额)
                S_Account account = (from tbaccount in myModels.S_Account
                                     select tbaccount).SingleOrDefault();
                decimal? TotalMoney_ = account.TotalMoney;
                decimal? Avail_ = account.Avail;
                account.TotalMoney = TotalMoney_ + Convert.ToDecimal(txtMoney);
                account.Avail = Avail_ + Convert.ToDecimal(txtMoney);
                myModels.Entry(account).State = System.Data.Entity.EntityState.Modified;

                //(4)添加账户明细表(新增一条进账记录)
                S_AmountOfDetail amountOfDetail = new S_AmountOfDetail();
                amountOfDetail.money = Convert.ToDecimal(txtMoney);
                amountOfDetail.reason = "餐饮消费";
                amountOfDetail.time = DateTime.Now;
                amountOfDetail.remark = "餐饮收入" + Convert.ToDecimal(txtMoney) + "元," + "该金额由餐饮收入";
                amountOfDetail.capitalPosition = "收入";
                myModels.S_AmountOfDetail.Add(amountOfDetail);

                //(5)修改就餐记录
                B_EatInRecord eatInRecord = (from tbeatInRecord in myModels.B_EatInRecord
                                             where tbeatInRecord.orderID == OrderID
                                             select tbeatInRecord).SingleOrDefault();
                eatInRecord.totalMoney=Convert.ToDecimal(txtMoney);
                eatInRecord.status = "已付款";
                eatInRecord.endTime = DateTime.Now;
                myModels.Entry(eatInRecord).State = System.Data.Entity.EntityState.Modified;

                myModels.SaveChanges();
                //提交事务
                scope.Complete();
                //返回成功信息
                MessageBox.Show("结算成功!", "系统提示", MessageBoxButton.OK, MessageBoxImage.Information);
                window.Close();

            }
        }
    }
相关标签: MVVM

上一篇: MVVM

下一篇: MVVM模型介绍: