Public Class frmHotkey_User

    Private Sub TBHOTKEY_PROFILEBindingNavigatorSaveItem_Click(sender As Object, e As EventArgs)
        Me.Validate()
        Me.TBHOTKEY_PROFILEBindingSource.EndEdit()
        Me.TableAdapterManager.UpdateAll(Me.MyDataset)

    End Sub

    Private Sub frmHotkey_User_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        'TODO: Diese Codezeile lädt Daten in die Tabelle "MyDataset.TBHOTKEY_USER_PROFILE". Sie können sie bei Bedarf verschieben oder entfernen.

        Try
            Me.TBHOTKEY_PROFILETableAdapter.Connection.ConnectionString = MyConnectionString
            Me.TBMYHOTKEYSTableAdapter.Connection.ConnectionString = MyConnectionString
            Me.TBHOTKEY_USER_PROFILETableAdapter.Connection.ConnectionString = MyConnectionString
            Me.TBHOTKEY_PROFILETableAdapter.Fill(Me.MyDataset.TBHOTKEY_PROFILE)

            If USER_LANGUAGE <> "de-DE" Then
                Me.lblmeinehotkeys.Text = "My (" & Environment.UserName & ") Hotkeys:"
            Else
                Me.lblmeinehotkeys.Text = "Meine (" & Environment.UserName & ") Hotkeys:"
            End If

            LoadMyHotkeys(USER_ID)
        Catch ex As Exception
            MsgBox("Error in Load Form: " & vbNewLine & ex.Message, MsgBoxStyle.Critical)
        End Try
      
    End Sub

    Private Sub LoadMyHotkeys(UserID As Integer)
        Try
            Me.TBMYHOTKEYSTableAdapter.Fill(Me.MyDataset.TBMYHOTKEYS, UserID)
        Catch ex As System.Exception
            MsgBox("Error in LoadMyHotkeys: " & vbNewLine & ex.Message, MsgBoxStyle.Critical)
        End Try

    End Sub

    Private Sub btnAddtomyHK_Click(sender As Object, e As EventArgs) Handles btnAddtomyHK.Click
        Try
            If ListBox1.SelectedIndex <> -1 Then
                TBHOTKEY_USER_PROFILETableAdapter.cmdInsert(USER_ID, ListBox1.SelectedValue)
                LoadMyHotkeys(USER_ID)
            End If
        Catch ex As Exception
            MsgBox("Error in Add MyHotkey: " & vbNewLine & ex.Message, MsgBoxStyle.Critical)
        End Try
      
    End Sub
    Sub Load_MyProfile(HKPROFILE_ID As Integer)
        Try
            Me.TBHOTKEY_USER_PROFILETableAdapter.Fill(Me.MyDataset.TBHOTKEY_USER_PROFILE, HKPROFILE_ID)
        Catch ex As Exception
            MsgBox("Error in Load_MyProfile: " & vbNewLine & ex.Message, MsgBoxStyle.Critical)
        End Try

    End Sub

    Private Sub ListBoxMyHK_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListBoxMyHK.SelectedIndexChanged
        If ListBoxMyHK.SelectedIndex <> -1 Then
            Console.WriteLine(ListBoxMyHK.SelectedValue)
            Load_MyProfile(ListBoxMyHK.SelectedValue)
        End If
    End Sub

    Private Sub btndelete_Click(sender As Object, e As EventArgs) Handles btndelete.Click
        If ListBoxMyHK.SelectedIndex <> -1 Then
            Me.TBHOTKEY_USER_PROFILETableAdapter.Delete(ListBoxMyHK.SelectedValue)
            LoadMyHotkeys(USER_ID)
            Me.MyDataset.TBHOTKEY_USER_PROFILE.Clear()
        End If
    End Sub

    Private Sub btnsave_Click(sender As Object, e As EventArgs) Handles btnsave.Click
        Try
            TBHOTKEY_USER_PROFILEBindingSource.EndEdit()
            If Me.MyDataset.TBHOTKEY_USER_PROFILE.GetChanges Is Nothing = False Then
                Me.CHANGED_WHOTextBox.Text = Environment.UserName
                TBHOTKEY_USER_PROFILEBindingSource.EndEdit()
                TBHOTKEY_USER_PROFILETableAdapter.Update(MyDataset.TBHOTKEY_USER_PROFILE)
                Me.lblSave.Visible = True
                LoadMyHotkeys(USER_ID)
            Else
                Me.lblSave.Visible = False
            End If
        Catch ex As Exception
            MsgBox("Error in Save My Profile: " & vbNewLine & ex.Message, MsgBoxStyle.Critical)
        End Try
    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        If Not Me.WD_SEARCHTextBox.Text = "" Then
            Me.OFDWindreamsuche.FileName = Me.WD_SEARCHTextBox.Text
        End If

        If Me.OFDWindreamsuche.ShowDialog = Windows.Forms.DialogResult.OK Then
            Me.WD_SEARCHTextBox.Text = Me.OFDWindreamsuche.FileName
        End If
    End Sub

    Private Sub HOTKEY2TextBox_KeyDown(sender As Object, e As KeyEventArgs) Handles HOTKEY2TextBox.KeyDown
        HOTKEY2TextBox.Text = ""
    End Sub

    Private Sub chkbxMaximizeWS_CheckedChanged(sender As Object, e As EventArgs) Handles chkbxMaximizeWS.CheckedChanged
        My.Settings.Save()
    End Sub
End Class