public List <CategoryBrandInfo> GetList() { string cmdText = @"select BrandId,CategoryId from CategoryBrand order by LastUpdatedDate desc " ; List <CategoryBrandInfo> list = new List <CategoryBrandInfo>(); using (SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.HnztcShopDbConnString, CommandType.Text, cmdText)) { if (reader != null && reader.HasRows) { while (reader.Read()) { CategoryBrandInfo model = new CategoryBrandInfo(); model.BrandId = reader.GetGuid(0); model.CategoryId = reader.GetGuid(1); list.Add(model); } } } return(list); }
public List <CategoryBrandInfo> GetList(string sqlWhere, params SqlParameter[] cmdParms) { string cmdText = @"select BrandId,CategoryId from CategoryBrand"; if (!string.IsNullOrEmpty(sqlWhere)) { cmdText += " where 1=1 " + sqlWhere; } List <CategoryBrandInfo> list = new List <CategoryBrandInfo>(); using (SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.HnztcShopDbConnString, CommandType.Text, cmdText, cmdParms)) { if (reader != null && reader.HasRows) { while (reader.Read()) { CategoryBrandInfo model = new CategoryBrandInfo(); model.BrandId = reader.GetGuid(0); model.CategoryId = reader.GetGuid(1); list.Add(model); } } } return(list); }
public List <CategoryBrandInfo> GetList(int pageIndex, int pageSize, string sqlWhere, params SqlParameter[] cmdParms) { int startIndex = (pageIndex - 1) * pageSize + 1; int endIndex = pageIndex * pageSize; string cmdText = @"select * from(select row_number() over(order by LastUpdatedDate desc) as RowNumber, BrandId,CategoryId from CategoryBrand" ; if (!string.IsNullOrEmpty(sqlWhere)) { cmdText += " where 1=1 " + sqlWhere; } cmdText += ")as objTable where RowNumber between " + startIndex + " and " + endIndex + " "; List <CategoryBrandInfo> list = new List <CategoryBrandInfo>(); using (SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.HnztcShopDbConnString, CommandType.Text, cmdText, cmdParms)) { if (reader != null && reader.HasRows) { while (reader.Read()) { CategoryBrandInfo model = new CategoryBrandInfo(); model.BrandId = reader.GetGuid(1); model.CategoryId = reader.GetGuid(2); list.Add(model); } } } return(list); }
public CategoryBrandInfo GetModel(object BrandId) { CategoryBrandInfo model = null; string cmdText = @"select top 1 BrandId,CategoryId from CategoryBrand where BrandId = @BrandId " ; SqlParameter parm = new SqlParameter("@BrandId", SqlDbType.UniqueIdentifier); parm.Value = Guid.Parse(BrandId.ToString()); using (SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.HnztcShopDbConnString, CommandType.Text, cmdText, parm)) { if (reader != null) { while (reader.Read()) { model = new CategoryBrandInfo(); model.BrandId = reader.GetGuid(0); model.CategoryId = reader.GetGuid(1); } } } return(model); }
public int Update(CategoryBrandInfo model) { string cmdText = @"update CategoryBrand set CategoryId = @CategoryId where BrandId = @BrandId" ; SqlParameter[] parms = { new SqlParameter("@BrandId", SqlDbType.UniqueIdentifier), new SqlParameter("@CategoryId", SqlDbType.UniqueIdentifier) }; parms[0].Value = model.BrandId; parms[1].Value = model.CategoryId; return(SqlHelper.ExecuteNonQuery(SqlHelper.HnztcShopDbConnString, CommandType.Text, cmdText, parms)); }
public int Insert(CategoryBrandInfo model) { string cmdText = @"insert into CategoryBrand (CategoryId,BrandId) values (@CategoryId,@BrandId) " ; SqlParameter[] parms = { new SqlParameter("@CategoryId", SqlDbType.UniqueIdentifier), new SqlParameter("@BrandId", SqlDbType.UniqueIdentifier) }; parms[0].Value = model.CategoryId; parms[1].Value = model.BrandId; return(SqlHelper.ExecuteNonQuery(SqlHelper.HnztcShopDbConnString, CommandType.Text, cmdText, parms)); }
public string SaveBrand(BrandInfo model) { if (string.IsNullOrWhiteSpace(model.BrandName)) { return(MessageContent.Submit_Params_InvalidError); } if (string.IsNullOrWhiteSpace(model.BrandCode)) { return(MessageContent.Submit_Params_InvalidError); } Guid categoryId = Guid.Empty; Guid.TryParse(model.CategoryId.ToString(), out categoryId); Guid gId = Guid.Empty; Guid.TryParse(model.Id.ToString(), out gId); model.Id = gId; Guid parentId = Guid.Empty; Guid.TryParse(model.ParentId.ToString(), out parentId); model.ParentId = parentId; model.LastUpdatedDate = DateTime.Now; CategoryBrand cbBll = new CategoryBrand(); Brand bll = new Brand(); int effect = -1; if (!gId.Equals(Guid.Empty)) { effect = bll.Update(model); CategoryBrandInfo cbModel = cbBll.GetModel(gId); if (!categoryId.Equals(Guid.Empty)) { if (cbModel == null) { cbModel = new CategoryBrandInfo(); cbModel.BrandId = gId; cbModel.CategoryId = categoryId; cbBll.Insert(cbModel); } else { if (!cbModel.CategoryId.Equals(categoryId)) { cbModel.CategoryId = categoryId; cbBll.Update(cbModel); } } } else { if (cbModel != null) { cbBll.Delete(gId, cbModel.CategoryId); } } } else { if (!categoryId.Equals(Guid.Empty)) { Guid brandId = bll.InsertAndGetId(model); CategoryBrandInfo cbModel = new CategoryBrandInfo(); cbModel.BrandId = brandId; cbModel.CategoryId = categoryId; cbBll.Insert(cbModel); effect = 1; } else { effect = bll.Insert(model); } } if (effect == 110) { return(MessageContent.Submit_Exist); } if (effect > 0) { return("1"); } else { return(MessageContent.Submit_Error); } }
/// <summary> /// 修改数据 /// </summary> /// <param name="model"></param> /// <returns></returns> public int Update(CategoryBrandInfo model) { return(dal.Update(model)); }
/// <summary> /// 添加数据到数据库 /// </summary> /// <param name="model"></param> /// <returns></returns> public int Insert(CategoryBrandInfo model) { return(dal.Insert(model)); }