Support for Regex Validation in Grid Columns

This commit is contained in:
Jonathan Jenne 2021-10-01 15:00:42 +02:00
parent 03e87efedc
commit 75d1ceb3de
3 changed files with 27 additions and 9 deletions

View File

@ -1,4 +1,5 @@
Imports System.ComponentModel
Imports System.Text.RegularExpressions
Imports DD_LIB_Standards
Imports DevExpress.Utils
Imports DevExpress.XtraEditors
@ -584,10 +585,30 @@ Public Class ClassControlCreator
Dim oIsRequired = oColumn.Item("VALIDATION")
Dim oValue = NotNull(oView.GetRowCellValue(e.RowHandle, oCol.ColumnName), "")
Try
Dim oRegex = NotNull(oColumn.Item("REGEX_MATCH"), String.Empty)
Dim oRegexMessage = NotNull(oColumn.Item("REGEX_MESSAGE_DE"), String.Empty)
If oRegex <> String.Empty Then
Dim oMatch = New Regex(oRegex).IsMatch(oValue)
Dim oDefaultMessage = "Wert entspricht nicht dem gefordertem Format!"
Dim oMessage = IIf(oRegexMessage <> String.Empty, oRegexMessage, oDefaultMessage)
If oMatch = False Then
oView.SetColumnError(oGridColumn, oMessage)
e.Valid = False
Exit For
End If
End If
Catch ex As Exception
LOGGER.Error(ex)
End Try
If oIsRequired And oValue = "" Then
oView.SetColumnError(oGridColumn, "Spalte muss ausgefüllt werden!")
e.Valid = False
Exit For
End If
Next
End Sub

View File

@ -279,7 +279,6 @@ Partial Class frmControl_Detail
resources.ApplyResources(Me.REGEX_MATCHTextBox, "REGEX_MATCHTextBox")
Me.REGEX_MATCHTextBox.MenuManager = Me.RibbonControl1
Me.REGEX_MATCHTextBox.Name = "REGEX_MATCHTextBox"
Me.REGEX_MATCHTextBox.Properties.ReadOnly = True
Me.REGEX_MATCHTextBox.StyleController = Me.LayoutControl1
'
'SimpleButton1
@ -294,7 +293,6 @@ Partial Class frmControl_Detail
resources.ApplyResources(Me.REGEX_MESSAGE_DETextBox, "REGEX_MESSAGE_DETextBox")
Me.REGEX_MESSAGE_DETextBox.MenuManager = Me.RibbonControl1
Me.REGEX_MESSAGE_DETextBox.Name = "REGEX_MESSAGE_DETextBox"
Me.REGEX_MESSAGE_DETextBox.Properties.ReadOnly = True
Me.REGEX_MESSAGE_DETextBox.StyleController = Me.LayoutControl1
'
'SQL_COMMANDTextBox

View File

@ -119,14 +119,13 @@ Public Class frmControl_Detail
End Sub
Private Sub SimpleButton1_Click(sender As Object, e As EventArgs) Handles SimpleButton1.Click
'TODO: Enable when regexes are implemented
'Dim oForm As New frmRegexEditor()
'oForm.RegexString = REGEX_MATCHTextBox.Text
Dim oForm As New frmRegexEditor()
oForm.RegexString = REGEX_MATCHTextBox.Text
'Dim oResult = oForm.ShowDialog()
'If oResult = DialogResult.OK Then
' REGEX_MATCHTextBox.Text = oForm.RegexString
'End If
Dim oResult = oForm.ShowDialog()
If oResult = DialogResult.OK Then
REGEX_MATCHTextBox.Text = oForm.RegexString
End If
End Sub
Private Sub SimpleButton2_Click(sender As Object, e As EventArgs) Handles SimpleButton2.Click