From a8ca303f5ef7dcf49895c48177cb7b4ddd27e025 Mon Sep 17 00:00:00 2001 From: Jonathan Jenne Date: Fri, 10 Jun 2022 11:48:41 +0200 Subject: [PATCH] Support import without printing documents --- MultiTool.Common/Templates/Template.vb | 33 +++++++++++----- MultiTool.Common/Winline/WebServiceData.vb | 45 ++++++++++++++++++++-- 2 files changed, 66 insertions(+), 12 deletions(-) diff --git a/MultiTool.Common/Templates/Template.vb b/MultiTool.Common/Templates/Template.vb index 5397f4f..5f9d655 100644 --- a/MultiTool.Common/Templates/Template.vb +++ b/MultiTool.Common/Templates/Template.vb @@ -35,6 +35,19 @@ Namespace Templates End Get End Property + Public ReadOnly Property PrintDocument As Boolean + Get + Dim oPrintDocument = GetParameter("PRINT") + Dim oDefaultValue = True + + If oPrintDocument IsNot Nothing Then + oDefaultValue = IIf(oPrintDocument = "0", False, True) + End If + + Return oDefaultValue + End Get + End Property + Public ReadOnly Property DocTypeCategory As DocumentTypeCategory Get Select Case DocType @@ -80,8 +93,8 @@ Namespace Templates Dim oParam1 As String = Utils.NotNull(Parameter1, String.Empty) Dim oParam2 As String = Utils.NotNull(Parameter2, String.Empty) - Dim oParamValue1 = TryGetParameter(oParam1) - Dim oParamValue2 = TryGetParameter(oParam2) + Dim oParamValue1 = TryGetParameter(oParam1, pName) + Dim oParamValue2 = TryGetParameter(oParam2, pName) If oParamValue1 IsNot Nothing AndAlso oParamValue1.Item1 = pName Then Return oParamValue1.Item2 @@ -94,15 +107,17 @@ Namespace Templates Return Nothing End Function - Private Function TryGetParameter(pParameterString As String) As Tuple(Of String, String) + Private Function TryGetParameter(pParameterString As String, pName As String) As Tuple(Of String, String) If pParameterString <> String.Empty Then - Dim oSplit = pParameterString.Split("=").ToList() + For Each oParameter In pParameterString.Split(",") + Dim oSplit = oParameter.Split("=").ToList() - If oSplit.Count = 2 Then - Return New Tuple(Of String, String)(oSplit.First, oSplit.Last) - Else - Return Nothing - End If + If oSplit.Count = 2 AndAlso oSplit.First = pName Then + Return New Tuple(Of String, String)(oSplit.First, oSplit.Last) + End If + Next + + Return Nothing Else Return Nothing End If diff --git a/MultiTool.Common/Winline/WebServiceData.vb b/MultiTool.Common/Winline/WebServiceData.vb index c9a4c5d..4170f4d 100644 --- a/MultiTool.Common/Winline/WebServiceData.vb +++ b/MultiTool.Common/Winline/WebServiceData.vb @@ -1,4 +1,5 @@ -Imports System.Net.Http +Imports System.Collections.Specialized +Imports System.Net.Http Imports System.Text Imports System.Xml Imports DigitalData.Modules.Database @@ -48,7 +49,6 @@ Namespace Winline ''' ''' True if request was successful. Public Async Function TransferDocumentToWinline(pDocument As Documents.Document, pTemplate As Template, pMandator As Mandator, Optional pIsTest As Boolean = False) As Task(Of Boolean) - Dim oBytes As Byte() = GetBytesFromDocument(pDocument) Dim oWS = Config RaiseEvent WebServiceProgress(Me, "Einstellungen laden") @@ -75,7 +75,13 @@ Namespace Winline RaiseEvent WebServiceProgress(Me, "Dateien schreiben") Logger.Debug("Writing request file to [{oOutputFilePath}]") + ' If configured, prevent printing the document and instead create it as a draft in the "Nicht gedruckt" section + If pTemplate.PrintDocument = False Then + pDocument.PrintVoucher = 0 + End If + ' --- Serialize Data into XML string + Dim oBytes As Byte() = GetBytesFromDocument(pDocument) IO.File.WriteAllBytes(oOutputFilePath, oBytes) ' --- Copy file to Winline Import Directory @@ -106,7 +112,19 @@ Namespace Winline ' 1 = As File (relative to Winline Server directory) Dim oByref = 1 - Dim oURL As String = $"{oWS.BaseUrl}/ewlservice/import?User={oWS.Username}&Password={oWS.Password}&Company={pMandator.Id}&Type={oTemplateType}&Vorlage={oTemplateName}&ActionCode={oActionCode}&Byref={oByref}&Data={oImportRelativeFilePath}" + Dim oParams As New NameValueCollection() From { + {"User", oWS.Username}, + {"Password", oWS.Password}, + {"Company", pMandator.Id}, + {"Type", oTemplateType}, + {"Vorlage", oTemplateName}, + {"ActionCode", oActionCode}, + {"Byref", oByref}, + {"Data", oImportRelativeFilePath} + } + + Dim oURL As String = $"{oWS.BaseUrl}/ewlservice/import{ToQueryString(oParams)}" + 'Dim oURL As String = $"{oWS.BaseUrl}/ewlservice/import?User={oWS.Username}&Password={oWS.Password}&Company={pMandator.Id}&Type={oTemplateType}&Vorlage={oTemplateName}&ActionCode={oActionCode}&Byref={oByref}&Data={oImportRelativeFilePath}" Dim oClient As New HttpClient With { .Timeout = TimeSpan.FromSeconds(Constants.HTTP_REQUEST_TIMEOUT_IN_SECONDS) } @@ -436,6 +454,27 @@ Namespace Winline Return False End Try End Function + + Private Function ToQueryString(ByVal nvc As NameValueCollection) As String + Dim sb As StringBuilder = New StringBuilder("?") + Dim first As Boolean = True + + For Each key As String In nvc.AllKeys + + For Each value As String In nvc.GetValues(key) + + If Not first Then + sb.Append("&") + End If + + sb.AppendFormat("{0}={1}", Uri.EscapeDataString(key), Uri.EscapeDataString(value)) + first = False + Next + Next + + Return sb.ToString() + End Function End Class + End Namespace \ No newline at end of file