/// <summary> /// 增加一条数据 /// </summary> public void Add(BookShop.Model.Room model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into Room("); strSql.Append("RoomNum,RoomType,RoomState,BedNum,GustNum,Description)"); strSql.Append(" values ("); strSql.Append("@RoomNum,@RoomType,@RoomState,@BedNum,@GustNum,@Description)"); SqlParameter[] parameters = { new SqlParameter("@RoomNum", SqlDbType.Int, 4), new SqlParameter("@RoomType", SqlDbType.Int, 4), new SqlParameter("@RoomState", SqlDbType.VarChar, 50), new SqlParameter("@BedNum", SqlDbType.Int, 4), new SqlParameter("@GustNum", SqlDbType.Int, 4), new SqlParameter("@Description", SqlDbType.VarChar, 100) }; parameters[0].Value = model.RoomNum; parameters[1].Value = model.RoomType; parameters[2].Value = model.RoomState; parameters[3].Value = model.BedNum; parameters[4].Value = model.GustNum; parameters[5].Value = model.Description; DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); }
/// <summary> /// 更新一条数据 /// </summary> public void Update(BookShop.Model.Room model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update Room set "); strSql.Append("RoomType=@RoomType,"); strSql.Append("RoomState=@RoomState,"); strSql.Append("BedNum=@BedNum,"); strSql.Append("GustNum=@GustNum,"); strSql.Append("Description=@Description"); strSql.Append(" where RoomNum=@RoomNum "); SqlParameter[] parameters = { new SqlParameter("@RoomNum", SqlDbType.Int, 4), new SqlParameter("@RoomType", SqlDbType.Int, 4), new SqlParameter("@RoomState", SqlDbType.VarChar, 50), new SqlParameter("@BedNum", SqlDbType.Int, 4), new SqlParameter("@GustNum", SqlDbType.Int, 4), new SqlParameter("@Description", SqlDbType.VarChar, 100) }; parameters[0].Value = model.RoomNum; parameters[1].Value = model.RoomType; parameters[2].Value = model.RoomState; parameters[3].Value = model.BedNum; parameters[4].Value = model.GustNum; parameters[5].Value = model.Description; DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); }
private void ShowInfo(int RoomNum) { BookShop.BLL.RoomService bll = new BookShop.BLL.RoomService(); BookShop.Model.Room model = bll.GetModel(RoomNum); this.lblRoomType.Text = model.RoomType.ToString(); this.lblRoomState.Text = model.RoomState; this.lblBedNum.Text = model.BedNum.ToString(); this.lblGustNum.Text = model.GustNum.ToString(); this.lblDescription.Text = model.Description; }
protected void btnAdd_Click(object sender, EventArgs e) { string strErr = ""; if (!PageValidate.IsNumber(txtRoomNum.Text)) { strErr += "RoomNum不是数字!\\n"; } if (!PageValidate.IsNumber(txtRoomType.Text)) { strErr += "RoomType不是数字!\\n"; } if (this.txtRoomState.Text == "") { strErr += "RoomState不能为空!\\n"; } if (!PageValidate.IsNumber(txtBedNum.Text)) { strErr += "BedNum不是数字!\\n"; } if (!PageValidate.IsNumber(txtGustNum.Text)) { strErr += "GustNum不是数字!\\n"; } if (this.txtDescription.Text == "") { strErr += "Description不能为空!\\n"; } if (strErr != "") { MessageBox.Show(this, strErr); return; } int RoomNum = int.Parse(this.txtRoomNum.Text); int RoomType = int.Parse(this.txtRoomType.Text); string RoomState = this.txtRoomState.Text; int BedNum = int.Parse(this.txtBedNum.Text); int GustNum = int.Parse(this.txtGustNum.Text); string Description = this.txtDescription.Text; BookShop.Model.Room model = new BookShop.Model.Room(); model.RoomNum = RoomNum; model.RoomType = RoomType; model.RoomState = RoomState; model.BedNum = BedNum; model.GustNum = GustNum; model.Description = Description; BookShop.BLL.RoomService bll = new BookShop.BLL.RoomService(); bll.Add(model); }
/// <summary> /// 得到一个对象实体 /// </summary> public BookShop.Model.Room GetModel(int RoomNum) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 RoomNum,RoomType,RoomState,BedNum,GustNum,Description from Room "); strSql.Append(" where RoomNum=@RoomNum "); SqlParameter[] parameters = { new SqlParameter("@RoomNum", SqlDbType.Int, 4) }; parameters[0].Value = RoomNum; BookShop.Model.Room model = new BookShop.Model.Room(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["RoomNum"].ToString() != "") { model.RoomNum = int.Parse(ds.Tables[0].Rows[0]["RoomNum"].ToString()); } if (ds.Tables[0].Rows[0]["RoomType"].ToString() != "") { model.RoomType = int.Parse(ds.Tables[0].Rows[0]["RoomType"].ToString()); } model.RoomState = ds.Tables[0].Rows[0]["RoomState"].ToString(); if (ds.Tables[0].Rows[0]["BedNum"].ToString() != "") { model.BedNum = int.Parse(ds.Tables[0].Rows[0]["BedNum"].ToString()); } if (ds.Tables[0].Rows[0]["GustNum"].ToString() != "") { model.GustNum = int.Parse(ds.Tables[0].Rows[0]["GustNum"].ToString()); } model.Description = ds.Tables[0].Rows[0]["Description"].ToString(); return(model); } else { return(null); } }