first pass of creating report
This commit is contained in:
parent
788d7fac9f
commit
f8b30e1a06
@ -136,8 +136,9 @@
|
||||
<Compile Include="Entities\State.vb" />
|
||||
<Compile Include="Entities\User.vb" />
|
||||
<Compile Include="Helpers.vb" />
|
||||
<Compile Include="Jobs\CertificateDocumentJob.vb" />
|
||||
<Compile Include="Jobs\PDFBurner.vb" />
|
||||
<Compile Include="Jobs\FinalizeDocument\FinalizeDocumentExceptions.vb" />
|
||||
<Compile Include="Jobs\FinalizeDocument\FinalizeDocumentJob.vb" />
|
||||
<Compile Include="Jobs\FinalizeDocument\PDFBurner.vb" />
|
||||
<Compile Include="Models\BaseModel.vb" />
|
||||
<Compile Include="Models\CertificateModel.vb" />
|
||||
<Compile Include="Models\ChartModel.vb" />
|
||||
@ -150,6 +151,7 @@
|
||||
<Compile Include="Models\EnvelopeModel.vb" />
|
||||
<Compile Include="Models\HistoryModel.vb" />
|
||||
<Compile Include="Models\ReceiverModel.vb" />
|
||||
<Compile Include="Models\ReportModel.vb" />
|
||||
<Compile Include="Models\UserModel.vb" />
|
||||
<Compile Include="My Project\AssemblyInfo.vb" />
|
||||
<Compile Include="My Project\Application.Designer.vb">
|
||||
@ -167,9 +169,9 @@
|
||||
<DependentUpon>Settings.settings</DependentUpon>
|
||||
<DesignTimeSharedInput>True</DesignTimeSharedInput>
|
||||
</Compile>
|
||||
<Compile Include="Reports\ReportCreator.vb" />
|
||||
<Compile Include="Reports\ReportItem.vb" />
|
||||
<Compile Include="Reports\ReportSource.vb" />
|
||||
<Compile Include="Jobs\FinalizeDocument\ReportCreator.vb" />
|
||||
<Compile Include="Jobs\FinalizeDocument\ReportItem.vb" />
|
||||
<Compile Include="Jobs\FinalizeDocument\ReportSource.vb" />
|
||||
<Compile Include="Reports\rptEnvelopeHistory.Designer.vb">
|
||||
<DependentUpon>rptEnvelopeHistory.vb</DependentUpon>
|
||||
</Compile>
|
||||
|
||||
@ -0,0 +1,52 @@
|
||||
Namespace Jobs.FinalizeDocument
|
||||
Public Class FinalizeDocumentExceptions
|
||||
|
||||
Public Class MergeDocumentException
|
||||
Inherits ApplicationException
|
||||
|
||||
Public Sub New(message As String)
|
||||
MyBase.New(message)
|
||||
End Sub
|
||||
|
||||
Public Sub New(message As String, innerException As Exception)
|
||||
MyBase.New(message, innerException)
|
||||
End Sub
|
||||
End Class
|
||||
|
||||
Public Class BurnAnnotationException
|
||||
Inherits ApplicationException
|
||||
|
||||
Public Sub New(message As String)
|
||||
MyBase.New(message)
|
||||
End Sub
|
||||
|
||||
Public Sub New(message As String, innerException As Exception)
|
||||
MyBase.New(message, innerException)
|
||||
End Sub
|
||||
End Class
|
||||
|
||||
Public Class CreateReportException
|
||||
Inherits ApplicationException
|
||||
|
||||
Public Sub New(message As String)
|
||||
MyBase.New(message)
|
||||
End Sub
|
||||
|
||||
Public Sub New(message As String, innerException As Exception)
|
||||
MyBase.New(message, innerException)
|
||||
End Sub
|
||||
End Class
|
||||
Public Class ExportDocumentException
|
||||
Inherits ApplicationException
|
||||
|
||||
Public Sub New(message As String)
|
||||
MyBase.New(message)
|
||||
End Sub
|
||||
|
||||
Public Sub New(message As String, innerException As Exception)
|
||||
MyBase.New(message, innerException)
|
||||
End Sub
|
||||
End Class
|
||||
|
||||
End Class
|
||||
End Namespace
|
||||
@ -5,25 +5,31 @@ Imports GdPicture14
|
||||
Imports Quartz
|
||||
Imports System.Security.Cryptography
|
||||
Imports System.IO
|
||||
Imports EnvelopeGenerator.Common.Jobs.FinalizeDocument.FinalizeDocumentExceptions
|
||||
Imports EnvelopeGenerator.Common.Jobs.FinalizeDocument
|
||||
Imports System.Web.Caching
|
||||
Imports System.Web.UI
|
||||
|
||||
Namespace Jobs
|
||||
Public Class CertificateDocumentJob
|
||||
Public Class FinalizeDocumentJob
|
||||
Implements IJob
|
||||
|
||||
Private LicenseManager As New LicenseManager()
|
||||
Private ReadOnly LicenseManager As New LicenseManager()
|
||||
Private GdViewer As GdViewer
|
||||
|
||||
Private ConfigModel As ConfigModel
|
||||
Private EnvelopeModel As EnvelopeModel
|
||||
|
||||
Private LogConfig As LogConfig
|
||||
Private Logger As Logger
|
||||
Private Database As MSSQLServer
|
||||
Private Config As DbConfig
|
||||
|
||||
Private ConfigModel As ConfigModel
|
||||
Private EnvelopeModel As EnvelopeModel
|
||||
Private ReportModel As ReportModel
|
||||
|
||||
Private ActionService As ActionService
|
||||
|
||||
Private PDFBurner As PDFBurner
|
||||
Private ReportCreator As ReportCreator
|
||||
|
||||
Private Class EnvelopeData
|
||||
Public EnvelopeId As Integer
|
||||
@ -45,15 +51,19 @@ Namespace Jobs
|
||||
GdViewer = New GdViewer()
|
||||
LicenseManager.RegisterKEY(oGdPictureKey)
|
||||
|
||||
Logger.Debug("Loading PDFBurner..")
|
||||
PDFBurner = New PDFBurner(LogConfig, oGdPictureKey)
|
||||
|
||||
Logger.Debug("Loading Database..")
|
||||
Database = GetDatabase(pContext, LogConfig)
|
||||
|
||||
Logger.Debug("Loading Models & Services")
|
||||
InitializeModels()
|
||||
InitializeServices()
|
||||
Dim oState = GetState()
|
||||
InitializeModels(oState)
|
||||
InitializeServices(oState)
|
||||
|
||||
Logger.Debug("Loading PDFBurner..")
|
||||
PDFBurner = New PDFBurner(LogConfig, oGdPictureKey)
|
||||
|
||||
Logger.Debug("Loading ReportCreator..")
|
||||
ReportCreator = New ReportCreator(LogConfig, oState)
|
||||
|
||||
Logger.Debug("Loading Configuration..")
|
||||
Config = ConfigModel.LoadConfiguration()
|
||||
@ -65,130 +75,139 @@ Namespace Jobs
|
||||
Dim oSql = $"SELECT * FROM TBSIG_ENVELOPE WHERE STATUS = {oCompleteStatus}"
|
||||
Dim oTable = Database.GetDatatable(oSql)
|
||||
|
||||
|
||||
Dim oEnvelopeIds As List(Of Integer) = oTable.Rows.Cast(Of DataRow).
|
||||
Select(Function(r) r.Item("GUID")).
|
||||
Cast(Of Integer).
|
||||
ToList()
|
||||
|
||||
Logger.Info("Found [{0}] completed envelopes.", oEnvelopeIds.Count)
|
||||
Dim oTotal As Integer = oEnvelopeIds.Count
|
||||
Dim oCurrent As Integer = 1
|
||||
|
||||
For Each oId In oEnvelopeIds
|
||||
|
||||
Logger.Info("Finalizing Envelope [{0}]", oId)
|
||||
Dim oEnvelopeData = GetEnvelopeData(oId)
|
||||
Logger.Info("Finalizing Envelope [{0}] ({1}/{2})", oId, oCurrent, oTotal)
|
||||
|
||||
If oEnvelopeData Is Nothing Then
|
||||
Logger.Warn("EnvelopeData could not be loaded for Envelope [{0}]!", oId)
|
||||
Logger.Debug("Loading Envelope..")
|
||||
Dim oEnvelope = EnvelopeModel.GetById(oId)
|
||||
|
||||
If oEnvelope Is Nothing Then
|
||||
Logger.Warn("Envelope could not be loaded for Id [{0}]!", oId)
|
||||
Throw New ArgumentNullException("EnvelopeData")
|
||||
End If
|
||||
|
||||
If GenerateFinalPDF(oEnvelopeData) = False Then
|
||||
Logger.Debug("Loading Envelope Data..")
|
||||
Dim oEnvelopeData = GetEnvelopeData(oId)
|
||||
|
||||
If oEnvelopeData Is Nothing Then
|
||||
Logger.Warn("EnvelopeData could not be loaded for Id [{0}]!", oId)
|
||||
Throw New ArgumentNullException("EnvelopeData")
|
||||
End If
|
||||
|
||||
Logger.Debug("Burning Annotations to pdf")
|
||||
Dim oBurnedDocument As Byte() = BurnAnnotationsToPdf(oEnvelopeData)
|
||||
If oBurnedDocument Is Nothing Then
|
||||
Logger.Warn("Document could not be finalized!")
|
||||
Throw New ApplicationException("Document could not be finalized")
|
||||
End If
|
||||
|
||||
' Dim oReport As Byte() = Await GenerateReportPdf(oId)
|
||||
' MergeDocuments()
|
||||
Logger.Debug("Creating report..")
|
||||
Dim oReport As Byte() = ReportCreator.CreateReport(oEnvelope)
|
||||
|
||||
Dim oEnvelope = EnvelopeModel.GetById(oId)
|
||||
If oEnvelope Is Nothing Then
|
||||
Logger.Warn("Envelope could not loaded!")
|
||||
Throw New ApplicationException("Envelope could not loaded!")
|
||||
End If
|
||||
Logger.Debug("Merging documents..")
|
||||
Dim oMergedDocument As Byte() = MergeDocuments(oBurnedDocument, oReport)
|
||||
|
||||
Dim oOutputDirectoryPath = Config.ExportPath
|
||||
Dim oOutputFilePath = Path.Combine(oOutputDirectoryPath, $"{oEnvelope.Uuid}.pdf")
|
||||
|
||||
Logger.Info("Writing finalized Pdf to disk..")
|
||||
Logger.Info("Output path is [{0}]", oOutputFilePath)
|
||||
|
||||
Try
|
||||
File.WriteAllBytes(oOutputFilePath, oMergedDocument)
|
||||
Catch ex As Exception
|
||||
Throw New ExportDocumentException("Could not export final document to disk!", ex)
|
||||
Logger.Error(ex)
|
||||
End Try
|
||||
|
||||
Logger.Debug("Setting envelope status..")
|
||||
If ActionService.FinalizeEnvelope(oEnvelope) = False Then
|
||||
Logger.Warn("Envelope could not be finalized!")
|
||||
Throw New ApplicationException("Envelope could not be finalized")
|
||||
End If
|
||||
|
||||
oCurrent += 1
|
||||
Logger.Info("Envelope finalized!")
|
||||
|
||||
Next
|
||||
|
||||
Logger.Info("Completed job {0} successfully!", JobId)
|
||||
Catch ex As MergeDocumentException
|
||||
Logger.Warn("Certificate Document job failed at step: Merging documents!")
|
||||
Logger.Error(ex)
|
||||
|
||||
Catch ex As Exception
|
||||
Logger.Warn("Certificate Document job failed!")
|
||||
Logger.Error(ex)
|
||||
End Try
|
||||
|
||||
Logger.Info("Job execution for [{0}] ended", JobId)
|
||||
End Function
|
||||
|
||||
Private Function MergeDocuments(pDocumentPath As String, pReport As Byte())
|
||||
Private Function MergeDocuments(pDocument As Byte(), pReport As Byte()) As Byte()
|
||||
Using oDocumentStream As New MemoryStream(pDocument)
|
||||
Using oReportStream As New MemoryStream(pReport)
|
||||
Using oFinalStream As New MemoryStream()
|
||||
Using oDocumentPDF As New GdPicturePDF()
|
||||
Using oReportPDF As New GdPicturePDF()
|
||||
|
||||
Using oGdPicturePDF As New GdPicturePDF()
|
||||
Using oGdPicturePDFReport As New GdPicturePDF()
|
||||
Using oStream As New MemoryStream(pReport)
|
||||
' Load the source file into memory
|
||||
oDocumentPDF.LoadFromStream(oDocumentStream, True)
|
||||
If oDocumentPDF.GetStat() Then
|
||||
Throw New MergeDocumentException($"Document could not be loaded: {oDocumentPDF.GetStat}")
|
||||
End If
|
||||
|
||||
' Load the source file into memory
|
||||
If oGdPicturePDF.LoadFromFile(pDocumentPath, True) <> GdPictureStatus.OK Then
|
||||
Throw New ApplicationException("Document could not be loaded!")
|
||||
End If
|
||||
' Load the report file into memory
|
||||
oReportPDF.LoadFromStream(oReportStream, True)
|
||||
If oDocumentPDF.GetStat() Then
|
||||
Throw New MergeDocumentException($"Report could not be loaded: {oDocumentPDF.GetStat}")
|
||||
End If
|
||||
|
||||
' Load the report file into memory
|
||||
If oGdPicturePDFReport.LoadFromStream(oStream, True) <> GdPictureStatus.OK Then
|
||||
Throw New ApplicationException("Report could not be loaded!")
|
||||
End If
|
||||
' Merge the documents
|
||||
Dim oMergedPDF = oDocumentPDF.Merge2Documents(oDocumentPDF, oReportPDF)
|
||||
If oDocumentPDF.GetStat() Then
|
||||
Throw New MergeDocumentException($"Documents could not be merged: {oDocumentPDF.GetStat}")
|
||||
End If
|
||||
|
||||
If oGdPicturePDF.ClonePages(oGdPicturePDFReport, "*") = GdPictureStatus.OK Then
|
||||
Throw New ApplicationException("Report could not be loaded!")
|
||||
End If
|
||||
oMergedPDF.SaveToStream(oFinalStream)
|
||||
|
||||
Return oFinalStream.ToArray()
|
||||
End Using
|
||||
End Using
|
||||
End Using
|
||||
End Using
|
||||
End Using
|
||||
End Function
|
||||
|
||||
Private Function GenerateFinalPDF(pData As EnvelopeData) As Boolean
|
||||
Private Function BurnAnnotationsToPdf(pData As EnvelopeData) As Byte()
|
||||
Dim pEnvelopeId = pData.EnvelopeId
|
||||
|
||||
Logger.Info("Burning [{0}] signatures", pData.AnnotationData.Count)
|
||||
Dim oAnnotations = pData.AnnotationData
|
||||
Dim oInputPath = pData.DocumentPath
|
||||
Dim oOutputPath = Config.ExportPath
|
||||
|
||||
Logger.Info("Input path: [{0}]", oInputPath)
|
||||
Logger.Info("Output path: [{0}]", oOutputPath)
|
||||
Dim oInputDocumentBuffer As Byte()
|
||||
Try
|
||||
oInputDocumentBuffer = File.ReadAllBytes(oInputPath)
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
Throw New BurnAnnotationException("Source document could not be read from disk!", ex)
|
||||
End Try
|
||||
|
||||
Dim oBurnResult = PDFBurner.BurnInstantJSONAnnotationsToPDF(oInputPath, oAnnotations, oOutputPath)
|
||||
|
||||
If oBurnResult = False Then
|
||||
Logger.Warn("PDF Could not be burned for Envelope [{0}]!", pEnvelopeId)
|
||||
Return False
|
||||
End If
|
||||
|
||||
Return True
|
||||
Return PDFBurner.BurnInstantJSONAnnotationsToPDF(oInputDocumentBuffer, oAnnotations)
|
||||
End Function
|
||||
|
||||
'Private Async Function GenerateReportPdf(pEnvelopeId As Integer) As Task(Of Byte())
|
||||
' Dim oSql As String = $"SELECT * FROM VWSIG_ENVELOPE_REPORT WHERE ENVELOPE_ID = {pEnvelopeId}"
|
||||
' Dim oTable As DataTable = Database.GetDatatable(oSql)
|
||||
' Dim oItems = GetReportSource(oTable)
|
||||
|
||||
' If oItems.Count = 0 Then
|
||||
' Return Nothing
|
||||
' End If
|
||||
|
||||
' Dim oState As New State() With {
|
||||
' .Database = Database,
|
||||
' .LogConfig = LogConfig
|
||||
' }
|
||||
' EnvelopeModel = New EnvelopeModel(oState)
|
||||
' Dim oEnvelope = EnvelopeModel.GetById(pEnvelopeId)
|
||||
|
||||
' Dim oCreator As New ReportCreator(oEnvelope)
|
||||
' Dim oBuffer = Await oCreator.CreateReport(oItems)
|
||||
|
||||
' Return oBuffer
|
||||
'End Function
|
||||
|
||||
'Private Function GetReportSource(pDataTable As DataTable) As List(Of ReportItem)
|
||||
' Return pDataTable.Rows.
|
||||
' Cast(Of DataRow).
|
||||
' Select(AddressOf ToReportItem).
|
||||
' OrderByDescending(Function(r) r.ItemDate).
|
||||
' ToList()
|
||||
'End Function
|
||||
|
||||
Private Function GetEnvelopeData(pEnvelopeId As Integer) As EnvelopeData
|
||||
Dim oSql = $"SELECT T.GUID, T2.FILEPATH FROM [dbo].[TBSIG_ENVELOPE] T
|
||||
JOIN TBSIG_ENVELOPE_DOCUMENT T2 ON T.GUID = T2.ENVELOPE_ID
|
||||
@ -210,6 +229,7 @@ Namespace Jobs
|
||||
|
||||
Return oData
|
||||
End Function
|
||||
|
||||
Private Function GetAnnotationData(pEnvelopeId As Integer) As List(Of String)
|
||||
Dim oSql = $"SELECT VALUE FROM TBSIG_DOCUMENT_STATUS WHERE ENVELOPE_ID = {pEnvelopeId}"
|
||||
Dim oTable As DataTable = Database.GetDatatable(oSql)
|
||||
@ -221,26 +241,14 @@ Namespace Jobs
|
||||
|
||||
End Function
|
||||
|
||||
Private Function ToReportItem(pRow As DataRow) As ReportItem
|
||||
Return New ReportItem() With {
|
||||
.EnvelopeId = pRow.Item("ENVELOPE_ID"),
|
||||
.EnvelopeTitle = pRow.ItemEx("HEAD_TITLE", String.Empty),
|
||||
.EnvelopeSubject = pRow.ItemEx("HEAD_SUBJECT", String.Empty),
|
||||
.ItemDate = pRow.ItemEx(Of Date)("POS_WHEN", Nothing),
|
||||
.ItemStatus = pRow.ItemEx("POS_STATUS", 0),
|
||||
.ItemUserReference = pRow.ItemEx("POS_WHO", "")
|
||||
}
|
||||
End Function
|
||||
|
||||
Private Sub InitializeServices()
|
||||
Dim oState = GetState()
|
||||
ActionService = New ActionService(oState)
|
||||
Private Sub InitializeServices(pState As State)
|
||||
ActionService = New ActionService(pState)
|
||||
End Sub
|
||||
|
||||
Private Sub InitializeModels()
|
||||
Dim oState = GetState()
|
||||
ConfigModel = New ConfigModel(oState)
|
||||
EnvelopeModel = New EnvelopeModel(oState)
|
||||
Private Sub InitializeModels(pState As State)
|
||||
ConfigModel = New ConfigModel(pState)
|
||||
EnvelopeModel = New EnvelopeModel(pState)
|
||||
ReportModel = New ReportModel(pState)
|
||||
End Sub
|
||||
|
||||
Private Function GetDatabase(pContext As IJobExecutionContext, pLogConfig As LogConfig) As MSSQLServer
|
||||
@ -4,8 +4,9 @@ Imports DigitalData.Modules.Base
|
||||
Imports DigitalData.Modules.Logging
|
||||
Imports GdPicture14
|
||||
Imports Newtonsoft.Json
|
||||
Imports EnvelopeGenerator.Common.Jobs.FinalizeDocument.FinalizeDocumentExceptions
|
||||
|
||||
Namespace Jobs
|
||||
Namespace Jobs.FinalizeDocument
|
||||
Public Class PDFBurner
|
||||
Inherits BaseClass
|
||||
|
||||
@ -26,47 +27,43 @@ Namespace Jobs
|
||||
Manager = New AnnotationManager()
|
||||
End Sub
|
||||
|
||||
Public Function BurnInstantJSONAnnotationsToPDF(pSourceFilePath As String, pInstantJSONList As List(Of String), pDestinationDirectoryPath As String) As Boolean
|
||||
Public Function BurnInstantJSONAnnotationsToPDF(pSourceBuffer As Byte(), pInstantJSONList As List(Of String)) As Byte()
|
||||
Dim oResult As GdPictureStatus
|
||||
|
||||
oResult = Manager.InitFromFile(pSourceFilePath)
|
||||
If oResult <> GdPictureStatus.OK Then
|
||||
Logger.Warn("Could not open file [{0}] for burning: [{1}]", pSourceFilePath, oResult.ToString)
|
||||
Return False
|
||||
End If
|
||||
|
||||
For Each oJSON In pInstantJSONList
|
||||
If AddInstantJSONAnnotationToPDF(oJSON) = False Then
|
||||
Logger.Warn("Adding Annotation failed. Exiting")
|
||||
Return False
|
||||
End If
|
||||
Next
|
||||
|
||||
Dim oFileInfo As New FileInfo(pSourceFilePath)
|
||||
Dim oDestinationFilePath As String = Path.Combine(pDestinationDirectoryPath, oFileInfo.Name)
|
||||
Logger.Debug("Export filepath: [{0}]", oDestinationFilePath)
|
||||
|
||||
Try
|
||||
oResult = Manager.BurnAnnotationsToPage(RemoveInitialAnnots:=True, VectorMode:=True)
|
||||
If oResult <> GdPictureStatus.OK Then
|
||||
Logger.Warn("Could not burn annotations to file file [{0}]: [{1}]", pSourceFilePath, oResult.ToString)
|
||||
Return False
|
||||
End If
|
||||
Using oSourceStream As New MemoryStream(pSourceBuffer)
|
||||
oResult = Manager.InitFromStream(oSourceStream)
|
||||
If oResult <> GdPictureStatus.OK Then
|
||||
Throw New BurnAnnotationException($"Could not open document for burning: [{oResult}]")
|
||||
End If
|
||||
|
||||
oResult = Manager.SaveDocumentToPDF(oDestinationFilePath)
|
||||
If oResult <> GdPictureStatus.OK Then
|
||||
Logger.Warn("Could not save file [{0}] to path [{1}]: [{2}]", oFileInfo.Name, oDestinationFilePath, oResult.ToString)
|
||||
Return False
|
||||
End If
|
||||
For Each oJSON In pInstantJSONList
|
||||
If AddInstantJSONAnnotationToPDF(oJSON) = False Then
|
||||
Throw New BurnAnnotationException($"Adding Annotation failed")
|
||||
End If
|
||||
Next
|
||||
|
||||
Manager.Close()
|
||||
|
||||
Return True
|
||||
oResult = Manager.BurnAnnotationsToPage(RemoveInitialAnnots:=True, VectorMode:=True)
|
||||
If oResult <> GdPictureStatus.OK Then
|
||||
Throw New BurnAnnotationException($"Could not burn annotations to file: [{oResult}]")
|
||||
End If
|
||||
|
||||
Using oNewStream As New MemoryStream()
|
||||
oResult = Manager.SaveDocumentToPDF(oNewStream)
|
||||
If oResult <> GdPictureStatus.OK Then
|
||||
Throw New BurnAnnotationException($"Could not save document to stream: [{oResult}]")
|
||||
End If
|
||||
|
||||
Manager.Close()
|
||||
|
||||
Return oNewStream.ToArray()
|
||||
End Using
|
||||
End Using
|
||||
Catch ex As Exception
|
||||
Logger.Warn("Could not burn and save annotations to file [{0}]!", oDestinationFilePath)
|
||||
Logger.Error(ex)
|
||||
|
||||
Return False
|
||||
Return Nothing
|
||||
End Try
|
||||
End Function
|
||||
|
||||
@ -0,0 +1,91 @@
|
||||
Imports System.IO
|
||||
Imports DigitalData.Modules.Logging
|
||||
Imports DigitalData.Modules.Base
|
||||
Imports EnvelopeGenerator.Common.Jobs.FinalizeDocument.FinalizeDocumentExceptions
|
||||
|
||||
Public Class ReportCreator
|
||||
Inherits BaseClass
|
||||
|
||||
Private Envelope As Envelope
|
||||
Private ReadOnly ReportModel As ReportModel
|
||||
Private ReadOnly EnvelopeModel As EnvelopeModel
|
||||
|
||||
Public Sub New(pLogConfig As LogConfig, pState As State)
|
||||
MyBase.New(pLogConfig)
|
||||
|
||||
ReportModel = New ReportModel(pState)
|
||||
EnvelopeModel = New EnvelopeModel(pState)
|
||||
End Sub
|
||||
|
||||
Public Function CreateReport(pEnvelope As Envelope) As Byte()
|
||||
Try
|
||||
Logger.Debug("Loading report data..")
|
||||
Dim oTable = ReportModel.List(pEnvelope.Id)
|
||||
Dim oItems = GetReportSource(oTable)
|
||||
|
||||
Envelope = pEnvelope
|
||||
|
||||
If oItems.Count = 0 Then
|
||||
Throw New CreateReportException("No report data found!")
|
||||
End If
|
||||
|
||||
Logger.Debug("Creating report with [{0}] items..", oItems.Count)
|
||||
Dim oBuffer = DoCreateReport(oItems)
|
||||
Logger.Debug("Report created!")
|
||||
|
||||
Return oBuffer
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
Throw New CreateReportException("Could not prepare report data!", ex)
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Private Function GetReportSource(pDataTable As DataTable) As List(Of ReportItem)
|
||||
Logger.Debug("Preparing report data")
|
||||
Return pDataTable.Rows.
|
||||
Cast(Of DataRow).
|
||||
Select(AddressOf ToReportItem).
|
||||
OrderByDescending(Function(r) r.ItemDate).
|
||||
ToList()
|
||||
End Function
|
||||
|
||||
Private Function DoCreateReport(pReportItems As List(Of ReportItem)) As Byte()
|
||||
Dim oItems = pReportItems.Select(AddressOf MergeEnvelope).ToList()
|
||||
Dim oSource As New ReportSource With {.Items = oItems}
|
||||
Dim oReport As New rptEnvelopeHistory() With {.DataSource = oSource, .DataMember = "Items"}
|
||||
|
||||
Logger.Debug("Creating report in memory..")
|
||||
oReport.CreateDocument()
|
||||
|
||||
Logger.Debug("Exporting report to stream..")
|
||||
Using oStream As New MemoryStream()
|
||||
oReport.ExportToPdf(oStream)
|
||||
|
||||
Logger.Debug("Writing report to buffer..")
|
||||
Return oStream.ToArray()
|
||||
End Using
|
||||
End Function
|
||||
|
||||
Private Function MergeEnvelope(pItem As ReportItem) As ReportItem
|
||||
If pItem.Envelope Is Nothing Then
|
||||
pItem.Envelope = Envelope
|
||||
End If
|
||||
Return pItem
|
||||
End Function
|
||||
|
||||
Private Function ToReportItem(pRow As DataRow) As ReportItem
|
||||
Try
|
||||
Return New ReportItem() With {
|
||||
.EnvelopeId = pRow.Item("ENVELOPE_ID"),
|
||||
.EnvelopeTitle = pRow.ItemEx("HEAD_TITLE", String.Empty),
|
||||
.EnvelopeSubject = pRow.ItemEx("HEAD_SUBJECT", String.Empty),
|
||||
.ItemDate = pRow.ItemEx(Of Date)("POS_WHEN", Nothing),
|
||||
.ItemStatus = pRow.ItemEx("POS_STATUS", 0),
|
||||
.ItemUserReference = pRow.ItemEx("POS_WHO", "")
|
||||
}
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
Throw New CreateReportException("Could not read data from database!", ex)
|
||||
End Try
|
||||
End Function
|
||||
End Class
|
||||
14
EnvelopeGenerator.Common/Models/ReportModel.vb
Normal file
14
EnvelopeGenerator.Common/Models/ReportModel.vb
Normal file
@ -0,0 +1,14 @@
|
||||
Public Class ReportModel
|
||||
Inherits BaseModel
|
||||
|
||||
Public Sub New(pState As State)
|
||||
MyBase.New(pState)
|
||||
End Sub
|
||||
|
||||
Public Function List(pEnvelopeId As Integer) As DataTable
|
||||
Dim oSql As String = $"SELECT * FROM VWSIG_ENVELOPE_REPORT WHERE ENVELOPE_ID = {pEnvelopeId}"
|
||||
Dim oTable As DataTable = Database.GetDatatable(oSql)
|
||||
|
||||
Return oTable
|
||||
End Function
|
||||
End Class
|
||||
@ -1,30 +0,0 @@
|
||||
Imports System.IO
|
||||
Imports DevExpress.XtraPrinting
|
||||
|
||||
Public Class ReportCreator
|
||||
Private Envelope As Envelope
|
||||
|
||||
Public Sub New(pEnvelope As Envelope)
|
||||
Envelope = pEnvelope
|
||||
End Sub
|
||||
|
||||
Public Async Function CreateReport(pReportItems As List(Of ReportItem)) As Task(Of Byte())
|
||||
Dim oItems = pReportItems.Select(AddressOf MergeEnvelope).ToList()
|
||||
Dim oSource As New ReportSource With {.Items = oItems}
|
||||
Dim oReport As New rptEnvelopeHistory() With {.DataSource = oSource, .DataMember = "Items"}
|
||||
|
||||
Await oReport.CreateDocumentAsync()
|
||||
|
||||
Using oStream As New MemoryStream()
|
||||
Await oReport.ExportToPdfAsync(oStream, New PdfExportOptions)
|
||||
Return oStream.ToArray()
|
||||
End Using
|
||||
End Function
|
||||
|
||||
Private Function MergeEnvelope(pItem As ReportItem) As ReportItem
|
||||
If pItem.Envelope Is Nothing Then
|
||||
pItem.Envelope = Envelope
|
||||
End If
|
||||
Return pItem
|
||||
End Function
|
||||
End Class
|
||||
@ -156,6 +156,9 @@
|
||||
<data name="Envelope Invitations Sent" xml:space="preserve">
|
||||
<value>Envelope Invitations Sent</value>
|
||||
</data>
|
||||
<data name="Envelope Overview" xml:space="preserve">
|
||||
<value>Overview</value>
|
||||
</data>
|
||||
<data name="Envelope successfully sent" xml:space="preserve">
|
||||
<value>The invitations were successfully prepared for dispatch.</value>
|
||||
</data>
|
||||
@ -220,7 +223,7 @@
|
||||
<value>Signature</value>
|
||||
</data>
|
||||
<data name="Signature Editor" xml:space="preserve">
|
||||
<value>Signature Editor</value>
|
||||
<value>Signature-Editor</value>
|
||||
</data>
|
||||
<data name="The envelope could not be deleted" xml:space="preserve">
|
||||
<value>The envelope could not be deleted!</value>
|
||||
|
||||
@ -156,6 +156,9 @@
|
||||
<data name="Envelope Invitations Sent" xml:space="preserve">
|
||||
<value>Die Einladungen wurden versendet</value>
|
||||
</data>
|
||||
<data name="Envelope Overview" xml:space="preserve">
|
||||
<value>Übersicht</value>
|
||||
</data>
|
||||
<data name="Envelope successfully sent" xml:space="preserve">
|
||||
<value>Die Einladungen wurden erfolgreich zum Versand bereitgestellt.</value>
|
||||
</data>
|
||||
@ -220,7 +223,7 @@
|
||||
<value>Signatur</value>
|
||||
</data>
|
||||
<data name="Signature Editor" xml:space="preserve">
|
||||
<value>Signatur Editor</value>
|
||||
<value>Signatur-Editor</value>
|
||||
</data>
|
||||
<data name="The envelope could not be deleted" xml:space="preserve">
|
||||
<value>Der Umschlag konnte nicht gelöscht werden!</value>
|
||||
|
||||
@ -190,6 +190,15 @@ Namespace My.Resources
|
||||
End Get
|
||||
End Property
|
||||
|
||||
'''<summary>
|
||||
''' Sucht eine lokalisierte Zeichenfolge, die Übersicht ähnelt.
|
||||
'''</summary>
|
||||
Public Shared ReadOnly Property Envelope_Overview() As String
|
||||
Get
|
||||
Return ResourceManager.GetString("Envelope Overview", resourceCulture)
|
||||
End Get
|
||||
End Property
|
||||
|
||||
'''<summary>
|
||||
''' Sucht eine lokalisierte Zeichenfolge, die Die Einladungen wurden erfolgreich zum Versand bereitgestellt. ähnelt.
|
||||
'''</summary>
|
||||
@ -371,7 +380,7 @@ Namespace My.Resources
|
||||
End Property
|
||||
|
||||
'''<summary>
|
||||
''' Sucht eine lokalisierte Zeichenfolge, die Signatur Editor ähnelt.
|
||||
''' Sucht eine lokalisierte Zeichenfolge, die Signatur-Editor ähnelt.
|
||||
'''</summary>
|
||||
Public Shared ReadOnly Property Signature_Editor() As String
|
||||
Get
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user