/// <summary> /// 添加一条记录 /// </summary> public int Add(ProductType entity, IDbTransaction tran) { string sql = @"insert into [ProductType] ([name], [order], [inPrice], [keywords], [description], [type], [typeInt]) values (@name, @order, @inPrice, @keywords, @description, @type, @typeInt)"; object param = new { name = entity.Name, order = entity.Order, inPrice = entity.InPrice, keywords = entity.Keywords, description = entity.Description, type = entity.Type, typeInt = entity.TypeInt }; int count = tran.Connection.Execute(sql, param, tran); return count; }
/// <summary> /// 添加一条记录 /// </summary> public ResultSet Add(ProductType entity) { Func<ProductType, ResultStatus> validate = (_entity) => { return new ResultStatus(); }; Func<ProductType, ResultStatus> op = (_entity) => { int ret = new ProductTypeDal().Add(entity); if (ret > 0) return new ResultStatus(); else return new ResultStatus() { Success = false, Code = StatusCollection.AddFailed.Code, Description = StatusCollection.AddFailed.Description }; }; return HandleBusiness(entity, op, validate); }
/// <summary> /// 添加一条记录 /// </summary> public int Add(ProductType entity) { string sql = @"insert into [ProductType] ([name], [order], [inPrice], [keywords], [description], [type], [typeInt]) values (@name, @order, @inPrice, @keywords, @description, @type, @typeInt)"; object param = new { name = entity.Name, order = entity.Order, inPrice = entity.InPrice, keywords = entity.Keywords, description = entity.Description, type = entity.Type, typeInt = entity.TypeInt }; using (IDbConnection conn = OpenConnection()) { int count = conn.Execute(sql, param); return count; } }
// <summary> // 修改一条数据,参数为实体Entity, 需要先取得实体,更改实体属性后再操作 // </summary> public bool Update2(ProductType entity) { return new ProductTypeDal().Update2(entity); }
/// <summary> /// 修改一条数据,参数为实体Entity, 需要先取得实体,更改实体属性后再操作. /// </summary> public bool Update2(ProductType entity) { StringBuilder sb = new StringBuilder(); sb.Append("update [ProductType] set "); sb.Append("[Name] = @Name, "); sb.Append("[Order] = @Order, "); sb.Append("[InPrice] = @InPrice, "); sb.Append("[Keywords] = @Keywords, "); sb.Append("[Description] = @Description, "); sb.Append("[Type] = @Type, "); sb.Append("[TypeInt] = @TypeInt "); sb.Append(" where [Id]= @Id "); int rows = 0; using (IDbConnection conn = OpenConnection()) { string sql = sb.ToString(); rows = conn.Execute(sql, entity); } if (rows > 0) { return true; } else { return false; } }