protected void add_ServerClick(object sender, EventArgs e) { var content = name.Text.Trim(); var value = CurrentNode; if (content.None()) { NotifyError(ap, "请输入要添加的类别名称"); return; } if (CurrentNode.HasValue) { var parent = CurrentNode.Value; if (DataContext.DepotCatalogLoad(Depot.Id).Count(o => o.Name == content && o.ParentId == parent) == 0) { var pinYin = DataContext.ToPinYin(content).Single(); var catalog = new DepotCatalog { Id = DataContext.GlobalId(), ParentId = parent, TopId = TopNode.Value.GlobalId(), DepotId = Depot.Id, Name = content, PinYin = pinYin, Ordinal = ordinal.PeekValue(100), State = State.启用, Code = string.Empty }; DataContext.DepotCatalog.Add(catalog); DataContext.SaveChanges(); catalog.Code = DataContext.ToQR(CodeType.Catalog, catalog.AutoId); DataContext.SaveChanges(); } } else { if (DataContext.DepotCatalogLoad(Depot.Id).Count(o => o.Name == content && o.ParentId == null) == 0) { var pinYin = DataContext.ToPinYin(content).Single(); var id = DataContext.GlobalId(); var catalog = new DepotCatalog { Id = id, ParentId = null, TopId = id, DepotId = Depot.Id, Name = content, PinYin = pinYin, Ordinal = ordinal.PeekValue(100), State = State.启用, Code = string.Empty }; DataContext.DepotCatalog.Add(catalog); DataContext.SaveChanges(); catalog.Code = DataContext.ToQR(CodeType.Catalog, catalog.AutoId); DataContext.SaveChanges(); } } ordinal.Text = string.Empty; ordinal.Value = null; name.Text = string.Empty; tree.DataSource = DataContext.DepotCatalogLoad(Depot.Id).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(); NotifyOK(ap, "物资类别添加成功"); }
public static Guid DepotCatalogAdd(this DepotEntities db, Guid depotId, Guid? parent, Guid top, string name, int ordinal, string code) { var pinYin = db.ToPinYin(name).Single(); var newId = db.GlobalId(); var catalog = new DepotCatalog { Id = newId, ParentId = parent, TopId = parent.HasValue ? top : newId, DepotId = depotId, Name = name, PinYin = pinYin, Ordinal = ordinal, State = State.启用, Code = code }; db.DepotCatalog.Add(catalog); db.SaveChanges(); return newId; }