Add placeholder for Report Filename
This commit is contained in:
parent
69f4c640a8
commit
13af72dee5
@ -14,7 +14,7 @@ Public Class Patterns
|
||||
GeneralConfig = pGeneralConfig
|
||||
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 oMatches As MatchCollection = oRegex.Matches(oString)
|
||||
|
||||
@ -51,6 +51,9 @@ Public Class Patterns
|
||||
Case "FILENAME"
|
||||
oValue = pDocument.FileName
|
||||
|
||||
Case "FILENAME_REPORT"
|
||||
oValue = pReportFileName
|
||||
|
||||
Case "MANDATORDB"
|
||||
oValue = pDocument.Mandator.Database
|
||||
|
||||
|
||||
@ -32,8 +32,8 @@ Public Class ReportGenerator(Of TReport As IReport)
|
||||
Return oFilePath
|
||||
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 oHeadMapper = oMapperConfig.GetMapper(Of ReportHead)(New Dictionary(Of String, String) From {
|
||||
{"Fakt_Kontoname", "Text1"},
|
||||
@ -60,7 +60,7 @@ Public Class ReportGenerator(Of TReport As IReport)
|
||||
Where(Function(item) item.Function.Name = Constants.FUNCTION_SQL).
|
||||
ToList()
|
||||
|
||||
FillFieldValuesFromSQL(pDocument, oSQLConfig)
|
||||
pDocument = FillFieldValuesFromSQL(pDocument, oSQLConfig, oFilePath)
|
||||
|
||||
Dim oHeadRow = pDocument.Rows.
|
||||
Where(Function(r) r.TableName.EndsWith("T025")).
|
||||
@ -99,11 +99,16 @@ Public Class ReportGenerator(Of TReport As IReport)
|
||||
oDataSource.Fill()
|
||||
oReport.DataSource = oDataSource
|
||||
|
||||
Return oReport
|
||||
Dim oResult = New ReportResult(Of TReport) With {
|
||||
.Report = oReport,
|
||||
.FileName = oFilePath
|
||||
}
|
||||
|
||||
Return oResult
|
||||
End Function
|
||||
|
||||
Private Sub FillFieldValuesFromSQL(pDocument As Document, oSQLConfig As List(Of TemplateConfigItem))
|
||||
For Each oSQLConfigItem In oSQLConfig
|
||||
Private Function FillFieldValuesFromSQL(pDocument As Document, pSQLConfig As List(Of TemplateConfigItem), pReportFileName As String) As Document
|
||||
For Each oSQLConfigItem In pSQLConfig
|
||||
' FieldList is a list of fields that will be changed
|
||||
' Example: Setting SQL for Article StorageLocation will invoke the sql for each row
|
||||
Dim oRowList = pDocument.Rows.
|
||||
@ -116,7 +121,7 @@ Public Class ReportGenerator(Of TReport As IReport)
|
||||
SingleOrDefault()
|
||||
|
||||
Dim oSQL = oSQLConfigItem.Function.Params
|
||||
oSQL = Patterns.ReplaceForImport(pDocument, oRow, oSQL)
|
||||
oSQL = Patterns.ReplaceForImport(pDocument, oRow, pReportFileName, oSQL)
|
||||
|
||||
Dim oValue = Database.GetScalarValue(oSQL)
|
||||
|
||||
@ -125,5 +130,13 @@ Public Class ReportGenerator(Of TReport As IReport)
|
||||
End If
|
||||
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
|
||||
@ -91,8 +91,8 @@ Public Class frmImportMain
|
||||
lookupMandator.ForceInitialize()
|
||||
lookupMandator.Properties.View.BestFitColumns()
|
||||
|
||||
DocumentLoader = New Documents.DocumentLoader(LogConfig, Winline, My.MappingConfiguration, My.TemplateConfiguration, ConfigManager.Config)
|
||||
DocumentCleaner = New Documents.DocumentCleaner(LogConfig, CurrentTemplate)
|
||||
DocumentLoader = New DocumentLoader(LogConfig, Winline, My.MappingConfiguration, My.TemplateConfiguration, ConfigManager.Config)
|
||||
DocumentCleaner = New DocumentCleaner(LogConfig, CurrentTemplate)
|
||||
|
||||
GridLoader = New GridLoader(LogConfig)
|
||||
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)
|
||||
|
||||
' Generate the report
|
||||
Dim oReport = ReportGenerator.GenerateReport(oDocument, CurrentTemplate)
|
||||
Dim oFilePath = ReportGenerator.GetReportFilePath(oDocument, CurrentTemplate)
|
||||
Dim oFileInfo = New FileInfo(oFilePath)
|
||||
Dim oReportResult = ReportGenerator.GenerateReport(oDocument, CurrentTemplate)
|
||||
Dim oFileInfo = New FileInfo(oReportResult.FileName)
|
||||
|
||||
' 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 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
|
||||
Process.Start(oFilePath)
|
||||
Process.Start(oReportResult.FileName)
|
||||
Catch ex As Exception
|
||||
FormHelper.ShowError(ex, "Export Report")
|
||||
End Try
|
||||
@ -539,8 +538,8 @@ Public Class frmImportMain
|
||||
|
||||
|
||||
|
||||
Dim oReport As OrderReport = oReportGenerator.GenerateReport(oDocument, CurrentTemplate)
|
||||
Dim oPrintTool As New ReportPrintTool(oReport)
|
||||
Dim oResult = oReportGenerator.GenerateReport(oDocument, CurrentTemplate)
|
||||
Dim oPrintTool As New ReportPrintTool(oResult.Report)
|
||||
oPrintTool.Report.CreateDocument(False)
|
||||
oPrintTool.ShowPreview()
|
||||
|
||||
@ -754,17 +753,14 @@ Public Class frmImportMain
|
||||
|
||||
' TODO: Call GetReportFilePath in GenerateReport to better control
|
||||
' when filename is generated and use it as placeholder
|
||||
Dim oReport = ReportGenerator.GenerateReport(pDocument, CurrentTemplate)
|
||||
Dim oFilePath = ReportGenerator.GetReportFilePath(pDocument, CurrentTemplate)
|
||||
Dim oReportResult = ReportGenerator.GenerateReport(pDocument, CurrentTemplate)
|
||||
|
||||
WebService.RaiseWebServiceProgress("Bericht exportieren")
|
||||
|
||||
' 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
|
||||
' Mark Document as Imported, will be moved on Form Close or File Reload
|
||||
pDocument.Imported = True
|
||||
|
||||
Return True
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user