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);
            }
        }
        /*СОХРАНИТЬ ДОСТОПРИМЕЧАТЕЛЬНОСТЬ */
        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);
            }
        }
Esempio n. 4
0
        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);
            }
        }
Esempio n. 5
0
        /*НА СТРАНИЧКУ ДЛЯ ПОЛЬЗОВАТЕЛЯ */
        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);
            }
        }
        /*ИЗМЕНИТЬ СТРАНУ */
        private void EditCountryAd_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                EditSightAd.Visibility = Visibility.Visible;

                foreach (var item in countries.ListCou)
                {
                    if (AllCouAd.SelectedItem != null)
                    {
                        if (AllCouAd.SelectedItem.ToString() == item.Name)
                        {
                            string s = item.Name;
                            item.Name       = CountryNameAd.Text;
                            item.Capital    = CapitalAd.Text;
                            item.Language   = LangAd.Text;
                            item.Population = float.Parse(PopAd.Text);
                            item.Square     = float.Parse(SquareAd.Text);
                            item.Flag       = FlagAd.Text;
                            foreach (var ls in item.LSight)
                            {
                                ls.Country = CountryNameAd.Text;
                            }

                            Log.L("Изменена страна" + item.Name + "; " + DateTime.Now);
                        }
                    }
                }

                Sort.C(countries.ListCou);
                AllCouAd.Items.Clear();

                foreach (var item in countries.ListCou)
                {
                    AllCouAd.Items.Add(item.Name);
                }

                Ser.Serialize(countries);

                EditSightListAd.Items.Clear();
                foreach (var item in sights)
                {
                    if (CountryNameAd.Text == item.Country)
                    {
                        EditSightListAd.Items.Add(item.Show());
                    }
                }

                MessageBox.Show("Изменения успешно сохранены");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "", MessageBoxButton.OK, MessageBoxImage.Warning);
                Log.L("Ошибка! " + ex.Message);
            }
        }
        /*СОХРАНИТЬ СТРАНУ*/
        //private void button_Click(object sender, RoutedEventArgs e)
        //{
        //    try {
        //        SaveCountryAd.Visibility = Visibility.Hidden;
        //        EditCountryAd.Visibility = Visibility.Visible;

        //        EditSightAd.Visibility = Visibility.Visible;

        //        List<Sight> sightscou = new List<Sight>();
        //        foreach (var item in sights)
        //        {
        //            if (CountryNameAd.Text == item.Country)
        //            {
        //                sightscou.Add(item);
        //            }
        //        }

        //        Country cou = new Country(CountryNameAd.Text, CapitalAd.Text, LangAd.Text, float.Parse(SquareAd.Text), float.Parse(PopAd.Text), FlagAd.Text, sightscou);

        //        Log.L("Добавлена страна " + cou.Name + "; " + DateTime.Now);
        //        countries.ListCou.Add(cou);

        //        Sort.C(countries.ListCou);

        //        AllCouAd.Items.Clear();
        //        foreach (var item in countries.ListCou)
        //        {
        //            AllCouAd.Items.Add(item.ShowName());
        //        }

        //        EditSightListAd.Items.Clear();
        //        foreach (var item in sights)
        //        {
        //            if (cou.Name == 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);
        //    }


        //}

        /*УДАЛИТЬ СТРАНУ */
        //private void DeleteCountryAd_Click(object sender, RoutedEventArgs e)
        //{
        //    try {
        //        if (AllCouAd.SelectedItem != null)
        //        {
        //            foreach (var item in countries.ListCou)
        //            {
        //                if (AllCouAd.SelectedItem.ToString() == item.Name)
        //                {
        //                    int i = countries.ListCou.IndexOf(item);
        //                    countries.ListCou.RemoveAt(i);
        //                    Log.L("Удалена страна" + item.Name + "; " + DateTime.Now);
        //                    break;

        //                }
        //            }
        //            AllCouAd.Items.Clear();

        //            foreach (var item in countries.ListCou)
        //            {
        //                AllCouAd.Items.Add(item.Name);

        //            }

        //            Ser.Serialize(countries);


        //            CountryNameAd.Text = "";
        //            CapitalAd.Text = "";
        //            LangAd.Text = "";
        //            SquareAd.Text = "";
        //            PopAd.Text = "";
        //            FlagAd.Text = "";
        //        }
        //        else
        //            MessageBox.Show("Выберите страну", "", MessageBoxButton.OK, MessageBoxImage.Warning);
        //      }
        //    catch (Exception ex)
        //    {
        //        MessageBox.Show(ex.Message, "", MessageBoxButton.OK, MessageBoxImage.Warning);
        //        Log.L("Ошибка! " + ex.Message);
        //    }
        //}

        /*УДАЛИТЬ ДОСТОПРИМЕЧАТЕЛЬНОСТЬ*/
        private void DeleteSightAd_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                foreach (var item in sights)
                {
                    if (EditSightListAd.SelectedItem.ToString() == item.Show())
                    {
                        int i = sights.IndexOf(item);
                        sights.RemoveAt(i);
                        Log.L("Удалена достопримечательность" + item.Name + "; " + DateTime.Now);

                        break;
                    }
                }

                foreach (var item in countries.ListCou)
                {
                    foreach (var ls in item.LSight)
                    {
                        if (EditSightListAd.SelectedItem.ToString() == ls.Show())
                        {
                            int i = item.LSight.IndexOf(ls);
                            item.LSight.RemoveAt(i);
                            break;
                        }
                    }
                }

                EditSightListAd.Items.Clear();

                foreach (var item in sights)
                {
                    if (CountryNameAd.Text == item.Country)
                    {
                        EditSightListAd.Items.Add(item.Show());
                    }
                }


                Ser.Serialize(countries);

                EdNameSightAd.Text = "";
                EdYearSightAd.Text = "";
                EdCitySightAd.Text = "";
                EdInfSightAd.Text  = "";
                SightImEdAd.Text   = "";
            }
            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);
            }
        }
        /*ИЗМЕНИТЬ ДОСТОПРИМЕЧАТЕЛЬНОСТЬ */
        private void EdSaveSightAd_Click(object sender, RoutedEventArgs e)
        {
            try {
                foreach (var item in sights)
                {
                    if (EditSightListAd.SelectedItem != null)
                    {
                        if (EditSightListAd.SelectedItem.ToString() == item.Show())
                        {
                            item.Name        = EdNameSightAd.Text;
                            item.Year        = EdYearSightAd.Text;
                            item.City        = EdCitySightAd.Text;
                            item.Information = EdInfSightAd.Text;
                            item.SightIm     = SightImAd.Text;
                            Log.L("Изменена достопримечательность " + item.Name + "; " + DateTime.Now);
                        }
                    }
                }
                EditSightListAd.Items.Clear();
                foreach (var item in sights)
                {
                    if (CountryNameAd.Text == item.Country)
                    {
                        EditSightListAd.Items.Add(item.Show());
                    }
                }

                Ser.Serialize(countries);



                MessageBox.Show("Изменения успешно сохранены");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "", MessageBoxButton.OK, MessageBoxImage.Warning);
                Log.L("Ошибка! " + ex.Message);
            }
        }