Пример #1
0
        // Constructor for View Rental
        public RentalForm(int id, bool isEndedRental)
        {
            InitializeComponent();

            // Hide all tabs not related to view rental
            this.Controls.Remove(tabControlRental);
            this.Controls.Add(panelViewRental);

            // If view ended rental, hide the change locker button
            if (isEndedRental)
            {
                buttonChangeLocker.Hide();
            }

            // Get data related to the rental
            _rental     = Rental.Get(id);
            _customer   = Customer.Get(_rental.CustomerId);
            _employee   = Employee.Get(_rental.EmployeeId);
            _locker     = Locker.Get(_rental.LockerId);
            _cabinet    = Cabinet.Get(_locker.CabinetId);
            _lockerType = LockerType.Get(_cabinet.LockerTypeId);

            // Insert the data into display fields
            ViewRentalLoadRentalData();
        }
        // Method to update the locker of the rental if changed
        public void ChangeBookedLocker(Rental rental, Locker previousLocker)
        {
            Locker locker = Locker.Get(rental.LockerId);

            // Change the locker of the rental
            rental.ChangeLocker();

            // Check if the rental is a started rental.
            if (rental.IsStarted())
            {
                // If yes, release the previous locker
                previousLocker.Reset();

                // Occupy the new locker
                locker.Occupied();

                // Check if the new cabinet is full, if yes set to full
                string lockerSearchCondition = String.Format("cabinet_id = {0} AND status = 'Available'", locker.CabinetId);
                int    noOfEmptyLocker       = Locker.Count(lockerSearchCondition);
                if (noOfEmptyLocker <= 0)
                {
                    Cabinet cabinet = Cabinet.Get(locker.CabinetId);
                    cabinet.Full();
                }

                // Check is the old cabinet full. If yes, set it as available
                Cabinet previousCabinet = Cabinet.Get(previousLocker.CabinetId);
                if (previousCabinet.IsFull())
                {
                    previousCabinet.Restore();
                }
            }
        }
Пример #3
0
        public void RestoreCabinetData(int id)
        {
            var cabItem = Cabinet.Get(id);

            //Check if the Locker Type available in the list (Not deleted). If no, show error.
            var lockerType = new LockerType();
            var typeItem   = LockerType.Get(cabItem.LockerTypeId);

            if (typeItem.IsDisabled())
            {
                throw new InvalidUserInputException("Restore Error - Cabinet Locker Type", "", typeItem.Name, "");
            }

            cabItem.Restore(); //Restore the cabinet

            //Calculate how many lockers in the cabinet
            int noOfLockers = cabItem.Row * cabItem.Column;

            //Restore the lockers assoicated to this cabinet
            List <Locker> lockerList = Locker.Where(String.Format("cabinet_id = {0}", id), 0, noOfLockers);

            for (int i = 0; i < noOfLockers; i++)
            {
                var restoreLocker = new Locker
                {
                    Id = lockerList[i].Id
                };
                restoreLocker.Reset();
            }
        }
Пример #4
0
        public void DeleteCabinetData(int id)
        {
            // Get the cabinet data
            var deletedCabinet = Cabinet.Get(id);

            // Calculate how many lockers in the cabinet
            int numberOfLockers = deletedCabinet.Row * deletedCabinet.Column;

            // Get all data of lockers for this cabinet
            List <Locker> lockers = Locker.Where(String.Format("cabinet_id = {0}", id), 0, numberOfLockers);

            // Check any locker was booked for rental. If yes, show error.
            foreach (Locker locker in lockers)
            {
                if (Rental.Count(String.Format("locker_id = {0} AND status <> 'Ended'", locker.Id)) > 0)
                {
                    throw new InvalidUserInputException("Delete Error - Cabinet Locker Booked");
                }
            }

            // Disable the cabinet
            deletedCabinet.TempDelete();

            // Disable Lockers belong to that cabinet
            foreach (Locker deletedLocker in lockers)
            {
                deletedLocker.TempDelete();
            }
        }
Пример #5
0
        public void ResetLocker(string lockerCode)
        {
            string        lockerCodeCondition = String.Format("code = '{0}'", lockerCode);
            List <Locker> lockers             = Locker.Where(lockerCodeCondition, 0, 1);
            var           locker = lockers[0];

            // Check if locker is already available, if yes, ignore.
            if (locker.IsAvailable())
            {
                return;
            }

            //Check if locker occupied / overdued, if yes, show error message.
            if (locker.IsOccupied() || locker.IsOverdued())
            {
                throw new InvalidUserInputException("Reset Error - Locker Occupied");
            }

            locker.Reset();

            //Check was the cabinet full. If yes, set to available.
            var selectedCabinet = Cabinet.Get(locker.CabinetId);

            if (selectedCabinet.IsFull())
            {
                selectedCabinet.Restore();
            }
        }
Пример #6
0
        public void DisableLocker(string lockerCode)
        {
            string        lockerCodeCondition = String.Format("code = '{0}'", lockerCode);
            List <Locker> lockers             = Locker.Where(lockerCodeCondition, 0, 1);
            var           locker = lockers[0];

            if (locker.IsNotAvailable())
            {
                throw new InvalidUserInputException("Disable Error - Locker Disabled");
            }
            else if (Rental.Count(String.Format("locker_id = {0} AND status <> 'Ended'", locker.Id)) > 0)
            {
                throw new InvalidUserInputException("Disable Error - Locker Booked");
            }
            else
            {
                locker.NotAvailable();

                //Check is the cabinet full. If yes, update and insert log.
                int noOfEmptyLocker = Locker.Count(String.Format("cabinet_id = {0} AND status = 'Available'",
                                                                 lockers[0].CabinetId));
                if (noOfEmptyLocker <= 0)
                {
                    var cabinet = Cabinet.Get(lockers[0].CabinetId);
                    cabinet.Full();
                }
            }
        }
