/// <summary>
 /// update Order Info 
 /// </summary>
 /// <param name="order"></param>
 /// <returns></returns>
 public int UpdateOrderInfoMoney(OrderInfo order)
 {
     string sql = "update OrderInfo set OrderState=2, OrderMemId=@OrderMemId,EndTime=@EndTime,OrderMoney=@OrderMoney,DisCount=@Discount where OrderId=@OrderId";
     SQLiteParameter[] ps ={
                              new SQLiteParameter("@OrderMemId",order.OrderMemId),
                              new SQLiteParameter("@EndTime",order.EndTime),
                              new SQLiteParameter("@OrderMoney",order.OrderMoney),
                              new SQLiteParameter("@DisCount",order.DisCount),
                              new SQLiteParameter("@OrderId",order.OrderId)
                          };
     return SqliteHelper.ExecuteNonQuery(sql, ps);
 }
 /// <summary>
 /// 添加一个订单
 /// </summary>
 /// <param name="order"></param>
 /// <returns></returns>
 public object AddOrderInfo(OrderInfo order)
 {
     string sql = "insert into OrderInfo(SubTime,Remark,OrderState,DelFlag,SubBy,OrderMoney) values(@SubTime,@Remark,@OrderState,@DelFlag,@SubBy,@OrderMoney);select last_insert_rowId()";
     SQLiteParameter[] ps = {
                               new SQLiteParameter("@SubTime",order.SubTime),
                               new SQLiteParameter("@Remark",order.Remark),
                               new SQLiteParameter("@OrderState",order.OrderState),
                               new SQLiteParameter("@DelFlag",order.DelFlag),
                               new SQLiteParameter("@SubBy",order.SubBy),
                               new SQLiteParameter("@OrderMoney",order.OrderMoney)
                           };
     return SqliteHelper.ExecuteSclar(sql, ps);
 }
        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("开单失败");
            }
        }
 /// <summary>
 /// update Order Info 
 /// </summary>
 /// <param name="order"></param>
 /// <returns></returns>
 /// 
 public bool UpdateOrderInfoMoney(OrderInfo order)
 {
     return dal.UpdateOrderInfoMoney(order) > 0;
 }
 /// <summary>
 /// 添加一个订单
 /// </summary>
 /// <param name="order"></param>
 /// <returns></returns>
 /// 
 public int AddOrderInfo(OrderInfo order)
 {
     return Convert.ToInt32(dal.AddOrderInfo(order));
 }
 //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("失败");
     }
 }