private void ShiftsMonthCalendar_DateSelected(object sender, DateRangeEventArgs e) { System.DateTime aDate = default(System.DateTime); //Calendar control functions to set the Start and End date startDate = shiftsMonthCalendar.SelectionRange.Start; endDate = shiftsMonthCalendar.SelectionRange.End; //***Add control array, ShiftDates, to show the dates of the shifts shiftDates = new BlockArray(this, 50, 100, 200, 1); aDate = startDate; int intcnt = 0; for (intcnt = 0; intcnt <= 6; intcnt++) { shiftDates.AddNewBlock(); shiftDates.Item(intcnt).BackColor = Color.White; shiftDates.Item(intcnt).Text = aDate.ToShortDateString(); //Show date on Button aDate = aDate.AddDays(1); //**This function allows you to go to the NEXT day } //***Add a block for each slot on all the shifts – ShiftBookings control array shiftBookings = new BlockArray(this, 50, 100, 300, 6); for (intcnt = 0; intcnt <= 41; intcnt++) { shiftBookings.AddNewBlock(); if (intcnt % 6 > 2) { shiftBookings.Item(intcnt).BackColor = Color.Turquoise; } //*** ONLY 4 slots on a SUNDAY (2 slots per shift) if (intcnt == 2 || intcnt == 5) { shiftBookings.Item(intcnt).BackColor = Color.DarkSlateGray; // shiftBookings.Item(intcnt).Enabled = false; } else { //***NB NB Add a click event dynamically to make button respond on the click of the user NB NB shiftBookings.Item(intcnt).Click += SlotSelected; } } shiftsMonthCalendar.Visible = false; calendarMessageLabel.Visible = false; FillCombo(); //workshop 7 SHIFT CONTROLLER METHOD WILL BE CALLED HERE TO SAVE NEW SHIFT TO MEMORY AND shiftController.NewShedule(startDate, endDate); //THEN WRITE TO DATABASE--LATER ShowControls(true); }
private void ShiftsMonthCalendar_DateSelected(object sender, DateRangeEventArgs e) { System.DateTime aDate = default(System.DateTime); // Find the systems date //Calendar control functions to set the Start and End date startDate = shiftsMonthCalendar.SelectionRange.Start; endDate = shiftsMonthCalendar.SelectionRange.Start; //***Add control array, ShiftDates, to show the dates of the shifts – instantiate with parameters shiftDates = new BlockArray(this, 50, 100, 400, 1); //these blocks will appear in a column aDate = startDate; int intcnt = 0; for (intcnt = 0; intcnt <= 6; intcnt++) { shiftDates.AddNewBlock(); shiftDates.Item(intcnt).BackColor = Color.White; shiftDates.Item(intcnt).Text = aDate.ToShortDateString(); //Display the date on the Button aDate = aDate.AddDays(1); //**This function allows you to go to the NEXT day } //***Add a block for each slot on all the shifts (6 slots) – ShiftBookings control array shiftBookings = new BlockArray(this, 50, 100, 500, 6); for (intcnt = 0; intcnt <= 41; intcnt++) // Why 41 blocks? W7-Q1 { // Add a new block for the shiftBooking shiftBookings.AddNewBlock(); // Afternoon slots should be turquoise (HINT: 6 blocks, use the remainder operator) if (intcnt % 6 > 2) { shiftBookings.Item(intcnt).BackColor = Color.Turquoise; } //*** ONLY 4 slots on a SUNDAY (indices 2 or 5)– ie 2 slots per shift, 2 INACTIVE Slots // ***the colours of these blocks (identify the indices) will change to Color.DarkSlateGray if (intcnt == 2 || intcnt == 5) { shiftBookings.Item(intcnt).BackColor = Color.DarkSlateGray; } else { //A click event to be added dynamically to make button respond on user click // subscribe to the eventhandler event for ALL slots except INACTIVE ones shiftBookings.Item(intcnt).Click += SlotSelected; } } // Hide the calendar & the message below the calendar shiftsMonthCalendar.Visible = false; calendarMessageLabel.Visible = false; // ***Call the method to fill the Combo box – the list of waiters becomes the datasource FillCombo(); //Call NewSchedule ShiftController method to create a ShiftBookings array in memory shiftController.NewShedule(startDate, endDate); //Show controls for ComboBox and labels ShowControls(true); }