private void SlotSelected(System.Object sender, System.EventArgs e)
        {
            Employee employee = default(Employee);
            Button   button   = default(Button);
            int      whichShift;


            button = (Button)sender;

            employee = (Employee)waitersComboBox.SelectedItem;
            //Cannot book a slot if NO employee(waitron) is selected
            if (employee == null)
            {
                MessageBox.Show("First select a Waiter for the shift");
            }
            else
            {
                whichShift = (Convert.ToInt32(button.Tag) / 6) * 2 + (Convert.ToInt32(button.Tag) % 6) / 3;
                if (shiftController.AddEmployeeToShift(whichShift, employee))
                {
                    button.Text      = employee.Name;
                    button.BackColor = Color.Red;
                    button.Click    -= SlotSelected;
                }
            }
        }
예제 #2
0
        private void SlotSelected(System.Object sender, System.EventArgs e)
        {
            int      whichShift;
            Employee employee = default(Employee);
            Button   button   = default(Button);

            //***The sender (control that was click-ed) is a button
            button = (Button)sender;
            //Select an Employee (Waiter) from the combobox
            employee = (Employee)waitersComboBox.SelectedItem;
            //Cannot book a slot if NO employee(waiter) is selected
            if (employee == null) // To DO:  test if the employee object is null)
            {
                //To DO:  display a message to the user to select a waiter
                MessageBox.Show("First select a Waiter for the shift");
            }
            else
            {
                button.AccessibleName = employee.ID;
                //***Calculate on which shift to schedule the employee (depends on the button click and whether Day or Evening shift
                whichShift = (Convert.ToInt32(button.Tag) / 6) * 2 + (Convert.ToInt32(button.Tag) % 6) / 3;
                if (shiftController.AddEmployeeToShift(whichShift, employee))
                {   //…..colour block;  write name
                    button.Text      = employee.Name;
                    button.BackColor = Color.Red;
                    //***ONCE booked, the button cannot be selected again
                    //***Disable the button --- not to be clicked again
                    button.Click += DeSelected;
                    button.Click -= SlotSelected;     //Form not listening to the click event method of the button
                }
            }
        }