224 lines
8.7 KiB
VB.net
224 lines
8.7 KiB
VB.net
Imports System.IO
|
|
Imports System.Reflection
|
|
Imports System.Security.Cryptography
|
|
Imports System.Text.RegularExpressions
|
|
Imports System.Xml
|
|
Imports DigitalData.Modules
|
|
Imports DigitalData.Modules.Database
|
|
Imports DigitalData.Modules.Interfaces
|
|
Imports DigitalData.Modules.Jobs
|
|
Imports DigitalData.Modules.Jobs.ImportZUGFeRDFiles
|
|
Imports DigitalData.Modules.Logging
|
|
|
|
Public Class Form1
|
|
Private _logConfig As LogConfig
|
|
Private _logger As Logger
|
|
Private _firebird As Firebird
|
|
Private _mssql As MSSQLServer
|
|
Private _zugferd As ZUGFeRDInterface
|
|
|
|
Private PropertyMap As New Dictionary(Of String, XmlItemProperty)
|
|
|
|
|
|
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
|
|
_logConfig = New LogConfig(LogConfig.PathType.CustomPath, Application.StartupPath & "\Log", Nothing, My.Application.Info.CompanyName, My.Application.Info.ProductName) With {
|
|
.Debug = True
|
|
}
|
|
_logger = _logConfig.GetLogger()
|
|
_mssql = New MSSQLServer(_logConfig, My.Settings.MSSQL_CONNECTIONSTRING)
|
|
|
|
_zugferd = New ZUGFeRDInterface(_logConfig, "21182889975216572111813147150675976632", New ZUGFeRDInterface.ZugferdOptions)
|
|
End Sub
|
|
|
|
Private Function LoadPropertyMapFor(Args As WorkerArgs)
|
|
Try
|
|
Dim oSQL As String = $"SELECT * FROM TBDD_ZUGFERD_XML_ITEMS WHERE ACTIVE = 1 ORDER BY XML_PATH"
|
|
Dim oResult As DataTable = _mssql.GetDatatable(oSQL)
|
|
|
|
For Each oRow As DataRow In oResult.Rows
|
|
Dim xmlPath = oRow.Item("XML_PATH")
|
|
Dim tableName = oRow.Item("TABLE_NAME")
|
|
Dim tableColumn = oRow.Item("TABLE_COLUMN")
|
|
Dim description = oRow.Item("DESCRIPTION")
|
|
Dim isRequired = oRow.Item("IS_REQUIRED")
|
|
Dim isGrouped = oRow.Item("IS_GROUPED")
|
|
Dim groupScope = oRow.Item("GROUP_SCOPE")
|
|
Dim specification = oRow.Item("SPECIFICATION")
|
|
|
|
Args.PropertyMap.Add(xmlPath, New XmlItemProperty() With {
|
|
.Description = description,
|
|
.TableName = tableName,
|
|
.TableColumn = tableColumn,
|
|
.IsRequired = isRequired,
|
|
.IsGrouped = isGrouped,
|
|
.GroupScope = groupScope,
|
|
.Specification = specification
|
|
})
|
|
Next
|
|
|
|
Return Args
|
|
Catch ex As Exception
|
|
_Logger.Error(ex)
|
|
Return Args
|
|
End Try
|
|
End Function
|
|
|
|
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
|
|
Dim oInputPath As String = "E:\TestFiles\ZUGFERDService\Input"
|
|
|
|
Dim DI As DirectoryInfo = New DirectoryInfo(oInputPath)
|
|
|
|
Dim oResult As DialogResult = DialogResult.OK
|
|
If DI.Exists = False Then
|
|
' Nur öffnen, wenn Pfad ungültig ist
|
|
oResult = FolderBrowserDialog1.ShowDialog()
|
|
oInputPath = FolderBrowserDialog1.SelectedPath
|
|
End If
|
|
|
|
If oResult = DialogResult.OK Then
|
|
Dim args As New WorkerArgs() With {
|
|
.MaxAttachmentSizeInMegaBytes = 10,
|
|
.IgnoreRejectionStatus = False,
|
|
.NamePortal = "TEST FROM FORM",
|
|
.WatchDirectory = oInputPath,
|
|
.SuccessDirectory = "E:\TestFiles\ZUGFERDService\Result\Success",
|
|
.ErrorDirectory = "E:\TestFiles\ZUGFERDService\Result\Error",
|
|
.OriginalEmailDirectory = "E:\TestFiles\ZUGFERDService\Result\Original_eml",
|
|
.RejectedEmailDirectory = "E:\TestFiles\ZUGFERDService\Result\Rejected_eml",
|
|
.AttachmentsSubDirectory = "Attachments",
|
|
.RejectionTemplateId = 1
|
|
}
|
|
args = LoadPropertyMapFor(args)
|
|
|
|
Dim job As New Jobs.ImportZUGFeRDFiles(_logConfig, _mssql)
|
|
|
|
job.Start(args)
|
|
End If
|
|
End Sub
|
|
|
|
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
|
|
Dim oResult = OpenFileDialog1.ShowDialog()
|
|
Dim oArgs As New WorkerArgs()
|
|
|
|
If oResult = DialogResult.OK Then
|
|
Try
|
|
Dim oDoc = _zugferd.ValidateZUGFeRDFileWithGDPicture(OpenFileDialog1.FileName)
|
|
Dim oZUGFERD = _zugferd.SerializeZUGFeRDDocument(oDoc)
|
|
Console.WriteLine()
|
|
Catch ex As Exception
|
|
MsgBox(ex.Message)
|
|
End Try
|
|
End If
|
|
End Sub
|
|
|
|
Public Sub WriteLog(pMessage As String, ParamArray pParams As String())
|
|
ListBox1.Items.Add(String.Format(pMessage, pParams))
|
|
End Sub
|
|
|
|
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
|
|
ListBox1.Text = ""
|
|
Dim oDialogResult = OpenFileDialog1.ShowDialog()
|
|
Dim oArgs As New WorkerArgs() With {
|
|
.AllowFacturX = False,
|
|
.AllowXRechnung = False
|
|
}
|
|
oArgs = LoadPropertyMapFor(oArgs)
|
|
|
|
Try
|
|
If oDialogResult = DialogResult.OK Then
|
|
Dim oDoc = _zugferd.ValidateZUGFeRDFileWithGDPicture(OpenFileDialog1.FileName)
|
|
Dim oResult = _zugferd.ValidateZUGFeRDDocument(oDoc)
|
|
oResult = _zugferd.SerializeZUGFeRDDocument(oDoc)
|
|
|
|
WriteLog("Specification: " & oResult.Specification)
|
|
WriteLog("Embedded File Name: " & oResult.DataFileName)
|
|
|
|
Dim oSpecification = oResult.Specification
|
|
|
|
If oSpecification = ZUGFeRDInterface.ZUGFERD_SPEC_10 Then
|
|
oSpecification = ZUGFeRDInterface.ZUGFERD_SPEC_DEFAULT
|
|
End If
|
|
|
|
Dim oPropertyMap = oArgs.PropertyMap.
|
|
Where(Function(kv) kv.Value.Specification = oSpecification).
|
|
ToDictionary(Function(kv) kv.Key, Function(kv) kv.Value)
|
|
|
|
Dim oResult2 = _zugferd.PropertyValues.CheckPropertyValues(oResult.SchemaObject, oPropertyMap, "test")
|
|
|
|
WriteLog("Valid Properties: [{0}]", oResult2.ValidProperties.Count)
|
|
For Each Prop In oResult2.ValidProperties
|
|
WriteLog("Property: [{0}] = [{1}]", Prop.Description, Prop.Value)
|
|
Next
|
|
|
|
WriteLog("Missing Properties: [{0}]", oResult2.MissingProperties.Count)
|
|
For Each Prop In oResult2.MissingProperties
|
|
WriteLog("Missing Property: [{0}]", Prop)
|
|
Next
|
|
|
|
WriteLog("--------------------------------")
|
|
End If
|
|
Catch ex As Exception
|
|
MsgBox(ex.Message)
|
|
End Try
|
|
|
|
End Sub
|
|
|
|
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
|
|
My.Settings.Save()
|
|
Dim result = checkMD5(txtMD5Checksum.Text)
|
|
If IsNothing(result) Then
|
|
MsgBox("Could not calculate MD5 Checksum")
|
|
Else
|
|
txtMD5Checksum.Text = result
|
|
End If
|
|
End Sub
|
|
Public Function checkMD5(ByVal filename As String) As String
|
|
Try
|
|
Dim MD5 As New MD5CryptoServiceProvider
|
|
Dim Hash As Byte()
|
|
Dim Result As String = ""
|
|
Dim Tmp As String = ""
|
|
|
|
Dim FN As New FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read, 8192)
|
|
MD5.ComputeHash(FN)
|
|
FN.Close()
|
|
|
|
Hash = MD5.Hash
|
|
Result = Strings.Replace(BitConverter.ToString(Hash), "-", "")
|
|
Return Result
|
|
Catch ex As Exception
|
|
Return Nothing
|
|
End Try
|
|
End Function
|
|
|
|
Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
|
|
Dim oResult = OpenFileDialog1.ShowDialog()
|
|
|
|
If oResult = DialogResult.OK Then
|
|
Dim oDoc = _zugferd.ValidateZUGFeRDFileWithGDPicture(OpenFileDialog1.FileName)
|
|
Dim oZUGFERD = _zugferd.SerializeZUGFeRDDocument(oDoc)
|
|
Dim oPropName As String = txtPropName.Text
|
|
|
|
Try
|
|
Dim oExtractor = New PropertyValues(_logConfig)
|
|
Dim oValue As List(Of Object) = oExtractor.GetPropValue(oZUGFERD, oPropName)
|
|
Dim oFinalValue As List(Of Object) = oExtractor.GetFinalPropValue(oValue)
|
|
Console.WriteLine()
|
|
|
|
Catch ex As Exception
|
|
MsgBox(ex.Message)
|
|
End Try
|
|
End If
|
|
End Sub
|
|
|
|
Private Sub Button7_Click(sender As Object, e As EventArgs) Handles Button7.Click
|
|
Dim oExtractor = New PDFEmbeds(_logConfig)
|
|
Dim oResult = OpenFileDialog1.ShowDialog()
|
|
Dim oExtensions = New List(Of String) From {"docx", "doc", "pdf", "xls", "xlsx", "ppt", "pptx", "txt", "xml"}
|
|
|
|
If oResult = DialogResult.OK Then
|
|
oExtractor.Extract(OpenFileDialog1.FileName, AllowedExtensions:=oExtensions)
|
|
End If
|
|
End Sub
|
|
End Class
|