2024-10-11 08:40:00 +02:00

223 lines
9.5 KiB
VB.net

Imports System.IO
Imports System.Security.Cryptography
Imports DigitalData.Modules
Imports DigitalData.Modules.Database
Imports DigitalData.Modules.Interfaces
Imports DigitalData.Modules.Jobs
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, "ZuiJA6OdjNXB7Fj_kVP7eoRF9zkM8frhIUa_-Pow6nUY2K1MrYaL0jF9_ppuVSVHuSIXQ201E7gGtpDxV21nByMTgW8VH9qp2w3Ziz2nib048QjknObNOZlx5t7CrhR1BmTVJfvDPQiLcGnRfqQnO03OfVPnIIjHWPs471dZWg79tB-VysgIvH-RmkWVKUPfkn9u5GfKfJ0ybGnQ7v4bKOWFwEnzxmWWouVv3XmUEZRh2lmubbHN9Qb752c486ndLHzjPRPFH2QcevziOcQ3_bEWCnIdqh8y6gpbRFTnXPZqCxlMuLPK-aJLm6ViF2M7EHWDSuThI2FId4zyuTf6-3K0hTw3ntPDCsd0dZW5CKSy0dpH6cDw9tUv_AxMp3UOkx_yo_GQCB273I9zLJae5Z0m5fUrqh3kfQ8pHCU5uDkLVo26NbQdOdX95LKX_RMsmtRYF8FSlj500TMcOMc3dPpqrh6-FA2LMpu86JHzZ2p_80MQ0kxa5chuCDA2z1Lx3CGMa9CAIEJgpCoI-wzSfmAcyeCnWoacV7k_klGci3l-dWbNIr_CPU6yrENhQaBfkqQoIYl5wECbL-WvsuBfRDvHDF0yyw_VoxUJ3hpH_q3mSlMrFuVKQtJcMnz8H81KoYwJn2zbNlCbyg6FH1VMl39UVhB2rB5W4S7llmbqEk4XJbx7Z7Ag5p-bktuwri7Exweq0DWOw85e-kv8T0d8prj2BRMOsDD7_Hjgz7iTgkU5_cS-5qGSWCjDpPRen5rL", 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 As String = 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',.XMLPath = xmlPath.Replace(".Value", "")
})
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,
.MinFileAgeInMinutes = 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 = ""
ListBox1.Items.Clear()
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("XML-Schema: " & oResult.UsedXMLSchema)
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.ToString) ''Prop.Description
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