- Find a relatively empty map of the US or one of its states by searching for the phrase “empty map of
<place name>”, where <place name> is replaced by your preferred place like “the US”, “Virginia”, “California”, etc. Right-click and save this image to your project folder. In Visual Studio, go to menu Project > ClientStaffing Properties, open Resources, then click on the arrow next to Add Resource,
choose “Add Existing Item”, browse to the project folder and select your empty map image. Then you will see that a small icon of the map is created under the Resources window. Click on Save All. Double- click on this icon to open up this image in Visual Studio. Note that as you move your mouse cursor across the image, you will see the coordinates of the cursor in pixels at the middle bottom of the Visual Studio window. Open a new Excel workbook, name the first four columns of a worksheet as ID, Name, XCoord and YCoord. Number rows from 1 to 30 in the first column. Determine about 30 places of interest on this empty map (generally cities, towns, schools, etc) and write them next to each row, record their pixel coordinates in columns XCoord and YCoord in their respective row. Name the worksheet “Location”, save the Excel file in your project folder. Open your Access database with your input tables (Staff, Client, Task and Assignment). Import the Excel table in worksheet Location similar to the previous tables into your database with ID being the primary key and Location being the table name. In the database table, change the column name Branch in table Staff to Location. Then change number in the Location column of Staff table and also the Location column of Client tables such that each number is unique between 1 and 30 and randomly distributed across both tables (i.e. numbers do not overlap even across the two tables) to prevent overlapping results.
- Create a new Class called Location with the public properties ID as integer, Name as string, XCoord as Integer and YCoord as Integer. In the Database Class, define a public property called LocationDA as OleDbDataAdapter. Create a function called GetLocations, which returns a sorted list of Integer type keys and Location type values. Similar to functions like GetStaff or GetClients, this function uses a locally declared variable as a new sorted list of integer keys and Location type values. It uses GetDataAdapter to select all the information in the Location table to LocationDA property of the Database Class and uses this data adapter to fill a table named “Location” in MyDataSet. Then, similar to GetStaff or GetClients, it uses a for-loop to create a new instance of the Location class, read the values from columns ID, Name, XCoord and YCoord and assigns them to the corresponding properties of this instance, and finally adding this instance with its ID number as key the instance itself as the value to the sorted list. After the for- loop it returns the sorted list. Change the Branch property of Staff to Location in the Staff Class.
Likewise, in GetStaff function in Database Class, change the column name “Branch” to “Location”. In the code page for frmDashboard, declare a public property called LocationSList as sorted list of integer type keys and Location type values; in the sub Initialize assign DB.GetLocations to LocationSList (right above the loops to populate the combo boxes). In the design view of frmDashboard, open up the Items collection of lstData in the properties window and type Location at the end of the list.
- Create a new form called frmMap with Text property as “Map”. 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 another Panel object to the form below the panel, change its name to pnlMap, and dock it in parent container to occupy the remaining space.
- In the code page for frmMap create 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, LocationSList as sorted list of integer type keys and Location type values. To bring the names and coordinates of the entities to be drawn on the map, create private properties Center as string, XCoord as integer, YCoord as integer, NeighborList as new list of string, XCoordList as new list of integer values, YCoordList as new list of integer values. Furthermore create the private property MapImage as Image and assign My.Resources.<mapname>, where <mapname> is the name of the map you placed under the Resources page of your project earlier. Create private properties XScale as decimal and YScale as decimal for rescaling the map.
- Create a public sub called GetCoordinates with a single parameter called type as string. In this sub, first clear NeighborList, XCoordList, and YCoordList. Include an if-elseif structure. In the if case check if parameter type equals “Staff”. Under the if case, declare a variable as Staff to represent the selected staff, and assign the value corresponding the key cboStaffName.Text to this variable. Concatenate Last and First properties of the selected staff variable with a comma+space in between and assign it to the Center property of frmMap class. Create a variable to represent the location of the selected staff variable as Location type, and assign the value in LocationSList that corresponds to the Location property of the selected staff variable as the key. Assign the XCoord and YCoord properties of the location variable to XCoord and YCoord properties of frmMap, respectively. Create a for-each loop over the AssignmentList of the selected staff variable. If the Assigned property of the loop variable equals true, then inside the if-then structure, add the Name property of the Client property of the loop variable to NeighborList; declare a variable for neighbor location as Location type and assign the value from LocationSList for the Location property of the Client property of the loop variable as the key to this variable. Add the XCoord and YCoord properties of the neighbor location variable to XCoordList and YCoordList, respectively. The Elseif case of the outer if-elseif structure, when type parameter equals “Client”, has a very similar structure by swapping Client with Staff (and vice versa), ClientSList with StaffSList and using a concatenation of Last and First properties of the Staff property of the loop variable with a comma+space in between to add to the NeighborList.
- Refer to lecture W11A-NetworkMap. Copy sub DrawNode from the frmMap class of the project for the lecture W11A to the frmMap class of your final project. Replace the first parameter (n As Node) with three parameters: name as String, xcrd as integer and ycrd as integer; keep the other parameters the same. Replace Text.Count and n.ID with name.Count; replace n.Xcoord with xcrd, and n.Ycoord with ycrd. Remove the lines that contain FillEllipse and DrawEllipse; instead include the following two lines right before the line e.Graphics.DrawString(name, aFont, textBrush, tx, ty): e.Graphics.DrawRectangle(borderPen, tx, ty, textwidth, size)
e.Graphics.FillRectangle(fillBrush, tx, ty, textwidth, size).
Similarly, copy sub DrawArc from the frmMap class of the project for the lecture W11A to the frmMap of your final project. Replace the first parameter (a as Arc) with the parameters begx as integer, begy as integer, endx as integer, and endy as integer. In this sub, replace a.Tail.Xcoord with begx, a.Tail.Ycoord with begy, a.Head.XCoord with endx, and a.Head.YCoord with endy.
- In the design view of frmMap, double-click on pnlMap to create the Paint event handler. Refer the the Panel2.Paint event handler sub in frmMap class of lecture W11A project. Copy the code in this sub from the beginning until the first for-each loop (excluding the loop) to the Paint event handler of pnlMap in your final project. Replace all occurrences of Panel2 with pnlMap. Then in the event handler, create a
for-loop with a counter variable i from 0 to NeighborList.Count – 1. Inside this loop, call DrawArc with the parameters XCoord, YCoord, XCoordList(i), YCoordList(i), Color.Black, 2, False, e. Then, call DrawNode with parameters NeighborList(i), XCoordList(i), YCoordList(i), Color.Black, Color.<of your choice>,Color.Black, e. After the loop, call DrawNode with parameters Center, XCoord, YCoord, Color.Black, Color.<of a different choice>, Color.Black, e.
- 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 frmMap, double-click on cboStaffName to create the event handler for SelectedIndexChanged event. In this event handler, call GetCoordinates with the parameter “Staff” and then call the Refresh sub of pnlMap. Do the same for
cboClientName using the parameter “Client” for GetCoordinates followed by Refresh sub of pnlMap.
- In the code page for frmDashboard, create a public sub called ShowMap. In this sub, create a variable named mapForm as frmMap and call GetForm function of the MainForm property of frmDashboard with the parameter “Map” and assign it to scheduleForm. Assign StaffSList, ClientSList, LocationSList properties of frmDashboard class to the properties of mapForm with the corresponding names. Then call Initialize sub of mapForm followed by Show and BringtoFront subs of mapForm.
- Create a button on frmDashboard called btnShowMap with the Text property “Show Map”. Double- click on this button to create its Click even handler. In this even handler, call the sub ShowMap. In the
code page for frmMain, create a case called “Map” in the select-case structure inside UpdateFormSList, and under this case, assign a new instance of frmMa to FormSList(formName). In the sub
InitializeFormSList, include a line to add the key “Map” 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 “Show Schedule”, create a menu item called “Show Ma”. 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 ShowMap 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