VeragAddIn

This commit is contained in:
2026-02-10 14:29:00 +01:00
parent b24d57cd2a
commit 4856d4e6d9
5 changed files with 146 additions and 4 deletions

View File

@@ -1,10 +1,13 @@
Option Explicit On
Imports System.Data
Imports System.Net
Imports System.Reflection
Imports System.Runtime.InteropServices
Imports System.Text.RegularExpressions
Imports System.Windows.Forms
'Imports System.Windows.Forms.LinkLabel
Imports HtmlAgilityPack
Imports Microsoft.Office.Interop
Imports Microsoft.Office.Tools.Ribbon
Imports VERAG_PROG_ALLGEMEIN
@@ -95,6 +98,10 @@ Public Class VERAGRibbon
Private Sub Button3_Click_1(sender As Object, e As RibbonControlEventArgs) Handles Button3.Click
If LOGIN_OK Then AVISO_Mail_Functions.newBarsanMAIL()
End Sub
Private Sub btnDFDS_Click(sender As Object, e As RibbonControlEventArgs) Handles btnDFDS.Click
If LOGIN_OK Then AVISO_Mail_Functions.newDSDFMAIL()
End Sub
End Class
Public Class AVISO_Mail_Functions
@@ -158,7 +165,7 @@ Public Class AVISO_Mail_Functions
loadAttachment(mailItem, ATTACHMENTS_LIST)
If isMail_EKOL(mailItem) Then
If vbYes = MsgBox("EKOL-Anhänge laden?", vbYesNoCancel) Then getATT_EKOL(mailItem, ATTACHMENTS_LIST)
If vbYes = MsgBox("DFDS-Anhänge laden?", vbYesNoCancel) Then getATT_DFDS(mailItem, ATTACHMENTS_LIST)
End If
If isMail_Barsan(mailItem) Then
@@ -251,6 +258,25 @@ Public Class AVISO_Mail_Functions
End Try
End Sub
Shared Sub newDSDFMAIL()
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_EKOL(mailItem) Then
VERAG_PROG_ALLGEMEIN.cFormularManager.PrintViaSpirePDF(AVISO_Mail_Functions.getATT_EKOL(mailItem))
End If
End If
End If
Catch ex As Exception
VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name)
End Try
End Sub
Shared Sub newBarsanMAIL()
Try
Dim explorer As Outlook.Explorer = Globals.ThisAddIn.Application.ActiveExplorer
@@ -653,6 +679,105 @@ Public Class AVISO_Mail_Functions
End Function
Shared Function getATT_DFDS(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 DataTable
Try
If ATT Is Nothing Then ATT = New List(Of String)
Dim dt As New DataTable()
dt.Columns.AddRange({
New DataColumn("Record"),
New DataColumn("Consignee"),
New DataColumn("Quantity"),
New DataColumn("GrossWeight"),
New DataColumn("OrderCustoms"),
New DataColumn("OperationType"),
New DataColumn("Description"),
New DataColumn("LinkText"),
New DataColumn("LinkUrl")
})
Dim doc As New HtmlAgilityPack.HtmlDocument()
doc.LoadHtml(mailItem.HTMLBody)
' all data rows (skip header)
Dim rows = doc.DocumentNode.SelectNodes("//tr[td]")
If rows Is Nothing Then Return dt
For Each row In rows
Dim cells = row.SelectNodes("td")
If cells Is Nothing OrElse cells.Count < 8 Then Continue For
Dim linkNode = cells(7).SelectSingleNode(".//a")
dt.Rows.Add(
Clean(cells(0).InnerText),
Clean(cells(1).InnerText),
Clean(cells(2).InnerText),
Clean(cells(3).InnerText),
Clean(cells(4).InnerText),
Clean(cells(5).InnerText),
Clean(cells(6).InnerText),
If(linkNode IsNot Nothing, Clean(linkNode.InnerText), ""),
If(linkNode IsNot Nothing, linkNode.GetAttributeValue("href", ""), "")
)
Next
Dim counter As Integer = 1
Dim sendungsNrOld As String = ""
For Each r In dt.Rows
If r("LinkUrl") <> "" AndAlso r("LinkUrl").ToString.Contains("https://web01.ekoltransport.com.tr/dfdsdocumentservice/download/") Then
Dim sendungsNr As String = r("Record")
Dim Descr As String = r("Description")
If Descr <> "" Then
Descr.ToString.Replace(";", "_")
Descr.ToString.Replace(".", "_")
Descr.ToString.Replace(" ", "_")
Descr = VERAG_PROG_ALLGEMEIN.cDATENSERVER.replaceInvalidCahr(Descr)
End If
If sendungsNrOld <> "" AndAlso sendungsNrOld <> sendungsNr Then
counter = 1
End If
Dim pdf = VERAG_PROG_ALLGEMEIN.cFormularManager.getPDFViaSpirePDF_FromURLStream(r("LinkUrl"), r("Record") & "_" & counter & "_" & IIf(Descr <> "", Descr, ""),, False)
If IO.File.Exists(pdf) Then
ATT.Add(pdf)
counter += 1
End If
sendungsNrOld = r("Record")
End If
Next
Catch ex As Exception
VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name)
End Try
End Function
Private Shared Function Clean(input As String) As String
If String.IsNullOrWhiteSpace(input) Then Return ""
Return HtmlEntity.DeEntitize(input).
Replace("o:p", "").
Replace(vbCr, "").
Replace(vbLf, "").
Trim()
End Function
Shared Function getATT_Barsan(mailItem As Outlook.MailItem, Optional ByRef ATT As List(Of String) = Nothing, Optional ByRef art As String = "") As List(Of String)