Add placeholder for Report Filename

This commit is contained in:
Jonathan Jenne 2022-04-25 10:41:13 +02:00
parent 69f4c640a8
commit 13af72dee5
3 changed files with 39 additions and 27 deletions

View File

@ -14,7 +14,7 @@ Public Class Patterns
GeneralConfig = pGeneralConfig GeneralConfig = pGeneralConfig
End Sub End Sub
Public Function ReplaceForImport(pDocument As Documents.Document, pRow As DocumentRow, oString As String) Public Function ReplaceForImport(pDocument As Documents.Document, pRow As DocumentRow, pReportFileName As String, oString As String)
Dim oRegex = New Regex("{#(\w+)#([\w\s_-]+)}+") Dim oRegex = New Regex("{#(\w+)#([\w\s_-]+)}+")
Dim oMatches As MatchCollection = oRegex.Matches(oString) Dim oMatches As MatchCollection = oRegex.Matches(oString)
@ -51,6 +51,9 @@ Public Class Patterns
Case "FILENAME" Case "FILENAME"
oValue = pDocument.FileName oValue = pDocument.FileName
Case "FILENAME_REPORT"
oValue = pReportFileName
Case "MANDATORDB" Case "MANDATORDB"
oValue = pDocument.Mandator.Database oValue = pDocument.Mandator.Database

View File

