Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Imports System.Runtime.InteropServices
- Public Class Form1
- Dim a As Boolean = False
- Public doc As XDocument = XDocument.Load("ScheduleConfig.xml")
- Public firstschedule As XDocument = New XDocument(New XElement("firstschedule"))
- 'Section 1: Adding Grade Levels
- Private Sub GradeLevelsButton_Click(sender As Object, e As EventArgs) Handles GradeLevelsButton.Click 'When the Add button is clicked
- Dim gl As XElement = New XElement("gradelevel") 'Declare the <gradelevel> tag
- Dim pass As Boolean = True 'If the name for the grade level is valid, then true, or else false
- For Each x As String In GradeLevelsBox.Items
- If x.Equals(GradeLevelsTextBox.Text) Then 'Invalid grade level name: there's already one with the same name
- MsgBox("There is already a grade with the same name.", MsgBoxStyle.Critical)
- pass = False
- ElseIf x.Equals("") Then 'Invalid grade level name: it's empty
- MsgBox("The grade name is empty.", MsgBoxStyle.Critical)
- pass = False
- End If
- Next
- If pass = True Then 'If the name for the grade level is valid
- gl.SetAttributeValue("name", GradeLevelsTextBox.Text) 'Add the name attribute to <gradelevel>
- GradeLevelsBox.Items.Add(GradeLevelsTextBox.Text) 'Add the grade level to the listbox
- doc.Root.Add(gl) 'Add <gradelevel> to the XDocument
- End If
- End Sub
- Private Sub GradeLevelsBox_Click() Handles GradeLevelsBox.Click 'When the GradeLevels listbox is clicked
- If GradeLevelsBox.SelectedItem = Nothing Then 'If nothing is selected, disable everything in the grade level editor
- MandatoryClassBox.Enabled = False
- OptionalClassBox.Enabled = False
- MandatoryTextBox.Enabled = False
- OptionalTextBox.Enabled = False
- MandatoryButton.Enabled = False
- OptionalButton.Enabled = False
- Button3.Enabled = False
- Else 'If something is selected
- MandatoryClassBox.Enabled = True 'Enable everything in the grade level editor
- OptionalClassBox.Enabled = True
- MandatoryTextBox.Enabled = True
- OptionalTextBox.Enabled = True
- MandatoryButton.Enabled = True
- OptionalButton.Enabled = True
- Button3.Enabled = True
- GradeLevelEdit_Load()
- End If
- End Sub
- Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load 'When the program opens up
- For Each a As XElement In doc.Root.Elements() 'Iterate through the XElements in the root element (<schedule>)
- If a.Name = "gradelevel" Then 'If the <gradelevel> element is found
- GradeLevelsBox.Items.Add(a.FirstAttribute.Value) 'Add the value of the name attribute to the grade level listbox
- End If
- Next
- GroupBox3.Visible = True 'Position the following groupboxes to their respected positions and visibilities
- GroupBox3.Location = New Point(460, 105)
- GroupBox2.Visible = True
- GroupBox2.Location = New Point(0, 137)
- GroupBox4.Visible = True
- GroupBox4.Location = New Point(0, 358)
- GroupBox5.Visible = False
- End Sub
- Private Sub GradeLevelsBox_SelectedIndexChanged(sender As Object, e As EventArgs) Handles GradeLevelsBox.SelectedIndexChanged
- GroupBox3.Text = GradeLevelsBox.SelectedItem
- If GradeLevelsBox.SelectedItem = Nothing Then
- MandatoryClassBox.Enabled = False
- OptionalClassBox.Enabled = False
- MandatoryTextBox.Enabled = False
- OptionalTextBox.Enabled = False
- MandatoryButton.Enabled = False
- OptionalButton.Enabled = False
- Button3.Enabled = False
- GradeLevelEdit_Load()
- Else
- MandatoryClassBox.Enabled = True
- OptionalClassBox.Enabled = True
- MandatoryTextBox.Enabled = True
- OptionalTextBox.Enabled = True
- MandatoryButton.Enabled = True
- OptionalButton.Enabled = True
- Button3.Enabled = True
- MandatoryClassBox.Items.Clear()
- OptionalClassBox.Items.Clear()
- GradeLevelEdit_Load()
- End If
- End Sub
- ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
- 'Section 2: Editing Schedule Properties
- Private Sub CheckBox1_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox1.CheckedChanged
- If CheckBox1.Checked Then
- LunchPeriodLength.Enabled = False
- Else
- LunchPeriodLength.Enabled = True
- End If
- End Sub
- Private Sub PeriodNumber_ValueChanged(sender As Object, e As EventArgs) Handles PeriodNumber.ValueChanged
- If PeriodNumber.Value < MandatoryClassBox.Items.Count Then
- PeriodNumberError.Visible = True
- Else
- PeriodNumberError.Visible = False
- End If
- End Sub
- Private Sub DeveloperLogsToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles DeveloperLogsToolStripMenuItem.Click
- DevLogs.Show()
- End Sub
- '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
- 'Section 3: Editing Grade Levels
- Private Sub MandatoryButton_Click(sender As Object, e As EventArgs) Handles MandatoryButton.Click
- Dim mc As XElement = New XElement("mandatory-class")
- Dim pass As Boolean = True
- For Each x As String In MandatoryClassBox.Items
- If x.Equals(MandatoryTextBox.Text) Or x.Equals(OptionalTextBox.Text) Then
- MsgBox("There is already a class with the same name.", MsgBoxStyle.Critical)
- pass = False
- End If
- Next
- For Each x As String In OptionalClassBox.Items
- If x.Equals(MandatoryTextBox.Text) Or x.Equals(OptionalTextBox.Text) Then
- MsgBox("There is already a class with the same name.", MsgBoxStyle.Critical)
- pass = False
- End If
- Next
- If pass = True Then
- mc.SetAttributeValue("name", MandatoryTextBox.Text)
- MandatoryClassBox.Items.Add(MandatoryTextBox.Text)
- MandatoryTextBox.Text = ""
- OptionalTextBox.Text = ""
- For Each a As XElement In doc.Root.Descendants()
- If a.Name = "gradelevel" Then
- If a.FirstAttribute.Value = GradeLevelsBox.SelectedItem Then
- a.Add(mc)
- End If
- End If
- Next
- If PeriodNumber.Value < MandatoryClassBox.Items.Count Then
- PeriodNumberError.Visible = True
- Else
- PeriodNumberError.Visible = False
- End If
- End If
- End Sub
- Private Sub OptionalButton_Click(sender As Object, e As EventArgs) Handles OptionalButton.Click
- Dim oc As XElement = New XElement("optional-class")
- Dim pass As Boolean = True
- For Each x As String In OptionalClassBox.Items
- If x.Equals(OptionalTextBox.Text) Or x.Equals(MandatoryTextBox.Text) Then
- MsgBox("There is already a class with the same name.", MsgBoxStyle.Critical)
- pass = False
- ElseIf x.Equals("") Then
- MsgBox("The class name is empty.", MsgBoxStyle.Critical)
- End If
- Next
- For Each x As String In MandatoryClassBox.Items
- If x.Equals(OptionalTextBox.Text) Or x.Equals(MandatoryTextBox.Text) Then
- MsgBox("There is already a class with the same name.", MsgBoxStyle.Critical)
- pass = False
- ElseIf x.Equals("") Then
- MsgBox("The class name is empty.", MsgBoxStyle.Critical)
- End If
- Next
- If pass = True Then
- oc.SetAttributeValue("name", OptionalTextBox.Text)
- OptionalClassBox.Items.Add(OptionalTextBox.Text)
- MandatoryTextBox.Text = ""
- OptionalTextBox.Text = ""
- For Each a As XElement In doc.Root.Descendants()
- If a.Name = "gradelevel" Then
- If a.FirstAttribute.Value = GradeLevelsBox.SelectedItem Then
- a.Add(oc)
- End If
- End If
- Next
- End If
- End Sub
- Private Sub MandatoryClassBox_SelectedIndexChanged(sender As Object, e As EventArgs) Handles MandatoryClassBox.SelectedIndexChanged
- Try
- GroupBox4.Enabled = True
- GroupBox4.Text = MandatoryClassBox.SelectedItem.ToString()
- ClassLevels.Items.Clear()
- For Each a As XElement In doc.Root.Elements()
- 'MsgBox("I can hear the drummers drumming: " + a.ToString)
- If a.Name = "gradelevel" Then
- If a.FirstAttribute.Value = GradeLevelsBox.SelectedItem Then
- 'MsgBox("And the trumpets someone's trying to summon someone.")
- For Each b As XElement In a.Elements()
- 'MsgBox("I know something's coming: " + b.ToString)
- If b.FirstAttribute.Value = GroupBox4.Text Then
- 'MsgBox("But I'm running from it to be standing at the summit: " + b.ToString)
- For Each c As XElement In b.Elements()
- 'MsgBox("Here to stay! " + c.ToString)
- If c.Name = "level" Then
- 'MsgBox("Oh, give me the beat, boys, and free my soul: " + c.ToString)
- If c.FirstAttribute.Name = "name" Then
- 'MsgBox("I wanna get lost in your rock and roll: " + c.ToString)
- If c.FirstAttribute.Value = "singlelevel" Then
- SingleLevel.Checked = True
- Else
- 'MsgBox("and drift away: " + c.ToString)
- SingleLevel.Checked = False
- ClassLevels.Items.Add(c.FirstAttribute.Value)
- End If
- End If
- End If
- Next
- End If
- Next
- End If
- End If
- Next
- Catch ex As NullReferenceException
- End Try
- End Sub
- Private Sub OptionalClassBox_SelectedIndexChanged(sender As Object, e As EventArgs) Handles OptionalClassBox.SelectedIndexChanged
- Try
- GroupBox4.Enabled = True
- GroupBox4.Text = OptionalClassBox.SelectedItem.ToString()
- Catch ex As NullReferenceException
- End Try
- End Sub
- Private Sub GradeLevelEdit_Closing(sender As Object, e As EventArgs) Handles MyBase.Closing
- doc.Root.Save("ScheduleConfig.xml")
- firstschedule.Root.Save("FirstSchedule.xml")
- End Sub
- Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
- For Each a As XElement In doc.Root.Elements()
- If a.HasAttributes Then
- If a.FirstAttribute.Value = GradeLevelsBox.SelectedItem Then
- GradeLevelsBox.Items.Remove(GradeLevelsBox.SelectedItem)
- a.Remove()
- End If
- End If
- Next
- End Sub
- Private Sub GradeLevelEdit_Load()
- For Each a As XElement In doc.Root.Elements()
- If a.HasAttributes = True Then
- If a.FirstAttribute.Value = GradeLevelsBox.SelectedItem Then
- For Each b As XElement In a.Elements()
- If b.Name = "mandatory-class" Then
- MandatoryClassBox.Items.Add(b.FirstAttribute.Value)
- End If
- If b.Name = "optional-class" Then
- OptionalClassBox.Items.Add(b.FirstAttribute.Value)
- End If
- Next
- End If
- End If
- Next
- End Sub
- ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
- 'Section 4: Editing Class Properties
- Private Sub ClassLevels_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ClassLevels.SelectedIndexChanged
- If SingleLevel.Checked Then
- ClassLevels.Enabled = False
- ClassLevelsTextBox.Enabled = False
- ClassLevelsButton.Enabled = False
- Else
- ClassLevels.Enabled = True
- ClassLevelsTextBox.Enabled = True
- ClassLevelsButton.Enabled = True
- End If
- End Sub
- Private Sub ClassLevelsButton_Click(sender As Object, e As EventArgs) Handles ClassLevelsButton.Click
- Dim pass As Boolean = True
- For Each x As String In ClassLevels.Items
- If x.Equals(ClassLevelsTextBox.Text) Then
- MsgBox("There is already a class level with the same name.", MsgBoxStyle.Critical)
- pass = False
- ElseIf x.Equals("") Then
- MsgBox("The class level is empty.", MsgBoxStyle.Critical)
- pass = False
- ElseIf x.Equals("singlelevel") Then
- MsgBox("singlelevel is a reserved name that cannot be used.", MsgBoxStyle.Critical)
- pass = False
- End If
- Next
- If pass = True Then
- ClassLevels.Items.Add(ClassLevelsTextBox.Text)
- Dim lv As XElement = New XElement("level")
- lv.SetAttributeValue("name", ClassLevelsTextBox.Text)
- For Each a As XElement In doc.Root.Elements()
- If a.HasAttributes Then
- If a.FirstAttribute.Value = GradeLevelsBox.SelectedItem Then
- For Each b As XElement In a.Elements()
- If b.FirstAttribute.Value = GroupBox4.Text Then
- b.Add(lv)
- End If
- Next
- End If
- End If
- Next
- End If
- End Sub
- Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
- Try
- MandatoryClassBox.Items.Remove(MandatoryClassBox.SelectedItem)
- OptionalClassBox.Items.Remove(OptionalClassBox.SelectedItem)
- For Each a As XElement In doc.Root.Elements()
- 'MsgBox("And we were trying different things: " + a.ToString)
- If a.Name = "gradelevel" Then
- 'MsgBox("We were smoking funny things: " + a.ToString)
- If a.FirstAttribute.Value = GradeLevelsBox.SelectedItem Then
- For Each b As XElement In a.Elements()
- 'MsgBox("Making love out by the lake to our favorite song: " + b.ToString())
- If b.FirstAttribute.Value = GroupBox4.Text Then
- 'MsgBox("Sipping whiskey out the bottle, not thinking 'bout tomorrow: " + b.ToString())
- b.Remove()
- End If
- Next
- End If
- End If
- Next
- Catch ex As NullReferenceException
- MsgBox("There is no course to delete", MsgBoxStyle.Critical)
- End Try
- End Sub
- Private Sub SingleLevel_CheckedChanged(sender As Object, e As EventArgs) Handles SingleLevel.CheckedChanged
- If SingleLevel.Checked Then
- For Each a As XElement In doc.Root.Elements()
- Dim sl As XElement = New XElement("level")
- sl.SetAttributeValue("name", "singlelevel")
- Try
- If a.HasAttributes Then
- If a.FirstAttribute.Value = GradeLevelsBox.SelectedItem Then
- For Each b As XElement In a.Elements()
- If b.FirstAttribute.Value = GroupBox4.Text Then
- b.Value = ""
- b.Add(sl)
- End If
- Next
- End If
- End If
- Catch ex As NullReferenceException
- MsgBox("NullReferenceException caught! " + a.ToString)
- End Try
- Next
- ClassLevelsTextBox.Enabled = False
- ClassLevels.Enabled = False
- ClassLevelsButton.Enabled = False
- Else
- ClassLevelsTextBox.Enabled = True
- ClassLevels.Enabled = True
- ClassLevelsButton.Enabled = True
- For Each a As XElement In doc.Root.Elements()
- Dim sl As XElement = New XElement("level")
- sl.SetAttributeValue("name", "singlelevel")
- If a.FirstAttribute.Value = GradeLevelsBox.SelectedItem Then
- For Each b As XElement In a.Elements()
- If b.FirstAttribute.Value = GroupBox4.Text Then
- b.Value = ""
- End If
- Next
- End If
- Next
- End If
- End Sub
- Dim check As Boolean = True
- Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
- If check = True Then
- GroupBox3.Visible = False
- GroupBox2.Visible = False
- GroupBox4.Visible = False
- GroupBox5.Visible = True
- Button1.Text = "Click for Courses"
- Dim fn As String = ""
- Dim ln As String = ""
- For Each a As XElement In doc.Root.Elements()
- If a.Name = "gradelevel" Then
- For Each b As XElement In a.Elements()
- If b.Name.ToString().Contains("-class") Then
- If b.FirstAttribute.Name = "name" Then
- CertifiedClasses.Items.Remove(b.FirstAttribute.Value)
- End If
- End If
- Next
- End If
- If a.Name.ToString().Contains("teachers") Then
- For Each b As XElement In a.Elements()
- If b.Name.ToString.Contains("teacher") Then
- For Each c As XElement In b.Elements()
- If c.Name.ToString.Contains("firstname") Then
- fn = c.Value.ToString
- End If
- If c.Name.ToString.Contains("lastname") Then
- ln = c.Value.ToString
- End If
- If c.Name.ToString.Contains("certification") = False Then
- If ln.Equals("") = False Then
- TeacherDirectory.Items.Remove(fn + " " + ln)
- fn = ""
- ln = ""
- End If
- End If
- Next
- End If
- Next
- End If
- Next
- For Each a As XElement In doc.Root.Elements()
- If a.Name = "gradelevel" Then
- For Each b As XElement In a.Elements()
- If b.Name.ToString().Contains("-class") Then
- If b.FirstAttribute.Name = "name" Then
- CertifiedClasses.Items.Add(b.FirstAttribute.Value, False)
- End If
- End If
- Next
- End If
- If a.Name.ToString().Contains("teachers") Then
- For Each b As XElement In a.Elements()
- If b.Name.ToString.Contains("teacher") Then
- For Each c As XElement In b.Elements()
- If c.Name.ToString.Contains("firstname") Then
- fn = c.Value.ToString
- End If
- If c.Name.ToString.Contains("lastname") Then
- ln = c.Value.ToString
- End If
- If c.Name.ToString.Contains("certification") = False Then
- If ln.Equals("") = False Then
- TeacherDirectory.Items.Add(fn + " " + ln)
- fn = ""
- ln = ""
- End If
- End If
- Next
- End If
- Next
- End If
- Next
- check = False
- Else
- GroupBox3.Visible = True
- GroupBox2.Visible = True
- GroupBox4.Visible = True
- GroupBox5.Visible = False
- Button1.Text = "Click for Teachers"
- check = True
- End If
- End Sub
- Private Sub CheckBox2_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox2.CheckedChanged
- If CheckBox2.CheckState = CheckState.Checked Then
- MinParccScore.Enabled = True
- Else
- MinParccScore.Enabled = False
- End If
- End Sub
- ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
- 'Section 5: Adding and Editing Teachers
- Private Sub AddTeacher_Click(sender As Object, e As EventArgs) Handles AddTeacher.Click
- Dim te As XElement = New XElement("teacher") '<teacher>
- Dim fn As XElement = New XElement("firstname") '<firstname>
- Dim ln As XElement = New XElement("lastname") '<lastname>
- Dim pass As Boolean = True 'Valid name test
- For Each x As String In TeacherDirectory.Items 'Iterator loop for the TeacherDirectory ListBox
- If x.ToString.Equals(FirstName.Text + " " + LastName.Text) Then 'Is there a teacher with the same name?
- MsgBox("There is already a teacher with the same name.", MsgBoxStyle.Critical) 'Error Message
- pass = False 'Failed
- ElseIf FirstName.Text.Equals("") Then 'Is the first name empty?
- MsgBox("The teacher has an empty first name.", MsgBoxStyle.Critical) 'Error Message
- pass = False 'Failed
- ElseIf LastName.Text.Equals("") Then 'Is the last name empty?
- MsgBox("The teacher has an empty last name.", MsgBoxStyle.Critical) 'Error Message
- pass = False 'Failed
- End If
- Next
- If pass = True Then 'If you passed the test
- TeacherDirectory.Items.Add(FirstName.Text + " " + LastName.Text) 'Add the new teacher's name to the TeacherDirectory
- For Each a As XElement In doc.Root.Elements() 'Iterate through the document
- If a.Name.ToString().Contains("teachers") Then 'Find <teachers>
- a.Add(te) 'Add the <teacher> tag to <teachers>
- te.Add(fn) 'Add the <firstname> tag inside of <teacher>
- te.Add(ln) 'Add the <lastname> tag inside of <teacher>
- fn.Add(FirstName.Text) 'Add the new teacher's first name inside of <firstname>
- ln.Add(LastName.Text) 'Add the new teacher's last name inside of <lastname>
- End If
- Next
- Dim b As Object() = CertifiedClasses.CheckedItems.OfType(Of Object).ToArray() 'Make a new array with all of the items in the CertifiedClasses CheckedListBox
- For c As Integer = 0 To b.Count() - 1 'Start a for loop that iterates through the elements of b()
- Try 'There is a possibility of an IndexOutOfRangeException
- Dim cr As XElement = New XElement("certification") '<certification>
- te.Add(cr) 'Add <certification> inside of <teacher>
- cr.Add(CertifiedClasses.CheckedItems.Item(c).ToString) 'Add the checked item with the index of c inside of <certification>
- Catch ex As IndexOutOfRangeException
- MsgBox("Index out of range", MsgBoxStyle.Exclamation) 'IndexOutOfRangeException
- End Try
- Next
- End If
- doc.Root.Save("ScheduleConfig.xml")
- End Sub
- Private Sub TeacherDirectory_SelectedIndexChanged(sender As Object, e As EventArgs) Handles TeacherDirectory.SelectedIndexChanged
- Dim fn As String = "" 'First Name
- Dim ln As String = "" 'Last Name
- Dim ct As Integer = 0 'Counter
- Dim fnright As Boolean = False 'First Name Selected
- Dim lnright As Boolean = False 'Last Name Selected
- Try
- For Each a As String In TeacherDirectory.SelectedItem.ToString.Split(" ") 'Split up the first name and last name
- If ct = 0 Then 'If a is the first name
- fn = a 'Set fn to a
- ElseIf ct = 1 Then 'If a is the last name
- ln = a 'Set ln to a
- End If
- ct = ct + 1 'Change a from first name to last name
- Next
- Catch ex As NullReferenceException 'When a NullReferenceException occurs, ignore it
- End Try
- For Each a As XElement In doc.Root.Elements() 'Iterate through the document
- If a.Name.ToString.Contains("teachers") Then 'If <teachers> is found
- For Each b As XElement In a.Elements() 'Iterate through <teachers>
- If b.Name.ToString.Contains("teacher") Then 'If <teacher> is found
- For Each c As XElement In b.Elements() 'Iterate through <teacher>
- If c.Name.ToString.Contains("certification") Then 'If <certification> is found
- 'MsgBox("Don't know what you got till it's gone: " + c.Name.ToString)
- Dim d As Object() = CertifiedClasses.Items.OfType(Of Object).ToArray() 'Make a new array with all of the items in the CertifiedClasses CheckedListBox
- For Each od In d 'Iterate through d()
- CertifiedClasses.SetItemChecked(CertifiedClasses.Items.IndexOf(od), False) 'Uncheck the item
- Next
- End If
- Next
- End If
- Next
- End If
- Next
- For Each a As XElement In doc.Root.Elements() 'Iterate through the document
- If a.Name.ToString().Contains("teachers") Then 'If <teachers> is found
- For Each b As XElement In a.Elements() 'Iterate through <teachers>
- If b.Name.ToString.Contains("teacher") Then 'If <teacher> is found
- For Each c As XElement In b.Elements() 'Iterate through <teacher>
- If c.Name.ToString.Contains("firstname") Then 'If <firstname> is found
- If c.Value.ToString.Equals(fn) Then 'If <firstname> is equal to fn
- fnright = True 'fnright is true
- Else 'Or else
- fnright = False 'fnright is false
- End If
- End If
- If c.Name.ToString.Contains("lastname") Then 'If <lastname> is found
- If c.Value.ToString.Equals(ln) Then 'If <lastname> is equal to ln
- lnright = True 'lnright is true
- Else 'Or else
- fnright = False 'lnright is false
- End If
- End If
- If c.Name.ToString.Contains("certification") = True Then 'If <certification> is found
- 'If a course has been deleted, scan through this checklist to remove it from the checklist and any of the teacher's XML elements.
- Dim d As Object() = CertifiedClasses.Items.OfType(Of Object).ToArray() 'Make a new array with all of the items in the CertifiedClasses CheckedListBox
- For Each od In d 'Iterate through d()
- If od.Contains(c.Value.ToString) Then 'If an item in CertifiedClasses is equal to the value of <certification>
- If VerifyCourseExistence(od) = True Then 'Verify the course existence
- For Each f As XElement In c.Ancestors() 'Iterate through the ancestors of <certification>
- If f.Name.ToString.Equals("teacher") Then 'If <teacher> is found
- FirstName.Text = fn 'Set the FirstName textbox to fn
- LastName.Text = ln 'Set the LastName textbox to ln
- If f.HasElements = True Then 'If there are elements in f
- For Each g As XElement In f.Elements() 'Iterate through <teacher>
- If f.Element("firstname").Value.ToString.Contains(FirstName.Text) Then 'If the value of <firstname> is equal to the textbox
- If f.Element("lastname").Value.ToString.Contains(LastName.Text) Then 'If the value of <lastname> is equal to the textbox
- CertifiedClasses.SetItemChecked(CertifiedClasses.Items.IndexOf(od), True) 'Set the CertifiedClasses item with the index of od to a checked state
- End If
- End If
- Next
- End If
- End If
- Next
- Else
- c.Remove() 'If the course does not exist, then remove the <certification> node with the inexistent course
- End If
- End If
- Next
- End If
- Next
- End If
- Next
- End If
- Next
- End Sub
- Function VerifyCourseExistence(ByVal course As Object)
- For Each a As XElement In doc.Root.Elements() 'Iterate through <teachers>
- If a.Name.ToString().Contains("gradelevel") Then 'If <gradelevel> is found
- For Each b As XElement In a.Elements() 'Iterate through <gradelevel>
- If b.FirstAttribute.Value.ToString.Contains(course.ToString) Then 'If an element's first attribute (name) is equal to the variable course in the parameters
- Return True 'Return True
- End If
- Next
- End If
- Next
- Return False 'When the course is not found, it will end here and Return False
- End Function
- Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
- Dim fnright As Boolean = False
- Dim lnright As Boolean = False
- 'Check to make sure there is a teacher to write to
- Dim pass As Boolean = False
- For Each x As String In TeacherDirectory.Items 'Iterator loop for the TeacherDirectory ListBox
- If x.ToString.Equals(FirstName.Text + " " + LastName.Text) Then 'Is there a teacher with the same name?
- pass = True
- End If
- Next
- If pass = False Then
- MsgBox("There is no teacher to write to.", MsgBoxStyle.Critical) 'Error Message
- Else
- For Each a As XElement In doc.Root.Elements()
- If a.Name.ToString.Contains("teachers") Then
- For Each b As XElement In a.Elements()
- If b.Name.ToString.Contains("teacher") Then
- Dim count As Integer = 1
- For Each c As String In TeacherDirectory.SelectedItem.ToString.Split(" ")
- If count = 1 Then
- For Each d As XElement In b.Elements()
- If d.Name = "firstname" Then
- If d.Value.ToString.Contains(c) Then
- fnright = True
- End If
- End If
- Next
- ElseIf count = 2 Then
- For Each d As XElement In b.Elements()
- If d.Name = "lastname" Then
- If d.Value.ToString.Contains(c) Then
- lnright = True
- End If
- End If
- Next
- End If
- count = count + 1
- Next
- If fnright = True And lnright = True Then
- b.Remove()
- End If
- End If
- Next
- End If
- Next
- Dim te As XElement = New XElement("teacher") '<teacher>
- Dim fn As XElement = New XElement("firstname") '<firstname>
- Dim ln As XElement = New XElement("lastname") '<lastname>
- Dim pass2 As Boolean = True
- If pass2 = True Then 'If you passed the test
- For Each a As XElement In doc.Root.Elements() 'Iterate through the document
- If a.Name.ToString().Contains("teachers") Then 'Find <teachers>
- a.Add(te) 'Add the <teacher> tag to <teachers>
- te.Add(fn) 'Add the <firstname> tag inside of <teacher>
- te.Add(ln) 'Add the <lastname> tag inside of <teacher>
- fn.Add(FirstName.Text) 'Add the new teacher's first name inside of <firstname>
- ln.Add(LastName.Text) 'Add the new teacher's last name inside of <lastname>
- End If
- Next
- Dim b As Object() = CertifiedClasses.CheckedItems.OfType(Of Object).ToArray() 'Make a new array with all of the items in the CertifiedClasses CheckedListBox
- For c As Integer = 0 To b.Count() - 1 'Start a for loop that iterates through the elements of b()
- Try 'There is a possibility of an IndexOutOfRangeException
- Dim cr As XElement = New XElement("certification") '<certification>
- te.Add(cr) 'Add <certification> inside of <teacher>
- cr.Add(CertifiedClasses.CheckedItems.Item(c).ToString) 'Add the checked item with the index of c inside of <certification>
- Catch ex As IndexOutOfRangeException
- MsgBox("Index out of range", MsgBoxStyle.Exclamation) 'IndexOutOfRangeException
- End Try
- Next
- End If
- doc.Root.Save("ScheduleConfig.xml")
- End If
- End Sub
- Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
- Dim fnright As Boolean = False
- Dim lnright As Boolean = False
- For Each a As XElement In doc.Root.Elements()
- If a.Name.ToString.Contains("teachers") Then
- For Each b As XElement In a.Elements()
- If b.Name.ToString.Contains("teacher") Then
- Dim count As Integer = 1
- For Each c As String In TeacherDirectory.SelectedItem.ToString.Split(" ")
- If count = 1 Then
- For Each d As XElement In b.Elements()
- If d.Name = "firstname" Then
- If d.Value.ToString.Contains(c) Then
- fnright = True
- End If
- End If
- Next
- ElseIf count = 2 Then
- For Each d As XElement In b.Elements()
- If d.Name = "lastname" Then
- If d.Value.ToString.Contains(c) Then
- lnright = True
- End If
- End If
- Next
- End If
- count = count + 1
- Next
- If fnright = True And lnright = True Then
- TeacherDirectory.Items.Remove(TeacherDirectory.SelectedItem)
- b.Remove()
- End If
- End If
- Next
- End If
- Next
- End Sub
- ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
- 'Section 6: Generating The Schedule
- Private Sub Button6_Click() Handles Button6.Click
- 'After each generated class, remove it from the list
- 'Dim ync As MsgBoxResult = MsgBox("Would you like your schedule to be generated through a simulation?", MsgBoxStyle.YesNoCancel)
- 'If ync = MsgBoxResult.Yes Then
- Dim pn As Integer = PeriodNumber.Value 'pn is a shortcut to PeriodNumber.Value (how many periods are in a day)
- If NumberOfStudents.Value < 1 Then 'If you have 0 or a negative number of students
- MsgBox("You have less than 1 student. That's a lotta damage.", MsgBoxStyle.Critical)
- Else 'If you have at least 1 student
- Dim studentid As Integer = 1 'Student ID
- For Each a As XElement In doc.Root.Elements 'Iterate through the document
- For std As Integer = 1 To NumberOfStudents.Value 'Use std as a variable for the nth student in the grade level
- If a.Name = "gradelevel" Then 'If you found the <gradelevel> element
- Dim gradename As String = "" 'Make gradename empty because the name of the grade has not been determined yet
- Randomize() 'Call the random number generator (I don't even think it's required)
- Dim genmath As Integer = CInt((Int(10 * Rnd()) + 1) + 10) 'Not used at the moment
- Dim enrmath As Integer = CInt((Int((28 - genmath) * Rnd()) + 1)) 'Not used at the moment
- Dim aermath As Integer = CInt(Int(30 - (genmath + enrmath))) 'Not used at the moment
- Dim genspan As Integer = CInt((Int(10 * Rnd()) + 1) + 15) 'Not used at the moment
- Dim enrspan As Integer = CInt(Int(30 - genspan)) 'Not used at the moment
- If a.HasAttributes Then 'If <gradelevel> has an attribute
- If a.FirstAttribute.Name = "name" Then 'If the attribute is name=""
- gradename = a.FirstAttribute.Value 'Set gradename to the value of the name="" attribute
- End If
- End If
- Dim stu As XElement = New XElement("student") '<student> element
- stu.Add(New XAttribute("grade", gradename.ToString)) 'Add grade="" attribute to <student> which has the value of the grade level of the student
- stu.Add(New XAttribute("id", studentid.ToString)) 'Add id="" attribute to <student> which has the value of the Student ID
- 'MsgBox(stu.ToString)
- firstschedule.Root.Add(stu) 'Add the <student> element to FirstSchedule.xml
- Dim clsofgrd As Object() = a.Elements().OfType(Of Object).ToArray 'Put the elements inside of <gradelevel> into an array
- For c As Integer = 1 To pn 'Make a for loop that goes from 1 to the period number
- Dim clscnt As Integer = 0 'Detects how many mandatory classes are remaining to be scheduled (0 by default)
- For Each b As XElement In a.Elements() 'Iterate through the elements of <gradelevel>
- If b.Name = "mandatory-class" Then 'If <mandatory-class> is found
- clscnt = clscnt + 1 'Increase clscnt by 1
- End If
- Next
- Dim cls As Integer = CInt(Int(clscnt * Rnd()) + 0) 'Set a random number from 0 to the number of classes there are
- Try
- If clsofgrd(cls).Equals(Nothing) Then
- MsgBox("Double whammy")
- End If
- Catch ex As IndexOutOfRangeException
- Continue For
- End Try
- Try 'There will be an IndexOutOfRangeException
- 'MsgBox(clsofgrd.GetValue(cls).ToString)
- stu.Add(New XElement("p" + c.ToString, clsofgrd.GetValue(cls))) 'Add the <p*> element to the student which contains the class picked in the random number generator on line 774
- 'DELETE THE SELECTED INDEX FROM THE ARRAY clsofgrd
- clsofgrd = clsofgrd.Where(Function(w) w IsNot clsofgrd(cls)).ToArray
- 'MsgBox(clsofgrd(cls))
- clscnt = clscnt - 1 'You added a mandatory class, so reduce this by 1
- Catch ex As IndexOutOfRangeException
- stu.Add(New XElement("MoreProblems", stu.ToString))
- 'MsgBox("Index outta range: " + cls.ToString + " : " + clscnt.ToString)
- End Try
- Next
- 'MsgBox(genmath.ToString + " " + enrmath.ToString + " " + aermath.ToString)
- End If
- studentid = studentid + 1
- Next
- Next
- End If
- 'End If
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement