/*СОХРАНИТЬ ДОСТОПРИМЕЧАТЕЛЬНОСТЬ */ private void ButSaveSightAd_Click(object sender, RoutedEventArgs e) { try { ButEditSightAd.Visibility = Visibility.Visible; ButSaveSightAd.Visibility = Visibility.Hidden; Sight si = new Sight(EdNameSightAd.Text, EdYearSightAd.Text, EdInfSightAd.Text, EdCitySightAd.Text, EdCountrySightAd.Text, SightImEdAd.Text); sights.Add(si); Log.L("Добавлена достопримечательность" + si.Name + "; " + DateTime.Now); Sort.S(sights); foreach (var item in countries.ListCou) { if (item.Name == si.Country) { item.LSight.Add(si); } } AllSightAd.Items.Clear(); foreach (var item in sights) { AllSightAd.Items.Add(item.ShowC()); } Ser.Serialize(countries); } catch (Exception ex) { MessageBox.Show(ex.Message, "", MessageBoxButton.OK, MessageBoxImage.Warning); Log.L("Ошибка! " + ex.Message); } }
/*ИЗМЕНИТЬ ДОСТОПРИМЕЧАТЕЛЬНОСТЬ */ private void ButEditSightAd_Click(object sender, RoutedEventArgs e) { try { Sight sig = new Sight(); foreach (var item in sights) { if (AllSightAd.SelectedItem != null) { if (AllSightAd.SelectedItem.ToString() == item.ShowC()) { sig = item; item.Name = EdNameSightAd.Text; item.Year = EdYearSightAd.Text; item.City = EdCitySightAd.Text; item.Country = EdCountrySightAd.Text; item.Information = EdInfSightAd.Text; item.SightIm = SightImEdAd.Text; Log.L("Изменена достопримечательность " + item.Name + "; " + DateTime.Now); } } } Sort.S(sights); foreach (var item in countries.ListCou) { if (AllSightAd.SelectedItem != null) { if (item.Name == sig.Country) { foreach (var s in item.LSight) { if (s.Name == sig.Name) { s.Name = EdNameSightAd.Text; s.Year = EdYearSightAd.Text; s.City = EdCitySightAd.Text; s.Country = EdCountrySightAd.Text; s.Information = EdInfSightAd.Text; s.SightIm = SightImEdAd.Text; } } } } } AllSightAd.Items.Clear(); foreach (var item in sights) { AllSightAd.Items.Add(item.ShowC()); } Ser.Serialize(countries); MessageBox.Show("Изменения успешно сохранены"); } catch (Exception ex) { MessageBox.Show(ex.Message, "", MessageBoxButton.OK, MessageBoxImage.Warning); Log.L("Ошибка! " + ex.Message); } }
/*СОХРАНИТЬ ДОСТОПРИМЕЧАТЕЛЬНОСТЬ*/ private void SaveSightAd_Click(object sender, RoutedEventArgs e) { try { SightAd.Visibility = Visibility.Hidden; foreach (var item in countries.ListCou) { if (CountryNameAd.Text == item.Name) { EditSightAd.Visibility = Visibility.Visible; } } Sight si = new Sight(NameSightAd.Text, YearSightAd.Text, InfSightAd.Text, CitySightAd.Text, CountryNameAd.Text, SightImAd.Text); sights.Add(si); Log.L("Добавлена достопримечательность " + si.Name + "; " + DateTime.Now); foreach (var item in countries.ListCou) { if (item.Name == si.Country) { item.LSight.Add(si); Sort.S(item.LSight); } } Sort.S(sights); EditSightListAd.Items.Clear(); foreach (var item in sights) { if (AllCouAd.SelectedItem != null) { if (AllCouAd.SelectedItem.ToString() == item.Country) { EditSightListAd.Items.Add(item.Show()); } } } Ser.Serialize(countries); } catch (Exception ex) { MessageBox.Show(ex.Message, "", MessageBoxButton.OK, MessageBoxImage.Warning); Log.L("Ошибка! " + ex.Message); } }