Improve Error handling across the board
This commit is contained in:
@@ -1,10 +1,13 @@
|
||||
Imports DigitalData.Modules.Logging
|
||||
Imports System.Text.RegularExpressions
|
||||
Imports DigitalData.Modules.Logging
|
||||
Imports DigitalData.Modules.Database
|
||||
Imports MultiTool.Common.Winline.Entities
|
||||
Imports System.Text.RegularExpressions
|
||||
Imports MultiTool.Common.Templates
|
||||
Imports MultiTool.Common.Constants
|
||||
Imports DigitalData.Modules.Language
|
||||
Imports DigitalData.Modules.Filesystem
|
||||
Imports MultiTool.Common.Winline.Entities
|
||||
Imports MultiTool.Common.Constants
|
||||
Imports MultiTool.Common.Templates
|
||||
Imports MultiTool.Common.Exceptions
|
||||
Imports MultiTool.Common.Documents
|
||||
|
||||
Namespace Winline
|
||||
Public Class WinlineData
|
||||
@@ -14,6 +17,7 @@ Namespace Winline
|
||||
Private ReadOnly Property MandatorConfig As MandatorConfig
|
||||
Private ReadOnly Property MappingConfig As MappingConfig
|
||||
Private ReadOnly Property Patterns As Patterns
|
||||
Private ReadOnly Property FileEx As File
|
||||
|
||||
Public Property Articles As New List(Of Article)
|
||||
Public Property Accounts As New List(Of Account)
|
||||
@@ -29,6 +33,8 @@ Namespace Winline
|
||||
Config = pConfig
|
||||
MandatorConfig = pMandatorConfig
|
||||
MappingConfig = pMappingConfig
|
||||
FileEx = New File(pLogConfig)
|
||||
Years = LoadEconomicYears()
|
||||
End Sub
|
||||
|
||||
''' <summary>
|
||||
@@ -65,8 +71,14 @@ Namespace Winline
|
||||
Public Property Year As Integer
|
||||
End Class
|
||||
|
||||
Private Function LoadEconomicYears() As IEnumerable(Of Integer)
|
||||
Dim oCurrentYear = Now.Year
|
||||
Dim oRange As IEnumerable(Of Integer) = Enumerable.Range(oCurrentYear - 10, 12).ToList()
|
||||
Return oRange
|
||||
End Function
|
||||
|
||||
Public Async Function LoadArticles(pMandator As Mandator) As Task
|
||||
|
||||
Public Async Function LoadArticlesAsync(pMandator As Mandator) As Task
|
||||
Logger.Info("Loading Articles for Mandator [{0}]", pMandator)
|
||||
Dim oYear = Config.GetWinLineYear()
|
||||
|
||||
@@ -104,7 +116,7 @@ Namespace Winline
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Public Async Function LoadPackingUnits(pMandator As Mandator) As Task
|
||||
Public Async Function LoadPackingUnitsAsync(pMandator As Mandator) As Task
|
||||
Logger.Info("Loading Packing Units for Mandator [{0}]", pMandator)
|
||||
Dim oYear = Config.GetWinLineYear()
|
||||
|
||||
@@ -155,7 +167,7 @@ Namespace Winline
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Public Async Function LoadAccounts(pMandator As Mandator) As Task
|
||||
Public Async Function LoadAccountsAsync(pMandator As Mandator) As Task
|
||||
Logger.Info("Loading Accounts for Mandator [{0}]", pMandator)
|
||||
Dim oYear = Config.GetWinLineYear()
|
||||
|
||||
@@ -207,7 +219,7 @@ Namespace Winline
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Public Async Function LoadMandators() As Task
|
||||
Public Async Function LoadMandatorsAsync() As Task
|
||||
Try
|
||||
Dim oSQL = "SELECT [c000], [c003], [c004] FROM [cwlsystem].[dbo].[T001SRV] (NOLOCK)"
|
||||
Dim oTable = Await Database.GetDatatableAsync(oSQL)
|
||||
@@ -241,13 +253,9 @@ Namespace Winline
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Public Sub LoadEconomicYears()
|
||||
Dim oCurrentYear = Now.Year
|
||||
Dim oRange As IEnumerable(Of Integer) = Enumerable.Range(oCurrentYear - 10, 12).ToList()
|
||||
Years = oRange
|
||||
End Sub
|
||||
|
||||
Public Async Function LoadDocumentKinds(pMandator As Mandator) As Task
|
||||
|
||||
Public Async Function LoadDocumentKindsAsync(pMandator As Mandator) As Task
|
||||
Dim oYear As Integer = Config.GetWinLineYear()
|
||||
|
||||
Try
|
||||
@@ -388,11 +396,11 @@ Namespace Winline
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Public Async Function TryGetArticlePrice(pArticle As String, pAccountNumber As String, pQuantity As String, pDocumentDate As Date, pMandator As Mandator, pTemplate As Template) As Task(Of Double)
|
||||
Return Await TryGetArticlePrice(pArticle, pAccountNumber, pQuantity, pDocumentDate, pMandator, pTemplate, 0)
|
||||
Public Async Function TryGetArticlePriceAsync(pArticle As String, pAccountNumber As String, pQuantity As String, pDocumentDate As Date, pMandator As Mandator, pTemplate As Template) As Task(Of Double)
|
||||
Return Await TryGetArticlePriceAsync(pArticle, pAccountNumber, pQuantity, pDocumentDate, pMandator, pTemplate, 0)
|
||||
End Function
|
||||
|
||||
Public Async Function TryGetArticlePrice(pArticle As String, pAccountNumber As String, pQuantity As String, pDocumentDate As Date, pMandator As Mandator, pTemplate As Template, pWaitingDays As Integer) As Task(Of Double)
|
||||
Public Async Function TryGetArticlePriceAsync(pArticle As String, pAccountNumber As String, pQuantity As String, pDocumentDate As Date, pMandator As Mandator, pTemplate As Template, pWaitingDays As Integer) As Task(Of Double)
|
||||
Try
|
||||
Dim oUserName = Environment.UserName
|
||||
Dim oYear As Integer = Config.GetWinLineYear()
|
||||
@@ -475,7 +483,7 @@ Namespace Winline
|
||||
''' <summary>
|
||||
''' This function is completely SCHAUM related.
|
||||
''' </summary>
|
||||
Public Async Function TryGetWaitingDays(pDocumentKind As Integer, pMandator As Mandator) As Task(Of Integer)
|
||||
Public Async Function TryGetWaitingDaysAsync(pDocumentKind As Integer, pMandator As Mandator) As Task(Of Integer)
|
||||
Try
|
||||
Dim oSql = $"
|
||||
SELECT [Karenztage].[u012] FROM [{pMandator.Database}].[dbo].[t670] As [Werksdefinition]
|
||||
@@ -894,6 +902,69 @@ Namespace Winline
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Private ReadOnly RunningNumberVersionRegex As Regex = New Regex("~\d{1,3}$")
|
||||
Private ReadOnly RunningNumberMaximumLength As Integer = 20
|
||||
|
||||
Public Async Function GetVersionedRunningNumberAsync(pDocument As Document, pMandator As Mandator, pAccountNumber As String, pRunningNumber As String) As Task(Of String)
|
||||
Try
|
||||
Dim oYear As Integer = Config.GetWinLineYear()
|
||||
Dim oSql As String = $"
|
||||
SELECT COUNT(*) FROM [{pMandator.Database}].[dbo].[v250]
|
||||
WHERE
|
||||
[c021] = '{pAccountNumber}' AND -- Account '
|
||||
[c022] = '{pRunningNumber}' AND -- Running Number '
|
||||
--[c035] = '4711' -- Belegart, needed?
|
||||
[c144] IS NULL AND -- Stornonummer Angebot
|
||||
[c145] IS NULL AND -- Stornonummer Auftrag
|
||||
[c146] IS NULL AND -- Stornonummer Lieferschein
|
||||
[c147] IS NULL AND -- Stornonummer Faktura
|
||||
[mesocomp] = '{pMandator.Id}' --AND [mesoyear] = {oYear}
|
||||
"
|
||||
|
||||
Dim oExistingCount = Await Database.GetScalarValueAsync(oSql)
|
||||
|
||||
If oExistingCount = 0 Then
|
||||
Logger.Debug("Running number [{0}] does not exist yet. Returning.")
|
||||
Return pRunningNumber
|
||||
Else
|
||||
Logger.Debug("Running number [{0}] already exists. Checking again.")
|
||||
Dim oVersionResult = FileEx.GetVersionedString(pRunningNumber, "~"c)
|
||||
|
||||
Dim oFinalLength As Integer = oVersionResult.Item1.Count + oVersionResult.Item2.ToString.Count + 1
|
||||
|
||||
If oFinalLength > RunningNumberMaximumLength Then
|
||||
Logger.Warn("Running number is too long ({0} chars total) and cannot be versioned. Versioning needs at least 2 characters.", oFinalLength)
|
||||
pDocument.AddDocumentError(DocumentErrorType.AttributeValidationFailed, "Das Feld Laufnummer hat die zulässige Länge überschritten.")
|
||||
Return pRunningNumber
|
||||
End If
|
||||
|
||||
Return Await GetVersionedRunningNumberAsync(pDocument, pMandator, pAccountNumber, $"{oVersionResult.Item1}~{oVersionResult.Item2}")
|
||||
End If
|
||||
|
||||
Catch ex As MultiToolException
|
||||
Logger.Error(ex)
|
||||
Throw ex
|
||||
|
||||
Catch ex As Exception
|
||||
Logger.Warn("Error while getting versioned running number for mandator [{0}] and running number [{1}]", pMandator, pRunningNumber)
|
||||
Logger.Error(ex)
|
||||
Return Nothing
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Public Function VersionNumber(pNumber As String) As String
|
||||
Dim oRunningNumberBase As String
|
||||
|
||||
If RunningNumberVersionRegex.IsMatch(pNumber) Then
|
||||
Dim oSplitNumber = pNumber.Split("~")
|
||||
oRunningNumberBase = oSplitNumber.First()
|
||||
Dim oRunningNumberVersion As Integer = Integer.Parse(oSplitNumber.Last())
|
||||
Return $"{oRunningNumberBase}~{oRunningNumberVersion + 1}"
|
||||
Else
|
||||
Return $"{pNumber}~2"
|
||||
End If
|
||||
End Function
|
||||
|
||||
Public Async Function ExecuteFinalSQL(pDocument As ExportDocument, pTemplate As Template, pMandator As Mandator) As Task(Of Boolean)
|
||||
Try
|
||||
Dim oSql As String = Patterns.ReplaceForExport(pDocument, pMandator, pTemplate.FinalSQL)
|
||||
|
||||
Reference in New Issue
Block a user