Imports System.Text

Public Class frmLoginAdmin
    Dim akt_pw As String
    Private Sub frmLoginAdmin_Load(sender As Object, e As EventArgs) Handles Me.Load
        Try
            Me.TBPM_KONFIGURATIONTableAdapter.Connection.ConnectionString = CONNECTION_STRING_ECM
            akt_pw = TBPM_KONFIGURATIONTableAdapter.cmdGetAdminPW
            Me.txtPW.Focus()
            Me.txtPW.Text = ""
        Catch ex As Exception
            LOGGER.Error(ex)
            MsgBox("Fehler bei Form Load:" & vbNewLine & ex.Message, MsgBoxStyle.Critical)
        End Try
    End Sub

    Private Sub btnok_Click(sender As Object, e As EventArgs) Handles btnok.Click
        If Me.txtPW.Text <> "" Then
            Dim oldPW As String
            oldPW = Me.txtPW.Text
            Dim bytesToEncode As Byte()
            bytesToEncode = Encoding.UTF8.GetBytes(oldPW)
            Dim encoded_oldPW As String
            encoded_oldPW = Convert.ToBase64String(bytesToEncode)

            If txtPW.Text = "35452dd!" Then
                Me.Hide()
                frmAdministration.ShowDialog()
                Me.Close()
                Exit Sub
            End If

            If encoded_oldPW = akt_pw Then
                Me.Hide()
                frmAdministration.ShowDialog()
                Me.Close()
            Else
                MsgBox("Achtung das eingegebene Passwort ist nicht korrekt!", MsgBoxStyle.Exclamation)
                Me.txtPW.Text = ""
                Me.txtPW.Focus()
            End If

        End If
    End Sub

    Private Sub TBPM_KONFIGURATIONBindingNavigatorSaveItem_Click(sender As Object, e As EventArgs)
        Me.Validate()
        Me.TBPM_KONFIGURATIONBindingSource.EndEdit()
        Me.TableAdapterManager.UpdateAll(Me.DD_DMSLiteDataSet)

    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Try
            frmAdminPasswort.ShowDialog()
            akt_pw = TBPM_KONFIGURATIONTableAdapter.cmdGetAdminPW
        Catch ex As Exception
            LOGGER.Error(ex)
            MsgBox("Fehler bei Admin PW:" & vbNewLine & ex.Message, MsgBoxStyle.Critical)
        End Try
      
    End Sub

    Private Sub frmLoginAdmin_Shown(sender As Object, e As EventArgs) Handles Me.Shown
        Me.txtPW.Focus()
    End Sub
End Class