Use FormHelper to show error messages

This commit is contained in:
Jonathan Jenne 2021-11-01 10:45:53 +01:00
parent b157fc0c2b
commit 0562d9c37d
2 changed files with 20 additions and 26 deletions

View File

@ -1,16 +1,20 @@
Imports DigitalData.Modules.Logging Imports DigitalData.Modules.Logging
Public Class Message Public Class FormHelper
Private Logger As Logger Private ReadOnly Logger As Logger
Public Sub New(pLogConfig As LogConfig) Public Sub New(pLogConfig As LogConfig)
Logger = pLogConfig.GetLogger() Logger = pLogConfig.GetLogger()
End Sub End Sub
Public Sub [Error](pException As Exception, pMessage As String) Public Sub ShowError(pException As Exception, pFunction As String, Optional pDetails As String = "")
Dim oMessage = String.Format(My.Resources.frmShared.In_der_Funktion___0___ist_folgender_Fehler_aufgetreten___1_, pFunction, vbNewLine & vbNewLine & pException.Message)
If pDetails <> String.Empty Then
oMessage &= $"{vbNewLine}{pDetails}"
End If
Logger.Error(pException) Logger.Error(pException)
Dim oMessage As String = $"{pMessage}{vbNewLine}{vbNewLine}{pException.Message}" MsgBox(oMessage, MsgBoxStyle.Critical, Application.ProductName)
MsgBox(oMessage, MsgBoxStyle.Critical, "Schwerwiegender Fehler")
End Sub End Sub
End Class End Class

View File

