WIP
This commit is contained in:
@@ -4,6 +4,7 @@ Imports DevExpress.XtraGrid.Columns
|
||||
Imports DevExpress.XtraRichEdit
|
||||
Imports DevExpress.XtraEditors
|
||||
Imports DevExpress.XtraReports.UI
|
||||
Imports DevExpress.DataAccess.ObjectBinding
|
||||
Imports DigitalData.Modules.Logging
|
||||
Imports DigitalData.Modules.Database
|
||||
Imports DigitalData.Modules.Config
|
||||
@@ -12,7 +13,7 @@ Imports DigitalData.GUIs.Common
|
||||
Imports ImporterShared.Documents
|
||||
Imports ImporterShared.Winline
|
||||
Imports ImporterShared.Schemas
|
||||
Imports ImporterForm.DocumentPositions
|
||||
Imports ImporterForm.Positions
|
||||
|
||||
Public Class frmMain
|
||||
Public LogConfig As LogConfig
|
||||
@@ -65,10 +66,12 @@ Public Class frmMain
|
||||
|
||||
' Load data for UI Fields
|
||||
cmbMandator.Properties.DataSource = Winline.Mandators
|
||||
|
||||
cmbCustomer.Properties.DataSource = Winline.Accounts
|
||||
cmbDeliveryAddress.Properties.DataSource = Winline.Accounts
|
||||
|
||||
cmbYears.Properties.Items.AddRange(Winline.Years)
|
||||
cmbYears.SelectedItem = Now.Year
|
||||
cmbYears.SelectedItem = ConfigManager.Config.GetYear()
|
||||
|
||||
' Initialize Grids
|
||||
GridBuilder = New GridBuilder(New List(Of GridView) From {GridViewFiles, GridViewPositions})
|
||||
@@ -82,6 +85,32 @@ Public Class frmMain
|
||||
End Try
|
||||
End Sub
|
||||
|
||||
#Region "Helpers"
|
||||
Private Function GetValidationMessage(FieldName As String) As String
|
||||
Return $"Das Feld '{FieldName}' muss ausgefüllt werden!"
|
||||
End Function
|
||||
|
||||
Private Function GetFocusedDocument() As Document
|
||||
Dim oRowHandles = GridViewFiles.GetSelectedRows().ToList()
|
||||
Dim oDocument As Document = GridViewFiles.GetRow(oRowHandles.First())
|
||||
Return oDocument
|
||||
End Function
|
||||
|
||||
Private Function GetFocusedPosition() As Position
|
||||
Dim oRowHandles = GridViewPositions.GetSelectedRows().ToList()
|
||||
Dim oPosition As Position = GridViewPositions.GetRow(oRowHandles.First())
|
||||
Return oPosition
|
||||
End Function
|
||||
|
||||
Private Sub TryOpenDirectory(pPath As String, pDisplayName As String)
|
||||
If Directory.Exists(pPath) Then
|
||||
Process.Start(pPath)
|
||||
Else
|
||||
MsgBox($"{pDisplayName} nicht konfiguriert oder nicht gefunden!", MsgBoxStyle.Exclamation, Text)
|
||||
End If
|
||||
End Sub
|
||||
#End Region
|
||||
|
||||
Private Sub btnLoadDocuments_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnLoadDocuments.ItemClick
|
||||
Try
|
||||
If DocumentLoader.LoadFiles(ConfigManager.Config.InputDirectory) = True Then
|
||||
@@ -90,6 +119,11 @@ Public Class frmMain
|
||||
RibbonGroupDocument.Enabled = True
|
||||
RibbonGroupPositions.Enabled = True
|
||||
|
||||
LayoutControlHead.Enabled = True
|
||||
GridControlPositions.Enabled = True
|
||||
|
||||
btnReloadDocument.Enabled = True
|
||||
|
||||
GridControlFiles.DataSource = DocumentLoader.Files
|
||||
txtFilesLoaded.Caption = $"{DocumentLoader.Files.Count} Dokumente geladen"
|
||||
End If
|
||||
@@ -111,42 +145,63 @@ Public Class frmMain
|
||||
Exit Sub
|
||||
End If
|
||||
|
||||
RichEditXml.LoadDocument(oDocument.FullName, DocumentFormat.PlainText)
|
||||
ShowDocument(oDocument)
|
||||
End Sub
|
||||
|
||||
Private Sub ShowDocument(pDocument As Document)
|
||||
' Load XML File in the sidebar
|
||||
RichEditXml.LoadDocument(pDocument.FullName, DocumentFormat.PlainText)
|
||||
|
||||
If pDocument.Mandator Is Nothing Then
|
||||
Dim oForm As New frmMandatorSelection() With {
|
||||
.Mandators = Winline.Mandators,
|
||||
.SelectedMandator = Nothing
|
||||
}
|
||||
Dim oResult = oForm.ShowDialog()
|
||||
|
||||
If oResult <> DialogResult.OK Then
|
||||
Exit Sub
|
||||
End If
|
||||
|
||||
pDocument.Mandator = oForm.SelectedMandator.Id
|
||||
End If
|
||||
|
||||
Try
|
||||
Select Case oDocument.Type
|
||||
Select Case pDocument.Type
|
||||
Case DocumentType.Order
|
||||
ShowDocument(oDocument, oDocument.Data, oDocument.DataOriginal)
|
||||
ShowOrderDocument(pDocument)
|
||||
|
||||
End Select
|
||||
|
||||
Catch ex As Xml.XmlException
|
||||
Dim oMessage As String = $"Fehler beim Laden des Dokuments {oDocument.Name}:{vbNewLine}{ex.Message}"
|
||||
Dim oMessage As String = $"Fehler beim Laden des Dokuments {pDocument.Name}:{vbNewLine}{ex.Message}"
|
||||
MsgBox(oMessage, MsgBoxStyle.Critical, Text)
|
||||
Logger.Error(ex)
|
||||
|
||||
Catch ex As Exceptions.NoMandatorException
|
||||
Dim oMessage As String = $"Fehler beim Laden des Dokuments {oDocument.Name}:{vbNewLine}{ex.Message}"
|
||||
Dim oMessage As String = $"Fehler beim Laden des Dokuments {pDocument.Name}:{vbNewLine}{ex.Message}"
|
||||
MsgBox(oMessage, MsgBoxStyle.Critical, Text)
|
||||
Logger.Error(ex)
|
||||
|
||||
Catch ex As Exception
|
||||
Dim oMessage As String = $"Unerwarteter Fehler beim Laden des Dokuments {oDocument.Name}:{vbNewLine}{ex.Message}"
|
||||
Dim oMessage As String = $"Unerwarteter Fehler beim Laden des Dokuments {pDocument.Name}:{vbNewLine}{ex.Message}"
|
||||
MsgBox(oMessage, MsgBoxStyle.Critical, Text)
|
||||
Logger.Error(ex)
|
||||
|
||||
End Try
|
||||
End Sub
|
||||
|
||||
Private Sub ShowDocument(pDocument As Document, pData As Orders.Input.MESOWebService, pDataOriginal As Orders.Input.MESOWebService)
|
||||
Private Sub ShowOrderDocument(pDocument As Document)
|
||||
If pDocument.Mandator Is Nothing Then
|
||||
Throw New Exceptions.NoMandatorException("Es konnte kein Mandant gefunden werden")
|
||||
End If
|
||||
|
||||
Dim oHead = GetOrderHead(pData)
|
||||
Dim oHeadOriginal = GetOrderHead(pDataOriginal)
|
||||
Dim oData As Orders.Input.MESOWebService = DirectCast(pDocument.Data, Orders.Input.MESOWebService)
|
||||
Dim oDataOriginal As Orders.Input.MESOWebService = DirectCast(pDocument.DataOriginal, Orders.Input.MESOWebService)
|
||||
Dim oHead = Orders.Helpers.GetOrderHead(oData)
|
||||
Dim oHeadOriginal = Orders.Helpers.GetOrderHead(oDataOriginal)
|
||||
|
||||
' ====== Head Data ======
|
||||
' --- Head Data --------------------------------------------------------------------------------------
|
||||
|
||||
' Original, Unreplaced Data
|
||||
txtCustomerGLN.Text = oHeadOriginal.Fakt_Kontonummer
|
||||
@@ -160,121 +215,67 @@ Public Class frmMain
|
||||
txtDocumentReference.Text = oHead.Auftragsreferenz
|
||||
dateOrderDate.EditValue = oHead.Datum_AuftragBestellung
|
||||
|
||||
Dim oMandator = Winline.Mandators.
|
||||
Where(Function(m) m.Id = pDocument.Mandator).
|
||||
SingleOrDefault()
|
||||
' --- Find Mandator --------------------------------------------------------------------------------------
|
||||
|
||||
If oMandator Is Nothing Then
|
||||
cmbMandator.ErrorText = "Dieses Feld muss ausgefüllt werden!"
|
||||
cmbMandator.EditValue = Nothing
|
||||
Else
|
||||
cmbMandator.EditValue = oMandator
|
||||
End If
|
||||
Dim oMandator = Winline.Mandators.
|
||||
Where(Function(m) m.Id = pDocument.Mandator).
|
||||
SingleOrDefault()
|
||||
cmbMandator.EditValue = oMandator
|
||||
|
||||
' --- Find Accounts --------------------------------------------------------------------------------------
|
||||
|
||||
' FAKTURA
|
||||
|
||||
If oHead.Fakt_Kontonummer = oHeadOriginal.Fakt_Kontonummer Then
|
||||
cmbCustomer.ErrorText = "Dieses Feld muss ausgefüllt werden!"
|
||||
cmbCustomer.ErrorText = GetValidationMessage("Faktura Konto")
|
||||
cmbCustomer.EditValue = Nothing
|
||||
Else
|
||||
cmbCustomer.EditValue = Winline.Accounts.
|
||||
Where(Function(oAccount)
|
||||
Dim oSelectedMandator As Mandator = cmbMandator.EditValue
|
||||
Return oAccount.Id = oHead.Fakt_Kontonummer And oAccount.Mandator = oSelectedMandator.Id
|
||||
End Function).
|
||||
SingleOrDefault()
|
||||
Dim oMatchingAccounts = Winline.Accounts.
|
||||
Where(Function(oAccount) oAccount.Mandator = oMandator.Id).
|
||||
Where(Function(oAccount) oAccount.Id = oHead.Fakt_Kontonummer)
|
||||
|
||||
If oMatchingAccounts.Count() > 1 Then
|
||||
Throw New Exceptions.MultipleAccountsException("Für die Kontonummer wurden mehrere Konten gefunden.")
|
||||
End If
|
||||
|
||||
If oMatchingAccounts.Count() = 0 Then
|
||||
Throw New Exceptions.NoAccountException("Für die Kontonummer wurde kein Konto gefunden.")
|
||||
End If
|
||||
|
||||
cmbCustomer.EditValue = oMatchingAccounts.SingleOrDefault()
|
||||
|
||||
End If
|
||||
|
||||
' DEVLIERY
|
||||
If oHead.Lief_Kontonummer = oHeadOriginal.Lief_Kontonummer Then
|
||||
cmbDeliveryAddress.ErrorText = "Dieses Feld muss ausgefüllt werden!"
|
||||
cmbDeliveryAddress.ErrorText = GetValidationMessage("Lieferanten Konto")
|
||||
cmbDeliveryAddress.EditValue = Nothing
|
||||
Else
|
||||
cmbDeliveryAddress.EditValue = Winline.Accounts.
|
||||
Where(Function(oAccount) oAccount.Id = oHead.Lief_Kontonummer And oAccount.Mandator = cmbMandator.EditValue).
|
||||
SingleOrDefault()
|
||||
Dim oMatchingAccounts = Winline.Accounts.
|
||||
Where(Function(oAccount) oAccount.Mandator = oMandator.Id).
|
||||
Where(Function(oAccount) oAccount.Id = oHead.Lief_Kontonummer)
|
||||
|
||||
If oMatchingAccounts.Count() > 1 Then
|
||||
Throw New Exceptions.MultipleAccountsException("Für die Kontonummer wurden mehrere Konten gefunden.")
|
||||
End If
|
||||
|
||||
If oMatchingAccounts.Count() = 0 Then
|
||||
Throw New Exceptions.NoAccountException("Für die Kontonummer wurde kein Konto gefunden.")
|
||||
End If
|
||||
|
||||
cmbDeliveryAddress.EditValue = oMatchingAccounts.SingleOrDefault()
|
||||
|
||||
End If
|
||||
|
||||
' TODO
|
||||
'cmbMandator.EditValue = Winline.Mandators.
|
||||
' Where(Function(m) m.Id = "SIVT").
|
||||
' SingleOrDefault()
|
||||
'cmbCustomer.EditValue = Winline.Accounts.
|
||||
' Where(Function(oAccount) oAccount.Id = oHead.Fakt_Kontonummer And oAccount.Mandator = cmbMandator.EditValue).
|
||||
' SingleOrDefault()
|
||||
|
||||
PositionGrid.LoadPositionViewAndColumns(GridViewPositions, DocumentType.Order)
|
||||
|
||||
LoadPositionViewAndColumns(GridViewPositions, DocumentType.Order)
|
||||
LoadPositionData(pData, pDataOriginal)
|
||||
Dim oPositionList = PositionData.Load(oData, oDataOriginal)
|
||||
GridControlPositions.DataSource = oPositionList
|
||||
GridViewPositions.BestFitColumns()
|
||||
End Sub
|
||||
|
||||
Public Sub LoadPositionData(pData As Orders.Input.MESOWebService, pDataOriginal As Orders.Input.MESOWebService)
|
||||
Dim oPositions = GetOrderPositions(pData)
|
||||
Dim oPositionsOriginal = GetOrderPositions(pDataOriginal)
|
||||
Dim oPositionList As New List(Of OrderPosition)
|
||||
|
||||
For Each oPosition In oPositions
|
||||
Dim oPositionOriginal = oPositionsOriginal.
|
||||
Where(Function(p) p.Zeilennummer = oPosition.Zeilennummer).
|
||||
SingleOrDefault()
|
||||
|
||||
oPositionList.Add(New OrderPosition With {
|
||||
.ArticleNumber = oPosition.Artikelnummer,
|
||||
.RowNumber = oPosition.Zeilennummer,
|
||||
.ArticleDescription = oPosition.Bezeichnung,
|
||||
.ArticleNumberVendor = oPosition.Lieferantenartikelnummer,
|
||||
.EDIPrice = oPosition.Einzelpreis,
|
||||
.WinLinePrice = 0,
|
||||
.Price = 0,
|
||||
.Amount = oPosition.Menge_bestellt,
|
||||
.EuropeanArticleNumber = oPositionOriginal.Artikelnummer
|
||||
})
|
||||
Next
|
||||
|
||||
GridControlPositions.DataSource = oPositionList
|
||||
End Sub
|
||||
|
||||
Public Sub LoadPositionViewAndColumns(pView As GridView, pDocumentType As DocumentType)
|
||||
Dim oColumns As List(Of GridColumn)
|
||||
|
||||
' Create columns list depending on DocumentType
|
||||
Select Case pDocumentType
|
||||
Case DocumentType.Order
|
||||
oColumns = New List(Of GridColumn) From {
|
||||
ColumnRowNumber,
|
||||
ColumnArticleNumber,
|
||||
ColumnArticleNumberVendor,
|
||||
ColumnEuropeanArticleNumber,
|
||||
ColumnArticleDescription,
|
||||
ColumnEDIPrice,
|
||||
ColumnWinLinePrice,
|
||||
ColumnPrice
|
||||
}
|
||||
|
||||
Case Else
|
||||
oColumns = New List(Of GridColumn)
|
||||
End Select
|
||||
|
||||
' Reset the grid
|
||||
pView.GridControl.DataSource = Nothing
|
||||
pView.GridControl.ForceInitialize()
|
||||
|
||||
' Add and adjust columns
|
||||
pView.Columns.AddRange(oColumns.ToArray())
|
||||
pView.BestFitColumns()
|
||||
|
||||
' Set columns readonly that need it
|
||||
Dim oReadOnlyColumns = oColumns.
|
||||
Except(DocumentPositions.WritableColumns).
|
||||
ToList()
|
||||
|
||||
For Each oColumn As GridColumn In GridViewPositions.Columns
|
||||
If oReadOnlyColumns.Contains(oColumn) Then
|
||||
oColumn.OptionsColumn.ReadOnly = True
|
||||
oColumn.OptionsColumn.AllowEdit = False
|
||||
Else
|
||||
oColumn.Caption &= " *"
|
||||
End If
|
||||
Next
|
||||
End Sub
|
||||
|
||||
Private Sub BarButtonItem1_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItem1.ItemClick
|
||||
TryOpenDirectory(ConfigManager.Config.InputDirectory, "Eingangsverzeichnis")
|
||||
@@ -313,36 +314,6 @@ Public Class frmMain
|
||||
sender.ErrorText = ""
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Private Sub TryOpenDirectory(pPath As String, pDisplayName As String)
|
||||
If Directory.Exists(pPath) Then
|
||||
Process.Start(pPath)
|
||||
Else
|
||||
MsgBox($"{pDisplayName} nicht konfiguriert oder nicht gefunden!", MsgBoxStyle.Exclamation, Text)
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Private Function GetOrderHead(pData As Orders.Input.MESOWebService) As Orders.Input.MESOWebServiceEXIMVRG_ordersT025
|
||||
Dim oHead As Orders.Input.MESOWebServiceEXIMVRG_ordersT025 = pData.Items.
|
||||
Where(Function(i) TypeOf i Is Orders.Input.MESOWebServiceEXIMVRG_ordersT025).
|
||||
FirstOrDefault()
|
||||
Return oHead
|
||||
End Function
|
||||
|
||||
Private Function GetOrderPositions(pData As Orders.Input.MESOWebService) As List(Of Orders.Input.MESOWebServiceEXIMVRG_ordersT026)
|
||||
Dim oPositions As List(Of Orders.Input.MESOWebServiceEXIMVRG_ordersT026) = pData.Items.
|
||||
Where(Function(i) TypeOf i Is Orders.Input.MESOWebServiceEXIMVRG_ordersT026).
|
||||
Select(Of Orders.Input.MESOWebServiceEXIMVRG_ordersT026)(Function(i) i).
|
||||
ToList()
|
||||
Return oPositions
|
||||
End Function
|
||||
|
||||
Private Function GetFocusedDocument() As Document
|
||||
Dim oRowHandles = GridViewFiles.GetSelectedRows().ToList()
|
||||
Dim oDocument As Document = GridViewFiles.GetRow(oRowHandles.First())
|
||||
Return oDocument
|
||||
End Function
|
||||
|
||||
Private Sub btnPreviewReport_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnPreviewReport.ItemClick
|
||||
Dim oDocument As Document = GetFocusedDocument()
|
||||
If oDocument Is Nothing Then
|
||||
@@ -352,8 +323,8 @@ Public Class frmMain
|
||||
Dim oReport As New OrderReport()
|
||||
Dim oDataSource = New DevExpress.DataAccess.ObjectBinding.ObjectDataSource With {
|
||||
.DataSource = New Orders.ReportSource With {
|
||||
.Head = GetOrderHead(oDocument.Data),
|
||||
.Positions = GetOrderPositions(oDocument.Data)
|
||||
.Head = Orders.Helpers.GetOrderHead(oDocument.Data),
|
||||
.Positions = Orders.Helpers.GetOrderPositions(oDocument.Data)
|
||||
}
|
||||
}
|
||||
oDataSource.Fill()
|
||||
@@ -364,6 +335,32 @@ Public Class frmMain
|
||||
End Sub
|
||||
|
||||
Private Sub btnReloadDocument_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnReloadDocument.ItemClick
|
||||
Dim oDocument As Document = GetFocusedDocument()
|
||||
|
||||
If oDocument Is Nothing Then
|
||||
Exit Sub
|
||||
End If
|
||||
|
||||
ShowDocument(oDocument)
|
||||
End Sub
|
||||
|
||||
Private Sub btnDeletePosition_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnDeletePosition.ItemClick
|
||||
Dim oPosition = GetFocusedPosition()
|
||||
|
||||
If oPosition Is Nothing Then
|
||||
MsgBox("Bitte wählen Sie eine Position aus!", MsgBoxStyle.Exclamation, Text)
|
||||
Exit Sub
|
||||
End If
|
||||
|
||||
Dim oResult = MsgBox($"Wollen Sie die ausgewählte Position Artikel [{oPosition.ArticleNumber}] wirklich löschen?", MsgBoxStyle.Question Or MsgBoxStyle.YesNo, Text)
|
||||
|
||||
If oResult = MsgBoxResult.Yes Then
|
||||
GridViewPositions.DeleteSelectedRows()
|
||||
MsgBox("Position gelöscht")
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Private Sub BarButtonItem7_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItem7.ItemClick
|
||||
MsgBox("Mach et!")
|
||||
End Sub
|
||||
End Class
|
||||
Reference in New Issue
Block a user