- Create a new form named frmSchedule with the Text property as “Schedule”. Add a panel object and dock it on top of the form, adjust its height so that it does not take too much space on the form. Add two combo boxes to the panel object named cboStaffName and cboClientName. Add label objects to
the immediate left of each combo box with the Text properties “Staff” and “Client”, respectively. Add a DataGridView object to the form below the panel, change its name to dgvSchedule, and dock it in parent container to occupy the remaining space.
- In the code page for frmSchedule, declare public properties Info as string, Schedule as new sorted list of string type keys and list of decimal type values (i.e. SortedList(Of String, List(Of Decimal))), and BgColor as Color. Also declare public properties StaffSList as sorted list of string type keys and Staff type values, ClientSList as sorted list of string type keys and Client type values, and TaskList as a list of Task values.
- Create a public sub called DrawGrid. In this sub, first clear the Rows collection of dgvSchedule, then clear the Columns collection of dgvSchedle. Include an if-then structure, where if the Count property of Schedule property is zero, then exit the sub. Declare variable maxWeek as integer and assign to it Schedule.Values(0).Count. Set the ColumnCount property of dgvSchedule to maxWeek + 1 (to display the names of staff of clients in the first column and display the hours in the remaining columns). Set the dgvSchedule.Columns(0).Name equal to “Week”. Create a for-loop with counter variable from 1 to maxWeek. In the loop, assign the loop variable to dgvSchedule.Columns(i).Name. Note that dgvSchedule has one row by default. After the loop, if Schedule.Count is greater than 1, then add additional rows by dgvSchedule.Rows.Add(Schedule.Count – 1). Declare a variable called rownum as integer and initialize it to 0. Add a for-each loop over the keys collection of Schedule to create the rows of the schedule grid. In this loop, assign the loop variable to dgvSchedule.Rows(rownum).Cells(“Week”).Value. Include an inner for-loop with counter variable i from 1 to maxWeek. In the inner loop, declare a variable as decimal and assign Schedule(key)(i – 1). If the variable is greater than 0, then assign this variable to dgvSchedule.Rows(rownum).Cells(i).Value, then assign BgColor to dgvSchedule.Rows(rownum).Cells(i).Style.BackColor. After the inner loop (and still inside the outer loop), increment rownum by 1. After the outer loop, set the AutoSizeColumnsMode property of dgvSchedule equal to DataGridViewAutoSizeColumnsMode.AllCells.
- Create a public sub called CreateSchedule with a single string parameter called type. In this sub, declare a variable called currStaff as Staff, currClient as Client, and currAssignmentList as a list of Assignment type values. Include an if-elseif structure. If the type parameter equal “Staff” then assign the value corresponding to the key cboStaffName.Text in StaffSList to currStaff; assign currStaff.AssignmentList to currAssignmentList; concatenate the Last, First and StaffClass properties of currStaff (with a comma between First and Last and parentheses around StaffClass) as a string and assign this string to Info; assign a color of your preference (e.g. Color.Green) to BgColor. Else if the type parameter equal “Client” then assign the value corresponding to the key cboClientName.Text in ClientSList to currClient; assign currClient.AssignmentList to currAssignmentList; assign the Name property of currClient to Info; assign a color of your preference (different that of Staff in the if case) to BgColor. After the if-elseif structure, first clear the sorted list Schedule. Create a for-each loop over currAssignmentList. In this loop, include an if-then structure to check if the Assigned property of the loop variable equals True. Inside the if-then structure, declare a variable called hourList as a new list of
decimal type values. Include a LINQ query over TaskList where the StaffClassID of the query variable equals the StaffClassID property of the Staff property of the loop variable AND the ClientID property of the query variable equals the ClientID property of the Client property of the loop variable, ordered by the Week property of the link variable. Include an inner for-each loop over the output of this LINQ query. In this inner loop, add the Hours property of the loop variable to hourList. After the loop, declare a string type variable to create a key. Using an inner if-elseif structure, check if the type parameter of CreateSchedule equals “Staff”. Under the if case, set key to be the Name property of the Client property of the outer loop variable. For the else if case, check if type parameter equals “Client”; under this case, set the key to be concatenation of the Last, First and StaffClass properties of the Staff property of the outer loop variable (with a comma between Last and First and parentheses around StaffClass). After the if-elseif structure, use this key and hourList as value to add to the sorted list Schedule at the end of the outer if-structure. After the outer for-each loop, call the sub DrawGrid.
- Create a public sub called Initialize. In this sub, clear the items collection of cboStaffName, populate cboStaffName using a for each loop over the Keys collection of StaffSList, and finally select the first item in cboStaffName. Then repeat the same for cboClientName. In the design view of frmSchedule, double- click on cboStaffName to create its SelectedIndexChanged event handler. In this event handler, call CreateSchedule with the parameter “Staff”. Repeat the same with cboClientName, this time calling CreateSchedule with the parameter “Client” in its respective event handler.
- In the code page for frmDashboard, create a public sub called ShowSchedule. In this sub, create a variable named scheduleForm as frmSchedule and call GetForm function of the MainForm property of frmDashboard using the parameter “Schedule” and assign it to scheduleForm. Assign StaffSList, ClientSList, TaskList properties of frmDashboard class to the properties of scheduleForm with the corresponding names. Then call Initialize sub of scheduleForm followed by Show and BringtoFront subs of scheduleForm.
- Create a button on frmDashboard called btnShowSchedule with the Text property “Show Schedule”.
Double-click on this button to create its Click even handler. In this even handler, call the sub ShowSchedule. In the code page for frmMain, create a case called “Schedule” in the select-case structure inside UpdateFormSList, and under this case, assign a new instance of frmSchedule to
FormSList(formName). In the sub InitializeFormSList, include a line to add the key “Schedule” with value
Nothing inside the With structure.
- In the design view of frmMain, under the top-level menu item called “Analysis” and below the sub- menu item “Client Analysis”, create a menu item called “Show Schedule”. Double-click on this menu item to create its event handler. In this even handler, add an if-then structure to check if the call to DatabaseLoaded function equals true. Inside the if-then structure, create a variable of type frmDashboard and call GetForm with parameter “Dashboard” to assign to this variable. Call BringToFront sub of this variable followed by the ShowSchedule sub of this variable.
This assignment has been answered 5 times in private sessions.
Or buy a ready solution below.
© 2023 Codify Tutor. All rights reserved