Esempio n. 1
0
 private void buttonEdit_Click(object sender, RoutedEventArgs e)
 {
     if (listViewTours.SelectedIndex != -1)
     {
         selectedTour = Pages.AddPage._tours[listViewTours.SelectedIndex];
         EditPage editPage = new EditPage();
         foreach (var tour in Pages.AddPage._tours)
         {
             editPage.cityFromBox.Text            = tour.CityFrom;
             editPage.cityToBox.Text              = tour.CityTo.Name;
             editPage.countryBox.Text             = tour.CityTo.Country;
             editPage.priceBox.Text               = Convert.ToString(tour.Price);
             editPage.dateGoPicker.SelectedDate   = Convert.ToDateTime(tour.DateGo);
             editPage.dateBackPicker.SelectedDate = Convert.ToDateTime(tour.DateBack);
             editPage.hotelBox.Text               = tour.CityTo.Hotel.HotelName;
             editPage.roomPrice1Box.Text          = Convert.ToString(tour.CityTo.Hotel.RoomPrice1);
             editPage.roomPrice2Box.Text          = Convert.ToString(tour.CityTo.Hotel.RoomPrice2);
             editPage.roomPrice3Box.Text          = Convert.ToString(tour.CityTo.Hotel.RoomPrice3);
         }
         NavigationService.Navigate(editPage);
     }
 }
Esempio n. 2
0
        public void buttonAdd_Click(object sender, RoutedEventArgs e)
        {
            if ((cityFromBox.Text == "Город отправления") || (cityToBox.Text == "Город прибытия") || (countryBox.Text == "Страна прибытия") || (hotelBox.Text == "Название отеля") || (priceBox.Text == "Цена") ||
                (dateGoPicker.SelectedDate == null) || (dateBackPicker.SelectedDate == null) || (roomPrice1Box.Text == "Цена 1-местного номера") || (roomPrice2Box.Text == "Цена 2-местного номера") || (roomPrice3Box.Text == "Цена 3-местного номера"))
            {
                MessageBox.Show("Введены не все данные!", "Ошибка");
                return;
            }
            int    a, b, c, d;
            double f, g, h, i, j, k, l, m;

            if ((int.TryParse(cityFromBox.Text, out a) == true) && (double.TryParse(cityFromBox.Text, out f) == true))
            {
                MessageBox.Show("Неверный формат данных!", "Ошибка");
                cityFromBox.Focus();
                return;
            }

            if ((int.TryParse(cityToBox.Text, out b) == true) && (double.TryParse(cityToBox.Text, out g) == true))
            {
                MessageBox.Show("Неверный формат данных!", "Ошибка");
                cityToBox.Focus();
                return;
            }

            if ((int.TryParse(countryBox.Text, out c) == true) && (double.TryParse(countryBox.Text, out h) == true))
            {
                MessageBox.Show("Неверный формат данных!", "Ошибка");
                countryBox.Focus();
                return;
            }

            if ((int.TryParse(hotelBox.Text, out d) == true) && (double.TryParse(hotelBox.Text, out i) == true))
            {
                MessageBox.Show("Неверный формат данных!", "Ошибка");
                cityFromBox.Focus();
                return;
            }

            if (double.TryParse(priceBox.Text, out j) == false)
            {
                MessageBox.Show("Неверный формат данных! Если число дробное, оно должно быть введено через запятую.", "Ошибка");
                priceBox.Focus();
                return;
            }

            if (double.TryParse(roomPrice1Box.Text, out k) == false)
            {
                MessageBox.Show("Неверный формат данных! Если число дробное, оно должно быть введено через запятую.", "Ошибка");
                roomPrice1Box.Focus();
                return;
            }

            if (double.TryParse(roomPrice2Box.Text, out l) == false)
            {
                MessageBox.Show("Неверный формат данных! Если число дробное, оно должно быть введено через запятую.", "Ошибка");
                roomPrice2Box.Focus();
                return;
            }

            if (double.TryParse(roomPrice3Box.Text, out m) == false)
            {
                MessageBox.Show("Неверный формат данных! Если число дробное, оно должно быть введено через запятую.", "Ошибка");
                roomPrice3Box.Focus();
                return;
            }

            _newHotel = new Hotels(hotelBox.Text, Convert.ToDouble(roomPrice1Box.Text), Convert.ToDouble(roomPrice2Box.Text),
                                   Convert.ToDouble(roomPrice3Box.Text));
            _newCityTo = new CityTo(cityToBox.Text, countryBox.Text, _newHotel);
            _newTour   = new Tours(cityFromBox.Text, _newCityTo, Convert.ToInt32(priceBox.Text),
                                   ConvertDate(Convert.ToDateTime(dateGoPicker.SelectedDate)), ConvertDate(Convert.ToDateTime(dateBackPicker.SelectedDate)));

            MessageBoxResult result = MessageBox.Show("Добавить новый тур?", "Подтвердите действие", MessageBoxButton.YesNo, MessageBoxImage.Question);

            if (result == MessageBoxResult.Yes)
            {
                _hotels.Add(_newHotel);
                _citiesTo.Add(_newCityTo);
                _tours.Add(_newTour);
                NavigationService.Navigate(Pages.ListPage);
                Pages.ListPage.RefreshListView();
                Pages.ToursPage.RefreshListView();
                Pages.ListPage.SerializeData();
                cityFromBox.Text          = "Город отправления"; cityFromBox.Foreground = new SolidColorBrush(Colors.Gray); cityToBox.Text = "Город прибытия"; cityToBox.Foreground = new SolidColorBrush(Colors.Gray);
                countryBox.Text           = "Страна прибытия"; countryBox.Foreground = new SolidColorBrush(Colors.Gray); priceBox.Text = "Цена"; priceBox.Foreground = new SolidColorBrush(Colors.Gray);
                dateGoPicker.SelectedDate = null; dateBackPicker.SelectedDate = null; hotelBox.Text = "Название отеля"; hotelBox.Foreground = new SolidColorBrush(Colors.Gray);
                roomPrice1Box.Text        = "Цена 1-местного номера"; roomPrice1Box.Foreground = new SolidColorBrush(Colors.Gray);
                roomPrice2Box.Text        = "Цена 2-местного номера"; roomPrice2Box.Foreground = new SolidColorBrush(Colors.Gray);
                roomPrice3Box.Text        = "Цена 3-местного номера"; roomPrice3Box.Foreground = new SolidColorBrush(Colors.Gray);
            }
            if (result == MessageBoxResult.No)
            {
                NavigationService.Navigate(Pages.AddPage);
            }
        }