Files
RecordOrganizer/app/DD-Record-Organiser/ClassWindreamDocGrid.vb
2016-09-22 14:56:08 +02:00

314 lines
13 KiB
VB.net

Imports DevExpress.Utils
Imports DevExpress.XtraGrid
Imports DevExpress.XtraGrid.Columns
Imports DevExpress.XtraGrid.Views.Grid
Imports DevExpress.XtraEditors
Imports DevExpress.XtraEditors.Repository
Public Class ClassWindreamDocGrid
Public Shared RESULT_DOC_PATH As String
Public Shared RESULT_OBJECTTYPE As String
Public Shared RESULT_INWORK As Boolean
Public Shared RESULT_DOC_ID As Integer
Public Shared RESULT_DISPLAYNAME As String
Public Shared RESULT_CONFIG_IDS As Hashtable
Private Shared _dropdownValueChangedHandler As EventHandler
Private Shared _datepickerValueChangedHandler As EventHandler
Private Shared _textValueChangedHandler As EventHandler
Public Shared Sub GetDocItems(gridView As GridView)
Try
RESULT_DOC_PATH = gridView.GetFocusedRowCellValue(gridView.Columns("FULLPATH"))
Catch ex As Exception
ClassLogger.Add(">> Attention: Could not set DocVariable RESULT_DOC_PATH: " & ex.Message, False)
RESULT_DOC_PATH = Nothing
End Try
Try
RESULT_OBJECTTYPE = gridView.GetFocusedRowCellValue(gridView.Columns("OBJECTTYPE"))
Catch ex As Exception
ClassLogger.Add(">> Attention: Could not set DocVariable RESULT_OBJECTTYPE: " & ex.Message, False)
RESULT_OBJECTTYPE = ""
End Try
Try
RESULT_INWORK = gridView.GetFocusedRowCellValue(gridView.Columns("in work?"))
Catch ex As Exception
ClassLogger.Add(">> Attention: Could not set DocVariable RESULT_INWORK: " & ex.Message, False)
RESULT_INWORK = ""
End Try
Try
RESULT_DOC_ID = gridView.GetFocusedRowCellValue(gridView.Columns("DocID"))
Catch ex As Exception
ClassLogger.Add(">> Attention: Could not set DocVariable RESULT_DOC_ID: " & ex.Message, False)
RESULT_DOC_ID = Nothing
End Try
Try
RESULT_DISPLAYNAME = gridView.GetFocusedRowCellValue(gridView.Columns("Displayname"))
Catch ex As Exception
ClassLogger.Add(">> Attention: Could not set DocVariable RESULT_DISPLAYNAME: " & ex.Message, False)
RESULT_DISPLAYNAME = ""
End Try
End Sub
Public Shared Sub FillColumns(gridView As GridView, DT_RESULT As DataTable, DT_WINDREAM_RESULTLIST As DataTable, DT_DOCRESULT_DROPDOWN_ITEMS As DataTable, DropdownValueChangedHandler As EventHandler, DatepickerValueChangedHandler As EventHandler, TextValueChangedHandler As EventHandler)
' Handler speichern
_dropdownValueChangedHandler = DropdownValueChangedHandler
_datepickerValueChangedHandler = DatepickerValueChangedHandler
_textValueChangedHandler = TextValueChangedHandler
' Tabelle vor dem verändern klonen
Dim clonedTable As DataTable = DT_RESULT.Clone()
RESULT_CONFIG_IDS = New Hashtable()
' Datentypen der DataTable setzen
For Each row As DataRow In DT_WINDREAM_RESULTLIST.Rows
Dim guid As Integer = row.Item("GUID")
Dim typeID As Integer = row.Item("TYPE_ID")
Dim isVisible As Boolean = row.Item("VISIBLE")
Dim isEditable As Boolean = row.Item("EDITABLE")
Dim columnTitle As String = row.Item("HEADER_CAPTION")
RESULT_CONFIG_IDS.Add(columnTitle, guid)
' Checkbox Spalte auf Boolean setzen
If typeID = 2 And isVisible Then
Dim checkboxColumn As DataColumn = clonedTable.Columns(columnTitle)
If Not IsNothing(checkboxColumn) Then
checkboxColumn.DataType = GetType(Boolean)
End If
End If
' Datepicker Spalte auf Date setzen
If typeID = 3 And isVisible = True Then
Dim datepickerColumn As DataColumn = clonedTable.Columns(columnTitle)
If Not IsNothing(datepickerColumn) Then
'datepickerColumn.DataType = GetType(DateTime)
End If
End If
Next
' Tabelle zurückspielen und zuweisen
Try
clonedTable.Load(DT_RESULT.CreateDataReader())
DT_RESULT = clonedTable
gridView.GridControl.DataSource = DT_RESULT
Catch ex As Exception
ClassLogger.Add(">> Attention: Could not load converted datatable DocSearch: " & ex.Message, False)
End Try
gridView.Columns.Item("ICON").MaxWidth = 24
gridView.Columns.Item("ICON").MinWidth = 24
gridView.Columns.Item("FULLPATH").Visible = False
gridView.Columns.Item("OBJECTTYPE").Visible = False
gridView.Columns.Item("DocID").Visible = False
Dim created, changed As String
If USER_LANGUAGE <> "de-DE" Then
changed = "Changed"
created = "Created"
Else
changed = "Geändert"
created = "Erstellt"
End If
Dim createdColumn = gridView.Columns(created)
If Not IsNothing(createdColumn) Then
createdColumn.DisplayFormat.FormatType = FormatType.DateTime
createdColumn.DisplayFormat.FormatString = CURRENT_DATE_FORMAT & " HH:MM:ss"
End If
Dim changedColumn = gridView.Columns(changed)
If Not IsNothing(changedColumn) Then
changedColumn.DisplayFormat.FormatType = FormatType.DateTime
changedColumn.DisplayFormat.FormatString = CURRENT_DATE_FORMAT & " HH:MM:ss"
End If
' Alle Spalten aus ReadOnly setzen, danach werden alle passenden auf nicht ReadOnly gesetzt
For Each column As GridColumn In gridView.Columns
column.OptionsColumn.AllowEdit = False
Next
For Each row As DataRow In DT_WINDREAM_RESULTLIST.Rows
Dim guid As Integer = row.Item("GUID")
Dim width As Integer = row.Item("WIDTH")
Dim typeID As Integer = row.Item("TYPE_ID")
Dim isVisible As Boolean = row.Item("VISIBLE")
Dim isEditable As Boolean = row.Item("EDITABLE")
Dim columnTitle As String = row.Item("HEADER_CAPTION")
' Breite der Spalten setzen
If Not IsNothing(width) And Not IsDBNull(width) Then
Dim column = DirectCast(gridView.Columns.Item(row.Item("HEADER_CAPTION")), DevExpress.XtraGrid.Columns.GridColumn)
If Not IsNothing(column) Then
column.Width = width
End If
End If
If typeID = 1 And isVisible And isEditable Then
Dim textedit As New RepositoryItemTextEdit()
Dim value As String = ClassDatabase.Execute_Scalar("SELECT VALUE FROM TBPMO_DOC_VALUES WHERE CONFIG_ID = " & guid)
Dim col As GridColumn = gridView.Columns(columnTitle)
gridView.GridControl.RepositoryItems.Add(textedit)
'Editor zuweisen
If Not IsNothing(col) Then
col.ColumnEdit = textedit
col.OptionsColumn.AllowEdit = True
End If
' Handler zuweisen
AddHandler textedit.Leave, _textValueChangedHandler
End If
If typeID = 2 And isVisible Then
Dim checkEdit As New RepositoryItemCheckEdit()
checkEdit.ValueChecked = True
checkEdit.ValueUnchecked = False
Dim col As GridColumn = gridView.Columns(columnTitle)
gridView.GridControl.RepositoryItems.Add(checkEdit)
If Not IsNothing(col) Then
col.ColumnEdit = checkEdit
If isEditable Then
col.OptionsColumn.AllowEdit = True
Else
col.OptionsColumn.AllowEdit = False
End If
End If
End If
If typeID = 3 And isVisible And isEditable Then
Dim dateedit As New RepositoryItemDateEdit()
Dim col As GridColumn = gridView.Columns(columnTitle)
gridView.GridControl.RepositoryItems.Add(dateedit)
If Not IsNothing(col) Then
col.ColumnEdit = dateedit
col.OptionsColumn.AllowEdit = True
col.DisplayFormat.FormatType = FormatType.DateTime
col.DisplayFormat.FormatString = CURRENT_DATE_FORMAT & " HH:MM:ss"
End If
AddHandler dateedit.EditValueChanged, _datepickerValueChangedHandler
End If
If typeID = 4 And isVisible And isEditable Then
Dim dropdown As New RepositoryItemComboBox()
' Dropdown Items finden
Dim matchingRows() As DataRow = DT_DOCRESULT_DROPDOWN_ITEMS.Select(String.Format("CONFIG_ID = {0}", guid), "SEQUENCE")
' Dropdown füllen
For Each matchingRow As DataRow In matchingRows
Dim item As New WindreamDocGridComboboxItem()
item.ConfigID = matchingRow.Item("CONFIG_ID")
item.Value = matchingRow.Item("VALUE")
dropdown.Items.Add(item)
Next
' Dropdown als Editor hinzufügen
gridView.GridControl.RepositoryItems.Add(dropdown)
Dim col As GridColumn = gridView.Columns(columnTitle)
'Editor zuweisen
If Not IsNothing(col) Then
col.OptionsColumn.AllowEdit = True
col.ColumnEdit = dropdown
End If
' Handler zuweisen
AddHandler dropdown.SelectedValueChanged, _dropdownValueChangedHandler
End If
Next
End Sub
Public Class WindreamDocGridComboboxItem
Implements IConvertible
Public ConfigID As Integer
Public Value As String
Public Overrides Function ToString() As String
Return Me.Value
End Function
Public Function ToString1(provider As IFormatProvider) As String Implements IConvertible.ToString
Return Me.Value
End Function
Public Function GetTypeCode() As TypeCode Implements IConvertible.GetTypeCode
Throw New NotImplementedException
End Function
Public Function ToBoolean(provider As IFormatProvider) As Boolean Implements IConvertible.ToBoolean
Throw New NotImplementedException
End Function
Public Function ToByte(provider As IFormatProvider) As Byte Implements IConvertible.ToByte
Throw New NotImplementedException
End Function
Public Function ToChar(provider As IFormatProvider) As Char Implements IConvertible.ToChar
Throw New NotImplementedException
End Function
Public Function ToDateTime(provider As IFormatProvider) As Date Implements IConvertible.ToDateTime
Throw New NotImplementedException
End Function
Public Function ToDecimal(provider As IFormatProvider) As Decimal Implements IConvertible.ToDecimal
Throw New NotImplementedException
End Function
Public Function ToDouble(provider As IFormatProvider) As Double Implements IConvertible.ToDouble
Throw New NotImplementedException
End Function
Public Function ToInt16(provider As IFormatProvider) As Short Implements IConvertible.ToInt16
Throw New NotImplementedException
End Function
Public Function ToInt32(provider As IFormatProvider) As Integer Implements IConvertible.ToInt32
Throw New NotImplementedException
End Function
Public Function ToInt64(provider As IFormatProvider) As Long Implements IConvertible.ToInt64
Throw New NotImplementedException
End Function
Public Function ToSByte(provider As IFormatProvider) As SByte Implements IConvertible.ToSByte
Throw New NotImplementedException
End Function
Public Function ToSingle(provider As IFormatProvider) As Single Implements IConvertible.ToSingle
Throw New NotImplementedException
End Function
Public Function ToType(conversionType As Type, provider As IFormatProvider) As Object Implements IConvertible.ToType
Throw New NotImplementedException
End Function
Public Function ToUInt16(provider As IFormatProvider) As UShort Implements IConvertible.ToUInt16
Throw New NotImplementedException
End Function
Public Function ToUInt32(provider As IFormatProvider) As UInteger Implements IConvertible.ToUInt32
Throw New NotImplementedException
End Function
Public Function ToUInt64(provider As IFormatProvider) As ULong Implements IConvertible.ToUInt64
Throw New NotImplementedException
End Function
End Class
End Class