@ -25,7 +25,7 @@ Public Class frmImportMain
Private WebService As WebService Private WebService As WebService
Private DocumentLoader As DocumentLoader Private DocumentLoader As DocumentLoader
Private SchemaLoader As SchemaLoader Private SchemaLoader As SchemaLoader
Private Message As Message Private FormHelper As FormHelper
Private Grids As List(Of GridControl) Private Grids As List(Of GridControl)
Private GridLoader As GridLoader Private GridLoader As GridLoader
@ -66,7 +66,7 @@ Public Class frmImportMain
Application.StartupPath Application.StartupPath
) )
Message = New Message(LogConfig) FormHelper = New FormHelper(LogConfig)
GridBuilder = New GridBuilder(GridViewFiles) GridBuilder = New GridBuilder(GridViewFiles)
GridBuilder.WithDefaults.WithClipboardHandler() GridBuilder.WithDefaults.WithClipboardHandler()
@ -93,7 +93,7 @@ Public Class frmImportMain
Winline = New Data(LogConfig, Database, ConfigManager.Config) Winline = New Data(LogConfig, Database, ConfigManager.Config)
WebService = New WebService(LogConfig, ConfigManager.Config, Application.UserAppDataPath) WebService = New WebService(LogConfig, ConfigManager.Config, Application.UserAppDataPath)
Catch ex As Exception Catch ex As Exception
ShowError(ex, My.Resources.frmImportMainExtra.Initialisieren_der_Anwendungs_Daten) FormHelper.ShowError(ex, My.Resources.frmImportMainExtra.Initialisieren_der_Anwendungs_Daten)
End Try End Try
txtVersion.Caption = String.Format(txtVersion.Tag.ToString, My.Application.Info.Version.ToString) txtVersion.Caption = String.Format(txtVersion.Tag.ToString, My.Application.Info.Version.ToString)
@ -140,7 +140,7 @@ Public Class frmImportMain
Grids = CreateGridsAndColumns(CurrentSchema) Grids = CreateGridsAndColumns(CurrentSchema)
Catch ex As Exception Catch ex As Exception
ShowError(ex, My.Resources.frmImportMainExtra.Laden_der_Winline_Daten) FormHelper.ShowError(ex, My.Resources.frmImportMainExtra.Laden_der_Winline_Daten)
Finally Finally
SplashScreenManager.CloseWaitForm() SplashScreenManager.CloseWaitForm()
btnLoadFiles.Enabled = True btnLoadFiles.Enabled = True
@ -213,7 +213,7 @@ Public Class frmImportMain
Where(Function(r) r.Id.ToString = oRow.Item("GUID")). Where(Function(r) r.Id.ToString = oRow.Item("GUID")).
SingleOrDefault() SingleOrDefault()
Dim oForm As New frmRowEditor(oColumns, oDocumentRow, CurrentDocument.Mandator, Winline) Dim oForm As New frmRowEditor(LogConfig, oColumns, oDocumentRow, CurrentDocument.Mandator, Winline)
If oForm.ShowDialog() = DialogResult.OK Then If oForm.ShowDialog() = DialogResult.OK Then
Dim oModifiedRow = oForm.DocumentRow Dim oModifiedRow = oForm.DocumentRow
Dim oIndex = CurrentDocument.Rows.IndexOf(oModifiedRow) Dim oIndex = CurrentDocument.Rows.IndexOf(oModifiedRow)
@ -222,7 +222,7 @@ Public Class frmImportMain
LoadDocument(CurrentDocument) LoadDocument(CurrentDocument)
End If End If
Catch ex As Exception Catch ex As Exception
ShowError(ex, My.Resources.frmImportMainExtra.Laden_der_Detailzeilen) FormHelper.ShowError(ex, My.Resources.frmImportMainExtra.Laden_der_Detailzeilen)
End Try End Try
End Sub End Sub
@ -241,7 +241,7 @@ Public Class frmImportMain
MsgBox(My.Resources.frmImportMainExtra.Es_konnte_kein_passender_Mandant_ermittelt_werden, MsgBoxStyle.Information, Text) MsgBox(My.Resources.frmImportMainExtra.Es_konnte_kein_passender_Mandant_ermittelt_werden, MsgBoxStyle.Information, Text)
Catch ex As Exception Catch ex As Exception
ShowError(ex, My.Resources.frmImportMainExtra.Laden_der_Detailzeilen) FormHelper.ShowError(ex, My.Resources.frmImportMainExtra.Laden_der_Detailzeilen)
Finally Finally
SplitContainerGrids.Enabled = True SplitContainerGrids.Enabled = True
@ -273,7 +273,7 @@ Public Class frmImportMain
MsgBox(My.Resources.frmImportMainExtra.Es_konnte_kein_passender_Mandant_ermittelt_werden, MsgBoxStyle.Information, Text) MsgBox(My.Resources.frmImportMainExtra.Es_konnte_kein_passender_Mandant_ermittelt_werden, MsgBoxStyle.Information, Text)
Catch ex As Exception Catch ex As Exception
ShowError(ex, My.Resources.frmImportMainExtra.Neuladen_des_Dokuments) FormHelper.ShowError(ex, My.Resources.frmImportMainExtra.Neuladen_des_Dokuments)
End Try End Try
End Sub End Sub
@ -289,7 +289,7 @@ Public Class frmImportMain
lookupMandator.EditValue = oDocument.Mandator lookupMandator.EditValue = oDocument.Mandator
LoadDocument(oDocument) LoadDocument(oDocument)
Catch ex As Exception Catch ex As Exception
ShowError(ex, My.Resources.frmImportMainExtra.Laden_des_Dokuments) FormHelper.ShowError(ex, My.Resources.frmImportMainExtra.Laden_des_Dokuments)
End Try End Try
End Sub End Sub
@ -363,10 +363,10 @@ Public Class frmImportMain
MsgBox(My.Resources.frmImportMainExtra.Datei_erfolgreich_in_die_WinLine_übertragen, MsgBoxStyle.Information, Text) MsgBox(My.Resources.frmImportMainExtra.Datei_erfolgreich_in_die_WinLine_übertragen, MsgBoxStyle.Information, Text)
Catch ex As HttpRequestException Catch ex As HttpRequestException
ShowError(ex, My.Resources.frmImportMainExtra.Übertragung_zur_WinLine, My.Resources.frmImportMainExtra.Die_Verbindung_zum_WinLine_Server_ist_fehlgeschlagen) FormHelper.ShowError(ex, My.Resources.frmImportMainExtra.Übertragung_zur_WinLine, My.Resources.frmImportMainExtra.Die_Verbindung_zum_WinLine_Server_ist_fehlgeschlagen)
Catch ex As Exception Catch ex As Exception
ShowError(ex, My.Resources.frmImportMainExtra.Übertragung_zur_WinLine) FormHelper.ShowError(ex, My.Resources.frmImportMainExtra.Übertragung_zur_WinLine)
Finally Finally
SplitContainerGrids.Enabled = True SplitContainerGrids.Enabled = True
@ -417,16 +417,6 @@ Public Class frmImportMain
TryOpenDirectory(oUserConfigDirectory.FullName, My.Resources.frmImportMainExtra.Konfigurationsverzeichnis) TryOpenDirectory(oUserConfigDirectory.FullName, My.Resources.frmImportMainExtra.Konfigurationsverzeichnis)
End Sub End Sub
Private Sub ShowError(pException As Exception, pFunction As String, Optional pDetails As String = "")
Dim oMessage = String.Format(My.Resources.frmImportMainExtra.In_der_Funktion___0___ist_folgender_Fehler_aufgetreten__1_, pFunction, vbNewLine & vbNewLine & pException.Message)
If pDetails <> String.Empty Then
oMessage &= $"{vbNewLine}{pDetails}"
End If
Logger.Error(pException)
MsgBox(oMessage, MsgBoxStyle.Critical, Text)
End Sub
Private Sub btnShowXml_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnShowXml.ItemClick Private Sub btnShowXml_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnShowXml.ItemClick
Dim oForm As New frmXmlEditor With {.FileName = CurrentDocument.FullName} Dim oForm As New frmXmlEditor With {.FileName = CurrentDocument.FullName}
oForm.Show() oForm.Show()