Rename Shared to Common
This commit is contained in:
129
MultiTool.Common/Report/ReportGenerator.vb
Normal file
129
MultiTool.Common/Report/ReportGenerator.vb
Normal file
@@ -0,0 +1,129 @@
|
||||
Imports System.Text.RegularExpressions
|
||||
Imports DevExpress.XtraReports
|
||||
Imports DigitalData.Modules.Database
|
||||
Imports DigitalData.Modules.Logging
|
||||
Imports MultiTool.Common.Documents
|
||||
Imports MultiTool.Common.Documents.DocumentRow
|
||||
Imports MultiTool.Common.Report
|
||||
Imports MultiTool.Common.Templates
|
||||
Imports MultiTool.Common.Winline.Entities
|
||||
|
||||
Public Class ReportGenerator(Of TReport As IReport)
|
||||
Inherits BaseClass
|
||||
|
||||
Private ReadOnly TemplateConfig As TemplateConfig
|
||||
Private ReadOnly GeneralConfig As GeneralConfig
|
||||
Private ReadOnly Patterns As Patterns
|
||||
Private ReadOnly FileEx As DigitalData.Modules.Filesystem.File
|
||||
|
||||
Public Sub New(pLogConfig As LogConfig, pDatabase As MSSQLServer, pTemplateConfig As TemplateConfig, pGeneralConfig As GeneralConfig)
|
||||
MyBase.New(pLogConfig)
|
||||
Database = pDatabase
|
||||
GeneralConfig = pGeneralConfig
|
||||
TemplateConfig = pTemplateConfig
|
||||
Patterns = New Patterns(pLogConfig, pGeneralConfig)
|
||||
FileEx = New DigitalData.Modules.Filesystem.File(LogConfig)
|
||||
End Sub
|
||||
|
||||
Public Function GetReportFilePath(pDocument As Document, pTemplate As Template)
|
||||
Dim oFinalDirectory = FileEx.CreateDateDirectory(pTemplate.OutputReportDirectory)
|
||||
Dim oFileName = FileEx.GetFilenameWithSuffix(IO.Path.GetFileNameWithoutExtension(pDocument.File.Name), FileEx.GetDateTimeString, "pdf")
|
||||
Dim oFilePath As String = IO.Path.Combine(oFinalDirectory, oFileName)
|
||||
Return oFilePath
|
||||
End Function
|
||||
|
||||
Public Function GenerateReport(pDocument As Document, pTemplate As Template) As TReport
|
||||
|
||||
Dim oMapperConfig As New Mapper(LogConfig)
|
||||
Dim oHeadMapper = oMapperConfig.GetMapper(Of ReportHead)(New Dictionary(Of String, String) From {
|
||||
{"Fakt_Kontoname", "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"},
|
||||
{"Bezeichnung", "Text3"},
|
||||
{"Menge_bestellt", "Text4"},
|
||||
{"Menge_geliefert", "Text5"},
|
||||
{"Colli", "Text6"},
|
||||
{"Einzelpreis[Original]", "Text7"},
|
||||
{"Einzelpreis[Final]", "Text8"},
|
||||
{"EinheitProPalette", "Text9"},
|
||||
{"Lagerstand", "Text10"}
|
||||
})
|
||||
|
||||
Dim oSQLConfig = TemplateConfig.Items.
|
||||
Where(Function(item) item.Function.Name = Constants.FUNCTION_SQL).
|
||||
ToList()
|
||||
|
||||
FillFieldValuesFromSQL(pDocument, oSQLConfig)
|
||||
|
||||
Dim oHeadRow = pDocument.Rows.
|
||||
Where(Function(r) r.TableName.EndsWith("T025")).
|
||||
Select(Function(r) r.Fields).
|
||||
FirstOrDefault()
|
||||
Dim oPositionRows = pDocument.Rows.
|
||||
Where(Function(r) r.TableName.EndsWith("T026")).
|
||||
ToList()
|
||||
|
||||
Dim oReportHead = oHeadMapper.Map(Of Dictionary(Of String, FieldValue), ReportHead)(oHeadRow)
|
||||
oReportHead.Title = pTemplate.Name
|
||||
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 oSQL = oSQLConfigItem.Function.Params
|
||||
oSQL = Patterns.ReplaceForImport(pDocument, oRow, oSQL)
|
||||
|
||||
Dim oValue = Database.GetScalarValue(oSQL)
|
||||
|
||||
If oValue IsNot Nothing Then
|
||||
oField.Value.Final = oValue
|
||||
End If
|
||||
Next
|
||||
Next
|
||||
End Sub
|
||||
End Class
|
||||
23
MultiTool.Common/Report/ReportHead.vb
Normal file
23
MultiTool.Common/Report/ReportHead.vb
Normal file
@@ -0,0 +1,23 @@
|
||||
Namespace Report
|
||||
Public Class ReportHead
|
||||
Public Property Title As String
|
||||
Public Property Subtitle As String
|
||||
Public Property Filename As String
|
||||
|
||||
Public Property DateCreated As Date
|
||||
Public Property Id As String
|
||||
|
||||
Public Property Text1 As String
|
||||
Public Property Text2 As String
|
||||
Public Property Text3 As String
|
||||
Public Property Text4 As String
|
||||
Public Property Text5 As String
|
||||
Public Property Text6 As String
|
||||
Public Property Text7 As String
|
||||
Public Property Text8 As String
|
||||
Public Property Text9 As String
|
||||
Public Property Text10 As String
|
||||
End Class
|
||||
|
||||
End Namespace
|
||||
|
||||
27
MultiTool.Common/Report/ReportPosition.vb
Normal file
27
MultiTool.Common/Report/ReportPosition.vb
Normal file
@@ -0,0 +1,27 @@
|
||||
Namespace Report
|
||||
Public Class ReportPosition
|
||||
Public Property Id As String
|
||||
|
||||
Public Property Text1 As String
|
||||
Public Property Text2 As String
|
||||
Public Property Text3 As String
|
||||
Public Property Text4 As String
|
||||
Public Property Text5 As String
|
||||
Public Property Text6 As String
|
||||
Public Property Text7 As String
|
||||
Public Property Text8 As String
|
||||
Public Property Text9 As String
|
||||
Public Property Text10 As String
|
||||
Public Property Text11 As String
|
||||
Public Property Text12 As String
|
||||
Public Property Text13 As String
|
||||
Public Property Text14 As String
|
||||
Public Property Text15 As String
|
||||
Public Property Text16 As String
|
||||
Public Property Text17 As String
|
||||
Public Property Text18 As String
|
||||
Public Property Text19 As String
|
||||
Public Property Text20 As String
|
||||
End Class
|
||||
|
||||
End Namespace
|
||||
18
MultiTool.Common/Report/ReportSource.vb
Normal file
18
MultiTool.Common/Report/ReportSource.vb
Normal file
@@ -0,0 +1,18 @@
|
||||
Imports System.ComponentModel
|
||||
Imports DevExpress.DataAccess.ObjectBinding
|
||||
|
||||
Namespace Report
|
||||
<HighlightedClass, DisplayName("ReportSource")>
|
||||
Public Class ReportSource
|
||||
<HighlightedMember>
|
||||
Public Property Head As ReportHead
|
||||
<HighlightedMember>
|
||||
Public Property Positions As IEnumerable(Of ReportPosition)
|
||||
<HighlightedMember>
|
||||
Public Iterator Function GetPositionList() As IEnumerable(Of ReportPosition)
|
||||
For Each oPosition In Positions
|
||||
Yield oPosition
|
||||
Next
|
||||
End Function
|
||||
End Class
|
||||
End Namespace
|
||||
Reference in New Issue
Block a user