/// <summary> /// 获取某个角色的权限 数据不要乱改啊!! /// </summary> /// <param name="Id">角色的Id</param> /// <returns></returns> public string GetManeOP(string Id) { rms_role Rmodel = RMS_RoleService.Instance.SingleM(Id);//当前角色 string menus = " [\n"; var sqlManu = " 1=1 "; sqlManu += " and companyid=" + UserData.companyid + " "; //只显示 自己公司的 sqlManu += " and projectid=" + Rmodel.projectid + " "; //只显示同一个项目 if (!IsSysRole) //不是系统管理员的角色,只能返回自己的菜单 { sqlManu += " and id in( select manuid from rms_rolemanus where roleid='" + UserData.RoleId + "')"; } List <rms_menus> list = RMS_MenusService.Instance.FetchW(sqlManu); //菜单集 List <rms_buttons> listControlButtons = RMS_ButtonsService.Instance.FetchW(" 1=1 "); //所有的按钮 List <rms_rolemanus> listRoleColumns = RMS_RoleManusService.Instance.FetchW(" roleid='" + Id + "'"); //这个角色已经添加的菜单 List <v_rolemanubuttons> listRoleMenuButtons = V_RoleManuButtonsService.Instance.FetchW(" roleid='" + Id + "'"); //这个角色已经添加的角色按钮 for (int i = 0; i < list.Count; i++) { if (list.Find(p => p.id == list[i].parentmanuid) == null)//此项没有父级 { menus += "{ \"MenuId\":\"" + list[i].id + "\","; menus += string.Format(" \"Name\":\"{0}\",", list[i].manuname); menus += string.Format(" \"iconCls\":\"{0}\",", list[i].icon); string ControlId_Browse = "0"; rms_rolemanus rcItem = listRoleColumns.Find(p => p.manuid.Equals(list[i].id)); if (rcItem != null) { ControlId_Browse = "1";//如果存在 } menus += string.Format(" \"ControlId_Browse\":\"{0}\",", ControlId_Browse); foreach (rms_buttons dd in listControlButtons)//添加列的数据 { string Ishave = "0"; v_rolemanubuttons rmbItem = listRoleMenuButtons.Find(p => p.id.Equals(dd.id) && p.manuid.Equals(list[i].id)); if (rmbItem != null) { Ishave = "1";//如果角色有此按钮存在 } menus += string.Format("\"ControlId_{0}\":\"{1}\",", dd.id, Ishave); } menus += GetSonTreeManu(list, list[i], listControlButtons, listRoleColumns, listRoleMenuButtons);//添加children menus += "},"; } } menus = menus.Substring(0, menus.Length - 1); menus = menus + "]"; return(menus); }
private string GetSonTreeManu(List <rms_menus> listAll, rms_menus SonItem, List <rms_buttons> listControlButtons, List <rms_rolemanus> listRoleColumns, List <v_rolemanubuttons> listRoleMenuButtons) { string menus = "\"children\":["; List <rms_menus> list = listAll.FindAll(p => p.parentmanuid.Equals(SonItem.id)); if (list != null && list.Count > 0) { for (int i = 0; i < list.Count; i++) { menus += "{ \"MenuId\":\"" + list[i].id + "\","; menus += string.Format(" \"Name\":\"{0}\",", list[i].manuname); menus += string.Format(" \"iconCls\":\"{0}\",", list[i].icon); string ControlId_Browse = "0"; rms_rolemanus rcItem = listRoleColumns.Find(p => p.manuid.Equals(list[i].id)); if (rcItem != null) { ControlId_Browse = "1";//如果存在 } menus += string.Format(" \"ControlId_Browse\":\"{0}\",", ControlId_Browse); foreach (rms_buttons dd in listControlButtons)//添加列的数据 { string Ishave = "0"; v_rolemanubuttons rmbItem = listRoleMenuButtons.Find(p => p.id.Equals(dd.id) && p.manuid.Equals(list[i].id)); if (rmbItem != null) { Ishave = "1";//如果角色有此按钮存在 } menus += string.Format("\"ControlId_{0}\":\"{1}\",", dd.id, Ishave); } menus += GetSonTreeManu(listAll, list[i], listControlButtons, listRoleColumns, listRoleMenuButtons);//添加children menus += "},"; } menus = menus.Substring(0, menus.Length - 1); } menus = menus + "]"; return(menus); }
public string SaveRoleOP(string RoleManus, string RoleManuButtons, string RoleId) { RMS_RoleManusService.Instance.GetDatabase().BeginTransaction(); //事务开始 RMS_RoleManuButtonsService.Instance.GetDatabase().BeginTransaction(); //事务开始 RMS_RoleService.Instance.GetDatabase().BeginTransaction(); //事务开始 try { List <string> manu = RoleManus.Split('_').ToList(); int res = 0; int f = RMS_RoleManusService.Instance.DeleteW(" roleid='" + RoleId + "'"); for (int i = 0; i < manu.Count; i++) { if (!string.IsNullOrEmpty(manu[i])) { rms_rolemanus item = new rms_rolemanus(); //item.id = Guid.NewGuid().ToString(); item.roleid = RoleId; item.manuid = int.Parse(manu[i]); RMS_RoleManusService.Instance.Insert(item); res++; } } List <string> ManuButtons = RoleManuButtons.Split('_').ToList(); int ff = RMS_RoleManuButtonsService.Instance.DeleteW(" roleid='" + RoleId + "'"); for (int i = 0; i < ManuButtons.Count; i++) { rms_rolemanubuttons item = new rms_rolemanubuttons(); //item.id = Guid.NewGuid().ToString(); string[] data = ManuButtons[i].Split(':'); if (!string.IsNullOrEmpty(data[0]) && !string.IsNullOrEmpty(data[1])) { item.roleid = RoleId; string sql = " manuid=" + data[0] + " and buttonid=" + data[1] + ""; rms_menubuttons bItem = RMS_MenuButtonsService.Instance.SingleW(sql); if (bItem != null) { item.menubuttonsid = bItem.id.ToString(); } RMS_RoleManuButtonsService.Instance.Insert(item); res++; } } bool isSucces = true;//操作是否成功 //if (res == manu.Count + ManuButtons.Count) //{ // #region 生成权限 json // bool ies = RDBiz.SetJurisdiction(RoleId);//保存 权限json // if (ies) // { // isSucces = true; // } // else // { // isSucces = false; // } // #endregion //} //else //{ // isSucces = false; //} if (isSucces) //是否成功 { RMS_RoleManusService.Instance.GetDatabase().CompleteTransaction(); //事务完成 RMS_RoleManuButtonsService.Instance.GetDatabase().CompleteTransaction(); //事务完成 RMS_RoleService.Instance.GetDatabase().CompleteTransaction(); //事务完成 bool ies = RMS_RoleService.Instance.SetJurisdiction(RoleId); //保存 权限json return("ok"); } else { RMS_RoleManusService.Instance.GetDatabase().AbortTransaction(); //事务回滚 RMS_RoleManuButtonsService.Instance.GetDatabase().AbortTransaction(); //事务回滚 RMS_RoleService.Instance.GetDatabase().AbortTransaction(); //事务回滚 return("Nok"); } } catch (Exception ex) { RMS_RoleManusService.Instance.GetDatabase().AbortTransaction(); //事务回滚 RMS_RoleManuButtonsService.Instance.GetDatabase().AbortTransaction(); //事务回滚 RMS_RoleService.Instance.GetDatabase().AbortTransaction(); //事务回滚 return("Nok"); } }