Imports DigitalData.Modules.Logging

Public Class frmAdmin_Globix
    Implements IAdminForm
    Public Property HasChanges As Boolean = False Implements IAdminForm.HasChanges
    Public Property IsInsert As Boolean = False Implements IAdminForm.IsInsert
    Public Property PrimaryKey As Integer Implements IAdminForm.PrimaryKey

    Public Sub New(PrimaryKey As Integer, Optional IsInsert As Boolean = False)
        ' Dieser Aufruf ist für den Designer erforderlich.
        InitializeComponent()

        ' Fügen Sie Initialisierungen nach dem InitializeComponent()-Aufruf hinzu.
        Me.PrimaryKey = PrimaryKey
        Me.IsInsert = IsInsert
    End Sub

    Private Sub frmAdmin_Attribute_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Try
            TBDD_DOKUMENTARTTableAdapter.Connection.ConnectionString = My.Database.CurrentSQLConnectionString
            Me.TBDD_DOKUMENTARTTableAdapter.Fill(Me.GlobixDataset.TBDD_DOKUMENTART, PrimaryKey)
        Catch ex As Exception
            ShowErrorMessage(ex)
        End Try
    End Sub

    Private Sub BarButtonItem2_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonSave.ItemClick
        ResetMessages()

        If SaveData() And HasChanges Then
            ShowStatus("Attribute gespeichert!")
        End If
    End Sub

    Private Sub ResetMessages()
        labelStatus.Visibility = DevExpress.XtraBars.BarItemVisibility.Never
    End Sub

    Private Sub ShowStatus(Message As String)
        labelStatus.Caption = Message
        labelStatus.Visibility = DevExpress.XtraBars.BarItemVisibility.Always
    End Sub

    Private Sub BarButtonItem1_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonSaveExit.ItemClick
        ResetMessages()

        If SaveData() Then
            Close()
        End If
    End Sub

    Public Function SaveData() As Boolean
        Try
            TBDD_DOKUMENTARTBindingSource.EndEdit()

            If DSIDB_Stammdaten.VWIDB_BE_ATTRIBUTE.GetChanges() IsNot Nothing Then
                HasChanges = True

                If IsInsert Then
                    txtAddedWho.EditValue = My.Application.User.UserName
                Else
                    txtChangedWho.EditValue = My.Application.User.UserName
                End If

                TBDD_DOKUMENTARTBindingSource.EndEdit()
                TBDD_DOKUMENTARTTableAdapter.Update(GlobixDataset.TBDD_DOKUMENTART)
            End If

            Return True
        Catch ex As Exception
            ShowErrorMessage(ex)
            Return False
        End Try
    End Function

    Private Sub SimpleButton2_Click(sender As Object, e As EventArgs) Handles SimpleButton2.Click

    End Sub

    Public Function DeleteData() As Boolean Implements IAdminForm.DeleteData
        Throw New NotImplementedException()
    End Function
End Class