From 94260b0656cb550b538a33b5f0ecd8abfff4b7db Mon Sep 17 00:00:00 2001 From: "d.breimaier" Date: Tue, 26 Sep 2023 08:51:48 +0200 Subject: [PATCH] Barsan-Implementation --- VERAGAddIn/VERAGAddIn.vbproj | 1 + VERAGAddIn/rbnVERAG.Designer.vb | 10 +++ VERAGAddIn/rbnVERAG.vb | 133 +++++++++++++++++++++++++++++++- 3 files changed, 143 insertions(+), 1 deletion(-) diff --git a/VERAGAddIn/VERAGAddIn.vbproj b/VERAGAddIn/VERAGAddIn.vbproj index 7c15e41..00b3356 100644 --- a/VERAGAddIn/VERAGAddIn.vbproj +++ b/VERAGAddIn/VERAGAddIn.vbproj @@ -172,6 +172,7 @@ + diff --git a/VERAGAddIn/rbnVERAG.Designer.vb b/VERAGAddIn/rbnVERAG.Designer.vb index 3d8b3cb..5662ff0 100644 --- a/VERAGAddIn/rbnVERAG.Designer.vb +++ b/VERAGAddIn/rbnVERAG.Designer.vb @@ -52,6 +52,7 @@ Me.btnGestellungsgarantien = Me.Factory.CreateRibbonButton Me.SplitButton1 = Me.Factory.CreateRibbonSplitButton Me.Button1 = Me.Factory.CreateRibbonButton + Me.Button3 = Me.Factory.CreateRibbonButton Me.Button4 = Me.Factory.CreateRibbonButton Me.Tab1.SuspendLayout() Me.VERAG.SuspendLayout() @@ -131,6 +132,7 @@ Me.SplitButton1.ControlSize = Microsoft.Office.Core.RibbonControlSize.RibbonControlSizeLarge Me.SplitButton1.Image = Global.VERAGAddIn.My.Resources.Resources.wheel Me.SplitButton1.Items.Add(Me.Button1) + Me.SplitButton1.Items.Add(Me.Button3) Me.SplitButton1.Items.Add(Me.Button4) Me.SplitButton1.Label = "Spezielle Optionen" Me.SplitButton1.Name = "SplitButton1" @@ -142,6 +144,13 @@ Me.Button1.Name = "Button1" Me.Button1.ShowImage = True ' + 'Button3 + ' + Me.Button3.Image = Global.VERAGAddIn.My.Resources.Resources.pdf + Me.Button3.Label = "Barsan PDFs auslesen" + Me.Button3.Name = "Button3" + Me.Button3.ShowImage = True + ' 'Button4 ' Me.Button4.Label = "Info" @@ -173,6 +182,7 @@ Friend WithEvents btnVollmachten As Microsoft.Office.Tools.Ribbon.RibbonButton Friend WithEvents btnVertraege As Microsoft.Office.Tools.Ribbon.RibbonButton Friend WithEvents btnGestellungsgarantien As Microsoft.Office.Tools.Ribbon.RibbonButton + Friend WithEvents Button3 As Microsoft.Office.Tools.Ribbon.RibbonButton End Class Partial Class ThisRibbonCollection diff --git a/VERAGAddIn/rbnVERAG.vb b/VERAGAddIn/rbnVERAG.vb index b740f7d..430db2c 100644 --- a/VERAGAddIn/rbnVERAG.vb +++ b/VERAGAddIn/rbnVERAG.vb @@ -13,6 +13,11 @@ Imports System.Net Imports System.Security.Policy Imports System.Diagnostics.Eventing.Reader Imports System.Runtime.InteropServices.ComTypes +Imports System.Drawing +Imports System.Threading.Tasks +Imports System.Net.Http +Imports System.Diagnostics +Imports VERAG_PROG_ALLGEMEIN.Kleinma.Controls Public Class VERAGRibbon Dim LOGIN_OK = False @@ -93,6 +98,9 @@ Public Class VERAGRibbon End Function + Private Sub Button3_Click_1(sender As Object, e As RibbonControlEventArgs) Handles Button3.Click + If LOGIN_OK Then AVISO_Mail_Functions.newBarsanMAIL() + End Sub End Class Public Class AVISO_Mail_Functions @@ -156,6 +164,13 @@ Public Class AVISO_Mail_Functions getATT_EKOL(mailItem, ATTACHMENTS_LIST) End If End If + + If isMail_Barsan(mailItem) Then + If vbYes = MsgBox("Barsan-Anhänge laden?", vbYesNoCancel) Then + getATT_Barsan(mailItem, ATTACHMENTS_LIST) + End If + End If + Dim Bezeichnung = strFileName Dim AvisoId = Nothing @@ -240,6 +255,29 @@ Public Class AVISO_Mail_Functions MsgBox(ex.Message & ex.StackTrace) End Try End Sub + + Shared Sub newBarsanMAIL() + Try + Dim explorer As Outlook.Explorer = Globals.ThisAddIn.Application.ActiveExplorer + Dim selection As Outlook.Selection = explorer.Selection + If selection.Count > 0 Then + Dim selectedItem = selection(1) + Dim mailItem As Outlook.MailItem = selectedItem + If mailItem IsNot Nothing Then + If AVISO_Mail_Functions.isMail_Barsan(mailItem) Then + Dim att = getATT_Barsan(mailItem) + 'Dim result As MsgBoxResult = MsgBox("Wollen Sie die " & att.Count & " Barsan - PDF's ausdrucken?", vbYesNoCancel) + 'If result = vbYes Then + ' VERAG_PROG_ALLGEMEIN.cFormularManager.PrintViaSpirePDF(att) + 'End If + End If + End If + + End If + Catch ex As Exception + MsgBox(ex.Message & ex.StackTrace) + End Try + End Sub Shared Function initFirmaUser() As Boolean Dim LOGIN_OK = False VERAG_PROG_ALLGEMEIN.cAllgemein.FIRMA = "VERAG" 'DEFAULT @@ -353,6 +391,12 @@ Public Class AVISO_Mail_Functions End If 'End If + If isMail_Barsan(mailItem) Then + If vbYes = MsgBox("Barsan-Anhänge laden?", vbYesNoCancel) Then + getATT_Barsan(mailItem, ATTACHMENTS_LIST) + End If + End If + loadAttachment(mailItem, ATTACHMENTS_LIST) @@ -544,6 +588,18 @@ Public Class AVISO_Mail_Functions Return False End Function + Shared Function isMail_Barsan(mailItem As Outlook.MailItem) As Boolean + Try + If mailItem IsNot Nothing Then + Dim srch As String = " 0 AndAlso l.Contains(""">") Then ' ENDE - Dim link = ("https://web01.ekol.com/documentservice/download/" & l.ToString.Substring(0, l.ToString.IndexOf(""">"))) + Dim link = ("https://web01.ekol.com/documentservice/download/" & l.ToString.Substring(0, l.ToString.IndexOf(""">") - 1)) 'Ansonten stüzt der Webservice-Aufruf ab! ABER -> For .NET 4.7 or later, the System.Net.ServicePointManager.SecurityProtocol should not be set manualy! System.Net.ServicePointManager.SecurityProtocol = System.Net.ServicePointManager.SecurityProtocol Or SecurityProtocolType.Tls11 Or SecurityProtocolType.Tls12 @@ -589,6 +645,81 @@ Public Class AVISO_Mail_Functions Return ATT End Function + + + Shared Function getATT_Barsan(mailItem As Outlook.MailItem, Optional ByRef ATT As List(Of String) = Nothing, Optional ByRef LKW_Nr As String = "", Optional ByRef RefNr As String = "", Optional ByRef INFO As String = "") As List(Of String) + If ATT Is Nothing Then ATT = New List(Of String) + Try + + If mailItem Is Nothing Then Return ATT + + Dim html = mailItem.HTMLBody + + Dim srch As String = " 0 AndAlso l.Contains(""">") Then ' ENDE + Dim link = ("https://portal.barsan.com/Dokuman/DokumanGoster.aspx" & l.ToString.Substring(0, l.ToString.IndexOf(""">"))) + + + 'Ansonten stüzt der Webservice-Aufruf ab! ABER -> For .NET 4.7 or later, the System.Net.ServicePointManager.SecurityProtocol should not be set manualy! + System.Net.ServicePointManager.SecurityProtocol = System.Net.ServicePointManager.SecurityProtocol Or SecurityProtocolType.Tls11 Or SecurityProtocolType.Tls12 + If l.ToString.ToLower().Contains(".pdf") Then + + Dim pdf = VERAG_PROG_ALLGEMEIN.cFormularManager.getPDFViaSpirePDF_FromURL(link) + 'Process.Start(pdf) + + + 'Dim client As New HttpClient() + + 'Try + + ' Dim response As HttpResponseMessage = Await client.GetAsync(link) + + ' response.EnsureSuccessStatusCode() + ' Dim responseBody As String = Await response.Content.ReadAsStringAsync() + ' Console.WriteLine(responseBody) + + ' Dim PDF = responseBody + 'Catch e As HttpRequestException + ' Console.WriteLine(vbLf & "Exception Caught!") + ' Console.WriteLine("Message :{0} ", e.Message) + 'End Try + + + + 'Dim TMP_PATH = GetTempFilePathWithExtension(".pdf") + + 'Dim TMP_PATH = VERAG_PROG_ALLGEMEIN.cFormularManager.getPDFViaSpirePDF_FromURL(res.ResponseUri.ToString) + + ''My.Computer.Network.DownloadFile(res.ResponseUri.ToString, TMP_PATH) + + If IO.File.Exists(pdf) Then + ATT.Add(pdf) + End If + End If + + End If + cnt += 1 + Next + End If + 'LKW_Nr = getEKOL_Var(html, "Position :") + 'RefNr = getEKOL_Var(html, "Truck :") + 'INFO = getEKOL_Var(html, "Route :") + + Catch ex As Exception + MsgBox(ex.Message & ex.StackTrace) + End Try + Return ATT + End Function + + Shared Function getEKOL_Var(html, varName, Optional splitTo = "
") If html.contains(varName) Then Dim split = html.split(varName)