コード例 #1
0
        public EditApartmentForm()
        {
            InitializeComponent();

            Apartments = ApartmentProvider.GetAllApartments().ToList();
            Apartments.ForEach(apartment => selectApartmentComboBox.Items.Add(apartment.ToDropDownString()));
        }
コード例 #2
0
        private void DeleteButton_Click(object sender, System.EventArgs e)
        {
            ApartmentProvider.DeleteApartment(SelectedApartment);

            MessageBox.Show(@"Apartment successfully deleted");

            Close();
        }
コード例 #3
0
        /// <summary>
        /// Updates the list of available apartments.
        /// </summary>
        private void UpdateNumberOfAvailableApartments()
        {
            var minimalCapacity = int.Parse(minimalCapacityNumericUpDown.Value.ToString(CultureInfo.InvariantCulture));
            var doubleBeds      = int.Parse(doubleBedsNumericUpDown.Value.ToString(CultureInfo.InvariantCulture));
            var from            = fromDateTimePicker.Value;
            var to = toDateTimePicker.Value;

            AvailableApartments = ApartmentProvider.GetAvailableApartments(minimalCapacity, doubleBeds, from, to);

            var availableApartmentsCount = AvailableApartments.Count();

            availableApartmentsLabel.Text = availableApartmentsCount.ToString();

            CheckApartmentsComboBoxAvailability(availableApartmentsCount);

            RefreshGui();
        }
コード例 #4
0
        private void ValidateData()
        {
            var apartments = ApartmentProvider.GetAllApartments().Except(new List <ApartmentInfo> {
                SelectedApartment
            }).ToList();

            if (!int.TryParse(roomNumberTextBox.Text, out var roomNumber))
            {
                MessageBox.Show(@"Please enter a valid room number");

                return;
            }

            if (apartments.Any(apartment => apartment.Number.Equals(roomNumber)))
            {
                MessageBox.Show(@"An apartment with this number already exists. Please enter a different number.");

                return;
            }

            if (!int.TryParse(priceTextBox.Text, out var price))
            {
                MessageBox.Show(@"Please enter a valid price");

                return;
            }

            if (price <= 0)
            {
                MessageBox.Show(@"Please enter a correct price.");

                return;
            }

            if (capacityComboBox.SelectedIndex < 0)
            {
                MessageBox.Show(@"Please select capacity.");

                return;
            }

            if (doubleBedsComboBox.SelectedIndex < 0)
            {
                MessageBox.Show(@"Please select the number of double beds.");

                return;
            }

            if (int.Parse(doubleBedsComboBox.SelectedItem.ToString()) * 2 > int.Parse(capacityComboBox.SelectedItem.ToString()))
            {
                MessageBox.Show(@"The capacity is not enough to accommodate this number of double beds.");

                return;
            }

            SelectedApartment.Number     = int.Parse(roomNumberTextBox.Text);
            SelectedApartment.Price      = int.Parse(priceTextBox.Text);
            SelectedApartment.Capacity   = capacityComboBox.SelectedIndex + 1;
            SelectedApartment.DoubleBeds = doubleBedsComboBox.SelectedIndex;

            ApartmentProvider.UpdateApartment(SelectedApartment);

            MessageBox.Show(@"Changes successfully saved.");

            Close();
        }