public void Add_Continent(string name, double pop, double square, double dens, string biggest, double peak, double lowest) { if (continents.Count() > 0 && continents.Where(x => x.Name == name).FirstOrDefault() == null) { Continent c = new Continent(name, pop, square, dens, biggest, peak, lowest); continents.Add(c); MessageBox.Show("Збережено"); } else if (continents.Count() == 0) { Continent c = new Continent(name, pop, square, dens, biggest, peak, lowest); continents.Add(c); MessageBox.Show("Збережено"); } else { MessageBox.Show("Такий континент вже існує"); } }
private void Click(object sender, MouseButtonEventArgs e) { if (list.SelectedItem is City) { City cur = (City)list.SelectedItem; map.Center = new Microsoft.Maps.MapControl.WPF.Location(cur.Latitude, cur.Longitude); map.ZoomLevel = 8; } else if (list.SelectedItem is Country) { Country count = (Country)list.SelectedItem; City cur = world.FindCity(count.Capital); if (cur != null) { map.Center = new Microsoft.Maps.MapControl.WPF.Location(cur.Latitude, cur.Longitude); map.ZoomLevel = 4; } else { MessageBox.Show("Не знайдено столицю країни, зверніться до служби підтримки"); } } else if (list.SelectedItem is Continent) { Continent cont = (Continent)list.SelectedItem; if (cont.Name.ToLowerInvariant() == "євразія") { map.Center = new Microsoft.Maps.MapControl.WPF.Location(49, 23); map.ZoomLevel = 3; return; } else if (cont.Name.ToLowerInvariant() == "африка") { map.Center = new Microsoft.Maps.MapControl.WPF.Location(3, 12); map.ZoomLevel = 3; return; } else if (cont.Name.ToLowerInvariant() == "австралія") { map.Center = new Microsoft.Maps.MapControl.WPF.Location(-26, 133); map.ZoomLevel = 3; return; } else if (cont.Name.ToLowerInvariant() == "північна америка") { map.Center = new Microsoft.Maps.MapControl.WPF.Location(65, -80); map.ZoomLevel = 3; return; } else if (cont.Name.ToLowerInvariant() == "південна америка") { map.Center = new Microsoft.Maps.MapControl.WPF.Location(-30, -60); map.ZoomLevel = 3; return; } else if (cont.Name.ToLowerInvariant() == "антарктида") { map.Center = new Microsoft.Maps.MapControl.WPF.Location(-70, 0); map.ZoomLevel = 3; return; } } else if (list.SelectedItem is Region) { Region region = (Region)list.SelectedItem; City cur = world.FindCity(region.Capital); if (cur != null) { map.Center = new Microsoft.Maps.MapControl.WPF.Location(cur.Latitude, cur.Longitude); map.ZoomLevel = 6; return; } Country c = world.FindCountry(region.Country); if (c != null) { City fromcountry = world.FindCity(c.Capital); if (fromcountry != null) { map.Center = new Microsoft.Maps.MapControl.WPF.Location(fromcountry.Latitude, fromcountry.Longitude); map.ZoomLevel = 6; return; } } MessageBox.Show("Не знайдено область, зверніться до служби підтримки"); } }
private void Continent_Ed_Click(object sender, RoutedEventArgs e) { string name = cont_name_ed.Text; double pop = -1; double square = -1; double peak = -1; double lowest = -1; string biggest = cont_biggest_ed.Text; double dens = -1; Continent cont = world.FindContinent(name); if (cont == null) { MessageBox.Show("Немає материка з такою назвою"); return; } try { if (cont_pop_ed.Text != "") { pop = double.Parse(cont_pop_ed.Text); } } catch (Exception ex) { MessageBox.Show(ex.Message.ToString(), "Error", MessageBoxButton.OK, MessageBoxImage.Error); } try { if (cont_square_ed.Text != "") { square = double.Parse(cont_square_ed.Text); } } catch (Exception ex) { MessageBox.Show(ex.Message.ToString(), "Error", MessageBoxButton.OK, MessageBoxImage.Error); } try { if (cont_peak_ed.Text != "") { peak = double.Parse(cont_peak_ed.Text); } } catch (Exception ex) { MessageBox.Show(ex.Message.ToString(), "Error", MessageBoxButton.OK, MessageBoxImage.Error); } try { if (cont_lowest_ed.Text != "") { lowest = double.Parse(cont_lowest_ed.Text); } } catch (Exception ex) { MessageBox.Show(ex.Message.ToString(), "Error", MessageBoxButton.OK, MessageBoxImage.Error); } try { if (cont_dens_ed.Text != "") { dens = double.Parse(cont_dens_ed.Text); } } catch (Exception ex) { MessageBox.Show(ex.Message.ToString(), "Error", MessageBoxButton.OK, MessageBoxImage.Error); } if (cont != null) { if (pop > 0) { cont.Set_Population(pop); } if (square > 0) { cont.Set_Square(square); } if (peak != -1) { cont.Set_Peak(peak); } if (lowest != -1) { cont.Set_Lowest(lowest); } if (dens > 0) { cont.Set_Density(dens); } if (biggest != "") { cont.Set_City(biggest); } MessageBox.Show("Змінено"); } }