Exemple #1
0
        public override string ToString()
        {
            var ev = Extravalue;

            if (ev == null)
            {
                ev = new ExtraValue();
            }
            switch (Type)
            {
            case "Bit":
                if (Extravalue == null)
                {
                    if (!Standard)
                    {
                        return("Click to edit");
                    }
                    else
                    {
                        return("false");
                    }
                }
                return(ev.BitValue.ToString());

            case "Code":
                return(ev.StrValue);

            case "Text":
            case "Text2":
            case "Data":
                return((ev.Data ?? "").Trim());

            case "Attr":
                return("Attributes");

            case "Date":
                return(ev.DateValue.FormatDate());

            case "Bits":
            {
                var q = from e in Model.ListExtraValues()
                        where e.BitValue == true
                        where e.Id == Id
                        where Codes.Contains(e.Field)
                        select NoPrefix(e.Field);

                return(string.Join("\n", q));
            }

            case "Int":
                return(ev.IntValue.ToString2("d"));
            }
            return("");
        }
Exemple #2
0
 public void AllCodesUniqueTest()
 {
     Assert.IsTrue(Codes.Contains(0));
     Assert.IsTrue(Codes.Contains(1));
     Assert.IsTrue(Codes.Contains(2));
     //Assert.IsTrue(Codes.Contains(1000));
     //Assert.IsTrue(Codes.Contains(1001));
     //Assert.IsTrue(Codes.Contains(1002));
     //Assert.IsTrue(Codes.Contains(2002));
     Assert.IsTrue(Codes.Contains(3002));
     Assert.IsFalse(Codes.Contains(4002));
     Assert.IsFalse(Codes.Contains(5002));
     Assert.IsFalse(Codes.Contains(6002));
 }
 internal void PrepareNotifications(int contentId, int[] articleIds, string[] codes, bool disableNotifications = false)
 {
     Notifications = new Notification[0];
     ArticleIds    = new int[0];
     Articles      = new Article[0];
     ValidateCodes(codes);
     Codes = codes.Distinct().ToArray();
     if (!disableNotifications)
     {
         ContentId     = contentId;
         SiteId        = ContentRepository.GetSiteId(contentId);
         Notifications = NotificationRepository.GetContentNotifications(contentId, codes).ToArray();
         if (Notifications.Any())
         {
             ArticleIds = articleIds;
             if (!Codes.Contains(NotificationCode.Create) && ServiceNotifications.Any())
             {
                 Articles = GetArticles();
             }
         }
     }
 }
Exemple #4
0
 public bool Equals(Keys key)
 {
     return(Codes.Contains(key));
 }
