82 lines
3.2 KiB
VB.net
82 lines
3.2 KiB
VB.net
Imports System.IO
|
|
Imports System.Reflection
|
|
Imports System.Text.RegularExpressions
|
|
Imports System.Xml
|
|
Imports DigitalData.Modules
|
|
Imports DigitalData.Modules.Database
|
|
Imports DigitalData.Modules.Interfaces
|
|
Imports DigitalData.Modules.Jobs.ImportZUGFeRDFiles
|
|
Imports DigitalData.Modules.Logging
|
|
|
|
Public Class Form1
|
|
|
|
Public Const ZUGFERD_IN = "ZUGFeRD in"
|
|
Public Const ZUGFERD_ERROR = "ZUGFeRD Error"
|
|
Public Const ZUGFERD_SUCCESS = "ZUGFeRD Success"
|
|
|
|
Private _logConfig As LogConfig
|
|
Private _firebird As Firebird
|
|
|
|
Private PropertyMap As New Dictionary(Of String, String)
|
|
|
|
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
|
|
_logConfig = New LogConfig(LogConfig.PathType.CurrentDirectory)
|
|
_logConfig.Debug = True
|
|
_firebird = New Firebird(_logConfig, My.Settings.FB_DATASOURCE, My.Settings.FB_DATABASE, My.Settings.FB_USER, My.Settings.FB_PASS)
|
|
|
|
PropertyMap.Add("TBEDM_INVOICE_HEAD.INVOICE_NR", "HeaderExchangedDocument.ID.Value")
|
|
PropertyMap.Add("TBEDM_INVOICE_HEAD.DOC_TYPE", "HeaderExchangedDocument.Name(0).Value")
|
|
PropertyMap.Add("TBEDM_INVOICE_HEAD.INVOICE_DATE", "HeaderExchangedDocument.IssueDateTime.Item.Value")
|
|
PropertyMap.Add("TBEDM_INVOICE_HEAD.INVOICE_DATE_FORMAT", "HeaderExchangedDocument.IssueDateTime.Item.format")
|
|
PropertyMap.Add("TBEDM_INVOICE_HEAD.NOTE", "HeaderExchangedDocument.IncludedNote(0).Content(0).Value")
|
|
End Sub
|
|
|
|
Private Function LoadFolderConfig(args As WorkerArgs)
|
|
Dim oSQL As String = "SELECT T1.FOLDER_TYPE, T.FOLDER_PATH FROM TBEDM_FOLDER T, TBEDM_FOLDER_TYPE T1 WHERE T.FOLDER_TYPE_ID = T1.GUID AND T1.""ACTIVE"" = True AND T.""ACTIVE"" = True"
|
|
Dim oResult As DataTable = _firebird.GetDatatable(oSQL)
|
|
|
|
For Each row As DataRow In oResult.Rows
|
|
Dim oFolderType = row.Item("FOLDER_TYPE")
|
|
|
|
Select Case oFolderType
|
|
Case ZUGFERD_IN
|
|
args.WatchDirectories.Add(row.Item("FOLDER_PATH"))
|
|
|
|
Case ZUGFERD_SUCCESS
|
|
args.SuccessDirectory = row.Item("FOLDER_PATH")
|
|
|
|
Case ZUGFERD_ERROR
|
|
args.ErrorDirectory = row.Item("FOLDER_PATH")
|
|
|
|
End Select
|
|
Next
|
|
|
|
Return args
|
|
End Function
|
|
|
|
Private Function LoadPropertyMapFor(args As WorkerArgs, specification As String)
|
|
Dim oSQL As String = $"SELECT * FROM TBEDM_XML_ITEMS WHERE SPECIFICATION = '{specification}' AND ACTIVE = True"
|
|
Dim oResult As DataTable = _firebird.GetDatatable(oSQL)
|
|
|
|
For Each row As DataRow In oResult.Rows
|
|
Dim xmlPath = row.Item("XML_PATH")
|
|
Dim tableName = row.Item("TABLE_NAME")
|
|
Dim tableColumn = row.Item("TABLE_COLUMN")
|
|
|
|
args.PropertyMap.Add($"{tableName}.{tableColumn}", xmlPath)
|
|
Next
|
|
|
|
Return args
|
|
End Function
|
|
|
|
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
|
|
Dim args As New WorkerArgs()
|
|
args = LoadFolderConfig(args)
|
|
args = LoadPropertyMapFor(args, "ZUGFeRD-Invoice")
|
|
|
|
Dim job As New Jobs.ImportZUGFeRDFiles(_logConfig, _firebird)
|
|
|
|
job.Start(args)
|
|
End Sub
|
|
End Class
|