/// <summary>
 /// add room info
 /// </summary>
 /// <param name="room"></param>
 /// <returns></returns>
 public int AddRoomInfo(RoomInfo room)
 {
     //RoomName,RoomType,RoomMinimumConsume,RoomMaxConsumer,IsDefault,SubTime,SubBy
     string sql = "insert into RoomInfo(RoomName,RoomType,RoomMinimunConsume,RoomMaxConsumer,IsDefault,DelFlag,SubTime,SubBy) values(@RoomName,@RoomType,@RoomMinimunConsume,@RoomMaxConsumer,@IsDefault,@DelFlag,@SubTime,@SubBy)";
     return AddOrUpdate(room, sql, 3);
     
 }
 private void btnOk_Click(object sender, EventArgs e)
 {
     RoomInfo r = new RoomInfo();
     
     if(txtRName.Text=="")
     {
         MessageBox.Show("请添加房间名");
         return;
     }
     if(txtRType.Text == "")
     {
         MessageBox.Show("请添加房间类型");
         return;
     }
     if(txtRMinMoney.Text=="")
     {
         MessageBox.Show("请添加房间的最低消费");
         return;
     }
     if(txtRPerNum.Text == "")
     {
         MessageBox.Show("请添加房间人数");
         return;
     }
     if (txtIsDeflaut.Text == "")
     {
         MessageBox.Show("请添加默认编号");
         return;
     }
     if (txtRName.Text != "" && txtRType.Text != "" && txtRMinMoney.Text!="" && txtRPerNum.Text!="" && txtIsDeflaut.Text!="")
     {
         r.IsDefault = Convert.ToInt32(txtIsDeflaut.Text);
         //r.RoomId = Convert.ToInt32(txtRType.Text);
         r.RoomMaxConsumer = Convert.ToInt32(txtRPerNum.Text);
         r.RoomMinimunConsume = Convert.ToDecimal(txtRMinMoney.Text);
         r.RoomName = txtRName.Text;
         r.RoomType = Convert.ToInt32(txtRType.Text);
         if(this.TP == 3)
         {
             r.SubBy = 1;
             r.SubTime = System.DateTime.Now;
             r.DelFlag = 0;
         }
         else if(this.TP == 4)
         {
             r.RoomId = Convert.ToInt32(labId.Text);
         }
         RoomInfoBLL bll = new RoomInfoBLL();
         string msg = bll.AddOrUpdate(r,this.TP) ? "操作成功" : "操作失败";
         MessageBox.Show(msg);
     }
     
     
 }
 /// <summary>
 /// RoomInfo object bind to talbe row
 /// </summary>
 /// <param name="dr"></param>
 /// <returns></returns>
 private RoomInfo RowToRoomInfo(DataRow dr)
 {
     RoomInfo r = new RoomInfo();
     r.IsDefault = Convert.ToInt32(dr["IsDefault"]);
     r.RoomId = Convert.ToInt32(dr["RoomId"]);
     r.RoomMaxConsumer = Convert.ToInt32(dr["RoomMaxConsumer"]);
     r.RoomMinimunConsume = Convert.ToDecimal(dr["RoomMinimunConsume"]);
     r.RoomName = dr["RoomName"].ToString();
     r.RoomType = Convert.ToInt32(dr["RoomType"]);
     r.SubBy = Convert.ToInt32(dr["SubBy"]);
     r.SubTime = Convert.ToDateTime(dr["subTime"]);
     return r;
 }
 /// <summary>
 /// add room info
 /// </summary>
 /// <param name="room"></param>
 /// <returns></returns>
 public bool AddOrUpdate(RoomInfo room,int temp)
 {
     int r = -1;
     if(temp == 3)
     {
         r = dal.AddRoomInfo(room);
     }
     else if(temp == 4)
     {
         r = dal.UpdateRoomInfo(room);
     }
     return r > 0;
 }
 public int AddOrUpdate(RoomInfo room, string sql, int temp)
 {
     SQLiteParameter[] ps = {
                                new SQLiteParameter("@RoomName",room.RoomName),
                                new SQLiteParameter("@RoomType",room.RoomType),
                                new SQLiteParameter("@RoomMinimunConsume",room.RoomMinimunConsume),
                                new SQLiteParameter("@RoomMaxConsumer",room.RoomMaxConsumer),
                                new SQLiteParameter("@IsDefault",room.IsDefault)
                                
                            };
     List<SQLiteParameter> list = new List<SQLiteParameter>();
     list.AddRange(ps);
     if(temp == 3)
     {
         list.Add(new SQLiteParameter("@DelFlag", room.DelFlag));
         list.Add(new SQLiteParameter("@SubTime", room.SubTime));
         list.Add(new SQLiteParameter("@SubBy", room.SubBy));
     }
     else if(temp == 4)
     {
         list.Add(new SQLiteParameter("@RoomId", room.RoomId));
     }
     return SqliteHelper.ExecuteNonQuery(sql, list.ToArray());
 }
 /// <summary>
 /// update
 /// </summary>
 /// <param name="room"></param>
 /// <returns></returns>
 public int UpdateRoomInfo(RoomInfo room)
 {
     string sql = "update RoomInfo set RoomName=@RoomName,RoomType=@RoomType,RoomMinimunConsume=@RoomMinimunConsume,RoomMaxConsumer=@RoomMaxConsumer,IsDefault=@IsDefault where RoomId=@RoomId";
     return AddOrUpdate(room, sql, 4);
 }
 /// <summary>
 /// get room information by room id
 /// </summary>
 /// <param name="id"></param>
 /// <returns></returns>
 public RoomInfo GetRoomInfoByRoomId(int id)
 {
     string sql = "select * from RoomInfo where DelFlag=0 and RoomId=" + id;
     DataTable dt = SqliteHelper.ExecuteTable(sql);
     RoomInfo room = new RoomInfo();
     if(dt.Rows.Count>0)
     {
         room = RowToRoomInfo(dt.Rows[0]);
     }
     return room;
 }