/// <summary> /// Вычленяет из кода часть, соответствующую уровню /// </summary> public static string CodePart(this GeoLevelType lvl, string code) { StringBuilder sb = new StringBuilder(code); if (sb.Length == 19) { return(sb.ToString(lvl.Start(), lvl.Len())); } return(string.Empty); }
public static int Len(this GeoLevelType lvl) { switch (lvl) { case GeoLevelType.State: return(2); case GeoLevelType.Region: case GeoLevelType.City: case GeoLevelType.Place: return(3); case GeoLevelType.Street: case GeoLevelType.Building: return(4); } return(0); }
/// <summary> /// Разбор уровней с региона по улицу. /// Формат следующий: имя пробел сокр.акроним точка /// </summary> /// <param name="s"></param> /// <param name="lvl"></param> /// <returns></returns> private bool ParseLvl14(string s, GeoLevelType lvl) { if (string.IsNullOrEmpty(s)) { return(false); } if (lvl == GeoLevelType.State) { return(ParseLvl0(s)); } Match m = Lvl14Rx.Match(s); string name = m.Groups["Name"].Value; string acronym = m.Groups["Acronym"].Value; var cmd = DbHelper.CreateCommand("select * from tblKLADR where GeoType=@lvl and Name=@name and AcrShortName=@acr") .AddParameter("@name", name) .AddParameter("@lvl", lvl) .AddParameter("@acr", acronym); var cutCondition = currentFoundState.Where(point => point.Template.ParentID == -1).Select(point => GeoLevelType.State.CodePart(point.FoundGeo.Code)); if (!Utils.IsCollectionEmpty(cutCondition)) { cmd.CommandText = cmd.CommandText + " and left(Code,2)=@state_code"; cmd.ExpandParameterToList <string>("@state_code", cutCondition); } var founded = cmd.Select <ObjGeo>().ToList(); var foundAcronym = new List <string>(); foreach (var geo in founded) { if (!foundAcronym.Contains(geo.AcronymName)) { foundAcronym.Add(geo.AcronymName); } } currentFoundState.AddRange( AddressParser.CloseLevelFound( currentFoundState.Where(p => p.ChildEndPoints.Count() == 0) , founded, foundAcronym, new AddressTemplate((int)lvl, (int)lvl - 1, 0, (int)lvl), s)); return(currentFoundState.Any(point => point.FoundGeo != null && point.FoundGeo.Level == lvl)); }
//SS RRR CCC PPP UUUU DDDD //00 000 000 001 1111 1111 //01 234 567 890 1234 5678 public static int Start(this GeoLevelType lvl) { switch (lvl) { case GeoLevelType.State: return(0); case GeoLevelType.Region: return(2); case GeoLevelType.City: return(5); case GeoLevelType.Place: return(8); case GeoLevelType.Street: return(11); case GeoLevelType.Building: return(15); } return(0); }
/// <summary> /// Разбор уровней с региона по улицу. /// Формат следующий: имя пробел сокр.акроним точка /// </summary> /// <param name="s"></param> /// <param name="lvl"></param> /// <returns></returns> private bool ParseLvl14(string s, GeoLevelType lvl) { if (string.IsNullOrEmpty(s)) return false; if (lvl == GeoLevelType.State) return ParseLvl0(s); Match m = Lvl14Rx.Match(s); string name = m.Groups["Name"].Value; string acronym = m.Groups["Acronym"].Value; var cmd = DbHelper.CreateCommand("select * from tblKLADR where GeoType=@lvl and Name=@name and AcrShortName=@acr") .AddParameter("@name", name) .AddParameter("@lvl", lvl) .AddParameter("@acr", acronym); var cutCondition = currentFoundState.Where(point => point.Template.ParentID == -1).Select(point => GeoLevelType.State.CodePart(point.FoundGeo.Code)); if (!Utils.IsCollectionEmpty(cutCondition)) { cmd.CommandText = cmd.CommandText + " and left(Code,2)=@state_code"; cmd.ExpandParameterToList<string>("@state_code", cutCondition); } var founded = cmd.Select<ObjGeo>().ToList(); var foundAcronym = new List<string>(); foreach (var geo in founded) { if (!foundAcronym.Contains(geo.AcronymName)) foundAcronym.Add(geo.AcronymName); } currentFoundState.AddRange( AddressParser.CloseLevelFound( currentFoundState.Where(p => p.ChildEndPoints.Count() == 0) , founded, foundAcronym, new AddressTemplate((int)lvl, (int)lvl - 1, 0, (int)lvl), s)); return currentFoundState.Any(point => point.FoundGeo != null && point.FoundGeo.Level == lvl); }