Report, Dynamic SQL
This commit is contained in:
@@ -18,6 +18,7 @@ Imports MultiTool.Shared.Constants
|
||||
Imports MultiTool.Shared.Exceptions
|
||||
Imports DevExpress.XtraReports.UI
|
||||
Imports MultiTool.Shared.Documents.DocumentRow
|
||||
Imports System.Text.RegularExpressions
|
||||
|
||||
Public Class frmImportMain
|
||||
Public LogConfig As LogConfig
|
||||
@@ -116,7 +117,7 @@ Public Class frmImportMain
|
||||
lookupMandator.ForceInitialize()
|
||||
lookupMandator.Properties.View.BestFitColumns()
|
||||
|
||||
DocumentLoader = New DocumentLoader(LogConfig, Winline)
|
||||
DocumentLoader = New DocumentLoader(LogConfig, Winline, My.MappingConfiguration, My.TemplateConfiguration)
|
||||
GridLoader = New GridLoader(LogConfig)
|
||||
|
||||
SplashScreenManager.SetWaitFormDescription(My.Resources.frmImportMainExtra.Lade_Vorlagen)
|
||||
@@ -297,12 +298,25 @@ Public Class frmImportMain
|
||||
|
||||
Private Sub GridViewFiles_FocusedRowChanged(sender As Object, e As Views.Base.FocusedRowChangedEventArgs) Handles GridViewFiles.FocusedRowChanged
|
||||
Try
|
||||
SplitContainerMain.Panel2.Enabled = True
|
||||
Dim oDocument As Document = GridViewFiles.GetRow(e.FocusedRowHandle)
|
||||
|
||||
If oDocument Is Nothing Then
|
||||
Exit Sub
|
||||
End If
|
||||
|
||||
If oDocument.Mandator Is Nothing Then
|
||||
lookupMandator.EditValue = Nothing
|
||||
SplitContainerMain.Panel2.Enabled = False
|
||||
|
||||
For Each oGrid In Grids
|
||||
oGrid.DataSource = Nothing
|
||||
Next
|
||||
|
||||
MsgBox("Für die aktuelle Datei konnte kein Mandant zugeordnet werden! Bitte wählen Sie einen aus und laden Sie dann die Datei erneut.", MsgBoxStyle.Exclamation, Text)
|
||||
Exit Sub
|
||||
End If
|
||||
|
||||
lookupMandator.EditValue = oDocument.Mandator
|
||||
LoadDocument(oDocument)
|
||||
Catch ex As Exception
|
||||
@@ -534,9 +548,17 @@ Public Class frmImportMain
|
||||
{"Colli", "Text6"},
|
||||
{"Einzelpreis[Original]", "Text7"},
|
||||
{"Einzelpreis[Final]", "Text8"},
|
||||
{"Umsatzsteuerprozent_Zeile", "Text9"}
|
||||
{"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).
|
||||
@@ -580,6 +602,58 @@ Public Class frmImportMain
|
||||
Return oPrintTool
|
||||
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)
|
||||
If oDocument.HasErrors Then
|
||||
@@ -607,8 +681,15 @@ Public Class frmImportMain
|
||||
End If
|
||||
|
||||
If oRow.HasErrors Then
|
||||
e.Appearance.Options.UseBackColor = True
|
||||
e.Appearance.BackColor = Color.LightCoral
|
||||
|
||||
Dim oColumName = e.Column.FieldName
|
||||
Dim oErrorField = oRow.Fields.Where(Function(field) field.Value.HasError).FirstOrDefault()
|
||||
|
||||
If Not IsNothing(oErrorField) AndAlso oColumName = oErrorField.Key Then
|
||||
e.Appearance.Options.UseBackColor = True
|
||||
e.Appearance.BackColor = Color.LightCoral
|
||||
End If
|
||||
|
||||
End If
|
||||
End Sub
|
||||
|
||||
@@ -638,6 +719,4 @@ Public Class frmImportMain
|
||||
SplashScreenManager.CloseWaitForm()
|
||||
End Try
|
||||
End Sub
|
||||
|
||||
|
||||
End Class
|
||||
Reference in New Issue
Block a user