示例#1
0
        public string GetSysScopeAuthorize()
        {
            try
            {
                if (string.IsNullOrWhiteSpace(Request.Params["scopeId"]))
                {
                    return(string.Empty);
                }

                string scopeId = Request.Params["scopeId"];

                SysScope scope = SysScopeServices.QuerySysScopeByRecordId(scopeId);
                if (scope == null)
                {
                    return(string.Empty);
                }

                StringBuilder strTree = new StringBuilder();
                strTree.Append("[{\"id\":\"" + scope.ASID + "\",");
                strTree.Append("\"attributes\":{\"type\":0},");
                strTree.Append("\"text\":\"" + scope.ASName + "[作用域]\"");

                List <SysScopeAuthorize> scopeAuthorizes = SysScopeAuthorizeServices.QuerySysScopeAuthorizeByScopeId(scope.ASID)
                                                           .Where(p => p.ASType == ASType.Village).ToList();

                List <BaseCompany> compamys = CompanyServices.QueryCompanyAndSubordinateCompany(GetCurrentUserCompanyId);
                if (compamys.Count == 0)
                {
                    return(string.Empty);
                }

                var list = VillageServices.QueryVillageByCompanyIds(compamys.Select(p => p.CPID).ToList());
                if (list.Count > 0)
                {
                    strTree.Append(",\"children\":[");
                }

                int i = 1;
                foreach (var item in list)
                {
                    string      villageName = item.VName;
                    BaseCompany company     = compamys.FirstOrDefault(p => p.CPID == item.CPID);
                    if (company != null)
                    {
                        villageName = string.Format("{0}【{1}】", item.VName, company.CPName);
                    }
                    strTree.Append("{\"id\":\"" + scope.ASID + "_" + item.VID + "\",");
                    strTree.Append("\"attributes\":{\"type\":1},");
                    strTree.Append("\"text\":\"" + villageName + "\"");
                    if (scopeAuthorizes != null && scopeAuthorizes.Exists(p => p.TagID == item.VID))
                    {
                        strTree.Append(",\"checked\":true");
                    }

                    strTree.Append("}");
                    if (i != list.Count())
                    {
                        strTree.Append(",");
                    }
                    i++;
                }
                if (list.Count > 0)
                {
                    strTree.Append("]");
                }

                strTree.Append("}]");
                return(strTree.ToString());
            }
            catch (MyException ex)
            {
                return(string.Empty);
            }
            catch (Exception ex)
            {
                ExceptionsServices.AddExceptions(ex, "作用域授权时获取小区信息失败");
                return(string.Empty);
            }
        }