/// <summary> /// 读取记录列表。 /// </summary> /// <param name="db">数据库操作对象</param> /// <param name="columns">需要返回的列,不提供任何列名时默认将返回所有列</param> public IList <VWTreeBrandEntity> GetBrandAllByClassStr(string classidstr) { string where = " where a.IsActive=1 "; string sql = ""; if (!string.IsNullOrEmpty(classidstr) || classidstr == "0") { sql = @"SELECT distinct a.[Id], a.[Name], a.[PYFirst] ,a.[Sort],a.[IsActive] from dbo.[Brand] a WITH(NOLOCK) inner join ClassBrand b WITH(NOLOCK) on a.id=b.BrandId inner join dbo.fun_splitstr('"+ classidstr + "','_') c on b.ClassId=c.Id" + where; } else { sql = @"SELECT distinct a.[Id], a.[Name], a.[PYFirst] ,a.[Sort],a.[IsActive] from dbo.[Brand] a WITH(NOLOCK) "+ where; } IList <VWTreeBrandEntity> entityList = new List <VWTreeBrandEntity>(); DbCommand cmd = db.GetSqlStringCommand(sql); //if (classid > 0) //{ // db.AddInParameter(cmd, "@ClassId", DbType.Int32, classid); //} using (IDataReader reader = db.ExecuteReader(cmd)) { while (reader.Read()) { VWTreeBrandEntity entity = new VWTreeBrandEntity(); entity.Id = StringUtils.GetDbInt(reader["Id"]); entity.Name = StringUtils.GetDbString(reader["Name"]); entity.PYFirst = StringUtils.GetDbString(reader["PYFirst"]); entity.Sort = StringUtils.GetDbInt(reader["Sort"]); entityList.Add(entity); } } return(entityList); }
/// <summary> /// 读取记录列表。 /// </summary> /// <param name="db">数据库操作对象</param> /// <param name="columns">需要返回的列,不提供任何列名时默认将返回所有列</param> public IList <VWTreeBrandEntity> GetTreeBrandAll(int classid) { string where = " where a.IsActive=1 "; if (classid > 0) { where += " and b.ClassId=@ClassId"; } string sql = ""; if (classid > 0) { sql = @"SELECT a.[Id], a.[Name], a.[PYFirst] ,a.[Sort],a.[IsActive] from dbo.[Brand] a WITH(NOLOCK) inner join ClassBrand b WITH(NOLOCK) on a.id=b.BrandId " + where; } else { sql = @"SELECT a.[Id], a.[Name], a.[PYFirst] ,a.[Sort],a.[IsActive] from dbo.[Brand] a WITH(NOLOCK) "+ where; } IList <VWTreeBrandEntity> entityList = new List <VWTreeBrandEntity>(); DbCommand cmd = db.GetSqlStringCommand(sql); if (classid > 0) { db.AddInParameter(cmd, "@ClassId", DbType.Int32, classid); } using (IDataReader reader = db.ExecuteReader(cmd)) { while (reader.Read()) { VWTreeBrandEntity entity = new VWTreeBrandEntity(); entity.Id = StringUtils.GetDbInt(reader["Id"]); entity.Name = StringUtils.GetDbString(reader["Name"]); entity.PYFirst = StringUtils.GetDbString(reader["PYFirst"]); entity.Sort = StringUtils.GetDbInt(reader["Sort"]); entityList.Add(entity); } } return(entityList); }
/// <summary> /// 获取品牌,并按照首字母建立层级结构 /// </summary> /// <param name="classid"></param> /// <returns></returns> public IList <VWTreeBrandEntity> GetTreeBrandAll(int classid, bool iscache = false) { IList <VWTreeBrandEntity> resultlist = new List <VWTreeBrandEntity>(); string _cachekey = "GetTreeBrandAll" + classid; if (iscache) { object obj = MemCache.GetCache(_cachekey); if (obj == null) { int rediclassid = classid; ClassesFoundEntity _classentity = ClassesFoundBLL.Instance.GetClassesFound(classid, false); if (_classentity.RedirectClassId > 0) { rediclassid = _classentity.RedirectClassId; } IList <int> classintlist = new List <int>(); classintlist = ClassesFoundBLL.Instance.GetSubClassEndList(rediclassid); string classidstr = ""; if (classintlist != null && classintlist.Count > 0) { classidstr = string.Join("_", classintlist); } else { classidstr = StringUtils.GetDbString(classid); } IList <VWTreeBrandEntity> list = null; list = BrandDA.Instance.GetBrandAllByClassStr(classidstr); if (list != null && list.Count > 0) { //string[] firstletter = new Array(); ArrayList firstletter = new ArrayList(); foreach (VWTreeBrandEntity entity in list) { if (!firstletter.Contains(entity.PYFirst)) { firstletter.Add(entity.PYFirst); } firstletter.Sort(); } foreach (string letter in firstletter) { VWTreeBrandEntity entity = new VWTreeBrandEntity(); entity.PYFirst = letter; resultlist.Add(entity); } foreach (VWTreeBrandEntity entity in list) { foreach (VWTreeBrandEntity entity2 in resultlist) { if (entity.PYFirst == entity2.PYFirst) { if (entity2.Children == null) { entity2.Children = new List <VWTreeBrandEntity>(); } entity2.Children.Add(entity); break; } } } } MemCache.AddCache(_cachekey, resultlist); } else { resultlist = (IList <VWTreeBrandEntity>)obj; } } else { int rediclassid = classid; ClassesFoundEntity _classentity = ClassesFoundBLL.Instance.GetClassesFound(classid, false); if (_classentity.RedirectClassId > 0) { rediclassid = _classentity.RedirectClassId; } IList <int> classintlist = new List <int>(); classintlist = ClassesFoundBLL.Instance.GetSubClassEndList(rediclassid); string classidstr = ""; if (classintlist != null && classintlist.Count > 0) { classidstr = string.Join("_", classintlist); } else { classidstr = StringUtils.GetDbString(classid); } IList <VWTreeBrandEntity> list = null; list = BrandDA.Instance.GetBrandAllByClassStr(classidstr); if (list != null && list.Count > 0) { //string[] firstletter = new Array(); ArrayList firstletter = new ArrayList(); foreach (VWTreeBrandEntity entity in list) { if (!firstletter.Contains(entity.PYFirst)) { firstletter.Add(entity.PYFirst); } firstletter.Sort(); } foreach (string letter in firstletter) { VWTreeBrandEntity entity = new VWTreeBrandEntity(); entity.PYFirst = letter; resultlist.Add(entity); } foreach (VWTreeBrandEntity entity in list) { foreach (VWTreeBrandEntity entity2 in resultlist) { if (entity.PYFirst == entity2.PYFirst) { if (entity2.Children == null) { entity2.Children = new List <VWTreeBrandEntity>(); } entity2.Children.Add(entity); break; } } } } } return(resultlist); }