Exemplo n.º 1
0
        private void DeSelected(System.Object sender, System.EventArgs e)
        {
            Employee waiter     = default(Employee);
            Button   button     = default(Button);
            int      whichShift = 0;

            button = (Button)sender;

            System.Windows.Forms.DialogResult response = default(System.Windows.Forms.DialogResult);
            response = MessageBox.Show("Are you sure you want to de-select? ", "De-Select Shift", MessageBoxButtons.YesNo);

            //1.***Allow the manager to decide whether he really wants to change
            if (response == System.Windows.Forms.DialogResult.Yes)
            {
                //2.***Swap the Dynamic event handling routines
                button.Click -= DeSelected;
                button.Click += SlotSelected;
                //3.***Use the AccessibleNamefield of the button to store the employee ID
                waiter = employeeController.Find(button.AccessibleName);
                //4.***Add the waitron back to the combobox if it was already taken out
                if (shiftController.GetShiftCount(waiter) == 5)
                {
                    waitersComboBox.Items.Add(waiter);
                    eventsMessageLabel.Visible = false;
                }
                //5.***Find the right shift and remove the waitron from that shift
                whichShift = (Convert.ToInt32(button.Tag) / 6) * 2 + (Convert.ToInt32(button.Tag) % 6) / 3;
                shiftController.RemoveEmployeeFromShift(whichShift, waiter);
                //6***Reset the blocks to what it looked like BEFORE it was selected
                button.Text           = "";
                button.AccessibleName = "";
                if (whichShift % 2 == 0)
                {
                    button.BackColor = Color.LightGoldenrodYellow;
                }
                else
                {
                    button.BackColor = Color.Turquoise;
                }
            }
        }