Exemplo n.º 1
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();
            }
        }
Exemplo n.º 2
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();
        }
Exemplo n.º 3
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);
        }
        public void DeleteLockerTypeData(int id)
        {
            // Check if any cabinet exists for this locker type. If yes, show error.
            if (Cabinet.Count(String.Format("locker_type_id = {0} AND status <> 'Disabled'", id)) > 0)
            {
                throw new InvalidUserInputException("Delete Error - Locker Type Cabinet");
            }

            // Delete the locker type
            LockerType deletedLockerType = LockerType.Get(id);

            deletedLockerType.TempDelete();
        }
Exemplo n.º 5
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();
                }
            }
        }
Exemplo n.º 6
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();
            }
        }
Exemplo n.º 7
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();
        }
        // Constructor for Edit Locker Type
        public LockerTypeForm(int id)
        {
            InitializeComponent();

            // Hide labels not related to Edit Locker Type
            labelAddLockerType.Hide();

            // Lock Name and Code input
            textBoxName.ReadOnly = true;
            textBoxCode.ReadOnly = true;

            // Declare this operation is not insert new locker
            _isNewInsert = false;

            // Get the Locker Type Data for this id
            _lockerType = LockerType.Get(id);

            // Load data into Input Field
            textBoxName.Text = _lockerType.Name;
            textBoxCode.Text = _lockerType.Code;
            numericUpDownRentalRate.Value = _lockerType.Rate;
        }
        public void RestoreLockerTypeData(int id)
        {
            LockerType lockerType = LockerType.Get(id);

            lockerType.Restore();
        }