/// <summary>
 /// 加载角色
 /// <param name="ObjectId">对象主键</param>
 /// <param name="Category">对象分类:1-部门2-角色3-岗位4-群组</param>
 /// </summary>
 /// <returns></returns>
 public ActionResult ScopeRoleList(string ObjectId, string Category)
 {
     string ModuleId = "cef74b80-24a5-4d77-9ede-bbbc75cdb431";
     DataTable DataList = base_datascopepermissionbll.GetScopeRoleList(ModuleId, ObjectId, Category);
     List<TreeJsonEntity> TreeList = new List<TreeJsonEntity>();
     if (!DataHelper.IsExistRows(DataList))
     {
         foreach (DataRow row in DataList.Rows)
         {
             TreeJsonEntity tree = new TreeJsonEntity();
             string RoleId = row["roleid"].ToString();
             bool hasChildren = false;
             DataTable childnode = DataHelper.GetNewDataTable(DataList, "parentid='" + RoleId + "'");
             if (childnode.Rows.Count > 0)
             {
                 hasChildren = true;
             }
             else
             {
                 if (row["sort"].ToString() == "Company")
                 {
                     continue;
                 }
             }
             if (row["parentid"].ToString() != "0")
             {
                 tree.checkstate = row["objectid"].ToString() != "" ? 1 : 0;
                 tree.showcheck = true;
             }
             tree.id = RoleId;
             tree.text = row["fullname"].ToString();
             tree.value = row["code"].ToString();
             tree.parentId = row["parentid"].ToString();
             tree.Attribute = "Type";
             tree.AttributeValue = row["sort"].ToString();
             tree.isexpand = true;
             tree.complete = true;
             tree.hasChildren = hasChildren;
             if (row["parentid"].ToString() == "0")
             {
                 tree.img = "/Content/Images/Icon16/molecule.png";
             }
             else if (row["sort"].ToString() == "Company")
             {
                 tree.img = "/Content/Images/Icon16/hostname.png";
             }
             else if (row["sort"].ToString() == "Roles")
             {
                 tree.img = "/Content/Images/Icon16/role.png";
             }
             TreeList.Add(tree);
         }
     }
     return Content(TreeList.TreeToJson());
 }
 /// <summary>
 /// 加载岗位
 /// <param name="ObjectId">对象主键</param>
 /// <param name="Category">对象分类:1-部门2-角色3-岗位4-群组</param>
 /// </summary>
 /// <returns></returns>
 public ActionResult ScopeUserList(string ObjectId, string Category)
 {
     string ModuleId = "58e86c4c-8022-4d30-95d5-b3d0eedcc878";
     DataTable DataList = base_datascopepermissionbll.GetScopeUserList(ModuleId, ObjectId, Category);
     List<TreeJsonEntity> TreeList = new List<TreeJsonEntity>();
     if (!DataHelper.IsExistRows(DataList))
     {
         foreach (DataRow row in DataList.Rows)
         {
             TreeJsonEntity tree = new TreeJsonEntity();
             string PostId = row["id"].ToString();
             bool hasChildren = false;
             DataTable childnode = DataHelper.GetNewDataTable(DataList, "parentid='" + PostId + "'");
             if (childnode.Rows.Count > 0)
             {
                 hasChildren = true;
             }
             else
             {
                 if (row["sort"].ToString() == "Company" || row["sort"].ToString() == "Department")
                 {
                     continue;
                 }
             }
             if (row["parentid"].ToString() != "0")
             {
                 tree.checkstate = row["objectid"].ToString() != "" ? 1 : 0;
                 tree.showcheck = true;
             }
             tree.id = PostId;
             tree.text = row["fullname"].ToString();
             tree.value = row["code"].ToString();
             tree.parentId = row["parentid"].ToString();
             tree.isexpand = true;
             tree.complete = true;
             tree.hasChildren = hasChildren;
             if (row["parentid"].ToString() == "0")
             {
                 tree.img = "/Content/Images/Icon16/molecule.png";
             }
             else if (row["sort"].ToString() == "Company")
             {
                 tree.img = "/Content/Images/Icon16/hostname.png";
             }
             else if (row["sort"].ToString() == "Department")
             {
                 tree.img = "/Content/Images/Icon16/chart_organisation.png";
             }
             else if (row["sort"].ToString() == "User")
             {
                 if (row["gender"].ToString() == "男")
                 {
                     tree.img = "/Content/Images/Icon16/user_green.png";
                 }
                 else if (row["gender"].ToString() == "女")
                 {
                     tree.img = "/Content/Images/Icon16/user_female.png";
                 }
             }
             TreeList.Add(tree);
         }
     }
     return Content(TreeList.TreeToJson());
 }
 /// <summary>
 /// 加载公司
 /// <param name="ObjectId">对象主键</param>
 /// <param name="Category">对象分类:1-部门2-角色3-岗位4-群组</param>
 /// </summary>
 /// <returns></returns>
 public ActionResult ScopeCompanyList(string ObjectId, string Category)
 {
     string ModuleId = "b29cabd8-ffb6-4d34-9d08-ee1dba2b5b6b";
     DataTable DataList = base_datascopepermissionbll.GetScopeCompanyList(ModuleId, ObjectId, Category);
     List<TreeJsonEntity> TreeList = new List<TreeJsonEntity>();
     if (!DataHelper.IsExistRows(DataList))
     {
         foreach (DataRow item in DataList.Rows)
         {
             bool hasChildren = false;
             DataTable childnode = DataHelper.GetNewDataTable(DataList, "parentid = '" + item["companyid"].ToString() + "'");
             if (childnode.Rows.Count > 0)
             {
                 hasChildren = true;
             }
             TreeJsonEntity tree = new TreeJsonEntity();
             tree.id = item["companyid"].ToString();
             tree.text = item["fullname"].ToString();
             tree.value = item["code"].ToString();
             tree.checkstate = item["objectid"].ToString() != "" ? 1 : 0;
             tree.showcheck = true;
             tree.isexpand = true;
             tree.complete = true;
             tree.hasChildren = hasChildren;
             tree.parentId = item["parentid"].ToString();
             if (item["parentid"].ToString() == "0")
             {
                 tree.img = "/Content/Images/Icon16/molecule.png";
             }
             else
             {
                 tree.img = "/Content/Images/Icon16/hostname.png";
             }
             TreeList.Add(tree);
         }
     }
     else
     {
         TreeJsonEntity tree = new TreeJsonEntity();
         tree.id = "";
         tree.text = "<span style='color:red'>没有找到您要的相关数据...</span>";
         tree.value = "";
         tree.isexpand = true;
         tree.complete = true;
         tree.hasChildren = false;
         tree.parentId = "0";
         tree.img = "/Content/Images/Icon32/database_red.png";
         TreeList.Add(tree);
     }
     return Content(TreeList.TreeToJson());
 }
 /// <summary>
 /// 加载岗位
 /// <param name="ObjectId">对象主键</param>
 /// <param name="Category">对象分类:1-部门2-角色3-岗位4-群组</param>
 /// </summary>
 /// <returns></returns>
 public ActionResult ScopePostList(string ObjectId, string Category)
 {
     string ModuleId = "eb0c4d65-4757-4892-b2e9-35882704e592";
     DataTable DataList = base_datascopepermissionbll.GetScopePostList(ModuleId, ObjectId, Category);
     List<TreeJsonEntity> TreeList = new List<TreeJsonEntity>();
     if (!DataHelper.IsExistRows(DataList))
     {
         foreach (DataRow row in DataList.Rows)
         {
             TreeJsonEntity tree = new TreeJsonEntity();
             string PostId = row["id"].ToString();
             bool hasChildren = false;
             DataTable childnode = DataHelper.GetNewDataTable(DataList, "parentid='" + PostId + "'");
             if (childnode.Rows.Count > 0)
             {
                 hasChildren = true;
             }
             else
             {
                 if (row["sort"].ToString() == "Company" || row["sort"].ToString() == "Department")
                 {
                     continue;
                 }
             }
             if (row["parentid"].ToString() != "0")
             {
                 tree.checkstate = row["objectid"].ToString() != "" ? 1 : 0;
                 tree.showcheck = true;
             }
             tree.id = PostId;
             tree.text = row["fullname"].ToString();
             tree.value = row["code"].ToString();
             tree.parentId = row["parentid"].ToString();
             tree.isexpand = true;
             tree.complete = true;
             tree.hasChildren = hasChildren;
             if (row["parentid"].ToString() == "0")
             {
                 tree.img = "/Content/Images/Icon16/molecule.png";
             }
             else if (row["sort"].ToString() == "Company")
             {
                 tree.img = "/Content/Images/Icon16/hostname.png";
             }
             else if (row["sort"].ToString() == "Department")
             {
                 tree.img = "/Content/Images/Icon16/chart_organisation.png";
             }
             else if (row["sort"].ToString() == "Post")
             {
                 tree.img = "/Content/Images/Icon16/outlook_new_meeting.png";
             }
             TreeList.Add(tree);
         }
     }
     return Content(TreeList.TreeToJson());
 }
 /// <summary>
 /// 加载模块 返回树JSON
 /// </summary>
 /// <param name="ObjectId">对象主键</param>
 /// <param name="Category">对象分类:1-部门2-角色3-岗位4-群组</param>
 /// <returns></returns>
 public ActionResult ModuleTree(string ObjectId, string Category)
 {
     DataTable dt = base_modulepermissionbll.GetList(ObjectId, Category);
     List<TreeJsonEntity> TreeList = new List<TreeJsonEntity>();
     if (!DataHelper.IsExistRows(dt))
     {
         foreach (DataRow item in dt.Rows)
         {
             string ModuleId = item["moduleid"].ToString();
             bool hasChildren = false;
             DataTable childnode = DataHelper.GetNewDataTable(dt, "ParentId = '" + ModuleId + "'");
             if (childnode.Rows.Count > 0)
             {
                 hasChildren = true;
             }
             TreeJsonEntity tree = new TreeJsonEntity();
             tree.id = item["moduleid"].ToString();
             tree.text = item["fullname"].ToString();
             tree.value = item["moduleid"].ToString();
             tree.checkstate = item["objectid"].ToString() != "" ? 1 : 0;
             tree.showcheck = true;
             tree.isexpand = true;
             tree.complete = true;
             tree.hasChildren = hasChildren;
             tree.parentId = item["parentid"].ToString();
             tree.img = item["icon"].ToString() != null ? "/Content/Images/Icon16/" + item["icon"].ToString() : item["icon"].ToString();
             TreeList.Add(tree);
         }
     }
     return Content(TreeList.TreeToJson());
 }
 /// <summary>
 /// 查看拥有视图权限 返回树JSON
 /// </summary>
 /// <param name="ObjectId">对象主键</param>
 /// <returns></returns>
 public ActionResult LookViewPermission(string ObjectId)
 {
     //如果ObjectId为空。自动获取当前登录用户拥有权限
     if (string.IsNullOrEmpty(ObjectId))
     {
         ObjectId = ManageProvider.Provider.Current().ObjectId;
     }
     DataTable dt = base_viewpermissionbll.GetViewPermission(ObjectId);
     List<TreeJsonEntity> TreeList = new List<TreeJsonEntity>();
     if (!DataHelper.IsExistRows(dt))
     {
         foreach (DataRow item in dt.Rows)
         {
             string id = item["id"].ToString();
             bool hasChildren = false;
             DataTable childnode = DataHelper.GetNewDataTable(dt, "ParentId = '" + id + "'");
             if (childnode.Rows.Count > 0)
             {
                 hasChildren = true;
             }
             TreeJsonEntity tree = new TreeJsonEntity();
             tree.id = item["id"].ToString();
             tree.text = item["fullname"].ToString();
             tree.value = item["id"].ToString();
             tree.isexpand = true;
             tree.complete = true;
             tree.hasChildren = hasChildren;
             tree.parentId = item["parentid"].ToString();
             tree.img = item["icon"].ToString() != "" ? "/Content/Images/Icon16/" + item["icon"].ToString() : "/Content/Images/Icon16/tag_blue.png";
             TreeList.Add(tree);
         }
     }
     return Content(TreeList.TreeToJson());
 }
 /// <summary>
 /// 查看拥有按钮权限 返回树JSON
 /// </summary>
 /// <param name="ObjectId">对象主键</param>
 /// <returns></returns>
 public ActionResult LookButtonePermission(string ObjectId)
 {
     //如果ObjectId为空。自动获取当前登录用户拥有权限
     if (string.IsNullOrEmpty(ObjectId))
     {
         ObjectId = ManageProvider.Provider.Current().ObjectId;
     }
     DataTable dt = base_buttonpermissionbll.GetButtonePermission(ObjectId);
     List<TreeJsonEntity> TreeList = new List<TreeJsonEntity>();
     if (!DataHelper.IsExistRows(dt))
     {
         foreach (DataRow item in dt.Rows)
         {
             string text = "";
             if (item["Sort"].ToString() == "按钮")
             {
                 if (item["Category"].ToString() == "1")
                 {
                     text = item["fullname"].ToString() + "(工具栏)";
                 }
                 else if (item["Category"].ToString() == "2")
                 {
                     text = item["fullname"].ToString() + "(右击栏)";
                 }
             }
             else
             {
                 text = item["fullname"].ToString();
             }
             string id = item["id"].ToString();
             bool hasChildren = false;
             DataTable childnode = DataHelper.GetNewDataTable(dt, "ParentId = '" + id + "'");
             if (childnode.Rows.Count > 0)
             {
                 hasChildren = true;
             }
             TreeJsonEntity tree = new TreeJsonEntity();
             tree.id = item["id"].ToString();
             tree.text = text;
             tree.value = item["id"].ToString();
             tree.isexpand = true;
             tree.complete = true;
             tree.hasChildren = hasChildren;
             tree.parentId = item["parentid"].ToString();
             tree.img = item["icon"].ToString() != null ? "/Content/Images/Icon16/" + item["icon"].ToString() : item["icon"].ToString();
             TreeList.Add(tree);
         }
     }
     return Content(TreeList.TreeToJson());
 }
 /// <summary>
 /// 加载无限树菜单
 /// </summary>
 /// <returns></returns>
 public ActionResult LoadTreeMenu(string ModuleId)
 {
     string ObjectId = ManageProvider.Provider.Current().ObjectId;
     List<Base_Module> list = base_modulepermissionbll.GetModuleList(ObjectId).FindAll(t => t.Enabled == 1);
     List<TreeJsonEntity> TreeList = new List<TreeJsonEntity>();
     foreach (Base_Module item in list)
     {
         TreeJsonEntity tree = new TreeJsonEntity();
         bool hasChildren = false;
         List<Base_Module> childnode = list.FindAll(t => t.ParentId == item.ModuleId);
         if (childnode.Count > 0)
         {
             hasChildren = true;
         }
         if (item.Category == "页面")
         {
             tree.Attribute = "Location";
             tree.AttributeValue = item.Location;
         }
         tree.id = item.ModuleId;
         tree.text = item.FullName;
         tree.value = item.ModuleId;
         tree.isexpand = false;
         tree.complete = true;
         tree.hasChildren = hasChildren;
         tree.parentId = item.ParentId;
         tree.img = item.Icon != null ? "/Content/Images/Icon16/" + item.Icon : item.Icon;
         TreeList.Add(tree);
     }
     return Content(TreeList.TreeToJson(ModuleId));
 }
 /// <summary>
 /// 快捷方式 返回菜单模块树JSON
 /// </summary>
 /// <returns></returns>
 public ActionResult ShortcutsModuleTreeJson()
 {
     Base_ShortcutsBll base_shortcutsbll = new Base_ShortcutsBll();
     string UserId = ManageProvider.Provider.Current().UserId;
     List<Base_Module> ShortcutList = base_shortcutsbll.GetShortcutList(UserId);
     string ObjectId = ManageProvider.Provider.Current().ObjectId;
     List<Base_Module> list = base_modulepermissionbll.GetModuleList(ObjectId).FindAll(t => t.Enabled == 1);
     List<TreeJsonEntity> TreeList = new List<TreeJsonEntity>();
     foreach (Base_Module item in list)
     {
         TreeJsonEntity tree = new TreeJsonEntity();
         tree.id = item.ModuleId;
         tree.text = item.FullName;
         tree.value = item.ModuleId;
         if (item.Category == "页面")
         {
             tree.checkstate = ShortcutList.FindAll(t => t.ModuleId == item.ModuleId).Count == 0 ? 0 : 1;
             //tree.checkstate = item["objectid"].ToString() != "" ? 1 : 0;
             tree.showcheck = true;
         }
         tree.isexpand = true;
         tree.complete = true;
         tree.hasChildren = list.FindAll(t => t.ParentId == item.ModuleId).Count > 0 ? true : false;
         tree.parentId = item.ParentId;
         tree.img = item.Icon != null ? "/Content/Images/Icon16/" + item.Icon : item.Icon;
         TreeList.Add(tree);
     }
     return Content(TreeList.TreeToJson());
 }