Mailsender, etc.
This commit is contained in:
@@ -3,6 +3,7 @@ Imports System.IO
|
||||
Imports System.Net
|
||||
Imports System.Net.Mail
|
||||
Imports ClosedXML.Excel
|
||||
Imports com.sun.xml.internal.rngom.digested
|
||||
Imports DAKOSY_Worker
|
||||
Imports VERAG_PROG_ALLGEMEIN
|
||||
|
||||
@@ -58,7 +59,6 @@ Module Mail
|
||||
' PARAM = "NCTSLIST_TOBB"
|
||||
' PARAM = "NCTSLIST_TOBB"
|
||||
'------------------------------------------------------------------------------------
|
||||
'PARAM = "TETRAPAK"
|
||||
|
||||
If PARAM = "" Then
|
||||
System.Console.WriteLine("OPTION nicht erkannt!")
|
||||
@@ -485,7 +485,45 @@ Module Mail
|
||||
End If
|
||||
End If
|
||||
|
||||
Case "BERICHT"
|
||||
|
||||
Dim von = CDate("01." & Now.AddMonths(-1).Month & "." & Now.AddMonths(-1).Year)
|
||||
Dim bis = CDate("01." & Now.Month & "." & Now.Year).AddDays(-1)
|
||||
|
||||
For Each r As DataRow In dtParam.Rows
|
||||
|
||||
System.Console.WriteLine("OPTION erkannt:" & dtParam.Rows(0).Item("ms_info"))
|
||||
System.Console.WriteLine("Auswertung Details gestartet...")
|
||||
If SendEmail_DiverseKunden(r.Item("ms_an"), r.Item("ms_kundenNr"), von, bis, "BERICHT", r.Item("ms_cc"), r.Item("ms_bcc"), r.Item("ms_subject"), r.Item("ms_mailtext")) Then
|
||||
System.Console.WriteLine("Vorgang erfolgreich abgeschlossen ...")
|
||||
End If
|
||||
|
||||
Next
|
||||
|
||||
|
||||
|
||||
Case "DETAILBERICHT"
|
||||
|
||||
Dim von = CDate("01." & Now.AddMonths(-1).Month & "." & Now.AddMonths(-1).Year)
|
||||
Dim bis = CDate("01." & Now.Month & "." & Now.Year).AddDays(-1)
|
||||
|
||||
For Each r As DataRow In dtParam.Rows
|
||||
|
||||
System.Console.WriteLine("OPTION erkannt:" & dtParam.Rows(0).Item("ms_info"))
|
||||
System.Console.WriteLine("Auswertung Details gestartet...")
|
||||
If SendEmail_DiverseKunden(r.Item("ms_an"), r.Item("ms_kundenNr"), von, bis, "DETAILBERICHT", r.Item("ms_cc"), r.Item("ms_bcc"), r.Item("ms_subject"), r.Item("ms_mailtext")) Then
|
||||
System.Console.WriteLine("Vorgang erfolgreich abgeschlossen ...")
|
||||
End If
|
||||
|
||||
Next
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Case Else
|
||||
|
||||
|
||||
System.Console.WriteLine("OPTION nicht erkannt!")
|
||||
End Select
|
||||
|
||||
@@ -952,6 +990,58 @@ Module Mail
|
||||
End Function
|
||||
|
||||
|
||||
Private Function SendEmail_DiverseKunden(Mailto As String, KdNr As String, von As Date, bis As Date, Auswertungstyp As String, Optional cc As String = "", Optional bcc As String = "", Optional Subject As String = "", Optional Body As String = "") As Boolean
|
||||
Try
|
||||
Dim excel As String = genEXCEL_Bericht_Kunden(KdNr, von, bis, Auswertungstyp)
|
||||
System.Console.WriteLine("EXCEL erstellt...")
|
||||
If excel <> "" And Not excel.StartsWith("ERROR: ") Then
|
||||
|
||||
System.Console.WriteLine("Sende E-Mail...")
|
||||
|
||||
Dim ADR As New cAdressen(KdNr)
|
||||
|
||||
If Subject = "" Then
|
||||
|
||||
Subject = "Auswertungen Zollanmeldungen " & ADR.Name_1
|
||||
|
||||
|
||||
Else
|
||||
Subject = replaceBodyVariable(Subject, von, bis)
|
||||
End If
|
||||
|
||||
|
||||
If Body = "" Then
|
||||
Body = "Anbei befinden sich die Auswertungen Zollanmeldungen von " & von.ToShortDateString & " bis " & bis.ToShortDateString & "." &
|
||||
"<br><br>Erstellt am: " & Now.ToShortDateString & ", um " & Now.ToShortTimeString &
|
||||
"<br><br><br>Automatisch generiertes E-Mail. Bitte Antworten Sie nicht an dieses E-Mail." &
|
||||
"<br><br>VERAG SPEDITION AG"
|
||||
|
||||
Else
|
||||
Body = replaceBodyVariable(Body, von, bis)
|
||||
End If
|
||||
|
||||
Dim anhenge As New List(Of String)
|
||||
anhenge.Add(excel)
|
||||
If VERAG_PROG_ALLGEMEIN.cProgramFunctions.sendMail(Mailto, Subject, Body,,, False, cc, bcc, anhenge) Then
|
||||
System.Console.WriteLine("E-Mail gesendet.")
|
||||
System.Console.WriteLine("Erfolgreich!")
|
||||
Else
|
||||
System.Console.WriteLine("ERROR BEIM SENDEN DER MAIL!")
|
||||
|
||||
End If
|
||||
|
||||
Return True
|
||||
Else
|
||||
System.Console.WriteLine(excel)
|
||||
End If
|
||||
Catch ex As Exception
|
||||
VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace, System.Reflection.MethodBase.GetCurrentMethod.Name, VERAG_PROG_ALLGEMEIN.ERROR_OP.MAIL)
|
||||
System.Console.WriteLine(ex.Message & ex.StackTrace)
|
||||
Return False
|
||||
End Try
|
||||
End Function
|
||||
|
||||
|
||||
Private Function SendEmail_BRG_Auswertung(Optional wochenAuswertung As Boolean = False, Optional details As Boolean = False) As Boolean
|
||||
Dim Msg As New MailMessage
|
||||
Dim myCredentials As New System.Net.NetworkCredential
|
||||
@@ -2482,6 +2572,243 @@ Module Mail
|
||||
|
||||
End Function
|
||||
|
||||
|
||||
Public Function genEXCEL_Bericht_Kunden(KdNr As String, von As Date, bis As Date, Auswertungstyp As String) As String
|
||||
|
||||
Dim KUNDE = New VERAG_PROG_ALLGEMEIN.cKunde(KdNr)
|
||||
|
||||
Dim dt As DataTable = (New SQL).loadDgvBySql("SELECT CAST([FilialenNr] as varchar) + '/' + CAST([AbfertigungsNr] as varchar) Abfertigungsnummer
|
||||
,cast([Abfertigungsdatum] as date)Abfertigungsdatum
|
||||
,Absender
|
||||
,Rechnungsbetrag Betrag
|
||||
,BelegNr
|
||||
,[FilialenNr],[AbfertigungsNr],Speditionsbuch.Abfertigungsart,Abfertigungsbezeichnung,Speditionsbuch.Zollsystem_Land
|
||||
FROM Speditionsbuch INNER JOIN [Abfertigungsarten] ON Speditionsbuch.Abfertigungsart=Abfertigungsarten.Abfertigungsart
|
||||
where EmpfängerKundenNr IN (" & KdNr & ") and VermittlerKundenNr IN (" & KdNr & ") and Abfertigungsdatum BETWEEN '" & von.ToShortDateString & "' AND '" & bis.ToShortDateString & "' And Speditionsbuch.Abfertigungsart IN (1,29,38)", "FMZOLL")
|
||||
|
||||
Try
|
||||
|
||||
Dim Path = ""
|
||||
If dt IsNot Nothing And dt.Rows.Count > 0 Then
|
||||
|
||||
Dim sPath As String = Environment.GetFolderPath(Environment.SpecialFolder.Personal) & "\VERAG\SR\"
|
||||
If Not My.Computer.FileSystem.DirectoryExists(sPath) Then
|
||||
My.Computer.FileSystem.CreateDirectory(sPath)
|
||||
End If
|
||||
|
||||
|
||||
Dim exclApp As Object 'as Application
|
||||
Dim Datei As Object 'as WorkBook
|
||||
Dim Blatt As Object 'Microsoft.Office.Interop.Excel.Worksheet 'As Object 'as Worksheet
|
||||
exclApp = CreateObject("Excel.Application")
|
||||
|
||||
Select Case Auswertungstyp.ToUpper
|
||||
|
||||
Case "DETAILBERICHT"
|
||||
|
||||
With exclApp
|
||||
.Visible = False
|
||||
|
||||
Try
|
||||
Path = sPath & "Detailbericht_" & KUNDE.KundenNr & "_" & von.ToShortDateString & "-" & bis.ToShortDateString & "" & " .xlsx"
|
||||
While System.IO.File.Exists(Path)
|
||||
Path = sPath & KUNDE.KundenNr & von.ToShortDateString & "-" & bis.ToShortDateString & "_" & Now.ToString("ddMMyyyyHHmmss") & ".xlsx"
|
||||
End While
|
||||
My.Computer.FileSystem.WriteAllBytes(Path, My.Resources.Detailauswertung_divers, False)
|
||||
Catch ex As System.Exception
|
||||
End Try
|
||||
|
||||
|
||||
Datei = .Workbooks.Open(Path) 'Anpassen
|
||||
Blatt = Datei.Worksheets(1) 'Anpassen
|
||||
|
||||
Dim cnt = 2
|
||||
For Each r In dt.Rows
|
||||
Dim ZOLLANMELDUNG As New DAKOSY_Worker.cZollsysteme_Aktenbeschriftung
|
||||
Try
|
||||
Dim zS = If(r("Zollsystem_Land") IsNot DBNull.Value, r("Zollsystem_Land").ToString(), "")
|
||||
If ZOLLANMELDUNG.getDataByBezugsnummer(r("FilialenNr") & "/" & r("AbfertigungsNr"), r("Abfertigungsart"), "", False, zS) Then
|
||||
|
||||
If ZOLLANMELDUNG.dtWARENPOS.Rows.Count > 0 Then
|
||||
|
||||
Dim rowcounter As Integer = 0
|
||||
|
||||
For Each row As DataRow In ZOLLANMELDUNG.dtWARENPOS.Rows
|
||||
|
||||
Dim ZollInProzent As Double = 0
|
||||
If If(ZOLLANMELDUNG.RechnungspreisohneWahrung, "") <> "" Then
|
||||
ZollInProzent = ZOLLANMELDUNG.ABGABEN_ZOLL / ZOLLANMELDUNG.RechnungspreisohneWahrung * 100
|
||||
End If
|
||||
|
||||
Blatt.Range("A" & cnt).Value = cnt - 1
|
||||
Blatt.Range("B" & cnt).Value = r("Abfertigungsdatum")
|
||||
Blatt.Range("C" & cnt).Value = VERAG_PROG_ALLGEMEIN.cAllgemein.getFirmaFromFiliale(r("FilialenNr"))
|
||||
Blatt.Range("D" & cnt).Value = ZOLLANMELDUNG.Empfaenger
|
||||
Blatt.Range("E" & cnt).Value = r("FilialenNr") & "/" & r("AbfertigungsNr")
|
||||
Blatt.Range("F" & cnt).Value = r("BelegNr")
|
||||
Blatt.Range("G" & cnt).Value = row.Item("PosNr")
|
||||
Blatt.Range("H" & cnt).Value = row.Item("WarenNr")
|
||||
Blatt.Range("I" & cnt).Value = "-"
|
||||
Blatt.Range("J" & cnt).Value = row.Item("WarenBez")
|
||||
Blatt.Range("K" & cnt).Value = ""
|
||||
Blatt.Range("L" & cnt).Value = ZOLLANMELDUNG.Waehrungscode
|
||||
Blatt.Range("M" & cnt).Value = ZOLLANMELDUNG.Geschaeftsart
|
||||
Blatt.Range("N" & cnt).Value = ZOLLANMELDUNG.Zollstelle_Eingang
|
||||
Blatt.Range("O" & cnt).Value = ""
|
||||
Blatt.Range("P" & cnt).Value = row.Item("Netto")
|
||||
Blatt.Range("Q" & cnt).Value = row.Item("PosWert")
|
||||
Blatt.Range("R" & cnt).Value = IIf(rowcounter = 0, ZOLLANMELDUNG.ABGABEN_EUST, "")
|
||||
Blatt.Range("S" & cnt).Value = IIf(rowcounter = 0, ZOLLANMELDUNG.ABGABEN_ZOLL, "")
|
||||
Blatt.Range("T" & cnt).Value = IIf(rowcounter = 0, ZollInProzent.ToString("N2") & " %", "")
|
||||
Blatt.Range("U" & cnt).Value = IIf(ZOLLANMELDUNG.VerBestLandZst.ToString.Count > 1, ZOLLANMELDUNG.VerBestLandZst.ToString.Substring(0, 2), "")
|
||||
Blatt.Range("V" & cnt).Value = ZOLLANMELDUNG.Absender
|
||||
Blatt.Range("W" & cnt).Value = row.Item("Herkunft")
|
||||
Blatt.Range("X" & cnt).Value = ZOLLANMELDUNG.Incoterms
|
||||
Blatt.Range("Y" & cnt).Value = row.Item("Verfahren")
|
||||
Blatt.Range("Z" & cnt).Value = row.Item("Preferenz")
|
||||
|
||||
If If(ZOLLANMELDUNG.ATCMRN, "") <> "" AndAlso Blatt.Range("F" & cnt).Value = "" Then
|
||||
Blatt.Range("F" & cnt).Value = ZOLLANMELDUNG.ATCMRN
|
||||
End If
|
||||
|
||||
cnt += 1
|
||||
rowcounter += 1
|
||||
Next
|
||||
Else
|
||||
Dim ZollInProzent As Double = 0
|
||||
If If(ZOLLANMELDUNG.RechnungspreisohneWahrung, "") <> "" Then
|
||||
ZollInProzent = ZOLLANMELDUNG.ABGABEN_ZOLL / ZOLLANMELDUNG.RechnungspreisohneWahrung * 100
|
||||
End If
|
||||
|
||||
Blatt.Range("A" & cnt).Value = cnt - 1
|
||||
Blatt.Range("B" & cnt).Value = r("Abfertigungsdatum")
|
||||
Blatt.Range("C" & cnt).Value = VERAG_PROG_ALLGEMEIN.cAllgemein.getFirmaFromFiliale(r("FilialenNr"))
|
||||
Blatt.Range("D" & cnt).Value = ZOLLANMELDUNG.Empfaenger
|
||||
Blatt.Range("E" & cnt).Value = r("FilialenNr") & "/" & r("AbfertigungsNr")
|
||||
Blatt.Range("F" & cnt).Value = r("BelegNr")
|
||||
Blatt.Range("G" & cnt).Value = ""
|
||||
Blatt.Range("H" & cnt).Value = ""
|
||||
Blatt.Range("I" & cnt).Value = "-"
|
||||
Blatt.Range("J" & cnt).Value = ""
|
||||
Blatt.Range("K" & cnt).Value = ""
|
||||
Blatt.Range("L" & cnt).Value = ZOLLANMELDUNG.Waehrungscode
|
||||
Blatt.Range("M" & cnt).Value = ZOLLANMELDUNG.Geschaeftsart
|
||||
Blatt.Range("N" & cnt).Value = ZOLLANMELDUNG.Zollstelle_Eingang
|
||||
Blatt.Range("O" & cnt).Value = ""
|
||||
Blatt.Range("P" & cnt).Value = ""
|
||||
Blatt.Range("Q" & cnt).Value = ""
|
||||
Blatt.Range("R" & cnt).Value = ZOLLANMELDUNG.ABGABEN_EUST
|
||||
Blatt.Range("S" & cnt).Value = ZOLLANMELDUNG.ABGABEN_ZOLL
|
||||
Blatt.Range("T" & cnt).Value = ZollInProzent.ToString("N2") & " %"
|
||||
Blatt.Range("U" & cnt).Value = IIf(ZOLLANMELDUNG.VerBestLandZst.ToString.Count > 1, ZOLLANMELDUNG.VerBestLandZst.ToString.Substring(0, 2), "")
|
||||
Blatt.Range("V" & cnt).Value = ZOLLANMELDUNG.Absender
|
||||
Blatt.Range("W" & cnt).Value = ""
|
||||
Blatt.Range("X" & cnt).Value = ZOLLANMELDUNG.Incoterms
|
||||
Blatt.Range("Y" & cnt).Value = ""
|
||||
Blatt.Range("Z" & cnt).Value = ""
|
||||
Blatt.Range("AA" & cnt).Value = ""
|
||||
|
||||
|
||||
If If(ZOLLANMELDUNG.ATCMRN, "") <> "" AndAlso Blatt.Range("F" & cnt).Value = "" Then
|
||||
Blatt.Range("F" & cnt).Value = ZOLLANMELDUNG.ATCMRN
|
||||
End If
|
||||
cnt += 1
|
||||
End If
|
||||
End If
|
||||
|
||||
Catch ex As Exception
|
||||
|
||||
End Try
|
||||
|
||||
Next
|
||||
|
||||
Datei.Save()
|
||||
.DisplayAlerts = False
|
||||
.quit()
|
||||
Try : Datei.close(True) : Catch : End Try
|
||||
End With
|
||||
|
||||
Case "BERICHT"
|
||||
|
||||
|
||||
With exclApp
|
||||
.Visible = False
|
||||
|
||||
Try
|
||||
Path = sPath & "Bericht_" & KUNDE.KundenNr & von.ToShortDateString & "-" & bis.ToShortDateString & "" & " .xlsx"
|
||||
While System.IO.File.Exists(Path)
|
||||
Path = sPath & KUNDE.KundenNr & von.ToShortDateString & "-" & bis.ToShortDateString & "_" & Now.ToString("ddMMyyyyHHmmss") & ".xlsx"
|
||||
End While
|
||||
My.Computer.FileSystem.WriteAllBytes(Path, My.Resources.Auswertung_divers, False)
|
||||
Catch ex As System.Exception
|
||||
|
||||
End Try
|
||||
|
||||
Datei = .Workbooks.Open(Path) 'Anpassen
|
||||
Blatt = Datei.Worksheets(1) 'Anpassen
|
||||
|
||||
Blatt.Range("I1").Value = von.ToShortDateString & "-" & bis.ToShortDateString
|
||||
|
||||
Dim cnt = 3
|
||||
For Each r In dt.Rows
|
||||
Blatt.Range("A" & cnt).Value = cnt - 2
|
||||
Blatt.Range("B" & cnt).Value = r("Abfertigungsnummer")
|
||||
' Blatt.Range("C" & cnt).Value = r("RechnungsNr")
|
||||
Blatt.Range("C" & cnt).Value = r("Abfertigungsdatum")
|
||||
Blatt.Range("D" & cnt).Value = r("Abfertigungsbezeichnung")
|
||||
Blatt.Range("E" & cnt).Value = r("Absender")
|
||||
Blatt.Range("F" & cnt).Value = "" 'r("Betrag")
|
||||
Blatt.Range("H" & cnt).Value = r("BelegNr")
|
||||
|
||||
Dim ZOLLANMELDUNG As New DAKOSY_Worker.cZollsysteme_Aktenbeschriftung
|
||||
Try
|
||||
Dim zS = If(r("Zollsystem_Land") IsNot DBNull.Value, r("Zollsystem_Land").ToString(), "")
|
||||
If ZOLLANMELDUNG.getDataByBezugsnummer(r("FilialenNr") & "/" & r("AbfertigungsNr"), r("Abfertigungsart"), "", False, zS) Then
|
||||
Blatt.Range("F" & cnt).Value = ZOLLANMELDUNG.RechnungspreisohneWahrung
|
||||
Blatt.Range("G" & cnt).Value = ZOLLANMELDUNG.Handelsrechnung.Replace(", ", "," & vbNewLine)
|
||||
Blatt.Range("I" & cnt).Value = ZOLLANMELDUNG.ABGABEN_ZOLL
|
||||
Blatt.Range("J" & cnt).Value = ZOLLANMELDUNG.ANZ_POS
|
||||
|
||||
If If(ZOLLANMELDUNG.ATCMRN, "") <> "" Then
|
||||
Blatt.Range("H" & cnt).Value = ZOLLANMELDUNG.ATCMRN
|
||||
End If
|
||||
End If
|
||||
|
||||
Catch ex As Exception
|
||||
MsgBox(ex.Message & ex.StackTrace)
|
||||
End Try
|
||||
|
||||
cnt += 1
|
||||
Next
|
||||
Datei.Save()
|
||||
.DisplayAlerts = False
|
||||
.quit()
|
||||
Try : Datei.close(True) : Catch : End Try
|
||||
End With
|
||||
|
||||
|
||||
|
||||
End Select
|
||||
|
||||
'Dim filepath = VERAG_PROG_ALLGEMEIN.cProgramFunctions.genExcelFromDT_NEW(dt,,,,, False, "Report Data_" & KUNDENADR.FullName & "_" & von.ToShortDateString & "-" & bis.ToShortDateString)
|
||||
Dim filepath = Path
|
||||
If filepath = "" Then Return "ERROR 01: Fehler beim Erzeugen des XLS."
|
||||
|
||||
Return filepath
|
||||
|
||||
End If
|
||||
|
||||
Catch ex As System.Exception
|
||||
' MsgBox(ex.Message)
|
||||
Return "ERROR 02: " & ex.Message & vbNewLine & ex.StackTrace
|
||||
End Try
|
||||
|
||||
|
||||
|
||||
Return ""
|
||||
|
||||
End Function
|
||||
|
||||
Private Sub releaseObject(ByVal obj As Object)
|
||||
Try
|
||||
System.Runtime.InteropServices.Marshal.ReleaseComObject(obj)
|
||||
|
||||
Reference in New Issue
Block a user