first visual basic code upload
This commit is contained in:
1 parent
93697318e4
commit
5e53ab7d73
101 files changed
+21213
No files matched your search
@@ -0,0 +1,53 @@
|
||||
' Age Class To Generate Age From Date Of Birth
|
||||
Public Class age
|
||||
|
||||
Private _days As Integer
|
||||
Private _monthes As Integer
|
||||
Private _years As Integer
|
||||
Private _birthdate As Date
|
||||
|
||||
Public Sub New(Birthdate As Date)
|
||||
_birthdate = Birthdate
|
||||
Calculate(Birthdate)
|
||||
End Sub
|
||||
|
||||
ReadOnly Property Birthdate As Date
|
||||
Get
|
||||
Return _birthdate
|
||||
End Get
|
||||
End Property
|
||||
|
||||
ReadOnly Property Years As Integer
|
||||
Get
|
||||
Return _years
|
||||
End Get
|
||||
End Property
|
||||
|
||||
ReadOnly Property Monthes As Integer
|
||||
Get
|
||||
Return _monthes
|
||||
End Get
|
||||
End Property
|
||||
|
||||
ReadOnly Property Days As Integer
|
||||
Get
|
||||
Return _days
|
||||
End Get
|
||||
End Property
|
||||
|
||||
ReadOnly Property Printable As String
|
||||
Get
|
||||
Return "You Are " & _years & " Years " & _monthes & " Monthes " & _days & " Old"
|
||||
End Get
|
||||
End Property
|
||||
|
||||
Private Sub Calculate(Birthdate As Date)
|
||||
|
||||
' Breaking Down The Date Difference Into Year, Monthes and Days
|
||||
_years = DateDiff(DateInterval.Year, Birthdate, Now)
|
||||
_monthes = DateDiff(DateInterval.Month, Birthdate, Now) Mod 12
|
||||
_days = DateDiff(DateInterval.Day, Birthdate, Now) Mod 30 - 10
|
||||
|
||||
End Sub
|
||||
|
||||
End Class
|
||||
@@ -0,0 +1,139 @@
|
||||
Imports System.IO
|
||||
Imports MySql.Data.MySqlClient
|
||||
|
||||
Public Class club
|
||||
|
||||
Private _id As Integer
|
||||
Private _title As String
|
||||
Private _owner As person
|
||||
Private _country As country
|
||||
Private _address As String
|
||||
Private _location As String
|
||||
Private _logo As MemoryStream
|
||||
|
||||
Public Sub New(ID As Integer)
|
||||
GetClubData(ID)
|
||||
End Sub
|
||||
|
||||
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 Country As country
|
||||
Get
|
||||
Return _country
|
||||
End Get
|
||||
End Property
|
||||
|
||||
ReadOnly Property Location As String
|
||||
Get
|
||||
Return _location
|
||||
End Get
|
||||
End Property
|
||||
|
||||
ReadOnly Property Logo As MemoryStream
|
||||
Get
|
||||
Return _logo
|
||||
End Get
|
||||
End Property
|
||||
|
||||
Public Sub GetClubData(ID As Integer)
|
||||
|
||||
Dim QRY As String = "select * from clubs where 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
|
||||
_country = New country(Int(RDR("country")))
|
||||
Catch ex As Exception
|
||||
_country = Nothing
|
||||
End Try
|
||||
|
||||
Try
|
||||
_location = RDR("location")
|
||||
Catch ex As Exception
|
||||
_location = Nothing
|
||||
End Try
|
||||
|
||||
Try ' Club Logo -----------------------------------------
|
||||
Dim data As Byte() = DirectCast(RDR("logo"), Byte())
|
||||
_logo = New System.IO.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
|
||||
|
||||
Public Sub Create(Title As String, Country As country, Location As String, Logo As MemoryStream)
|
||||
|
||||
End Sub
|
||||
|
||||
Public Sub UpdateLogo(LogoPictureBox As PictureBox)
|
||||
|
||||
' To Avoid Wrong Execution Of Code
|
||||
If _id = 0 Then Exit Sub
|
||||
|
||||
' Query To Update
|
||||
Dim QRY As String = "update clubs 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
|
||||
LogoPictureBox.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
|
||||
@@ -0,0 +1,228 @@
|
||||
Imports System.IO
|
||||
Imports MySql.Data.MySqlClient
|
||||
|
||||
Public Class country
|
||||
|
||||
Private _id As Integer
|
||||
Private _name As String
|
||||
Private _flag As MemoryStream
|
||||
Private _flat_flag As String
|
||||
Private _shiny_flag As String
|
||||
Private _iso As String
|
||||
Private _iso3 As String
|
||||
Private _num_code As Integer
|
||||
Private _call_code As Integer
|
||||
Private _currency As String
|
||||
|
||||
Public Sub New()
|
||||
|
||||
End Sub
|
||||
|
||||
Public Sub New(id As Integer)
|
||||
GetCountryData(id)
|
||||
End Sub
|
||||
|
||||
ReadOnly Property ID As Integer
|
||||
Get
|
||||
Return _id
|
||||
End Get
|
||||
End Property
|
||||
|
||||
ReadOnly Property Name As String
|
||||
Get
|
||||
Return _name
|
||||
End Get
|
||||
End Property
|
||||
|
||||
ReadOnly Property Flag As MemoryStream
|
||||
Get
|
||||
Return _flag
|
||||
End Get
|
||||
End Property
|
||||
|
||||
ReadOnly Property FlatFlag As String
|
||||
Get
|
||||
Return _flat_flag
|
||||
End Get
|
||||
End Property
|
||||
|
||||
ReadOnly Property ShinyFlag As String
|
||||
Get
|
||||
Return _shiny_flag
|
||||
End Get
|
||||
End Property
|
||||
|
||||
ReadOnly Property ISO As String
|
||||
Get
|
||||
Return _iso
|
||||
End Get
|
||||
End Property
|
||||
|
||||
ReadOnly Property ISO3 As String
|
||||
Get
|
||||
Return _iso3
|
||||
End Get
|
||||
End Property
|
||||
|
||||
ReadOnly Property NumCode As Integer
|
||||
Get
|
||||
Return _num_code
|
||||
End Get
|
||||
End Property
|
||||
|
||||
ReadOnly Property CallCode As Integer
|
||||
Get
|
||||
Return _call_code
|
||||
End Get
|
||||
End Property
|
||||
|
||||
ReadOnly Property Currency As String
|
||||
Get
|
||||
Return _currency
|
||||
End Get
|
||||
End Property
|
||||
|
||||
Private Sub GetCountryData(ID As Integer)
|
||||
|
||||
Dim QRY As String = ("select * from countries where 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
|
||||
_id = RDR("id")
|
||||
Catch ex As Exception
|
||||
_id = 0
|
||||
End Try
|
||||
|
||||
Try ' First Name
|
||||
_name = RDR("name")
|
||||
Catch ex As Exception
|
||||
_name = Nothing
|
||||
End Try
|
||||
|
||||
Try ' Middle Name
|
||||
_flat_flag = RDR("flatFlag")
|
||||
Catch ex As Exception
|
||||
_flat_flag = Nothing
|
||||
End Try
|
||||
|
||||
Try ' Last Name
|
||||
_shiny_flag = RDR("shinyFlag")
|
||||
Catch ex As Exception
|
||||
_shiny_flag = Nothing
|
||||
End Try
|
||||
|
||||
Try ' Gender
|
||||
_iso = RDR("iso")
|
||||
Catch ex As Exception
|
||||
_iso = Nothing
|
||||
End Try
|
||||
|
||||
Try ' Birthday
|
||||
_iso3 = RDR("iso3")
|
||||
Catch ex As Exception
|
||||
_iso3 = Nothing
|
||||
End Try
|
||||
|
||||
Try ' Age
|
||||
_num_code = RDR("numcode")
|
||||
Catch ex As Exception
|
||||
_num_code = 0
|
||||
End Try
|
||||
|
||||
Try ' Weight
|
||||
_call_code = RDR("callcode")
|
||||
Catch ex As Exception
|
||||
_call_code = 0
|
||||
End Try
|
||||
|
||||
Try ' Category
|
||||
_currency = RDR("currency")
|
||||
Catch ex As Exception
|
||||
_currency = Nothing
|
||||
End Try
|
||||
|
||||
Try ' Country Flag --------------------------------------
|
||||
Dim data As Byte() = DirectCast(RDR("flag"), Byte())
|
||||
_flag = New System.IO.MemoryStream(data)
|
||||
Catch ex As Exception
|
||||
_flag = Nothing
|
||||
End Try
|
||||
|
||||
End While
|
||||
End If
|
||||
CON.Close()
|
||||
Catch ex As MySqlException
|
||||
MessageBox.Show(ex.Message)
|
||||
End Try
|
||||
|
||||
End Sub
|
||||
|
||||
Public Sub UpdateFlag(FlagPictureBox As PictureBox)
|
||||
|
||||
' To Avoid Wrong Execution Of Code
|
||||
If _id = 0 Then Exit Sub
|
||||
|
||||
' Query To Update
|
||||
Dim QRY As String = "update countries set flag = @flag 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
|
||||
FlagPictureBox.Image.Save(Picture, System.Drawing.Imaging.ImageFormat.Png)
|
||||
Dim arrImage() As Byte = Picture.GetBuffer
|
||||
Picture.Close()
|
||||
|
||||
Try
|
||||
CON.Open()
|
||||
COM.Parameters.AddWithValue("@flag", arrImage)
|
||||
COM.ExecuteNonQuery()
|
||||
CON.Close()
|
||||
Catch ex As MySqlException
|
||||
MessageBox.Show(ex.Message)
|
||||
Finally
|
||||
CON.Dispose()
|
||||
End Try
|
||||
|
||||
End Sub
|
||||
|
||||
Public Function GetCountryList() As List(Of country)
|
||||
|
||||
Dim QRY As String = "select * from countries order by name 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 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,41 @@
|
||||
Imports Newtonsoft.Json
|
||||
|
||||
Public Class location
|
||||
|
||||
Private _latitude As Double
|
||||
Private _longitude As Double
|
||||
Private _altitude As Double
|
||||
Private product As Object
|
||||
|
||||
Public Sub New(latitude, longitude)
|
||||
_latitude = latitude
|
||||
_longitude = longitude
|
||||
End Sub
|
||||
|
||||
Public Sub New(latitude, longitude, altitude)
|
||||
|
||||
_latitude = latitude
|
||||
_longitude = longitude
|
||||
_altitude = altitude
|
||||
|
||||
End Sub
|
||||
|
||||
ReadOnly Property Latitude As Double
|
||||
Get
|
||||
Return _latitude
|
||||
End Get
|
||||
End Property
|
||||
|
||||
ReadOnly Property Longitude As Double
|
||||
Get
|
||||
Return _longitude
|
||||
End Get
|
||||
End Property
|
||||
|
||||
ReadOnly Property Altitude As Double
|
||||
Get
|
||||
Return _altitude
|
||||
End Get
|
||||
End Property
|
||||
|
||||
End Class
|
||||
@@ -0,0 +1,371 @@
|
||||
Imports System.IO
|
||||
Imports MySql.Data.MySqlClient
|
||||
|
||||
Public Class person
|
||||
|
||||
' Person Data Variables
|
||||
Private _id As Integer ' Member ID
|
||||
Private _first_name As String ' First Name
|
||||
Private _middle_name As String ' Middle Name
|
||||
Private _last_name As String ' Last Name
|
||||
Private _gender As String ' Gender
|
||||
Private _birthday As Date ' Date Of Birth
|
||||
Private _age As age ' Calculated From Birthday
|
||||
Private _weight As weight ' Weight
|
||||
Private _picture As MemoryStream ' Picture
|
||||
|
||||
' Person Country
|
||||
Private _nationality As country ' Country Object
|
||||
|
||||
' Person Team / Club
|
||||
Private _team As club ' Club Object
|
||||
|
||||
'--------------------------------------------------------------------------------------
|
||||
' CONSTRUCTORS
|
||||
'--------------------------------------------------------------------------------------
|
||||
|
||||
Public Sub New(Fname As String, Sname As String, Lname As String, DateOfBirth As String, Gender As String, Weight As String, CPR As String, Country As Integer, Mobile As String, Email As String, Address As String, Club As Integer, PictureBox As PictureBox)
|
||||
|
||||
' Create A New Person
|
||||
CREATE(Fname, Sname, Lname, DateOfBirth, Gender, Weight, CPR, Country, Mobile, Email, Address, Club, PictureBox)
|
||||
|
||||
' Get Person Data From Returned ID
|
||||
GetPersonData(_id)
|
||||
|
||||
End Sub
|
||||
|
||||
Public Sub New(ID As Integer)
|
||||
|
||||
If ID = 0 Then
|
||||
ZeroID()
|
||||
Else
|
||||
GetPersonData(ID)
|
||||
End If
|
||||
|
||||
End Sub
|
||||
|
||||
'--------------------------------------------------------------------------------------
|
||||
' PROPERTIES
|
||||
'--------------------------------------------------------------------------------------
|
||||
|
||||
Public Property ID As Integer
|
||||
Get
|
||||
Return _id
|
||||
End Get
|
||||
Set(value As Integer)
|
||||
_id = value
|
||||
GetPersonData(_id)
|
||||
End Set
|
||||
End Property
|
||||
|
||||
ReadOnly Property FirstName As String
|
||||
Get
|
||||
Return _first_name
|
||||
End Get
|
||||
End Property
|
||||
|
||||
ReadOnly Property LastName As String
|
||||
Get
|
||||
Return _last_name
|
||||
End Get
|
||||
End Property
|
||||
|
||||
ReadOnly Property MiddleName As String
|
||||
Get
|
||||
Return _first_name + " " + _last_name
|
||||
End Get
|
||||
End Property
|
||||
|
||||
ReadOnly Property ShortName As String
|
||||
Get
|
||||
Return _first_name + " " + _last_name
|
||||
End Get
|
||||
End Property
|
||||
|
||||
ReadOnly Property FullName As String
|
||||
Get
|
||||
Return _first_name + " " + _middle_name + " " + _last_name
|
||||
End Get
|
||||
End Property
|
||||
|
||||
ReadOnly Property Age As age
|
||||
Get
|
||||
Return _age
|
||||
End Get
|
||||
End Property
|
||||
|
||||
ReadOnly Property Birthday As Date
|
||||
Get
|
||||
Return _birthday
|
||||
End Get
|
||||
End Property
|
||||
|
||||
ReadOnly Property Weight As weight
|
||||
Get
|
||||
Return _weight
|
||||
End Get
|
||||
End Property
|
||||
|
||||
ReadOnly Property Gender As String
|
||||
Get
|
||||
Return _gender
|
||||
End Get
|
||||
End Property
|
||||
|
||||
ReadOnly Property Team As club
|
||||
Get
|
||||
Return _team
|
||||
End Get
|
||||
End Property
|
||||
|
||||
ReadOnly Property Nationality As country
|
||||
Get
|
||||
Return _nationality
|
||||
End Get
|
||||
End Property
|
||||
|
||||
ReadOnly Property Picture As MemoryStream
|
||||
Get
|
||||
Return _picture
|
||||
End Get
|
||||
End Property
|
||||
|
||||
'--------------------------------------------------------------------------------------
|
||||
' Create Section
|
||||
'--------------------------------------------------------------------------------------
|
||||
|
||||
Public Sub CREATE(Fname As String, Sname As String, Lname As String, DateOfBirth As String, Gender As String, Weight As String, CPR As String, Country As Integer, Mobile As String, Email As String, Address As String, Club As Integer, PictureBox As PictureBox)
|
||||
|
||||
Dim QRY As String = ("
|
||||
insert into
|
||||
person (fname, mname, lname, country, gender, date_of_birth, weight, cpr, mobile, email, address, club, picture)
|
||||
values ('" & Fname & "', '" & Sname & "', '" & Lname & "', " & Country & ", '" & Gender & "', '" & DateOfBirth & "', '" & Weight & "', '" & CPR & "', '" & Mobile & "', '" & Email & "', '" & Address & "', " & Club & ", @picture);
|
||||
|
||||
select last_insert_id() as 'id';
|
||||
")
|
||||
|
||||
' Generate Weight Object
|
||||
_weight = New weight(ReadMySQLDate(DateOfBirth), Gender, CDbl(Val(Weight)))
|
||||
|
||||
' Connection
|
||||
Dim CON As New MySqlConnection(CON_STRING)
|
||||
Dim COM As New MySqlCommand(QRY, CON)
|
||||
|
||||
Dim Picture As New MemoryStream
|
||||
PictureBox.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("@picture", arrImage)
|
||||
RDR = COM.ExecuteReader
|
||||
If RDR.HasRows = True Then
|
||||
|
||||
While RDR.Read
|
||||
|
||||
Try ' ID
|
||||
_id = RDR("id")
|
||||
Catch ex As Exception
|
||||
_id = 0
|
||||
End Try
|
||||
|
||||
End While
|
||||
|
||||
End If
|
||||
CON.Close()
|
||||
Catch ex As MySqlException
|
||||
MessageBox.Show(ex.Message)
|
||||
End Try
|
||||
|
||||
' Updating Weight
|
||||
UpdateWeight(CDbl(Val(Weight)))
|
||||
|
||||
End Sub
|
||||
|
||||
|
||||
'--------------------------------------------------------------------------------------
|
||||
' Update Section
|
||||
'--------------------------------------------------------------------------------------
|
||||
|
||||
Public Sub UpdatePicture(PictureBox As PictureBox)
|
||||
|
||||
' Query To Update
|
||||
Dim QRY As String = "update person set picture = @picture 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
|
||||
PictureBox.Image.Save(Picture, System.Drawing.Imaging.ImageFormat.Png)
|
||||
Dim arrImage() As Byte = Picture.GetBuffer
|
||||
Picture.Close()
|
||||
|
||||
Try
|
||||
CON.Open()
|
||||
COM.Parameters.AddWithValue("@picture", arrImage)
|
||||
COM.ExecuteNonQuery()
|
||||
CON.Close()
|
||||
Catch ex As MySqlException
|
||||
MessageBox.Show(ex.Message)
|
||||
Finally
|
||||
CON.Dispose()
|
||||
End Try
|
||||
|
||||
End Sub
|
||||
|
||||
|
||||
'--------------------------------------------------------------------------------------
|
||||
' SUBROUTINES
|
||||
'--------------------------------------------------------------------------------------
|
||||
|
||||
Private Sub GetPersonData(FighterID As Integer)
|
||||
|
||||
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.weight,
|
||||
person.gender,
|
||||
person.country as 'country',
|
||||
clubs.id as 'club',
|
||||
person.picture as 'picture'
|
||||
FROM
|
||||
person
|
||||
left join
|
||||
clubs on person.club = clubs.id
|
||||
left join
|
||||
countries on clubs.country = countries.id
|
||||
where
|
||||
person.id=" + FighterID.ToString
|
||||
)
|
||||
|
||||
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
|
||||
_id = RDR("pid")
|
||||
Catch ex As Exception
|
||||
_id = 0
|
||||
End Try
|
||||
|
||||
Try ' First Name
|
||||
_first_name = RDR("fname")
|
||||
Catch ex As Exception
|
||||
_first_name = Nothing
|
||||
End Try
|
||||
|
||||
Try ' Middle Name
|
||||
_middle_name = RDR("mname")
|
||||
Catch ex As Exception
|
||||
_middle_name = Nothing
|
||||
End Try
|
||||
|
||||
Try ' Last Name
|
||||
_last_name = RDR("lname")
|
||||
Catch ex As Exception
|
||||
_last_name = Nothing
|
||||
End Try
|
||||
|
||||
Try ' Gender
|
||||
_gender = RDR("gender")
|
||||
Catch ex As Exception
|
||||
_gender = Nothing
|
||||
End Try
|
||||
|
||||
Try ' Birthday
|
||||
_birthday = CDate(RDR("date_of_birth"))
|
||||
Catch ex As Exception
|
||||
_birthday = Nothing
|
||||
End Try
|
||||
|
||||
Try ' Age
|
||||
_age = New age(_birthday)
|
||||
Catch ex As Exception
|
||||
_age = Nothing
|
||||
End Try
|
||||
|
||||
Try ' Weight
|
||||
_weight = New weight(_birthday, _gender, RDR("weight"))
|
||||
Catch ex As Exception
|
||||
_weight = Nothing
|
||||
End Try
|
||||
|
||||
Try ' Team Name
|
||||
_team = New club(RDR("club"))
|
||||
Catch ex As Exception
|
||||
_team = Nothing
|
||||
End Try
|
||||
|
||||
Try ' Country
|
||||
_nationality = New country(RDR("country"))
|
||||
Catch ex As Exception
|
||||
_nationality = Nothing
|
||||
End Try
|
||||
|
||||
Try ' Fighter Picture -------------------------------------------
|
||||
Dim data As Byte() = DirectCast(RDR("picture"), Byte())
|
||||
_picture = New System.IO.MemoryStream(data)
|
||||
Catch ex As Exception
|
||||
_picture = Nothing
|
||||
End Try
|
||||
|
||||
End While
|
||||
End If
|
||||
CON.Close()
|
||||
Catch ex As MySqlException
|
||||
MessageBox.Show(ex.Message)
|
||||
End Try
|
||||
|
||||
End Sub
|
||||
|
||||
'--------------------------------------------------------------------------------------
|
||||
' FUNCTIONS
|
||||
'--------------------------------------------------------------------------------------
|
||||
|
||||
Public Sub UpdateWeight(Weight As Double)
|
||||
|
||||
' This Updates The Weight Of The Person
|
||||
_weight.UpdateWeight(Me._id, Weight)
|
||||
|
||||
End Sub
|
||||
|
||||
'--------------------------------------------------------------------------------------
|
||||
' Zero ID Person
|
||||
'--------------------------------------------------------------------------------------
|
||||
|
||||
Private Sub ZeroID()
|
||||
|
||||
_id = 0
|
||||
_first_name = "B"
|
||||
_middle_name = "Y"
|
||||
_last_name = "E"
|
||||
_gender = "EXGEN"
|
||||
_birthday = ""
|
||||
_age = Nothing
|
||||
_weight = Nothing
|
||||
_picture = Nothing
|
||||
_team = Nothing
|
||||
_nationality = Nothing
|
||||
|
||||
End Sub
|
||||
|
||||
End Class
|
||||
@@ -0,0 +1,209 @@
|
||||
Imports System.IO
|
||||
Imports MySql.Data.MySqlClient
|
||||
|
||||
Public Class referee
|
||||
|
||||
' Referee Data Variables
|
||||
Private _id As Integer ' Member ID
|
||||
Private _first_name As String ' First Name
|
||||
Private _middle_name As String ' Middle Name
|
||||
Private _last_name As String ' Last Name
|
||||
Private _gender As String ' Gender
|
||||
Private _birthday As Date ' Date Of Birth
|
||||
Private _age As Integer ' Calculated From Birthday
|
||||
Private _picture As MemoryStream ' Picture
|
||||
|
||||
' Referee Team / Club
|
||||
Private _team As club ' Team Within Country
|
||||
|
||||
' Referee Country
|
||||
Private _nationality As country ' Country Name
|
||||
|
||||
'--------------------------------------------------------------------------------------
|
||||
' CONSTRUCTORS
|
||||
'--------------------------------------------------------------------------------------
|
||||
|
||||
' With Initial Parameter
|
||||
Public Sub New(ID As Integer)
|
||||
GetRefereeData(ID)
|
||||
End Sub
|
||||
|
||||
'--------------------------------------------------------------------------------------
|
||||
' PROPERTIES
|
||||
'--------------------------------------------------------------------------------------
|
||||
|
||||
Public Property ID As Integer
|
||||
Get
|
||||
Return _id
|
||||
End Get
|
||||
Set(value As Integer)
|
||||
_id = value
|
||||
GetRefereeData(_id)
|
||||
End Set
|
||||
End Property
|
||||
|
||||
ReadOnly Property FirstNAME As String
|
||||
Get
|
||||
Return _first_name
|
||||
End Get
|
||||
End Property
|
||||
|
||||
ReadOnly Property LastNAME As String
|
||||
Get
|
||||
Return _last_name
|
||||
End Get
|
||||
End Property
|
||||
|
||||
ReadOnly Property MiddleNAME As String
|
||||
Get
|
||||
Return _first_name + " " + _last_name
|
||||
End Get
|
||||
End Property
|
||||
|
||||
ReadOnly Property ShortName As String
|
||||
Get
|
||||
Return _first_name + " " + _last_name
|
||||
End Get
|
||||
End Property
|
||||
|
||||
ReadOnly Property FullName As String
|
||||
Get
|
||||
Return _first_name + " " + _middle_name + " " + _last_name
|
||||
End Get
|
||||
End Property
|
||||
|
||||
ReadOnly Property Age As Integer
|
||||
Get
|
||||
Return _age
|
||||
End Get
|
||||
End Property
|
||||
|
||||
ReadOnly Property Birthday As Date
|
||||
Get
|
||||
Return _birthday
|
||||
End Get
|
||||
End Property
|
||||
|
||||
ReadOnly Property Country As country
|
||||
Get
|
||||
Return _nationality
|
||||
End Get
|
||||
End Property
|
||||
|
||||
ReadOnly Property Team As club
|
||||
Get
|
||||
Return _team
|
||||
End Get
|
||||
End Property
|
||||
|
||||
ReadOnly Property Picture As MemoryStream
|
||||
Get
|
||||
Return _picture
|
||||
End Get
|
||||
End Property
|
||||
|
||||
'--------------------------------------------------------------------------------------
|
||||
' SUBROUTINES
|
||||
'--------------------------------------------------------------------------------------
|
||||
Private Sub GetRefereeData(FighterID As Integer)
|
||||
|
||||
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.gender,
|
||||
person.club as 'club',
|
||||
person.country as 'country',
|
||||
person.picture
|
||||
FROM
|
||||
person
|
||||
where
|
||||
person.id=" + FighterID.ToString
|
||||
)
|
||||
|
||||
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 = RDR("pid")
|
||||
Catch ex As Exception
|
||||
_id = 0
|
||||
End Try
|
||||
|
||||
Try
|
||||
_first_name = RDR("fname")
|
||||
Catch ex As Exception
|
||||
_first_name = Nothing
|
||||
End Try
|
||||
|
||||
Try
|
||||
_middle_name = RDR("mname")
|
||||
Catch ex As Exception
|
||||
_middle_name = Nothing
|
||||
End Try
|
||||
|
||||
Try
|
||||
_last_name = RDR("lname")
|
||||
Catch ex As Exception
|
||||
_last_name = Nothing
|
||||
End Try
|
||||
|
||||
Try
|
||||
_gender = RDR("gender")
|
||||
Catch ex As Exception
|
||||
_gender = Nothing
|
||||
End Try
|
||||
|
||||
Try
|
||||
_birthday = CDate(RDR("date_of_birth"))
|
||||
Catch ex As Exception
|
||||
_birthday = Nothing
|
||||
End Try
|
||||
|
||||
Try
|
||||
_age = RDR("age")
|
||||
Catch ex As Exception
|
||||
_age = 0
|
||||
End Try
|
||||
|
||||
Try
|
||||
_team = New club(Int(RDR("club")))
|
||||
Catch ex As Exception
|
||||
_team = Nothing
|
||||
End Try
|
||||
|
||||
Try
|
||||
_nationality = New country(Int(RDR("country")))
|
||||
Catch ex As Exception
|
||||
_nationality = Nothing
|
||||
End Try
|
||||
|
||||
Try ' Fighter Personal Picture ----------------------------------
|
||||
Dim arrImage() As Byte = DirectCast(RDR("picture"), Byte())
|
||||
_picture = New MemoryStream(arrImage)
|
||||
Catch ex As Exception
|
||||
_picture = Nothing
|
||||
End Try '--------------------------------------------------------
|
||||
|
||||
End While
|
||||
End If
|
||||
CON.Close()
|
||||
Catch ex As MySqlException
|
||||
MessageBox.Show(ex.Message)
|
||||
End Try
|
||||
|
||||
End Sub
|
||||
|
||||
End Class
|
||||
@@ -0,0 +1,205 @@
|
||||
Imports System.IO
|
||||
Imports MySql.Data.MySqlClient
|
||||
|
||||
' Weight Class To Generate Weight (Category, Class) From Gender, Weight, Date Of Birth.
|
||||
Public Class weight
|
||||
|
||||
Private _id As Integer ' Weight Profile ID
|
||||
Private _age As age ' Age Object (years, monthes, days)
|
||||
Private _gender As String ' Weight Filter Gender
|
||||
Private _weight As Double ' Weight In KG
|
||||
Private _weight_class As String ' Weight Class Name
|
||||
Private _weight_category As String ' Weight Category Name
|
||||
|
||||
Public Sub New(Birthdate As Date, Gender As String, Weight As Double)
|
||||
|
||||
_age = New age(Birthdate)
|
||||
_gender = Gender
|
||||
_weight = Weight
|
||||
|
||||
' Weight Filter That Gets
|
||||
WeightFilter(_age.Years, Weight, Gender)
|
||||
|
||||
End Sub
|
||||
|
||||
ReadOnly Property WeightFilterID As Integer
|
||||
Get
|
||||
Return _id
|
||||
End Get
|
||||
End Property
|
||||
|
||||
ReadOnly Property Weight As String
|
||||
Get
|
||||
Return Math.Round(_weight, 1).ToString
|
||||
End Get
|
||||
End Property
|
||||
|
||||
ReadOnly Property WeightClass As String
|
||||
Get
|
||||
Return _weight_class
|
||||
End Get
|
||||
End Property
|
||||
|
||||
ReadOnly Property WeightCategory As String
|
||||
Get
|
||||
Return _weight_category
|
||||
End Get
|
||||
End Property
|
||||
|
||||
Private Sub WeightFilter(Age As Integer, Weight As String, Gender As String)
|
||||
|
||||
Dim QRY As String = ("
|
||||
|
||||
SELECT
|
||||
id,
|
||||
Category,
|
||||
ClassName
|
||||
FROM
|
||||
weight_divisions
|
||||
WHERE
|
||||
('" & Age & "' BETWEEN weight_divisions.minAge AND weight_divisions.maxAge)
|
||||
AND
|
||||
(weight_divisions.gender = '" & Gender & "')
|
||||
AND
|
||||
('" & Weight & "' > weight_divisions.minWeight AND '" & Weight & "' <= weight_divisions.maxWeight)
|
||||
|
||||
")
|
||||
|
||||
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
|
||||
_id = RDR("id")
|
||||
_weight_category = RDR("Category")
|
||||
_weight_class = RDR("ClassName")
|
||||
End While
|
||||
End If
|
||||
|
||||
CON.Close()
|
||||
Catch ex As MySqlException
|
||||
_weight_category = Nothing
|
||||
_weight_class = Nothing
|
||||
MessageBox.Show(ex.Message)
|
||||
Finally
|
||||
CON.Dispose()
|
||||
End Try
|
||||
|
||||
End Sub
|
||||
|
||||
Private Sub GetPersonWeight(PersonID As Integer)
|
||||
|
||||
Dim QRY As String =
|
||||
("
|
||||
select
|
||||
person.weight,
|
||||
person.gender,
|
||||
person.date_of_birth,
|
||||
FROM
|
||||
person
|
||||
where
|
||||
person.id=" + PersonID.ToString
|
||||
)
|
||||
|
||||
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
|
||||
_age = New age(RDR("date_of_birth"))
|
||||
Catch ex As Exception
|
||||
|
||||
End Try
|
||||
|
||||
Try
|
||||
_weight = RDR("weight")
|
||||
Catch ex As Exception
|
||||
_weight = 0
|
||||
End Try
|
||||
|
||||
Try
|
||||
_gender = RDR("gender")
|
||||
Catch ex As Exception
|
||||
_gender = Nothing
|
||||
End Try
|
||||
|
||||
End While
|
||||
End If
|
||||
CON.Close()
|
||||
Catch ex As MySqlException
|
||||
MessageBox.Show(ex.Message)
|
||||
End Try
|
||||
|
||||
End Sub
|
||||
|
||||
Public Sub UpdateWeight(PersonID As Integer, NewWeight As Double)
|
||||
|
||||
' If Person ID = 0 Just Dont Do any Thing
|
||||
If PersonID = 0 Then Exit Sub
|
||||
|
||||
Dim QRY As String = ("
|
||||
|
||||
/* Take The New Reading */
|
||||
|
||||
SET @pid = " & PersonID.ToString & "; /* Person ID */
|
||||
SET @weight = " & NewWeight.ToString & "; /* New Weight Reading */
|
||||
SET SQL_SAFE_UPDATES = 0; /* Disable Safe Mode For Updates */
|
||||
|
||||
/* Update Person Weight */
|
||||
|
||||
UPDATE person SET weight = @weight WHERE id = @pid;
|
||||
|
||||
/* Update Participants Weight Classes */
|
||||
|
||||
UPDATE
|
||||
person
|
||||
LEFT JOIN
|
||||
weight_divisions
|
||||
ON
|
||||
(YEAR(CURDATE()) - YEAR(person.date_of_birth) BETWEEN weight_divisions.minAge AND weight_divisions.maxAge) AND
|
||||
(weight_divisions.gender = person.gender) AND
|
||||
(person.weight > weight_divisions.minWeight AND person.weight <= weight_divisions.maxWeight)
|
||||
SET
|
||||
person.wp = weight_divisions.id,
|
||||
person.category = weight_divisions.category,
|
||||
person.weight_Class = weight_divisions.className
|
||||
WHERE
|
||||
person.id = @pid;
|
||||
|
||||
/* Take Snap Shot Copy Current Weight To Person Body As A History */
|
||||
|
||||
INSERT INTO person_body (pid, weight, category, weight_class) SELECT id, weight, category, weight_class FROM person WHERE id = @pid;
|
||||
|
||||
/* Enable Safe Mode For Updates */
|
||||
|
||||
SET SQL_SAFE_UPDATES = 1;
|
||||
")
|
||||
|
||||
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
|
||||
Reference in new issue
Block a user