jj: add preventduplicate values and add new items to lookupGrid

This commit is contained in:
Jonathan Jenne
2018-08-23 15:28:11 +02:00
parent d352487f29
commit 433155e804
10 changed files with 440 additions and 263 deletions

View File

@@ -469,7 +469,7 @@ Public Class frmIndex
End Try
End Function
' <STAThread()> _
Private Sub AddVorschlag_ComboBox(indexname As String, y As Integer, conid As Integer, sql_Vorschlag As String, Multiselect As Boolean, Optional Vorgabe As String = "")
Private Sub AddVorschlag_ComboBox(indexname As String, y As Integer, conid As Integer, sql_Vorschlag As String, Multiselect As Boolean, Optional Vorgabe As String = "", Optional AddNewValues As Boolean = False, Optional PreventDuplicateValues As Boolean = False)
Try
Dim connectionString As String
Dim sqlCnn As SqlConnection
@@ -521,9 +521,23 @@ Public Class frmIndex
If table.Rows.Count > 0 Then
Dim columnCount = 1
' Alle bis auf die erste Spalte der Tabelle entfernen
While (table.Columns.Count > columnCount)
table.Columns.RemoveAt(columnCount)
End While
'table.Columns.Item(0).ReadOnly = True
If Multiselect Then
' Neue Spalte für Selektion einfügen
Dim selectedColumn As New DataColumn() With {
.ColumnName = "SELECTED",
.DataType = GetType(Boolean),
.DefaultValue = False
}
table.Columns.Add(selectedColumn)
' Spalte an erste Stelle verschieben
selectedColumn.SetOrdinal(0)
End If
Const LOOKUP_NO_RECORDS As String = "Keine Datensätze ausgewählt"
Const LOOKUP_N_RECORDS As String = "{0} Datensätze ausgewählt"
@@ -546,9 +560,9 @@ Public Class frmIndex
gridLookup.Size = New Size(300, LOOKUP_CONTROL_HEIGHT)
' TODO: Hier noch die Vorbelegung für Vektor Indexe einfügen
gridLookup.Properties.DataSource = Nothing
gridLookup.Properties.PopupFormSize = New Size(gridLookup.Properties.PopupFormSize.Width, 100)
gridLookup.Properties.NullText = LOOKUP_NO_RECORDS
gridLookup.Properties.DataSource = Nothing
' Da das gridLookup ein Readonly Control sein soll,
' sich aber trotzdem öffnen lassen soll, müssen wir so das setzen eines neuen Werts verhindern
@@ -566,6 +580,8 @@ Public Class frmIndex
Dim frm As New frmLookupGrid()
frm.MultiSelect = True
frm.DataSource = table
frm.AddNewValues = AddNewValues
frm.PreventDuplicates = PreventDuplicateValues
frm.StartPosition = FormStartPosition.Manual
frm.SelectedValues = gridLookup.Properties.DataSource
frm.Location = pnlIndex.PointToScreen(New Point(340, y))
@@ -587,6 +603,7 @@ Public Class frmIndex
textBox.Font = New Font(textBox.Font.FontFamily, 9)
textBox.Location = New Point(11, y)
textBox.Size = New Size(300, LOOKUP_CONTROL_HEIGHT)
textBox.ReadOnly = True
AddHandler lookupButton.Click, Sub()
Dim frm As New frmLookupGrid()
@@ -609,13 +626,10 @@ Public Class frmIndex
' Für ergebnisse die kleiner/gleich MAX_COMBOBOX_ITEMS sind
' die normale ComboBox verwenden
'If table.Rows.Count <= MAX_COMBOBOX_ITEMS Then
' 'Die Standardcombobox anlegen
' newCMB = addCombobox(indexname, y)
' newCMB.DataSource = table
' newCMB.DisplayMember = table.Columns(0).ColumnName
' newCMB.AutoCompleteSource = AutoCompleteSource.ListItems
' newCMB.AutoCompleteMode = AutoCompleteMode.Suggest
' newCMB.DropDownHeight = (newCMB.ItemHeight + 0.2) * 25
@@ -624,31 +638,6 @@ Public Class frmIndex
' newCMB.Text = Vorgabe
' Get_NextComboBoxResults(newCMB)
' End If
'Else
' Dim searchLookup As New DevExpress.XtraEditors.SearchLookUpEdit()
' searchLookup.Properties.DataSource = table
' searchLookup.Properties.DisplayMember = table.Columns(0).ColumnName
' searchLookup.Properties.ValueMember = table.Columns(0).ColumnName
' searchLookup.Location = New Point(11, y)
' searchLookup.Size = New Size(300, 27)
' searchLookup.Properties.AppearanceFocused.BackColor = Color.Lime
' searchLookup.Properties.AppearanceFocused.BackColor2 = Color.Lime
' AddHandler searchLookup.EditValueChanged, Sub(sender As Object, e As EventArgs)
' SendKeys.Send("{TAB}")
' End Sub
' If Vorgabe <> String.Empty Then
' searchLookup.EditValue = Vorgabe
' End If
' pnlIndex.Controls.Add(searchLookup)
'End If
Else
End If
@@ -890,7 +879,7 @@ Public Class frmIndex
If LogErrorsOnly = False Then ClassLogger.Add(" >> In CheckWrite_IndexeMan", False)
Dim result As Boolean = False
For Each ctrl As Control In Me.pnlIndex.Controls
' ' MsgBox(ctrl.Name)
' MsgBox(ctrl.Name)
If ctrl.Name.StartsWith("txt") Then
Dim box As TextBox = ctrl
If box.Text = "" Then
@@ -930,25 +919,25 @@ Public Class frmIndex
result = True
End If
Else
Indexwert_Postprocessing(Replace(cmbMulti.Name, "cmb", ""), cmbMulti.Text)
Indexwert_Postprocessing(Replace(cmbMulti.Name, "cmbMulti", ""), cmbMulti.Text)
result = True
End If
ElseIf ctrl.Name.StartsWith("cmbSingle") Then
Dim cmbSingle As TextBox = ctrl
If cmbSingle.Text = "" Then
Dim optional_index As Boolean = ClassDatabase.Execute_Scalar("SELECT OPTIONAL FROM TBDD_INDEX_MAN WHERE DOK_ID = " & dokartid & " AND NAME = '" & Replace(cmbSingle.Name, "cmbMulti", "") & "'", MyConnectionString, True)
Dim optional_index As Boolean = ClassDatabase.Execute_Scalar("SELECT OPTIONAL FROM TBDD_INDEX_MAN WHERE DOK_ID = " & dokartid & " AND NAME = '" & Replace(cmbSingle.Name, "cmbSingle", "") & "'", MyConnectionString, True)
If optional_index = False Then
MsgBox("Bitte wählen Sie einen Wert aus der Combobox.", MsgBoxStyle.Exclamation)
cmbSingle.Focus()
Return False
Else
Indexwert_Postprocessing(Replace(cmbSingle.Name, "cmbMulti", ""), "")
Indexwert_Postprocessing(Replace(cmbSingle.Name, "cmbSingle", ""), "")
result = True
End If
Else
Indexwert_Postprocessing(Replace(cmbSingle.Name, "cmb", ""), cmbSingle.Text)
Indexwert_Postprocessing(Replace(cmbSingle.Name, "cmbSingle", ""), cmbSingle.Text)
result = True
End If
ElseIf ctrl.Name.StartsWith("cmb") Then
@@ -984,16 +973,12 @@ Public Class frmIndex
End If
Next
Return True
Catch ex As Exception
ClassLogger.Add(" - Unvorhergesehener Fehler in CheckWrite_IndexeMan - Fehler: " & vbNewLine & ex.Message)
MsgBox(ex.Message, MsgBoxStyle.Critical, "Unerwarteter Unexpected error in CheckWrite_IndexeMan:")
Return False
End Try
End Function
Sub Indexwert_Postprocessing(indexname As String, wert_in As String)
@@ -2081,6 +2066,8 @@ Public Class frmIndex
For Each DR As DataRow In DT_INDEXEMAN.Rows
Dim type = DR.Item("DATATYPE")
Dim MultiSelect As Boolean = DR.Item("MULTISELECT")
Dim AddNewItems As Boolean = DR.Item("VKT_ADD_ITEM")
Dim PreventDuplicates As Boolean = DR.Item("VKT_PREVENT_MULTIPLE_VALUES")
If type <> "BOOLEAN" Then
addLabel(DR.Item("NAME"), DR.Item("COMMENT").ToString, ylbl, anz)
@@ -2100,7 +2087,7 @@ Public Class frmIndex
End If
Case "INTEGER"
If DR.Item("SUGGESTION") = True And DR.Item("SQL_RESULT").ToString.Length > 0 Then
AddVorschlag_ComboBox(DR.Item("NAME"), y, DR.Item("CONNECTION_ID"), DR.Item("SQL_RESULT"), MultiSelect, DefaultValue)
AddVorschlag_ComboBox(DR.Item("NAME"), y, DR.Item("CONNECTION_ID"), DR.Item("SQL_RESULT"), MultiSelect, DefaultValue, AddNewItems, PreventDuplicates)
'AddAutoSuggest_Textbox(DR.Item("NAME"), y, DR.Item("CONNECTION_ID"), DR.Item("SQL_RESULT"), DefaultValue)
Else
Dim VORBELGUNG As Integer = DefaultValue
@@ -2109,7 +2096,7 @@ Public Class frmIndex
End If
Case "VARCHAR"
If DR.Item("SUGGESTION") = True And DR.Item("SQL_RESULT").ToString.Length > 0 Then
AddVorschlag_ComboBox(DR.Item("NAME"), y, DR.Item("CONNECTION_ID"), DR.Item("SQL_RESULT"), MultiSelect, DefaultValue)
AddVorschlag_ComboBox(DR.Item("NAME"), y, DR.Item("CONNECTION_ID"), DR.Item("SQL_RESULT"), MultiSelect, DefaultValue, AddNewItems, PreventDuplicates)
'AddAutoSuggest_Textbox(DR.Item("NAME"), y, DR.Item("CONNECTION_ID"), DR.Item("SQL_RESULT"), DefaultValue)
Else
If DR.Item("NAME").ToString.ToLower = "dateiname" Then