@ -32,8 +32,8 @@ Public Class ReportGenerator(Of TReport As IReport)
Return oFilePath Return oFilePath
End Function End Function
Public Function GenerateReport(pDocument As Document, pTemplate As Template) As TReport Public Function GenerateReport(pDocument As Document, pTemplate As Template) As ReportResult(Of TReport)
Dim oFilePath = GetReportFilePath(pDocument, pTemplate)
Dim oMapperConfig As New Mapper(LogConfig) Dim oMapperConfig As New Mapper(LogConfig)
Dim oHeadMapper = oMapperConfig.GetMapper(Of ReportHead)(New Dictionary(Of String, String) From { Dim oHeadMapper = oMapperConfig.GetMapper(Of ReportHead)(New Dictionary(Of String, String) From {
{"Fakt_Kontoname", "Text1"}, {"Fakt_Kontoname", "Text1"},
@ -60,7 +60,7 @@ Public Class ReportGenerator(Of TReport As IReport)
Where(Function(item) item.Function.Name = Constants.FUNCTION_SQL). Where(Function(item) item.Function.Name = Constants.FUNCTION_SQL).
ToList() ToList()
FillFieldValuesFromSQL(pDocument, oSQLConfig) pDocument = FillFieldValuesFromSQL(pDocument, oSQLConfig, oFilePath)
Dim oHeadRow = pDocument.Rows. Dim oHeadRow = pDocument.Rows.
Where(Function(r) r.TableName.EndsWith("T025")). Where(Function(r) r.TableName.EndsWith("T025")).
@ -99,11 +99,16 @@ Public Class ReportGenerator(Of TReport As IReport)
oDataSource.Fill() oDataSource.Fill()
oReport.DataSource = oDataSource oReport.DataSource = oDataSource
Return oReport Dim oResult = New ReportResult(Of TReport) With {
.Report = oReport,
.FileName = oFilePath
}
Return oResult
End Function End Function
Private Sub FillFieldValuesFromSQL(pDocument As Document, oSQLConfig As List(Of TemplateConfigItem)) Private Function FillFieldValuesFromSQL(pDocument As Document, pSQLConfig As List(Of TemplateConfigItem), pReportFileName As String) As Document
For Each oSQLConfigItem In oSQLConfig For Each oSQLConfigItem In pSQLConfig
' FieldList is a list of fields that will be changed ' FieldList is a list of fields that will be changed
' Example: Setting SQL for Article StorageLocation will invoke the sql for each row ' Example: Setting SQL for Article StorageLocation will invoke the sql for each row
Dim oRowList = pDocument.Rows. Dim oRowList = pDocument.Rows.
@ -116,7 +121,7 @@ Public Class ReportGenerator(Of TReport As IReport)
SingleOrDefault() SingleOrDefault()
Dim oSQL = oSQLConfigItem.Function.Params Dim oSQL = oSQLConfigItem.Function.Params
oSQL = Patterns.ReplaceForImport(pDocument, oRow, oSQL) oSQL = Patterns.ReplaceForImport(pDocument, oRow, pReportFileName, oSQL)
Dim oValue = Database.GetScalarValue(oSQL) Dim oValue = Database.GetScalarValue(oSQL)
@ -125,5 +130,13 @@ Public Class ReportGenerator(Of TReport As IReport)
End If End If
Next Next
Next Next
End Sub
End Class Return pDocument
End Function
Public Structure ReportResult(Of T)
Public Report As T
Public FileName As String
End Structure
End Class

View File

@ -91,8 +91,8 @@ Public Class frmImportMain
lookupMandator.ForceInitialize() lookupMandator.ForceInitialize()
lookupMandator.Properties.View.BestFitColumns() lookupMandator.Properties.View.BestFitColumns()
DocumentLoader = New Documents.DocumentLoader(LogConfig, Winline, My.MappingConfiguration, My.TemplateConfiguration, ConfigManager.Config) DocumentLoader = New DocumentLoader(LogConfig, Winline, My.MappingConfiguration, My.TemplateConfiguration, ConfigManager.Config)
DocumentCleaner = New Documents.DocumentCleaner(LogConfig, CurrentTemplate) DocumentCleaner = New DocumentCleaner(LogConfig, CurrentTemplate)
GridLoader = New GridLoader(LogConfig) GridLoader = New GridLoader(LogConfig)
ReportGenerator = New ReportGenerator(Of OrderReport)(LogConfig, Database, My.TemplateConfiguration, My.GeneralConfiguration) ReportGenerator = New ReportGenerator(Of OrderReport)(LogConfig, Database, My.TemplateConfiguration, My.GeneralConfiguration)
@ -280,19 +280,18 @@ Public Class frmImportMain
Dim oDocument As Document = GridViewFiles.GetRow(GridViewFiles.FocusedRowHandle) Dim oDocument As Document = GridViewFiles.GetRow(GridViewFiles.FocusedRowHandle)
' Generate the report ' Generate the report
Dim oReport = ReportGenerator.GenerateReport(oDocument, CurrentTemplate) Dim oReportResult = ReportGenerator.GenerateReport(oDocument, CurrentTemplate)
Dim oFilePath = ReportGenerator.GetReportFilePath(oDocument, CurrentTemplate) Dim oFileInfo = New FileInfo(oReportResult.FileName)
Dim oFileInfo = New FileInfo(oFilePath)
' Export it to pdf ' Export it to pdf
oReport.ExportToPdf(oFilePath) oReportResult.Report.ExportToPdf(oReportResult.FileName)
Dim oMessage = $"Die Datei wurde im Verzeichnis '{oFileInfo.Directory}' abgelegt. Möchten Sie die Datei jetzt öffnen?" Dim oMessage = $"Die Datei wurde im Verzeichnis '{oFileInfo.Directory}' abgelegt. Möchten Sie die Datei jetzt öffnen?"
Dim oResult = MsgBox(oMessage, MsgBoxStyle.Question Or MsgBoxStyle.YesNo, Text) Dim oDialogResult = MsgBox(oMessage, MsgBoxStyle.Question Or MsgBoxStyle.YesNo, Text)
If oResult = MsgBoxResult.Yes Then If oDialogResult = MsgBoxResult.Yes Then
Try Try
Process.Start(oFilePath) Process.Start(oReportResult.FileName)
Catch ex As Exception Catch ex As Exception
FormHelper.ShowError(ex, "Export Report") FormHelper.ShowError(ex, "Export Report")
End Try End Try
@ -539,8 +538,8 @@ Public Class frmImportMain
Dim oReport As OrderReport = oReportGenerator.GenerateReport(oDocument, CurrentTemplate) Dim oResult = oReportGenerator.GenerateReport(oDocument, CurrentTemplate)
Dim oPrintTool As New ReportPrintTool(oReport) Dim oPrintTool As New ReportPrintTool(oResult.Report)
oPrintTool.Report.CreateDocument(False) oPrintTool.Report.CreateDocument(False)
oPrintTool.ShowPreview() oPrintTool.ShowPreview()
@ -754,17 +753,14 @@ Public Class frmImportMain
' TODO: Call GetReportFilePath in GenerateReport to better control ' TODO: Call GetReportFilePath in GenerateReport to better control
' when filename is generated and use it as placeholder ' when filename is generated and use it as placeholder
Dim oReport = ReportGenerator.GenerateReport(pDocument, CurrentTemplate) Dim oReportResult = ReportGenerator.GenerateReport(pDocument, CurrentTemplate)
Dim oFilePath = ReportGenerator.GetReportFilePath(pDocument, CurrentTemplate)
WebService.RaiseWebServiceProgress("Bericht exportieren") WebService.RaiseWebServiceProgress("Bericht exportieren")
' Export it to pdf ' Export it to pdf
oReport.ExportToPdf(oFilePath) oReportResult.Report.ExportToPdf(oReportResult.FileName)
WebService.RaiseWebServiceProgress("Datei archivieren") ' Mark Document as Imported, will be moved on Form Close or File Reload
' Mark Document as Imported, will be moved on Form Close
pDocument.Imported = True pDocument.Imported = True
Return True Return True