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 id = CurrentNode.Value; var role = db.Value.StoreRole.Single(o => o.Id == id); role.Ordinal = ordinal.PeekValue(100); role.Name = content; if (role.State == 1) { role.Right = "{0}{1}{2}{3}{4}{5}".Formatted(r1.PeekValue(true), r2.PeekValue(true), r3.PeekValue(true), r4.PeekValue(true), r5.PeekValue(true), r6.PeekValue(true)); } db.Value.SaveChanges(); tree.DataSource = db.Value.StoreRole.Where(o => o.StoreId == StoreId && o.State < 2).OrderBy(o => o.Ordinal).ToList(); tree.DataBind(); var node = tree.GetAllNodes().ToList().First(o => o.Value == id.ToString()); node.Selected = true; } else { var role = new StoreRole { Id = db.Value.GlobalId(), StoreId = StoreId, Name = content, Right = "{0}{1}{2}{3}{4}{5}".Formatted(r1.PeekValue(true), r2.PeekValue(true), r3.PeekValue(true), r4.PeekValue(true), r5.PeekValue(true), r6.PeekValue(true)), Ordinal = ordinal.PeekValue(100), State = 1 }; db.Value.StoreRole.Add(role); db.Value.SaveChanges(); tree.DataSource = db.Value.StoreRole.Where(o => o.StoreId == StoreId && o.State < 2).OrderBy(o => o.Ordinal).ToList(); tree.DataBind(); var node = tree.GetAllNodes().ToList().First(o => o.Value == role.Id.ToString()); node.Selected = true; tree0.Nodes[0].Selected = false; InitializeArea(); } Notify(ap, "角色保存成功", "success"); }
protected void add_ServerClick(object sender, EventArgs e) { if (name.Text.Trim().Null()) { Notify(ap, "请输入仓库名称", "error"); return; } if ("{0}{1}{2}".Formatted(t1.PeekValue(true), t2.PeekValue(true), t3.PeekValue(true)).Null()) { Notify(ap, "请选择物资类型", "error"); return; } if (new[] { t1x, t2x, t3x }.PeekValue(-1) == -1) { Notify(ap, "请选择默认物资类型", "error"); return; } var store = new Store { Id = db.Value.GlobalId(), Name = name.Text.Trim(), CampusId = CurrentCampus, Ordinal = ordinal.PeekValue(100), DefaultView = view.PeekValue(1), DefaultType = new[] { t1x, t2x, t3x }.PeekValue(1), Types = "{0}{1}{2}".Formatted(t1.PeekValue(true), t2.PeekValue(true), t3.PeekValue(true)), State = StoreState.启用 }; db.Value.Store.Add(store); var role = new StoreRole { Id = db.Value.GlobalId(), StoreId = store.Id, Name = "{0}管理组".Formatted(store.Name), Right = "*", Ordinal = 0, State = 0 }; db.Value.StoreRole.Add(role); role.User.Add(db.Value.GetUser(CurrentUser)); db.Value.SaveChanges(); Response.Redirect("~/Store/Home"); }