MS Globix DLL ControlCreator
This commit is contained in:
@@ -5,7 +5,9 @@ Imports System.IO
|
||||
Imports System.Security.AccessControl
|
||||
Imports System.Security.Principal
|
||||
Imports System.Text.RegularExpressions
|
||||
Imports DigitalData.GUIs.GlobalIndexer
|
||||
Imports DigitalData.Modules.Logging
|
||||
Imports DigitalData.Controls.LookupGrid
|
||||
Imports Independentsoft
|
||||
|
||||
Public Class frmGlobix_Index
|
||||
@@ -35,6 +37,21 @@ Public Class frmGlobix_Index
|
||||
Private clsPostProcessing As GlobixPostprocessing
|
||||
Private _DataASorDB As ClassDataASorDB
|
||||
Private _idbdata As ClassIDBData
|
||||
Private _Patterns As GlobixPatterns
|
||||
Private _Controls As DigitalData.GUIs.GlobalIndexer.ControlCreator
|
||||
Public Class DocType
|
||||
Public Property Guid
|
||||
Public Property Name
|
||||
|
||||
Public Overrides Function ToString() As String
|
||||
Return Name
|
||||
End Function
|
||||
End Class
|
||||
Public Class ControlMeta
|
||||
Public Property IndexName As String
|
||||
Public Property IndexType As String
|
||||
Public Property MultipleValues As Boolean = False
|
||||
End Class
|
||||
#End Region
|
||||
Public Sub New(LogConfig As LogConfig)
|
||||
|
||||
@@ -49,6 +66,7 @@ Public Class frmGlobix_Index
|
||||
clsPatterns = New GlobixPatterns(LogConfig)
|
||||
clsPostProcessing = New GlobixPostprocessing(LogConfig)
|
||||
_idbdata = New ClassIDBData(LogConfig)
|
||||
_Patterns = New GlobixPatterns(LogConfig)
|
||||
End Sub
|
||||
|
||||
Private Sub frmGlobix_Index_Load(sender As Object, e As EventArgs) Handles MyBase.Load
|
||||
@@ -247,7 +265,15 @@ Public Class frmGlobix_Index
|
||||
checkItemPreselection.Checked = True
|
||||
|
||||
If My.Application.Globix.CURRENT_LASTDOCTYPE <> "" Then
|
||||
cmbDoctype.SelectedIndex = cmbDoctype.FindStringExact(My.Application.Globix.CURRENT_LASTDOCTYPE)
|
||||
Dim oFoundDocType = ComboBoxEdit1.Properties.Items.
|
||||
Cast(Of DocType)().
|
||||
Where(Function(dt) dt.Name = My.Application.Globix.CURRENT_LASTDOCTYPE).
|
||||
FirstOrDefault()
|
||||
If oFoundDocType IsNot Nothing Then
|
||||
ComboBoxEdit1.SelectedItem = oFoundDocType
|
||||
End If
|
||||
|
||||
|
||||
End If
|
||||
Else
|
||||
If My.Application.Globix.DTTBGI_REGEX_DOCTYPE.Rows.Count > 0 Then
|
||||
@@ -257,7 +283,14 @@ Public Class frmGlobix_Index
|
||||
|
||||
_Logger.Debug("There is a match on REGEX_DOCTYPE: [{0}]", oRoW.Item("DOCTYPE"))
|
||||
_Logger.Debug("Regex: [{0}], FileName: [{1}]", oRoW.Item("Regex"), oOnlyFilename)
|
||||
cmbDoctype.SelectedIndex = cmbDoctype.FindStringExact(oRoW.Item("DOCTYPE"))
|
||||
Dim oFoundDocType = ComboBoxEdit1.Properties.Items.
|
||||
Cast(Of DocType)().
|
||||
Where(Function(dt) dt.Name = My.Application.Globix.CURRENT_LASTDOCTYPE).
|
||||
FirstOrDefault()
|
||||
|
||||
If oFoundDocType IsNot Nothing Then
|
||||
ComboBoxEdit1.SelectedItem = oFoundDocType
|
||||
End If
|
||||
Exit For
|
||||
End If
|
||||
Next
|
||||
@@ -277,44 +310,46 @@ Public Class frmGlobix_Index
|
||||
Dim oSql = String.Format("select * from VWGI_DOCTYPE where UPPER(USERNAME) = UPPER('{0}') ORDER BY SEQUENCE", My.Application.User.UserName)
|
||||
Dim oFilter = $"USERNAME like '%{My.Application.User.UserName}%'"
|
||||
DT_DOKART = _DataASorDB.GetDatatable("DD_ECM", oSql, "VWGI_DOCTYPE", oFilter, "SEQUENCE")
|
||||
cmbDoctype.DataSource = DT_DOKART
|
||||
cmbDoctype.ValueMember = DT_DOKART.Columns("DOCTYPE_ID").ColumnName
|
||||
cmbDoctype.DisplayMember = DT_DOKART.Columns("DOCTYPE").ColumnName
|
||||
cmbDoctype.AutoCompleteMode = AutoCompleteMode.Suggest
|
||||
cmbDoctype.AutoCompleteSource = AutoCompleteSource.ListItems
|
||||
cmbDoctype.SelectedIndex = -1
|
||||
'cmbDoctype.DataSource = DT_DOKART
|
||||
'cmbDoctype.ValueMember = DT_DOKART.Columns("DOCTYPE_ID").ColumnName
|
||||
'cmbDoctype.DisplayMember = DT_DOKART.Columns("DOCTYPE").ColumnName
|
||||
'cmbDoctype.AutoCompleteMode = AutoCompleteMode.Suggest
|
||||
'cmbDoctype.AutoCompleteSource = AutoCompleteSource.ListItems
|
||||
'cmbDoctype.SelectedIndex = -1
|
||||
For Each oRow As DataRow In DT_DOKART.Rows
|
||||
ComboBoxEdit1.Properties.Items.Add(New DocType With {
|
||||
.Guid = oRow.Item("DOCTYPE_ID"),
|
||||
.Name = oRow.Item("DOCTYPE")
|
||||
})
|
||||
Next
|
||||
Catch ex As Exception
|
||||
_Logger.Warn("Unexpected error in Refresh_Dokart: " & vbNewLine & ex.Message)
|
||||
MsgBox(ex.Message, MsgBoxStyle.Critical, "Unexpected error in Laden der Dokumentarten:")
|
||||
End Try
|
||||
End Sub
|
||||
|
||||
Private Sub cmbDoctype_SelectedValueChanged(sender As Object, e As EventArgs) Handles cmbDoctype.SelectedValueChanged
|
||||
|
||||
End Sub
|
||||
Private Sub ComboBoxEdit1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBoxEdit1.SelectedIndexChanged
|
||||
If ComboBoxEdit1.SelectedIndex <> -1 And FormLoaded = True Then
|
||||
Dim oSelectedItem As DocType = ComboBoxEdit1.SelectedItem
|
||||
|
||||
Private Sub cmbDoctype_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cmbDoctype.SelectedIndexChanged
|
||||
If cmbDoctype.SelectedIndex <> -1 And FormLoaded = True Then
|
||||
If cmbDoctype.SelectedValue.GetType.ToString = "System.Int32" Then
|
||||
My.Application.Globix.CURRENT_DOCTYPE_ID = cmbDoctype.SelectedValue
|
||||
My.Application.Globix.CURRENT_DOCTYPE_ID = oSelectedItem.Guid
|
||||
|
||||
'lblhinweis.Visible = False
|
||||
ClearNotice()
|
||||
'lblhinweis.Visible = False
|
||||
ClearNotice()
|
||||
|
||||
'lblerror.Visible = False
|
||||
ClearError()
|
||||
'lblerror.Visible = False
|
||||
ClearError()
|
||||
|
||||
pnlIndex.Controls.Clear()
|
||||
Dim oSql As String = "Select * from TBDD_DOKUMENTART WHERE GUID = " & oSelectedItem.Guid
|
||||
Dim oFilter = "GUID = " & oSelectedItem.Guid
|
||||
My.Application.Globix.CURR_DT_DOCTYPE = _DataASorDB.GetDatatable("DD_ECM", oSql, "TBDD_DOKUMENTART", oFilter, "")
|
||||
|
||||
|
||||
Me.pnlIndex.Controls.Clear()
|
||||
My.Application.Globix.CURRENT_DOCTYPE_DuplicateHandling = My.Application.Globix.CURR_DT_DOCTYPE.Rows(0).Item("DUPLICATE_HANDLING").ToString
|
||||
Refresh_IndexeMan(My.Application.Globix.CURRENT_DOCTYPE_ID)
|
||||
|
||||
Dim oSql As String = "Select * from TBDD_DOKUMENTART WHERE GUID = " & cmbDoctype.SelectedValue.ToString
|
||||
Dim oFilter = "GUID = " & cmbDoctype.SelectedValue.ToString
|
||||
My.Application.Globix.CURR_DT_DOCTYPE = _DataASorDB.GetDatatable("DD_ECM", oSql, "TBDD_DOKUMENTART", oFilter, "")
|
||||
|
||||
|
||||
My.Application.Globix.CURRENT_DOCTYPE_DuplicateHandling = My.Application.Globix.CURR_DT_DOCTYPE.Rows(0).Item("DUPLICATE_HANDLING").ToString
|
||||
Refresh_IndexeMan(cmbDoctype.SelectedValue)
|
||||
End If
|
||||
|
||||
End If
|
||||
End Sub
|
||||
@@ -355,11 +390,15 @@ Public Class frmGlobix_Index
|
||||
Dim oControlCount As Integer = 1
|
||||
Dim oLabelPosition As Integer = 11
|
||||
Dim oControlPosition As Integer = 33
|
||||
Dim oControls As New GlobixControls(_LogConfig, pnlIndex, Me)
|
||||
|
||||
' Dim oControls As New GlobixControls(_LogConfig, pnlIndex, Me)
|
||||
Dim oControls As New DigitalData.GUIs.GlobalIndexer.ControlCreator(_LogConfig, pnlIndex, Me) With {
|
||||
.OnControlChanged = AddressOf PrepareDependingControl,
|
||||
.OnLookupData = AddressOf GetLookupData
|
||||
}
|
||||
_Controls = oControls
|
||||
If DT_INDEXEMAN.Rows.Count = 0 Then
|
||||
ShowError("Keine Manuellen Indizes für die " & vbNewLine & "Dokumentart " & cmbDoctype.Text & " definiert")
|
||||
_Logger.Info(" - Keine Manuellen Indizes für die " & vbNewLine & "Dokumentart " & cmbDoctype.Text & " definiert")
|
||||
ShowError("Keine Manuellen Indizes für die " & vbNewLine & "Dokumentart " & ComboBoxEdit1.Text & " definiert")
|
||||
_Logger.Info(" - Keine Manuellen Indizes für die " & vbNewLine & "Dokumentart " & ComboBoxEdit1.Text & " definiert")
|
||||
End If
|
||||
|
||||
For Each oRow As DataRow In DT_INDEXEMAN.Rows
|
||||
@@ -387,7 +426,8 @@ Public Class frmGlobix_Index
|
||||
End If
|
||||
Case "INTEGER"
|
||||
If (oSQLSuggestion = True And oRow.Item("SQL_RESULT").ToString.Length > 0) Or MultiSelect = True Then
|
||||
Dim oControl = oControls.AddVorschlag_ComboBox(oControlName, oControlPosition, oConnectionId, oRow.Item("SQL_RESULT"), MultiSelect, oDataType, oDefaultValue, AddNewItems, PreventDuplicates, oSQLSuggestion)
|
||||
|
||||
Dim oControl = oControls.AddLookupControl(oControlName, oControlPosition, MultiSelect, oDataType, oRow.Item("SQL_RESULT"), oConnectionId, oDefaultValue, AddNewItems, PreventDuplicates)
|
||||
If Not IsNothing(oControl) Then
|
||||
pnlIndex.Controls.Add(oControl)
|
||||
End If
|
||||
@@ -400,7 +440,7 @@ Public Class frmGlobix_Index
|
||||
End If
|
||||
Case "VARCHAR"
|
||||
If (oSQLSuggestion = True And oRow.Item("SQL_RESULT").ToString.Length > 0) Or MultiSelect = True Then
|
||||
Dim oControl = oControls.AddVorschlag_ComboBox(oControlName, oControlPosition, oConnectionId, oRow.Item("SQL_RESULT"), MultiSelect, oDataType, oDefaultValue, AddNewItems, PreventDuplicates, oSQLSuggestion)
|
||||
Dim oControl = oControls.AddLookupControl(oControlName, oControlPosition, MultiSelect, oDataType, oRow.Item("SQL_RESULT"), oConnectionId, oDefaultValue, AddNewItems, PreventDuplicates)
|
||||
If Not IsNothing(oControl) Then
|
||||
pnlIndex.Controls.Add(oControl)
|
||||
End If
|
||||
@@ -419,7 +459,7 @@ Public Class frmGlobix_Index
|
||||
End If
|
||||
End If
|
||||
Case "DATE"
|
||||
Dim oPicker = oControls.AddDateTimePicker(oControlName, oControlPosition, oDataType, oDefaultValue)
|
||||
Dim oPicker = oControls.AddDateTimePicker(oControlName, oControlPosition, oDataType)
|
||||
pnlIndex.Controls.Add(oPicker)
|
||||
|
||||
Case Else
|
||||
@@ -452,6 +492,122 @@ Public Class frmGlobix_Index
|
||||
MsgBox(ex.Message, MsgBoxStyle.Critical, "Unexpected error in LoadIndexe_Man:")
|
||||
End Try
|
||||
End Sub
|
||||
Private Sub PrepareDependingControl(pControl As Control)
|
||||
If TypeOf pControl Is Label Then
|
||||
Exit Sub
|
||||
End If
|
||||
|
||||
Try
|
||||
Dim oMeta = DirectCast(pControl.Tag, ControlMeta)
|
||||
Dim oIndexName As String = oMeta.IndexName
|
||||
Dim oSQL = $"SELECT * FROM TBDD_INDEX_MAN WHERE SQL_RESULT LIKE '%{oIndexName}%'"
|
||||
Dim oDatatable As DataTable = My.Database.GetDatatable(oSQL)
|
||||
|
||||
If Not IsNothing(oDatatable) Then
|
||||
_Logger.Debug("Found [{0}] depending controls for [{1}]", oDatatable.Rows.Count, pControl.Name)
|
||||
|
||||
For Each oRow As DataRow In oDatatable.Rows
|
||||
Dim oControlName As String = NotNull(oRow.Item("NAME"), "")
|
||||
Dim oConnectionId As Integer = NotNull(oRow.Item("CONNECTION_ID"), -1)
|
||||
Dim oControlSql As String = NotNull(oRow.Item("SQL_RESULT"), "")
|
||||
|
||||
If oConnectionId = -1 Or oControlSql = String.Empty Then
|
||||
_Logger.Warn("Missing SQL Query or ConnectionId for Control [{0}]! Continuing.", oControlName)
|
||||
Continue For
|
||||
End If
|
||||
|
||||
oControlSql = _Patterns.ReplaceUserValues(oControlSql, My.Application.Globix.CURRENT_DOCTYPE_ID)
|
||||
oControlSql = _Patterns.ReplaceInternalValues(oControlSql)
|
||||
oControlSql = _Patterns.ReplaceControlValues(oControlSql, pnlIndex)
|
||||
_Logger.Debug("Setting new value for [{0}]", oControlName)
|
||||
SetDependingControlResult(oControlName, oControlSql, oConnectionId)
|
||||
Next
|
||||
End If
|
||||
Catch ex As Exception
|
||||
_Logger.Error(ex)
|
||||
End Try
|
||||
End Sub
|
||||
Private Sub SetDependingControlResult(IndexName As String, pSqlCommand As String, SqlConnectionId As Integer)
|
||||
Try
|
||||
If pSqlCommand Is Nothing OrElse pSqlCommand = String.Empty Then
|
||||
_Logger.Warn("New Value for Index [{0}] could not be set. Supplied SQL is empty.")
|
||||
Exit Sub
|
||||
End If
|
||||
|
||||
Dim oConnectionString = GetConnectionString(SqlConnectionId)
|
||||
|
||||
|
||||
Dim oDatatable As DataTable = My.Database.GetDatatableWithConnection(pSqlCommand, oConnectionString)
|
||||
Dim oFoundControl As Control = Nothing
|
||||
|
||||
For Each oControl As Control In pnlIndex.Controls
|
||||
If TypeOf oControl Is Label Then
|
||||
Continue For
|
||||
End If
|
||||
|
||||
Dim oMeta = DirectCast(oControl.Tag, ControlMeta)
|
||||
Dim oIndex As String = oMeta.IndexName
|
||||
|
||||
If oIndex = IndexName Then
|
||||
oFoundControl = oControl
|
||||
Exit For
|
||||
End If
|
||||
Next
|
||||
|
||||
If oFoundControl Is Nothing Then
|
||||
_Logger.Warn("Depending Control for Index [{0}] not found!", IndexName)
|
||||
End If
|
||||
|
||||
If oDatatable Is Nothing Then
|
||||
_Logger.Warn("Error in SQL Command: {0}", pSqlCommand)
|
||||
End If
|
||||
|
||||
Select Case oFoundControl.GetType.Name
|
||||
Case GetType(DevExpress.XtraEditors.TextEdit).Name
|
||||
If oDatatable.Rows.Count > 0 Then
|
||||
Dim oFirstRow As DataRow = oDatatable.Rows.Item(0)
|
||||
|
||||
If oFirstRow.ItemArray.Length > 0 Then
|
||||
Dim oValue = oFirstRow.Item(0).ToString()
|
||||
|
||||
_Logger.Debug("Setting Value for TextEdit [{0}]: [{1}]", oFoundControl.Name, oValue)
|
||||
DirectCast(oFoundControl, DevExpress.XtraEditors.TextEdit).Text = oValue
|
||||
End If
|
||||
End If
|
||||
Case GetType(LookupControl2).Name
|
||||
_Logger.Debug("Setting Value for LookupControl [{0}]: [{1}]", oFoundControl.Name, "DATATABLE")
|
||||
DirectCast(oFoundControl, LookupControl2).DataSource = oDatatable
|
||||
Case GetType(ComboBox).Name
|
||||
_Logger.Debug("Setting Value for Combobox [{0}]: [{1}]", oFoundControl.Name, "DATATABLE")
|
||||
DirectCast(oFoundControl, ComboBox).DataSource = oDatatable
|
||||
Case Else
|
||||
_Logger.Debug("Could not set depending control result for [{0}]", oFoundControl.GetType.Name)
|
||||
End Select
|
||||
Catch ex As Exception
|
||||
_Logger.Error(ex)
|
||||
End Try
|
||||
End Sub
|
||||
Private Function GetLookupData(pLookup As LookupControl2, pSQLCommand As String, pConnectionId As Integer)
|
||||
Dim oConnectionString = GetConnectionString(pConnectionId)
|
||||
|
||||
If oConnectionString IsNot Nothing And pSQLCommand.Length > 0 Then
|
||||
_Logger.Debug("Connection String (redacted): [{0}]", oConnectionString.Substring(0, 30))
|
||||
|
||||
If _Patterns.HasComplexPatterns(pSQLCommand) Then
|
||||
_Logger.Debug(" >>sql enthält Platzhalter und wird erst während der Laufzeit gefüllt!", False)
|
||||
Return Nothing
|
||||
Else
|
||||
pSQLCommand = _Patterns.ReplaceInternalValues(pSQLCommand)
|
||||
pSQLCommand = _Patterns.ReplaceUserValues(pSQLCommand, My.Application.Globix.CURRENT_DOCTYPE_ID)
|
||||
|
||||
Dim oDatatable = My.Database.GetDatatableWithConnection(pSQLCommand, oConnectionString)
|
||||
Return oDatatable
|
||||
End If
|
||||
Else
|
||||
_Logger.Warn("Connection String for control [{0}] is empty!", pLookup.Name)
|
||||
Return Nothing
|
||||
End If
|
||||
End Function
|
||||
Function GetPlaceholderValue(InputValue As String, FileName As String, UserShortName As String) As String
|
||||
Dim oResult As String
|
||||
|
||||
@@ -702,11 +858,13 @@ Public Class frmGlobix_Index
|
||||
_Logger.Debug("Manuelle Indexe geladen")
|
||||
|
||||
If My.Application.Globix.CURR_DT_MAN_INDEXE.Rows.Count > 0 Then
|
||||
My.Application.Globix.CURRENT_DOCTYPE_ID = Me.cmbDoctype.SelectedValue
|
||||
If CheckWrite_IndexeMan(Me.cmbDoctype.SelectedValue) = True Then
|
||||
Dim oDokart As DocType = ComboBoxEdit1.SelectedItem
|
||||
My.Application.Globix.CURRENT_DOCTYPE_ID = oDokart.Guid
|
||||
|
||||
If CheckWrite_IndexeMan(ComboBoxEdit1.SelectedItem) = True Then
|
||||
'##### Manuelle Indexe indexiert #####
|
||||
_Logger.Info("Datei [" & My.Application.Globix.CURRENT_WORKFILE & "] wird nun indexiert...")
|
||||
If FillIndexe_Autom(Me.cmbDoctype.SelectedValue) = True Then
|
||||
If FillIndexe_Autom(oDokart.Guid) = True Then
|
||||
_Logger.Debug(" ...FillIndexe_Autom durchlaufen")
|
||||
|
||||
'Den Zielnamen zusammenbauen
|
||||
@@ -719,7 +877,7 @@ Public Class frmGlobix_Index
|
||||
'Die Datei verschieben
|
||||
If Move_File2_Target() = True Then
|
||||
_Logger.Debug(" ...Move_File2_Target durchlaufen")
|
||||
My.Application.Globix.CURRENT_LASTDOCTYPE = cmbDoctype.Text
|
||||
My.Application.Globix.CURRENT_LASTDOCTYPE = oDokart.Name
|
||||
_Logger.Info("Datei '" & My.Application.Globix.CURRENT_NEWFILENAME & "' erfolgreich erzeugt.")
|
||||
Dim oDEL As String = "DELETE FROM TBGI_FILES_USER WHERE GUID = " & My.Application.Globix.CURRENT_WORKFILE_GUID
|
||||
My.Database.ExecuteNonQuery(oDEL)
|
||||
|
||||
Reference in New Issue
Block a user