Add ReportGenerator class
This commit is contained in:
@@ -30,6 +30,7 @@ Public Class frmImportMain
|
||||
Private FileEx As DigitalData.Modules.Filesystem.File
|
||||
Private WebService As WebServiceData
|
||||
Private DocumentLoader As DocumentLoader
|
||||
Private ReportGenerator As ReportGenerator(Of OrderReport)
|
||||
Private FormHelper As FormHelper
|
||||
|
||||
Private Grids As List(Of GridControl)
|
||||
@@ -119,6 +120,7 @@ Public Class frmImportMain
|
||||
|
||||
DocumentLoader = New DocumentLoader(LogConfig, Winline, My.MappingConfiguration, My.TemplateConfiguration)
|
||||
GridLoader = New GridLoader(LogConfig)
|
||||
ReportGenerator = New ReportGenerator(Of OrderReport)(LogConfig, Database, My.TemplateConfiguration, My.GeneralConfiguration)
|
||||
|
||||
SplashScreenManager.SetWaitFormDescription(My.Resources.frmImportMainExtra.Lade_Vorlagen)
|
||||
|
||||
@@ -411,15 +413,23 @@ Public Class frmImportMain
|
||||
btnLoadFiles.Enabled = False
|
||||
SplitContainerGrids.Enabled = False
|
||||
|
||||
' Get the document
|
||||
Dim oDocument As Document = GridViewFiles.GetRow(GridViewFiles.FocusedRowHandle)
|
||||
Dim oFinalDirectory = My.Helpers.GetDateDirectory(My.GeneralConfiguration.OutputReportDirectory)
|
||||
Dim oFileName = My.Helpers.GetFilenameWithSuffix(IO.Path.GetFileNameWithoutExtension(oDocument.File.Name), My.Helpers.GetDateTimeString, "pdf")
|
||||
Dim oFilePath As String = IO.Path.Combine(oFinalDirectory, oFileName)
|
||||
Dim oReport = GenerateReport(Of OrderReport)(oDocument)
|
||||
oReport.ExportToPdf(oFilePath)
|
||||
|
||||
' Transfer to winline
|
||||
Await WebService.TransferDocumentToWinline(oDocument, lookupMandator.EditValue)
|
||||
|
||||
WebService.RaiseWebServiceProgress("Bericht erzeugen")
|
||||
|
||||
' Generate the report
|
||||
Dim oReport = ReportGenerator.GenerateReport(oDocument)
|
||||
Dim oFilePath = ReportGenerator.GetReportFilePath(oDocument)
|
||||
|
||||
WebService.RaiseWebServiceProgress("Bericht exportieren")
|
||||
|
||||
' Export it to pdf
|
||||
oReport.ExportToPdf(oFilePath)
|
||||
|
||||
MsgBox(My.Resources.frmImportMainExtra.Datei_erfolgreich_in_die_WinLine_übertragen, MsgBoxStyle.Information, Text)
|
||||
Catch ex As HttpRequestException
|
||||
FormHelper.ShowError(ex, My.Resources.frmImportMainExtra.Übertragung_zur_WinLine, My.Resources.frmImportMainExtra.Die_Verbindung_zum_WinLine_Server_ist_fehlgeschlagen)
|
||||
@@ -519,7 +529,10 @@ Public Class frmImportMain
|
||||
SplitContainerGrids.Enabled = False
|
||||
|
||||
Dim oDocument As Document = GridViewFiles.GetRow(GridViewFiles.FocusedRowHandle)
|
||||
Dim oReport = GenerateReport(Of OrderReport)(oDocument)
|
||||
Dim oReportGenerator = New ReportGenerator(Of OrderReport)(LogConfig, Database,
|
||||
My.TemplateConfiguration,
|
||||
My.GeneralConfiguration)
|
||||
Dim oReport As OrderReport = oReportGenerator.GenerateReport(oDocument)
|
||||
Dim oPrintTool As New ReportPrintTool(oReport)
|
||||
oPrintTool.Report.CreateDocument(False)
|
||||
oPrintTool.ShowPreview()
|
||||
@@ -529,135 +542,12 @@ Public Class frmImportMain
|
||||
GridControlFiles.Enabled = True
|
||||
SetDocumentButtonsEnabled(True)
|
||||
SplashScreenManager.CloseWaitForm()
|
||||
|
||||
|
||||
|
||||
Catch ex As Exception
|
||||
FormHelper.ShowError(ex, My.Resources.frmImportMainExtra.Erstellen_der_Berichtsvorschau)
|
||||
|
||||
End Try
|
||||
End Sub
|
||||
|
||||
Private Function GenerateReport(Of TReport)(pDocument As Document) As TReport
|
||||
|
||||
Dim oMapperConfig As New Mapper(LogConfig)
|
||||
Dim oHeadMapper = oMapperConfig.GetMapper(Of ReportHead)(New Dictionary(Of String, String) From {
|
||||
{"Fakt_Kontonummer[External]", "Text1"},
|
||||
{"Fakt_Kontonummer[Final]", "Text2"},
|
||||
{"Auftrags-Bestellnummer", "Text3"},
|
||||
{"Datum_Auftrag-Bestellung", "Text4"},
|
||||
{"Bestellt_von", "Text5"}
|
||||
})
|
||||
|
||||
Dim oPositionMapper = oMapperConfig.GetMapper(Of ReportPosition)(New Dictionary(Of String, String) From {
|
||||
{"Artikelnummer", "Text1"},
|
||||
{"Lieferantenartikelnummer", "Text2"},
|
||||
{"Menge_bestellt", "Text4"},
|
||||
{"Menge_geliefert", "Text5"},
|
||||
{"Colli", "Text6"},
|
||||
{"Einzelpreis[Original]", "Text7"},
|
||||
{"Einzelpreis[Final]", "Text8"},
|
||||
{"EinheitProPalette", "Text9"},
|
||||
{"Lagerstand", "Text10"}
|
||||
})
|
||||
|
||||
Dim oSQLConfig = My.TemplateConfiguration.Items.
|
||||
Where(Function(item) item.Function.Name = "SQL").
|
||||
ToList()
|
||||
|
||||
FillFieldValuesFromSQL(pDocument, oSQLConfig)
|
||||
|
||||
Dim oHeadRow = pDocument.Rows.
|
||||
Where(Function(r) r.Name.EndsWith("T025")).
|
||||
Select(Function(r) r.Fields).
|
||||
FirstOrDefault()
|
||||
Dim oPositionRows = pDocument.Rows.
|
||||
Where(Function(r) r.Name.EndsWith("T026")).
|
||||
ToList()
|
||||
|
||||
Dim oReportHead = oHeadMapper.Map(Of Dictionary(Of String, FieldValue), ReportHead)(oHeadRow)
|
||||
oReportHead.Title = "EDI Bestellung (orders)"
|
||||
oReportHead.Subtitle = "Schaum"
|
||||
oReportHead.Filename = pDocument.FileName
|
||||
|
||||
Dim oReportPositions As New List(Of ReportPosition)
|
||||
|
||||
Dim oCounter = 1
|
||||
|
||||
For Each oRow As DocumentRow In oPositionRows
|
||||
Dim oReportPosition As ReportPosition = oPositionMapper.Map(Of Dictionary(Of String, FieldValue), ReportPosition)(oRow.Fields)
|
||||
oReportPosition.Id = oCounter
|
||||
oReportPositions.Add(oReportPosition)
|
||||
|
||||
oCounter += 1
|
||||
Next
|
||||
|
||||
Dim oReportSource As New ReportSource With {
|
||||
.Head = oReportHead,
|
||||
.Positions = oReportPositions
|
||||
}
|
||||
|
||||
Dim oReport = Activator.CreateInstance(GetType(TReport))
|
||||
Dim oDataSource = New DevExpress.DataAccess.ObjectBinding.ObjectDataSource With {
|
||||
.DataSource = oReportSource
|
||||
}
|
||||
oDataSource.Fill()
|
||||
oReport.DataSource = oDataSource
|
||||
|
||||
Return oReport
|
||||
End Function
|
||||
|
||||
Private Sub FillFieldValuesFromSQL(pDocument As Document, oSQLConfig As List(Of TemplateConfigItem))
|
||||
For Each oSQLConfigItem In oSQLConfig
|
||||
' 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.
|
||||
Where(Function(row) row.Fields.Any(Function(field) field.Key = oSQLConfigItem.Name)).
|
||||
ToList()
|
||||
|
||||
For Each oRow As DocumentRow In oRowList
|
||||
Dim oField = oRow.Fields.
|
||||
Where(Function(field) field.Key = oSQLConfigItem.Name).
|
||||
SingleOrDefault()
|
||||
|
||||
Dim oRegex = New Regex("{#(\w+)#([\w\s_-]+)}+")
|
||||
Dim oSQL = oSQLConfigItem.Function.Params
|
||||
Dim oMatches As MatchCollection = oRegex.Matches(oSQL)
|
||||
|
||||
For Each oMatch As Match In oMatches
|
||||
Dim oPlaceholderString As String = oMatch.Groups.Item(0)?.Value
|
||||
Dim oPlaceholderType As String = oMatch.Groups.Item(1)?.Value
|
||||
Dim oPlaceholderValue As String = oMatch.Groups.Item(2)?.Value
|
||||
|
||||
Select Case oPlaceholderType.ToUpper
|
||||
Case "FIELD"
|
||||
Dim oFieldName = oPlaceholderValue
|
||||
Dim oTargetField = oRow.Fields.
|
||||
Where(Function(field) field.Key = oFieldName).
|
||||
SingleOrDefault()
|
||||
|
||||
oSQL = oSQL.Replace(oPlaceholderString, oTargetField.Value.Final)
|
||||
|
||||
Case "CONST"
|
||||
Select Case oMatch.Groups.Item(2).Value.ToUpper
|
||||
Case "MESOYEAR"
|
||||
oSQL = oSQL.Replace(oPlaceholderString, My.GeneralConfiguration.GetWinLineYear())
|
||||
|
||||
Case "MESOCOMP"
|
||||
oSQL = oSQL.Replace(oPlaceholderString, pDocument.Mandator.Id)
|
||||
|
||||
End Select
|
||||
End Select
|
||||
Next
|
||||
|
||||
Dim oValue = Database.GetScalarValue(oSQL)
|
||||
|
||||
If oValue IsNot Nothing Then
|
||||
oField.Value.Final = oValue
|
||||
End If
|
||||
Next
|
||||
Next
|
||||
End Sub
|
||||
|
||||
Private Sub GridViewFiles_CustomDrawCell(sender As Object, e As Views.Base.RowCellCustomDrawEventArgs) Handles GridViewFiles.CustomDrawCell
|
||||
Dim oDocument As Document = GridViewFiles.GetRow(e.RowHandle)
|
||||
|
||||
Reference in New Issue
Block a user