Imports System.IO
Imports MySql.Data.MySqlClient

Public Class frm_main

    Public Server As Boolean = False

    Private Sub frm_event_managment_Load(sender As Object, e As EventArgs) Handles MyBase.Load

        EnableIfDatabase()

    End Sub

    Private Sub btn_system_settings_Click(sender As Object, e As EventArgs) Handles btn_system_settings.Click

        Me.Hide()
        frm_settings.Show()

    End Sub

    Private Sub btn_run_event_Click(sender As Object, e As EventArgs) Handles btn_manage_event.Click

        If Not SelectedEvent.ID = 0 Then
            frm_event_control.Show()
            Me.Hide()
        End If

    End Sub

    Private Sub btn_person_data_Click(sender As Object, e As EventArgs) Handles btn_person_data.Click

        frm_add_person.Show()

    End Sub

    Private Sub btn_create_event_Click(sender As Object, e As EventArgs) Handles btn_create_event.Click

        frm_create_event.Show()
        Me.Hide()

    End Sub

    Private Sub btn_history_view_Click(sender As Object, e As EventArgs) Handles btn_history_view.Click



    End Sub

    Private Sub lst_events_SelectedIndexChanged(sender As Object, e As EventArgs) Handles lst_events.SelectedIndexChanged

        Try
            SelectedEvent = New platformevent(lst_events.SelectedValue)
            lbl_country_iso3.Text = SelectedEvent.Country.ISO3
            pb_event_logo.Image = Image.FromStream(SelectedEvent.Logo)
            pb_event_country_flag.Image = Image.FromStream(SelectedEvent.Country.Flag)
        Catch ex As Exception

        End Try

    End Sub

    Private Sub btn_update_club_logo_Click(sender As Object, e As EventArgs) Handles btn_update_club_logo.Click

        frm_update_logo.Show()

    End Sub

    Private Sub btn_update_country_flag_Click(sender As Object, e As EventArgs) Handles btn_update_country_flag.Click

        frm_update_flag.Show()

    End Sub

    Private Sub btn_delete_event_Click(sender As Object, e As EventArgs) Handles btn_delete_event.Click

        If Not lst_events.SelectedValue = 0 Then

            Dim iCancelEvent As DialogResult = MessageBox.Show("Would You Like To Cancel The Event ?", "Event Cancelation", MessageBoxButtons.YesNo, MessageBoxIcon.Stop)

            If iCancelEvent = DialogResult.Yes Then

                Try
                    EventList(lst_events)
                Catch ex As Exception

                End Try

            End If

        End If

    End Sub

    Private Sub btn_friendly_match_Click(sender As Object, e As EventArgs) Handles btn_friendly_match.Click

        frm_friendly_match.Show()
        Me.Hide()

    End Sub

    Public Sub EnableIfDatabase()

        If (CON_TEST(My.Settings.server, My.Settings.port, My.Settings.database, My.Settings.userid, My.Settings.password)) Then

            EventList(lst_events)
            btn_create_event.Enabled = True
            btn_delete_event.Enabled = True
            btn_friendly_match.Enabled = True
            btn_history_view.Enabled = True
            btn_manage_event.Enabled = True
            btn_person_data.Enabled = True
            btn_system_settings.Enabled = True
            btn_update_club_logo.Enabled = True
            btn_update_country_flag.Enabled = True
            btn_add_club.Enabled = True

        Else

            btn_create_event.Enabled = False
            btn_delete_event.Enabled = False
            btn_friendly_match.Enabled = False
            btn_history_view.Enabled = False
            btn_manage_event.Enabled = False
            btn_person_data.Enabled = False
            btn_add_club.Enabled = False
            btn_update_club_logo.Enabled = False
            btn_update_country_flag.Enabled = False
            btn_system_settings.Enabled = True
            Me.Hide()

        End If
    End Sub

End Class