예제 #1
0
        public ActionResult AddCategory(CategoryModel model)
        {
            if (AdminCategories.GetCateIdByName(model.CategroyName) > 0)
                ModelState.AddModelError("CategroyName", "名称已经存在");

            if (model.ParentCateId != 0 && AdminCategories.GetCategoryById(model.ParentCateId) == null)
                ModelState.AddModelError("ParentCateId", "父分类不存在");

            if (ModelState.IsValid)
            {
                CategoryInfo categoryInfo = new CategoryInfo()
                {
                    DisplayOrder = model.DisplayOrder,
                    Name = model.CategroyName,
                    ParentId = model.ParentCateId,
                    PriceRange = CommonHelper.StringArrayToString(CommonHelper.RemoveArrayItem(StringHelper.SplitString(CommonHelper.TBBRTrim(model.PriceRange).Replace(",", ","))))
                };

                AdminCategories.CreateCategory(categoryInfo);
                AddMallAdminLog("添加分类", "添加分类,分类为:" + model.CategroyName);
                return PromptView("分类添加成功");
            }

            Load();
            return View(model);
        }
예제 #2
0
        /// <summary>
        /// 更新分类
        /// </summary>
        public static void UpdateCategory(CategoryInfo categoryInfo, int oldParentId)
        {
            if (categoryInfo.ParentId != oldParentId)//父分类改变时
            {
                int changeLayer = 0;
                List<CategoryInfo> categoryList = BrnMall.Data.Categories.GetCategoryList();
                CategoryInfo oldParentCategoryInfo = categoryList.Find(x => x.CateId == oldParentId);//旧的父分类
                if (categoryInfo.ParentId > 0)//非顶层分类时
                {
                    CategoryInfo newParentCategoryInfo = categoryList.Find(x => x.CateId == categoryInfo.ParentId);//新的父分类
                    if (oldParentCategoryInfo == null)
                    {
                        changeLayer = newParentCategoryInfo.Layer - 1;
                    }
                    else
                    {
                        changeLayer = newParentCategoryInfo.Layer - oldParentCategoryInfo.Layer;
                    }
                    categoryInfo.Layer = newParentCategoryInfo.Layer + 1;
                    categoryInfo.Path = newParentCategoryInfo.Path + "," + categoryInfo.CateId;

                    if (newParentCategoryInfo.HasChild == 0)
                    {
                        newParentCategoryInfo.HasChild = 1;
                        BrnMall.Data.Categories.UpdateCategory(newParentCategoryInfo);
                    }
                }
                else//顶层分类时
                {
                    changeLayer = 1 - oldParentCategoryInfo.Layer;
                    categoryInfo.Layer = 1;
                    categoryInfo.Path = categoryInfo.CateId.ToString();
                }

                if (oldParentId > 0 && categoryList.FindAll(x => x.ParentId == oldParentId).Count == 1)
                {
                    oldParentCategoryInfo.HasChild = 0;
                    BrnMall.Data.Categories.UpdateCategory(oldParentCategoryInfo);
                }

                foreach (CategoryInfo info in categoryList.FindAll(x => x.ParentId == categoryInfo.CateId))
                {
                    UpdateChildCategoryLayerAndPath(categoryList, info, changeLayer, categoryInfo.Path);
                }
            }

            BrnMall.Data.Categories.UpdateCategory(categoryInfo);

            BrnMall.Core.BMACache.Remove(CacheKeys.MALL_CATEGORY_LIST);

            WriteMallAdminCategorySelectListCache(GetCategoryList());
        }
예제 #3
0
        /// <summary>
        /// 通过IDataReader创建CategoryInfo信息
        /// </summary>
        public static CategoryInfo BuildCategoryFromReader(IDataReader reader)
        {
            CategoryInfo categoryInfo = new CategoryInfo();

            categoryInfo.CateId = TypeHelper.ObjectToInt(reader["cateid"]);
            categoryInfo.DisplayOrder = TypeHelper.ObjectToInt(reader["displayorder"]);
            categoryInfo.Name = reader["name"].ToString();
            categoryInfo.PriceRange = reader["pricerange"].ToString();
            categoryInfo.ParentId = TypeHelper.ObjectToInt(reader["parentid"]);
            categoryInfo.Layer = TypeHelper.ObjectToInt(reader["layer"]);
            categoryInfo.HasChild = TypeHelper.ObjectToInt(reader["haschild"]);
            categoryInfo.Path = reader["path"].ToString();

            return categoryInfo;
        }
예제 #4
0
        /// <summary>
        /// 创建分类
        /// </summary>
        public static void CreateCategory(CategoryInfo categoryInfo)
        {
            if (categoryInfo.ParentId > 0)
            {
                List<CategoryInfo> categoryList = BrnMall.Data.Categories.GetCategoryList();
                CategoryInfo parentCategoryInfo = categoryList.Find(x => x.CateId == categoryInfo.ParentId);//父分类
                categoryInfo.Layer = parentCategoryInfo.Layer + 1;
                categoryInfo.HasChild = 0;
                categoryInfo.Path = "";
                int categoryId = BrnMall.Data.Categories.CreateCategory(categoryInfo);

                categoryInfo.CateId = categoryId;
                categoryInfo.Path = parentCategoryInfo.Path + "," + categoryId;
                BrnMall.Data.Categories.UpdateCategory(categoryInfo);

                if (parentCategoryInfo.HasChild == 0)
                {
                    parentCategoryInfo.HasChild = 1;
                    BrnMall.Data.Categories.UpdateCategory(parentCategoryInfo);
                }
            }
            else
            {
                categoryInfo.Layer = 1;
                categoryInfo.HasChild = 0;
                categoryInfo.Path = "";
                int categoryId = BrnMall.Data.Categories.CreateCategory(categoryInfo);

                categoryInfo.CateId = categoryId;
                categoryInfo.Path = categoryId.ToString();
                BrnMall.Data.Categories.UpdateCategory(categoryInfo);
            }


            BrnMall.Core.BMACache.Remove(CacheKeys.MALL_CATEGORY_LIST);

            WriteMallAdminCategorySelectListCache(GetCategoryList());
        }
예제 #5
0
        /// <summary>
        /// 更新分类
        /// </summary>
        /// <returns></returns>
        public void UpdateCategory(CategoryInfo categoryInfo)
        {
            DbParameter[] parms = {
                                        GenerateInParam("@displayorder", SqlDbType.Int,4, categoryInfo.DisplayOrder),
                                        GenerateInParam("@name", SqlDbType.NChar,60, categoryInfo.Name),
                                        GenerateInParam("@pricerange", SqlDbType.Char,200,categoryInfo.PriceRange),
                                        GenerateInParam("@parentid", SqlDbType.SmallInt, 2, categoryInfo.ParentId),
                                        GenerateInParam("@layer", SqlDbType.TinyInt,1,categoryInfo.Layer),
                                        GenerateInParam("@haschild", SqlDbType.TinyInt,1,categoryInfo.HasChild),
                                        GenerateInParam("@path", SqlDbType.Char,100, categoryInfo.Path),
                                        GenerateInParam("@cateid", SqlDbType.SmallInt, 2, categoryInfo.CateId)    
                                    };

            string commandText = string.Format("UPDATE [{0}categories] SET [displayorder]=@displayorder,[name]=@name,[pricerange]=@pricerange,[parentId]=@parentId,[layer]=@layer,[haschild]=@haschild,[path]=@path WHERE [cateid]=@cateid",
                                                RDBSHelper.RDBSTablePre);
            RDBSHelper.ExecuteNonQuery(CommandType.Text, commandText, parms);
        }
