Ejemplo n.º 1
0
 private void CustomReloadCollection(ICollection<FiasModelItem> collection, string sql, string parent)
 {
     collection.Clear();
     using (var transaction = connection.BeginTransaction())
     {
         using (var query = new DbQuery(connection, transaction))
         {
             query.SqlText = string.Format(sql, parent);
             query.ExecuteDataReader();
             while (query.DataReader.Read())
             {
                 var item = new FiasModelItem
                 {
                     Id = query.DataReader["id"].ToString(),
                     KladrId = query.DataReader["KLADR"].ToString(),
                     FullName = query.DataReader["full_name"].ToString(),
                     FormalName = query.DataReader["formal_name"].ToString(),
                     ScName = query.DataReader["SCNAME"].ToString(),
                     ShortName = query.DataReader["SOCRNAME"].ToString(),
                     Level = query.DataReader["ADDR_LEVEL"].ToString(),
                     IdDetail = query.DataReader["ID_DETAIL"].ToString(),
                     LiveStatus = query.DataReader["id_live_status"].ToString()
                 };
                 collection.Add(item);
             }
         }
     }
 }
Ejemplo n.º 2
0
        public void Open(string guid, string kladr)
        {
            connection.ConnectionString = ConnectionString;
            connection.Open();
            CustomReloadCollection(RegionCollection, FiasSql.RegionSql, null);

            var searchResult = new Dictionary<string, string>();
            using (var transaction = connection.BeginTransaction())
            {
                using (var query = new DbQuery(connection, transaction))
                {
                    query.SqlText = "select ID_REGION, ID_AUTO, ID_AREA, ID_CITY, ID_CTAR, ID_PLACE, ID_STREET, ID_HOUSE from PR_FIAS_EXTRACT(@ID_GUID, @ID_KLADR)";
                    query.Parameters.Add(query.GetNewParameter("ID_GUID", guid == string.Empty ? null : guid));
                    query.Parameters.Add(query.GetNewParameter("ID_KLADR", kladr == string.Empty ? null : kladr));
                    query.ExecuteDataReader();
                    if (query.DataReader.Read())
                    {
                        for (var i = 0; i < query.DataReader.FieldCount; i++)
                        {
                            searchResult.Add(query.DataReader.GetName(i), query.DataReader[i].ToString());
                        }
                    }
                }
            }
            if (searchResult.Count == 0) return;
            if (searchResult["ID_REGION"] != string.Empty) SelectedRegion = RegionCollection.FirstOrDefault(a => a.Id == searchResult["ID_REGION"]);
            if (searchResult["ID_AUTO"] != string.Empty) SelectedAuto = AutoCollection.FirstOrDefault(a => a.Id == searchResult["ID_AUTO"]);
            if (searchResult["ID_AREA"] != string.Empty) SelectedArea = AreaCollection.FirstOrDefault(a => a.Id == searchResult["ID_AREA"]);
            if (searchResult["ID_CITY"] != string.Empty) SelectedCity = CityCollection.FirstOrDefault(a => a.Id == searchResult["ID_CITY"]);
            if (searchResult["ID_CTAR"] != string.Empty) SelectedCtar = CtarCollection.FirstOrDefault(a => a.Id == searchResult["ID_CTAR"]);
            if (searchResult["ID_PLACE"] != string.Empty) SelectedPlace = PlaceCollection.FirstOrDefault(a => a.Id == searchResult["ID_PLACE"]);
            if (searchResult["ID_STREET"] != string.Empty) SelectedStreet = StreetCollection.FirstOrDefault(a => a.Id == searchResult["ID_STREET"]);
            if (searchResult["ID_HOUSE"] != string.Empty) SelectedHouse = HouseCollection.FirstOrDefault(a => a.Id == searchResult["ID_HOUSE"]);
        }