Exemple #5
0
        public async Task <JsonResult> SavePermission(string UserName, ICollection <int> Codes)
        {
            if (Codes == null)
            {
                Codes = new List <int>();
            }
            try
            {
                ApplicationDbContext dbContext = HttpContext.GetOwinContext().Get <ApplicationDbContext>();
                ApplicationUser      user      = await UserManager.FindByEmailAsync(UserName);

                IEnumerable <SubCategory> currentSubMenus = user.CanAccessCategories;
                IEnumerable <SubCategory> menuToDelete    = from subMenu in currentSubMenus where !Codes.Contains(subMenu.Code) select subMenu;
                foreach (var m in menuToDelete.ToList())
                {
                    user.CanAccessCategories.Remove(m as SubMenu);
                }
                foreach (int code in Codes)
                {
                    if (currentSubMenus.Count(m => m.Code == code) == 0)
                    {
                        SubMenu menu = dbContext.Categories.Where(c => c.Code == code).First() as SubMenu;
                        user.CanAccessCategories.Add(menu);
                    }
                }
                int i = dbContext.SaveChanges();
                return(Json(new { result = i >= 0 }));
            }
            catch (Exception e)
            {
                return(Json(new { result = false, message = e.Message }));
            }
        }
        public static async Task <List <NatureAreaType> > Load(string connectionString, Codes codes)
        {
            const string natureAreaTypeCodeSql =
                @"SELECT nat.geometry_id AS NatureAreaId, nat.code AS Code, nat.fraction AS Percentage
FROM data.codes_geometry nat
WHERE nat.code LIKE 'NA-%' and nat.code not LIKE 'NA-BS%' and nat.code not LIKE 'NA-LKM%'
GROUP BY nat.geometry_id, nat.code, nat.fraction";

            IEnumerable <NatureAreaTypeDto> dtos = null;

            using (var conn = new NpgsqlConnection(connectionString))
            {
                conn.Open();

                dtos = await conn.QueryAsync <NatureAreaTypeDto>(natureAreaTypeCodeSql);
            }

            var dict = new Dictionary <string, NatureAreaType>();
            var natureAreaPercentages = new Dictionary <(int, string), NatureAreaPercentage>();

            foreach (var dto in dtos)
            {
                if (!codes.Contains(dto.Code))
                {
                    continue;
                }

                if (!dict.TryGetValue(dto.Code, out var natureAreaType))
                {
                    natureAreaType = new NatureAreaType(dto.Code, codes.GetCode(dto.Code).Name);

                    dict.Add(dto.Code, natureAreaType);
                }

                var key = (dto.NatureAreaId, dto.Code);

                if (natureAreaPercentages.TryGetValue(key, out var natureArea))
                {
                    double newPercentage = natureArea.Percentage + (dto.Percentage / 10);

                    if (newPercentage > 1)
                    {
                        Console.WriteLine($"{key.Code} {key.NatureAreaId} exceeds 1 as percentage.");
                    }
                    else
                    {
                        natureArea.Percentage = newPercentage;
                    }
                }
                else
                {
                    var natureAreaPercentage = new NatureAreaPercentage {
                        NatureAreaId = dto.NatureAreaId, Percentage = dto.Percentage / 10
                    };
                    natureAreaType.NatureAreas.Add(natureAreaPercentage);
                    natureAreaPercentages.Add(key, natureAreaPercentage);
                }
            }

            return(dict.Values.ToList());
        }
