Example #1
0
        internal static ResolveRating EnsureParentChildConsistency(ObjGeo parent, ObjGeo child)
        {
            if (parent.Level >= child.Level)
            {
                throw new ArgumentOutOfRangeException("parent.Level >= child.Level");
            }

            ResolveRating ret       = ResolveRating.Clear;
            string        childCode = child.Level.CodeTrim(child.Code);

            if (childCode.StartsWith((child.Level - 1).CodeTrim(parent.Code)))
            {
                return(ret);
            }

            if (childCode.StartsWith(parent.Level.CodeTrim(parent.Code)))
            {
                ret |= ResolveRating.Shortage;
                return(ret);
            }

            if (parent.Level.CodePart(child.Code).All(ch => ch == '0'))
            {
                ret |= ResolveRating.Excess;
            }
            else
            {
                ret |= ResolveRating.NoMatch;
            }

            return(ret);
        }
Example #2
0
        internal static IEnumerable <FindEndPoint> CloseLevelFound(IEnumerable <FindEndPoint> parents, IEnumerable <ObjGeo> foundList, IEnumerable <string> foundAcronym, AddressTemplate tmpl, string restTail)
        {
            var ret = new List <FindEndPoint>();

            if (foundList != null)
            {
                foreach (var geo in foundList)
                {
                    ResolveRating rating = foundAcronym != null && foundAcronym.Any(s => s.Equals(geo.AcronymName, StringComparison.InvariantCultureIgnoreCase)) ? ResolveRating.Clear : ResolveRating.AcronymNotFound;

                    if (parents == null)
                    {
                        var point = new FindEndPoint()
                        {
                            FoundGeo = geo, ResolveRating = rating, RestTail = restTail
                        };
                        ret.Add(point);
                    }
                    else
                    {
                        foreach (var point in parents)
                        {
                            rating |= EnsureParentChildConsistency(point.FoundGeo, geo);
                            if (rating < ResolveRating.Excess)
                            {
                                ObjGeo actualGeo = null;
                                //51 Признак актуальности - в актуальное , т.е. в 0
                                if (geo.Actual == 51)
                                {
                                    actualGeo = DbHelper.Select <ObjGeo>("select top 1 * from tblKLADR where OriginalCode in (select NewCode from tbl_KLADR_AltNames where OldCode=@code and Lvl=@lvl)"
                                                                         , DbHelper.CreateParameter("@code", geo.OriginalCode.Substring(0, geo.OriginalCode.Length - 2) + "00")
                                                                         , DbHelper.CreateParameter("@lvl", (int)geo.Level + 1)).FirstOrDefault();
                                }

                                var newPoint = new FindEndPoint()
                                {
                                    FoundGeo = actualGeo ?? geo, ParentEndPoint = point, ResolveRating = rating | point.ResolveRating, RestTail = restTail
                                };
                                ret.Add(newPoint);
                            }
                        }
                    }
                }
            }

            ret.ForEach(point => point.Template = tmpl);
            return(ret);
        }