Imports Syncfusion.Pdf.Parsing Imports Syncfusion.Pdf Public Class clspdfhelper Public Enum GetEmpfaengerType FromFaktura FromLastFaktura Andere FromCollection End Enum Public Function ConCatPDF(Optional DeleteSource As Boolean = True) As String Dim document As New PdfDocument document.EnableMemoryOptimization = False Dim newfi As String Dim newfn As String Dim pdfitem As clspdfcollectionitem For i = 1 To Globals.pdfCollection.Count pdfitem = Globals.pdfCollection.Item(i) If i = 1 Then newfn = System.IO.Path.GetDirectoryName(pdfitem.Path) newfi = System.IO.Path.GetFileName(pdfitem.Path) 'newfn = System.IO.Path.GetDirectoryName(Globals.pdfCollection.Item(i).ToString) 'newfi = System.IO.Path.GetFileName(Globals.pdfCollection.Item(i).ToString) newfi = newfi.Replace(".pdf", "_concat.pdf") newfn = newfn + "\" + newfi End If Dim loadeddocument As New PdfLoadedDocument(pdfitem.Path) 'Dim loadeddocument As New PdfLoadedDocument(Globals.pdfCollection.Item(i).ToString) loadeddocument.EnableMemoryOptimization = False document.ImportPageRange(loadeddocument, 0, loadeddocument.Pages.Count - 1) loadeddocument = Nothing Next document.Save(newfn) document.Close() document.Dispose() If DeleteSource Then For i = 1 To Globals.pdfCollection.Count pdfitem = Globals.pdfCollection.Item(i) ' System.IO.File.Delete(Globals.pdfCollection.Item(i)) System.IO.File.Delete(pdfitem.Path) Next End If Return newfn End Function Public Sub HandlePDF(ByVal alsPDF As Boolean, ByVal alsMail As Boolean, Optional Mailtext As Integer = 0, Optional empfaengertyp As clsMailClient.EmpfangerFrom = clsMailClient.EmpfangerFrom.Behandlung, Optional keyvalue As Integer = 0) Dim pdfitem As clspdfcollectionitem If alsPDF = True Then If Globals.pdfCollection.Count > 1 Then If alsMail = False Then Process.Start(ConCatPDF()) If alsMail = True Then Dim em As New clsMailClient em.CreateOutlookMail(empfaengertyp, keyvalue, ConCatPDF(), Mailtext) End If Else pdfitem = Globals.pdfCollection.Item(1) If alsMail = False Then Process.Start(pdfitem.Path) 'If alsMail = False Then Process.Start(Globals.pdfCollection.Item(1)) If alsMail = True Then Dim email As New clsMailClient ' email.CreateOutlookMail(empfaengertyp, keyvalue, Globals.pdfCollection.Item(1), Mailtext) email.CreateOutlookMail(empfaengertyp, keyvalue, pdfitem.Path, Mailtext) End If End If pdfCollection.Clear() End If End Sub Public Sub Create_Archivdoc(ByVal From As GetEmpfaengerType, Optional keyvalue As String = "", Optional Bezeichnung As String = "") If Globals.License.DMS = False Then Exit Sub Dim s As String Dim tmpcollection As New Collection For i = 1 To Globals.pdfCollection.Count tmpcollection.Add(Globals.pdfCollection.Item(i)) Next i Globals.pdfCollection.Clear() Dim tmpcolitem As clspdfcollectionitem Dim fakturanralt As Integer tmpcolitem = tmpcollection.Item(1) fakturanralt = tmpcolitem.fakturanr Globals.pdfCollection.Add(tmpcollection.Item(1)) If tmpcollection.Count > 1 Then For i = 2 To tmpcollection.Count tmpcolitem = tmpcollection.Item(i) If tmpcolitem.fakturanr <> fakturanralt Then fakturanralt = tmpcolitem.fakturanr s = ConCatPDF(False) save_doc_to_db(s, Bezeichnung, 0, 0, From) Globals.pdfCollection.Clear() Globals.pdfCollection.Add(tmpcollection.Item(i)) Else Globals.pdfCollection.Add(tmpcollection.Item(i)) End If Next End If If Globals.pdfCollection.Count > 0 Then s = ConCatPDF(False) save_doc_to_db(s, Bezeichnung, 0, 0, From) End If Globals.pdfCollection.Clear() For i = 1 To tmpcollection.Count Globals.pdfCollection.Add(tmpcollection.Item(i)) Next End Sub Private Sub save_doc_to_db(ByVal ifilename As String, ByVal bezeichnung As String, ByVal patient As Integer, ByVal debitor As Integer, ByVal From As GetEmpfaengerType) Dim s As String Dim db As New clsDB Dim Fakturadb As New clsDB Dim StrukturEintrag_Patient As Integer Dim StrukturEintrag_Garant As Integer Dim CopyDocToGarant As String Dim nrfaktura As Integer Dim Patientname As String Dim Fakturanr As String Dim pcolitem As clspdfcollectionitem If From = GetEmpfaengerType.FromLastFaktura Then Fakturadb.Get_Tabledata("Faktura", "", "Select top 1 * from faktura order by nrfaktura desc") Fakturanr = Fakturadb.dsDaten.Tables(0).Rows(0).Item("nrfaktura") End If If From = GetEmpfaengerType.FromFaktura Then pcolitem = Globals.pdfCollection.Item(1) Fakturadb.Get_Tabledata("Faktura", "", "Select top 1 * from faktura WHeRE NRFAKTURA=" + pcolitem.fakturanr.ToString + " order by nrfaktura desc") Fakturanr = pcolitem.fakturanr End If patient = Fakturadb.dsDaten.Tables(0).Rows(0).Item("nrpatient") debitor = Fakturadb.dsDaten.Tables(0).Rows(0).Item("nrdebitor") bezeichnung = bezeichnung + " " + Fakturanr.ToString If Globals.License.DMS = True Then db.Get_Tabledata("DMS", "", "Select wert from dms_settings where nreintrag=8") StrukturEintrag_Patient = db.dsDaten.Tables(0).Rows(0).Item(0) db.Get_Tabledata("DMS", "", "Select wert from dms_settings where nreintrag=9") StrukturEintrag_Garant = db.dsDaten.Tables(0).Rows(0).Item(0) db.Get_Tabledata("DMS", "", "Select wert from dms_settings where nreintrag=10") CopyDocToGarant = db.dsDaten.Tables(0).Rows(0).Item(0) 'Patienten-Dokumente Dim dok As New clsDok Dim Directoryname As String = System.IO.Path.GetDirectoryName(ifilename) Dim Filename As String = System.IO.Path.GetFileName(ifilename) Dim DestFilename As String DestFilename = System.IO.Path.GetFileNameWithoutExtension(Filename) + "_" + patient.ToString + System.IO.Path.GetExtension(Filename) System.IO.File.Copy(Directoryname + "\" + Filename, Directoryname + "\" + DestFilename) dok.Create_Doc(StrukturEintrag_Patient, bezeichnung, Directoryname + "\" + DestFilename, patient, Fakturanr) System.IO.File.Delete(Directoryname + "\" + DestFilename) If CopyDocToGarant = True And patient <> debitor Then DestFilename = System.IO.Path.GetFileNameWithoutExtension(Filename) + "_fuer_" + patient.ToString + System.IO.Path.GetExtension(Filename) System.IO.File.Copy(Directoryname + "\" + Filename, Directoryname + "\" + DestFilename) dok.Create_Doc(StrukturEintrag_Garant, bezeichnung, Directoryname + "\" + DestFilename, debitor, Fakturanr) System.IO.File.Delete(Directoryname + "\" + DestFilename) End If dok = Nothing db.Dispose() End If End Sub End Class Public Class clspdfcollectionitem Dim m_fakturanr As String Property fakturanr As String Get Return m_fakturanr End Get Set(value As String) m_fakturanr = value End Set End Property Dim m_path As String Property Path As String Get Return m_path End Get Set(value As String) m_path = value End Set End Property Sub New(ByVal fakturanr As String, path As String) Me.fakturanr = fakturanr Me.Path = path End Sub End Class