Imports DigitalData.Modules.Database
Imports DigitalData.Modules.Logging

Public Class FrmConnection
    Public Property LogConfig As LogConfig

    Private _logger As NLog.Logger

    Private Sub FrmConnection_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        _logger = LogConfig.GetLogger()

        FbDatabaseLocationTextBox.DataBindings.Add("Text", My.Settings, "fbDatabaseLocation")
        FbDatasourceTextBox.DataBindings.Add("Text", My.Settings, "fbDatasource")
        FbUserTextBox.DataBindings.Add("Text", My.Settings, "fbUser")
        FbPasswordTextBox.DataBindings.Add("Text", My.Settings, "fbPassword")
    End Sub

    Private Sub BtnConnect_Click(sender As Object, e As EventArgs) Handles btnConnect.Click
        Dim dbTest As Firebird

        Try
            dbTest = New Firebird(LogConfig, My.Settings.fbDatasource, My.Settings.fbDatabaseLocation, My.Settings.fbUser, My.Settings.fbPassword)


            My.Settings.Save()

            MsgBox("Connection successful!", MsgBoxStyle.Information, "Database Connection")

            lblConnectionStatus.Text = "Connection established!"
            lblConnectionStatus.BackColor = Color.GreenYellow

            DialogResult = DialogResult.OK
        Catch ex As Exception
            MsgBox("Connection failed!", MsgBoxStyle.Information, "Database Connection")

            lblConnectionStatus.Text = "No connection established"
            lblConnectionStatus.BackColor = Color.Red

            DialogResult = DialogResult.None
        End Try
    End Sub
End Class