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,37 @@
Public Class dataset
Private _id As Integer
Private _name As String
Public Sub New(id As Integer, name As String)
_id = id
_name = name
End Sub
Public Property ID As Integer
Set(value As Integer)
_id = value
End Set
Get
Return _id
End Get
End Property
Public Property NAME As String
Set(value As String)
_name = value
End Set
Get
Return _name
End Get
End Property
End Class
@@ -0,0 +1,197 @@
Public Class match_timer
'--[MATCH SETTINGS]---------------
Private _set_minutes As Integer
Private _set_seconds As Integer
'--[MATCH SETTINGS]---------------
Private _run_minutes As Integer
Private _run_seconds As Integer
'--[MATCH SETTINGS]---------------
Private _timeUp As Boolean
Private _last10Sec As Boolean
'--[MATCH SETTINGS]---------------
Private _stop As Boolean
Private _start As Boolean
Private _pause As Boolean
Private _continue As Boolean
Public Sub New(minutes As Integer, seconds As Integer)
' In Case Negative Numbers Where Set
If minutes < 0 Then
MsgBox("Sorry You Cant Set Negative Numbers", vbOKOnly + vbCritical, "Wrong Setting")
Exit Sub
End If
' Timing Setup
_set_minutes = minutes
_set_seconds = seconds
' Copy To Running Timer
_run_minutes = _set_minutes
_run_seconds = _set_seconds
' Control Bits
_stop = False
_start = False
_pause = True
_continue = False
' Timer Flags
_timeUp = False
_last10Sec = False
End Sub
ReadOnly Property ReadMinutes As Integer
Get
Return _run_minutes
End Get
End Property
ReadOnly Property ReadSeconds As Integer
Get
Return _run_seconds
End Get
End Property
ReadOnly Property ReadTime() As String
Get
Return Zero(_run_minutes) + ":" + Zero(_run_seconds)
End Get
End Property
ReadOnly Property TimeUp() As Boolean
Get
Return _timeUp
End Get
End Property
ReadOnly Property Last10Sec() As Boolean
Get
Return _last10Sec
End Get
End Property
Public Sub Run()
If _pause = False And _start = True Or _stop = False Then
If _run_minutes > 0 And _run_seconds = 0 Then
_run_minutes -= 1
_run_seconds = 59
ElseIf _run_minutes >= 0 And (_run_seconds > 0 And _run_seconds <= 59) Then
_run_seconds -= 1
DetectLast10Sec(_run_seconds)
ElseIf _run_minutes = 0 And _run_seconds = 0 Then
_timeUp = True
End If
End If
End Sub
Private Sub DetectLast10Sec(seconds As Integer)
If seconds >= 0 And seconds < 10 Then
_last10Sec = True
Else
_last10Sec = False
End If
End Sub
Public Sub StartTime()
If _stop = False Then
_start = True
_pause = False
Else
MsgBox("Cant Start Timer When Its Already Finished Count Down", vbOKOnly + vbInformation, "Timer Message")
End If
End Sub
Public Sub StopTime()
If _start = True Then
_pause = True
_stop = True
Else
MsgBox("Cant Stop Timer When Its Not Even Started", vbOKOnly + vbInformation, "Timer Message")
End If
End Sub
Public Sub PauseTime()
If _start = True And _stop = False Then
_pause = True
Else
MsgBox("Cant Pause Timer When (Not Started) Or Ended", vbOKOnly + vbInformation, "Timer Message")
End If
End Sub
Public Sub ResumeTime()
If _start = True And _stop = False Then
_pause = False
Else
MsgBox("Cant Resume Timer When (Not Started) Or Ended", vbOKOnly + vbInformation, "Timer Message")
End If
End Sub
Public Sub ResetTime()
If _start = True And _stop = False Then
' Display A Message For The User To Choose
Dim iAsk As DialogResult = MessageBox.Show("Would You Like To Stop And Reset The Timer ?", "Timer Message", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
' Checking The Dialog Result
If iAsk = DialogResult.Yes Then
' Its Safe To Do A Reset
Reset_Time()
End If
ElseIf _start = True And _stop = True Then
' Its Safe To Do A Reset
Reset_Time()
End If
End Sub
Private Sub Reset_Time()
_start = False
_pause = True
_stop = False
_run_minutes = _set_minutes
_run_seconds = _set_seconds
End Sub
Private Function Zero(Number As Integer) As String
If Number >= 0 And Number < 10 Then
Return "0" + Number.ToString
Else
Return Number.ToString
End If
End Function
End Class
@@ -0,0 +1,32 @@
Imports MySql.Data.MySqlClient
Module MySQL
Public Function CON_STRING() As String
With My.Settings
Return "Server=" & .server & "; Port=" & .port & "; Database=" & .database & "; Uid=" & .userid & "; Pwd = " & .password & ";"
End With
End Function
Public Function CON_TEST(Server As String, Port As Integer, Database As String, UserName As String, Password As String) As Boolean
Dim CON_TEST_STRING As String = "server=" & Server & "; Port=" & Port & "; user id=" & UserName & "; password=" & Password & "; database=" & Database & ";"
Dim CON As New MySqlConnection(CON_TEST_STRING)
Try
CON.Open()
CON.Close()
MessageBox.Show("Connection Sucessfull")
Return True
Catch ex As MySqlException
MessageBox.Show(ex.Message)
Return False
End Try
End Function
End Module
@@ -0,0 +1,429 @@
Imports System.IO
Imports MySql.Data.MySqlClient
Module functions
'-------------------------------------------------------------------------------------------------------------
' Person
'-------------------------------------------------------------------------------------------------------------
Public Function GetPersonList() As List(Of dataset)
Dim QRY As String = ("
select
distinct
person.id, concat(person.fname, if(isnull(person.mname), '', concat(' ', person.mname)), ' ', person.lname) as name
from
person
left join
event_matches on (person.id = coalesce(event_matches.blue_fighter, 0) or person.id = coalesce(event_matches.red_fighter, 0))
order by
fname,
mname,
lname
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 dataset)
Try
CON.Open()
RDR = COM.ExecuteReader
If RDR.HasRows = True Then
While RDR.Read
LST.Add(New dataset(RDR("id"), RDR("name")))
End While
End If
CON.Close()
Catch ex As MySqlException
MessageBox.Show(ex.Message)
Finally
CON.Dispose()
End Try
Return LST
End Function
'-------------------------------------------------------------------------------------------------------------
' File Functions
'-------------------------------------------------------------------------------------------------------------
Public Function GetFilePath() As String
'Creating A New Dialog
Dim OpenVideoFile As New OpenFileDialog
'Filtering The Types
OpenVideoFile.Filter = "Video Files | *.mp4; *.avi; *.mkv;"
'Openning The File
If OpenVideoFile.ShowDialog = System.Windows.Forms.DialogResult.OK Then
Try
Dim FilePath As String = OpenVideoFile.FileName()
Return FilePath
Catch ex As Exception
MessageBox.Show(ex.Message)
Return Nothing
End Try
Else
Return Nothing
End If
End Function
'-------------------------------------------------------------------------------------------------------------
' Picture Function
'-------------------------------------------------------------------------------------------------------------
Public Function ResizePicture(YourPictureBox As PictureBox, Width As Integer, Height As Integer) As Byte()
'Creating A New Dialog
Dim OpenPictureFile As New OpenFileDialog
'Filtering The Types
OpenPictureFile.Filter = "Image Files | *.jpg; *.jpeg; *.bmp; *.png; *.gif;"
'Openning The File
If OpenPictureFile.ShowDialog = System.Windows.Forms.DialogResult.OK Then
Try
' Getting File Path
Dim FilePath As String = OpenPictureFile.FileName()
Dim FileName As String = System.IO.Path.GetFileName(OpenPictureFile.FileName)
' Picture File
Dim Picture As New MemoryStream
' Define New Image Size
Dim LogoSize As New Size(Width, Height)
' Resizing The Image
Dim ResizedImage = New Bitmap(Image.FromFile(FilePath), LogoSize)
' Display The Image
YourPictureBox.Image = ResizedImage
' Saving The Image As PNG Format
YourPictureBox.Image.Save(Picture, System.Drawing.Imaging.ImageFormat.Png)
' Read The Image As Bytes
Dim arrImage() As Byte = Picture.GetBuffer
' Closing The Picture
Picture.Close()
' Returns Image Data In Bytes Format
Return arrImage
Catch ex As Exception
MessageBox.Show(ex.Message)
Return Nothing
End Try
Else
Return Nothing
End If
End Function
'-------------------------------------------------------------------------------------------------------------
' Country Functions
'-------------------------------------------------------------------------------------------------------------
Public Sub GetCountryList(ComboBox As ComboBox)
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 dataset)
Try
CON.Open()
RDR = COM.ExecuteReader
If RDR.HasRows = True Then
While RDR.Read
LST.Add(New dataset(RDR("id"), RDR("name")))
End While
End If
CON.Close()
Catch ex As MySqlException
MessageBox.Show(ex.Message)
Finally
CON.Dispose()
End Try
ComboBox.DataSource = LST
ComboBox.ValueMember = "ID"
ComboBox.DisplayMember = "name"
End Sub
Public Sub GetCountryFlag(FlagPictureBox As PictureBox, CountryID As Integer)
Dim QRY As String
Try
QRY = "select flag from countries where id=" & CountryID
Catch ex As Exception
Exit Sub
End Try
Dim CON As New MySqlConnection(CON_STRING)
Dim COM As New MySqlCommand(QRY, CON)
Dim RDR As MySqlDataReader
Dim LST As New List(Of dataset)
Try
CON.Open()
RDR = COM.ExecuteReader
If RDR.HasRows = True Then
While RDR.Read
Try
Dim data As Byte() = DirectCast(RDR("flag"), Byte())
Dim flag As New System.IO.MemoryStream(data)
FlagPictureBox.Image = Image.FromStream(flag)
Catch ex As Exception
FlagPictureBox.Image = Nothing
Exit Sub
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 UpdateCountryFlag(FlagPictureBox As PictureBox, CountryID As Integer)
' Query To Update
Dim QRY As String = "update countries set flag = @flag where id=" & CountryID
' 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
'-------------------------------------------------------------------------------------------------------------
' Clubs Functions
'-------------------------------------------------------------------------------------------------------------
Public Sub GetClubsList(ComboBox As ComboBox)
Dim QRY As String = "select id, title from clubs order by title 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 dataset)
Try
CON.Open()
RDR = COM.ExecuteReader
If RDR.HasRows = True Then
While RDR.Read
LST.Add(New dataset(RDR("id"), RDR("title")))
End While
End If
CON.Close()
Catch ex As MySqlException
MessageBox.Show(ex.Message)
Finally
CON.Dispose()
End Try
ComboBox.DataSource = LST
ComboBox.ValueMember = "ID"
ComboBox.DisplayMember = "name"
End Sub
Public Sub GetClubLogo(LogoPictureBox As PictureBox, ClubID As Integer)
Dim QRY As String
Try
QRY = "select logo from clubs where id=" & ClubID
Catch ex As Exception
Exit Sub
End Try
Dim CON As New MySqlConnection(CON_STRING)
Dim COM As New MySqlCommand(QRY, CON)
Dim RDR As MySqlDataReader
Dim LST As New List(Of dataset)
Try
CON.Open()
RDR = COM.ExecuteReader
If RDR.HasRows = True Then
While RDR.Read
Try
Dim data As Byte() = DirectCast(RDR("logo"), Byte())
Dim flag As New System.IO.MemoryStream(data)
LogoPictureBox.Image = Image.FromStream(flag)
Catch ex As Exception
LogoPictureBox.Image = Nothing
Exit Sub
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 UpdateClubLogo(LogoPictureBox As PictureBox, ClubID As Integer)
' Query To Update
Dim QRY As String = "update clubs set logo = @logo where id=" & ClubID
' 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
Public Sub EventList(ListBox As ListBox)
Try
ListBox.Items.Clear()
Catch ex As Exception
End Try
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 dataset)
Try
CON.Open()
RDR = COM.ExecuteReader
If RDR.HasRows = True Then
While RDR.Read
LST.Add(New dataset(RDR("id"), RDR("title")))
End While
End If
CON.Close()
Catch ex As MySqlException
MessageBox.Show(ex.Message)
Finally
CON.Dispose()
End Try
ListBox.DataSource = LST
ListBox.ValueMember = "ID"
ListBox.DisplayMember = "name"
End Sub
'-------------------------------------------------------------------------------------------------------------
' Clubs Functions
'-------------------------------------------------------------------------------------------------------------
Public Function IsFormOpen(ByVal frm As Form) As Boolean
If Application.OpenForms.OfType(Of Form).Contains(frm) Then
Return True
Else
Return False
End If
End Function
Public Sub ClearComboBox(ComboBox As ComboBox)
Try
ComboBox.DataSource = Nothing
ComboBox.Items.Clear()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Public Sub ClearListBox(ListBox As ListBox)
Try
ListBox.DataSource = Nothing
ListBox.Items.Clear()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Public Sub SubPopulateComboBox(Data As List(Of dataset), ComboBox As ComboBox)
ClearComboBox(ComboBox)
ComboBox.DataSource = Data
ComboBox.ValueMember = "ID"
ComboBox.DisplayMember = "NAME"
End Sub
Public Sub SubPopulateListBox(Data As List(Of dataset), ListBox As ListBox)
ClearListBox(ListBox)
ListBox.DataSource = Data
ListBox.ValueMember = "ID"
ListBox.DisplayMember = "NAME"
End Sub
End Module
@@ -0,0 +1,49 @@
Imports System.IO
Imports MySql.Data.MySqlClient
Module MySQL
Public TAKEONE_EVENT As Integer ' This Carries The Select Event Number
Public Function CON_STRING() As String
With My.Settings
Return "server=" & .server & "; Port=" & .port & "; user id=" & .userid & "; password=" & .password & "; database=" & .database & ";"
End With
End Function
Public Function CON_TEST(Server As String, Port As Integer, Database As String, UserName As String, Password As String) As Boolean
Dim CON_TEST_STRING As String = "server=" & Server & "; Port=" & Port & "; user id=" & UserName & "; password=" & Password & "; database=" & Database & ";"
Dim CON As New MySqlConnection(CON_TEST_STRING)
Try
CON.Open()
CON.Close()
'MessageBox.Show("Connection Sucessfull")
Return True
Catch ex As MySqlException
'MessageBox.Show(ex.Message)
Return False
End Try
End Function
Public Function ReadMySQLDate(MySQLDate As String) As Date
Dim dDate As Date = Date.ParseExact(MySQLDate, "yyyy-MM-dd", Globalization.CultureInfo.InvariantCulture)
Return dDate
End Function
Public Function ReadMySQLDateTime(MySQLDateTime As String) As DateTime
Dim dDate As DateTime = DateTime.ParseExact(MySQLDateTime, "yyyy-MM-dd hh:mm:ss", Globalization.CultureInfo.InvariantCulture)
Return dDate
End Function
End Module
@@ -0,0 +1,5 @@
Module EventSelection
Public SelectedEvent As platformevent
End Module