public String Update(string subList, int myrole_id, int role_id) { string[] list = subList.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries); if (list == null || list.Length == 0) { return("noselect"); } //查询出当前管理员所管理的科目 DataTable dtRoleSub = GetManagerSubjectByCache(myrole_id); if (dtRoleSub.Rows.Count == 0) { return("nopower"); } //查询传入的科目是否有不包含在当前管理员的科目中的 bool isContain = false; foreach (string sub_id in list) { isContain = false; int subject_id = WebUtility.FilterParam(sub_id); if (subject_id == 0) { return("selecterror"); } foreach (DataRow dr in dtRoleSub.Rows) { if ((int)dr["Subject_id"] == subject_id) { isContain = true; break; } } if (!isContain) { return("nopower"); } } //判断是否有管理该角色的权限 DataTable dtRole = new BLL.sys_role().GetDataTableByCache(); Common.Tree.RoleTree tree = new Common.Tree.RoleTree(dtRole, 0, "Role_parent_id", "Role_id"); tree.Creat(); if (!tree.isParent(myrole_id, role_id)) { return("nopower"); } Model.role_vs_subject modelrvs = new Model.role_vs_subject(); modelrvs.role_id = role_id; modelrvs.sub_list = subList; if (Exists(role_id)) { if (Update(modelrvs)) { return("success"); } else { return("error"); } } else { if (Add(modelrvs)) { return("success"); } else { return("error"); } } }
/// <summary> /// 根据角色ID取角色详细 /// </summary> /// <param name="role_id"></param> /// <returns></returns> public DataTable GetList(int Role_id, int set_role_id) { //0 角色 1 当前角色管理的科目 2要修改的角色管理的科目 DataSet ds = dal.GetList(Role_id, set_role_id); if (ds.Tables[0].Rows.Count == 0) { return(null); } int row2Len = ds.Tables[2].Rows.Count; Common.Tree.RoleTree tree = new Common.Tree.RoleTree(ds.Tables[1], "Subject_parent", "Subject_id", "Subject_title"); Common.Tree.Node[] nodes = tree.CreateUnknowRootTree(); StringBuilder sb = new StringBuilder(); sb.Append("["); int len = 0; foreach (int index in nodes[0].Child) { if (len > 0) { sb.Append(","); } sb.Append("{").Append("\"id\":").Append(nodes[index].Weight).Append(",\"text\":\"").Append(nodes[index].Name).Append("\",\"state\":\"open\""); if (row2Len > 0) { DataRow[] drs = ds.Tables[2].Select("Subject_id=" + nodes[index].Weight); if (drs.Length > 0) { sb.Append(",\"checked\":true"); } } if (nodes[index].Child.Count > 0) { sb.Append(",\"children\":["); RecursiveSetRBJson(sb, nodes, index, ds.Tables[2], row2Len); sb.Append("]"); } sb.Append("}"); len++; } sb.Append("]"); DataTable outtable = new DataTable("table"); outtable.Columns.Add(new DataColumn("dtrole", typeof(DataTable))); outtable.Columns.Add(new DataColumn("subjson", typeof(string))); DataRow dr = outtable.NewRow(); dr[0] = ds.Tables[0].Copy(); if (sb.Length < 3) { dr[1] = "nodata"; } else { dr[1] = sb.ToString(); } outtable.Rows.Add(dr); return(outtable); }