//临时 public void update() { var f = new FunctionService(); var role = new RoleTypeService(); if (f.FindAll().Count > 21) return; var ro = new RoleAuthorityService(); f.Insert(new function() { Meno = "淘汰任务", Name = "EliminateTask" }); f.Insert(new function() { Name = "DeadTask", Meno = "死亡任务" }); f.Insert(new function() { Name = "EliminateInfo", Meno = "淘汰信息管理" }); f.Insert(new function() { Name = "DeadInfo", Meno = "死亡信息管理" }); var roletype = new RoleTypeService(); roletype.Insert(new role_type() { Name="淘汰生猪负责员" }); roletype.Insert(new role_type() { Name = "死亡生猪处理员" }); foreach (var a in role.FindAll()) { for (int i = 20; i < 24; i++) ro.Insert(new role_authority() { FunctionId = i, RoleTypeId = a.Id, Check = true }); } }
/// <summary> /// 根据角色类型id查看权限 /// </summary> /// <param name="roleTypeId">角色id</param> /// <returns></returns> public RoleAuthority GetRoleAuthorityList(long roleTypeId) { var roleAuthorityService = new RoleAuthorityService(); List<role_authority> roleAuthorityList = roleAuthorityService.FindByRoleTypeId(roleTypeId); var authorityList = new RoleAuthority(); int i = 0; foreach (role_authority roleAuthority in roleAuthorityList.OrderBy(m => m.FunctionId)) { authorityList.RoleAuthoritys.Add(new Authority()); authorityList.RoleAuthoritys[i].Function = roleAuthority.function.Meno; authorityList.RoleAuthoritys[i].Add = roleAuthority.Add; authorityList.RoleAuthoritys[i].Check = roleAuthority.Check; authorityList.RoleAuthoritys[i].Delete = roleAuthority.Delete; authorityList.RoleAuthoritys[i].Edit = roleAuthority.Edit; i++; } return authorityList; }
/// <summary> /// 更新权限表 /// </summary> /// <param name="authorityList"></param> /// <returns></returns> public bool UpdateRoleAuthorityList(RoleAuthority authorityList) { var roleAuthorityService = new RoleAuthorityService(); List<role_authority> roleAuthorityList = roleAuthorityService.FindByRoleTypeId(long.Parse(authorityList.Role)); int i = 0; foreach (role_authority roleAuthority in roleAuthorityList.OrderBy(m => m.FunctionId)) { roleAuthority.Add = authorityList.RoleAuthoritys[i].Add; roleAuthority.Check = authorityList.RoleAuthoritys[i].Check; roleAuthority.Delete = authorityList.RoleAuthoritys[i].Delete; roleAuthority.Edit = authorityList.RoleAuthoritys[i].Edit; roleAuthority.Meno = authorityList.Meno; i++; roleAuthorityService.Update(roleAuthority); } return true; }
/// <summary> /// 根据类型id查找关联它的表是否为0 /// </summary> /// <param name="typeid">类型id</param> /// <param name="typename">类型名字</param> /// <returns></returns> public string GetRelationtById(long typeid, string typename) { var cureTypeService = new CureTypeService(); var medicineService = new MedicineService(); var unitService = new UnitService(); var fodderTypeService = new FodderTypeService(); var excetionTypeService = new ExceptionTypeService(); var pigTypeService = new PigTypeService(); var pigHouseTypeService = new PigHouseTypeService(); var taskStatusTypeService = new TaskStatusTypeService(); var taskTypeService = new TaskTypeService(); var roleTypeService = new RoleTypeService(); var preventionTypeService = new PreventionTypeService(); var roleAuthorityService = new RoleAuthorityService(); var customerService = new CustomerService(); if (typeid == 0) { return "不存在于数据库,可以删除"; } try { if (typename == "治疗") { cureTypeService.Delete(cureTypeService.Find(typeid)); } if (typename == "单位") { unitService.Delete(unitService.Find(typeid)); } if (typename == "药物") { medicineService.Delete(medicineService.Find(typeid)); } if (typename == "异常") { excetionTypeService.Delete(excetionTypeService.Find(typeid)); } if (typename == "饲料") { fodderTypeService.Delete(fodderTypeService.Find(typeid)); } if (typename == "生猪") { if (pigTypeService.Find(typeid).Name == "母猪" || pigTypeService.Find(typeid).Name == "公猪") { return "不可删除"; } pigTypeService.Delete(pigTypeService.Find(typeid)); } if (typename == "防疫") { preventionTypeService.Delete(preventionTypeService.Find(typeid)); } if (typename == "猪舍") { pigHouseTypeService.Delete(pigHouseTypeService.Find(typeid)); } if (typename == "任务状态") { if (taskStatusTypeService.Find(typeid).Name == "未完成" || taskStatusTypeService.Find(typeid).Name == "已完成" || taskStatusTypeService.Find(typeid).Name == "正在进行") { return "不可删除"; } taskStatusTypeService.Delete(taskStatusTypeService.Find(typeid)); } if (typename == "任务类型") { if (taskTypeService.Find(typeid).Name == "喂饲" || taskTypeService.Find(typeid).Name == "防疫" || taskTypeService.Find(typeid).Name == "巡查" || taskTypeService.Find(typeid).Name == "治疗" || taskTypeService.Find(typeid).Name == "销售" || taskTypeService.Find(typeid).Name == "转栏" || taskTypeService.Find(typeid).Name == "添加生猪") { return "不可删除"; } taskTypeService.Delete(taskTypeService.Find(typeid)); } if (typename == "角色") { foreach (role_authority c in roleAuthorityService.FindByRoleTypeId(typeid)) roleAuthorityService.Delete(roleAuthorityService.Find(c.Id)); roleTypeService.Delete(roleTypeService.Find(typeid)); } if (typename == "客户名称") { customerService.Delete(customerService.Find(typeid)); } } catch (Exception) { return "不可删除"; } return ""; }
public ActionResult Catalog() { //若未登录,则不初始化左边的菜单栏 if (!User.Identity.IsAuthenticated) { return null; } //若session已有记录,则不再重复获得各个权限的session if (Session["CheckFeed"] != null) { return PartialView(); } employee employee = new EmployeeService().FindByNumber(User.Identity.Name.Split('|')[0]); if (employee == null) { return null; } List<role> roleList = new RoleService().FindByEmployeeId(employee.Id); var roleAuthorityService = new RoleAuthorityService(); List<List<role_authority>> list = roleList.Select(role => roleAuthorityService.FindByRoleTypeId(role.RoleId)).ToList(); //增加权限 Session["AddFeed"] = roleAuthorityService.GetAddAuthority(list, "Feed"); Session["AddPreventionDisease"] = roleAuthorityService.GetAddAuthority(list, "PreventionDisease"); Session["AddTransferPigsty"] = roleAuthorityService.GetAddAuthority(list, "TransferPigsty"); Session["AddInspect"] = roleAuthorityService.GetAddAuthority(list, "Inspect"); Session["AddCure"] = roleAuthorityService.GetAddAuthority(list, "Cure"); Session["AddSale"] = roleAuthorityService.GetAddAuthority(list, "Sale"); Session["AddAddPig"] = roleAuthorityService.GetAddAuthority(list, "AddPig"); Session["AddDataImport"] = roleAuthorityService.GetAddAuthority(list, "DataImport"); Session["AddAddNewPig"] = roleAuthorityService.GetAddAuthority(list, "AddNewPig"); Session["AddPigData"] = roleAuthorityService.GetAddAuthority(list, "PigData"); Session["AddFeedInfo"] = roleAuthorityService.GetAddAuthority(list, "FeedInfo"); Session["AddPreventionDiseaseInfo"] = roleAuthorityService.GetAddAuthority(list, "PreventionDiseaseInfo"); Session["AddTransferPigstyInfo"] = roleAuthorityService.GetAddAuthority(list, "TransferPigstyInfo"); Session["AddInspectInfo"] = roleAuthorityService.GetAddAuthority(list, "InspectInfo"); Session["AddCureInfo"] = roleAuthorityService.GetAddAuthority(list, "CureInfo"); Session["AddSalesInfo"] = roleAuthorityService.GetAddAuthority(list, "SalesInfo"); Session["AddFodderTake"] = roleAuthorityService.GetAddAuthority(list, "FodderTake"); Session["AddMedicineTake"] = roleAuthorityService.GetAddAuthority(list, "MedicineTake"); Session["AddSystemManage"] = roleAuthorityService.GetAddAuthority(list, "SystemManage"); Session["AddEliminateTask"] = roleAuthorityService.GetAddAuthority(list, "EliminateTask"); Session["AddDeadTask"] = roleAuthorityService.GetAddAuthority(list, "DeadTask"); Session["AddEliminateInfo"] = roleAuthorityService.GetAddAuthority(list, "EliminateInfo"); Session["AddDeadInfo"] = roleAuthorityService.GetAddAuthority(list, "DeadInfo"); //删除权限 Session["DelFeed"] = roleAuthorityService.GetDelAuthority(list, "Feed"); Session["DelPreventionDisease"] = roleAuthorityService.GetDelAuthority(list, "PreventionDisease"); Session["DelTransferPigsty"] = roleAuthorityService.GetDelAuthority(list, "TransferPigsty"); Session["DelInspect"] = roleAuthorityService.GetDelAuthority(list, "Inspect"); Session["DelCure"] = roleAuthorityService.GetDelAuthority(list, "Cure"); Session["DelSale"] = roleAuthorityService.GetDelAuthority(list, "Sale"); Session["DelAddPig"] = roleAuthorityService.GetDelAuthority(list, "AddPig"); Session["DelDataImport"] = roleAuthorityService.GetDelAuthority(list, "DataImport"); Session["DelAddNewPig"] = roleAuthorityService.GetDelAuthority(list, "AddNewPig"); Session["DelPigData"] = roleAuthorityService.GetDelAuthority(list, "PigData"); Session["DelFeedInfo"] = roleAuthorityService.GetDelAuthority(list, "FeedInfo"); Session["DelPreventionDiseaseInfo"] = roleAuthorityService.GetDelAuthority(list, "PreventionDiseaseInfo"); Session["DelTransferPigstyInfo"] = roleAuthorityService.GetDelAuthority(list, "TransferPigstyInfo"); Session["DelInspectInfo"] = roleAuthorityService.GetDelAuthority(list, "InspectInfo"); Session["DelCureInfo"] = roleAuthorityService.GetDelAuthority(list, "CureInfo"); Session["DelSalesInfo"] = roleAuthorityService.GetDelAuthority(list, "SalesInfo"); Session["DelFodderTake"] = roleAuthorityService.GetDelAuthority(list, "FodderTake"); Session["DelMedicineTake"] = roleAuthorityService.GetDelAuthority(list, "MedicineTake"); Session["DelSystemManage"] = roleAuthorityService.GetDelAuthority(list, "SystemManage"); Session["DelEliminateTask"] = roleAuthorityService.GetDelAuthority(list, "EliminateTask"); Session["DelDeadTask"] = roleAuthorityService.GetDelAuthority(list, "DeadTask"); Session["DelEliminateInfo"] = roleAuthorityService.GetDelAuthority(list, "EliminateInfo"); Session["DelDeadInfo"] = roleAuthorityService.GetDelAuthority(list, "DeadInfo"); //查看权限,若无查看权限,则默认增删查改权限都没有 Session["CheckFeed"] = roleAuthorityService.GetCheckAuthority(list, "Feed"); Session["CheckPreventionDisease"] = roleAuthorityService.GetCheckAuthority(list, "PreventionDisease"); Session["CheckTransferPigsty"] = roleAuthorityService.GetCheckAuthority(list, "TransferPigsty"); Session["CheckInspect"] = roleAuthorityService.GetCheckAuthority(list, "Inspect"); Session["CheckCure"] = roleAuthorityService.GetCheckAuthority(list, "Cure"); Session["CheckSale"] = roleAuthorityService.GetCheckAuthority(list, "Sale"); Session["CheckAddPig"] = roleAuthorityService.GetCheckAuthority(list, "AddPig"); Session["CheckDataImport"] = roleAuthorityService.GetCheckAuthority(list, "DataImport"); Session["CheckAddNewPig"] = roleAuthorityService.GetCheckAuthority(list, "AddNewPig"); Session["CheckPigData"] = roleAuthorityService.GetCheckAuthority(list, "PigData"); Session["CheckFeedInfo"] = roleAuthorityService.GetCheckAuthority(list, "FeedInfo"); Session["CheckPreventionDiseaseInfo"] = roleAuthorityService.GetCheckAuthority(list, "PreventionDiseaseInfo"); Session["CheckTransferPigstyInfo"] = roleAuthorityService.GetCheckAuthority(list, "TransferPigstyInfo"); Session["CheckInspectInfo"] = roleAuthorityService.GetCheckAuthority(list, "InspectInfo"); Session["CheckCureInfo"] = roleAuthorityService.GetCheckAuthority(list, "CureInfo"); Session["CheckSalesInfo"] = roleAuthorityService.GetCheckAuthority(list, "SalesInfo"); Session["CheckFodderTake"] = roleAuthorityService.GetCheckAuthority(list, "FodderTake"); Session["CheckMedicineTake"] = roleAuthorityService.GetCheckAuthority(list, "MedicineTake"); Session["CheckSystemManage"] = roleAuthorityService.GetCheckAuthority(list, "SystemManage"); Session["CheckEliminateTask"] = roleAuthorityService.GetCheckAuthority(list, "EliminateTask"); Session["CheckDeadTask"] = roleAuthorityService.GetCheckAuthority(list, "DeadTask"); Session["CheckEliminateInfo"] = roleAuthorityService.GetCheckAuthority(list, "EliminateInfo"); Session["CheckDeadInfo"] = roleAuthorityService.GetCheckAuthority(list, "DeadInfo"); //编辑权限 Session["EditFeed"] = roleAuthorityService.GetEditAuthority(list, "Feed"); Session["EditPreventionDisease"] = roleAuthorityService.GetEditAuthority(list, "PreventionDisease"); Session["EditTransferPigsty"] = roleAuthorityService.GetEditAuthority(list, "TransferPigsty"); Session["EditInspect"] = roleAuthorityService.GetEditAuthority(list, "Inspect"); Session["EditCure"] = roleAuthorityService.GetEditAuthority(list, "Cure"); Session["EditSale"] = roleAuthorityService.GetEditAuthority(list, "Sale"); Session["EditAddPig"] = roleAuthorityService.GetEditAuthority(list, "AddPig"); Session["EditDataImport"] = roleAuthorityService.GetEditAuthority(list, "DataImport"); Session["EditAddNewPig"] = roleAuthorityService.GetEditAuthority(list, "AddNewPig"); Session["EditPigData"] = roleAuthorityService.GetEditAuthority(list, "PigData"); Session["EditFeedInfo"] = roleAuthorityService.GetEditAuthority(list, "FeedInfo"); Session["EditPreventionDiseaseInfo"] = roleAuthorityService.GetEditAuthority(list, "PreventionDiseaseInfo"); Session["EditTransferPigstyInfo"] = roleAuthorityService.GetEditAuthority(list, "TransferPigstyInfo"); Session["EditInspectInfo"] = roleAuthorityService.GetEditAuthority(list, "InspectInfo"); Session["EditCureInfo"] = roleAuthorityService.GetEditAuthority(list, "CureInfo"); Session["EditSalesInfo"] = roleAuthorityService.GetEditAuthority(list, "SalesInfo"); Session["EditFodderTake"] = roleAuthorityService.GetEditAuthority(list, "FodderTake"); Session["EditMedicineTake"] = roleAuthorityService.GetEditAuthority(list, "MedicineTake"); Session["EditSystemManage"] = roleAuthorityService.GetEditAuthority(list, "SystemManage"); Session["EditEliminateTask"] = roleAuthorityService.GetEditAuthority(list, "EliminateTask"); Session["EditDeadTask"] = roleAuthorityService.GetEditAuthority(list, "DeadTask"); Session["EditEliminateInfo"] = roleAuthorityService.GetEditAuthority(list, "EliminateInfo"); Session["EditDeadInfo"] = roleAuthorityService.GetEditAuthority(list, "DeadInfo"); return PartialView(); }
public ActionResult PigData(int pageIndex = 1) { if (Session["CheckFeed"] == null || !(bool) Session["CheckPigData"]) { Response.Write("<script>history.go(0);</script>"); return View("Error"); } var pigInfo = new PigInfo(); PagedList<PigInfo> infoPagerList; if (Request.Form["CheckPig"] != null) { Session["check"] = Request.Form["CheckPig"]; Session["chooseid"] = Request.Form["SearchChose"]; infoPagerList = pigInfo.GetPigList(Request.Form["CheckPig"], Request.Form["SearchChose"], 1, PageSize); } else if (Session["check"] != null && Session["chooseid"] != null && Request.HttpMethod == "POST" && Session["chooseid"] as string != "") { infoPagerList = pigInfo.GetPigList(Session["check"] as string, Session["chooseid"] as string, pageIndex, PageSize); } else { //infoPagerList = pigInfo.GetInfoPagedList( // pigInfo.GetPigList("", ""), pageIndex, PageSize); Session["check"] = ""; Session["chooseid"] = ""; infoPagerList = pigInfo.GetPigList(pageIndex, PageSize); } ViewData["pigSum"] = infoPagerList.TotalItemCount; //ViewData["NomalpigSum"] = infoPagerList.Count(m => m.state == "正常"); //ViewData["UnNomalpigSum"] = infoPagerList.Count(m => m.state != "正常"); if (Request.IsAjaxRequest()) { return PartialView("PigDataUCJqInfoList", infoPagerList); } var pigHouseList = new ListService().GetPigHouseList(); var First = pigHouseList.FirstOrDefault(); if (First != null) ViewData["pigsty"] = new ListService().FindPigstyListByPigHouseId(First.Value); else ViewData["pigsty"] = new List<SelectListItem>(); ViewData["Search"] = new ListService().GetPigInfoSearchList(); ViewData["pighouse"] = new ListService().GetPigHouseList(); ViewData["pigtype"] = new ListService().GetPigTypeList(); //临时 var rolau = new RoleAuthorityService(); rolau.update(); // return View(infoPagerList); }
public void RoleTypeSaveChanges(BasicInfoModel model) { var typeService = new RoleTypeService(); var roleauthorityService = new RoleAuthorityService(); List<role_type> types = typeService.FindAll(); foreach (role_type type in types) { int idFlag = 0; int nameFlag = 0; string newname = ""; foreach (NameModel name in model.Names) { if (type.Id == name.Id) { idFlag = 1; if (type.Name.Equals(name.Name)) { nameFlag = 1; } else { newname = name.Name; } } } //若存在此Id,但是name变化了的,则需要修改数据库 if (idFlag == 1) { if (nameFlag == 0) { if (string.IsNullOrEmpty(newname)) { throw new Exception(); } role_type modifyCure = typeService.Find(type.Id); modifyCure.Name = newname; typeService.Update(modifyCure); } } } //如果model里的Id为0,说明是新建的类型 foreach (NameModel name in model.Names) { if (name.Id == 0 && typeService.FindByName(name.Name) == null) { var newType = new role_type {Name = name.Name}; typeService.Insert(newType); for (int j = 1; j <= 19; j++) { var roleAuthority = new role_authority { RoleTypeId = typeService.FindByName(name.Name).Id, FunctionId = j, Check = true }; roleauthorityService.Insert(roleAuthority); } } } }