private void readDirectory() { comboCityID.Clear(); string directory = String.Format(@"{0}xmldata\", AppDomain.CurrentDomain.BaseDirectory); string[] path = Directory.GetFiles(directory); for (int i = 0; i < path.Length; i++) { string extension = System.IO.Path.GetExtension(path[i]); if (extension == ".xaml") { string filename = System.IO.Path.GetFileNameWithoutExtension(path[i]); if (int.TryParse(filename, out _)) { int id = Convert.ToInt32(filename); City city = new City(); city = XamlOperation.readXML(id); comboCityID.Add(id); cb_ID.Items.Add(city.name + " (" + id.ToString() + ")"); } } } }
private void TakeCity_click(object sender, RoutedEventArgs e) { if (string.IsNullOrEmpty(cb_ID.Text)) { Error = "Вы ничего не выбрали"; return; } City city = XamlOperation.readXML(comboCityID[cb_ID.SelectedIndex]); city.checkWeatherUpdate(); mainWindow.setCity(city); Hide(); }
private void AddCity_Click(object sender, RoutedEventArgs e) { if (string.IsNullOrEmpty(fiel_id.Text)) { Error = "Поле не заполнено."; return; } if (!int.TryParse(fiel_id.Text, out _)) { Error = "Значение было введено неправильно."; return; } int id = Convert.ToInt32(fiel_id.Text); if (XamlOperation.isCityDownloaded(id)) { Error = "Город уже существует."; return; } if (!XamlOperation.isCityValid(id)) { Error = "Город не был найден."; return; } errorTextBox.Visibility = Visibility.Hidden; City city = new City(); city.id = id; city.weatherDatas = XamlOperation.readGismeteoXML(id); city.name = city.weatherDatas[0].city; XamlOperation.writeXML(city); MessageBox.Show("Город был успешно добавлен."); }