//load desk
 private void LoadDeskInfoByDelFlag(int p)
 {
     DeskInfoBLL bll = new DeskInfoBLL();
     dgvDeskInfo.AutoGenerateColumns = false;
     dgvDeskInfo.DataSource = bll.GetAllDeskInfoByDelFlag(p);
     dgvDeskInfo.SelectedRows[0].Selected = false;
     
     
 }
        private void btnOK_Click(object sender, EventArgs e)
        {
            //change desk state
            DeskInfoBLL dkBll = new DeskInfoBLL();
            bool dkFlag = dkBll.UpdateDeskStateByDeskId(this.ID, 1);
            //add an order
            OrderInfoBLL orBll = new OrderInfoBLL();
            OrderInfo or = new OrderInfo();
            or.SubTime = System.DateTime.Now;
            or.OrderMoney = 0;
            or.DelFlag = 0;
            or.OrderState = 1;
            or.Remark = txtPersonCount.Text + txtDescription.Text;
            or.SubBy = 1;
            int orderId = orBll.AddOrderInfo(or);

            //add R_Order_Desk
            R_Order_DeskBLL rodBll = new R_Order_DeskBLL();
            R_Order_Desk rod = new R_Order_Desk();
            rod.DeskId = this.ID;
            rod.OrderId = orderId;
            bool rodFlag = rodBll.AddROrderDesk(rod);

            if(dkFlag && rodFlag)
            {
                MessageBox.Show("开单成功");
                if(ckbMeal.Checked)
                {
                    MyEventArgs mea = new MyEventArgs();
                    //deskName
                    mea.Name = labDeskName.Text;
                    //Order Id
                    mea.Temp = orderId;
                    FrmAddMoney fam = new FrmAddMoney();
                    this.evtFrmMoney += new EventHandler(fam.SetText);
                    if(this.evtFrmMoney != null)
                    {
                        this.evtFrmMoney(this, mea);
                        fam.FormClosed += new FormClosedEventHandler(fam_FormClosed);
                        fam.ShowDialog();
                    }
                }
            }
            else
            {
                MessageBox.Show("开单失败");
            }
        }
        // load desk
        private void LoadDeskInfoByRoomIdAndByTabPageIndex(TabPage tp)
        {
            if(tp!=null)
            {
                // RoomInfo object
                RoomInfo r = tp.Tag as RoomInfo;
                // ListView object
                ListView lv = tp.Controls[0] as ListView;
                lv.Clear();

                DeskInfoBLL bll = new DeskInfoBLL();
                //get deskinfo based on roomId
                List<DeskInfo> listDesk = bll.GetAllDeskInfoByRoomId(r.RoomId);
                for (int i = 0; i < listDesk.Count; i++)
                {
                    lv.Items.Add(listDesk[i].DeskName, listDesk[i].DeskState);
                    lv.Items[i].Tag = listDesk[i];
                }
            }
           
        }
 /// <summary>
 /// delete room
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void btnDeleteRoom_Click(object sender, EventArgs e)
 {
     //RoomInfoBLL bll = new RoomInfoBLL();
     if(dgvRoomInfo.SelectedRows.Count > 0)
     {
         int id = Convert.ToInt32(dgvRoomInfo.SelectedRows[0].Cells[0].Value.ToString());
         DeskInfoBLL dbll = new DeskInfoBLL();
         if(dbll.GetDeskCountByRoomId(id))
         {
             MessageBox.Show("房间有桌子不能删除");
         }
         else
         {
             RoomInfoBLL rbll = new RoomInfoBLL();
             if(rbll.SoftDeleteRoomInfoByRoomId(id))
             {
                 MessageBox.Show("操作成功");
                 LoadRoomByDelFlag(0);
             }
             else
             {
                 MessageBox.Show("操作失败");
             }
         }
     }
     else
     {
         MessageBox.Show("请选择要删除的房间");
     }
 }
 //Pay the bill
 private void btnAccounts_Click(object sender, EventArgs e)
 {
     MemberInfo mem = cmbMemmber.SelectedItem as MemberInfo;
     if(string.IsNullOrEmpty(txtMoney.Text))
     {
         MessageBox.Show("请输入钱");
         return;
     }
     if(Convert.ToDecimal(txtMoney.Text) < Convert.ToDecimal(lblMoney.Text))
     {
         MessageBox.Show("就这点钱? 搞笑呢");
         return;
     }
     OrderInfo order = new OrderInfo();
     //deskState in DeskInfo table
     DeskInfoBLL bll = new DeskInfoBLL();
     bool deskFlag = bll.UpdateDeskStateByDeskId(this.deskId, 0);
     //non-member
     if(cmbMemmber.SelectedIndex != 0)
     {
         order.OrderMemId = mem.MemmberId;
         order.DisCount = Convert.ToDecimal(mem.MemDiscount);
         //after pay in member money
         decimal money = mem.MemMoney - Convert.ToDecimal(lblMoney.Text);
         MemberInfoBLL mbll = new MemberInfoBLL();
         //if(money < 0)
         //{
         
         //}
         //Member money in MemmberInfo table
         bool memFlag = mbll.UpdateMoneyByMemId(mem.MemmberId, money);
     }
     order.EndTime = System.DateTime.Now;
     order.OrderId = Convert.ToInt32(labOrderId.Text);
     order.OrderMoney = Convert.ToDecimal(lblMoney.Text);
     OrderInfoBLL obll = new OrderInfoBLL();
     bool orderFlag = obll.UpdateOrderInfoMoney(order);
     lblSpareMoney.Text = (Convert.ToDecimal(txtMoney.Text) - Convert.ToDecimal(lblMoney.Text)).ToString();
     if(deskFlag && orderFlag)
     {
         MessageBox.Show("结账成功");
     }
     else
     {
         MessageBox.Show("失败");
     }
 }