2023-11-07 10:51:00 +01:00

225 lines
8.5 KiB
VB.net

Imports System.Data.SqlClient
Imports DevExpress.XtraGrid
Imports DevExpress.XtraGrid.Views.Grid
Imports DigitalData.Modules.Config
Imports DigitalData.Modules.Database
Imports DigitalData.Modules.Logging
Imports DigitalData.Modules.Base
Imports DigitalData.GUIs.Common
Public Class frmConfig
Private ReadOnly TBMT_CONFIG_GENERAL As New DS_DD_ECM.TBMT_CONFIGDataTable
Private ReadOnly ConfigManager As ConfigManager(Of MultiTool.Common.Config)
Private ReadOnly FormHelper As FormHelper
Private ReadOnly GridBuilder As GridBuilder
Private BindingSource As BindingSource = TBEDIXMLITEMSBindingSource
Private View As GridView = GridViewItems
Private Logger As Logger
Private FormLoading As Boolean = True
Private ReadOnly Property Config As Common.Config
Get
Return ConfigManager?.Config
End Get
End Property
Public Sub New(pLogConfig As LogConfig, pConfigManager As ConfigManager(Of Common.Config))
' Dieser Aufruf ist für den Designer erforderlich.
InitializeComponent()
' Fügen Sie Initialisierungen nach dem InitializeComponent()-Aufruf hinzu.
FormHelper = New FormHelper(pLogConfig, Me)
ConfigManager = pConfigManager
GridBuilder = New GridBuilder(GridViewTables, GridViewItems)
Logger = pLogConfig.GetLogger()
End Sub
Private Sub frmConfig_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Try
GridBuilder.WithDefaults()
GridBuilder.WithReadOnlyOptions(GridViewTables)
Dim oConnectionString = MSSQLServer.DecryptConnectionString(Config.ConnectionString)
Dim oBuilder As New SqlConnectionStringBuilder(oConnectionString) With {
.InitialCatalog = "DD_ECM"
}
oConnectionString = oBuilder.ToString()
Logger.Debug("Connection String: [{0}]", oConnectionString)
Logger.Debug("Setting default values")
DS_DD_ECM.TBMT_CONFIG.ADDED_WHOColumn.DefaultValue = Environment.UserName
DS_DD_ECM.TBMT_CONFIG.CHANGED_WHOColumn.DefaultValue = Environment.UserName
DS_DD_ECM.TBMT_TEMPLATE_ITEMS.ADDED_WHOColumn.DefaultValue = Environment.UserName
DS_DD_ECM.TBMT_TEMPLATE_ITEMS.CHANGED_WHOColumn.DefaultValue = Environment.UserName
Logger.Debug("Initializing Tables Adapter")
TBMT_TABLESTableAdapter.Connection.ConnectionString = oConnectionString
Logger.Debug("Initializing Templates Adapter")
TBMT_TEMPLATE_ITEMSTableAdapter.Connection.ConnectionString = oConnectionString
Logger.Debug("Initializing Config Adapter")
TBMT_CONFIGTableAdapter.Connection.ConnectionString = oConnectionString
Logger.Debug("Loading Data from Adapters")
TBMT_TABLESTableAdapter.Fill(DS_DD_ECM.TBMT_TABLES)
TBMT_CONFIGTableAdapter.Fill(DS_DD_ECM.TBMT_CONFIG)
TBMT_CONFIGTableAdapter.FillGeneral(TBMT_CONFIG_GENERAL)
Logger.Debug("Loading general config")
LoadGeneralConfig(TBMT_CONFIG_GENERAL)
BindingSource = TBEDIXMLITEMSBindingSource
FormLoading = False
GridViewItems.FocusedRowHandle = GridControl.InvalidRowHandle
Catch ex As Exception
Logger.Error(ex)
FormHelper.ShowError(ex, "Laden des Formulars")
End Try
End Sub
Private Sub LoadGeneralConfig(TBMT_CONFIG_GENERAL As DS_DD_ECM.TBMT_CONFIGDataTable)
For Each oRow As DataRow In TBMT_CONFIG_GENERAL.Rows
Dim oConfigKey = oRow.ItemEx("KEY", "")
Dim oConfigValue = oRow.ItemEx("VALUE", "")
Select Case oConfigKey
Case "YEAR_OVERRIDE"
txtYearOverride.EditValue = oConfigValue
Case "WEBSERVICE_BASEURL"
txtWebserviceBaseurl.EditValue = oConfigValue
Case "WEBSERVICE_USERNAME"
txtWebserviceUsername.EditValue = oConfigValue
Case "WEBSERIVCE_PASSWORD"
txtWebservicePassword.EditValue = oConfigValue
Case "WEBSERVICE_IMPORT_BASE_PATH"
txtWebserviceImportBasePath.EditValue = oConfigValue
Case "WEBSERVICE_IMPORT_RELATIVE_PATH"
txtWebserviceImportRelativePath.EditValue = oConfigValue
End Select
Next
End Sub
Private Sub SaveGeneralConfig(TBMT_CONFIG_GENERAL As DS_DD_ECM.TBMT_CONFIGDataTable)
For Each oRow As DataRow In TBMT_CONFIG_GENERAL.Rows
Dim oConfigKey = oRow.ItemEx("KEY", "")
Select Case oConfigKey
Case "YEAR_OVERRIDE"
oRow.Item("VALUE") = txtYearOverride.EditValue
Case "WEBSERVICE_BASEURL"
oRow.Item("VALUE") = txtWebserviceBaseurl.EditValue
Case "WEBSERVICE_USERNAME"
oRow.Item("VALUE") = txtWebserviceUsername.EditValue
Case "WEBSERIVCE_PASSWORD"
oRow.Item("VALUE") = txtWebservicePassword.EditValue
Case "WEBSERVICE_IMPORT_BASE_PATH"
oRow.Item("VALUE") = txtWebserviceImportBasePath.EditValue
Case "WEBSERVICE_IMPORT_RELATIVE_PATH"
oRow.Item("VALUE") = txtWebserviceImportRelativePath.EditValue
End Select
Next
End Sub
Private Sub Save()
GridViewItems.PostEditor()
TBMT_CONFIGTableAdapter.Update(DS_DD_ECM.TBMT_CONFIG)
DS_DD_ECM.TBMT_CONFIG.AcceptChanges()
GridViewConfig.PostEditor()
TBMT_TEMPLATE_ITEMSTableAdapter.Update(DS_DD_ECM.TBMT_TEMPLATE_ITEMS)
DS_DD_ECM.TBMT_TEMPLATE_ITEMS.AcceptChanges()
TBMT_CONFIG_GENERAL.AcceptChanges()
SaveGeneralConfig(TBMT_CONFIG_GENERAL)
TBMT_CONFIGTableAdapter.Update(TBMT_CONFIG_GENERAL)
End Sub
Private Sub BarButtonItem1_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItem1.ItemClick
Try
TBMT_CONFIGBindingSource.EndEdit()
TBEDIXMLITEMSBindingSource.EndEdit()
Save()
Catch ex As Exception
FormHelper.ShowError(ex, "Speichern der Konfiguration")
End Try
End Sub
Private Sub BarButtonItem2_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItem2.ItemClick
BindingSource?.AddNew()
End Sub
Private Sub XtraTabControl1_SelectedPageChanged(sender As Object, e As DevExpress.XtraTab.TabPageChangedEventArgs) Handles XtraTabControl1.SelectedPageChanged
Select Case e.Page.Name
Case tabPageSchema.Name
BindingSource = TBEDIXMLITEMSBindingSource
View = GridViewItems
Case tabPageConfig.Name
BindingSource = TBMT_CONFIGBindingSource
View = GridViewConfig
End Select
End Sub
Private Sub BarButtonItem3_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItem3.ItemClick
If View.FocusedRowHandle <> GridControl.InvalidRowHandle Then
Dim oResult = MsgBox("Wollen Sie den ausgewählten Eintrag löschen?", MsgBoxStyle.Question Or MsgBoxStyle.YesNo, "Eintrag löschen?")
If oResult = MsgBoxResult.Yes Then
Dim oRow As DataRow = View.GetDataRow(View.FocusedRowHandle)
BindingSource.RemoveCurrent()
BindingSource.EndEdit()
Save()
End If
End If
End Sub
Private Sub GridViewTables_FocusedRowChanged(sender As Object, e As Views.Base.FocusedRowChangedEventArgs) Handles GridViewTables.FocusedRowChanged
Try
If FormLoading Then
Logger.Debug("Form still loading. Exiting.")
Exit Sub
End If
If GridViewTables.FocusedRowHandle < 0 Then
Logger.Debug("No row selected. Exiting.")
Exit Sub
End If
Dim oRow As DataRow = GridViewTables.GetDataRow(GridViewTables.FocusedRowHandle)
If oRow Is Nothing Then
Logger.Debug("Invalid row handle. Exiting.")
Exit Sub
End If
Dim oTableId = oRow.Item("GUID")
Logger.Debug("Loading Items for Table [{0}]", oTableId)
TBMT_TEMPLATE_ITEMSTableAdapter.Fill(DS_DD_ECM.TBMT_TEMPLATE_ITEMS, oTableId)
Catch ex As Exception
Logger.Error(ex)
FormHelper.ShowError(ex, "Laden der Tabelle")
End Try
End Sub
End Class