EDN Admin
Well-known member
Im in the process of finishing up a dive competition program and need help calculating the scores correctly. There are 16 divers that must complete a minimum of 8 dive types with 8 judges scoring the competition. As it is currently set up, the scores are accumulative but I need each of the different dives to be judged individually just like in the Olympics so there are 8 winners, one from each dive type. Here is the code from my Form: Option Strict On
Option Explicit On
Imports System.IO.Path
Imports System.Environment
Public Class Form1
Private rand As New Random
Private Const noVideoURL As String = "http://www.fls-online.com/NoVideoAvailable.htm"
Private programDataFolderPath As String = _
Combine(GetFolderPath(SpecialFolder.ApplicationData), _
My.Application.Info.AssemblyName)
Private diversSetupFilePath As String = Combine(programDataFolderPath, "Diver Setup.xml")
Private diveTypeSetupFilePath As String = Combine(programDataFolderPath, "Dive Type Setup.xml")
Public diveTypeList As New List(Of DiveType)
Private diversList As New List(Of Diver)
Private diversScoreList As New List(Of DiverScore)
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles MyBase.Load
If Not My.Computer.FileSystem.DirectoryExists(programDataFolderPath) Then
My.Computer.FileSystem.CreateDirectory(programDataFolderPath)
End If
btn_SetupDiveType_EditSelected.Enabled = False
btn_SetupDiveType_RemoveSelected.Enabled = False
btn_Competition_BeginCompetition.Enabled = False
btn_Competition_EnterJudgesScores.Enabled = False
lbl_CompetitorUp.Text = ""
With ListView_Competition_Divers
.Columns.Add("Diver Name", 125, HorizontalAlignment.Left)
.Columns.Add("Dive Type", 150, HorizontalAlignment.Left)
.Columns.Add("Difficulty", 75, HorizontalAlignment.Left)
.FullRowSelect = True
.GridLines = True
.MultiSelect = False
.View = View.Details
End With
With TextBox_DiversStats
.ReadOnly = True
.ScrollBars = ScrollBars.Vertical
.Font = New Font("Tahoma", 10, FontStyle.Regular)
.BackColor = Me.BackColor
.TabStop = False
End With
WebBrowser1.Url = New Uri("http://www.fls-online.com/index.htm")
InitializeDiveTypes()
ReadDiveTypes()
ReadSettings()
CheckNoRows_SetupDivers()
PopulateDiveTypeDGV()
CheckNoRows_SetupDiveTypes()
UpdateCompetitorsLabel()
End Sub
Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) _
Handles Me.FormClosing
If e.CloseReason = CloseReason.UserClosing Then
If diversList.Count = 0 Then
If My.Computer.FileSystem.FileExists(diversSetupFilePath) Then
My.Computer.FileSystem.DeleteFile(diversSetupFilePath)
End If
Else
WriteSettings()
End If
WriteDiveTypes()
End If
End Sub
#Region "Classes And Enums"
Public Class DiveType
Public Name As String = "--"
Public DegreeOfDifficulty As Double
Public DiveExampleURL_List As New List(Of String)
Public IsPermanent As Boolean = False
End Class
Public Class Diver
Public FirstName As String = "--"
Public LastName As String = "--"
Public FullName As String = "--"
Public DiveTypeList As New List(Of DiveType)
End Class
Public Class CompetitionDiver
Public FullName As String = "--"
Public Selected As Boolean = False
End Class
Private Class DiverScore
Public DiverFullName As String = "--"
Public EventName As String = "--"
Public EventDegreeOfDifficulty As Double
Public Judge1Score As Double
Public Judge2Score As Double
Public Judge3Score As Double
Public Judge4Score As Double
Public Judge5Score As Double
Public Judge6Score As Double
Public Judge7Score As Double
Public Judge8Score As Double
Public EventScore_8Judges As Double
Public EventScore_6Judges As Double
End Class
Private Class CompetitonScores
Public DiverFullName As String = "--"
Public OverallScore As Double
End Class
#End Region
#Region "Common Methods And Functions"
Private Sub InitializeDiveTypes()
Dim dt As New DiveType
With dt
.Name = "Forward Dive"
.DegreeOfDifficulty = 1.4
.IsPermanent = True
.DiveExampleURL_List.Add("http://www.youtube.com/embed/8XiVkxZMmcI")
.DiveExampleURL_List.Add("http://www.youtube.com/embed/_9su0zu_-sU")
.DiveExampleURL_List.Add("http://www.youtube.com/embed/0QTUFLEiHgs")
.DiveExampleURL_List.Add("http://www.youtube.com/embed/fdBZ_Khsmg4")
.DiveExampleURL_List.Add("http://www.youtube.com/embed/gHH1_TLq_eE")
.DiveExampleURL_List.Add("http://www.youtube.com/embed/RkVvcIKm8q4")
End With
diveTypeList.Add(dt)
dt = New DiveType
With dt
.Name = "Forward 1-1/2 Somersaults"
.DegreeOfDifficulty = 2
.IsPermanent = True
.DiveExampleURL_List.Add("http://www.youtube.com/embed/nafbci68_jU")
.DiveExampleURL_List.Add("http://www.youtube.com/embed/B5IcsAd2sj4")
.DiveExampleURL_List.Add("http://www.youtube.com/embed/Lh5yKA3nQCQ")
.DiveExampleURL_List.Add("http://www.youtube.com/embed/602wxnWpw4o")
.DiveExampleURL_List.Add("http://www.youtube.com/embed/gNEO6A2-70A")
.DiveExampleURL_List.Add("http://www.youtube.com/embed/R2mf7xRi7G4")
End With
diveTypeList.Add(dt)
dt = New DiveType
With dt
.Name = "Back Dive"
.DegreeOfDifficulty = 1.76
.IsPermanent = True
.DiveExampleURL_List.Add("http://www.youtube.com/embed/e_8MI-8iH_E")
.DiveExampleURL_List.Add("http://www.youtube.com/embed/qsrwu4Yf_DU")
.DiveExampleURL_List.Add("http://www.youtube.com/embed/sVErMUCVgYE")
.DiveExampleURL_List.Add("http://www.youtube.com/embed/r4B691n8500")
.DiveExampleURL_List.Add("http://www.youtube.com/embed/wxgatI72-IY")
.DiveExampleURL_List.Add("http://www.youtube.com/embed/XnpY85hwlEk")
.DiveExampleURL_List.Add("http://www.youtube.com/embed/E3IsSslDjYA")
End With
diveTypeList.Add(dt)
dt = New DiveType
With dt
.Name = "Back 1-1/2 Somersaults"
.DegreeOfDifficulty = 2.54
.IsPermanent = True
.DiveExampleURL_List.Add("http://www.youtube.com/embed/nafbci68_jU")
.DiveExampleURL_List.Add("http://www.youtube.com/embed/B5IcsAd2sj4")
.DiveExampleURL_List.Add("http://www.youtube.com/embed/Lh5yKA3nQCQ")
.DiveExampleURL_List.Add("http://www.youtube.com/embed/602wxnWpw4o")
.DiveExampleURL_List.Add("http://www.youtube.com/embed/gNEO6A2-70A")
.DiveExampleURL_List.Add("http://www.youtube.com/embed/R2mf7xRi7G4")
End With
diveTypeList.Add(dt)
dt = New DiveType
With dt
.Name = "Inward Dive"
.DegreeOfDifficulty = 1.85
.IsPermanent = True
.DiveExampleURL_List.Add("http://www.youtube.com/embed/thC_mJaVNFI")
.DiveExampleURL_List.Add("http://www.youtube.com/embed/LVh4xJFGkRE")
.DiveExampleURL_List.Add("http://www.youtube.com/embed/k2vYS7hlaOg")
.DiveExampleURL_List.Add("http://www.youtube.com/embed/YB6hJiDLQ9s")
.DiveExampleURL_List.Add("http://www.youtube.com/embed/z3RhIH9YHBY")
End With
diveTypeList.Add(dt)
dt = New DiveType
With dt
.Name = "Inward 1-1/2 Somersaults "
.DegreeOfDifficulty = 2.46
.IsPermanent = True
.DiveExampleURL_List.Add("http://www.youtube.com/embed/7YcrO-6Iaqw")
.DiveExampleURL_List.Add("http://www.youtube.com/embed/XGU12WKAz6I")
.DiveExampleURL_List.Add("http://www.youtube.com/embed/Te4vz3uC2LA")
.DiveExampleURL_List.Add("http://www.youtube.com/embed/AE3mCtYNVPs")
.DiveExampleURL_List.Add("http://www.youtube.com/embed/cOrXjd_YAV4")
.DiveExampleURL_List.Add("http://www.youtube.com/embed/D4PYFcKqhhw")
End With
diveTypeList.Add(dt)
dt = New DiveType
With dt
.Name = "Forward Armstand"
.DegreeOfDifficulty = 1.65
.IsPermanent = True
.DiveExampleURL_List.Add("http://www.youtube.com/embed/SpCLAUEfEwg")
.DiveExampleURL_List.Add("http://www.youtube.com/embed/038Dm8aEWlw")
End With
diveTypeList.Add(dt)
dt = New DiveType
With dt
.Name = "Forward Armstand Somersault Tuck"
.DegreeOfDifficulty = 2.31
.IsPermanent = True
.DiveExampleURL_List.Add("http://www.youtube.com/embed/XipbK-6v_NY")
.DiveExampleURL_List.Add("http://www.youtube.com/embed/T_ctdgs9-Y0")
.DiveExampleURL_List.Add("http://www.youtube.com/embed/K-AV0_Z5ohs")
End With
diveTypeList.Add(dt)
End Sub
Private Sub CheckNoRows_SetupDivers()
If diversList.Count = 0 Then
btn_SetupDivers_EditSelected.Enabled = False
btn_SetupDivers_RemoveSelected.Enabled = False
SetupDivers_BindingNavigator.Enabled = False
SetupDivers_DataGridView.Enabled = False
Else
btn_SetupDivers_EditSelected.Enabled = True
btn_SetupDivers_RemoveSelected.Enabled = True
SetupDivers_BindingNavigator.Enabled = True
SetupDivers_DataGridView.Enabled = True
End If
End Sub
Private Sub CheckNoRows_SetupDiveTypes()
If diveTypeList.Count = 0 Then
DiveType_BindingNavigator.Enabled = False
DiveType_DataGridView.Enabled = False
Else
DiveType_BindingNavigator.Enabled = True
DiveType_DataGridView.Enabled = True
End If
End Sub
Private Sub PopulateDiversDGV()
With SetupDivers_BindingNavigator
.BindingSource = Nothing
.Enabled = False
End With
With SetupDivers_DataGridView
.DataSource = Nothing
.Enabled = False
End With
If diversList.Count > 0 Then
Dim qry = From d As Diver In diversList _
Order By d.FullName
Dim dt As New DataTable
Dim column As New DataColumn
With column
.DataType = System.Type.GetType("System.String")
.ColumnName = "Divers First Name"
dt.Columns.Add(column)
End With
column = New DataColumn
With column
.DataType = System.Type.GetType("System.String")
.ColumnName = "Divers Last Name"
dt.Columns.Add(column)
End With
column = New DataColumn
With column
.DataType = System.Type.GetType("System.String")
.ColumnName = "Divers Full Name"
dt.Columns.Add(column)
End With
Dim row As DataRow
For Each d As Diver In qry
row = dt.NewRow
row("Divers First Name") = d.FirstName
row("Divers Last Name") = d.LastName
row("Divers Full Name") = d.FullName
dt.Rows.Add(row)
Next
Dim bs As New BindingSource
bs.DataSource = dt
With SetupDivers_BindingNavigator
.BindingSource = bs
.Enabled = True
End With
With SetupDivers_DataGridView
.DataSource = bs
.Enabled = True
.SelectionMode = DataGridViewSelectionMode.FullRowSelect
.MultiSelect = False
.AlternatingRowsDefaultCellStyle.BackColor = Color.LightBlue
.Columns(0).Width = 100
.Columns(1).Width = 100
.Columns(2).AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill
If SetupDivers_DataGridView.RowCount > 0 Then
SetupDivers_DataGridView.Rows(0).Selected = True
End If
End With
If diversList.Count = 0 Then
If My.Computer.FileSystem.FileExists(diversSetupFilePath) Then
My.Computer.FileSystem.DeleteFile(diversSetupFilePath)
End If
Else
WriteSettings()
End If
Else
PopulateDivers_DiveTypeDGV("")
End If
End Sub
Private Sub PopulateDivers_DiveTypeDGV(ByVal diverFullName As String)
SetupDivers_DiveType_DataGridView.DataSource = Nothing
Dim qry = From thisDiver As Diver In diversList _
Where thisDiver.FullName = diverFullName
If qry.Count = 1 Then
Dim dt As New DataTable
Dim column As New DataColumn
With column
.DataType = System.Type.GetType("System.String")
.ColumnName = "Dive Type"
dt.Columns.Add(column)
End With
column = New DataColumn
With column
.DataType = System.Type.GetType("System.Double")
.ColumnName = "Degree Of Difficulty"
dt.Columns.Add(column)
End With
Dim row As DataRow
For Each dType As DiveType In qry.First.DiveTypeList
row = dt.NewRow
row("Dive Type") = dType.Name
row("Degree Of Difficulty") = dType.DegreeOfDifficulty
dt.Rows.Add(row)
Next
Dim bs As New BindingSource
bs.DataSource = dt
With SetupDivers_DiveType_DataGridView
.DataSource = bs
.Enabled = True
.SelectionMode = DataGridViewSelectionMode.FullRowSelect
.MultiSelect = False
.RowHeadersVisible = False
.AlternatingRowsDefaultCellStyle.BackColor = Color.LightGreen
.Columns(0).Width = 300
With .Columns(1)
.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill
.DefaultCellStyle.Format = "f2"
End With
End With
End If
End Sub
Private Sub PopulateDiveTypeDGV()
With DiveType_BindingNavigator
.BindingSource = Nothing
.Enabled = False
End With
With DiveType_DataGridView
.DataSource = Nothing
.Enabled = False
End With
If diveTypeList.Count > 0 Then
Dim qry = From dType As DiveType In diveTypeList _
Order By dType.Name
Dim dt As New DataTable
Dim column As New DataColumn
With column
.DataType = System.Type.GetType("System.String")
.ColumnName = "Dive Type Name"
dt.Columns.Add(column)
End With
column = New DataColumn
With column
.DataType = System.Type.GetType("System.Double")
.ColumnName = "Degree Of Difficulty"
dt.Columns.Add(column)
End With
column = New DataColumn
With column
.DataType = System.Type.GetType("System.Int32")
.ColumnName = "Example URL Count"
dt.Columns.Add(column)
End With
Dim row As DataRow
For Each dType As DiveType In qry
row = dt.NewRow
row("Dive Type Name") = dType.Name
row("Degree Of Difficulty") = dType.DegreeOfDifficulty
row("Example URL Count") = dType.DiveExampleURL_List.Count
dt.Rows.Add(row)
Next
Dim bs As New BindingSource
bs.DataSource = dt
With DiveType_BindingNavigator
.BindingSource = bs
.Enabled = True
End With
With DiveType_DataGridView
.DataSource = bs
.Enabled = True
.SelectionMode = DataGridViewSelectionMode.FullRowSelect
.MultiSelect = False
.AlternatingRowsDefaultCellStyle.BackColor = Color.LightSalmon
.Columns(0).Width = 350
With .Columns(1)
.Width = 150
.DefaultCellStyle.Format = "f2"
End With
With .Columns(2)
.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill
.DefaultCellStyle.Format = "n0"
End With
If DiveType_DataGridView.RowCount > 0 Then
DiveType_DataGridView.Rows(0).Selected = True
End If
End With
End If
End Sub
Private Sub ReadSettings()
If My.Computer.FileSystem.FileExists(diversSetupFilePath) Then
diversList.Clear()
Dim settingsInfo = XElement.Load(diversSetupFilePath)
For Each diverInfo As XElement In settingsInfo...<DiverSetup>
Dim thisDiver As New Diver
With thisDiver
.FirstName = diverInfo...<FirstName>.Value
.LastName = diverInfo...<LastName>.Value
.FullName = .FirstName & " " & .LastName
Dim dtList As New List(Of DiveType)
For Each dtInfo As XElement In diverInfo...<DiveTypeNames>
For Each diveName As XElement In dtInfo...<Name>
Dim thisDiveName As String = diveName.Value
Dim qry = From dt As DiveType In diveTypeList _
Where dt.Name = thisDiveName
If qry.Count = 1 Then
dtList.Add(qry.First)
End If
Next
Next
thisDiver.DiveTypeList = dtList
End With
diversList.Add(thisDiver)
Next
PopulateDiversDGV()
End If
End Sub
Private Sub WriteSettings()
Dim settingsDoc = <DiversSetup>
<%= From d As Diver In diversList Select _
<DiverSetup>
<FirstName><%= d.FirstName %></FirstName>
<LastName><%= d.LastName %></LastName>
<DiveTypeNames><%= From dt As DiveType In d.DiveTypeList Select _
<Name><%= dt.Name %></Name> %>
</DiveTypeNames>
</DiverSetup> %>
</DiversSetup>
settingsDoc.Save(diversSetupFilePath)
End Sub
Private Sub ReadDiveTypes()
If My.Computer.FileSystem.FileExists(diveTypeSetupFilePath) Then
Dim diveTypeInfo = XElement.Load(diveTypeSetupFilePath)
For Each dt As XElement In diveTypeInfo...<DiveType>
Dim thisDiveType As New DiveType
Dim allValuesGood As Boolean = True
With thisDiveType
.Name = dt...<Name>.Value
If Not Double.TryParse(dt...<DegreeOfDifficulty>.Value, .DegreeOfDifficulty) Then
allValuesGood = False
End If
If Not Boolean.TryParse(dt...<IsPermanent>.Value, .IsPermanent) Then
allValuesGood = False
End If
If allValuesGood Then
For Each url As XElement In dt...<URLs>
.DiveExampleURL_List.Add(url...<URL>.Value)
Next
End If
End With
If allValuesGood Then
diveTypeList.Add(thisDiveType)
End If
Next
End If
End Sub
Private Sub WriteDiveTypes()
Dim qry = From dt As DiveType In diveTypeList Where Not dt.IsPermanent
If qry.Count > 0 Then
Dim diveTypeDoc = <DiveTypes>
<%= From dt As DiveType In diveTypeList Where Not dt.IsPermanent Select _
<DiveType>
<Name><%= dt.Name %></Name>
<DegreeOfDifficulty><%= dt.DegreeOfDifficulty.ToString %></DegreeOfDifficulty>
<IsPermanent><%= dt.IsPermanent.ToString %></IsPermanent>
<URLs><%= From s As String In dt.DiveExampleURL_List Select _
<URL><%= s %></URL> %>
</URLs>
</DiveType> %>
</DiveTypes>
diveTypeDoc.Save(diveTypeSetupFilePath)
Else
If My.Computer.FileSystem.FileExists(diveTypeSetupFilePath) Then
My.Computer.FileSystem.DeleteFile(diveTypeSetupFilePath)
End If
End If
End Sub
Private Sub UpdateCompetitorsLabel()
If ListView_Competition_Divers.Items.Count = 0 Then
lbl_Competion_SelectedDivers.Text = "Total Competitors: 0 | Total Events: 0"
Else
Dim competitorCount As Integer = 0
For i As Integer = 0 To ListView_Competition_Divers.Items.Count - 1
If i = 0 Then
competitorCount += 1
Else
If ListView_Competition_Divers.Items(i).Text <> ListView_Competition_Divers.Items(i - 1).Text Then
competitorCount += 1
End If
End If
Next
lbl_Competion_SelectedDivers.Text = "Total Competitors: " & competitorCount.ToString("n0") & _
" | Total Events: " & ListView_Competition_Divers.Items.Count.ToString("n0")
End If
End Sub
#End Region
#Region "Main"
Private Sub TabControl_Main_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) _
Handles TabControl_Main.SelectedIndexChanged
If TabControl_Main.SelectedTab.Name = "TabPage_Competition" Then
If diversList.Count < 16 Then
Dim sb As New System.Text.StringBuilder
sb.AppendLine("There must be a minimum of sixteen (16)")
sb.AppendLine("divers set up before the competition can")
sb.AppendLine("be run.")
sb.AppendLine()
sb.AppendLine("This program will navigate you back to the")
sb.AppendLine("setup area where you can add divers in")
sb.AppendLine("order to fulfill this requirement.")
MessageBox.Show(sb.ToString, "Cannot Navigate To Competition", _
MessageBoxButtons.OK, MessageBoxIcon.Warning)
TabControl_Main.SelectedTab = TabPage_Setup
End If
End If
End Sub
#End Region
#Region "Setup Divers"
Private Sub btn_Setup_AddNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles btn_SetupDivers_AddNew.Click
Using aed As New AddEditDiver
aed.ShowDialog()
If Not aed.userCancel Then
Dim qry = From d As Diver In diversList _
Where d.FullName = aed.diver.FullName
If qry.Count = 0 Then
diversList.Add(aed.diver)
PopulateDiversDGV()
CheckNoRows_SetupDivers()
WriteSettings()
Else
MessageBox.Show("This diver is already in your list" & vbCrLf & _
"and therefore cannot be added.", "Cannot Add Diver", _
MessageBoxButtons.OK, MessageBoxIcon.Warning)
End If
End If
End Using
End Sub
Private Sub btn_Setup_EditSelected_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles btn_SetupDivers_EditSelected.Click
If SetupDivers_DataGridView.RowCount > 0 AndAlso SetupDivers_DataGridView.SelectedRows.Count = 1 Then
Dim fullName As String = SetupDivers_DataGridView.SelectedRows(0).Cells(2).Value.ToString
Dim qry = From d As Diver In diversList _
Where d.FullName = fullName
If qry.Count = 1 Then
Dim diverFullName As String = qry.First.FullName
Using aed As New AddEditDiver
aed.diver = qry.First
aed.ShowDialog()
If Not aed.userCancel Then
Dim thisDiver As New Diver
With thisDiver
.FirstName = aed.diver.FirstName
.LastName = aed.diver.LastName
.FullName = aed.diver.FullName
Dim dtList As New List(Of DiveType)
For Each dt As DiveType In aed.diver.DiveTypeList
dtList.Add(dt)
Next
.DiveTypeList = dtList
End With
For i As Integer = diversList.Count - 1 To 0 Step -1
If diversList(i).FullName = diverFullName Then
diversList.RemoveAt(i)
Exit For
End If
Next
diversList.Add(thisDiver)
PopulateDiversDGV()
End If
End Using
WriteSettings()
End If
End If
End Sub
Private Sub btn_Setup_RemoveSelected_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles btn_SetupDivers_RemoveSelected.Click
If SetupDivers_DataGridView.RowCount > 0 AndAlso SetupDivers_DataGridView.SelectedRows.Count = 1 Then
Dim fullName As String = SetupDivers_DataGridView.SelectedRows(0).Cells(2).Value.ToString
Dim qry = From d As Diver In diversList _
Where d.FullName = fullName
If qry.Count = 1 Then
Dim sb As New System.Text.StringBuilder
sb.AppendLine("You have elected to remove the")
sb.AppendLine("following diver from your list:")
sb.AppendLine()
sb.AppendLine("First Name: " & qry.First.FirstName)
sb.AppendLine("Last Name: " & qry.First.LastName)
sb.AppendLine("Dive Types Defined: " & qry.First.DiveTypeList.Count.ToString("n0"))
sb.AppendLine()
sb.AppendLine("Are you certain that you want to")
sb.AppendLine("PERMANENTLY remove this diver")
sb.AppendLine("from your list of divers?")
If MessageBox.Show(sb.ToString, "Confirm Deletion", MessageBoxButtons.YesNo, _
MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
For i As Integer = diversList.Count - 1 To 0 Step -1
If diversList(i).FullName = qry.First.FullName Then
diversList.RemoveAt(i)
Exit For
End If
Next
PopulateDiversDGV()
CheckNoRows_SetupDivers()
End If
WriteSettings()
End If
End If
End Sub
Private Sub SetupDivers_DataGridView_SelectionChanged(ByVal sender As Object, ByVal e As System.EventArgs) _
Handles SetupDivers_DataGridView.SelectionChanged
If SetupDivers_DataGridView.RowCount > 0 AndAlso SetupDivers_DataGridView.SelectedRows.Count = 1 Then
Dim fullName As String = SetupDivers_DataGridView.SelectedRows(0).Cells(2).Value.ToString
Dim qry = From d As Diver In diversList Where d.FullName = fullName
If qry.Count = 1 Then
PopulateDivers_DiveTypeDGV(qry.First.FullName)
End If
End If
End Sub
#End Region
#Region "Setup Dive Types"
Private Sub btn_SetupDiveType_AddNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles btn_SetupDiveType_AddNew.Click
Using aedt As New AddEditDiveType
aedt.ShowDialog()
If Not aedt.userCancel Then
Dim evaluateDiveName As String = aedt.diveType.Name.ToLower
If evaluateDiveName.Contains(" "c) Then
evaluateDiveName = evaluateDiveName.Replace(" "c, "")
End If
Dim findDuplicate = From dt As DiveType In diveTypeList _
Where dt.Name.ToLower.Replace(" "c, "") = evaluateDiveName
If findDuplicate.Count = 0 Then
diveTypeList.Add(aedt.diveType)
PopulateDiveTypeDGV()
CheckNoRows_SetupDiveTypes()
WriteDiveTypes()
Else
MessageBox.Show("This dive type has already been defined" & vbCrLf & _
"and therefore cannot be added.", "Cannot Add This Dive Type", _
MessageBoxButtons.OK, MessageBoxIcon.Warning)
End If
End If
End Using
End Sub
Private Sub btn_SetupDiveType_EditSelected_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles btn_SetupDiveType_EditSelected.Click
If DiveType_DataGridView.RowCount > 0 AndAlso _
DiveType_DataGridView.SelectedRows.Count = 1 Then
Dim diveName As String = DiveType_DataGridView.SelectedRows(0).Cells(0).Value.ToString
Dim qry = From dt As DiveType In diveTypeList _
Where dt.Name = diveName
If qry.Count = 1 Then
Using aedt As New AddEditDiveType
aedt.diveType = qry.First
aedt.ShowDialog()
If Not aedt.userCancel Then
For i As Integer = diveTypeList.Count - 1 To 0 Step -1
If diveTypeList(i).Name = diveName Then
diveTypeList.RemoveAt(i)
Exit For
End If
Next
Dim thisDiveType As New DiveType
With thisDiveType
.Name = aedt.diveType.Name
.DegreeOfDifficulty = aedt.diveType.DegreeOfDifficulty
.DiveExampleURL_List = aedt.diveType.DiveExampleURL_List
End With
For Each d As Diver In diversList
For i As Integer = d.DiveTypeList.Count - 1 To 0 Step -1
If d.DiveTypeList(i).Name = diveName Then
d.DiveTypeList.RemoveAt(i)
d.DiveTypeList.Add(thisDiveType)
End If
Next
Next
diveTypeList.Add(thisDiveType)
PopulateDiveTypeDGV()
PopulateDiversDGV()
CheckNoRows_SetupDiveTypes()
WriteDiveTypes()
End If
End Using
End If
End If
End Sub
Private Sub btn_SetupDiveType_RemoveSelected_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles btn_SetupDiveType_RemoveSelected.Click
If DiveType_DataGridView.RowCount > 0 AndAlso _
DiveType_DataGridView.SelectedRows.Count = 1 Then
Dim diveName As String = DiveType_DataGridView.SelectedRows(0).Cells(0).Value.ToString
Dim qry = From dt As DiveType In diveTypeList _
Where dt.Name = diveName
If qry.Count = 1 Then
Dim sb As New System.Text.StringBuilder
sb.AppendLine("You have elected to remove the")
sb.AppendLine("following dive type from your list:")
sb.AppendLine()
sb.AppendLine("Dive Type Name: " & qry.First.Name)
sb.AppendLine("Degree Of Difficulty: " & qry.First.DegreeOfDifficulty.ToString("f2"))
sb.AppendLine("Example URL Count: " & qry.First.DiveExampleURL_List.Count.ToString("n0"))
sb.AppendLine()
sb.AppendLine("Are you certain that you want to")
sb.AppendLine("PERMANENTLY remove this dive type")
sb.AppendLine("from your list of dive types?")
If MessageBox.Show(sb.ToString, "Confirm Deletion", MessageBoxButtons.YesNo, _
MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
For i As Integer = diveTypeList.Count - 1 To 0 Step -1
If diveTypeList(i).Name = diveName Then
diveTypeList.RemoveAt(i)
Exit For
End If
Next
For Each d As Diver In diversList
For i As Integer = d.DiveTypeList.Count - 1 To 0 Step -1
If d.DiveTypeList(i).Name = diveName Then
d.DiveTypeList.RemoveAt(i)
End If
Next
Next
PopulateDiveTypeDGV()
PopulateDiversDGV()
CheckNoRows_SetupDiveTypes()
WriteDiveTypes()
End If
End If
End If
End Sub
Private Sub DiveType_DataGridView_SelectionChanged(ByVal sender As Object, ByVal e As System.EventArgs) _
Handles DiveType_DataGridView.SelectionChanged
If DiveType_DataGridView.RowCount > 0 AndAlso _
DiveType_DataGridView.SelectedRows.Count = 1 Then
Dim diveName As String = DiveType_DataGridView.SelectedRows(0).Cells(0).Value.ToString
Dim qry = From dt As DiveType In diveTypeList _
Where dt.Name = diveName
If qry.Count = 1 Then
If qry.First.IsPermanent Then
btn_SetupDiveType_EditSelected.Enabled = False
btn_SetupDiveType_RemoveSelected.Enabled = False
Else
btn_SetupDiveType_EditSelected.Enabled = True
btn_SetupDiveType_RemoveSelected.Enabled = True
End If
End If
End If
End Sub
#End Region
#Region "Competition"
Private Sub btn_Competition_AddEditDivers_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles btn_Competition_AddEditDivers.Click
diversScoreList.Clear()
Dim dsList As New List(Of CompetitionDiver)
For Each d As Diver In diversList
Dim thisComp As New CompetitionDiver
With thisComp
.FullName = d.FullName
.Selected = False
End With
dsList.Add(thisComp)
Next
If ListView_Competition_Divers.Items.Count > 0 Then
For Each lvi As ListViewItem In ListView_Competition_Divers.Items
Dim fullName As String = lvi.Text
Dim qry = From cd As CompetitionDiver In dsList _
Where cd.FullName = fullName
If qry.Count = 1 Then
qry.First.Selected = True
End If
Next
End If
Using caed As New CompetitionAddEditDivers
caed.competitorsList = dsList
caed.ShowDialog()
If Not caed.userCancel Then
Dim qry = From cd As CompetitionDiver In caed.competitorsList _
Where cd.Selected Order By cd.FullName
With ListView_Competition_Divers
.BeginUpdate()
.Items.Clear()
Dim eventsList As New List(Of String)
For Each cd As CompetitionDiver In qry
Dim diverName As String = cd.FullName
Dim findEvents = From d As Diver In diversList Where d.FullName = diverName
For Each d As Diver In findEvents
For Each dt As DiveType In d.DiveTypeList
If Not eventsList.Contains(dt.Name) Then
eventsList.Add(dt.Name)
End If
Next
Next
Next
eventsList.Sort()
For Each competition As String In eventsList
For Each cd As CompetitionDiver In qry
Dim diverName As String = cd.FullName
Dim findDiver = From d As Diver In diversList _
Where d.FullName = diverName
If findDiver.Count = 1 Then
For Each dt As DiveType In findDiver.First.DiveTypeList
If dt.Name = competition Then
Dim lvItem As New ListViewItem(cd.FullName, 0)
lvItem.SubItems.Add(dt.Name)
lvItem.SubItems.Add(dt.DegreeOfDifficulty.ToString("f2"))
ListView_Competition_Divers.Items.AddRange(New ListViewItem() {lvItem})
End If
Next
End If
Next
Next
.EndUpdate()
End With
End If
End Using
If ListView_Competition_Divers.Items.Count = 0 Then
btn_Competition_BeginCompetition.Enabled = False
Else
btn_Competition_BeginCompetition.Enabled = True
End If
UpdateCompetitorsLabel()
End Sub
Private Sub btn_Competition_BeginCompetition_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles btn_Competition_BeginCompetition.Click
btn_Competition_AddEditDivers.Enabled = False
btn_Competition_BeginCompetition.Enabled = False
Dim diverName As String = ListView_Competition_Divers.Items(0).Text
Dim eventName As String = ListView_Competition_Divers.Items(0).SubItems(1).Text
ListView_Competition_Divers.Items(0).BackColor = Color.LightCyan
Dim sb As New System.Text.StringBuilder
sb.AppendLine("Competitor Now Diving: " & diverName)
sb.AppendLine("Event Name: " & eventName)
Dim qry = From dt As DiveType In diveTypeList _
Where dt.Name = eventName
If qry.Count = 1 Then
Dim vidList As New List(Of String)
vidList = qry.First.DiveExampleURL_List
If vidList.Count = 0 Or (vidList.Count = 1 AndAlso vidList(0) Is Nothing) Then
WebBrowser1.Navigate(noVideoURL)
Else
Dim url As String = vidList(rand.Next(0, vidList.Count))
WebBrowser1.Navigate(url)
End If
End If
lbl_CompetitorUp.Text = sb.ToString
With btn_Competition_EnterJudgesScores
.Enabled = True
.Focus()
End With
End Sub
Private Sub btn_Competition_EnterJudgesScores_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles btn_Competition_EnterJudgesScores.Click
Using js As New JudgesScores
js.ShowDialog()
If Not js.userCancel Then
Dim diverName As String = ListView_Competition_Divers.Items(0).Text
Dim eventName As String = ListView_Competition_Divers.Items(0).SubItems(1).Text
Dim thisDS As New DiverScore
With thisDS
.DiverFullName = diverName
.EventName = eventName
Dim qry = From dt As DiveType In diveTypeList Where dt.Name = eventName
If qry.Count = 1 Then
.EventDegreeOfDifficulty = qry.First.DegreeOfDifficulty
End If
.Judge1Score = js.judgesScoresList(0)
.Judge2Score = js.judgesScoresList(1)
.Judge3Score = js.judgesScoresList(2)
.Judge4Score = js.judgesScoresList(3)
.Judge5Score = js.judgesScoresList(4)
.Judge6Score = js.judgesScoresList(5)
.Judge7Score = js.judgesScoresList(6)
.Judge8Score = js.judgesScoresList(7)
Dim judgeScoreList As New List(Of Double)
judgeScoreList.Add(.Judge1Score * .EventDegreeOfDifficulty)
judgeScoreList.Add(.Judge2Score * .EventDegreeOfDifficulty)
judgeScoreList.Add(.Judge3Score * .EventDegreeOfDifficulty)
judgeScoreList.Add(.Judge4Score * .EventDegreeOfDifficulty)
judgeScoreList.Add(.Judge5Score * .EventDegreeOfDifficulty)
judgeScoreList.Add(.Judge6Score * .EventDegreeOfDifficulty)
judgeScoreList.Add(.Judge7Score * .EventDegreeOfDifficulty)
judgeScoreList.Add(.Judge8Score * .EventDegreeOfDifficulty)
judgeScoreList.Sort()
.EventScore_8Judges = judgeScoreList.Sum
For i As Integer = 0 To judgeScoreList.Count - 1
If i > 0 AndAlso i < judgeScoreList.Count - 1 Then
.EventScore_6Judges += judgeScoreList(i)
End If
Next
End With
diversScoreList.Add(thisDS)
UpdateDiversScores(eventName)
lbl_CompetitorUp.Text = ""
ListView_Competition_Divers.Items.RemoveAt(0)
UpdateCompetitorsLabel()
btn_Competition_EnterJudgesScores.Enabled = False
btn_Competition_BeginCompetition_Click(Nothing, Nothing)
End If
End Using
End Sub
Private Sub UpdateDiversScores(ByVal eventName As String)
Dim csList As New List(Of CompetitonScores)
Dim competitorNames = From ds As DiverScore In diversScoreList _
Select ds.DiverFullName Distinct
Dim sb As New System.Text.StringBuilder
sb.AppendLine("----- " & eventName & " -----")
sb.AppendLine()
If ListView_Competition_Divers.Items.Count > 0 Then
For Each compName As String In competitorNames
Dim thisDiverName As String = compName
Dim qry = From ds As DiverScore In diversScoreList _
Where ds.DiverFullName = thisDiverName
Dim totalScoreSoFar As Double = 0
For Each ds As DiverScore In qry
totalScoreSoFar += ds.EventScore_6Judges
Next
Dim thisCS As New CompetitonScores
With thisCS
.DiverFullName = thisDiverName
.OverallScore += totalScoreSoFar
End With
csList.Add(thisCS)
Next
End If
Dim scoresQry = From cs As CompetitonScores In csList _
Order By cs.OverallScore Descending, cs.DiverFullName
For i As Integer = 0 To scoresQry.Count - 1
Dim thisCS As CompetitonScores = scoresQry(i)
If i > 0 Then
sb.AppendLine()
sb.AppendLine("--------------------")
sb.AppendLine()
End If
If i = 0 Then
sb.AppendLine("Competitor Name: " & thisCS.DiverFullName & "**")
Else
sb.AppendLine("Competitor Name: " & thisCS.DiverFullName)
End If
sb.AppendLine("Overall Score: " & thisCS.OverallScore.ToString("f2"))
Next
If sb.ToString.Length > 0 Then
With TextBox_DiversStats
.Text = sb.ToString
.Refresh()
End With
End If
End Sub
Private Sub ListView_Competition_Divers_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) _
Handles ListView_Competition_Divers.SelectedIndexChanged
If Not ListView_Competition_Divers.Items(0).Selected Then
ListView_Competition_Divers.Items(0).Selected = True
End If
End Sub
#End Region
End Class
Any and all help is greatly appreciated... Then after we get the scores calculated correctly, I need to factor in for the possiblity of a tie. I know I need to add back in the highest and lowest scores that were originally thrown out but other than that Im confused on where that would go and how that would look like in my code.
If you need any further information and/or code to help me figure this all out just let me know as I have 4 other files for this program.
View the full article
Option Explicit On
Imports System.IO.Path
Imports System.Environment
Public Class Form1
Private rand As New Random
Private Const noVideoURL As String = "http://www.fls-online.com/NoVideoAvailable.htm"
Private programDataFolderPath As String = _
Combine(GetFolderPath(SpecialFolder.ApplicationData), _
My.Application.Info.AssemblyName)
Private diversSetupFilePath As String = Combine(programDataFolderPath, "Diver Setup.xml")
Private diveTypeSetupFilePath As String = Combine(programDataFolderPath, "Dive Type Setup.xml")
Public diveTypeList As New List(Of DiveType)
Private diversList As New List(Of Diver)
Private diversScoreList As New List(Of DiverScore)
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles MyBase.Load
If Not My.Computer.FileSystem.DirectoryExists(programDataFolderPath) Then
My.Computer.FileSystem.CreateDirectory(programDataFolderPath)
End If
btn_SetupDiveType_EditSelected.Enabled = False
btn_SetupDiveType_RemoveSelected.Enabled = False
btn_Competition_BeginCompetition.Enabled = False
btn_Competition_EnterJudgesScores.Enabled = False
lbl_CompetitorUp.Text = ""
With ListView_Competition_Divers
.Columns.Add("Diver Name", 125, HorizontalAlignment.Left)
.Columns.Add("Dive Type", 150, HorizontalAlignment.Left)
.Columns.Add("Difficulty", 75, HorizontalAlignment.Left)
.FullRowSelect = True
.GridLines = True
.MultiSelect = False
.View = View.Details
End With
With TextBox_DiversStats
.ReadOnly = True
.ScrollBars = ScrollBars.Vertical
.Font = New Font("Tahoma", 10, FontStyle.Regular)
.BackColor = Me.BackColor
.TabStop = False
End With
WebBrowser1.Url = New Uri("http://www.fls-online.com/index.htm")
InitializeDiveTypes()
ReadDiveTypes()
ReadSettings()
CheckNoRows_SetupDivers()
PopulateDiveTypeDGV()
CheckNoRows_SetupDiveTypes()
UpdateCompetitorsLabel()
End Sub
Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) _
Handles Me.FormClosing
If e.CloseReason = CloseReason.UserClosing Then
If diversList.Count = 0 Then
If My.Computer.FileSystem.FileExists(diversSetupFilePath) Then
My.Computer.FileSystem.DeleteFile(diversSetupFilePath)
End If
Else
WriteSettings()
End If
WriteDiveTypes()
End If
End Sub
#Region "Classes And Enums"
Public Class DiveType
Public Name As String = "--"
Public DegreeOfDifficulty As Double
Public DiveExampleURL_List As New List(Of String)
Public IsPermanent As Boolean = False
End Class
Public Class Diver
Public FirstName As String = "--"
Public LastName As String = "--"
Public FullName As String = "--"
Public DiveTypeList As New List(Of DiveType)
End Class
Public Class CompetitionDiver
Public FullName As String = "--"
Public Selected As Boolean = False
End Class
Private Class DiverScore
Public DiverFullName As String = "--"
Public EventName As String = "--"
Public EventDegreeOfDifficulty As Double
Public Judge1Score As Double
Public Judge2Score As Double
Public Judge3Score As Double
Public Judge4Score As Double
Public Judge5Score As Double
Public Judge6Score As Double
Public Judge7Score As Double
Public Judge8Score As Double
Public EventScore_8Judges As Double
Public EventScore_6Judges As Double
End Class
Private Class CompetitonScores
Public DiverFullName As String = "--"
Public OverallScore As Double
End Class
#End Region
#Region "Common Methods And Functions"
Private Sub InitializeDiveTypes()
Dim dt As New DiveType
With dt
.Name = "Forward Dive"
.DegreeOfDifficulty = 1.4
.IsPermanent = True
.DiveExampleURL_List.Add("http://www.youtube.com/embed/8XiVkxZMmcI")
.DiveExampleURL_List.Add("http://www.youtube.com/embed/_9su0zu_-sU")
.DiveExampleURL_List.Add("http://www.youtube.com/embed/0QTUFLEiHgs")
.DiveExampleURL_List.Add("http://www.youtube.com/embed/fdBZ_Khsmg4")
.DiveExampleURL_List.Add("http://www.youtube.com/embed/gHH1_TLq_eE")
.DiveExampleURL_List.Add("http://www.youtube.com/embed/RkVvcIKm8q4")
End With
diveTypeList.Add(dt)
dt = New DiveType
With dt
.Name = "Forward 1-1/2 Somersaults"
.DegreeOfDifficulty = 2
.IsPermanent = True
.DiveExampleURL_List.Add("http://www.youtube.com/embed/nafbci68_jU")
.DiveExampleURL_List.Add("http://www.youtube.com/embed/B5IcsAd2sj4")
.DiveExampleURL_List.Add("http://www.youtube.com/embed/Lh5yKA3nQCQ")
.DiveExampleURL_List.Add("http://www.youtube.com/embed/602wxnWpw4o")
.DiveExampleURL_List.Add("http://www.youtube.com/embed/gNEO6A2-70A")
.DiveExampleURL_List.Add("http://www.youtube.com/embed/R2mf7xRi7G4")
End With
diveTypeList.Add(dt)
dt = New DiveType
With dt
.Name = "Back Dive"
.DegreeOfDifficulty = 1.76
.IsPermanent = True
.DiveExampleURL_List.Add("http://www.youtube.com/embed/e_8MI-8iH_E")
.DiveExampleURL_List.Add("http://www.youtube.com/embed/qsrwu4Yf_DU")
.DiveExampleURL_List.Add("http://www.youtube.com/embed/sVErMUCVgYE")
.DiveExampleURL_List.Add("http://www.youtube.com/embed/r4B691n8500")
.DiveExampleURL_List.Add("http://www.youtube.com/embed/wxgatI72-IY")
.DiveExampleURL_List.Add("http://www.youtube.com/embed/XnpY85hwlEk")
.DiveExampleURL_List.Add("http://www.youtube.com/embed/E3IsSslDjYA")
End With
diveTypeList.Add(dt)
dt = New DiveType
With dt
.Name = "Back 1-1/2 Somersaults"
.DegreeOfDifficulty = 2.54
.IsPermanent = True
.DiveExampleURL_List.Add("http://www.youtube.com/embed/nafbci68_jU")
.DiveExampleURL_List.Add("http://www.youtube.com/embed/B5IcsAd2sj4")
.DiveExampleURL_List.Add("http://www.youtube.com/embed/Lh5yKA3nQCQ")
.DiveExampleURL_List.Add("http://www.youtube.com/embed/602wxnWpw4o")
.DiveExampleURL_List.Add("http://www.youtube.com/embed/gNEO6A2-70A")
.DiveExampleURL_List.Add("http://www.youtube.com/embed/R2mf7xRi7G4")
End With
diveTypeList.Add(dt)
dt = New DiveType
With dt
.Name = "Inward Dive"
.DegreeOfDifficulty = 1.85
.IsPermanent = True
.DiveExampleURL_List.Add("http://www.youtube.com/embed/thC_mJaVNFI")
.DiveExampleURL_List.Add("http://www.youtube.com/embed/LVh4xJFGkRE")
.DiveExampleURL_List.Add("http://www.youtube.com/embed/k2vYS7hlaOg")
.DiveExampleURL_List.Add("http://www.youtube.com/embed/YB6hJiDLQ9s")
.DiveExampleURL_List.Add("http://www.youtube.com/embed/z3RhIH9YHBY")
End With
diveTypeList.Add(dt)
dt = New DiveType
With dt
.Name = "Inward 1-1/2 Somersaults "
.DegreeOfDifficulty = 2.46
.IsPermanent = True
.DiveExampleURL_List.Add("http://www.youtube.com/embed/7YcrO-6Iaqw")
.DiveExampleURL_List.Add("http://www.youtube.com/embed/XGU12WKAz6I")
.DiveExampleURL_List.Add("http://www.youtube.com/embed/Te4vz3uC2LA")
.DiveExampleURL_List.Add("http://www.youtube.com/embed/AE3mCtYNVPs")
.DiveExampleURL_List.Add("http://www.youtube.com/embed/cOrXjd_YAV4")
.DiveExampleURL_List.Add("http://www.youtube.com/embed/D4PYFcKqhhw")
End With
diveTypeList.Add(dt)
dt = New DiveType
With dt
.Name = "Forward Armstand"
.DegreeOfDifficulty = 1.65
.IsPermanent = True
.DiveExampleURL_List.Add("http://www.youtube.com/embed/SpCLAUEfEwg")
.DiveExampleURL_List.Add("http://www.youtube.com/embed/038Dm8aEWlw")
End With
diveTypeList.Add(dt)
dt = New DiveType
With dt
.Name = "Forward Armstand Somersault Tuck"
.DegreeOfDifficulty = 2.31
.IsPermanent = True
.DiveExampleURL_List.Add("http://www.youtube.com/embed/XipbK-6v_NY")
.DiveExampleURL_List.Add("http://www.youtube.com/embed/T_ctdgs9-Y0")
.DiveExampleURL_List.Add("http://www.youtube.com/embed/K-AV0_Z5ohs")
End With
diveTypeList.Add(dt)
End Sub
Private Sub CheckNoRows_SetupDivers()
If diversList.Count = 0 Then
btn_SetupDivers_EditSelected.Enabled = False
btn_SetupDivers_RemoveSelected.Enabled = False
SetupDivers_BindingNavigator.Enabled = False
SetupDivers_DataGridView.Enabled = False
Else
btn_SetupDivers_EditSelected.Enabled = True
btn_SetupDivers_RemoveSelected.Enabled = True
SetupDivers_BindingNavigator.Enabled = True
SetupDivers_DataGridView.Enabled = True
End If
End Sub
Private Sub CheckNoRows_SetupDiveTypes()
If diveTypeList.Count = 0 Then
DiveType_BindingNavigator.Enabled = False
DiveType_DataGridView.Enabled = False
Else
DiveType_BindingNavigator.Enabled = True
DiveType_DataGridView.Enabled = True
End If
End Sub
Private Sub PopulateDiversDGV()
With SetupDivers_BindingNavigator
.BindingSource = Nothing
.Enabled = False
End With
With SetupDivers_DataGridView
.DataSource = Nothing
.Enabled = False
End With
If diversList.Count > 0 Then
Dim qry = From d As Diver In diversList _
Order By d.FullName
Dim dt As New DataTable
Dim column As New DataColumn
With column
.DataType = System.Type.GetType("System.String")
.ColumnName = "Divers First Name"
dt.Columns.Add(column)
End With
column = New DataColumn
With column
.DataType = System.Type.GetType("System.String")
.ColumnName = "Divers Last Name"
dt.Columns.Add(column)
End With
column = New DataColumn
With column
.DataType = System.Type.GetType("System.String")
.ColumnName = "Divers Full Name"
dt.Columns.Add(column)
End With
Dim row As DataRow
For Each d As Diver In qry
row = dt.NewRow
row("Divers First Name") = d.FirstName
row("Divers Last Name") = d.LastName
row("Divers Full Name") = d.FullName
dt.Rows.Add(row)
Next
Dim bs As New BindingSource
bs.DataSource = dt
With SetupDivers_BindingNavigator
.BindingSource = bs
.Enabled = True
End With
With SetupDivers_DataGridView
.DataSource = bs
.Enabled = True
.SelectionMode = DataGridViewSelectionMode.FullRowSelect
.MultiSelect = False
.AlternatingRowsDefaultCellStyle.BackColor = Color.LightBlue
.Columns(0).Width = 100
.Columns(1).Width = 100
.Columns(2).AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill
If SetupDivers_DataGridView.RowCount > 0 Then
SetupDivers_DataGridView.Rows(0).Selected = True
End If
End With
If diversList.Count = 0 Then
If My.Computer.FileSystem.FileExists(diversSetupFilePath) Then
My.Computer.FileSystem.DeleteFile(diversSetupFilePath)
End If
Else
WriteSettings()
End If
Else
PopulateDivers_DiveTypeDGV("")
End If
End Sub
Private Sub PopulateDivers_DiveTypeDGV(ByVal diverFullName As String)
SetupDivers_DiveType_DataGridView.DataSource = Nothing
Dim qry = From thisDiver As Diver In diversList _
Where thisDiver.FullName = diverFullName
If qry.Count = 1 Then
Dim dt As New DataTable
Dim column As New DataColumn
With column
.DataType = System.Type.GetType("System.String")
.ColumnName = "Dive Type"
dt.Columns.Add(column)
End With
column = New DataColumn
With column
.DataType = System.Type.GetType("System.Double")
.ColumnName = "Degree Of Difficulty"
dt.Columns.Add(column)
End With
Dim row As DataRow
For Each dType As DiveType In qry.First.DiveTypeList
row = dt.NewRow
row("Dive Type") = dType.Name
row("Degree Of Difficulty") = dType.DegreeOfDifficulty
dt.Rows.Add(row)
Next
Dim bs As New BindingSource
bs.DataSource = dt
With SetupDivers_DiveType_DataGridView
.DataSource = bs
.Enabled = True
.SelectionMode = DataGridViewSelectionMode.FullRowSelect
.MultiSelect = False
.RowHeadersVisible = False
.AlternatingRowsDefaultCellStyle.BackColor = Color.LightGreen
.Columns(0).Width = 300
With .Columns(1)
.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill
.DefaultCellStyle.Format = "f2"
End With
End With
End If
End Sub
Private Sub PopulateDiveTypeDGV()
With DiveType_BindingNavigator
.BindingSource = Nothing
.Enabled = False
End With
With DiveType_DataGridView
.DataSource = Nothing
.Enabled = False
End With
If diveTypeList.Count > 0 Then
Dim qry = From dType As DiveType In diveTypeList _
Order By dType.Name
Dim dt As New DataTable
Dim column As New DataColumn
With column
.DataType = System.Type.GetType("System.String")
.ColumnName = "Dive Type Name"
dt.Columns.Add(column)
End With
column = New DataColumn
With column
.DataType = System.Type.GetType("System.Double")
.ColumnName = "Degree Of Difficulty"
dt.Columns.Add(column)
End With
column = New DataColumn
With column
.DataType = System.Type.GetType("System.Int32")
.ColumnName = "Example URL Count"
dt.Columns.Add(column)
End With
Dim row As DataRow
For Each dType As DiveType In qry
row = dt.NewRow
row("Dive Type Name") = dType.Name
row("Degree Of Difficulty") = dType.DegreeOfDifficulty
row("Example URL Count") = dType.DiveExampleURL_List.Count
dt.Rows.Add(row)
Next
Dim bs As New BindingSource
bs.DataSource = dt
With DiveType_BindingNavigator
.BindingSource = bs
.Enabled = True
End With
With DiveType_DataGridView
.DataSource = bs
.Enabled = True
.SelectionMode = DataGridViewSelectionMode.FullRowSelect
.MultiSelect = False
.AlternatingRowsDefaultCellStyle.BackColor = Color.LightSalmon
.Columns(0).Width = 350
With .Columns(1)
.Width = 150
.DefaultCellStyle.Format = "f2"
End With
With .Columns(2)
.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill
.DefaultCellStyle.Format = "n0"
End With
If DiveType_DataGridView.RowCount > 0 Then
DiveType_DataGridView.Rows(0).Selected = True
End If
End With
End If
End Sub
Private Sub ReadSettings()
If My.Computer.FileSystem.FileExists(diversSetupFilePath) Then
diversList.Clear()
Dim settingsInfo = XElement.Load(diversSetupFilePath)
For Each diverInfo As XElement In settingsInfo...<DiverSetup>
Dim thisDiver As New Diver
With thisDiver
.FirstName = diverInfo...<FirstName>.Value
.LastName = diverInfo...<LastName>.Value
.FullName = .FirstName & " " & .LastName
Dim dtList As New List(Of DiveType)
For Each dtInfo As XElement In diverInfo...<DiveTypeNames>
For Each diveName As XElement In dtInfo...<Name>
Dim thisDiveName As String = diveName.Value
Dim qry = From dt As DiveType In diveTypeList _
Where dt.Name = thisDiveName
If qry.Count = 1 Then
dtList.Add(qry.First)
End If
Next
Next
thisDiver.DiveTypeList = dtList
End With
diversList.Add(thisDiver)
Next
PopulateDiversDGV()
End If
End Sub
Private Sub WriteSettings()
Dim settingsDoc = <DiversSetup>
<%= From d As Diver In diversList Select _
<DiverSetup>
<FirstName><%= d.FirstName %></FirstName>
<LastName><%= d.LastName %></LastName>
<DiveTypeNames><%= From dt As DiveType In d.DiveTypeList Select _
<Name><%= dt.Name %></Name> %>
</DiveTypeNames>
</DiverSetup> %>
</DiversSetup>
settingsDoc.Save(diversSetupFilePath)
End Sub
Private Sub ReadDiveTypes()
If My.Computer.FileSystem.FileExists(diveTypeSetupFilePath) Then
Dim diveTypeInfo = XElement.Load(diveTypeSetupFilePath)
For Each dt As XElement In diveTypeInfo...<DiveType>
Dim thisDiveType As New DiveType
Dim allValuesGood As Boolean = True
With thisDiveType
.Name = dt...<Name>.Value
If Not Double.TryParse(dt...<DegreeOfDifficulty>.Value, .DegreeOfDifficulty) Then
allValuesGood = False
End If
If Not Boolean.TryParse(dt...<IsPermanent>.Value, .IsPermanent) Then
allValuesGood = False
End If
If allValuesGood Then
For Each url As XElement In dt...<URLs>
.DiveExampleURL_List.Add(url...<URL>.Value)
Next
End If
End With
If allValuesGood Then
diveTypeList.Add(thisDiveType)
End If
Next
End If
End Sub
Private Sub WriteDiveTypes()
Dim qry = From dt As DiveType In diveTypeList Where Not dt.IsPermanent
If qry.Count > 0 Then
Dim diveTypeDoc = <DiveTypes>
<%= From dt As DiveType In diveTypeList Where Not dt.IsPermanent Select _
<DiveType>
<Name><%= dt.Name %></Name>
<DegreeOfDifficulty><%= dt.DegreeOfDifficulty.ToString %></DegreeOfDifficulty>
<IsPermanent><%= dt.IsPermanent.ToString %></IsPermanent>
<URLs><%= From s As String In dt.DiveExampleURL_List Select _
<URL><%= s %></URL> %>
</URLs>
</DiveType> %>
</DiveTypes>
diveTypeDoc.Save(diveTypeSetupFilePath)
Else
If My.Computer.FileSystem.FileExists(diveTypeSetupFilePath) Then
My.Computer.FileSystem.DeleteFile(diveTypeSetupFilePath)
End If
End If
End Sub
Private Sub UpdateCompetitorsLabel()
If ListView_Competition_Divers.Items.Count = 0 Then
lbl_Competion_SelectedDivers.Text = "Total Competitors: 0 | Total Events: 0"
Else
Dim competitorCount As Integer = 0
For i As Integer = 0 To ListView_Competition_Divers.Items.Count - 1
If i = 0 Then
competitorCount += 1
Else
If ListView_Competition_Divers.Items(i).Text <> ListView_Competition_Divers.Items(i - 1).Text Then
competitorCount += 1
End If
End If
Next
lbl_Competion_SelectedDivers.Text = "Total Competitors: " & competitorCount.ToString("n0") & _
" | Total Events: " & ListView_Competition_Divers.Items.Count.ToString("n0")
End If
End Sub
#End Region
#Region "Main"
Private Sub TabControl_Main_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) _
Handles TabControl_Main.SelectedIndexChanged
If TabControl_Main.SelectedTab.Name = "TabPage_Competition" Then
If diversList.Count < 16 Then
Dim sb As New System.Text.StringBuilder
sb.AppendLine("There must be a minimum of sixteen (16)")
sb.AppendLine("divers set up before the competition can")
sb.AppendLine("be run.")
sb.AppendLine()
sb.AppendLine("This program will navigate you back to the")
sb.AppendLine("setup area where you can add divers in")
sb.AppendLine("order to fulfill this requirement.")
MessageBox.Show(sb.ToString, "Cannot Navigate To Competition", _
MessageBoxButtons.OK, MessageBoxIcon.Warning)
TabControl_Main.SelectedTab = TabPage_Setup
End If
End If
End Sub
#End Region
#Region "Setup Divers"
Private Sub btn_Setup_AddNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles btn_SetupDivers_AddNew.Click
Using aed As New AddEditDiver
aed.ShowDialog()
If Not aed.userCancel Then
Dim qry = From d As Diver In diversList _
Where d.FullName = aed.diver.FullName
If qry.Count = 0 Then
diversList.Add(aed.diver)
PopulateDiversDGV()
CheckNoRows_SetupDivers()
WriteSettings()
Else
MessageBox.Show("This diver is already in your list" & vbCrLf & _
"and therefore cannot be added.", "Cannot Add Diver", _
MessageBoxButtons.OK, MessageBoxIcon.Warning)
End If
End If
End Using
End Sub
Private Sub btn_Setup_EditSelected_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles btn_SetupDivers_EditSelected.Click
If SetupDivers_DataGridView.RowCount > 0 AndAlso SetupDivers_DataGridView.SelectedRows.Count = 1 Then
Dim fullName As String = SetupDivers_DataGridView.SelectedRows(0).Cells(2).Value.ToString
Dim qry = From d As Diver In diversList _
Where d.FullName = fullName
If qry.Count = 1 Then
Dim diverFullName As String = qry.First.FullName
Using aed As New AddEditDiver
aed.diver = qry.First
aed.ShowDialog()
If Not aed.userCancel Then
Dim thisDiver As New Diver
With thisDiver
.FirstName = aed.diver.FirstName
.LastName = aed.diver.LastName
.FullName = aed.diver.FullName
Dim dtList As New List(Of DiveType)
For Each dt As DiveType In aed.diver.DiveTypeList
dtList.Add(dt)
Next
.DiveTypeList = dtList
End With
For i As Integer = diversList.Count - 1 To 0 Step -1
If diversList(i).FullName = diverFullName Then
diversList.RemoveAt(i)
Exit For
End If
Next
diversList.Add(thisDiver)
PopulateDiversDGV()
End If
End Using
WriteSettings()
End If
End If
End Sub
Private Sub btn_Setup_RemoveSelected_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles btn_SetupDivers_RemoveSelected.Click
If SetupDivers_DataGridView.RowCount > 0 AndAlso SetupDivers_DataGridView.SelectedRows.Count = 1 Then
Dim fullName As String = SetupDivers_DataGridView.SelectedRows(0).Cells(2).Value.ToString
Dim qry = From d As Diver In diversList _
Where d.FullName = fullName
If qry.Count = 1 Then
Dim sb As New System.Text.StringBuilder
sb.AppendLine("You have elected to remove the")
sb.AppendLine("following diver from your list:")
sb.AppendLine()
sb.AppendLine("First Name: " & qry.First.FirstName)
sb.AppendLine("Last Name: " & qry.First.LastName)
sb.AppendLine("Dive Types Defined: " & qry.First.DiveTypeList.Count.ToString("n0"))
sb.AppendLine()
sb.AppendLine("Are you certain that you want to")
sb.AppendLine("PERMANENTLY remove this diver")
sb.AppendLine("from your list of divers?")
If MessageBox.Show(sb.ToString, "Confirm Deletion", MessageBoxButtons.YesNo, _
MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
For i As Integer = diversList.Count - 1 To 0 Step -1
If diversList(i).FullName = qry.First.FullName Then
diversList.RemoveAt(i)
Exit For
End If
Next
PopulateDiversDGV()
CheckNoRows_SetupDivers()
End If
WriteSettings()
End If
End If
End Sub
Private Sub SetupDivers_DataGridView_SelectionChanged(ByVal sender As Object, ByVal e As System.EventArgs) _
Handles SetupDivers_DataGridView.SelectionChanged
If SetupDivers_DataGridView.RowCount > 0 AndAlso SetupDivers_DataGridView.SelectedRows.Count = 1 Then
Dim fullName As String = SetupDivers_DataGridView.SelectedRows(0).Cells(2).Value.ToString
Dim qry = From d As Diver In diversList Where d.FullName = fullName
If qry.Count = 1 Then
PopulateDivers_DiveTypeDGV(qry.First.FullName)
End If
End If
End Sub
#End Region
#Region "Setup Dive Types"
Private Sub btn_SetupDiveType_AddNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles btn_SetupDiveType_AddNew.Click
Using aedt As New AddEditDiveType
aedt.ShowDialog()
If Not aedt.userCancel Then
Dim evaluateDiveName As String = aedt.diveType.Name.ToLower
If evaluateDiveName.Contains(" "c) Then
evaluateDiveName = evaluateDiveName.Replace(" "c, "")
End If
Dim findDuplicate = From dt As DiveType In diveTypeList _
Where dt.Name.ToLower.Replace(" "c, "") = evaluateDiveName
If findDuplicate.Count = 0 Then
diveTypeList.Add(aedt.diveType)
PopulateDiveTypeDGV()
CheckNoRows_SetupDiveTypes()
WriteDiveTypes()
Else
MessageBox.Show("This dive type has already been defined" & vbCrLf & _
"and therefore cannot be added.", "Cannot Add This Dive Type", _
MessageBoxButtons.OK, MessageBoxIcon.Warning)
End If
End If
End Using
End Sub
Private Sub btn_SetupDiveType_EditSelected_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles btn_SetupDiveType_EditSelected.Click
If DiveType_DataGridView.RowCount > 0 AndAlso _
DiveType_DataGridView.SelectedRows.Count = 1 Then
Dim diveName As String = DiveType_DataGridView.SelectedRows(0).Cells(0).Value.ToString
Dim qry = From dt As DiveType In diveTypeList _
Where dt.Name = diveName
If qry.Count = 1 Then
Using aedt As New AddEditDiveType
aedt.diveType = qry.First
aedt.ShowDialog()
If Not aedt.userCancel Then
For i As Integer = diveTypeList.Count - 1 To 0 Step -1
If diveTypeList(i).Name = diveName Then
diveTypeList.RemoveAt(i)
Exit For
End If
Next
Dim thisDiveType As New DiveType
With thisDiveType
.Name = aedt.diveType.Name
.DegreeOfDifficulty = aedt.diveType.DegreeOfDifficulty
.DiveExampleURL_List = aedt.diveType.DiveExampleURL_List
End With
For Each d As Diver In diversList
For i As Integer = d.DiveTypeList.Count - 1 To 0 Step -1
If d.DiveTypeList(i).Name = diveName Then
d.DiveTypeList.RemoveAt(i)
d.DiveTypeList.Add(thisDiveType)
End If
Next
Next
diveTypeList.Add(thisDiveType)
PopulateDiveTypeDGV()
PopulateDiversDGV()
CheckNoRows_SetupDiveTypes()
WriteDiveTypes()
End If
End Using
End If
End If
End Sub
Private Sub btn_SetupDiveType_RemoveSelected_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles btn_SetupDiveType_RemoveSelected.Click
If DiveType_DataGridView.RowCount > 0 AndAlso _
DiveType_DataGridView.SelectedRows.Count = 1 Then
Dim diveName As String = DiveType_DataGridView.SelectedRows(0).Cells(0).Value.ToString
Dim qry = From dt As DiveType In diveTypeList _
Where dt.Name = diveName
If qry.Count = 1 Then
Dim sb As New System.Text.StringBuilder
sb.AppendLine("You have elected to remove the")
sb.AppendLine("following dive type from your list:")
sb.AppendLine()
sb.AppendLine("Dive Type Name: " & qry.First.Name)
sb.AppendLine("Degree Of Difficulty: " & qry.First.DegreeOfDifficulty.ToString("f2"))
sb.AppendLine("Example URL Count: " & qry.First.DiveExampleURL_List.Count.ToString("n0"))
sb.AppendLine()
sb.AppendLine("Are you certain that you want to")
sb.AppendLine("PERMANENTLY remove this dive type")
sb.AppendLine("from your list of dive types?")
If MessageBox.Show(sb.ToString, "Confirm Deletion", MessageBoxButtons.YesNo, _
MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
For i As Integer = diveTypeList.Count - 1 To 0 Step -1
If diveTypeList(i).Name = diveName Then
diveTypeList.RemoveAt(i)
Exit For
End If
Next
For Each d As Diver In diversList
For i As Integer = d.DiveTypeList.Count - 1 To 0 Step -1
If d.DiveTypeList(i).Name = diveName Then
d.DiveTypeList.RemoveAt(i)
End If
Next
Next
PopulateDiveTypeDGV()
PopulateDiversDGV()
CheckNoRows_SetupDiveTypes()
WriteDiveTypes()
End If
End If
End If
End Sub
Private Sub DiveType_DataGridView_SelectionChanged(ByVal sender As Object, ByVal e As System.EventArgs) _
Handles DiveType_DataGridView.SelectionChanged
If DiveType_DataGridView.RowCount > 0 AndAlso _
DiveType_DataGridView.SelectedRows.Count = 1 Then
Dim diveName As String = DiveType_DataGridView.SelectedRows(0).Cells(0).Value.ToString
Dim qry = From dt As DiveType In diveTypeList _
Where dt.Name = diveName
If qry.Count = 1 Then
If qry.First.IsPermanent Then
btn_SetupDiveType_EditSelected.Enabled = False
btn_SetupDiveType_RemoveSelected.Enabled = False
Else
btn_SetupDiveType_EditSelected.Enabled = True
btn_SetupDiveType_RemoveSelected.Enabled = True
End If
End If
End If
End Sub
#End Region
#Region "Competition"
Private Sub btn_Competition_AddEditDivers_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles btn_Competition_AddEditDivers.Click
diversScoreList.Clear()
Dim dsList As New List(Of CompetitionDiver)
For Each d As Diver In diversList
Dim thisComp As New CompetitionDiver
With thisComp
.FullName = d.FullName
.Selected = False
End With
dsList.Add(thisComp)
Next
If ListView_Competition_Divers.Items.Count > 0 Then
For Each lvi As ListViewItem In ListView_Competition_Divers.Items
Dim fullName As String = lvi.Text
Dim qry = From cd As CompetitionDiver In dsList _
Where cd.FullName = fullName
If qry.Count = 1 Then
qry.First.Selected = True
End If
Next
End If
Using caed As New CompetitionAddEditDivers
caed.competitorsList = dsList
caed.ShowDialog()
If Not caed.userCancel Then
Dim qry = From cd As CompetitionDiver In caed.competitorsList _
Where cd.Selected Order By cd.FullName
With ListView_Competition_Divers
.BeginUpdate()
.Items.Clear()
Dim eventsList As New List(Of String)
For Each cd As CompetitionDiver In qry
Dim diverName As String = cd.FullName
Dim findEvents = From d As Diver In diversList Where d.FullName = diverName
For Each d As Diver In findEvents
For Each dt As DiveType In d.DiveTypeList
If Not eventsList.Contains(dt.Name) Then
eventsList.Add(dt.Name)
End If
Next
Next
Next
eventsList.Sort()
For Each competition As String In eventsList
For Each cd As CompetitionDiver In qry
Dim diverName As String = cd.FullName
Dim findDiver = From d As Diver In diversList _
Where d.FullName = diverName
If findDiver.Count = 1 Then
For Each dt As DiveType In findDiver.First.DiveTypeList
If dt.Name = competition Then
Dim lvItem As New ListViewItem(cd.FullName, 0)
lvItem.SubItems.Add(dt.Name)
lvItem.SubItems.Add(dt.DegreeOfDifficulty.ToString("f2"))
ListView_Competition_Divers.Items.AddRange(New ListViewItem() {lvItem})
End If
Next
End If
Next
Next
.EndUpdate()
End With
End If
End Using
If ListView_Competition_Divers.Items.Count = 0 Then
btn_Competition_BeginCompetition.Enabled = False
Else
btn_Competition_BeginCompetition.Enabled = True
End If
UpdateCompetitorsLabel()
End Sub
Private Sub btn_Competition_BeginCompetition_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles btn_Competition_BeginCompetition.Click
btn_Competition_AddEditDivers.Enabled = False
btn_Competition_BeginCompetition.Enabled = False
Dim diverName As String = ListView_Competition_Divers.Items(0).Text
Dim eventName As String = ListView_Competition_Divers.Items(0).SubItems(1).Text
ListView_Competition_Divers.Items(0).BackColor = Color.LightCyan
Dim sb As New System.Text.StringBuilder
sb.AppendLine("Competitor Now Diving: " & diverName)
sb.AppendLine("Event Name: " & eventName)
Dim qry = From dt As DiveType In diveTypeList _
Where dt.Name = eventName
If qry.Count = 1 Then
Dim vidList As New List(Of String)
vidList = qry.First.DiveExampleURL_List
If vidList.Count = 0 Or (vidList.Count = 1 AndAlso vidList(0) Is Nothing) Then
WebBrowser1.Navigate(noVideoURL)
Else
Dim url As String = vidList(rand.Next(0, vidList.Count))
WebBrowser1.Navigate(url)
End If
End If
lbl_CompetitorUp.Text = sb.ToString
With btn_Competition_EnterJudgesScores
.Enabled = True
.Focus()
End With
End Sub
Private Sub btn_Competition_EnterJudgesScores_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles btn_Competition_EnterJudgesScores.Click
Using js As New JudgesScores
js.ShowDialog()
If Not js.userCancel Then
Dim diverName As String = ListView_Competition_Divers.Items(0).Text
Dim eventName As String = ListView_Competition_Divers.Items(0).SubItems(1).Text
Dim thisDS As New DiverScore
With thisDS
.DiverFullName = diverName
.EventName = eventName
Dim qry = From dt As DiveType In diveTypeList Where dt.Name = eventName
If qry.Count = 1 Then
.EventDegreeOfDifficulty = qry.First.DegreeOfDifficulty
End If
.Judge1Score = js.judgesScoresList(0)
.Judge2Score = js.judgesScoresList(1)
.Judge3Score = js.judgesScoresList(2)
.Judge4Score = js.judgesScoresList(3)
.Judge5Score = js.judgesScoresList(4)
.Judge6Score = js.judgesScoresList(5)
.Judge7Score = js.judgesScoresList(6)
.Judge8Score = js.judgesScoresList(7)
Dim judgeScoreList As New List(Of Double)
judgeScoreList.Add(.Judge1Score * .EventDegreeOfDifficulty)
judgeScoreList.Add(.Judge2Score * .EventDegreeOfDifficulty)
judgeScoreList.Add(.Judge3Score * .EventDegreeOfDifficulty)
judgeScoreList.Add(.Judge4Score * .EventDegreeOfDifficulty)
judgeScoreList.Add(.Judge5Score * .EventDegreeOfDifficulty)
judgeScoreList.Add(.Judge6Score * .EventDegreeOfDifficulty)
judgeScoreList.Add(.Judge7Score * .EventDegreeOfDifficulty)
judgeScoreList.Add(.Judge8Score * .EventDegreeOfDifficulty)
judgeScoreList.Sort()
.EventScore_8Judges = judgeScoreList.Sum
For i As Integer = 0 To judgeScoreList.Count - 1
If i > 0 AndAlso i < judgeScoreList.Count - 1 Then
.EventScore_6Judges += judgeScoreList(i)
End If
Next
End With
diversScoreList.Add(thisDS)
UpdateDiversScores(eventName)
lbl_CompetitorUp.Text = ""
ListView_Competition_Divers.Items.RemoveAt(0)
UpdateCompetitorsLabel()
btn_Competition_EnterJudgesScores.Enabled = False
btn_Competition_BeginCompetition_Click(Nothing, Nothing)
End If
End Using
End Sub
Private Sub UpdateDiversScores(ByVal eventName As String)
Dim csList As New List(Of CompetitonScores)
Dim competitorNames = From ds As DiverScore In diversScoreList _
Select ds.DiverFullName Distinct
Dim sb As New System.Text.StringBuilder
sb.AppendLine("----- " & eventName & " -----")
sb.AppendLine()
If ListView_Competition_Divers.Items.Count > 0 Then
For Each compName As String In competitorNames
Dim thisDiverName As String = compName
Dim qry = From ds As DiverScore In diversScoreList _
Where ds.DiverFullName = thisDiverName
Dim totalScoreSoFar As Double = 0
For Each ds As DiverScore In qry
totalScoreSoFar += ds.EventScore_6Judges
Next
Dim thisCS As New CompetitonScores
With thisCS
.DiverFullName = thisDiverName
.OverallScore += totalScoreSoFar
End With
csList.Add(thisCS)
Next
End If
Dim scoresQry = From cs As CompetitonScores In csList _
Order By cs.OverallScore Descending, cs.DiverFullName
For i As Integer = 0 To scoresQry.Count - 1
Dim thisCS As CompetitonScores = scoresQry(i)
If i > 0 Then
sb.AppendLine()
sb.AppendLine("--------------------")
sb.AppendLine()
End If
If i = 0 Then
sb.AppendLine("Competitor Name: " & thisCS.DiverFullName & "**")
Else
sb.AppendLine("Competitor Name: " & thisCS.DiverFullName)
End If
sb.AppendLine("Overall Score: " & thisCS.OverallScore.ToString("f2"))
Next
If sb.ToString.Length > 0 Then
With TextBox_DiversStats
.Text = sb.ToString
.Refresh()
End With
End If
End Sub
Private Sub ListView_Competition_Divers_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) _
Handles ListView_Competition_Divers.SelectedIndexChanged
If Not ListView_Competition_Divers.Items(0).Selected Then
ListView_Competition_Divers.Items(0).Selected = True
End If
End Sub
#End Region
End Class
Any and all help is greatly appreciated... Then after we get the scores calculated correctly, I need to factor in for the possiblity of a tie. I know I need to add back in the highest and lowest scores that were originally thrown out but other than that Im confused on where that would go and how that would look like in my code.
If you need any further information and/or code to help me figure this all out just let me know as I have 4 other files for this program.
View the full article