예제 #6
0
 /// <summary>
 /// 创建分类
 /// </summary>
 /// <returns></returns>
 public int CreateCategory(CategoryInfo categoryInfo)
 {
     DbParameter[] parms = {
                                 GenerateInParam("@displayorder", SqlDbType.Int,4, categoryInfo.DisplayOrder),
                                 GenerateInParam("@name", SqlDbType.NChar,60, categoryInfo.Name),
                                 GenerateInParam("@pricerange", SqlDbType.Char,200,categoryInfo.PriceRange),
                                 GenerateInParam("@parentid", SqlDbType.SmallInt, 2, categoryInfo.ParentId),
                                 GenerateInParam("@layer", SqlDbType.TinyInt,1,categoryInfo.Layer),
                                 GenerateInParam("@haschild", SqlDbType.TinyInt,1,categoryInfo.HasChild),
                                 GenerateInParam("@path", SqlDbType.Char,100, categoryInfo.Path)
                             };
     string commandText = string.Format("INSERT INTO [{0}categories]([displayorder],[name],[pricerange],[parentid],[layer],[haschild],[path]) VALUES(@displayorder,@name,@pricerange,@parentid,@layer,@haschild,@path);SELECT SCOPE_IDENTITY()",
                                         RDBSHelper.RDBSTablePre);
     return TypeHelper.ObjectToInt(RDBSHelper.ExecuteScalar(CommandType.Text, commandText, parms), -1);
 }
예제 #7
0
 /// <summary>
 /// 创建分类
 /// </summary>
 public static int CreateCategory(CategoryInfo categoryInfo)
 {
     return BrnMall.Core.BMAData.RDBS.CreateCategory(categoryInfo);
 }
예제 #8
0
 /// <summary>
 /// 更新分类
 /// </summary>
 public static void UpdateCategory(CategoryInfo categoryInfo)
 {
     BrnMall.Core.BMAData.RDBS.UpdateCategory(categoryInfo);
 }
예제 #9
0
 /// <summary>
 /// 递归更新分类及其子分类的级别和路径
 /// </summary>
 /// <param name="categoryList">分类列表</param>
 /// <param name="categoryInfo">分类信息</param>
 /// <param name="changeLayer">变化的级别</param>
 /// <param name="parentPath">父路径</param>
 private static void UpdateChildCategoryLayerAndPath(List<CategoryInfo> categoryList, CategoryInfo categoryInfo, int changeLayer, string parentPath)
 {
     categoryInfo.Layer = categoryInfo.Layer + changeLayer;
     categoryInfo.Path = parentPath + "," + categoryInfo.CateId;
     BrnMall.Data.Categories.UpdateCategory(categoryInfo);
     foreach (CategoryInfo info in categoryList.FindAll(x => x.ParentId == categoryInfo.CateId))
     {
         UpdateChildCategoryLayerAndPath(categoryList, info, changeLayer, categoryInfo.Path);
     }
 }
예제 #10
0
        /// <summary>
        /// 获得分类列表
        /// </summary>
        /// <param name="keyword">关键词</param>
        /// <returns></returns>
        public List<CategoryInfo> GetCategoryListByKeyword(string keyword)
        {
            DbParameter[] parms = {
                                    GenerateInParam("@keyword", SqlDbType.NChar,40,keyword)
                                   };


            List<CategoryInfo> categoryList = new List<CategoryInfo>();
            IDataReader reader = RDBSHelper.ExecuteReader(CommandType.StoredProcedure,
                                                          string.Format("{0}getcategorylistbykeyword", RDBSHelper.RDBSTablePre),
                                                          parms);
            while (reader.Read())
            {
                CategoryInfo categoryInfo = new CategoryInfo();

                categoryInfo.CateId = TypeHelper.ObjectToInt(reader["cateid"]);
                categoryInfo.DisplayOrder = TypeHelper.ObjectToInt(reader["displayorder"]);
                categoryInfo.Name = reader["name"].ToString();
                categoryInfo.PriceRange = reader["pricerange"].ToString();
                categoryInfo.ParentId = TypeHelper.ObjectToInt(reader["parentid"]);
                categoryInfo.Layer = TypeHelper.ObjectToInt(reader["layer"]);
                categoryInfo.HasChild = TypeHelper.ObjectToInt(reader["haschild"]);
                categoryInfo.Path = reader["path"].ToString();

                categoryList.Add(categoryInfo);
            }
            reader.Close();
            return categoryList;
        }