From 7a166c1f3a5f6be6a6f23b92ee9f7ce019cf5499 Mon Sep 17 00:00:00 2001 From: Jonathan Jenne Date: Thu, 17 Oct 2019 15:54:36 +0200 Subject: [PATCH] load textbox if combobox is readonly in mass validator --- app/DD_PM_WINDREAM/frmMassValidator.vb | 261 +++++++++++++------------ 1 file changed, 135 insertions(+), 126 deletions(-) diff --git a/app/DD_PM_WINDREAM/frmMassValidator.vb b/app/DD_PM_WINDREAM/frmMassValidator.vb index 3fe5da7..0525954 100644 --- a/app/DD_PM_WINDREAM/frmMassValidator.vb +++ b/app/DD_PM_WINDREAM/frmMassValidator.vb @@ -135,7 +135,7 @@ Public Class frmMassValidator Dim oCount = 0 For Each oControlRow As DataRow In DTCONTROLS.Rows - Dim ctrl As Control + Dim oControl As Control Select Case oControlRow.Item("CTRL_TYPE").ToString.ToUpper Case "TXT" @@ -146,161 +146,170 @@ Public Class frmMassValidator AddHandler txt.LostFocus, AddressOf OnTextBoxLostFocus AddHandler txt.KeyUp, AddressOf OnTextBoxKeyUp - ctrl = txt + oControl = txt Case "LBL" LOGGER.Debug("Versuch LBL zu laden") - ctrl = ClassControlCreator.CreateExistingLabel(oControlRow, False) + oControl = ClassControlCreator.CreateExistingLabel(oControlRow, False) Case "CMB" LOGGER.Debug("Versuch CMB zu laden") - Dim cmb = ClassControlCreator.CreateExistingCombobox(oControlRow, False) + If oControlRow.Item("READ_ONLY") Then + Dim cmbReadonly = ClassControlCreator.CreateExistingTextbox(oControlRow, False) + oControl = cmbReadonly + Else + Dim cmb = ClassControlCreator.CreateExistingCombobox(oControlRow, False) - AddHandler cmb.SelectedValueChanged, AddressOf OnCmbselectedIndex + AddHandler cmb.SelectedValueChanged, AddressOf OnCmbselectedIndex #Region "CONTROL LIST" - If ClassControlCreator.GET_CONTROL_PROPERTIES(DTCONTROLS, cmb.Name) = 0 Then - MsgBox("Unexpected Error in getting control-properties (CMB load) - Check the log and inform Your sysadmin!", MsgBoxStyle.Critical) - Exit Sub - End If - Dim CURR_SQL_PROVIDER As String - If CURRENT_CONTROL_ID > 0 Then - If CURR_CON_ID > 0 Then - Dim commandsql = CURR_SELECT_CONTROL - If commandsql <> "" Then - LOGGER.Debug("ConID > 0 And commandsql <> ''") - Dim connectionString As String - - Dim ConRow As DataRow() = ClassControlCreator.GET_CONNECTION_INFO(CURR_CON_ID) - If ConRow Is Nothing Then - MsgBox("Unexpected Error in getting Coninfo (CMB load) - Check the log and inform Your sysadmin!", MsgBoxStyle.Critical) - Exit Sub - End If - - For Each row As DataRow In ConRow - Select Case row("SQL_PROVIDER").ToString.ToLower - Case "ms-sql" - CURR_SQL_PROVIDER = "ms-sql" - If row("USERNAME") = "WINAUTH" Then - connectionString = "Data Source=" & row("SERVER") & ";Initial Catalog=" & row("DATENBANK") & ";Trusted_Connection=True;" - Else - connectionString = "Data Source=" & row("SERVER") & ";Initial Catalog= " & row("DATENBANK") & ";User Id=" & row("USERNAME") & ";Password=" & row("PASSWORD") & ";" - End If - LOGGER.Debug("ConnString Sql-Server: " & connectionString) - Case "oracle" - CURR_SQL_PROVIDER = "oracle" - Dim conn As New OracleConnectionStringBuilder - Dim connstr As String - If row("SERVER") <> "" And row("DATENBANK").GetType.ToString <> "system.dbnull" Then - connstr = "Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=" & row("SERVER") & ")(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=" & - row("DATENBANK") & ")));User Id=" & row("USERNAME") & ";Password=" & row("PASSWORD") & ";" - Else - conn.DataSource = row("SERVER") - conn.UserID = row("USERNAME") - conn.Password = row("PASSWORD") - conn.PersistSecurityInfo = True - conn.ConnectionTimeout = 120 - connstr = conn.ConnectionString - End If + If ClassControlCreator.GET_CONTROL_PROPERTIES(DTCONTROLS, cmb.Name) = 0 Then + MsgBox("Unexpected Error in getting control-properties (CMB load) - Check the log and inform Your sysadmin!", MsgBoxStyle.Critical) + Exit Sub + End If + Dim CURR_SQL_PROVIDER As String + If CURRENT_CONTROL_ID > 0 Then + If CURR_CON_ID > 0 Then + Dim commandsql = CURR_SELECT_CONTROL + If commandsql <> "" Then + LOGGER.Debug("ConID > 0 And commandsql <> ''") + Dim connectionString As String + + Dim ConRow As DataRow() = ClassControlCreator.GET_CONNECTION_INFO(CURR_CON_ID) + If ConRow Is Nothing Then + MsgBox("Unexpected Error in getting Coninfo (CMB load) - Check the log and inform Your sysadmin!", MsgBoxStyle.Critical) + Exit Sub + End If - connectionString = connstr - Case Else - LOGGER.Info("ConnectionString-Type not integrated") - MsgBox("ConnectionString-Type not integrated", MsgBoxStyle.Critical) - Exit Sub - End Select + For Each row As DataRow In ConRow + Select Case row("SQL_PROVIDER").ToString.ToLower + Case "ms-sql" + CURR_SQL_PROVIDER = "ms-sql" + If row("USERNAME") = "WINAUTH" Then + connectionString = "Data Source=" & row("SERVER") & ";Initial Catalog=" & row("DATENBANK") & ";Trusted_Connection=True;" + Else + connectionString = "Data Source=" & row("SERVER") & ";Initial Catalog= " & row("DATENBANK") & ";User Id=" & row("USERNAME") & ";Password=" & row("PASSWORD") & ";" + End If + LOGGER.Debug("ConnString Sql-Server: " & connectionString) + Case "oracle" + CURR_SQL_PROVIDER = "oracle" + Dim conn As New OracleConnectionStringBuilder + Dim connstr As String + If row("SERVER") <> "" And row("DATENBANK").GetType.ToString <> "system.dbnull" Then + connstr = "Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=" & row("SERVER") & ")(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=" & + row("DATENBANK") & ")));User Id=" & row("USERNAME") & ";Password=" & row("PASSWORD") & ";" + Else + conn.DataSource = row("SERVER") + conn.UserID = row("USERNAME") + conn.Password = row("PASSWORD") + conn.PersistSecurityInfo = True + conn.ConnectionTimeout = 120 + connstr = conn.ConnectionString + End If + + connectionString = connstr + Case Else + LOGGER.Info("ConnectionString-Type not integrated") + MsgBox("ConnectionString-Type not integrated", MsgBoxStyle.Critical) + Exit Sub + End Select - Next + Next - If connectionString Is Nothing = False And CURR_SQL_PROVIDER = "ms-sql" Then - Try - Dim sqlCnn As SqlClient.SqlConnection - Dim sqlCmd As SqlClient.SqlCommand - Dim adapter As New SqlClient.SqlDataAdapter - Dim NewDataset As New DataSet - Dim i As Integer - - - 'sql = ClassPatterns.ReplaceAllValues(sql, pnldesigner, aktivesDokument) - If clsPatterns.HasOnlySimplePatterns(CURR_SELECT_CONTROL) Then - CURR_SELECT_CONTROL = clsPatterns.ReplaceInternalValues(CURR_SELECT_CONTROL) - CURR_SELECT_CONTROL = clsPatterns.ReplaceControlValues(CURR_SELECT_CONTROL, pnldesigner) - - sqlCnn = New SqlClient.SqlConnection(connectionString) - ' Try - sqlCnn.Open() - sqlCmd = New SqlClient.SqlCommand(CURR_SELECT_CONTROL, sqlCnn) - adapter.SelectCommand = sqlCmd - adapter.Fill(NewDataset) - - For i = 0 To NewDataset.Tables(0).Rows.Count - 1 - cmb.Items.Add(NewDataset.Tables(0).Rows(i).Item(0)) - Next - adapter.Dispose() - sqlCmd.Dispose() - sqlCnn.Close() - End If - Catch ex As Exception - LOGGER.Error(ex) - LOGGER.Info("Unexpected Error in running depending sql-command: " & ex.Message) - Clipboard.SetText("Error: " & ex.Message & vbNewLine & "SQL: " & CURR_SELECT_CONTROL) - MsgBox(ex.Message, MsgBoxStyle.Critical, "Unexpected Error in running depending sql-command:") - End Try + If connectionString Is Nothing = False And CURR_SQL_PROVIDER = "ms-sql" Then + Try + Dim sqlCnn As SqlClient.SqlConnection + Dim sqlCmd As SqlClient.SqlCommand + Dim adapter As New SqlClient.SqlDataAdapter + Dim NewDataset As New DataSet + Dim i As Integer + + + 'sql = ClassPatterns.ReplaceAllValues(sql, pnldesigner, aktivesDokument) + If clsPatterns.HasOnlySimplePatterns(CURR_SELECT_CONTROL) Then + CURR_SELECT_CONTROL = clsPatterns.ReplaceInternalValues(CURR_SELECT_CONTROL) + CURR_SELECT_CONTROL = clsPatterns.ReplaceControlValues(CURR_SELECT_CONTROL, pnldesigner) + + sqlCnn = New SqlClient.SqlConnection(connectionString) + ' Try + sqlCnn.Open() + sqlCmd = New SqlClient.SqlCommand(CURR_SELECT_CONTROL, sqlCnn) + adapter.SelectCommand = sqlCmd + adapter.Fill(NewDataset) + + For i = 0 To NewDataset.Tables(0).Rows.Count - 1 + cmb.Items.Add(NewDataset.Tables(0).Rows(i).Item(0)) + Next + adapter.Dispose() + sqlCmd.Dispose() + sqlCnn.Close() + End If + Catch ex As Exception + LOGGER.Error(ex) + LOGGER.Info("Unexpected Error in running depending sql-command: " & ex.Message) + Clipboard.SetText("Error: " & ex.Message & vbNewLine & "SQL: " & CURR_SELECT_CONTROL) + MsgBox(ex.Message, MsgBoxStyle.Critical, "Unexpected Error in running depending sql-command:") + End Try + End If + Else + LOGGER.Debug("Else Row 571") End If Else - LOGGER.Debug("Else Row 571") - End If - Else - If CURR_CHOICE_LIST <> "" Then - LOGGER.Debug("In add_ComboBox - AListe: " & CURR_CHOICE_LIST) - Dim liste = WINDREAM.GetValuesfromAuswahlliste(CURR_CHOICE_LIST) - If liste IsNot Nothing Then - cmb.Items.Add("") - For Each index As String In liste - cmb.Items.Add(index) - Next - cmb.SelectedIndex = -1 - Else - MsgBox("Resultliste windream is nothing!", MsgBoxStyle.Exclamation, CURR_CHOICE_LIST) + If CURR_CHOICE_LIST <> "" Then + LOGGER.Debug("In add_ComboBox - AListe: " & CURR_CHOICE_LIST) + Dim liste = WINDREAM.GetValuesfromAuswahlliste(CURR_CHOICE_LIST) + If liste IsNot Nothing Then + cmb.Items.Add("") + For Each index As String In liste + cmb.Items.Add(index) + Next + cmb.SelectedIndex = -1 + Else + MsgBox("Resultliste windream is nothing!", MsgBoxStyle.Exclamation, CURR_CHOICE_LIST) + End If End If End If End If - End If #End Region - Dim maxWith As Integer = cmb.Width - Using g As Graphics = Me.CreateGraphics - For Each oItem As Object In cmb.Items 'Für alle Einträge... - Dim g1 As Graphics = cmb.CreateGraphics - If g1.MeasureString(Text, cmb.Font).Width + 30 > maxWith Then - maxWith = g1.MeasureString(Text, cmb.Font).Width + 30 - End If - g1.Dispose() - Next oItem - End Using - cmb.DropDownWidth = maxWith + Dim maxWith As Integer = cmb.Width + Using g As Graphics = Me.CreateGraphics + For Each oItem As Object In cmb.Items 'Für alle Einträge... + Dim g1 As Graphics = cmb.CreateGraphics + If g1.MeasureString(Text, cmb.Font).Width + 30 > maxWith Then + maxWith = g1.MeasureString(Text, cmb.Font).Width + 30 + End If + g1.Dispose() + Next oItem + End Using + cmb.DropDownWidth = maxWith + + oControl = cmb + End If + + + - ctrl = cmb Case "DTP" LOGGER.Debug("Versuch DTP zu laden") - ctrl = ClassControlCreator.CreateExistingDatepicker(oControlRow, False) + oControl = ClassControlCreator.CreateExistingDatepicker(oControlRow, False) Case "DGV" LOGGER.Debug("Versuch DGV zu laden") Dim dgv = ClassControlCreator.CreateExistingDataGridView(oControlRow, False) AddHandler dgv.RowValidating, AddressOf onDGVRowValidating - ctrl = dgv + oControl = dgv Case "CHK" LOGGER.Debug("Versuch Checkbox zu laden") - ctrl = ClassControlCreator.CreateExisingCheckbox(oControlRow, False) + oControl = ClassControlCreator.CreateExisingCheckbox(oControlRow, False) Case "LINE" LOGGER.Debug("Versuch Linie zu laden") - ctrl = ClassControlCreator.CreateExistingLine(oControlRow, False) + oControl = ClassControlCreator.CreateExistingLine(oControlRow, False) Case "LOOKUP" Dim lookup As LookupControl2 = ClassControlCreator.CreateExistingLookupControl(oControlRow, False) - ctrl = lookup + oControl = lookup lookup.PreventDuplicates = oControlRow.Item("VKT_PREVENT_MULTIPLE_VALUES") lookup.AllowAddNewValues = oControlRow.Item("VKT_ADD_ITEM") lookup.MultiSelect = oControlRow.Item("MULTISELECT") @@ -312,7 +321,7 @@ Public Class frmMassValidator ''Wenn Multiselect false dann prüfen ob abhängiges Control If CBool(oControlRow.Item("MULTISELECT")) = False Then Dim filteredData As DataTable = DTCONTROLS.Clone() - Dim oExpression = $"SQL_UEBERPRUEFUNG like '%#CTRL#{ctrl.Name}%'" + Dim oExpression = $"SQL_UEBERPRUEFUNG like '%#CTRL#{oControl.Name}%'" DTCONTROLS.Select(oExpression).CopyToDataTable(filteredData, LoadOption.PreserveChanges) If filteredData.Rows.Count = 1 Then AddHandler lookup.SelectedValuesChanged, AddressOf onLookUp1 @@ -329,14 +338,14 @@ Public Class frmMassValidator Where r.CONTROL_ID = oControlRow.Item("GUID") Select r).ToList() - ctrl = ClassControlCreator.CreateExistingGridControl(oControlRow, columns, False) + oControl = ClassControlCreator.CreateExistingGridControl(oControlRow, columns, False) End Select - If ctrl IsNot Nothing AndAlso TypeOf ctrl IsNot Label Then - ctrl.TabIndex = oCount + If oControl IsNot Nothing AndAlso TypeOf oControl IsNot Label Then + oControl.TabIndex = oCount End If - pnldesigner.Controls.Add(ctrl) + pnldesigner.Controls.Add(oControl) oCount += 1 Next