This commit is contained in:
Jonathan Jenne
2021-11-11 16:31:08 +01:00
parent 8dcd06154d
commit 6bed0b3024
25 changed files with 1390 additions and 1393 deletions

View File

@@ -17,6 +17,7 @@ Imports MultiTool.Shared.Winline
Imports MultiTool.Shared.Constants
Imports DevExpress.XtraReports.UI
Imports MultiTool.Shared.Documents.DocumentRow
Imports DevExpress.XtraGrid.Columns
Public Class frmImportMain
Private LogConfig As LogConfig
@@ -100,8 +101,8 @@ Public Class frmImportMain
FormHelper.ShowError(ex, My.Resources.frmImportMainExtra.Initialisieren_der_Anwendungs_Daten)
End Try
txtVersion.Caption = String.Format(txtVersion.Tag.ToString, My.Application.Info.Version.ToString)
txtCulture.Caption = String.Format(txtCulture.Tag.ToString, My.Application.UICulture.ToString)
txtVersion.Caption = String.Format(My.Resources.frmImportMainExtra.Version__0_, My.Application.Info.Version.ToString)
txtCulture.Caption = String.Format(My.Resources.frmImportMainExtra.Culture___0_, My.Application.UICulture.ToString)
End Sub
Private Async Sub frmImportMain_Shown(sender As Object, e As EventArgs) Handles MyBase.Shown
@@ -167,24 +168,28 @@ Public Class frmImportMain
If oTableCounter = 0 Then
Dim oGrid = GridLoader.GetGridFromElement(GridControl1, oTable)
AddHandler oGrid.DoubleClick, AddressOf Grid_MouseDoubleClick
AddHandler DirectCast(oGrid.FocusedView, GridView).CustomDrawCell, AddressOf GridView_CustomDrawCell
oGrids.Add(oGrid)
End If
If oTableCounter = 1 Then
Dim oGrid = GridLoader.GetGridFromElement(GridControl2, oTable)
AddHandler oGrid.DoubleClick, AddressOf Grid_MouseDoubleClick
AddHandler DirectCast(oGrid.FocusedView, GridView).CustomDrawCell, AddressOf GridView_CustomDrawCell
oGrids.Add(oGrid)
End If
If oTableCounter = 2 Then
Dim oGrid = GridLoader.GetGridFromElement(GridControl3, oTable)
AddHandler oGrid.DoubleClick, AddressOf Grid_MouseDoubleClick
AddHandler DirectCast(oGrid.FocusedView, GridView).CustomDrawCell, AddressOf GridView_CustomDrawCell
oGrids.Add(oGrid)
End If
If oTableCounter = 3 Then
Dim oGrid = GridLoader.GetGridFromElement(GridControl4, oTable)
AddHandler oGrid.DoubleClick, AddressOf Grid_MouseDoubleClick
AddHandler DirectCast(oGrid.FocusedView, GridView).CustomDrawCell, AddressOf GridView_CustomDrawCell
oGrids.Add(oGrid)
End If
@@ -202,7 +207,7 @@ Public Class frmImportMain
Return oGrids
End Function
Private Sub Grid_MouseDoubleClick(sender As Object, e As MouseEventArgs) Handles GridControlFiles.MouseDoubleClick
Private Sub Grid_MouseDoubleClick(sender As Object, e As MouseEventArgs)
Try
Dim oGrid As GridControl = DirectCast(sender, GridControl)
Dim oView As GridView = DirectCast(oGrid.FocusedView, GridView)
@@ -234,13 +239,22 @@ Public Class frmImportMain
Private Sub btnLoadFiles_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnLoadFiles.ItemClick
Try
SplashScreenManager.ShowWaitForm()
SetDocumentButtonsEnabled(False)
GridControlFiles.Enabled = False
btnLoadFiles.Enabled = False
SplitContainerGrids.Enabled = False
AddHandler DocumentLoader.FileLoadComplete, Sub(_sender As Object, _e As DocumentLoader.FileLoadInfo)
Dim oMessage = String.Format("Lade Dateien ({0}/{1})", _e.FilesLoaded, _e.FilesTotal)
SplashScreenManager.SetWaitFormDescription(oMessage)
End Sub
If DocumentLoader.LoadFiles(ConfigManager.Config.InputDirectory, CurrentSchema, lookupMandator.EditValue) Then
GridControlFiles.DataSource = Nothing
GridControlFiles.DataSource = DocumentLoader.Files
txtFilesLoaded.Caption = String.Format(txtFilesLoaded.Tag.ToString, DocumentLoader.Files.Count)
txtFilesLoaded.Caption = String.Format(My.Resources.frmImportMainExtra._0__Dateien_geladen, DocumentLoader.Files.Count)
End If
Catch ex As Exceptions.NoMandatorException
MsgBox(My.Resources.frmImportMainExtra.Es_konnte_kein_passender_Mandant_ermittelt_werden, MsgBoxStyle.Information, Text)
@@ -250,6 +264,10 @@ Public Class frmImportMain
Finally
SplitContainerGrids.Enabled = True
btnLoadFiles.Enabled = True
GridControlFiles.Enabled = True
SetDocumentButtonsEnabled(True)
SplashScreenManager.CloseWaitForm()
End Try
End Sub
@@ -302,46 +320,57 @@ Public Class frmImportMain
Try
Dim oDatasources As New Dictionary(Of String, DataTable)
' Reset datasource so that all data will be refreshed
For Each oGrid In Grids
oGrid.DataSource = Nothing
Next
' Create initial Datatable for each Root Element
For Each oTable In CurrentSchema.Tables
Dim oDataTable As New DataTable()
' This is makes it possible to fetch the DocumentRow later
oDataTable.Columns.Add(New DataColumn(COLUMN_GUID))
For Each oColumn In oTable.Columns
oDataTable.Columns.Add(New DataColumn(oColumn.Name))
Next
oDatasources.Add(oTable.Name, oDataTable)
Next
' List of Root Elements in XML
For Each oRow In pDocument.Rows
' Grab grid for the current DocumentRow
Dim oGrid As GridControl = Grids.
Where(Function(g) g.Name = oRow.Name).
SingleOrDefault()
' Create initial Datatable if none exists for this Root Element
If Not oDatasources.ContainsKey(oRow.Name) Then
Dim oTable As New DataTable()
oTable.Columns.Add(New DataColumn(COLUMN_GUID))
For Each oField In oRow.Fields
oTable.Columns.Add(New DataColumn(oField.Key))
Next
oDatasources.Add(oRow.Name, oTable)
oGrid.DataSource = Nothing
oGrid.DataSource = oTable
End If
Dim oDataTable = oDatasources.Item(oRow.Name)
' Grab table for the current DocumentRow and create new row
Dim oDataTable As DataTable = oDatasources.Item(oRow.Name)
Dim oDataRow = oDataTable.NewRow()
' Assign the Guid of the DocumentRow
oDataRow.Item(COLUMN_GUID) = oRow.Id.ToString
' Set values for the current row
For Each oField In oRow.Fields
oDataRow.Item(oField.Key) = oField.Value
If oDataTable.Columns.Contains(oField.Key) Then
oDataRow.Item(oField.Key) = oField.Value
Else
Logger.Warn("Element [{0}] from files does not exist in Schema. Skipping.", oField.Key)
End If
Next
' Add row to the current table
oDataTable.Rows.Add(oDataRow)
oDataTable.AcceptChanges()
' Finally load data into grid
oGrid.DataSource = oDataTable
Next
txtCurrentFile.Caption = String.Format(txtCurrentFile.Tag.ToString, pDocument.Name)
txtCurrentFile.Caption = String.Format(My.Resources.frmImportMainExtra.Aktuelle_Datei___0_, pDocument.Name)
CurrentDocument = pDocument
SetDocumentButtonsEnabled(True)
@@ -356,6 +385,8 @@ Public Class frmImportMain
btnShowXml.Enabled = pEnabled
btnReloadFile.Enabled = pEnabled
btnTransferFile.Enabled = pEnabled
btnRemoveRow.Enabled = pEnabled
btnOpenReport.Enabled = pEnabled
' TODO: Implement all file transfer first
' btnTransferAllFiles.Enabled = pEnabled
End Sub
@@ -483,14 +514,19 @@ Public Class frmImportMain
Dim oDocument As Document = GridViewFiles.GetRow(GridViewFiles.FocusedRowHandle)
Dim oMapperConfig As New Mapper(LogConfig)
Dim oHeadMapper = oMapperConfig.GetMapper(Of ReportHead)(New Dictionary(Of String, String) From {
{"Fakt_Kontonummer[Original]", "Text1"},
{"Auftrags-Bestellnummer", "Text2"},
{"Datum_Auftrag-Bestellung", "Text5"}
{"Fakt_Kontonummer[Final]", "Text2"},
{"Auftrags-Bestellnummer", "Text3"},
{"Datum_Auftrag-Bestellung", "Text4"}
})
Dim oPositionMapper = oMapperConfig.GetMapper(Of ReportPosition)(New Dictionary(Of String, String) From {
{"BELEGKEY", "Text1"},
{"Artikelnummer", "Text2"}
{"Artikelnummer", "Text1"},
{"Lieferantenartikelnummer", "Text2"},
{"Menge_bestellt", "Text4"},
{"Menge_geliefert", "Text5"},
{"Colli", "Text6"},
{"Einzelpreis", "Text7"},
{"Umsatzsteuerprozent_Zeile", "Text8"}
})
Dim oHeadRow = oDocument.Rows.
@@ -502,9 +538,12 @@ Public Class frmImportMain
ToList()
Dim oReportHead = oHeadMapper.Map(Of Dictionary(Of String, FieldValue), ReportHead)(oHeadRow)
oReportHead.Title = "EDI Bestellung (orders)"
oReportHead.Subtitle = "Schaum"
Dim oReportPositions As New List(Of ReportPosition)
Dim oCounter = 0
Dim oCounter = 1
For Each oRow As DocumentRow In oPositionRows
Dim oReportPosition As ReportPosition = oPositionMapper.Map(Of Dictionary(Of String, FieldValue), ReportPosition)(oRow.Fields)
@@ -519,7 +558,7 @@ Public Class frmImportMain
.Positions = oReportPositions
}
Dim oReport As New XtraReport3
Dim oReport As New OrderReport
Dim oDataSource = New DevExpress.DataAccess.ObjectBinding.ObjectDataSource With {
.DataSource = oReportSource
}
@@ -530,4 +569,36 @@ Public Class frmImportMain
printTool.Report.CreateDocument(False)
printTool.ShowPreviewDialog()
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
e.Appearance.Options.UseBackColor = True
e.Appearance.BackColor = Color.LightCoral
End If
End Sub
Private Sub GridView_CustomDrawCell(sender As Object, e As Views.Base.RowCellCustomDrawEventArgs)
Dim oView As GridView = sender
If e.RowHandle < 0 Or CurrentDocument Is Nothing Then
Exit Sub
End If
Dim oObject As DataRowView = oView.GetRow(e.RowHandle)
Dim oGuid = oObject.Row.Item(COLUMN_GUID)
Dim oRow As DocumentRow = CurrentDocument.Rows.
Where(Function(r) r.Id.ToString = oGuid).
SingleOrDefault()
If oRow Is Nothing Then
Exit Sub
End If
If oRow.HasErrors Then
e.Appearance.Options.UseBackColor = True
e.Appearance.BackColor = Color.LightCoral
End If
End Sub
End Class