private void Load_Order_ProductByOrdrtId(int p) { R_Order_ProductBll rop = new R_Order_ProductBll(); dgvROrderProduct.AutoGenerateColumns = false; //禁止自动生成列 dgvROrderProduct.DataSource = rop.GetR_Order_ProductByOrderId(p); dgvROrderProduct.ClearSelection(); //清除选中项 }
//退菜操作 private void btnDeleteRorderPro_Click(object sender, EventArgs e) { if (dgvROrderProduct.SelectedRows.Count <= 0) { md.MsgDivShow("请先选中要退的菜"); return; } else { int rOrderProId = ((R_Order_Product)dgvROrderProduct.SelectedRows[0].DataBoundItem).ROrderProId; R_Order_ProductBll ropBll = new R_Order_ProductBll(); md.MsgDivShow(ropBll.SoftDeleteR_Order_ProductByROrderProId(rOrderProId) ? "成功" : "失败", 1); LoadR_Order_ProductByOrdrtId(Convert.ToInt32(labOrderId.Text)); //刷新 } }
//显示点的菜 private void LoadR_Order_ProductByOrdrtId(int p) { R_Order_ProductBll ropBll = new R_Order_ProductBll(); dgvROrderProduct.AutoGenerateColumns = false; dgvROrderProduct.DataSource = ropBll.GetR_Order_ProductByOrderId(p); dgvROrderProduct.ClearSelection();//清除默认选中项 //显示总金额和总数量 R_Order_Product rop = ropBll.GetCountAndSumMoney(Convert.ToInt32(labOrderId.Text)); //总金额 labSumMoney.Text = rop.Money.ToString(); labCount.Text = rop.Count.ToString(); //总数量 }
//结账 private void btnAccounts_Click(object sender, EventArgs e) { //餐桌状态发生改变 DeskInfoBLL dkbll = new DeskInfoBLL(); bool dkResult = dkbll.UpdateDeskInfoStateByDeskId(Convert.ToInt32(labdkId.Text), 0); //订单状态发生改变 OrderInfoBll orderBll = new OrderInfoBll(); OrderInfo order = new OrderInfo(); order.EndTime = System.DateTime.Now; //当前的时间 order.OrderMoney = Convert.ToDouble(lblMoney.Text); //结账后的金额 order.OrderState = 2; //状态 order.OrderId = Convert.ToInt32(labOrderId.Text); if (cmbMember.SelectedIndex != 0) { //获取选中的会员对象 MemberInfo mem = (MemberInfo)cmbMember.SelectedItem; order.OrderMemberId = mem.MemberId; //会员的id order.DisCount = mem.MemDiscount; //折扣 //根据会员的id更新该会员的金额 MemberInfoBl memBll = new MemberInfoBl(); //得到会员的金额 double money = Convert.ToDouble(labyuMoney.Text) - Convert.ToDouble(lblMoney.Text); //更新会员余额 memBll.UpdateMemberMoneyById(mem.MemberId, money);//==不接收了 } //更新订单中的金额 bool orderResult = orderBll.UpdateOrderInfo(order); //会员结账----更改会员余额 //改变订单对应的订单和菜单的中间表中的菜的状态 R_Order_ProductBll ropBll = new R_Order_ProductBll(); bool ropResult = ropBll.UpdateR_Order_ProductDelFlagByOrderId(Convert.ToInt32(labOrderId.Text)); if (dkResult && orderResult & ropResult) { md.MsgDivShow("顾客结账成功", 1); } else { md.MsgDivShow("结账失败了", 1); } }
//用户双击该控件发生 private void dgvProduct_CellDoubleClick(object sender, DataGridViewCellEventArgs e) { //判断是都选中了菜 if (dgvProduct.SelectedRows.Count <= 0) { md.MsgDivShow("请先选中要添加的菜", 1); return; } int tCount; if (string.IsNullOrEmpty(txtCount.Text) || txtCount.Text == "1" || txtCount.Text == "0") { //txtCount.Text = "1"; tCount = 1; } //判断文本框中输入的数量 else if (!int.TryParse(txtCount.Text, out tCount))//转换不成功 说明txtCount没有值 { md.MsgDivShow("请输入正确个数", 1); return; } //文本框的数量转换成功了 //获取选中菜的Id====添加到中间表(订单和菜的中间表) //int proId=((ProductInfo)dgvProduct.SelectedRows[0].DataBoundItem).ProId;//菜的Id R_Order_Product rop = new R_Order_Product();//中间表对象 rop.DelFlag = 0; rop.OrderId = Convert.ToInt32(labOrderId.Text); //订单的id // rop.ProId=proId;//菜的Id rop.ProId = ((ProductInfo)dgvProduct.SelectedRows[0].DataBoundItem).ProId; //菜的Id rop.SubTime = System.DateTime.Now; rop.UnitCount = tCount; R_Order_ProductBll ropBll = new R_Order_ProductBll(); md.MsgDivShow(ropBll.AddR_Order_Product(rop) ? "操作成功" : "操作失败", 1); //刷新 //显示点的菜 //=============坑 LoadR_Order_ProductByOrdrtId(Convert.ToInt32(labOrderId.Text)); }