188 lines
5.5 KiB
VB.net

Imports System.IO
Imports MySql.Data.MySqlClient
Public Class fighter
' Scoring Information
Private _event As Integer ' Event Number
Private _match As Integer ' Match Number
Private _person As person ' Fighter ID
Private _score As Integer ' Total Score
Private _gamjum As Integer ' Total Gamgum Foul
Private _tranfer As Integer ' Transfered Point From Opponent Gam Jum
'-----------------------------------------------------------------------------------------------------------
' Properties
'-----------------------------------------------------------------------------------------------------------
Public Sub New(FighterID As Integer, EventID As Integer, MatchID As Integer)
_person = New person(FighterID)
_event = EventID
_match = MatchID
_score = 0
_gamjum = 0
End Sub
'-----------------------------------------------------------------------------------------------------------
' Properties
'-----------------------------------------------------------------------------------------------------------
ReadOnly Property Person As person
Get
Return _person
End Get
End Property
ReadOnly Property Score As Integer
Get
Return _score
End Get
End Property
ReadOnly Property Gamjum As Integer
Get
Return _gamjum
End Get
End Property
'-----------------------------------------------------------------------------------------------------------
' Subroutines
'-----------------------------------------------------------------------------------------------------------
Public Sub AdjustScore(Amount As Integer)
_score += Amount
RegisterScore(Amount, 0)
End Sub
Public Sub AdjustGamjum(Amount As Integer)
_gamjum += Amount
RegisterScore(0, Amount)
End Sub
'-----------------------------------------------------------------------------------------------------------
' Subroutines
'-----------------------------------------------------------------------------------------------------------
Public Sub RegisterScore(Score As Integer, Gamjum As Integer)
Dim QRY As String = ("
insert into event_matches_scores (eid, mid, pid, score, gamjum) values (" & _event & ", " & _match & ", " & _person.ID & ", " & Score & ", " & Gamjum & ");
select sum(score) as 'score', sum(gamjum) as 'gamjum' from event_matches_scores where eid = " & _event & " and mid = " & _match & " and pid = " & _person.ID & ";
")
' Connection
Dim CON As New MySqlConnection(CON_STRING)
Dim COM As New MySqlCommand(QRY, CON)
Dim RDR As MySqlDataReader
Try
CON.Open()
RDR = COM.ExecuteReader
If RDR.HasRows = True Then
While RDR.Read
Try ' Score
_score = RDR("score")
Catch ex As Exception
_score = 0
End Try
Try ' Gamjum
_gamjum = RDR("gamjum")
Catch ex As Exception
_gamjum = 0
End Try
End While
End If
CON.Close()
Catch ex As MySqlException
MessageBox.Show(ex.Message)
End Try
End Sub
Private Sub GetMatchScores()
Dim QRY As String = ("select sum(score) as 'score', sum(gamjum) as 'gamjum' from event_matches_scores where eid = " & _event & " and mid = " & _match & " and pid = " & _person.ID & ";")
Dim CON As New MySqlConnection(CON_STRING)
Dim COM As New MySqlCommand(QRY, CON)
Dim RDR As MySqlDataReader
Try
CON.Open()
RDR = COM.ExecuteReader
If RDR.HasRows = True Then
While RDR.Read
Try ' Score
_score = RDR("score")
Catch ex As Exception
_score = 0
End Try
Try ' Gamjum
_gamjum = RDR("gamjum")
Catch ex As Exception
_gamjum = 0
End Try
End While
End If
CON.Close()
Catch ex As MySqlException
MessageBox.Show(ex.Message)
End Try
End Sub
Public Function GetPointsList() As List(Of country)
Dim QRY As String = ("
select
score,
gamjum
from
event_matches_scores
where
eid = " & _event & " and mid = " & _match & " and pid = " & _person.ID & "
order by
eid,
mid
desc;
")
Dim CON As New MySqlConnection(CON_STRING)
Dim COM As New MySqlCommand(QRY, CON)
Dim RDR As MySqlDataReader
Dim LST As New List(Of country)
Try
CON.Open()
RDR = COM.ExecuteReader
If RDR.HasRows = True Then
While RDR.Read
LST.Add(New country(RDR("id")))
End While
End If
CON.Close()
Catch ex As MySqlException
MessageBox.Show(ex.Message)
Finally
CON.Dispose()
End Try
Return LST
End Function
End Class