Imports System.ComponentModel

Public Class frm_settings

    Private Sub frm_settings_Closing(sender As Object, e As CancelEventArgs) Handles Me.Closing

        frm_main.EnableIfDatabase()
        frm_main.Show()

    End Sub

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

        Load_Settings()

    End Sub

    Private Sub btn_save_connection_Click(sender As Object, e As EventArgs) Handles btn_save_connection.Click

        Save_Settings()
        Me.Close()

    End Sub

    Private Sub Load_Settings()

        ' Load Video Intro Settings
        chk_intro.Checked = My.Settings.video_intro_enable
        txt_path.Text = My.Settings.video_intro_path

        ' Load Database Settings
        chk_database_enable.Checked = My.Settings.database_enable
        txt_server.Text = My.Settings.server
        txt_port.Text = My.Settings.port
        txt_user.Text = My.Settings.userid
        txt_password.Text = My.Settings.password
        txt_database.Text = My.Settings.database

        ' Load Video Capture Settings
        chk_video_capture.Checked = My.Settings.video_capture_enable

    End Sub

    Private Sub Save_Settings()

        ' Video Intro Settings
        My.Settings.video_intro_enable = chk_intro.Checked
        My.Settings.video_intro_path = txt_path.Text

        ' Database Settings
        My.Settings.database_enable = chk_database_enable.Checked
        My.Settings.userid = txt_user.Text
        My.Settings.password = txt_password.Text
        My.Settings.database = txt_database.Text
        My.Settings.port = txt_port.Text
        My.Settings.server = txt_server.Text

        ' Video Capture Settings
        My.Settings.video_capture_enable = chk_video_capture.Checked

        ' Command to Commit Save
        My.Settings.Save()

    End Sub

    Private Sub LoadFilePath()

        '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()
                txt_path.Text = FilePath
                My.Settings.video_intro_path = txt_path.Text
            Catch ex As Exception
                MessageBox.Show(ex.Message)
            End Try

        End If

    End Sub

    Private Sub btn_load_file_Click(sender As Object, e As EventArgs) Handles btn_load_file.Click

        LoadFilePath()

    End Sub

End Class