Пример #7
0
        // Constructor for View Rental
        public SelectLockerForm(int rentalId)
        {
            InitializeComponent();

            // Get all data related to the rental
            _rental     = Rental.Get(rentalId);
            _locker     = Locker.Get(_rental.LockerId);
            _cabinet    = Cabinet.Get(_locker.CabinetId);
            _lockerType = LockerType.Get(_cabinet.LockerTypeId);

            // Set the start date and end date of rental
            _startDate = _rental.StartDate;
            _endDate   = _rental.EndDate;

            // Clear combo box  & locker type dictonary to avoid error
            _lockerTypeDictonary.Clear();

            // Only add the involved locker type into the directonary
            _lockerTypeDictonary.Add(_lockerType.Id, _lockerType.Name);

            // Bind locker type dictonary onto combo box locker type locker cabinet (In Locker Module)
            comboBoxLockerTypeLockerCabinet.DataSource = new BindingSource(_lockerTypeDictonary, null);

            // Display the Locker Type Name and Set the Locker Type Id as ValueMember
            comboBoxLockerTypeLockerCabinet.DisplayMember = "Value";
            comboBoxLockerTypeLockerCabinet.ValueMember   = "Key";

            // Trigger SelectedIndexChanged event
            comboBoxLockerTypeLockerCabinet.SelectedIndex = -1;

            // Select the invloved locker type
            comboBoxLockerTypeLockerCabinet.SelectedIndex = 0;

            // Disable the comboBox
            comboBoxLockerTypeLockerCabinet.Enabled = false;

            // Load all cabinet list
            _lockerCabinetPage.PageNumber = 1;
            LockerCabinetPage();

            //Default select the involved cabinet to load
            textBoxCabinetCode.Text = _cabinet.Code;

            // Get the available lockers for the selected cabinet
            CabinetLockerController cabinetLockerController = new CabinetLockerController();
            List <Locker>           availableLockers        = cabinetLockerController.GetAvailableLockers(_cabinet.Id, _startDate, _endDate);

            textBoxEmptyLockerNo.Text = availableLockers.Count.ToString();

            _lockerPage.PageNumber = 1;
            LockerPage(availableLockers);
        }
        // Method to End the Rental;
        public void EndRental()
        {
            // End the rental
            _rental.End();

            // Set the Locker to Available
            Locker locker = Locker.Get(_rental.LockerId);

            locker.Reset();

            // Check is the cabinet full, if yes, set it as available
            Cabinet cabinet = Cabinet.Get(locker.CabinetId);

            if (cabinet.IsFull())
            {
                cabinet.Restore();
            }
        }
Пример #9
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();
                }
            }
        }
Пример #10
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();
            }
        }
Пример #11
0
        // Constructor for End Rental
        public RentalForm(Rental rental)
        {
            InitializeComponent();

            // Hide all tabs not related to End Rental
            this.Controls.Remove(tabControlRental);
            this.Controls.Add(panelEndRental);

            // Set rental data
            _rental = rental;

            // Get data related to the rental
            _customer   = Customer.Get(_rental.CustomerId);
            _locker     = Locker.Get(_rental.LockerId);
            _cabinet    = Cabinet.Get(_locker.CabinetId);
            _lockerType = LockerType.Get(_cabinet.LockerTypeId);

            // Insert the data into display fields
            EndRentalLoadRentalData();
        }
Пример #12
0
        //  Methods
        public void ValidateQr(string qrString)
        {
            _qrString = qrString;
            _cabinet  = Cabinet.Where(String.Format("code = '{0}'", _cabinetCode), 0, 1)[0];

            string rentalCondition   = String.Format("rental_key ='{0}'", _qrString);
            string employeeCondition = String.Format("master_key = '{0}'", _qrString);

            // Check if the QR Code belong to any rental or employee
            List <Rental>   rentals   = Rental.Where(rentalCondition, 0, 1);
            List <Employee> employees = Employee.Where(employeeCondition, 0, 1);

            // If the QR Code does not belong to any rental / employee, show error
            if (!rentals.Any() && !employees.Any())
            {
                throw new InvalidQRCodeException("Invalid QR");
            }
            else
            {
                if (rentals.Any())
                {
                    _rental      = rentals[0];
                    _isMasterKey = false;

                    if (_rental.IsEnded())
                    {
                        throw new InvalidQRCodeException("Ended QR");
                    }
                    else if (_rental.IsOverdue())
                    {
                        // Calculate the overdue days
                        TimeSpan overdueTime = DateTime.Now.Date.Subtract(_rental.EndDate.Date);
                        int      overdueDays = overdueTime.Days;

                        // Get the overdue locker data
                        _locker = Locker.Get(_rental.LockerId);

                        throw new InvalidQRCodeException("Overdue QR", overdueDays.ToString(), _locker.Code);
                    }
                    else if (_rental.IsNotStarted())
                    {
                        throw new InvalidQRCodeException("Not Started QR");
                    }
                    else
                    {
                        _locker  = Locker.Get(_rental.LockerId);
                        _cabinet = Cabinet.Get(_locker.CabinetId);

                        if (!_cabinet.Code.Equals(_cabinetCode))
                        {
                            throw new InvalidQRCodeException("Incorrect Cabinet");
                        }
                    }
                }
                else
                {
                    _employee = employees[0];
                    if (_employee.IsDisabled())
                    {
                        throw new InvalidQRCodeException("Deactivated Master QR");
                    }
                    else if (_employee.IsDefault())
                    {
                        throw new InvalidQRCodeException("Inactive Master QR");
                    }
                    else
                    {
                        _isMasterKey = true;
                    }
                }
            }
        }