Trim values from user on save

This commit is contained in:
Jonathan Jenne 2021-11-01 10:47:09 +01:00
parent f71b53b5c3
commit 00165025f6

View File

@ -10,8 +10,13 @@ Imports DigitalData.Modules.Language
Imports DevExpress.XtraEditors.Controls Imports DevExpress.XtraEditors.Controls
Imports System.Globalization Imports System.Globalization
Imports DevExpress.XtraEditors Imports DevExpress.XtraEditors
Imports DigitalData.Modules.Logging
Public Class frmRowEditor Public Class frmRowEditor
Private ReadOnly LogConfig As LogConfig
Private ReadOnly Logger As Logger
Private ReadOnly FormHelper As FormHelper
Private ReadOnly _Columns As List(Of String) Private ReadOnly _Columns As List(Of String)
Private ReadOnly _DataTable As New DataTable Private ReadOnly _DataTable As New DataTable
Private ReadOnly _Accounts As List(Of Account) Private ReadOnly _Accounts As List(Of Account)
@ -40,10 +45,14 @@ Public Class frmRowEditor
End Get End Get
End Property End Property
Public Sub New(pColumns As List(Of String), pDocumentRow As DocumentRow, pMandator As Mandator, pWinline As Data) Public Sub New(pLogConfig As LogConfig, pColumns As List(Of String), pDocumentRow As DocumentRow, pMandator As Mandator, pWinline As Data)
' Dieser Aufruf ist für den Designer erforderlich. ' Dieser Aufruf ist für den Designer erforderlich.
InitializeComponent() InitializeComponent()
LogConfig = pLogConfig
Logger = pLogConfig.GetLogger()
FormHelper = New FormHelper(pLogConfig)
_Columns = pColumns _Columns = pColumns
_Accounts = pWinline.Accounts.Where(Function(a) a.Mandator.Id = pMandator.Id).ToList() _Accounts = pWinline.Accounts.Where(Function(a) a.Mandator.Id = pMandator.Id).ToList()
_Articles = pWinline.Articles.Where(Function(a) a.Mandator.Id = pMandator.Id).ToList() _Articles = pWinline.Articles.Where(Function(a) a.Mandator.Id = pMandator.Id).ToList()
@ -119,41 +128,47 @@ Public Class frmRowEditor
End Sub End Sub
Private Sub btnSave_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnSave.ItemClick Private Sub btnSave_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnSave.ItemClick
GridView1.CloseEditor() Try
GridView1.CloseEditor()
For Each oRow As DataRow In _DataTable.Rows For Each oRow As DataRow In _DataTable.Rows
Dim oField = _DocumentRow.Fields. Dim oField = _DocumentRow.Fields.
Where(Function(f) f.Key = oRow.Item(COL_KEY)). Where(Function(f) f.Key = oRow.Item(COL_KEY)).
SingleOrDefault() SingleOrDefault()
If oField.Key Is Nothing Then If oField.Key Is Nothing Then
oField = New KeyValuePair(Of String, FieldValue)(oRow.Item(COL_KEY), New FieldValue()) oField = New KeyValuePair(Of String, FieldValue)(oRow.Item(COL_KEY), New FieldValue())
End If
Dim oFieldValue As FieldValue = oField.Value
Dim oGridValue As String = Utils.NotNull(oRow.Item(COL_VALUE_FINAL), String.Empty)
If oField.Key = "Datum_Auftrag-Bestellung" And oGridValue.Length > 0 Then
If TryParseDate(oGridValue) Is Nothing Then
MsgBox(String.Format(My.Resources.frmRowEditorExtra.Datumswert_für___0___enthält_einen_ungüligen_Wert, oField.Key), MsgBoxStyle.Exclamation, Text)
Exit Sub
End If End If
End If
If Not oFieldValue.Final.Equals(oGridValue) Then Dim oFieldValue As FieldValue = oField.Value
oFieldValue.Final = Utils.NotNull(oRow.Item(COL_VALUE_FINAL), String.Empty) Dim oGridValue As String = Utils.NotNull(oRow.Item(COL_VALUE_FINAL), String.Empty)
If _DocumentRow.Fields.ContainsKey(oField.Key) Then If oField.Key = "Datum_Auftrag-Bestellung" And oGridValue.Length > 0 Then
_DocumentRow.Fields.Item(oField.Key) = oFieldValue If TryParseDate(oGridValue) Is Nothing Then
Else MsgBox(String.Format(My.Resources.frmRowEditorExtra.Datumswert_für___0___enthält_einen_ungüligen_Wert, oField.Key), MsgBoxStyle.Exclamation, Text)
_DocumentRow.Fields.Add(oField.Key, oFieldValue) Exit Sub
End If
End If End If
End If
Next If Not oFieldValue.Final.Equals(oGridValue) Then
Dim oValue = Utils.NotNull(oRow.Item(COL_VALUE_FINAL), String.Empty).ToString
oFieldValue.Final = oValue.Trim()
DialogResult = DialogResult.OK If _DocumentRow.Fields.ContainsKey(oField.Key) Then
Close() _DocumentRow.Fields.Item(oField.Key) = oFieldValue
Else
_DocumentRow.Fields.Add(oField.Key, oFieldValue)
End If
End If
Next
DialogResult = DialogResult.OK
Close()
Catch ex As Exception
MsgBox("")
Logger.Error(ex)
End Try
End Sub End Sub
Private Function TryParseDate(pValue As String) Private Function TryParseDate(pValue As String)