/// <summary> /// 获取数据库一条记录实体(根据主键条件) /// </summary> /// <param name="id">主键字段id</param> /// <returns>Entity.ShopListEntity实体类</returns> public static Entity.ShopListEntity GetById(int id) { Entity.ShopListEntity entity = null; List <SqlParameter> commandParms = new List <SqlParameter>(); commandParms.Add(SqlHelper.CreateParam("@Id", SqlDbType.Int, 0, ParameterDirection.Input, id)); using (SqlDataReader reader = SqlHelper.ExecuteReader(ConnectionString, CommandType.Text, C_SP_SHOPLIST_GET, commandParms)) { if (reader.Read()) { entity = ConvertToEntityFromDataReader(reader); } } return(entity); }
/// <summary> /// 更新数据库中一条记录(根据主键条件) /// </summary> /// <param name="entity">Entity.ShopListEntity实体类</param> public static void Update(Entity.ShopListEntity entity) { List <SqlParameter> commandParms = new List <SqlParameter>(); commandParms.Add(SqlHelper.CreateParam("@Id", SqlDbType.Int, 0, ParameterDirection.Input, entity.Id)); commandParms.Add(SqlHelper.CreateParam("@StationId", SqlDbType.Int, 0, ParameterDirection.Input, entity.StationId)); commandParms.Add(SqlHelper.CreateParam("@ShopType", SqlDbType.Int, 0, ParameterDirection.Input, entity.ShopType)); commandParms.Add(SqlHelper.CreateParam("@ShopImageUrl", SqlDbType.VarChar, 200, ParameterDirection.Input, entity.ShopImageUrl)); commandParms.Add(SqlHelper.CreateParam("@ShopName", SqlDbType.NVarChar, 50, ParameterDirection.Input, entity.ShopName)); commandParms.Add(SqlHelper.CreateParam("@Title", SqlDbType.NVarChar, 50, ParameterDirection.Input, entity.Title)); commandParms.Add(SqlHelper.CreateParam("@Summury", SqlDbType.NVarChar, 100, ParameterDirection.Input, entity.Summury)); commandParms.Add(SqlHelper.CreateParam("@ShopNo", SqlDbType.VarChar, 10, ParameterDirection.Input, entity.ShopNo)); commandParms.Add(SqlHelper.CreateParam("@Address", SqlDbType.NVarChar, 100, ParameterDirection.Input, entity.Address)); commandParms.Add(SqlHelper.CreateParam("@AddTime", SqlDbType.DateTime, 0, ParameterDirection.Input, entity.AddTime)); commandParms.Add(SqlHelper.CreateParam("@Operateuser", SqlDbType.NVarChar, 10, ParameterDirection.Input, entity.Operateuser)); SqlHelper.ExecuteNonQuery(ConnectionString, CommandType.Text, C_SP_SHOPLIST_UPDATE, commandParms); }
/// <summary> /// 转换SqlDataReader类型数据记录为实体 /// </summary> private static Entity.ShopListEntity ConvertToEntityFromDataReader(SqlDataReader reader) { Entity.ShopListEntity entity = new Entity.ShopListEntity(); entity.Id = Convert.ToInt32(reader["Id"]); entity.StationId = Convert.ToInt32(reader["StationId"]); entity.ShopType = Convert.ToInt32(reader["ShopType"]); if (Convert.IsDBNull(reader["ShopImageUrl"])) { entity.ShopImageUrl = null; } else { entity.ShopImageUrl = reader["ShopImageUrl"].ToString(); } entity.ShopName = reader["ShopName"].ToString(); entity.Title = reader["Title"].ToString(); if (Convert.IsDBNull(reader["Summury"])) { entity.Summury = null; } else { entity.Summury = reader["Summury"].ToString(); } entity.ShopNo = reader["ShopNo"].ToString(); if (Convert.IsDBNull(reader["Address"])) { entity.Address = null; } else { entity.Address = reader["Address"].ToString(); } entity.AddTime = Convert.ToDateTime(reader["AddTime"]); entity.Operateuser = reader["Operateuser"].ToString(); return(entity); }