/// <summary> /// 判断当前节点是否已存在相同的 /// </summary> /// <param name="entity"></param> /// <returns></returns> public int ExistNum(ProductPropertyEntity entity) { ///id=0,判断总数,ID>0判断除自己之外的总数 string sql = @"Select count(1) from dbo.[ProductProperty] WITH(NOLOCK) "; string where = "where "; if (entity.Id == 0) { where = where + " (PropertyName=@PropertyName) "; } else { where = where + " id<>@Id and (PropertyName=@PropertyName) "; } sql = sql + where; DbCommand cmd = db.GetSqlStringCommand(sql); if (entity.Id > 0) { db.AddInParameter(cmd, "@Id", DbType.Int32, entity.Id); } db.AddInParameter(cmd, "@PropertyName", DbType.String, entity.PropertyName); object identity = db.ExecuteScalar(cmd); if (identity == null || identity == DBNull.Value) { return(0); } return(Convert.ToInt32(identity)); }
/// <summary> /// 根据主键值读取记录。如果数据库不存在这条数据将返回null /// </summary> /// <param name="db">数据库操作对象</param> /// <param name="columns">需要返回的列,不提供任何列名时默认将返回所有列</param> public ProductPropertyEntity GetProductProperty(int id) { string sql = @"SELECT [Id],[PropertyId],[PropertyName],[PropertyDetailId],[ProductId],[Sort],[IsSpec] FROM dbo.[ProductProperty] WITH(NOLOCK) WHERE [Id]=@id" ; DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@Id", DbType.Int32, id); ProductPropertyEntity entity = new ProductPropertyEntity(); using (IDataReader reader = db.ExecuteReader(cmd)) { if (reader.Read()) { entity.Id = StringUtils.GetDbInt(reader["Id"]); entity.PropertyId = StringUtils.GetDbInt(reader["PropertyId"]); entity.PropertyName = StringUtils.GetDbString(reader["PropertyName"]); entity.PropertyDetailId = StringUtils.GetDbInt(reader["PropertyDetailId"]); entity.ProductId = StringUtils.GetDbInt(reader["ProductId"]); entity.Sort = StringUtils.GetDbInt(reader["Sort"]); entity.IsSpec = StringUtils.GetDbInt(reader["IsSpec"]); } } return(entity); }
public IList <ProductPropertyEntity> GetPropertyByProductId(int productid) { string sql = @"SELECT [Id],[PropertyId],[PropertyName],[PropertyDetailId],[ProductId],[Sort],[IsSpec] from dbo.[ProductProperty] WITH(NOLOCK) where ProductId=@ProductId "; IList <ProductPropertyEntity> entityList = new List <ProductPropertyEntity>(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@ProductId", DbType.Int32, productid); using (IDataReader reader = db.ExecuteReader(cmd)) { while (reader.Read()) { ProductPropertyEntity entity = new ProductPropertyEntity(); entity.Id = StringUtils.GetDbInt(reader["Id"]); entity.PropertyId = StringUtils.GetDbInt(reader["PropertyId"]); entity.PropertyName = StringUtils.GetDbString(reader["PropertyName"]); entity.PropertyDetailId = StringUtils.GetDbInt(reader["PropertyDetailId"]); entity.ProductId = StringUtils.GetDbInt(reader["ProductId"]); entity.Sort = StringUtils.GetDbInt(reader["Sort"]); entity.IsSpec = StringUtils.GetDbInt(reader["IsSpec"]); entityList.Add(entity); } } return(entityList); }
public static ProductProperty PropertyEntityToProperty(this ProductPropertyEntity prop) { return(new ProductProperty { Alias = prop.Alias, LanguageCode = prop.LanguageCode, ProductId = prop.ProductId, DisplayName = prop.PropertyDisplayName, PropertyId = prop.PropertyId, PropertyName = prop.PropertyName, Value = prop.Value, ValueType = prop.ValueType }); }
/// <summary> /// 根据主键值更新记录的全部字段(注意:该方法不会对自增字段、timestamp类型字段以及主键字段更新!如果要更新主键字段,请使用Update方法)。 /// 如果数据库有数据被更新了则返回True,否则返回False /// </summary> /// <param name="db">数据库操作对象</param> /// <param name="productProperty">待更新的实体对象</param> public int UpdateProductProperty(ProductPropertyEntity entity) { string sql = @" UPDATE dbo.[ProductProperty] SET [PropertyId]=@PropertyId,[PropertyName]=@PropertyName,[PropertyDetailId]=@PropertyDetailId,[ProductId]=@ProductId,[Sort]=@Sort,[IsSpec]=@IsSpec WHERE [Id]=@id"; DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@Id", DbType.Int32, entity.Id); db.AddInParameter(cmd, "@PropertyId", DbType.Int32, entity.PropertyId); db.AddInParameter(cmd, "@PropertyName", DbType.String, entity.PropertyName); db.AddInParameter(cmd, "@PropertyDetailId", DbType.Int32, entity.PropertyDetailId); db.AddInParameter(cmd, "@ProductId", DbType.Int32, entity.ProductId); db.AddInParameter(cmd, "@Sort", DbType.Int32, entity.Sort); db.AddInParameter(cmd, "@IsSpec", DbType.Int32, entity.IsSpec); return(db.ExecuteNonQuery(cmd)); }
/// <summary> /// 读取记录列表。 /// </summary> /// <param name="db">数据库操作对象</param> /// <param name="columns">需要返回的列,不提供任何列名时默认将返回所有列</param> public IList <ProductPropertyEntity> GetProductPropertyList(int pagesize, int pageindex, ref int recordCount) { string sql = @"SELECT [Id],[PropertyId],[PropertyName],[PropertyDetailId],[ProductId],[Sort],[IsSpec] FROM (SELECT ROW_NUMBER() OVER (ORDER BY Id desc) AS ROWNUMBER, [Id],[PropertyId],[PropertyName],[PropertyDetailId],[ProductId],[Sort],[IsSpec] from dbo.[ProductProperty] WITH(NOLOCK) WHERE 1=1 ) as temp where rownumber BETWEEN ((@PageIndex - 1) * @PageSize + 1) AND @PageIndex * @PageSize" ; string sql2 = @"Select count(1) from dbo.[ProductProperty] with (nolock) "; IList <ProductPropertyEntity> entityList = new List <ProductPropertyEntity>(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@PageIndex", DbType.Int32, pageindex); db.AddInParameter(cmd, "@PageSize", DbType.Int32, pagesize); using (IDataReader reader = db.ExecuteReader(cmd)) { while (reader.Read()) { ProductPropertyEntity entity = new ProductPropertyEntity(); entity.Id = StringUtils.GetDbInt(reader["Id"]); entity.PropertyId = StringUtils.GetDbInt(reader["PropertyId"]); entity.PropertyName = StringUtils.GetDbString(reader["PropertyName"]); entity.PropertyDetailId = StringUtils.GetDbInt(reader["PropertyDetailId"]); entity.ProductId = StringUtils.GetDbInt(reader["ProductId"]); entity.Sort = StringUtils.GetDbInt(reader["Sort"]); entity.IsSpec = StringUtils.GetDbInt(reader["IsSpec"]); entityList.Add(entity); } } cmd = db.GetSqlStringCommand(sql2); using (IDataReader reader = db.ExecuteReader(cmd)) { if (reader.Read()) { recordCount = StringUtils.GetDbInt(reader[0]); } else { recordCount = 0; } } return(entityList); }
/// <summary> /// 插入一条记录到表ProductProperty,如果表中存在自增字段,则返回值为新记录的自增字段值,否则返回0。 /// 该方法提供给界面等UI层调用 /// </summary> /// <param name="productProperty">要添加的ProductProperty数据实体对象</param> public int AddProductProperty(ProductPropertyEntity productProperty) { if (productProperty.Id > 0) { return(UpdateProductProperty(productProperty)); } else if (string.IsNullOrEmpty(productProperty.PropertyName)) { return((int)CommonStatus.ADD_Fail_Empty); } else if (ProductPropertyBLL.Instance.IsExist(productProperty)) { return((int)CommonStatus.ADD_Fail_Exist); } else { return(ProductPropertyDA.Instance.AddProductProperty(productProperty)); } }
/// <summary> /// 插入一条记录到表ProductProperty,如果表中存在自增字段,则返回值为新记录的自增字段值,否则返回0 /// </summary> /// <param name="db">数据库操作对象</param> /// <param name="productProperty">待插入的实体对象</param> public int AddProductProperty(ProductPropertyEntity entity) { string sql = @"insert into ProductProperty( [PropertyId],[PropertyName],[PropertyDetailId],[ProductId],[Sort],[IsSpec])VALUES ( @PropertyId,@PropertyName,@PropertyDetailId,@ProductId,@Sort,@IsSpec); SELECT SCOPE_IDENTITY();" ; DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@PropertyId", DbType.Int32, entity.PropertyId); db.AddInParameter(cmd, "@PropertyName", DbType.String, entity.PropertyName); db.AddInParameter(cmd, "@PropertyDetailId", DbType.Int32, entity.PropertyDetailId); db.AddInParameter(cmd, "@ProductId", DbType.Int32, entity.ProductId); db.AddInParameter(cmd, "@Sort", DbType.Int32, entity.Sort); db.AddInParameter(cmd, "@IsSpec", DbType.Int32, entity.IsSpec); object identity = db.ExecuteScalar(cmd); if (identity == null || identity == DBNull.Value) { return(0); } return(Convert.ToInt32(identity)); }
public bool SaveProductProperty(ProductPropertyEntity propertyEntity) { return((_connection.Table <ProductPropertyEntity>().FirstOrDefault(x => x.Id == propertyEntity.Id) == null ? _connection.Insert(propertyEntity) : _connection.Update(propertyEntity)) != -1); }
/// <summary> /// 更新一条ProductProperty记录。 /// 该方法提供给界面等UI层调用 /// </summary> /// <param name="productProperty">待更新的实体对象</param> /// <param name="columns">要更新的列名,不提供任何列名时默认将更新主键之外的所有列</param> public int UpdateProductProperty(ProductPropertyEntity productProperty) { return(ProductPropertyDA.Instance.UpdateProductProperty(productProperty)); }
/// <summary> /// 判断对象是否存在 /// </summary> /// <param name="dicEnum"></param> /// <returns></returns> public bool IsExist(ProductPropertyEntity productProperty) { return(ProductPropertyDA.Instance.ExistNum(productProperty) > 0); }