Projektdateien hinzufügen.
This commit is contained in:
184
EDIDocumentImport/frmMain.vb
Normal file
184
EDIDocumentImport/frmMain.vb
Normal file
@@ -0,0 +1,184 @@
|
||||
Imports System.IO
|
||||
Imports System.Globalization
|
||||
Imports DevExpress.XtraGrid.Views.Grid
|
||||
Imports DevExpress.XtraGrid.Columns
|
||||
Imports DevExpress.XtraRichEdit
|
||||
Imports DigitalData.Modules.Logging
|
||||
Imports DigitalData.Modules.Database
|
||||
Imports DigitalData.Modules.Config
|
||||
Imports DigitalData.Controls.SQLConfig
|
||||
Imports DigitalData.GUIs.Common
|
||||
Imports EDIDocumentImport.DocumentInfo
|
||||
Imports EDIDocumentImport.DocumentPositions
|
||||
|
||||
Public Class frmMain
|
||||
Public LogConfig As LogConfig
|
||||
Public Logger As Logger
|
||||
Public ConfigManager As ConfigManager(Of Config)
|
||||
Public DocumentLoader As DocumentLoader
|
||||
Public Database As MSSQLServer
|
||||
Public FileLoader As FileLoader
|
||||
Public GridBuilder As GridBuilder
|
||||
Public Winline As WinLineInfo
|
||||
|
||||
Private Sub frmMain_Load(sender As Object, e As EventArgs) Handles MyBase.Load
|
||||
Try
|
||||
LogConfig = New LogConfig(LogConfig.PathType.AppData, Nothing, Nothing, "Digital Data", "EDI Document Importer")
|
||||
ConfigManager = New ConfigManager(Of Config)(LogConfig, Application.UserAppDataPath)
|
||||
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
|
||||
Database = New MSSQLServer(LogConfig, ConfigManager.Config.ConnectionString)
|
||||
Winline = New WinLineInfo(LogConfig, Database)
|
||||
|
||||
' Initialize Grids
|
||||
GridBuilder = New GridBuilder(New List(Of GridView) From {GridViewFiles, GridViewPositions})
|
||||
GridBuilder.
|
||||
WithDefaults().
|
||||
WithReadOnlyOptions(GridViewFiles)
|
||||
|
||||
' Construct classes related to the xml data
|
||||
FileLoader = New FileLoader(LogConfig, ConfigManager.Config)
|
||||
DocumentLoader = New DocumentLoader(LogConfig)
|
||||
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 FileLoader.LoadFiles() = True Then
|
||||
GridControlFiles.DataSource = FileLoader.Files
|
||||
txtFilesLoaded.Caption = $"{FileLoader.Files.Count} Dokumente geladen"
|
||||
End If
|
||||
Catch ex As Exception
|
||||
MsgBox(ex.Message, 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 oFile As FileInfo = GridViewFiles.GetRow(e.FocusedRowHandle)
|
||||
|
||||
If oFile Is Nothing Then
|
||||
Exit Sub
|
||||
End If
|
||||
|
||||
RichEditXml.LoadDocument(oFile.FullName, DocumentFormat.PlainText)
|
||||
|
||||
Try
|
||||
Dim oResult As Tuple(Of Object, DocumentType) = FileLoader.LoadFile(oFile.FullName)
|
||||
|
||||
Select Case oResult.Item2
|
||||
Case DocumentType.Order
|
||||
ShowDocument(oResult.Item1)
|
||||
|
||||
End Select
|
||||
Catch ex As Xml.XmlException
|
||||
Dim oMessage As String = $"Fehler beim Verarbeiten des Dokuments {oFile.Name}:{vbNewLine}{ex.Message}"
|
||||
MsgBox(oMessage, MsgBoxStyle.Critical, Text)
|
||||
|
||||
Catch ex As Exception
|
||||
|
||||
MsgBox(ex.Message, MsgBoxStyle.Critical, Text)
|
||||
End Try
|
||||
End Sub
|
||||
|
||||
Private Sub ShowDocument(pDocument As Orders.MESOWebService)
|
||||
' ====== Head Data ======
|
||||
|
||||
Dim oHead As Orders.MESOWebServiceEXIMVRG_ordersT025 = pDocument.Items.
|
||||
Where(Function(i) TypeOf i Is Orders.MESOWebServiceEXIMVRG_ordersT025).
|
||||
FirstOrDefault()
|
||||
|
||||
txtBELEGKEY.Text = oHead.BELEGKEY
|
||||
txtRunningNumber.Text = oHead.Laufnummer
|
||||
txtMandator.Text = oHead.Fakt_Kontonummer
|
||||
txtOrderIssuer.Text = oHead.Fakt_Ansprechpartner
|
||||
txtOrderNumber.Text = oHead.AuftragsBestellnummer
|
||||
dateOrderDate.EditValue = oHead.Datum_AuftragBestellung
|
||||
|
||||
' ====== Position Data ======
|
||||
|
||||
Dim oPositions As List(Of Orders.MESOWebServiceEXIMVRG_ordersT026) = pDocument.Items.
|
||||
Where(Function(i) TypeOf i Is Orders.MESOWebServiceEXIMVRG_ordersT026).
|
||||
Select(Of Orders.MESOWebServiceEXIMVRG_ordersT026)(Function(i) i).
|
||||
ToList()
|
||||
|
||||
Dim oPositionList As New List(Of OrderPosition)
|
||||
For Each oPosition In oPositions
|
||||
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
|
||||
})
|
||||
Next
|
||||
|
||||
LoadViewAndColumns(GridViewPositions, DocumentType.Order)
|
||||
GridControlPositions.DataSource = oPositionList
|
||||
End Sub
|
||||
|
||||
|
||||
Public Sub LoadViewAndColumns(pView As GridView, pDocumentType As DocumentType)
|
||||
Dim oColumns As List(Of GridColumn)
|
||||
|
||||
Select Case pDocumentType
|
||||
Case DocumentType.Order
|
||||
oColumns = New List(Of GridColumn) From {
|
||||
ColumnRowNumber,
|
||||
ColumnArticleNumber,
|
||||
ColumnArticleNumberVendor,
|
||||
ColumnArticleDescription,
|
||||
ColumnEDIPrice,
|
||||
ColumnWinLinePrice,
|
||||
ColumnPrice
|
||||
}
|
||||
|
||||
Case Else
|
||||
oColumns = New List(Of GridColumn)
|
||||
End Select
|
||||
|
||||
pView.GridControl.DataSource = Nothing
|
||||
pView.GridControl.ForceInitialize()
|
||||
|
||||
pView.Columns.AddRange(oColumns.ToArray())
|
||||
pView.BestFitColumns()
|
||||
End Sub
|
||||
|
||||
|
||||
|
||||
Private Sub BarButtonItem1_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItem1.ItemClick
|
||||
Process.Start(ConfigManager.Config.InputDirectory)
|
||||
End Sub
|
||||
|
||||
Private Sub BarButtonItem2_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItem2.ItemClick
|
||||
Process.Start(ConfigManager.Config.OutputDirectory)
|
||||
End Sub
|
||||
|
||||
Private Sub BarButtonItem3_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItem3.ItemClick
|
||||
Dim oUserConfigDirectory = New FileInfo(ConfigManager.UserConfigPath).Directory
|
||||
Process.Start(oUserConfigDirectory.FullName)
|
||||
End Sub
|
||||
|
||||
Private Sub checkShowXml_CheckedChanged(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles checkShowXml.CheckedChanged
|
||||
SplitContainerControl3.Collapsed = Not checkShowXml.Checked
|
||||
End Sub
|
||||
End Class
|
||||
Reference in New Issue
Block a user