806 lines
34 KiB
VB.net
806 lines
34 KiB
VB.net
Imports System.IO
|
|
Imports System.Net
|
|
Imports System.Text
|
|
Imports System.Text.RegularExpressions
|
|
Imports System.Web
|
|
Imports System.Xml
|
|
Imports Renci.SshNet
|
|
Imports Renci.SshNet.Sftp
|
|
Imports VERAG_PROG_ALLGEMEIN
|
|
|
|
|
|
|
|
Public Class frmNachrichtenVerarbeitung_MDM_divers
|
|
Dim cntDatenEingelesen As Integer = 0
|
|
Dim dsNichtErkannt As Integer = 0
|
|
Dim SQL As New VERAG_PROG_ALLGEMEIN.SQL
|
|
Dim allowClose = False
|
|
Dim deleteFilesAfterDownload = False
|
|
Dim renameFilesAfterDownload = False
|
|
Dim enableEinlesen = True
|
|
Dim rmc As New cRMC
|
|
Dim uta As New cUTA
|
|
Dim ids As New cIDS
|
|
Dim programName As String
|
|
Dim Dateiname = ""
|
|
Public year As Integer
|
|
|
|
Sub New(programName As String)
|
|
|
|
' Dieser Aufruf ist für den Designer erforderlich.
|
|
InitializeComponent()
|
|
Me.programName = programName
|
|
|
|
' Fügen Sie Initialisierungen nach dem InitializeComponent()-Aufruf hinzu.
|
|
|
|
End Sub
|
|
Sub New(programName As String, allowClose As Boolean, deleteFilesAfterDownload As Boolean, renameFilesAfterDownload As Boolean, Optional enableEinlesen As Boolean = True) 'autostart
|
|
|
|
' Dieser Aufruf ist für den Designer erforderlich.
|
|
InitializeComponent()
|
|
Me.programName = programName
|
|
Me.allowClose = allowClose
|
|
Me.deleteFilesAfterDownload = deleteFilesAfterDownload
|
|
Me.renameFilesAfterDownload = renameFilesAfterDownload
|
|
Me.enableEinlesen = enableEinlesen
|
|
' Fügen Sie Initialisierungen nach dem InitializeComponent()-Aufruf hinzu.
|
|
|
|
End Sub
|
|
|
|
Private Sub frmDYNachrichtenVerarbeitung_Load(sender As Object, e As EventArgs) Handles Me.Load
|
|
|
|
ListBox3.Items.Clear()
|
|
Me.Refresh()
|
|
|
|
Button2.Enabled = enableEinlesen
|
|
|
|
lblFTP.Text = programName
|
|
|
|
If programName.Contains("RMC") Then
|
|
rmc.initImportPfade(programName)
|
|
For Each d In System.IO.Directory.GetFiles(rmc.VERARBEITUNG_PFAD)
|
|
ListBox3.Items.Add(frmStartOptions.cut_file(d))
|
|
Me.Refresh()
|
|
Next
|
|
ElseIf programName.Contains("UTA") Then
|
|
uta.initImportPfade(programName)
|
|
For Each d In System.IO.Directory.GetFiles(uta.VERARBEITUNG_PFAD)
|
|
ListBox3.Items.Add(frmStartOptions.cut_file(d))
|
|
Me.Refresh()
|
|
Next
|
|
ElseIf programName.Contains("IDS") Then
|
|
ids.initImportPfade(programName)
|
|
For Each d In System.IO.Directory.GetFiles(ids.VERARBEITUNG_PFAD)
|
|
ListBox3.Items.Add(frmStartOptions.cut_file(d))
|
|
Me.Refresh()
|
|
Next
|
|
End If
|
|
|
|
End Sub
|
|
|
|
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
|
|
Me.Enabled = False
|
|
Try
|
|
Label9.Visible = True
|
|
Dim cnt = getNachrichtenDaten()
|
|
Label9.Text = cnt & " Datensätze empfangen."
|
|
|
|
Catch ex As System.Exception
|
|
VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace & vbNewLine & "Datei: " & Dateiname, System.Reflection.MethodInfo.GetCurrentMethod.Name)
|
|
End Try
|
|
Me.Enabled = True
|
|
|
|
End Sub
|
|
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
|
|
Me.Enabled = False
|
|
Try
|
|
Label5.Visible = True
|
|
DatenEinlesen()
|
|
If dsNichtErkannt > 0 Then
|
|
|
|
Label6.Text = dsNichtErkannt & " Datensätze nicht " & vbNewLine & "erkannt."
|
|
Label6.Visible = True
|
|
End If
|
|
Catch ex As System.Exception
|
|
VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace & vbNewLine & "Datei: " & Dateiname, System.Reflection.MethodInfo.GetCurrentMethod.Name)
|
|
End Try
|
|
Me.Enabled = True
|
|
Label5.Text = cntDatenEingelesen & " Datensätze verarbeitet."
|
|
|
|
End Sub
|
|
|
|
|
|
Function getNachrichtenDaten() As Integer
|
|
Dim cnt = 0
|
|
Try
|
|
If programName.Contains("RMC") Then
|
|
DownloadFtpDirectory(rmc.API_STRING & "/", New NetworkCredential(rmc.API.Rows(0).Item("api_user").ToString, rmc.API.Rows(0).Item("api_password").ToString), "", cnt, deleteFilesAfterDownload)
|
|
ElseIf programName.Contains("UTA") Then
|
|
DownloadSFtpDirectory(uta.API_STRING, New NetworkCredential(uta.API.Rows(0).Item("api_user").ToString, uta.API.Rows(0).Item("api_password").ToString), "", cnt, deleteFilesAfterDownload, "/TRX/" & year, renameFilesAfterDownload)
|
|
ElseIf programName.Contains("IDS") Then
|
|
'keinFTP (NOCH NICHT)!
|
|
End If
|
|
|
|
|
|
Catch ex As System.Exception
|
|
VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace & vbNewLine & "Datei: " & Dateiname, System.Reflection.MethodInfo.GetCurrentMethod.Name)
|
|
End Try
|
|
|
|
Return cnt
|
|
End Function
|
|
|
|
|
|
Sub DownloadFtpDirectory(url As String, credentials As NetworkCredential, localPath As String, ByRef cnt As Integer, deleteAfterDownload As Boolean)
|
|
Dim listRequest As FtpWebRequest = WebRequest.Create(url)
|
|
listRequest.Method = WebRequestMethods.Ftp.ListDirectoryDetails
|
|
listRequest.Credentials = credentials
|
|
|
|
Dim verarbeitungspfad = ""
|
|
|
|
If programName.Contains("RMC") Then
|
|
verarbeitungspfad = rmc.VERARBEITUNG_PFAD
|
|
ElseIf programName.Contains("UTA") Then
|
|
verarbeitungspfad = uta.VERARBEITUNG_PFAD
|
|
End If
|
|
|
|
Dim lines As List(Of String) = New List(Of String)
|
|
|
|
Using listResponse As FtpWebResponse = listRequest.GetResponse(),
|
|
listStream As Stream = listResponse.GetResponseStream(),
|
|
listReader As StreamReader = New StreamReader(listStream)
|
|
|
|
While Not listReader.EndOfStream
|
|
lines.Add(listReader.ReadLine())
|
|
End While
|
|
End Using
|
|
|
|
For Each line As String In lines
|
|
Dim tokens As String() =
|
|
line.Split(New Char() {" "}, 9, StringSplitOptions.RemoveEmptyEntries)
|
|
Dim name As String = HttpUtility.UrlEncode(tokens(8)) 'tokens(8) 'handle special characters within filename!
|
|
Dim permissions As String = tokens(0)
|
|
|
|
Dim localFilePath As String = Path.Combine(localPath, name)
|
|
Dim fileUrl As String = url + name
|
|
|
|
|
|
If permissions(0) <> "d" Then 'in keine Unterorder suchen, nur die erste Ebene
|
|
|
|
Dim downloadRequest As FtpWebRequest = WebRequest.Create(fileUrl)
|
|
downloadRequest.Method = WebRequestMethods.Ftp.DownloadFile
|
|
downloadRequest.Credentials = credentials
|
|
|
|
' Dim fileDateTmp As Date = ServerDateFile(credentials, fileUrl)
|
|
'name = name.Replace(".csv", "_RGDAT_" & Now.ToShortDateString & ".csv")
|
|
|
|
Dim destFilenameTMP = verarbeitungspfad
|
|
If System.IO.File.Exists(verarbeitungspfad & name) Then
|
|
Dim fi As FileInfo = New FileInfo(verarbeitungspfad & name)
|
|
destFilenameTMP &= name.Replace(fi.Extension, "_") & Now.ToString("yyMMdd_HHmmss.fff") & fi.Extension
|
|
Else
|
|
destFilenameTMP &= name
|
|
|
|
End If
|
|
|
|
Try
|
|
|
|
|
|
Using downloadResponse As FtpWebResponse = downloadRequest.GetResponse(),
|
|
sourceStream As Stream = downloadResponse.GetResponseStream(),
|
|
targetStream As Stream = File.OpenWrite(destFilenameTMP)
|
|
Dim buffer As Byte() = New Byte(10240 - 1) {}
|
|
Dim read As Integer
|
|
Do
|
|
read = sourceStream.Read(buffer, 0, buffer.Length)
|
|
If read > 0 Then
|
|
targetStream.Write(buffer, 0, read)
|
|
End If
|
|
Loop While read > 0
|
|
|
|
sourceStream.Dispose()
|
|
targetStream.Dispose()
|
|
downloadResponse.Dispose()
|
|
|
|
'Dim destFilename = verarbeitungspfad & If(IO.File.Exists(verarbeitungspfad & name), name.Replace(".csv", "_") & Now.ToString("yyMMdd_HHmmss.fff") & ".csv", name)
|
|
|
|
'IO.File.Move(destFilenameTMP, destFilename) 'Datei umbenennen
|
|
|
|
|
|
Dim fi As FileInfo = New FileInfo(destFilenameTMP)
|
|
ListBox3.Items.Add(frmStartOptions.cut_file(fi.Name)) 'zur Liste hinzufügen
|
|
cnt += 1
|
|
|
|
|
|
'Datei nach download löschen
|
|
If deleteAfterDownload Then
|
|
Dim ftpReq As FtpWebRequest = WebRequest.Create(fileUrl)
|
|
ftpReq.Method = WebRequestMethods.Ftp.DeleteFile
|
|
ftpReq.Credentials = credentials
|
|
Dim ftpResp As FtpWebResponse = ftpReq.GetResponse
|
|
ftpResp.Close()
|
|
End If
|
|
|
|
End Using
|
|
Catch ex As System.Exception
|
|
|
|
End Try
|
|
End If
|
|
'End If
|
|
Next
|
|
End Sub
|
|
Function DownloadSFtpDirectory(url As String, credentials As NetworkCredential, localPath As String, ByRef cnt As Integer, deleteAfterDownload As Boolean, Path As String, renameAfterDownload As Boolean) As Integer
|
|
|
|
|
|
Dim ConnectionInfo As New ConnectionInfo(url, "22", credentials.UserName, New PasswordAuthenticationMethod(credentials.UserName, credentials.Password))
|
|
Using client = New SftpClient(ConnectionInfo)
|
|
client.Connect()
|
|
|
|
Dim files = client.ListDirectory(Path).OrderBy(Function(file) file.LastAccessTime).Reverse
|
|
|
|
Dim targetFile As SftpFile
|
|
|
|
For Each file As SftpFile In files
|
|
|
|
'If file.IsRegularFile AndAlso file.Name.ToLower.EndsWith(".uta") AndAlso file.Length > 0 AndAlso IIf(renameAfterDownload, Not file.Name.ToLower.StartsWith("_"), True) Then
|
|
|
|
If file.IsRegularFile AndAlso file.Name.ToLower.EndsWith(".uta") AndAlso file.Length > 0 AndAlso IIf(renameAfterDownload, Not file.Name.ToLower.StartsWith("_"), Not file.Name.ToLower.StartsWith("_")) Then
|
|
|
|
Dim remoteFileName = "/" & file.Name
|
|
Dim filePath = uta.VERARBEITUNG_PFAD & IIf(System.IO.File.Exists(uta.VERARBEITUNG_PFAD & file.Name), file.Name.Replace(".UTA", "_") & Now.ToString("yyMMdd_HHmmss.fff") & ".UTA", file.Name)
|
|
|
|
Dim downloadedFile As Stream = System.IO.File.Create(filePath)
|
|
|
|
client.DownloadFile(Path + remoteFileName, downloadedFile)
|
|
|
|
If System.IO.File.Exists(filePath) AndAlso deleteAfterDownload Then
|
|
|
|
client.DeleteFile(Path + remoteFileName) 'Datei nach erfolgreichem Herunterladen vom Server löschen
|
|
|
|
End If
|
|
|
|
If System.IO.File.Exists(filePath) AndAlso Not deleteAfterDownload And renameAfterDownload Then
|
|
|
|
Try
|
|
|
|
Dim remoteFileNameRenamed = "/_" & file.Name
|
|
client.RenameFile(Path + remoteFileName, Path + remoteFileNameRenamed) 'verarbeitete Datei kennzeichnen mit beginnenden "_"
|
|
|
|
Catch ex As Exception
|
|
End Try
|
|
|
|
End If
|
|
|
|
downloadedFile.Dispose()
|
|
|
|
Dim fi As FileInfo = New FileInfo(filePath)
|
|
If fi.Extension = ".uta" Then
|
|
ListBox3.Items.Add(frmStartOptions.cut_file(fi.Name)) 'zur Liste hinzufügen
|
|
cnt += 1
|
|
End If
|
|
End If
|
|
Next
|
|
|
|
End Using
|
|
|
|
End Function
|
|
|
|
|
|
|
|
Private Function ServerDateFile(credentials As NetworkCredential, fileUrl As String) As Date
|
|
Dim ServerDate As DateTime
|
|
Try
|
|
Dim request As FtpWebRequest = WebRequest.Create(fileUrl)
|
|
request.Method = WebRequestMethods.Ftp.GetDateTimestamp
|
|
request.Credentials = credentials
|
|
|
|
Using response = CType(request.GetResponse(), Net.FtpWebResponse)
|
|
ServerDate = response.LastModified.ToShortDateString
|
|
End Using
|
|
|
|
Return ServerDate
|
|
Catch ex As WebException
|
|
VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace & vbNewLine & programName & " GET DATE FILE: " & Dateiname, System.Reflection.MethodInfo.GetCurrentMethod.Name)
|
|
Return Now
|
|
End Try
|
|
|
|
Return ServerDate
|
|
End Function
|
|
|
|
Sub DatenEinlesen()
|
|
|
|
VERAG_PROG_ALLGEMEIN.cAllgemein.ERR_OP_GLOBAL = VERAG_PROG_ALLGEMEIN.ERROR_OP.MAIL
|
|
|
|
If ListBox3.Items.Count = 0 Then
|
|
Label6.Text = "Keine Daten zum Einlesen vorhanden."
|
|
Label6.Visible = True
|
|
Exit Sub
|
|
End If
|
|
|
|
Dim deleteTable As Boolean = False
|
|
Dim verarbeitungspfad, zielpfad
|
|
If programName.Contains("RMC") Then
|
|
verarbeitungspfad = rmc.VERARBEITUNG_PFAD
|
|
zielpfad = rmc.ZIEL_PFAD
|
|
ElseIf programName.Contains("UTA") Then
|
|
verarbeitungspfad = uta.VERARBEITUNG_PFAD
|
|
zielpfad = uta.ZIEL_PFAD
|
|
ElseIf programName.Contains("IDS") Then
|
|
verarbeitungspfad = ids.VERARBEITUNG_PFAD
|
|
zielpfad = ids.ZIEL_PFAD
|
|
End If
|
|
|
|
For i = 1 To 2
|
|
|
|
For Each d In System.IO.Directory.GetFiles(verarbeitungspfad)
|
|
Try
|
|
Dateiname = d
|
|
If System.IO.File.Exists(d) Then
|
|
Dim found = False
|
|
Dim fi As FileInfo = New FileInfo(d)
|
|
|
|
Dim alreadyMoved = False
|
|
|
|
If programName.Contains("RMC") Then
|
|
|
|
Select Case i
|
|
|
|
Case 1
|
|
'------------------------------------------
|
|
'------------------ CSV ------------------
|
|
'------------------------------------------
|
|
If fi.Extension.ToLower = ".csv" Then
|
|
|
|
If Not found Then
|
|
If readRMC(d) <> "" Then found = True
|
|
End If
|
|
If found Then cntDatenEingelesen += 1
|
|
End If
|
|
Case 2
|
|
|
|
'------------------------------------------
|
|
'------------------ PDF ------------------
|
|
'------------------------------------------
|
|
If fi.Extension.ToLower = ".pdf" Then
|
|
|
|
found = False
|
|
|
|
If Not System.IO.Directory.Exists(zielpfad & "Invoice_PDF\" & Now.Year & "\" & Now.ToString("yyyyMMdd") & "\") Then System.IO.Directory.CreateDirectory(zielpfad & Now.Year & "\" & Now.ToString("yyyyMMdd") & "\")
|
|
|
|
'File in Datenarchiv sichern:
|
|
|
|
|
|
'd.breimaier: 2024-06-05 aktuell nur die RMC-Dateien! (später, wenn CSV vollständig, dann alle PDFs importieren!
|
|
'd.breimaier: 2024-06-17 laut Christian Schuster von Comcore (EDV-BEtr. von RMC) nicht möglich CSV mit easytrip und sofico Datensätzen zu ergängen!
|
|
|
|
If fi.Name.ToString.StartsWith("invoice_") Then
|
|
|
|
Dim DS As New VERAG_PROG_ALLGEMEIN.cDATENSERVER("MDM", "MDM_DATEN", "RMC", Now.Year, Now.ToString("yyyyMMdd"), frmStartOptions.getFileName(d))
|
|
|
|
DS.uploadDataToDATENSERVER(d,,,,,, True)
|
|
|
|
SQL.doSQL("Update [tblRMCImport] SET [rmc_daId]='" & DS.da_id & "' where [rmc_pdfFileName] = '" & DS.da_name & "' and [rmc_importDatum] > DATEADD(DAY,-4,getdate()) ", "FMZOLL")
|
|
|
|
End If
|
|
|
|
'copy file to lydia
|
|
|
|
Dim filepathToLydia = IIf(rmc.PDFRECHNUNGEN <> "", rmc.PDFRECHNUNGEN, "\\share01\F\Juricevic Datensicherung\RMC_RECHNUNGEN\")
|
|
If Dateiname.ToString.ToLower.Contains("nto") Then
|
|
frmStartOptions.copyFile(d, filepathToLydia & "NETTO\")
|
|
Else
|
|
frmStartOptions.copyFile(d, filepathToLydia & "BRUTTO\")
|
|
End If
|
|
|
|
|
|
frmStartOptions.moveFile_DateBack(d, zielpfad & "Invoice_PDF\" & Now.Year & "\" & Now.ToString("yyyyMMdd") & "\")
|
|
If fi.Name.ToLower.Contains("pdf") Then addDGVEinarbeitung("PDF", fi.Name)
|
|
dgvEinarbeitung.Refresh()
|
|
|
|
End If
|
|
|
|
|
|
End Select
|
|
|
|
|
|
ElseIf programName.Contains("UTA") Then
|
|
|
|
Select Case i
|
|
|
|
Case 1
|
|
'------------------------------------------
|
|
'------------------ .UTA ------------------
|
|
'------------------------------------------
|
|
|
|
'If Not deleteTable Then
|
|
' deleteTable = uta.clearimporttable()
|
|
'End If
|
|
|
|
If fi.Extension.ToLower = ".uta" Then
|
|
|
|
If Not found Then
|
|
|
|
If readUTA(d) <> "" Then found = True
|
|
|
|
End If
|
|
|
|
If found Then cntDatenEingelesen += 1
|
|
End If
|
|
|
|
Case 2
|
|
'------------------------------------------
|
|
'------------------ .PDF ------------------
|
|
'------------------------------------------
|
|
'PDFs über EEA und Zugpfrd
|
|
If fi.Extension.ToLower = ".pdf" Then
|
|
|
|
If True Then 'Not System.IO.Directory.Exists(zielpfad & "Invoice_PDF\" & Now.Year & "\" & Now.ToString("yyyyMMdd") & "\") Then System.IO.Directory.CreateDirectory(zielpfad & Now.Year & "\" & Now.ToString("yyyyMMdd") & "\")
|
|
|
|
If fi.Name.ToString.StartsWith("AP") Then
|
|
|
|
Dim DS As New VERAG_PROG_ALLGEMEIN.cDATENSERVER("MDM", "MDM_DATEN", "UTA", Now.Year, Now.ToString("yyyyMMdd"), frmStartOptions.getFileName(d))
|
|
|
|
DS.uploadDataToDATENSERVER(d,,,,,, True)
|
|
|
|
|
|
'zugferd-Daten aus pdf auslesen!
|
|
|
|
'1 Read your PDF
|
|
'2 Get the catalog inside your PDF
|
|
'3 Get the Array with name AF from Catalog
|
|
'4 Get first element from AF array (should be file spec)
|
|
'5 From file spec get the dictionary named EF
|
|
'6 Get the stream content of EF
|
|
|
|
Try
|
|
|
|
Dim invoiceNr As String = ""
|
|
Dim invoiceDate As String = ""
|
|
Dim UTA_Beleg_ID As String = ""
|
|
Dim doc = New Spire.Pdf.PdfDocument()
|
|
doc.LoadFromFile(fi.FullName)
|
|
|
|
Dim pdfAtt = doc.Attachments(0)
|
|
If pdfAtt.FileName = "ZUGFeRD-invoice.xml" Then
|
|
|
|
Dim filename = Path.GetFileName(pdfAtt.FileName)
|
|
File.WriteAllBytes(filename, pdfAtt.Data)
|
|
|
|
Dim docxml As New XmlDocument()
|
|
docxml.Load(New XmlTextReader(filename))
|
|
If docxml.HasChildNodes Then
|
|
|
|
If docxml.GetElementsByTagName("rsm:ExchangedDocument").Count > 0 Then
|
|
Dim count As Integer = 1
|
|
For Each node As XmlElement In docxml.GetElementsByTagName("rsm:ExchangedDocument")
|
|
If node.HasChildNodes Then
|
|
For Each element As XmlElement In node.ChildNodes
|
|
If element.Name = "ram:ID" AndAlso element.InnerText <> "" Then invoiceNr = element.InnerText 'Rechnungsnummer
|
|
If element.Name = "ram:IssueDateTime" AndAlso element.InnerText <> "" Then invoiceDate = element.InnerText
|
|
|
|
Next
|
|
|
|
count = count + 1
|
|
|
|
End If
|
|
Next
|
|
|
|
End If
|
|
|
|
End If
|
|
End If
|
|
|
|
If UTA_Beleg_ID <> "" Then
|
|
'TO DO -> ÄNDERN----------------------
|
|
If SQL.doSQL("Update [tblUTAImportNew] SET [daId]='" & DS.da_id & "' where [UTA_Beleg_ID] = '" & UTA_Beleg_ID & "' ", "FMZOLL") Then
|
|
frmStartOptions.moveFile_DateBack(d, zielpfad & "Invoice_PDF\" & Now.Year & "\" & Now.ToString("yyyyMMdd") & "\")
|
|
End If
|
|
'TO DO -> ÄNDERN----------------------
|
|
End If
|
|
|
|
|
|
Catch ex As System.Exception
|
|
End Try
|
|
|
|
End If
|
|
|
|
End If
|
|
End If
|
|
|
|
If fi.Name.ToLower.Contains("pdf") Then addDGVEinarbeitung("PDF", fi.Name)
|
|
dgvEinarbeitung.Refresh()
|
|
|
|
End Select
|
|
|
|
|
|
ElseIf programName.Contains("IDS") Then
|
|
|
|
Select Case i
|
|
|
|
Case 1
|
|
'------------------------------------------
|
|
'------------------ .CSV ------------------
|
|
'------------------------------------------
|
|
|
|
|
|
If fi.Extension.ToLower = ".csv" Then
|
|
|
|
If Not found Then
|
|
|
|
If readIDS(d) <> "" Then found = True
|
|
|
|
End If
|
|
|
|
If found Then cntDatenEingelesen += 1
|
|
End If
|
|
|
|
Case 2
|
|
'------------------------------------------
|
|
'------------------ .PDF ------------------
|
|
'------------------------------------------
|
|
|
|
If fi.Extension.ToLower = ".pdf" Then
|
|
|
|
If True Then
|
|
|
|
|
|
|
|
|
|
Dim DS As New VERAG_PROG_ALLGEMEIN.cDATENSERVER("MDM", "MDM_DATEN", "IDS", Now.Year, Now.ToString("yyyyMMdd"), frmStartOptions.getFileName(d))
|
|
|
|
If DS.uploadDataToDATENSERVER(d,,,,,, True) Then
|
|
If SQL.doSQL("Update [tblIDSInvoicesNew] SET [daId]='" & DS.da_id & "' where [DocumentName] = '" & DS.da_name & "' ", "FMZOLL") Then
|
|
frmStartOptions.moveFile_DateBack(d, zielpfad & "Invoice_PDF\" & Now.Year & "\" & Now.ToString("yyyyMMdd") & "\")
|
|
End If
|
|
End If
|
|
|
|
Try
|
|
|
|
Catch ex As System.Exception
|
|
End Try
|
|
|
|
End If
|
|
|
|
End If
|
|
|
|
|
|
If fi.Name.ToLower.Contains("pdf") Then addDGVEinarbeitung("PDF", fi.Name)
|
|
dgvEinarbeitung.Refresh()
|
|
|
|
End Select
|
|
|
|
|
|
|
|
End If
|
|
If True Then
|
|
If Not alreadyMoved Then
|
|
If found Then
|
|
If Not System.IO.Directory.Exists(zielpfad & Now.Year & "\" & Now.ToString("yyyyMMdd") & "\") Then System.IO.Directory.CreateDirectory(zielpfad & Now.Year & "\" & Now.ToString("yyyyMMdd") & "\")
|
|
frmStartOptions.moveFile_DateBack(d, zielpfad & Now.Year & "\" & Now.ToString("yyyyMMdd") & "\")
|
|
End If
|
|
End If
|
|
End If
|
|
End If
|
|
Me.Refresh()
|
|
|
|
|
|
|
|
Catch ex As System.Exception
|
|
VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace & vbNewLine & "Datei: " & Dateiname, System.Reflection.MethodInfo.GetCurrentMethod.Name)
|
|
End Try
|
|
Next
|
|
Next
|
|
|
|
If programName.Contains("UTA") Then uta.importUTALeistungen()
|
|
|
|
End Sub
|
|
|
|
|
|
|
|
|
|
Private Sub btnOK_Click(sender As Object, e As EventArgs) Handles btnOK.Click
|
|
Me.Close()
|
|
End Sub
|
|
|
|
Private Sub btn_Click(sender As Object, e As EventArgs) Handles btn.Click
|
|
Me.Close()
|
|
End Sub
|
|
|
|
|
|
|
|
Sub addDGVEinarbeitung(art, BezugsNr)
|
|
dgvEinarbeitung.Rows.Add(art, BezugsNr)
|
|
Try
|
|
dgvEinarbeitung.FirstDisplayedScrollingRowIndex = dgvEinarbeitung.RowCount - 1
|
|
Catch ex As System.Exception
|
|
End Try
|
|
End Sub
|
|
|
|
|
|
Function readRMC(d As String) As String
|
|
Try
|
|
|
|
Dim fi As FileInfo = New FileInfo(d)
|
|
Dim kdNr = ""
|
|
|
|
Dim filetimestamp = Regex.Replace(fi.Name, "[^\d]", "") 'entferne alle nicht numerischen Werte!
|
|
Dim fileNr = filetimestamp.Substring(0, IIf(filetimestamp.Length > 8, filetimestamp.Length - 8, filetimestamp.Length))
|
|
Dim fileType = IIf(fi.Name.ToLower.Contains("nto"), "netto", "brutto")
|
|
|
|
Dim dt As New DataTable
|
|
dt.Columns.Add("KundenNr", GetType(String))
|
|
dt.Columns.Add("Kunde", GetType(String))
|
|
dt.Columns.Add("UID", GetType(String))
|
|
|
|
|
|
Using MyReader As New Microsoft.VisualBasic.FileIO.TextFieldParser(d, Encoding.GetEncoding(1252))
|
|
|
|
MyReader.TextFieldType = FileIO.FieldType.Delimited
|
|
MyReader.SetDelimiters(";")
|
|
Dim currentRow As String()
|
|
|
|
|
|
|
|
Dim cnt = 0
|
|
Dim firstLine = True
|
|
|
|
While Not MyReader.EndOfData
|
|
Try
|
|
|
|
currentRow = MyReader.ReadFields()
|
|
If firstLine Then
|
|
If SQL.isleernothing(currentRow(0)) = "KundenNr" Then
|
|
firstLine = False
|
|
Else
|
|
createRMC(fi, fileNr, filetimestamp, currentRow, fileType, kdNr, cnt, dt)
|
|
End If
|
|
Else
|
|
|
|
createRMC(fi, fileNr, filetimestamp, currentRow, fileType, kdNr, cnt, dt)
|
|
|
|
End If
|
|
|
|
Catch ex As System.Exception
|
|
VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace & vbNewLine & "Datei: " & Dateiname, System.Reflection.MethodInfo.GetCurrentMethod.Name)
|
|
End Try
|
|
End While
|
|
readRMC = "Zeilen: " & cnt
|
|
End Using
|
|
|
|
addDGVEinarbeitung("RMC: Detail" & kdNr, readRMC)
|
|
|
|
If dt.Rows.Count > 0 Then
|
|
Dim filepath = VERAG_PROG_ALLGEMEIN.cProgramFunctions.genExcelFromDT_NEW(dt,,,,, False,)
|
|
If filepath <> "" Then
|
|
Dim anhenge As New List(Of String)
|
|
anhenge.Add(filepath)
|
|
VERAG_PROG_ALLGEMEIN.cProgramFunctions.sendMail("juricevic@verag.ag", "Wölfl-UIDNr", "Im Anhang die zu prüfenden Kunden von WÖLFL für Importdatei: " & fi.Name & vbNewLine & "Pro Importdatei wird ein Email generiert/gesendet" & vbNewLine & "*Automatic generated e-mail*",,,,, "d.breimaier@verag.ag", anhenge)
|
|
End If
|
|
|
|
End If
|
|
|
|
Catch ex As System.Exception
|
|
VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace & vbNewLine & "Datei: " & Dateiname, System.Reflection.MethodInfo.GetCurrentMethod.Name)
|
|
MsgBox(ex.StackTrace & ex.Message)
|
|
readRMC = ""
|
|
End Try
|
|
End Function
|
|
|
|
|
|
Function readUTA(d As String) As String
|
|
Try
|
|
|
|
Dim fi As FileInfo = New FileInfo(d)
|
|
Dim cnt = 0
|
|
Dim objFileRead As StreamReader = New StreamReader(d)
|
|
|
|
|
|
If uta.readAndSaveUTA(objFileRead, fi, cnt) Then
|
|
addDGVEinarbeitung(fi.Name, "OK")
|
|
Else
|
|
addDGVEinarbeitung(fi.Name, "Fehler")
|
|
End If
|
|
|
|
readUTA = "Zeilen: " & cnt
|
|
|
|
Catch ex As System.Exception
|
|
VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace & vbNewLine & "Datei: " & Dateiname, System.Reflection.MethodInfo.GetCurrentMethod.Name)
|
|
MsgBox(ex.StackTrace & ex.Message)
|
|
End Try
|
|
|
|
|
|
End Function
|
|
|
|
Function readIDS(d As String) As String
|
|
Try
|
|
|
|
Dim fi As FileInfo = New FileInfo(d)
|
|
Dim cnt = 0
|
|
Dim objFileRead As StreamReader = New StreamReader(d)
|
|
|
|
|
|
If ids.readAndSaveIDS(objFileRead, fi, cnt) Then
|
|
addDGVEinarbeitung(fi.Name, "OK")
|
|
Else
|
|
addDGVEinarbeitung(fi.Name, "Fehler")
|
|
End If
|
|
|
|
readIDS = "Zeilen: " & cnt
|
|
|
|
Catch ex As System.Exception
|
|
VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace & vbNewLine & "Datei: " & Dateiname, System.Reflection.MethodInfo.GetCurrentMethod.Name)
|
|
MsgBox(ex.StackTrace & ex.Message)
|
|
End Try
|
|
|
|
|
|
End Function
|
|
|
|
|
|
Private Sub dgvEinarbeitung_SelectionChanged(sender As Object, e As EventArgs) Handles dgvEinarbeitung.SelectionChanged
|
|
dgvEinarbeitung.ClearSelection()
|
|
|
|
End Sub
|
|
|
|
|
|
Private Sub frmTCNachrichtenVerarbeitung_Shown(sender As Object, e As EventArgs) Handles Me.Shown
|
|
If allowClose Then
|
|
Me.Refresh()
|
|
|
|
Button2.PerformClick()
|
|
Button1.PerformClick()
|
|
|
|
System.Threading.Thread.Sleep(2000)
|
|
|
|
Me.Close()
|
|
End If
|
|
End Sub
|
|
|
|
Private Sub createRMC(fi As FileInfo, filenr As Integer, filetimestamp As String, currentRow As String(), fileType As String, ByRef kdNr As String, cnt As Integer, dt As DataTable)
|
|
|
|
Dim RMC As New VERAG_PROG_ALLGEMEIN.cRMC
|
|
RMC.rmc_file = fi.Name
|
|
RMC.rmc_version = filetimestamp
|
|
RMC.rmc_fileNr = filenr
|
|
RMC.rmc_kdNr = SQL.isleernothing(currentRow(0))
|
|
RMC.rmc_kdName = SQL.isleernothing(currentRow(1))
|
|
RMC.rmc_fibuNr = SQL.isleernothing(currentRow(2))
|
|
RMC.rmc_UID = SQL.isleernothing(currentRow(3))
|
|
RMC.rmc_landKZ = SQL.isleernothing(currentRow(4))
|
|
RMC.rmc_landBezeichnung = SQL.isleernothing(currentRow(5))
|
|
RMC.rmc_reDatum = SQL.isleernothing(currentRow(6))
|
|
RMC.rmc_sammelReNr = SQL.isleernothing(currentRow(7))
|
|
RMC.rmc_reNr = SQL.isleernothing(currentRow(8))
|
|
RMC.rmc_betragNetto = SQL.isleernothing(currentRow(9))
|
|
RMC.rmc_betragMWST = SQL.isleernothing(currentRow(10))
|
|
RMC.rmc_betragBrutto = SQL.isleernothing(currentRow(11))
|
|
|
|
Dim waherung = SQL.isleernothing(currentRow(12))
|
|
If waherung IsNot Nothing Then
|
|
RMC.rmc_waehrung = IIf(waherung.ToString.Length > 3, waherung.ToString.Substring(0, 3), waherung)
|
|
End If
|
|
|
|
RMC.rmc_euroBrutto = SQL.isleernothing(currentRow(13))
|
|
RMC.rmc_pdfFileName = "invoice_" & RMC.rmc_kdNr & "_" & filenr & "_" & RMC.rmc_sammelReNr & IIf(fileType = "netto", "_nto_e_verag.pdf", "_bto_e_verag.pdf")
|
|
|
|
If RMC.SAVE() Then
|
|
If kdNr <> RMC.rmc_kdNr Then
|
|
Dim adress As New VERAG_PROG_ALLGEMEIN.cAdressen(RMC.rmc_UID, RMC.rmc_kdNr)
|
|
If Not adress.hasEntry Then
|
|
Dim R As DataRow = dt.NewRow
|
|
R("KundenNr") = RMC.rmc_kdNr
|
|
R("Kunde") = RMC.rmc_kdName
|
|
R("UID") = RMC.rmc_UID
|
|
dt.Rows.Add(R)
|
|
End If
|
|
'If adress IsNot Nothing Then adress.UpdateSpecialField("WölflKundenNr", RMC.rmc_kdNr) -> nicht updaten, sondern nur info ausgeben!
|
|
End If
|
|
|
|
kdNr = RMC.rmc_kdNr
|
|
cnt += 1
|
|
End If
|
|
|
|
End Sub
|
|
|
|
|
|
End Class
|
|
|