Public Class frmLogRecord
    Dim formloaded As Boolean = False
    Private Shared _Instance As frmLogRecord = Nothing
    Public Shared Function Instance() As frmLogRecord
        If _Instance Is Nothing OrElse _Instance.IsDisposed = True Then
            _Instance = New frmLogRecord
        End If
        _Instance.BringToFront()
        Return _Instance
    End Function

    Private Sub TBPMO_RECORD_LOG_CONFIGBindingNavigatorSaveItem_Click(sender As Object, e As EventArgs) Handles TBPMO_RECORD_LOG_CONFIGBindingNavigatorSaveItem.Click
        Save_Log()
    End Sub

    Private Sub frmLogRecord_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Try
            Me.TBPMO_RECORD_LOG_CONFIGTableAdapter.Connection.ConnectionString = MyConnectionString
            Me.TBPMO_RECORD_LOG_CONFIGTableAdapter.Fill(Me.DD_DMSDataSet.TBPMO_RECORD_LOG_CONFIG)

            Dim DT1 As DataTable = ClassDatabase.Return_Datatable("SELECT GUID, NAME AS DISPLAY FROM TBPMO_FORM ORDER BY NAME")

            FORM_IDComboBox.DataSource = DT1
            FORM_IDComboBox.DisplayMember = DT1.Columns(1).ColumnName
            FORM_IDComboBox.ValueMember = DT1.Columns(0).ColumnName

        Catch ex As Exception
            MsgBox("Error in Load Form:" & vbNewLine & ex.Message, MsgBoxStyle.Critical)
        End Try
    End Sub
    Sub Save_Log()
        Try
            Me.TBPMO_RECORD_LOG_CONFIGBindingSource.EndEdit()
            If DD_DMSDataSet.TBPMO_RECORD_LOG_CONFIG.GetChanges Is Nothing = False Then
                Me.CHANGED_WHOTextBox.Text = Environment.UserName
                Me.TBPMO_RECORD_LOG_CONFIGBindingSource.EndEdit()
                TBPMO_RECORD_LOG_CONFIGTableAdapter.Update(Me.DD_DMSDataSet.TBPMO_RECORD_LOG_CONFIG)
                lblSaveWVEmail.Visible = True
            Else
                lblSaveWVEmail.Visible = False
            End If
        Catch ex As Exception
            MsgBox("Fehler in Save_Log:" & vbNewLine & ex.Message, MsgBoxStyle.Critical)
        End Try
    End Sub

    Private Sub frmLogRecord_Shown(sender As Object, e As EventArgs) Handles Me.Shown
        formloaded = True
        Load_Controls()
    End Sub

    Private Sub FORM_IDComboBox_SelectedIndexChanged(sender As Object, e As EventArgs) Handles FORM_IDComboBox.SelectedIndexChanged
        Load_Controls()
    End Sub
    Sub Load_Controls()
        If formloaded = True Then
            Try
                If FORM_IDComboBox.SelectedIndex <> -1 Then
                    Dim sql = String.Format("SELECT GUID, NAME FROM TBPMO_CONTROL WHERE FORM_ID = {0} and CONTROL_TYPE_ID not in (1,5) ORDER BY NAME", FORM_IDComboBox.SelectedValue)
                    Dim DT1 As DataTable = ClassDatabase.Return_Datatable(sql)
                    CONTROL_IDComboBox.DataSource = DT1
                    CONTROL_IDComboBox.DisplayMember = DT1.Columns(1).ColumnName
                    CONTROL_IDComboBox.ValueMember = DT1.Columns(0).ColumnName
                End If
            Catch ex As Exception
                If Not ex.Message.StartsWith("Der Operator &") Then
                    MsgBox("Fehler in Load Controls:" & vbNewLine & ex.Message, MsgBoxStyle.Critical)
                End If

            End Try
        End If
    End Sub
End Class