Ejemplo n.º 1
0
        public bool Save(APIreader reader)
        {
            bool saveOut = false;

            //Пробуем сохранить данные в БД
            try
            {
                if (reader.allData.Length > 1)
                {
                    int cityId = SaveInBD("SELECT City_id, Name FROM City", reader.capital,
                                          "INSERT INTO City(City_id, Name) VALUES(", ", '" + reader.capital + "')");
                    int regionId = SaveInBD("SELECT Region_id, Name FROM Region", reader.region,
                                            "INSERT INTO Region(Region_id, Name) VALUES(", reader.region);
                    int countryId = SaveInBD("SELECT Country_id, Name FROM Country", reader.country,
                                             "INSERT INTO Country(Country_id, Name) VALUES(", ", '" + reader.country + "')");
                    Query("UPDATE Country " +
                          "SET Name='" + reader.country +
                          "', CodeName='" + reader.code +
                          "', Capital=" + cityId +
                          ", Area=" + reader.area +
                          ", Population=" + reader.population +
                          ", Region=" + regionId + " " +
                          "WHERE Country_id=" + countryId);
                    saveOut = true;
                }
            }
            catch
            {
                saveOut = false;
                connectionDB.Close();
            }
            return(saveOut);
        }
Ejemplo n.º 2
0
 private void SearchClick(object sender, EventArgs e)
 {
     ListBox.Items.Clear();
     if (apireader == null || apireader.CheckNewCountry(TextBox.Text))
     {
         apireader = new APIreader(TextBox.Text);
     }
     ListBox.Items.AddRange(apireader.allData);
 }