public CountryAd() { InitializeComponent(); try { countries.ListCou = new List <Country>(); if (File.Exists("../../allcountries.xml")) { countries = Ser.DeSerialize(countries); Sort.C(countries.ListCou); foreach (var item in countries.ListCou) { AllCouAd.Items.Add(item.Name); foreach (var s in item.LSight) { Sort.S(item.LSight); sights.Add(s); } } Sort.S(sights); } } catch (Exception ex) { MessageBox.Show(ex.Message, "", MessageBoxButton.OK, MessageBoxImage.Warning); Log.L("Ошибка! " + ex.Message); } }
public MainWindow() { InitializeComponent(); try { countries.ListCou = new List <Country>(); Log.L("Вход в режим пользователя; " + DateTime.Now); var Pat = System.Reflection.Assembly.GetExecutingAssembly().Location; var p = "Map.png"; image.Source = new BitmapImage(new Uri(System.IO.Path.Combine(System.IO.Path.GetDirectoryName(Pat) + "/Map/", p))); if (File.Exists("../../allcountries.xml")) { countries = Ser.DeSerialize(countries); Sort.C(countries.ListCou); foreach (var item in countries.ListCou) { AllCou.Items.Add(item.Name); foreach (var s in item.LSight) { Sort.S(item.LSight); sights.Add(s); } } } } catch (Exception ex) { MessageBox.Show(ex.Message, "", MessageBoxButton.OK, MessageBoxImage.Warning); Log.L("Ошибка! " + ex.Message); } }
/*НА СТРАНИЧКУ ДЛЯ ПОЛЬЗОВАТЕЛЯ */ private void Back_Click(object sender, RoutedEventArgs e) { try { MainPage.Visibility = Visibility.Visible; Admin.Visibility = Visibility.Hidden; AdditionalInf.Visibility = Visibility.Visible; AllCou.Items.Clear(); sights.Clear(); if (File.Exists("../../allcountries.xml")) { countries = Ser.DeSerialize(countries); foreach (var item in countries.ListCou) { AllCou.Items.Add(item.Name); foreach (var s in item.LSight) { Sort.S(item.LSight); sights.Add(s); } } } Log.L("Вход в режим пользователя; " + DateTime.Now); } catch (Exception ex) { MessageBox.Show(ex.Message, "", MessageBoxButton.OK, MessageBoxImage.Warning); Log.L("Ошибка! " + ex.Message); } }
public static void Serialize(ListCountries listcou) { using (FileStream fs = new FileStream("../../allcountries.xml", FileMode.Create)) { StreamWriter sw = new StreamWriter(fs, Encoding.Default); serializer.Serialize(sw, listcou); sw.Close(); fs.Close(); }; }
public static ListCountries DeSerialize(ListCountries listcou) { ListCountries AllCou = null; using (FileStream fs = new FileStream("../../allcountries.xml", FileMode.Open)) { StreamReader sr = new StreamReader(fs, Encoding.Default); AllCou = (ListCountries)serializer.Deserialize(sr); sr.Close(); fs.Close(); }; return(AllCou); }