/// <summary> /// 更新一条数据 /// </summary> public bool Update(HeqiaoDaoshiCore.Model.HotelRoom model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update HotelRoom set "); strSql.Append("HotelRoomName=@HotelRoomName,"); strSql.Append("Price=@Price,"); strSql.Append("Introduction=@Introduction,"); strSql.Append("Address=@Address,"); strSql.Append("Picture=@Picture,"); strSql.Append("State=@State,"); strSql.Append("IsDelete=@IsDelete,"); strSql.Append("HotelUuid=@HotelUuid"); strSql.Append(" where ID=@ID"); SqlParameter[] parameters = { new SqlParameter("@HotelRoomName", SqlDbType.NVarChar, -1), new SqlParameter("@Price", SqlDbType.NVarChar, -1), new SqlParameter("@Introduction", SqlDbType.NVarChar, -1), new SqlParameter("@Address", SqlDbType.NVarChar, -1), new SqlParameter("@Picture", SqlDbType.NVarChar, -1), new SqlParameter("@State", SqlDbType.Int, 4), new SqlParameter("@IsDelete", SqlDbType.Int, 4), new SqlParameter("@HotelUuid", SqlDbType.UniqueIdentifier, 16), new SqlParameter("@ID", SqlDbType.Int, 4), new SqlParameter("@HotelRoomUuid", SqlDbType.UniqueIdentifier, 16) }; parameters[0].Value = model.HotelRoomName; parameters[1].Value = model.Price; parameters[2].Value = model.Introduction; parameters[3].Value = model.Address; parameters[4].Value = model.Picture; parameters[5].Value = model.State; parameters[6].Value = model.IsDelete; parameters[7].Value = model.HotelUuid; parameters[8].Value = model.ID; parameters[9].Value = model.HotelRoomUuid; int rows = DbHelperSql.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public HeqiaoDaoshiCore.Model.HotelRoom DataRowToModel(DataRow row) { HeqiaoDaoshiCore.Model.HotelRoom model = new HeqiaoDaoshiCore.Model.HotelRoom(); if (row != null) { if (row["ID"] != null && row["ID"].ToString() != "") { model.ID = int.Parse(row["ID"].ToString()); } if (row["HotelRoomUuid"] != null && row["HotelRoomUuid"].ToString() != "") { model.HotelRoomUuid = new Guid(row["HotelRoomUuid"].ToString()); } if (row["HotelRoomName"] != null) { model.HotelRoomName = row["HotelRoomName"].ToString(); } if (row["Price"] != null) { model.Price = row["Price"].ToString(); } if (row["Introduction"] != null) { model.Introduction = row["Introduction"].ToString(); } if (row["Address"] != null) { model.Address = row["Address"].ToString(); } if (row["Picture"] != null) { model.Picture = row["Picture"].ToString(); } if (row["State"] != null && row["State"].ToString() != "") { model.State = int.Parse(row["State"].ToString()); } if (row["IsDelete"] != null && row["IsDelete"].ToString() != "") { model.IsDelete = int.Parse(row["IsDelete"].ToString()); } if (row["HotelUuid"] != null && row["HotelUuid"].ToString() != "") { model.HotelUuid = new Guid(row["HotelUuid"].ToString()); } } return(model); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(HeqiaoDaoshiCore.Model.HotelRoom model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into HotelRoom("); strSql.Append("HotelRoomUuid,HotelRoomName,Price,Introduction,Address,Picture,State,IsDelete,HotelUuid)"); strSql.Append(" values ("); strSql.Append("@HotelRoomUuid,@HotelRoomName,@Price,@Introduction,@Address,@Picture,@State,@IsDelete,@HotelUuid)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@HotelRoomUuid", SqlDbType.UniqueIdentifier, 16), new SqlParameter("@HotelRoomName", SqlDbType.NVarChar, -1), new SqlParameter("@Price", SqlDbType.NVarChar, -1), new SqlParameter("@Introduction", SqlDbType.NVarChar, -1), new SqlParameter("@Address", SqlDbType.NVarChar, -1), new SqlParameter("@Picture", SqlDbType.NVarChar, -1), new SqlParameter("@State", SqlDbType.Int, 4), new SqlParameter("@IsDelete", SqlDbType.Int, 4), new SqlParameter("@HotelUuid", SqlDbType.UniqueIdentifier, 16) }; parameters[0].Value = Guid.NewGuid(); parameters[1].Value = model.HotelRoomName; parameters[2].Value = model.Price; parameters[3].Value = model.Introduction; parameters[4].Value = model.Address; parameters[5].Value = model.Picture; parameters[6].Value = model.State; parameters[7].Value = model.IsDelete; parameters[8].Value = Guid.NewGuid(); object obj = DbHelperSql.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 得到一个对象实体 /// </summary> public HeqiaoDaoshiCore.Model.HotelRoom GetModel(int ID) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 ID,HotelRoomUuid,HotelRoomName,Price,Introduction,Address,Picture,State,IsDelete,HotelUuid from HotelRoom "); strSql.Append(" where ID=@ID"); SqlParameter[] parameters = { new SqlParameter("@ID", SqlDbType.Int, 4) }; parameters[0].Value = ID; HeqiaoDaoshiCore.Model.HotelRoom model = new HeqiaoDaoshiCore.Model.HotelRoom(); DataSet ds = DbHelperSql.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }