.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();
}
}
}