Imports DD_LIB_Standards Imports DevExpress.Utils Imports DevExpress.XtraEditors Imports DevExpress.XtraEditors.Controls Imports DevExpress.XtraEditors.NavigatorButtons Imports DevExpress.XtraGrid Imports DevExpress.XtraGrid.Views.Base Imports DevExpress.XtraGrid.Views.Grid Imports DigitalData.Controls.LookupGrid Public Class ClassControlCreator ''' ''' Konstanten ''' Private Const DEFAULT_TEXT = "Bezeichnung definieren" Private Const DEFAULT_FONT_SIZE As Integer = 10 Private Const DEFAULT_FONT_FAMILY As String = "Arial" Private Const DEFAULT_FONT_STYLE As FontStyle = FontStyle.Regular Private Const DEFAULT_COLOR As Integer = 0 Private Const DEFAULT_WIDTH As Integer = 170 Private Const DEFAULT_HEIGHT As Integer = 20 Private Const DEFAULT_HEIGHT_TABLE As Integer = 150 Public Const PREFIX_TEXTBOX = "TXT" Public Const PREFIX_LABEL = "LBL" Public Const PREFIX_CHECKBOX = "CHK" Public Const PREFIX_COMBOBOX = "CMB" Public Const PREFIX_DATETIMEPICKER = "DTP" Public Const PREFIX_DATAGRIDVIEW = "DGV" Public Const PREFIX_TABLE = "TB" Public Const PREFIX_LINE = "LINE" ''' ''' Standard Eigenschaften für alle Controls ''' Private Class ControlDBProps Public Guid As Integer Public Name As String Public Location As Point Public [Font] As Font Public [Color] As Color End Class Private Shared Function TransformDataRow(row As DataRow) As ControlDBProps Dim x As Integer = row.Item("X_LOC") Dim y As Integer = row.Item("Y_LOC") Dim style As FontStyle = NotNull(row.Item("FONT_STYLE"), DEFAULT_FONT_STYLE) Dim size As Single = NotNull(row.Item("FONT_SIZE"), DEFAULT_FONT_SIZE) Dim familyString As String = NotNull(row.Item("FONT_FAMILY"), DEFAULT_FONT_FAMILY) Dim family As FontFamily = New FontFamily(familyString) Dim Guid As Integer = row.Item("GUID") Dim Name As String = row.Item("NAME") Dim Location As New Point(x, y) Dim Font As New Font(family, size, style, GraphicsUnit.Point) Dim Color As Color = IntToColor(NotNull(row.Item("FONT_COLOR"), DEFAULT_COLOR)) Return New ControlDBProps() With { .Guid = Guid, .Name = Name, .Location = Location, .Font = Font, .Color = Color } End Function Public Shared Function CreateBaseControl(ctrl As Control, row As DataRow, designMode As Boolean) As Control Dim props As ControlDBProps = TransformDataRow(row) ctrl.Tag = props.Guid ctrl.Name = props.Name ctrl.Location = props.Location ctrl.Font = props.Font ctrl.ForeColor = props.Color If designMode Then ctrl.Cursor = Cursors.Hand End If Return ctrl End Function ' ----------------------- NEW CONTROLS ----------------------- Public Shared Function CreateNewTextBox(location As Point) As TextBox Dim control As New TextBox With { .Name = $"{PREFIX_TEXTBOX}_{clsTools.ShortGuid()}", .Size = New Size(DEFAULT_WIDTH, DEFAULT_HEIGHT), .Location = location, .ReadOnly = True, .BackColor = Color.White, .Cursor = Cursors.Hand } Return control End Function Public Shared Function CreateNewLabel(location As Point) As Label Dim control As New Label With { .Name = $"{PREFIX_LABEL}_{clsTools.ShortGuid}", .Text = DEFAULT_TEXT, .AutoSize = True, .Location = location, .Cursor = Cursors.Hand } Return control End Function Public Shared Function CreateNewCheckbox(location As Point) As CheckBox Dim control As New CheckBox With { .Name = $"{PREFIX_CHECKBOX}_{clsTools.ShortGuid}", .AutoSize = True, .Text = DEFAULT_TEXT, .Cursor = Cursors.Hand, .Location = location } Return control End Function Public Shared Function CreateNewCombobox(location As Point) As ComboBox Dim control As New ComboBox With { .Name = $"{PREFIX_COMBOBOX}_{clsTools.ShortGuid}", .Size = New Size(DEFAULT_WIDTH, DEFAULT_HEIGHT), .Cursor = Cursors.Hand, .Location = location } Return control End Function Public Shared Function CreateNewDatetimepicker(location As Point) As DateTimePicker Dim control As New DateTimePicker With { .Name = $"{PREFIX_DATETIMEPICKER}_{clsTools.ShortGuid}", .Size = New Size(DEFAULT_WIDTH, DEFAULT_HEIGHT), .Cursor = Cursors.Hand, .Location = location, .Format = DateTimePickerFormat.Short } Return control End Function Public Shared Function CreateNewDatagridview(location As Point) As DataGridView Dim control As New DataGridView With { .Name = $"{PREFIX_DATAGRIDVIEW}_{clsTools.ShortGuid}", .Size = New Size(DEFAULT_WIDTH, DEFAULT_HEIGHT_TABLE), .Cursor = Cursors.Hand, .Location = location, .AllowUserToAddRows = False, .AllowUserToDeleteRows = False, .AllowUserToResizeColumns = False, .AllowUserToResizeRows = False } control.Columns.Add(New DataGridViewTextBoxColumn With { .HeaderText = "", .Name = "column1" }) Return control End Function Friend Shared Function CreateNewLookupControl(location As Point) As LookupControl2 Dim control As New LookupControl2 With { .Name = $"{PREFIX_DATAGRIDVIEW}_{clsTools.ShortGuid}", .Size = New Size(DEFAULT_WIDTH, DEFAULT_HEIGHT), .Cursor = Cursors.Hand, .Location = location } Return control End Function Public Shared Function CreateNewTable(location As Point) As GridControl Dim oControl As New GridControl With { .Name = $"{PREFIX_TABLE}_{clsTools.ShortGuid}", .Size = New Size(DEFAULT_WIDTH, DEFAULT_HEIGHT_TABLE), .Cursor = Cursors.Hand, .Location = location } oControl.UseEmbeddedNavigator = True oControl.ForceInitialize() Dim oView As GridView = oControl.DefaultView oView.OptionsView.ShowGroupPanel = False Dim oDatatable As New DataTable() oDatatable.Columns.Add("column1", GetType(String)) oDatatable.Columns.Add("column2", GetType(String)) oControl.DataSource = oDatatable Return oControl End Function Public Shared Function CreateNewLine(location As Point) As LineLabel Dim control As New LineLabel With { .Name = $"{PREFIX_LINE}_{clsTools.ShortGuid}", .Text = "---------------------------------", .Size = New Size(100, 5), .Location = location } Return control End Function ' ----------------------- EXISITING CONTROLS ----------------------- Public Shared Function CreateExistingTextbox(row As DataRow, designMode As Boolean) As TextBox Dim control As TextBox = CreateBaseControl(New TextBox(), row, designMode) control.BackColor = Color.White If row.Item("HEIGHT") > 27 Then control.Multiline = True End If control.Height = row.Item("HEIGHT") control.Width = row.Item("WIDTH") If Not designMode Then control.AcceptsReturn = True control.ReadOnly = row.Item("READ_ONLY") control.TabStop = Not row.Item("READ_ONLY") Else control.ReadOnly = True End If Return control End Function Public Shared Function CreateExistingLabel(row As DataRow, designMode As Boolean) As Label Dim control As Label = CreateBaseControl(New Label(), row, designMode) control.Text = row.Item("CTRL_TEXT") control.AutoSize = True Return control End Function Public Shared Function CreateExistingCombobox(row As DataRow, designMode As Boolean) As Windows.Forms.ComboBox Dim control As Windows.Forms.ComboBox = CreateBaseControl(New Windows.Forms.ComboBox(), row, designMode) control.Size = New Size(row.Item("WIDTH"), row.Item("HEIGHT")) If Not designMode Then control.Enabled = Not row.Item("READ_ONLY") control.TabStop = Not row.Item("READ_ONLY") control.AutoCompleteMode = AutoCompleteMode.SuggestAppend control.AutoCompleteSource = AutoCompleteSource.ListItems End If Return control End Function Public Shared Function CreateExistingDatepicker(row As DataRow, designMode As Boolean) As DateTimePicker Dim control As DateTimePicker = CreateBaseControl(New DateTimePicker(), row, designMode) control.Size = New Size(row.Item("WIDTH"), row.Item("HEIGHT")) control.Format = DateTimePickerFormat.Short If Not designMode Then control.Enabled = Not row.Item("READ_ONLY") control.TabStop = Not row.Item("READ_ONLY") End If Return control End Function Public Shared Function CreateExisingCheckbox(row As DataRow, designMode As Boolean) As CheckBox Dim control As CheckBox = CreateBaseControl(New CheckBox(), row, designMode) control.AutoSize = True control.Text = row.Item("CTRL_TEXT") If Not designMode Then control.Enabled = Not row.Item("READ_ONLY") control.TabStop = Not row.Item("READ_ONLY") End If Return control End Function Public Shared Function CreateExistingDataGridView(row As DataRow, designMode As Boolean) As DataGridView Dim control As DataGridView = CreateBaseControl(New DataGridView(), row, designMode) control.Size = New Size(row.Item("WIDTH"), row.Item("HEIGHT")) control.AllowUserToAddRows = False control.AllowUserToDeleteRows = False control.AllowUserToResizeColumns = False control.AllowUserToResizeRows = False control.AlternatingRowsDefaultCellStyle.BackColor = Color.Aqua Dim col As New DataGridViewTextBoxColumn col.HeaderText = "" col.Name = "column1" col.Width = control.Width - 30 control.Columns.Add(col) If Not designMode Then control.Enabled = Not row.Item("READ_ONLY") control.TabStop = Not row.Item("READ_ONLY") End If Return control End Function Public Shared Function CreateExistingLookupControl(row As DataRow, designMode As Boolean) As LookupControl2 Dim control As LookupControl2 = CreateBaseControl(New LookupControl2(), row, designMode) control.Width = row.Item("WIDTH") If designMode Then control.Cursor = Cursors.Hand End If Return control End Function Public Shared Function CreateExistingTable(row As DataRow, columns As List(Of DD_DMSLiteDataSet.TBPM_CONTROL_TABLERow), designMode As Boolean) As GridControl Dim oControl As GridControl = CreateBaseControl(New GridControl(), row, designMode) Dim oDatatable As New DataTable Dim oView As GridView oControl.ForceInitialize() oView = oControl.DefaultView oView.OptionsView.ShowGroupPanel = False If Not designMode Then oView.OptionsBehavior.Editable = Not row.Item("READ_ONLY") oView.OptionsBehavior.ReadOnly = row.Item("READ_ONLY") If row.Item("VKT_ADD_ITEM") = True Then oView.OptionsBehavior.AllowAddRows = DefaultBoolean.True oView.OptionsView.NewItemRowPosition = NewItemRowPosition.Bottom Else oView.OptionsBehavior.AllowAddRows = DefaultBoolean.False oView.OptionsView.NewItemRowPosition = NewItemRowPosition.None End If End If oControl.Size = New Size(row.Item("WIDTH"), row.Item("HEIGHT")) ' Add and configure navigator to delete rows oControl.UseEmbeddedNavigator = True With oControl.EmbeddedNavigator.Buttons .CancelEdit.Visible = False .Edit.Visible = False .EndEdit.Visible = False .First.Visible = False .Last.Visible = False .Next.Visible = False .NextPage.Visible = False .PrevPage.Visible = False .Prev.Visible = False End With For Each oRow As DD_DMSLiteDataSet.TBPM_CONTROL_TABLERow In columns Dim oColumn = New DataColumn() With { .DataType = GetType(String), .ColumnName = oRow.SPALTENNAME, .Caption = oRow.SPALTEN_HEADER, .ReadOnly = False } oDatatable.Columns.Add(oColumn) Next oControl.DataSource = oDatatable AddHandler oView.CellValueChanged, Function(sender As Object, e As CellValueChangedEventArgs) ' TODO: Do the validation End Function Return oControl End Function Public Shared Function CreateExistingLine(row As DataRow, designMode As Boolean) As LineLabel Dim control As LineLabel = CreateBaseControl(New LineLabel(), row, designMode) control.Text = "------------------------------" control.BorderStyle = BorderStyle.None control.AutoSize = False control.BackColor = IntToColor(NotNull(row.Item("FONT_COLOR"), DEFAULT_COLOR)) control.Size = New Size(row.Item("WIDTH"), row.Item("HEIGHT")) Return control End Function ' ----------------------- CUSTOM LABEL/LINE CLASS ----------------------- Public Class LineLabel Inherits Label Protected Overrides Sub OnPaint(e As PaintEventArgs) 'MyBase.OnPaint(e) Dim size As New Size(e.ClipRectangle.Width, 2) Dim rect As New Rectangle(New Point(0, 0), size) 'ControlPaint.DrawBorder(e.Graphics, rect, Me.ForeColor, ButtonBorderStyle.Solid) e.Graphics.DrawLine(New Pen(ForeColor, 100), New Point(0, 0), New Point(e.ClipRectangle.Width, 2)) End Sub End Class Public Shared Function GET_CONTROL_PROPERTIES(DT_CONTROL As DataTable, ControlName As String) Try CURRENT_CONTROL_ID = 0 CURR_CON_ID = 0 CURR_SELECT_CONTROL = "" CURR_CHOICE_LIST = "" Dim dt As New DataTable dt = DT_CONTROL ' Define the filter Dim filter As String = "NAME = '" & ControlName & "'" ' Filter the rows using Select() method of DataTable Dim FilteredRows As DataRow() = dt.Select(filter) If FilteredRows.Count = 1 Then For Each row As DataRow In FilteredRows CURRENT_CONTROL_ID = row("GUID") CURR_CON_ID = IIf(IsDBNull(row("CONNECTION_ID")), 0, row("CONNECTION_ID")) If CURR_CON_ID = 0 Then LOGGER.Info(" >> CONNECTION NOT DEFINED - CTRL_GUID:" & CURRENT_CONTROL_ID, False) End If CURR_SELECT_CONTROL = IIf(IsDBNull(row("SQL_UEBERPRUEFUNG")), "", row("SQL_UEBERPRUEFUNG")) CURR_CHOICE_LIST = IIf(IsDBNull(row("CHOICE_LIST")), "", row("CHOICE_LIST")) Next Return 1 Else Return 0 End If Catch ex As Exception LOGGER.Error(ex) LOGGER.Info("Unexpected Error in GET_CONTROL_PROPERTIES (" & ControlName & "):" & ex.Message) Return 0 End Try End Function Public Shared Function GET_DEPENDING_CONTROLS(DT_CONTROLS As DataTable, ControlName As String) Try Dim dt As New DataTable dt = DT_CONTROLS ' Define the filter Dim filter As String = String.Format("SQL_UEBERPRUEFUNG LIKE '%{0}%'", ControlName) Dim FilteredRows As DataRow() = dt.Select(filter) CURR_DT_DEPENDING_CONTROLS = Nothing If FilteredRows.Length > 0 Then CURR_DT_DEPENDING_CONTROLS = FilteredRows.CopyToDataTable End If Return True Catch ex As Exception LOGGER.Error(ex) LOGGER.Info("Unexpected Error in GET_DEPENDING_CONTROLS (" & ControlName & "):" & ex.Message) Return 0 End Try End Function Public Shared Function GET_CONNECTION_INFO(CON_ID As Integer) Try Dim dt As New DataTable dt = CURRENT_DT_TBDD_CONNECTION ' Define the filter Dim filter As String = "GUID = " & CON_ID ' Filter the rows using Select() method of DataTable Dim FilteredRows As DataRow() = dt.Select(filter) If FilteredRows.Count = 1 Then Return FilteredRows Else Return Nothing End If Catch ex As Exception LOGGER.Error(ex) LOGGER.Info("Unexpected Error in GET_CONNECTION_INFO (" & CON_ID.ToString & "):" & ex.Message) Return Nothing End Try End Function End Class