Пример #1
0
        public void CreateDefaultDB(string path)
        {
            // создаем файл бд
            DataAccessLevel.SQLiteDatabaseCreator creator = new DataAccessLevel.SQLiteDatabaseCreator();
            creator.CreateDataBaseFile(path);

            // создаем структуру таблиц
            creator.CreateTables(path);

            // вставляем одну стку настек по умолчанию
            DataAccessLevel.SettingsDataContext sdc = new DataAccessLevel.SettingsDataContext();
            sdc.cityID   = 27786;
            sdc.sourceID = 1; // по умолчанию - owm
            sdc.saveDate = DateTime.Now;

            DataAccessLevel.SQLiteDatabaseWorker worker = new DataAccessLevel.SQLiteDatabaseWorker();
            worker.SetConnect(path);
            worker.SaveSettings(sdc);
            worker.CloseConnect();

            // считываем города из файла
            DataAccessLevel.RegionCitiesLists DBlist = SaveCities(@"D:\cities.xml");

            // записываем города в базу
            worker.SetConnect(path);
            worker.FillCitiesAndRegionsTables(DBlist);
            worker.CloseConnect();
        }
Пример #2
0
        public DataAccessLevel.RegionCitiesLists SaveCities(string path)
        {
            string      fileName = path;
            XmlDocument xDoc     = new XmlDocument();

            xDoc.Load(fileName);
            string owmid      = "";
            string yaid       = "";
            string regionName = "";
            string CityName   = "";

            List <Yandex.Cities1> ListOfCities = new List <Yandex.Cities1>();

            DataAccessLevel.RegionCitiesLists DBlist = new DataAccessLevel.RegionCitiesLists();

            foreach (XmlElement node in xDoc.DocumentElement)
            {
                var attr = node.Attributes;
                for (int i = 0; i < attr.Count; i++)
                {
                    CityName = node.InnerText;
                    if (node.HasAttribute("owmid"))
                    {
                        owmid = attr.GetNamedItem("owmid").Value;
                    }
                    else
                    {
                        owmid = "";
                    }
                    yaid       = attr.GetNamedItem("id").Value;
                    regionName = attr.GetNamedItem("part").Value;
                }

                ListOfCities.Add(new Yandex.Cities1
                {
                    citName = CityName,
                    id      = yaid,
                    part    = regionName,
                    region  = owmid
                });
            }

            var custs = (from customer in ListOfCities
                         select new { customer.part }).Distinct();


            int k = 1;

            foreach (var item in custs)
            {
                DBlist.regionsList.Add(new DataAccessLevel.RegionsDataContext
                {
                    name     = item.part,
                    regionID = k
                });
                var custs2 = (from customer in ListOfCities
                              select new { customer.citName, customer.part, customer.id, customer.region }).Where(t => t.part.ToString() == item.part.ToString());
                foreach (var item2 in custs2)
                {
                    DBlist.citiesList.Add(new DataAccessLevel.CitiesDataContext
                    {
                        name     = item2.citName,
                        regionID = k,
                        yandexID = int.Parse(item2.id),
                        owmID    = item2.region
                    });
                }
                k++;
            }
            return(DBlist);
        }