Exemple #7
0
        public static async Task <List <DescriptionVariable> > Load(string connectionString, Codes descriptionVariableCodes)
        {
            Console.WriteLine("Loading DescriptionVariables");

            const string descriptionVariableSql =
                @"SELECT bv.code AS DvCode, nomt.code AS NatCode, bv.geometry_id AS NatureAreaId, nomt.fraction AS NatureAreaPercentage
                    FROM data.codes_geometry bv, data.codes_geometry nomt
                    WHERE bv.geometry_id = nomt.geometry_id and bv.code like 'NA-BS%' and nomt.code like 'NA-%' and nomt.code NOT like 'NA-BS%' and nomt.code NOT like 'NA-LKM%'
                    GROUP BY bv.code, nomt.code, bv.geometry_id, nomt.fraction";

            IEnumerable <DescriptionVariableDto> descriptionVariableDtos;

            using (var conn = new NpgsqlConnection(connectionString))
            {
                conn.Open();

                descriptionVariableDtos = await conn.QueryAsync <DescriptionVariableDto>(descriptionVariableSql);
            }

            var dict        = new Dictionary <string, DescriptionVariable>();
            var natureAreas = new Dictionary <(string, int, string), NatureAreaIdTypePercentage>();

            foreach (var dto in descriptionVariableDtos)
            {
                var codes = dto.DvCode.Split(',', StringSplitOptions.RemoveEmptyEntries);

                //dto.DvCode = dto.DvCode.Remove(0,3);

                foreach (var code in codes)
                {
                    if (!descriptionVariableCodes.Contains(dto.DvCode.ToUpper()))
                    {
                        // Ignored code as it doesn't exist in the code file.
                        continue;
                    }

                    if (!dict.TryGetValue(dto.DvCode, out var descriptionVariable))
                    {
                        descriptionVariable = new DescriptionVariable(dto.DvCode, descriptionVariableCodes.GetCode(dto.DvCode).Name);

                        dict.Add(dto.DvCode, descriptionVariable);
                    }

                    var key = (dto.DvCode, dto.NatureAreaId, dto.NatCode);
                    // descriptionVariable.NatureAreas.FirstOrDefault(na => na.NatureAreaId == dto.NatureAreaId && na.NatureAreaTypeCode == dto.NatCode);

                    if (natureAreas.TryGetValue(key, out var natureArea))
                    {
                        double newPercentage = natureArea.NatureAreaPercentage + (dto.NatureAreaPercentage / 10);

                        if (newPercentage > 1)
                        {
                            Console.WriteLine($"{key.DvCode} {key.NatCode} {key.NatureAreaId} exceeds 1 as percentage.");
                        }
                        else
                        {
                            natureArea.NatureAreaPercentage = newPercentage;
                        }
                    }
                    else
                    {
                        natureArea = new NatureAreaIdTypePercentage
                        {
                            NatureAreaId         = dto.NatureAreaId,
                            NatureAreaTypeCode   = dto.NatCode,
                            NatureAreaPercentage = dto.NatureAreaPercentage / 10
                        };

                        descriptionVariable.NatureAreas.Add(natureArea);

                        natureAreas.Add(key, natureArea);
                    }
                }
            }

            Console.WriteLine("Finished loading DescriptionVariables");

            return(dict.Values.ToList());
        }
        internal void SendServiceNotifications()
        {
            if (!ServiceNotifications.Any())
            {
                return;
            }

            try
            {
                IEnumerable <ExternalNotificationModel> notificationQueue;
                if (Codes.Contains(NotificationCode.Delete))
                {
                    notificationQueue = from notification in ServiceNotifications
                                        join article in Articles on notification.ContentId equals article.ContentId
                                        select new ExternalNotificationModel
                    {
                        EventName = NotificationCode.Delete,
                        ArticleId = article.Id,
                        ContentId = ContentId,
                        SiteId    = SiteId,
                        Url       = notification.ExternalUrl,
                        OldXml    = GetXDocument(article).ToString(),
                        NewXml    = null
                    };
                }
                else if (Codes.Contains(NotificationCode.Create))
                {
                    notificationQueue = from notification in ServiceNotifications
                                        join article in GetArticles() on notification.ContentId equals article.ContentId
                                        select new ExternalNotificationModel
                    {
                        EventName = NotificationCode.Create,
                        ArticleId = article.Id,
                        ContentId = ContentId,
                        SiteId    = SiteId,
                        Url       = notification.ExternalUrl,
                        OldXml    = null,
                        NewXml    = GetXDocument(article).ToString()
                    };
                }
                else
                {
                    var oldArticles = Articles;
                    var newArticles = GetArticles();
                    notificationQueue = from notification in ServiceNotifications
                                        from code in Codes
                                        join oldArticle in oldArticles on notification.ContentId equals oldArticle.ContentId
                                        join newArticle in newArticles on oldArticle.Id equals newArticle.Id
                                        where
                                        notification.ForModify && code == NotificationCode.Update ||
                                        notification.ForFrontend && code == NotificationCode.Custom ||
                                        notification.ForStatusChanged && code == NotificationCode.ChangeStatus ||
                                        notification.ForStatusPartiallyChanged && code == NotificationCode.PartialChangeStatus ||
                                        notification.ForDelayedPublication && code == NotificationCode.DelayedPublication
                                        select new ExternalNotificationModel
                    {
                        EventName = code,
                        ArticleId = oldArticle.Id,
                        ContentId = ContentId,
                        SiteId    = SiteId,
                        Url       = notification.ExternalUrl,
                        OldXml    = GetXDocument(oldArticle).ToString(),
                        NewXml    = GetXDocument(newArticle).ToString()
                    };
                }

                new ExternalInterfaceNotificationService().Insert(notificationQueue);
            }
            catch (Exception ex)
            {
                HandleException(ex);
            }
        }
 /// <summary>
 /// 判断是否能翻译该语言
 /// </summary>
 /// <param name="code"></param>
 /// <returns></returns>
 public bool CanTranslate(string code)
 {
     return(Codes.Contains(code));
 }
Exemple #10
0
 /// <summary>
 /// Gets a value indicating whether the code item list contains a
 /// specific code.
 /// </summary>
 ///
 /// <param name="item">
 /// The code item to search for in the list.
 /// </param>
 ///
 /// <returns>
 /// <b>true</b> if the item is in the collection; otherwise, <b>false</b>.
 /// </returns>
 ///
 public bool Contains(CodedValue item)
 {
     return(Codes.Contains(item));
 }
Exemple #11
0
 public bool IsValid(string code)
 {
     return(Codes.Contains(code) == false);
 }
Exemple #12
0
 public bool Equals(Keys key)
 {
     return /*Codes.Contains(AnyKeyCode) || */ (Codes.Contains(key));
 }