public void AddCities(CountryCity countryCity)//добавляем новый город { countryCityList.Add(countryCity); dataGridView1.Rows.Clear(); dataGridView1.Columns.Clear(); FillDGV(); }
public void UpdateCities(CountryCity countryCity)//обновляем город { countryCityList.Clear(); LoadData(); dataGridView1.Rows.Clear(); dataGridView1.Columns.Clear(); FillDGV(); }
void LoadData()//загрузили данные { using (var cmd = new NpgsqlCommand($"Select distinct countries.id_country, id_city, name_country, name_city FROM countries, cities WHERE countries.id_country = cities.id_country", Connection)) { using (var reader = cmd.ExecuteReader()) while (reader.Read()) { var countryCity = new CountryCity(); var idCountries = reader["id_country"].ToString().Trim(); countryCity.idCountry = Int32.Parse(idCountries); var idCities = reader["id_city"].ToString().Trim(); countryCity.idCity = Int32.Parse(idCities); countryCity.nameCountry = reader["name_country"].ToString().Trim(); countryCity.nameCity = reader["name_city"].ToString().Trim(); countryCityList.Add(countryCity); } } }
private void button_search_countries_Click(object sender, EventArgs e)//кнопка поиска { if (textBox_search.Text.Length < 1) { MessageBox.Show($"Поле поиска не может быть пустым!", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { dataGridView1.Rows.Clear(); dataGridView1.Columns.Clear(); countryCityList.Clear(); using (var cmdCount = new NpgsqlCommand($"SELECT COUNT(*) FROM cities WHERE name_city LIKE '%" + textBox_search.Text.ToString().Trim() + "%'", Connection)) { int countRows = Convert.ToInt32(cmdCount.ExecuteScalar()); if (countRows > 0) { using (var cmd = new NpgsqlCommand("Select DISTINCT countries.id_country, id_city, name_country, name_city FROM countries, cities WHERE countries.id_country = cities.id_country AND name_city LIKE '%" + textBox_search.Text.ToString().Trim() + "%'", Connection)) { using (var reader = cmd.ExecuteReader()) { while (reader.Read()) { var countryCity = new CountryCity(); countryCity.nameCity = reader["name_city"].ToString().Trim(); countryCity.nameCountry = reader["name_country"].ToString().Trim(); var idCo = reader["id_country"].ToString().Trim(); countryCity.idCountry = Int32.Parse(idCo); var idCi = reader["id_city"].ToString().Trim(); countryCity.idCity = Int32.Parse(idCi); countryCityList.Add(countryCity); } } } FillDGV(); MessageBox.Show($"Совпадения найдены!", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("Совпадений не найдено! Туры в данный город не осуществляются!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } }