protected void GetSelectListAll(WebDepartments son, StringBuilder sbr, List <int> fatherList) { StringBuilder inSbr = new StringBuilder(); if (son != null) { if (son.Sons != null && son.Sons.Any()) { inSbr.Append("<select name='DeptId' class='form-control'><option value='0'>请选择</option>"); son.Sons.ToList().ForEach(i => { if (i.Id == son.Id || i.Id == son.ParentID || fatherList.Contains(i.Id)) { inSbr.Append("<option value='" + i.Id + "' selected='true'>" + i.Name + "</option>"); } else { inSbr.Append("<option value='" + i.Id + "'>" + i.Name + "</option>"); } }); inSbr.Append("</select>"); sbr.Insert(0, inSbr); } GetSelectListAll(son.Father, sbr, fatherList); } }
/// <summary> /// 递归得到它的所有祖宗以selectlist的形式进行拼接 /// </summary> /// <param name="son"></param> /// <param name="sbr"></param> protected void GetSelectList(WebDepartments son, StringBuilder sbr) { StringBuilder inSbr = new StringBuilder(); if (son != null) { if (son.Level == 0) { inSbr.Append("<select name='Parent' onchange = 'areaOnSelect(this)'><option value=''>全部</option>"); } else { inSbr.Append("<select name='Sub' onchange = 'areaOnSelect(this)'><option value=''>全部</option>"); } departmentsRepository.GetModel(i => i.ParentID == son.Id).ToList().ForEach(i => { if (i.Id == son.Id) { inSbr.Append("<option value='" + i.Id + "' selected='true'>" + i.Name + "</option>"); } else { inSbr.Append("<option value='" + i.Id + "'>" + i.Name + "</option>"); } }); inSbr.Append("</select>"); sbr.Insert(0, inSbr); // GetSelectList(son.Father, sbr); } }
public ActionResult Edit(int id, WebDepartments entity) { try { var oldlist = departmentsRepository.GetModel(i => i.ParentID == entity.ParentID); if (oldlist.FirstOrDefault(i => i.Name == entity.Name && i.Id != entity.Id) != null) { ModelState.AddModelError("", "同级不能重名..."); return(View()); } if (ModelState.IsValid) { var old = departmentsRepository.Find(id); old.Name = entity.Name; old.Level = entity.Level; old.SortNumber = entity.SortNumber; old.LinkUrl = entity.LinkUrl; departmentsRepository.Update(old); return(RedirectToAction("Index")); } else { ModelState.AddModelError("", "请把表单填写完整..."); return(View()); } } catch { return(View()); } }
public ActionResult Create(WebDepartments entity) { try { var oldlist = departmentsRepository.GetModel(i => i.ParentID == entity.ParentID); if (oldlist.FirstOrDefault(i => i.Name == entity.Name) != null) { ModelState.AddModelError("", "同级不能重名..."); return(View()); } if (ModelState.IsValid) { entity.Id = -1; entity.Operator = ""; entity.About = ""; departmentsRepository.Insert(entity); return(RedirectToAction("Index")); } else { ModelState.AddModelError("", "请把表单填写完整..."); return(View()); } } catch { return(View()); } }
private void FindDeptFatherTree(WebDepartments dept, List <int> fatherList) { if (dept != null) { dept.Father = DeptDB.FirstOrDefault(i => i.Id == dept.ParentID); fatherList.Add(dept.ParentID ?? 0); FindDeptFatherTree(dept.Father, fatherList); } }
/// <summary> /// 部门-角色-下拉列表 /// </summary> /// <param name="dataSetTypeId"></param> /// <param name="id"></param> /// <returns></returns> public PartialViewResult Dept_Role_SelectList(int deptId = 0, int roleId = 0) { var deptList = new List <SelectListItem>(); deptList = new List <SelectListItem>(departmentsRepository.GetModel().Select(i => new SelectListItem { Text = i.Name, Value = i.Id.ToString(), Selected = i.Id == deptId ? true : false })); deptList.Insert(0, new SelectListItem { Text = "请选择", Value = "0", Selected = true }); var roleList = new List <SelectListItem>(); if (deptId > 0) { roleList = new List <SelectListItem>(roleRepository.GetModel(i => i.DepartmentID == deptId).Select(i => new SelectListItem { Text = i.RoleName, Value = i.Id.ToString(), Selected = i.Id == roleId ? true : false })); } roleList.Insert(0, new SelectListItem { Text = "请选择", Value = "0", Selected = true }); ViewBag.roleList = roleList; ViewBag.deptList = deptList; StringBuilder str = new StringBuilder(); List <int> fatherList = new List <int>(); var father = new WebDepartments(); if (deptId > 0) { father = departmentsRepository.GetModel().FirstOrDefault(i => i.Id == deptId); fatherList.Add(deptId); } else { father = departmentsRepository.GetModel().FirstOrDefault(i => i.Level == 1); father.Sons = null;//默认“请选择”状态它的子列表为空 } FindDeptFatherTree(father, fatherList); GetSelectListAll(father, str, fatherList); ViewBag.DeptStr = str.ToString(); return(PartialView()); }
protected override void Seed(ManagerContext context) { try { #region 操作命令字典表(操作权限的按钮) context.WebAuthorityCommands.Add(new WebAuthorityCommands { Flag = 1, ActionName = "Details", Name = "查看", Feature = WebAuthorityCommandFeature.Dialog }); context.WebAuthorityCommands.Add(new WebAuthorityCommands { Flag = 2, ActionName = "Add", Name = "添加", Feature = WebAuthorityCommandFeature.None }); context.WebAuthorityCommands.Add(new WebAuthorityCommands { Flag = 4, ActionName = "Edit", Name = "编辑", Feature = WebAuthorityCommandFeature.None }); context.WebAuthorityCommands.Add(new WebAuthorityCommands { Flag = 8, ActionName = "Deleted", Name = "删除", Feature = WebAuthorityCommandFeature.Warn }); context.WebAuthorityCommands.Add(new WebAuthorityCommands { Flag = 16, ActionName = "Freeze", Name = "冻结", Feature = WebAuthorityCommandFeature.Warn }); context.WebAuthorityCommands.Add(new WebAuthorityCommands { Flag = 32, ActionName = "Approve", Name = "审核", Feature = WebAuthorityCommandFeature.Warn }); context.SaveChanges(); #endregion #region 部门表 var department = new WebDepartments { About = "", Name = "根", Level = 0, Operator = "admin", ParentID = null, SortNumber = 0, Sons = new List <WebDepartments> { new WebDepartments { About = "", Name = "总裁办", Level = 1, Operator = "admin", SortNumber = 0 }, new WebDepartments { About = "", Name = "研发部", Level = 1, Operator = "admin", SortNumber = 0, Sons = new List <WebDepartments> { new WebDepartments { About = "", Name = "设计部", Level = 2, Operator = "admin", SortNumber = 0 }, new WebDepartments { About = "", Name = "产品部", Level = 2, Operator = "admin", SortNumber = 0 }, new WebDepartments { About = "", Name = "开发部", Level = 2, Operator = "admin", SortNumber = 0, Sons = new List <WebDepartments> { new WebDepartments { About = "", Name = "C#组", Level = 3, Operator = "admin", SortNumber = 0 }, new WebDepartments { About = "", Name = "JAVA组", Level = 3, Operator = "admin", SortNumber = 0 }, new WebDepartments { About = "", Name = "IOS组", Level = 3, Operator = "admin", SortNumber = 0 }, new WebDepartments { About = "", Name = "Android组", Level = 3, Operator = "admin", SortNumber = 0 }, } } } }, new WebDepartments { About = "", Name = "人力部", Level = 1, Operator = "admin", SortNumber = 0, }, new WebDepartments { About = "", Name = "财物部", Level = 1, Operator = "admin", SortNumber = 0, } } }; context.WebDepartments.Add(department); context.SaveChanges(); #endregion #region 菜单表 var menu = new WebManageMenus { About = "", LinkUrl = "", Level = 0, Name = "根", Operator = "admin", ParentID = null, SortNumber = 0 }; #region 系统菜单 var systemMenu = new WebManageMenus { About = "", LinkUrl = "", Level = 1, Name = "系统管理", Operator = "admin", SortNumber = 0 }; systemMenu.Sons.Add(new WebManageMenus { About = "", LinkUrl = "", Level = 2, Name = "菜单管理", Operator = "admin", ParentID = null, SortNumber = 0, Sons = new List <WebManageMenus> { new WebManageMenus { About = "", LinkUrl = "/WebMenu/Create", Level = 3, Name = "添加菜单", Operator = "admin", ParentID = null, SortNumber = 0, IsDisplayMenuTree = false, Authority = (long)(Authority.Create | Authority.Detail) }, new WebManageMenus { About = "", LinkUrl = "/WebMenu/Index", Level = 3, Name = "管理菜单", Operator = "admin", ParentID = null, SortNumber = 0, Authority = (long)(Authority.Edit | Authority.Detail | Authority.Delete) } , new WebManageMenus { About = "", LinkUrl = "/WebMenu/Edit", Level = 3, Name = "编辑菜单", Operator = "admin", ParentID = null, SortNumber = 0, IsDisplayMenuTree = false, Authority = (long)(Authority.Edit | Authority.Detail) } , new WebManageMenus { About = "", LinkUrl = "/WebMenu/Delete", Level = 3, Name = "删除菜单", Operator = "admin", ParentID = null, SortNumber = 0, IsDisplayMenuTree = false, Authority = (long)(Authority.Delete) } } }); systemMenu.Sons.Add(new WebManageMenus { About = "", LinkUrl = "", Level = 2, Name = "部门管理", Operator = "admin", ParentID = null, SortNumber = 0, Sons = new List <WebManageMenus> { new WebManageMenus { About = "", LinkUrl = "/WebDept/Create", Level = 3, Name = "添加部门", Operator = "admin", ParentID = null, SortNumber = 0, IsDisplayMenuTree = false, Authority = (long)(Authority.Create | Authority.Detail) }, new WebManageMenus { About = "", LinkUrl = "/WebDept/Index", Level = 3, Name = "管理部门", Operator = "admin", ParentID = null, SortNumber = 0, Authority = (long)(Authority.Edit | Authority.Detail | Authority.Delete) } , new WebManageMenus { About = "", LinkUrl = "/WebDept/Edit", Level = 3, Name = "编辑部门", Operator = "admin", ParentID = null, SortNumber = 0, IsDisplayMenuTree = false, Authority = (long)(Authority.Edit | Authority.Detail) } , new WebManageMenus { About = "", LinkUrl = "/WebDept/Delete", Level = 3, Name = "删除部门", Operator = "admin", ParentID = null, SortNumber = 0, IsDisplayMenuTree = false, Authority = (long)(Authority.Delete) } } }); systemMenu.Sons.Add(new WebManageMenus { About = "后台管理默认的主页", LinkUrl = "", Level = 2, Name = "用户管理", Operator = "admin", ParentID = null, SortNumber = 0, Sons = new List <WebManageMenus> { new WebManageMenus { About = "", LinkUrl = "/WebUser/Create", Level = 3, Name = "添加用户", Operator = "admin", ParentID = null, SortNumber = 0, Authority = (long)(Authority.Detail | Authority.Create) }, new WebManageMenus { About = "", LinkUrl = "/WebUser/Index", Level = 3, Name = "管理用户", Operator = "admin", ParentID = null, SortNumber = 0, Authority = (long)(Authority.Edit | Authority.Detail | Authority.Delete | Authority.Freeze) }, new WebManageMenus { About = "", LinkUrl = "/WebUser/Edit", Level = 3, Name = "编辑用户", Operator = "admin", ParentID = null, SortNumber = 0, IsDisplayMenuTree = false, Authority = (long)(Authority.Edit | Authority.Detail) } , new WebManageMenus { About = "", LinkUrl = "/WebUser/Delete", Level = 3, Name = "删除用户", Operator = "admin", ParentID = null, SortNumber = 0, IsDisplayMenuTree = false, Authority = (long)(Authority.Delete) } } }); systemMenu.Sons.Add(new WebManageMenus { About = "", LinkUrl = "", Level = 2, Name = "角色管理", Operator = "admin", ParentID = null, SortNumber = 0, Sons = new List <WebManageMenus> { new WebManageMenus { About = "", LinkUrl = "/WebRole/Create", Level = 3, Name = "添加角色", Operator = "admin", ParentID = null, SortNumber = 0, Authority = (long)(Authority.Detail | Authority.Create) }, new WebManageMenus { About = "", LinkUrl = "/WebRole/Index", Level = 3, Name = "管理角色", Operator = "admin", ParentID = null, SortNumber = 0, Authority = (long)(Authority.Edit | Authority.Detail | Authority.Delete) }, new WebManageMenus { About = "", LinkUrl = "/WebRole/Edit", Level = 3, Name = "编辑角色", Operator = "admin", ParentID = null, SortNumber = 0, IsDisplayMenuTree = false, Authority = (long)(Authority.Edit | Authority.Detail) } , new WebManageMenus { About = "", LinkUrl = "/WebRole/Delete", Level = 3, Name = "删除角色", Operator = "admin", ParentID = null, SortNumber = 0, IsDisplayMenuTree = false, Authority = (long)(Authority.Delete) } } }); systemMenu.Sons.Add(new WebManageMenus { About = "", LinkUrl = "", Level = 2, Name = "数据集管理", Operator = "admin", ParentID = null, SortNumber = 0, Sons = new List <WebManageMenus> { new WebManageMenus { About = "", LinkUrl = "/WebDataCtrl/Create", Level = 3, Name = "添加类型", Operator = "admin", ParentID = null, SortNumber = 0, Authority = (long)(Authority.Create | Authority.Detail) }, new WebManageMenus { About = "", LinkUrl = "/WebDataCtrl/Index", Level = 3, Name = "管理类型", Operator = "admin", ParentID = null, SortNumber = 0, Authority = (long)(Authority.Edit | Authority.Detail | Authority.Delete) } , new WebManageMenus { About = "", LinkUrl = "/WebDataCtrl/Delete", Level = 3, Name = "删除类型", Operator = "admin", ParentID = null, SortNumber = 0, Authority = (long)(Authority.Delete) } , new WebManageMenus { About = "", LinkUrl = "/WebDataCtrl/Edit", Level = 3, Name = "编辑类型", Operator = "admin", ParentID = null, SortNumber = 0, IsDisplayMenuTree = false, Authority = (long)(Authority.Edit | Authority.Detail) }, new WebManageMenus { About = "", LinkUrl = "/WebDataSetting/Create", Level = 3, Name = "添加数据集", Operator = "admin", ParentID = null, SortNumber = 0, Authority = (long)(Authority.Create | Authority.Detail) }, new WebManageMenus { About = "", LinkUrl = "/WebDataSetting/Index", Level = 3, Name = "管理数据集", Operator = "admin", ParentID = null, SortNumber = 0, Authority = (long)(Authority.Edit | Authority.Detail | Authority.Delete) }, new WebManageMenus { About = "", LinkUrl = "/WebDataSetting/Edit", Level = 3, Name = "编辑数据集", Operator = "admin", ParentID = null, SortNumber = 0, IsDisplayMenuTree = false, Authority = (long)(Authority.Edit | Authority.Detail) } , new WebManageMenus { About = "", LinkUrl = "/WebDataSetting/Delete", Level = 3, Name = "删除数据集", Operator = "admin", ParentID = null, SortNumber = 0, IsDisplayMenuTree = false, Authority = (long)(Authority.Delete) } } }); systemMenu.Sons.Add(new WebManageMenus { About = "", LinkUrl = "", Level = 2, Name = "操作日志管理", Operator = "admin", ParentID = null, SortNumber = 0, Sons = new List <WebManageMenus> { new WebManageMenus { About = "", LinkUrl = "/WebLogger/Index", Level = 3, Name = "日志列表", Operator = "admin", ParentID = null, SortNumber = 0, Authority = (long)(Authority.Detail) } } }); menu.Sons.Add(systemMenu); systemMenu.Sons.Add(new WebManageMenus { About = "", LinkUrl = "", Level = 2, Name = "权限按钮管理", Operator = "admin", ParentID = null, SortNumber = 0, Sons = new List <WebManageMenus> { new WebManageMenus { About = "", LinkUrl = "/WebAuthorityCommand/Index", Level = 3, Name = "权限按钮列表", Operator = "admin", ParentID = null, SortNumber = 0, Authority = (long)(Authority.Create | Authority.Detail) }, new WebManageMenus { About = "", LinkUrl = "/WebAuthorityCommand/Create", Level = 3, Name = "添加权限按钮", Operator = "admin", ParentID = null, SortNumber = 1, Authority = (long)(Authority.Edit | Authority.Detail | Authority.Delete) }, new WebManageMenus { About = "", LinkUrl = "/WebAuthorityCommand/Edit", Level = 3, Name = "编辑权限按钮", Operator = "admin", ParentID = null, SortNumber = 1, IsDisplayMenuTree = false, Authority = (long)(Authority.Edit | Authority.Detail) }, new WebManageMenus { About = "", LinkUrl = "/WebAuthorityCommand/AuthorityAction", Level = 3, Name = "权限页面管理", Operator = "admin", ParentID = null, SortNumber = 1, } } }); menu.Sons.Add(systemMenu); #endregion context.WebManageMenus.Add(menu); context.SaveChanges(); #endregion #region 角色表 var role = new WebManageRoles { About = "", DepartmentID = department.Sons.FirstOrDefault().Id, Operator = "admin", //OperatorAuthority = 1 | 2 | 4 | 8, RoleName = "管理员", SortNumber = 0, }; context.WebManageRoles.Add(role); context.SaveChanges(); #endregion #region 角色与菜单授权 List <WebManageRoles_WebManageMenus_Authority_R> webManageRoles_WebManageMenus_Authority_R = new List <WebManageRoles_WebManageMenus_Authority_R>(); context.WebManageMenus.ToList().ForEach(item => { webManageRoles_WebManageMenus_Authority_R.Add(new WebManageRoles_WebManageMenus_Authority_R { MenuId = item.Id, Authority = 1 | 2 | 4 | 8 | 16 | 32, RoleId = role.Id, }); }); context.WebManageRoles_WebManageMenus_Authority_R.AddRange(webManageRoles_WebManageMenus_Authority_R); context.SaveChanges(); #endregion #region 用户表 var user1 = new WebManageUsers { Description = "", Email = "*****@*****.**", LoginName = "admin", Mobile = "13800138000", Operator = "", Password = Lind.DDD.Utils.Encryptor.Utility.EncryptString("admin", Utils.Encryptor.Utility.EncryptorType.MD5), RealName = "管理员", WebSystemID = 1, ThridUserId = "", DataCreateDateTime = DateTime.Now, DataStatus = Status.Normal, LastModifyTime = DateTime.Now, WebDepartments = new List <WebDepartments> { department }, WebManageRoles = new List <WebManageRoles>() { role }, }; var it = department.Sons.Where(i => i.Name == "研发部").FirstOrDefault(); var user2 = new WebManageUsers { Description = "", Email = "*****@*****.**", LoginName = "it", Mobile = "13800138000", Operator = "", Password = Lind.DDD.Utils.Encryptor.Utility.EncryptString("it", Utils.Encryptor.Utility.EncryptorType.MD5), RealName = "技术人员", WebSystemID = 1, DataCreateDateTime = DateTime.Now, DataStatus = Status.Normal, LastModifyTime = DateTime.Now, WebDepartments = new List <WebDepartments> { it.Sons.FirstOrDefault(i => i.Name == "开发部"), it.Sons.FirstOrDefault(i => i.Name == "设计部") }, WebManageRoles = new List <WebManageRoles>() { role }, }; context.WebManageUsers.AddRange(new List <WebManageUsers> { user1, user2 }); context.SaveChanges(); #endregion base.Seed(context); } catch (DbEntityValidationException db) { throw db; } catch (Exception ex) { throw ex; } }