Modules/GUIs.ZooFlow/Administration/frmAdmin_CWProfile.vb
2021-04-22 16:57:16 +02:00

208 lines
7.9 KiB
VB.net

Imports System.ComponentModel
Imports DevExpress.XtraEditors
Imports DevExpress.XtraGrid.Views.Grid
Imports DevExpress.XtraLayout
Imports DevExpress.XtraTab
Imports DigitalData.Controls.RegexEditor
Imports DigitalData.Controls.SQLEditor
Imports DigitalData.GUIs.Common
Imports DigitalData.Modules.Logging
Public Class frmAdmin_CWProfile
Implements frmAdmin_Interface
Public Property PrimaryKey As Integer Implements frmAdmin_Interface.PrimaryKey
Public Property HasChanges As Boolean Implements frmAdmin_Interface.HasChanges
Public Property IsInsert As Boolean Implements frmAdmin_Interface.IsInsert
Private Const BUTTON_REGEX_PROFILE = "BUTTON_REGEX_PROFILE"
Private Const BUTTON_SEARCH_SQL = "BUTTON_SEARCH_SQL"
Private Const BUTTON_COUNT_SQL = "BUTTON_COUNT_SQL"
Private Const TAB_PAGE_PROFILE = "TAB_PAGE_PROFILE"
Private Const TAB_PAGE_DOCSEARCH = "TAB_PAGE_DOCSEARCH"
Private Const TAB_PAGE_DATASEARCH = "TAB_PAGE_DATASEARCH"
Private Pages As ClassDetailPages
Public Sub New(PrimaryKey As Integer)
' Dieser Aufruf ist für den Designer erforderlich.
InitializeComponent()
' Fügen Sie Initialisierungen nach dem InitializeComponent()-Aufruf hinzu.
Logger = My.LogConfig.GetLogger()
Me.PrimaryKey = PrimaryKey
Me.IsInsert = IsInsert
End Sub
Private Sub frmAdmin_CWProfile_Load(sender As Object, e As EventArgs) Handles Me.Load
Try
TBCW_PROFILESTableAdapter.Connection.ConnectionString = My.Database.CurrentSQLConnectionString
TBCW_PROFILESTableAdapter.Fill(DBCW_Stammdaten.TBCW_PROFILES, PrimaryKey)
TBCW_PROF_DOC_SEARCHTableAdapter.Connection.ConnectionString = My.Database.CurrentSQLConnectionString
TBCW_PROF_DOC_SEARCHTableAdapter.Fill(DBCW_Stammdaten.TBCW_PROF_DOC_SEARCH, PrimaryKey)
TBCW_PROF_DATA_SEARCHTableAdapter.Connection.ConnectionString = My.Database.CurrentSQLConnectionString
TBCW_PROF_DATA_SEARCHTableAdapter.Fill(DBCW_Stammdaten.TBCW_PROF_DATA_SEARCH, PrimaryKey)
' Configure the GridViews with some default options
Dim oViews As New List(Of GridView) From {GridViewDataSearch, GridViewDocSearch}
Dim oGridBuilder As New GridBuilder(oViews)
oGridBuilder.
WithDefaults().
WithReadOnlyOptions()
' Add Focus Handler to all controls in all LayoutControls
Dim oLayoutControls = New List(Of LayoutControl) From {LayoutControlProfile, LayoutControlDocSearch, LayoutControlDataSearch}
Pages = New ClassDetailPages(oLayoutControls)
Pages.AddRange({
New ClassDetailPages.DetailPage With {
.IsPrimary = True,
.Name = "Profil",
.TabPage = PageProfile,
.BindingSource = TBCW_PROFILESBindingSource,
.DataTable = DBCW_Stammdaten.TBCW_PROFILES,
.AddedWhoEdit = txtAddedWho,
.ChangedWhoEdit = txtChangedWho
},
New ClassDetailPages.DetailPage With {
.Name = "Dokument-Suche",
.TabPage = PageDocumentSearch,
.BindingSource = TBCW_PROF_DOC_SEARCHBindingSource,
.DataTable = DBCW_Stammdaten.TBCW_PROF_DOC_SEARCH,
.AddedWhoEdit = txtAddedWho1,
.ChangedWhoEdit = txtChangedWho1
},
New ClassDetailPages.DetailPage With {
.Name = "Daten-Suche",
.TabPage = PageDataSearch,
.BindingSource = TBCW_PROF_DATA_SEARCHBindingSource,
.DataTable = DBCW_Stammdaten.TBCW_PROF_DATA_SEARCH
}
})
AddHandler Pages.AnyControl_Focus, AddressOf AnyControl_Focus
AddHandler Pages.AnyControl_Changed, AddressOf AnyControl_Changed
Catch ex As Exception
ShowError(ex)
End Try
End Sub
Private Sub AnyControl_Focus(sender As Object, e As ClassDetailPages.DetailPageEventArgs)
If Not IsNothing(e.Page) Then
If e.Page.IsPrimary = True Then
BarButtonNew.Enabled = False
Else
BarButtonNew.Enabled = True
End If
RibbonPageGroup1.Text = e.Page.Name
End If
End Sub
Private Sub AnyControl_Changed(sender As Object, e As ClassDetailPages.DetailPageEventArgs)
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
Public Function SaveData() As Boolean Implements frmAdmin_Interface.SaveData
If Pages.CurrentPage Is Nothing Then
Return False
End If
Dim oPage = Pages.CurrentPage
Try
oPage.BindingSource.EndEdit()
If oPage.DataTable.GetChanges() IsNot Nothing Then
HasChanges = True
If IsInsert Then
oPage.AddedWhoEdit.EditValue = My.Application.User.UserName
Else
oPage.ChangedWhoEdit.EditValue = My.Application.User.UserName
End If
oPage.BindingSource.EndEdit()
Return True
Else
HasChanges = False
End If
Return False
Catch ex As Exception
ShowError(ex)
Return False
End Try
End Function
Private Sub BarButtonSave_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonSave.ItemClick
ResetMessages()
If SaveData() And HasChanges Then
Select Case Pages.CurrentPage.TabPage.Name
Case PageProfile.Name
TBCW_PROFILESTableAdapter.Update(Pages.CurrentPage.DataTable)
Case PageDocumentSearch.Name
TBCW_PROF_DOC_SEARCHTableAdapter.Update(Pages.CurrentPage.DataTable)
End Select
ShowStatus($"{Pages.CurrentPage.Name} gespeichert!")
End If
End Sub
Public Function DeleteData() As Boolean Implements frmAdmin_Interface.DeleteData
Throw New NotImplementedException()
End Function
Private Sub TextEdit4_ButtonClick(sender As Object, e As DevExpress.XtraEditors.Controls.ButtonPressedEventArgs) Handles TextEdit4.ButtonClick
Dim oTextEdit As TextEdit = sender
If e.Button.Tag = BUTTON_REGEX_PROFILE Then
Dim oForm As New frmRegexEditor(oTextEdit.EditValue)
Dim oResult = oForm.ShowDialog()
If oResult = DialogResult.OK Then
oTextEdit.EditValue = oForm.RegexString
End If
End If
End Sub
Private Sub TextEdit7_ButtonClick(sender As Object, e As DevExpress.XtraEditors.Controls.ButtonPressedEventArgs) Handles TextEdit7.ButtonClick
Dim oTextEdit As TextEdit = sender
If e.Button.Tag = BUTTON_SEARCH_SQL Then
Dim oForm As New frmSQLEditor(oTextEdit.EditValue)
Dim oResult = oForm.ShowDialog()
If oResult = DialogResult.OK Then
oTextEdit.EditValue = oForm.SQLString
End If
End If
End Sub
Private Sub TextEdit8_ButtonClick(sender As Object, e As DevExpress.XtraEditors.Controls.ButtonPressedEventArgs) Handles TextEdit8.ButtonClick
Dim oTextEdit As TextEdit = sender
If e.Button.Tag = BUTTON_COUNT_SQL Then
Dim oForm As New frmSQLEditor(oTextEdit.EditValue)
Dim oResult = oForm.ShowDialog()
If oResult = DialogResult.OK Then
oTextEdit.EditValue = oForm.SQLString
End If
End If
End Sub
End Class