369 lines
15 KiB
VB.net
369 lines
15 KiB
VB.net
Imports System.IO
|
|
Imports DevExpress.XtraGrid.Views.Grid
|
|
Imports DevExpress.XtraGrid.Columns
|
|
Imports DevExpress.XtraRichEdit
|
|
Imports DevExpress.XtraEditors
|
|
Imports DevExpress.XtraReports.UI
|
|
Imports DigitalData.Modules.Logging
|
|
Imports DigitalData.Modules.Database
|
|
Imports DigitalData.Modules.Config
|
|
Imports DigitalData.Controls.SQLConfig
|
|
Imports DigitalData.GUIs.Common
|
|
Imports ImporterShared.Documents
|
|
Imports ImporterShared.Winline
|
|
Imports ImporterShared.Schemas
|
|
Imports ImporterForm.DocumentPositions
|
|
|
|
Public Class frmMain
|
|
Public LogConfig As LogConfig
|
|
Public Logger As Logger
|
|
Public ConfigManager As ConfigManager(Of ImporterShared.Config)
|
|
Public Database As MSSQLServer
|
|
Public DocumentLoader As DocumentLoader
|
|
Public GridBuilder As GridBuilder
|
|
|
|
Public Winline As Data
|
|
Public WebService As WebService
|
|
|
|
Private Sub frmMain_Load(sender As Object, e As EventArgs) Handles MyBase.Load
|
|
Try
|
|
txtVersion.Caption = String.Format(txtVersion.Caption, Application.ProductVersion)
|
|
|
|
LogConfig = New LogConfig(LogConfig.PathType.AppData, Nothing, Nothing, "Digital Data", "EDI Document Importer")
|
|
ConfigManager = New ConfigManager(Of ImporterShared.Config)(LogConfig,
|
|
Application.UserAppDataPath,
|
|
Application.CommonAppDataPath,
|
|
Application.StartupPath)
|
|
Logger = LogConfig.GetLogger()
|
|
|
|
' If ConnectionString does not exist, show SQL Config Form
|
|
If ConfigManager.Config.ConnectionString = String.Empty Then
|
|
Dim oForm As New frmSQLConfig(LogConfig) With {
|
|
.FormTitle = "EDI Document Importer"
|
|
}
|
|
Dim oResult = oForm.ShowDialog()
|
|
|
|
If oResult = DialogResult.OK Then
|
|
ConfigManager.Config.ConnectionString = oForm.ConnectionString
|
|
ConfigManager.Save()
|
|
End If
|
|
End If
|
|
|
|
' Initialize Database
|
|
Dim oConnectionString = MSSQLServer.DecryptConnectionString(ConfigManager.Config.ConnectionString)
|
|
Database = New MSSQLServer(LogConfig, oConnectionString)
|
|
Winline = New Data(LogConfig, Database, ConfigManager.Config)
|
|
WebService = New WebService(LogConfig, ConfigManager.Config)
|
|
|
|
' Load WinLine Data
|
|
Winline.Mandators.Clear()
|
|
Winline.LoadMandators()
|
|
Winline.LoadEconomicYears()
|
|
For Each oMandator In Winline.Mandators
|
|
Winline.LoadAccounts(oMandator)
|
|
Next
|
|
|
|
' 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
|
|
|
|
' Initialize Grids
|
|
GridBuilder = New GridBuilder(New List(Of GridView) From {GridViewFiles, GridViewPositions})
|
|
GridBuilder.WithDefaults()
|
|
|
|
' Construct classes related to the xml data
|
|
DocumentLoader = New DocumentLoader(LogConfig, Winline)
|
|
Catch ex As Exception
|
|
Logger.Error(ex)
|
|
MsgBox(ex.Message, MsgBoxStyle.Critical, Text)
|
|
End Try
|
|
End Sub
|
|
|
|
Private Sub btnLoadDocuments_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnLoadDocuments.ItemClick
|
|
Try
|
|
If DocumentLoader.LoadFiles(ConfigManager.Config.InputDirectory) = True Then
|
|
|
|
RibbonGroupData.Enabled = True
|
|
RibbonGroupDocument.Enabled = True
|
|
RibbonGroupPositions.Enabled = True
|
|
|
|
GridControlFiles.DataSource = DocumentLoader.Files
|
|
txtFilesLoaded.Caption = $"{DocumentLoader.Files.Count} Dokumente geladen"
|
|
End If
|
|
Catch ex As Exception
|
|
Dim oMessage = ex.Message
|
|
|
|
If ex.InnerException IsNot Nothing Then
|
|
oMessage &= vbNewLine & vbNewLine & ex.InnerException.Message
|
|
End If
|
|
|
|
MsgBox(oMessage, MsgBoxStyle.Critical, Text)
|
|
End Try
|
|
End Sub
|
|
|
|
Private Sub GridViewFiles_FocusedRowChanged(sender As Object, e As DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs) Handles GridViewFiles.FocusedRowChanged
|
|
Dim oDocument As Document = GridViewFiles.GetRow(e.FocusedRowHandle)
|
|
|
|
If oDocument Is Nothing Then
|
|
Exit Sub
|
|
End If
|
|
|
|
RichEditXml.LoadDocument(oDocument.FullName, DocumentFormat.PlainText)
|
|
|
|
Try
|
|
Select Case oDocument.Type
|
|
Case DocumentType.Order
|
|
ShowDocument(oDocument, oDocument.Data, oDocument.DataOriginal)
|
|
|
|
End Select
|
|
|
|
Catch ex As Xml.XmlException
|
|
Dim oMessage As String = $"Fehler beim Laden des Dokuments {oDocument.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}"
|
|
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}"
|
|
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)
|
|
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)
|
|
|
|
' ====== Head Data ======
|
|
|
|
' Original, Unreplaced Data
|
|
txtCustomerGLN.Text = oHeadOriginal.Fakt_Kontonummer
|
|
txtDeliveryAddressGLN.Text = oHeadOriginal.Lief_Kontonummer
|
|
|
|
' Regular Data from EDI
|
|
txtRunningNumber.Text = oHead.Laufnummer
|
|
txtOrderIssuer.Text = oHead.Fakt_Ansprechpartner
|
|
txtOrderNumber.Text = oHead.AuftragsBestellnummer
|
|
txtDocumentKind.Text = oHead.Belegart
|
|
txtDocumentReference.Text = oHead.Auftragsreferenz
|
|
dateOrderDate.EditValue = oHead.Datum_AuftragBestellung
|
|
|
|
Dim oMandator = Winline.Mandators.
|
|
Where(Function(m) m.Id = pDocument.Mandator).
|
|
SingleOrDefault()
|
|
|
|
If oMandator Is Nothing Then
|
|
cmbMandator.ErrorText = "Dieses Feld muss ausgefüllt werden!"
|
|
cmbMandator.EditValue = Nothing
|
|
Else
|
|
cmbMandator.EditValue = oMandator
|
|
End If
|
|
|
|
If oHead.Fakt_Kontonummer = oHeadOriginal.Fakt_Kontonummer Then
|
|
cmbCustomer.ErrorText = "Dieses Feld muss ausgefüllt werden!"
|
|
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()
|
|
End If
|
|
|
|
If oHead.Lief_Kontonummer = oHeadOriginal.Lief_Kontonummer Then
|
|
cmbDeliveryAddress.ErrorText = "Dieses Feld muss ausgefüllt werden!"
|
|
cmbDeliveryAddress.EditValue = Nothing
|
|
Else
|
|
cmbDeliveryAddress.EditValue = Winline.Accounts.
|
|
Where(Function(oAccount) oAccount.Id = oHead.Lief_Kontonummer And oAccount.Mandator = cmbMandator.EditValue).
|
|
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()
|
|
|
|
|
|
LoadPositionViewAndColumns(GridViewPositions, DocumentType.Order)
|
|
LoadPositionData(pData, pDataOriginal)
|
|
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")
|
|
End Sub
|
|
|
|
Private Sub BarButtonItem2_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItem2.ItemClick
|
|
TryOpenDirectory(ConfigManager.Config.OutputDirectory, "Ausgangsverzeichnis")
|
|
End Sub
|
|
|
|
Private Sub BarButtonItem3_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItem3.ItemClick
|
|
Dim oUserConfigDirectory = New FileInfo(ConfigManager.UserConfigPath).Directory
|
|
TryOpenDirectory(oUserConfigDirectory.FullName, "Konfigurationsverzeichnis")
|
|
End Sub
|
|
|
|
Private Sub checkShowXml_CheckedChanged(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles checkShowXml.CheckedChanged
|
|
SplitContainerControl3.Collapsed = Not checkShowXml.Checked
|
|
End Sub
|
|
|
|
Private Sub BarButtonItem4_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItem4.ItemClick
|
|
Dim oDocument As Document = GetFocusedDocument()
|
|
If oDocument Is Nothing Then
|
|
Exit Sub
|
|
End If
|
|
|
|
WebService.TransferDocumentToWinLine(oDocument)
|
|
End Sub
|
|
|
|
Private Sub BarButtonItem8_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItem8.ItemClick
|
|
TryOpenDirectory(LogConfig.LogDirectory, "Logverzeichnis")
|
|
End Sub
|
|
|
|
Private Sub cmbAccount_Validating(sender As BaseEdit, e As System.ComponentModel.CancelEventArgs) Handles cmbCustomer.Validating, cmbDeliveryAddress.Validating
|
|
If sender.EditValue Is Nothing Then
|
|
sender.ErrorText = "Dieses Feld muss ausgefüllt werden!"
|
|
Else
|
|
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
|
|
Exit Sub
|
|
End If
|
|
|
|
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)
|
|
}
|
|
}
|
|
oDataSource.Fill()
|
|
oReport.DataSource = oDataSource
|
|
|
|
Dim oReportPrintTool As New ReportPrintTool(oReport)
|
|
oReportPrintTool.ShowPreview()
|
|
End Sub
|
|
|
|
Private Sub btnReloadDocument_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnReloadDocument.ItemClick
|
|
|
|
End Sub
|
|
End Class |