first visual basic code upload

This commit is contained in:
ghassan committed 2020-02-16 03:39:56 +03:00
1 parent 93697318e4
commit 5e53ab7d73
101 files changed
+21213

No files matched your search

@@ -0,0 +1,187 @@
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
@@ -0,0 +1,409 @@
Imports System.IO
Imports MySql.Data.MySqlClient
Public Class match
'--[MATCH FIGHTERS]---------------
Public BlueFighter As fighter ' Blue Fighter Information
Public RedFighter As fighter ' Red Fighter Information
'--[MATCH REFEREE]----------------
Public Referee As person ' Referee Information
'--[MATCH RECORD NUMBER]----------
Private _eventID As Integer ' Event Record Number & Also The Event Number
Private _courtID As Integer ' Court Record Number
Private _matchID As Integer ' Match Record Number
'--[EVENT MATCH NUMBERS]----------
Private _eventRound As Integer ' Event Phase Number (Which Phase Is The Event Matches)
Private _matchNumber As Integer ' Match Event Round Match Number
Private _courtNumber As Integer ' Match Court Number
'--[MATCH SETTINGS]---------------
Private _maxRound As Integer ' Max Number Of Rounds
Private _maxRoundMin As Integer ' Max Round Minutes
Private _maxRoundSec As Integer ' Max Round Sec
Private _maxBreakMin As Integer ' Max Break Minutes
Private _maxBreakSec As Integer ' Max Break Seconds
Private _maxScoreDif As Integer ' Max Score Difference
Private _enaMaxSdiff As Boolean ' End Match When Difference Reached
Private _enaSudenDth As Boolean ' Enable Forth Round When Score Are Equal
'--[Display Numbers]--------------
Private _RoundNum As Integer = 1 ' Round Number
Private _RoundMin As Integer ' Round Minutes
Private _RoundSec As Integer ' Round Seconds
Private _BreakMin As Integer ' Break Minutes
Private _BreakSec As Integer ' Break Seconds
'--[CONSTRUCTORS]-------------------------------------------------
ReadOnly Property ID As Integer
Get
Return _matchID
End Get
End Property
ReadOnly Property COURT As Integer
Get
Return _courtID
End Get
End Property
ReadOnly Property ROUND As Integer
Get
Return _RoundNum
End Get
End Property
'--[CONSTRUCTORS]-------------------------------------------------
' Incase you have an event and its match number
Public Sub New(EventID As Integer, MatchNumber As Integer)
_eventID = EventID
_matchID = MatchNumber
GetMatchData()
End Sub
' Incase you want to create instant match
Public Sub New(BlueID As Integer, RedID As Integer, RefereeID As Integer)
BlueFighter = New fighter(BlueID, _eventID, _matchID)
RedFighter = New fighter(RedID, _eventID, _matchID)
Referee = New person(RefereeID)
SetDefault()
ReTime_Round()
ReTime_Break()
End Sub
'-----------------------------------------------------------------
' READING MATCH NUMBER
'-----------------------------------------------------------------
Private Sub SetDefault()
_RoundNum = 1
_maxRound = My.Settings.match_rounds
_maxRoundMin = My.Settings.match_round_time_minutes
_maxRoundSec = My.Settings.match_round_time_seconds
_maxBreakMin = My.Settings.match_break_time_minutes
_maxBreakSec = My.Settings.match_break_time_seconds
_enaSudenDth = My.Settings.match_enable_sudden_death
End Sub
Private Sub ReTime_Round()
_RoundMin = _maxRoundMin
_RoundSec = _maxRoundSec
End Sub
Private Sub ReTime_Break()
_BreakMin = _maxBreakMin
_BreakSec = _maxBreakSec
End Sub
Public Function Time_CountDown() As Boolean
If _RoundMin > 0 Then
If _RoundSec > 0 And _RoundSec < 60 Then
_RoundSec -= 1
Return False
Else
_RoundMin -= 1
_RoundSec = 59
Return False
End If
Else
If _RoundSec > 0 And _RoundSec < 60 Then
_RoundSec -= 1
Return False
Else
_RoundSec = 59
Return True
End If
End If
End Function
'-----------------------------------------------------------------
' READING MATCH NUMBER
'-----------------------------------------------------------------
' THIS FUNCTION GETS THE NEWLY CREATED MATCH NUMBER
Private Sub GetMatchData()
Dim QRY As String = "SELECT ecn, ern, emn, blue_fighter, red_fighter FROM test.event_matches where emn = " & _matchID & " and started = 0 and ended = 0 and (not isnull(red_fighter)) and (not isnull(blue_fighter)) order by ern, emn asc"
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
_courtID = RDR("ecn")
Catch ex As Exception
_courtID = 0
End Try
Try
_eventRound = RDR("ern")
Catch ex As Exception
_eventRound = 0
End Try
Try
BlueFighter = New fighter(RDR("blue_fighter"), _eventID, _matchID)
Catch ex As Exception
BlueFighter = Nothing
End Try
Try
RedFighter = New fighter(RDR("red_fighter"), _eventID, _matchID)
Catch ex As Exception
RedFighter = Nothing
End Try
End While
End If
CON.Close()
Catch ex As MySqlException
MessageBox.Show(ex.Message)
Finally
CON.Dispose()
End Try
End Sub
' THIS FUNCTION RETURNS AVAILABLE NUMBER FOR A NEW MATCH
Private Function GetAvailableNewMatchID() As Integer
' Select the Unstarted Matches From The Match Sequence
Dim QRY As String = ("
select
person.id as 'pid',
person.fname,
person.mname,
person.lname,
TIMESTAMPDIFF(YEAR, person.date_of_birth, CURDATE()) as 'age',
person.date_of_birth,
person.category,
person.weight,
person.weight_class,
person.gender,
person.picture,
clubs.title as 'club',
clubs.logo as 'logo',
countries.iso3 as 'country',
countries.flatflag as 'flag'
FROM
person
left join
clubs on person.club = clubs.id
left join
countries on person.country = countries.id
where
person.id=1
")
Dim CON As New MySqlConnection(CON_STRING)
Dim COM As New MySqlCommand(QRY, CON)
Dim RDR As MySqlDataReader
Dim NUM As Integer
Try
CON.Open()
RDR = COM.ExecuteReader
If RDR.HasRows = True Then
While RDR.Read
Try
NUM = RDR("ID")
Catch ex As Exception
End Try
End While
End If
CON.Close()
Catch ex As MySqlException
MessageBox.Show(ex.Message)
Finally
CON.Dispose()
End Try
Return NUM
End Function
Public Sub StartMatch()
' Update The Table With The Winner ID
Dim QRY As String = ("
SET SQL_SAFE_UPDATES = 0;
UPDATE
`event_matches`
SET
`started` = 1
WHERE
`emn` = " & _matchID & ";
")
' Executing The Command
Dim CON As New MySqlConnection(CON_STRING)
Dim COM As New MySqlCommand(QRY, CON)
Try
CON.Open()
COM.ExecuteNonQuery()
CON.Close()
Catch ex As MySqlException
MessageBox.Show(ex.Message)
Finally
CON.Dispose()
End Try
End Sub
Public Sub EndMatch()
' Testing This Condition
If _matchID = 0 Or _matchID = Nothing Then Exit Sub
' Update The Table With The Winner ID
Dim QRY As String = ("
SET SQL_SAFE_UPDATES = 0;
UPDATE
`event_matches`
SET
`ended` = 1
WHERE
`emn` = " & _matchID & ";
")
' Executing The Command
Dim CON As New MySqlConnection(CON_STRING)
Dim COM As New MySqlCommand(QRY, CON)
Try
CON.Open()
COM.ExecuteNonQuery()
CON.Close()
Catch ex As MySqlException
MessageBox.Show(ex.Message)
Finally
CON.Dispose()
End Try
End Sub
'-----------------------------------------------------------------
' METHODES OF ENDING A MATCH
'-----------------------------------------------------------------
' THIS SUB ENDS THE MATCH AUTOMATICALLY BY CALCULATING THE POINTS
Private Sub AutoEndMatch()
' Winner ID Holder
Dim WinnerID As Integer
' This Is Where We Do Decision Making
If BlueFighter.Score > RedFighter.Score Then
WinnerID = BlueFighter.Person.ID ' Blue Fighter Wins
ElseIf BlueFighter.Score < RedFighter.Score Then
WinnerID = RedFighter.Person.ID ' Red Fighter Wins
End If
' Update The Table With The Winner ID
Dim QRY As String = ("
SET SQL_SAFE_UPDATES = 0;
UPDATE
`event_matches`
SET
`blue_score` = " & BlueFighter.Score & ",
`blue_foul` = " & BlueFighter.Gamjum & ",
`red_score` = " & RedFighter.Score & ",
`red_foul` = " & RedFighter.Gamjum & ",
`winner` = " & WinnerID & ",
`ended` = 1
WHERE
`emn` = " & _matchID & ";
")
' Executing The Command
Dim CON As New MySqlConnection(CON_STRING)
Dim COM As New MySqlCommand(QRY, CON)
Try
CON.Open()
COM.ExecuteNonQuery()
CON.Close()
Catch ex As MySqlException
MessageBox.Show(ex.Message)
Finally
CON.Dispose()
End Try
End Sub
' THIS SUB ENDS THE MATCH MANUALLY BY THE MAIN REFEREE IF NEEDED TO
Private Sub ManualEndMatch(WinnerID As Integer, WinnerBy As String, Note As String)
' Update The Table With The Winner ID
Dim QRY As String = ("
SET SQL_SAFE_UPDATES = 0;
UPDATE
`event_matches`
SET
`blue_score` = " & BlueFighter.Score & ",
`blue_foul` = " & BlueFighter.Gamjum & ",
`red_score` = " & RedFighter.Score & ",
`red_foul` = " & RedFighter.Gamjum & ",
`winner` = " & WinnerID & ",
`notes` = '" & Note & "',
`winnerBy` = '" & WinnerBy & "',
`ended` = 1
WHERE
`emn` = " & _matchID & ";
")
Dim CON As New MySqlConnection(CON_STRING)
Dim COM As New MySqlCommand(QRY, CON)
Try
CON.Open()
COM.ExecuteNonQuery()
CON.Close()
Catch ex As MySqlException
MessageBox.Show(ex.Message)
Finally
CON.Dispose()
End Try
End Sub
End Class
@@ -0,0 +1,391 @@
Imports System.IO
Imports MySql.Data.MySqlClient
Public Class platformevent
' TAKEONE Event
Private _id As Integer
Private _title As String
Private _organizer As String
Private _type As String
Private _rules As String
' Location
Private _address As String
Private _location As String
Private _country As country
' Event Parameters
Private _court As Integer
Private _enroll_start As Date
Private _enroll_end As Date
Private _weigh_in As Date
Private _event_start As Date
Private _event_end As Date
Private _fee As Double
Private _currency As String
Private _logo As MemoryStream
' Making New Instance Without Any Action
Public Sub New()
End Sub
' Make New Instance Of Event By Reading Data From Its ID
Public Sub New(id As Integer)
GetEventData(id)
End Sub
' Make New Instance Directly By Creating A New Event Record
Public Sub New(EventTitle As String, Type As String, Rounds As Integer, Organizer As String, Country As Integer, Address As String, Location As String, Courts As Integer, Rules As String, Currency As String, Fee As Integer, EnrollStart As String, EnrollEnd As String, WeighIn As String, EventStart As String, EventEnd As String, Logo As PictureBox)
CreateNewEvent(EventTitle, Type, Rounds, Organizer, Country, Address, Location, Courts, Rules, Currency, Fee, EnrollStart, EnrollEnd, WeighIn, EventStart, EventEnd, Logo)
GetEventData(_id)
End Sub
' Set Of Properties
ReadOnly Property ID As Integer
Get
Return _id
End Get
End Property
ReadOnly Property Title As String
Get
Return _title
End Get
End Property
ReadOnly Property Organizer As String
Get
Return _organizer
End Get
End Property
ReadOnly Property Type As String
Get
Return _type
End Get
End Property
ReadOnly Property Country As country
Get
Return _country
End Get
End Property
ReadOnly Property Address As String
Get
Return _address
End Get
End Property
ReadOnly Property Location As String
Get
Return _location
End Get
End Property
ReadOnly Property Courts As Integer
Get
Return _court
End Get
End Property
ReadOnly Property EnrollStartDate As Date
Get
Return _enroll_start
End Get
End Property
ReadOnly Property EnrollEndDate As Date
Get
Return _enroll_end
End Get
End Property
ReadOnly Property WeighInDate As Date
Get
Return _weigh_in
End Get
End Property
ReadOnly Property EventStartDate As Date
Get
Return _event_start
End Get
End Property
ReadOnly Property EventEndDate As Date
Get
Return _event_end
End Get
End Property
ReadOnly Property Rules As String
Get
Return _rules
End Get
End Property
ReadOnly Property Currency As String
Get
Return _currency
End Get
End Property
ReadOnly Property Fee As Integer
Get
Return _fee
End Get
End Property
ReadOnly Property Logo As MemoryStream
Get
Return _logo
End Get
End Property
' Set Of Functions
Public Function EventList()
Dim QRY As String = "select * from event order by event_start asc"
Dim CON As New MySqlConnection(CON_STRING)
Dim COM As New MySqlCommand(QRY, CON)
Dim RDR As MySqlDataReader
Dim LST As New List(Of platformevent)
Try
CON.Open()
RDR = COM.ExecuteReader
If RDR.HasRows = True Then
While RDR.Read
LST.Add(New platformevent(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
Private Sub GetEventData(id As Integer)
Dim QRY As String = ("select event.* from event where event.id = " & id & " LIMIT 1")
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
_id = Int(RDR("id"))
Catch ex As Exception
_id = 0
End Try
Try
_title = RDR("title")
Catch ex As Exception
_title = Nothing
End Try
Try
_organizer = RDR("organizor")
Catch ex As Exception
_organizer = Nothing
End Try
Try
_type = RDR("type")
Catch ex As Exception
_type = Nothing
End Try
Try
_country = New country(Int(RDR("country")))
Catch ex As Exception
_country = Nothing
End Try
Try
_address = RDR("address")
Catch ex As Exception
_address = Nothing
End Try
Try
_location = RDR("location")
Catch ex As Exception
_location = Nothing
End Try
Try
_court = RDR("courts")
Catch ex As Exception
_court = 0
End Try
Try
_enroll_start = CDate(RDR("enroll_start"))
Catch ex As Exception
_enroll_start = Now
End Try
Try
_enroll_end = CDate(RDR("enroll_end"))
Catch ex As Exception
_enroll_end = Now
End Try
Try
_weigh_in = CDate(RDR("weigh_in"))
Catch ex As Exception
'_weigh_in = Now
End Try
Try
_event_start = CDate(RDR("event_start"))
Catch ex As Exception
'_event_start = Now
End Try
Try
_event_end = CDate(RDR("event_end"))
Catch ex As Exception
'_event_end = Now
End Try
Try
_rules = RDR("rules")
Catch ex As Exception
_rules = Nothing
End Try
Try
_currency = RDR("currency ")
Catch ex As Exception
_currency = Nothing
End Try
Try
_fee = RDR("participation_fee")
Catch ex As Exception
_fee = 0
End Try
Try ' Event Logo -----------------------------------------
Dim data As Byte() = DirectCast(RDR("logo"), Byte())
_logo = New MemoryStream(data)
Catch ex As Exception
_logo = Nothing
End Try
End While
End If
CON.Close()
Catch ex As MySqlException
MessageBox.Show(ex.Message)
Finally
CON.Dispose()
End Try
End Sub
' Set Of Routines
Public Sub CreateNewEvent(EventTitle As String, Type As String, Rounds As Integer, Organizer As String, Country As Integer, Address As String, Location As String, Courts As Integer, Rules As String, Currency As String, Fee As Integer, EnrollStart As String, EnrollEnd As String, WeighIn As String, EventStart As String, EventEnd As String, Logo As PictureBox)
' Query To Update
Dim QRY As String = ("
/* This Is To Insert The Information Of The New Event */
insert into
event (title, type, rounds, organizor, country, address, location, courts, rules, currency, fee, enroll_start, enroll_end, weigh_in, event_start, event_end, logo)
values ('" & EventTitle & "', '" & Type & "', '" & Rounds & "', '" & Organizer & "', " & Country & ", '" & Address & "', '" & Location & "', " & Courts & ", '" & Rules & "', '" & Currency & "', " & Fee & ", '" & EnrollStart & "', '" & EnrollEnd & "', '" & WeighIn & "', '" & EventStart & "', '" & EventEnd & "', @logo);
/* This Is To Return The Newly Created Event Record */
select last_insert_id() as 'eid';
")
' Connection
Dim CON As New MySqlConnection(CON_STRING)
Dim COM As New MySqlCommand(QRY, CON)
Dim Picture As New MemoryStream
Logo.Image.Save(Picture, System.Drawing.Imaging.ImageFormat.Png)
Dim arrImage() As Byte = Picture.GetBuffer
Picture.Close()
Dim RDR As MySqlDataReader
Try
CON.Open()
COM.Parameters.AddWithValue("@logo", arrImage)
RDR = COM.ExecuteReader
If RDR.HasRows = True Then
While RDR.Read
Try ' ID
_id = RDR("eid")
Catch ex As Exception
_id = 0
End Try
End While
End If
CON.Close()
Catch ex As MySqlException
MessageBox.Show(ex.Message)
End Try
End Sub
Public Sub UpdateLogo(Logo As PictureBox)
' Query To Update
Dim QRY As String = "update event set logo = @logo where id=" & _id
' Connection
Dim CON As New MySqlConnection(CON_STRING)
Dim COM As New MySqlCommand(QRY, CON)
' Preparing The Image
Dim Picture As New MemoryStream
Logo.Image.Save(Picture, System.Drawing.Imaging.ImageFormat.Png)
Dim arrImage() As Byte = Picture.GetBuffer
Picture.Close()
Try
CON.Open()
COM.Parameters.AddWithValue("@logo", arrImage)
COM.ExecuteNonQuery()
CON.Close()
Catch ex As MySqlException
MessageBox.Show(ex.Message)
Finally
CON.Dispose()
End Try
End Sub
End Class