Ejemplo n.º 1
0
        private void ButtonChangeLocker_Click(object sender, EventArgs e)
        {
            var result = MessageBox.Show("Do you want to change the locker for this rental?", "Change Locker",
                                         MessageBoxButtons.YesNo, MessageBoxIcon.Warning);

            if (result == DialogResult.Yes)
            {
                //Check if the rental overdue. If yes, show error message and return.

                TimeSpan timeSpan = _rental.EndDate.Date.Subtract(DateTime.Now.Date);
                int      daysLeft = Convert.ToInt32(timeSpan.Days);
                if (daysLeft < 0)
                {
                    MessageBox.Show("Access Error: Rental Overdued." + Environment.NewLine +
                                    "You cannot change details for an overdued rental.", "Access Error",
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                SelectLockerForm selectLockerForm = new SelectLockerForm(_rental.Id);
                selectLockerForm.ShowDialog();

                if (selectLockerForm.IsSelected())
                {
                    // Assign the original cabinet data into a temporary variable
                    Locker previousLocker = _locker;

                    // Get the new locker type, cabinet and locker data for the selected locker
                    _locker          = selectLockerForm.SelectedLocker;
                    _cabinet         = Cabinet.Get(_locker.CabinetId);
                    _lockerType      = LockerType.Get(_cabinet.LockerTypeId);
                    _rental.LockerId = _locker.Id;

                    // Save the rental
                    RentalController rentalController = new RentalController();
                    rentalController.ChangeBookedLocker(_rental, previousLocker);
                    _isInsertComplete = true;

                    // Load the new data into locker display
                    ViewRentalLoadRentalData();
                }
            }
        }
Ejemplo n.º 2
0
        private void ButtonNextAddRental_Click(object sender, EventArgs e)
        {
            try
            {
                _rentalController.SetAddRentalData(_customer, _employee,
                                                   dateTimePickerStartDateAddRental.Value, dateTimePickerEndDateAddRental.Value,
                                                   (int)numericUpDownDurationAddRental.Value);

                _rentalController.CheckRentalDuration((int)numericUpDownDurationAddRental.Value);

                DateTime startdate = dateTimePickerStartDateAddRental.Value;
                DateTime endDate   = dateTimePickerEndDateAddRental.Value;

                SelectLockerForm selectLockerForm = new SelectLockerForm(startdate, endDate);
                selectLockerForm.ShowDialog();

                if (!selectLockerForm.IsSelected())
                {
                    return;
                }

                _rentalController.SetAddRentalLockerData(selectLockerForm.SelectedLocker);

                // Get data of the selected locker
                _locker     = selectLockerForm.SelectedLocker;
                _cabinet    = Cabinet.Get(_locker.CabinetId);
                _lockerType = LockerType.Get(_cabinet.LockerTypeId);

                PayRentalLoadRentalData();

                // Show Pay Rental
                this.Controls.Remove(panelAddRental);
                this.Controls.Add(panelPayRental);

                // Hide OK button and show only Confrim Button
                buttonOKPayRental.Hide();
            }
            catch (InvalidUserInputException exception)
            {
                exception.ShowErrorMessage();
            }
        }