/// <summary> /// 批量添加分类 /// </summary> /// <param name="catid"></param> private void bathAddCat(string catid) { SiteClassBll bll = new SiteClassBll(); int siteClassId; int parentId; SiteClassInfo siteCat = new SiteClassInfo(); if (int.TryParse(catid, out siteClassId)) { siteCat = bll.GetCatById(siteClassId); SiteCatName = siteCat.ClassName.Replace(" ",""); } if (!int.TryParse(Request.Form["parCatName"], out parentId)) return; #region 添加分类 ClassInfo cat = new ClassInfo(); cat.CatName = SiteCatName; cat.SpellWord = WordCenter.GetShortPinyin(cat.CatName); cat.SEOWords = ""; cat.Sort = 0; cat.CreateDate = DateTime.Now; cat.UpdateTime = DateTime.Now; cat.HasChild = false; ClassInfoBll catbll = new ClassInfoBll(); if (parentId != 0) { ClassInfo parCat = catbll.getCat(parentId); cat.ParentId = parCat.Id; cat.Level = parCat.Level + 1; cat.ParentName = parCat.CatName; if (!string.IsNullOrEmpty(parCat.CatCrumbleIds)) { cat.CatCrumbleIds = parCat.CatCrumbleIds + "," + parCat.Id; cat.CatCrumbleNames = parCat.CatCrumbleNames + "," + parCat.CatName; } else { cat.CatCrumbleIds = parCat.Id.ToString(CultureInfo.InvariantCulture); cat.CatCrumbleNames = parCat.CatName; } if (!parCat.HasChild) { parCat.HasChild = true; catbll.UpdateCat(parCat); } } else { cat.ParentId = 0; cat.Level = 1; cat.ParentName = ""; cat.CatCrumbleIds = ""; cat.CatCrumbleNames = ""; } cat.Id = catbll.AddCat(cat); #endregion #region 添加子分类 AllSiteCat = bll.GetClassInfo(siteCat.SiteId); addChildCat(siteCat.ClassId, cat); #endregion }
/// <summary> /// 添加分类 /// </summary> private void addCat() { if (Request.Form.Count < 3 || string.IsNullOrEmpty(Request.Form["catName"]) || string.IsNullOrEmpty(Request.Form["parCatName"])) return; int parentId; if (!int.TryParse(Request.Form["parCatName"], out parentId)) return; int catSort; int.TryParse(Request.Form["catSort"], out catSort); ClassInfo cat = new ClassInfo(); cat.CatName = Request.Form["catName"]; cat.SpellWord = new WordCenter().GetPyString(cat.CatName); cat.SEOWords = Request.Form["seoKey"]; cat.Sort = catSort; cat.CreateDate = DateTime.Now; cat.UpdateTime = DateTime.Now; cat.HasChild = false; cat.IsDel = false; ClassInfoBll catbll = new ClassInfoBll(); if (parentId != 0) { ClassInfo parCat = catbll.getCat(parentId); cat.ParentId = parCat.Id; cat.Level = parCat.Level + 1; cat.ParentName = parCat.CatName; if (!string.IsNullOrEmpty(parCat.CatCrumbleIds)) { cat.CatCrumbleIds = parCat.CatCrumbleIds + "," + parCat.Id; cat.CatCrumbleNames = parCat.CatCrumbleNames + "," + parCat.CatName; } else { cat.CatCrumbleIds = parCat.Id.ToString(CultureInfo.InvariantCulture); cat.CatCrumbleNames = parCat.CatName; } if (!parCat.HasChild) { parCat.HasChild = true; catbll.UpdateCat(parCat); } } else { cat.ParentId = 0; cat.Level = 1; cat.ParentName = ""; cat.CatCrumbleIds = ""; cat.CatCrumbleNames = ""; } catbll.AddCat(cat); }
/// <summary> /// 添加商城对应的子分类 /// </summary> /// <param name="siteCatId"></param> /// <param name="parCat"></param> private void addChildCat(string siteCatId, ClassInfo parCat) { var ChildCat = AllSiteCat.Where(p => p.ParentClass == siteCatId); foreach (var child in ChildCat) { ClassInfo cat = new ClassInfo(); cat.CatName = child.ClassName.Replace(" ",""); cat.SpellWord = WordCenter.GetShortPinyin(cat.CatName); cat.SEOWords = ""; cat.Sort = 0; cat.CreateDate = DateTime.Now; cat.UpdateTime = DateTime.Now; cat.HasChild = false; ClassInfoBll catbll = new ClassInfoBll(); if (parCat != null) { cat.ParentId = parCat.Id; cat.Level = parCat.Level + 1; cat.ParentName = parCat.CatName; if (!string.IsNullOrEmpty(parCat.CatCrumbleIds)) { cat.CatCrumbleIds = parCat.CatCrumbleIds + "," + parCat.Id; cat.CatCrumbleNames = parCat.CatCrumbleNames + "," + parCat.CatName; } else { cat.CatCrumbleIds = parCat.Id.ToString(CultureInfo.InvariantCulture); cat.CatCrumbleNames = parCat.CatName; } if (!parCat.HasChild) { parCat.HasChild = true; catbll.UpdateCat(parCat); } cat.Id = int.Parse(catbll.AddCat(cat).ToString()); if (AllSiteCat.Exists(p => p.ParentClass == child.ClassId)) { addChildCat(child.ClassId, cat); } } } }