protected void AddChildren(List<Guid> list, StoreCatalog catalog) { list.Add(catalog.Id); foreach (var child in catalog.ChildrenStoreCatalog) { AddChildren(list, child); } }
protected void add_ServerClick(object sender, EventArgs e) { var content = name.Text.Trim(); var value = CurrentNode; if (content.Null()) { Notify(ap, "请输入要添加的类别名称", "error"); return; } if (CurrentNode.HasValue) { var parent = CurrentNode.Value; if (db.Value.StoreCatalog.Count(o => o.StoreId == StoreId && o.State < 2 && o.Name == content && o.ParentId == parent) == 0) { var pinYin = db.Value.ToPinYin(content).Single(); var catalog = new StoreCatalog { Id = db.Value.GlobalId(), ParentId = parent, StoreId = StoreId, Name = content, PinYin = pinYin, Ordinal = ordinal.PeekValue(100), State = 1, Code = string.Empty }; db.Value.StoreCatalog.Add(catalog); db.Value.SaveChanges(); } } else { if (db.Value.StoreCatalog.Count(o => o.StoreId == StoreId && o.State < 2 && o.Name == content && o.ParentId == null) == 0) { var pinYin = db.Value.ToPinYin(content).Single(); var catalog = new StoreCatalog { Id = db.Value.GlobalId(), ParentId = null, StoreId = StoreId, Name = content, PinYin = pinYin, Ordinal = ordinal.PeekValue(100), State = 1, Code = string.Empty }; db.Value.StoreCatalog.Add(catalog); if (CurrentStore.State == StoreState.食品) { var dictionary = new StoreDictionary { StoreId = StoreId, Type = DictionaryType.使用对象, Name = content, PinYin = catalog.PinYin }; db.Value.StoreDictionary.Add(dictionary); var dictionary2 = new StoreDictionary { StoreId = StoreId, Type = DictionaryType.年龄段, Name = content, PinYin = catalog.PinYin }; db.Value.StoreDictionary.Add(dictionary2); } db.Value.SaveChanges(); } } ordinal.Text = string.Empty; ordinal.Value = null; name.Text = string.Empty; tree.DataSource = db.Value.StoreCatalog.Where(o => o.StoreId == StoreId && o.State < 2).OrderBy(o => o.Ordinal).ToList(); tree.DataBind(); if (value.HasValue) { var node = tree.GetAllNodes().ToList().First(o => o.Value == value.Value.ToString()); node.Selected = true; node.Expanded = true; node.ExpandParentNodes(); node.ExpandChildNodes(); } else { tree0.Nodes[0].Selected = true; } view.Rebind(); Notify(ap, "类别添加成功", "success"); }