222 lines
8.0 KiB
VB.net
222 lines
8.0 KiB
VB.net
Imports System.ComponentModel
|
|
Imports System.IO
|
|
Imports System.Xml
|
|
Imports DevExpress.XtraGrid
|
|
Imports DevExpress.XtraGrid.Views.Grid
|
|
Imports DigitalData.Controls.SQLConfig
|
|
Imports DigitalData.Modules.Config
|
|
Imports DigitalData.Modules.Database
|
|
Imports DigitalData.Modules.Logging
|
|
Imports ImporterShared
|
|
Imports ImporterShared.Documents
|
|
Imports ImporterShared.Schemas
|
|
Imports ImporterShared.Winline
|
|
|
|
Public Class frmImportMain
|
|
Private LogConfig As LogConfig
|
|
Private Logger As Logger
|
|
Private ConfigManager As ConfigManager(Of ImporterShared.Config)
|
|
Private Database As MSSQLServer
|
|
Private Winline As Data
|
|
Private WebService As WebService
|
|
Private PositionData As PositionData
|
|
Private DocumentLoader As Documents.DocumentLoader
|
|
Private SchemaLoader As Schemas.SchemaLoader
|
|
Private GridLoader As GridLoader
|
|
|
|
Private Grids As List(Of GridControl)
|
|
|
|
Private CurrentSchema As String
|
|
|
|
Private Sub frmImportMain_Load(sender As Object, e As EventArgs) Handles MyBase.Load
|
|
txtVersion.Caption = String.Format(txtVersion.Caption, Application.ProductVersion)
|
|
|
|
LogConfig = New LogConfig(LogConfig.PathType.AppData, Nothing, Nothing, "Digital Data", "EDI Document Importer")
|
|
Logger = LogConfig.GetLogger()
|
|
Logger.Info("EDI Document Importer, Version [{0}]", Application.ProductVersion)
|
|
|
|
ConfigManager = New ConfigManager(Of ImporterShared.Config)(LogConfig,
|
|
Application.UserAppDataPath,
|
|
Application.CommonAppDataPath,
|
|
Application.StartupPath)
|
|
|
|
' 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)
|
|
PositionData = New PositionData(LogConfig, Winline)
|
|
|
|
' Load WinLine Data
|
|
Winline.Mandators.Clear()
|
|
Winline.LoadMandators()
|
|
Winline.LoadEconomicYears()
|
|
Winline.LoadDocumentKinds(Winline.Mandators)
|
|
For Each oMandator In Winline.Mandators
|
|
Winline.LoadAccounts(oMandator)
|
|
Next
|
|
|
|
DocumentLoader = New DocumentLoader(LogConfig, Winline)
|
|
SchemaLoader = New SchemaLoader(LogConfig)
|
|
GridLoader = New GridLoader(LogConfig)
|
|
|
|
SchemaLoader.LoadFiles(ConfigManager.Config.SchemaDirectory)
|
|
CurrentSchema = SchemaLoader.SchemaList.First().FullName
|
|
|
|
Dim oSchema = SchemaLoader.GetSchemaFromFile(CurrentSchema)
|
|
Grids = CreateGridsAndColumns(oSchema)
|
|
|
|
|
|
End Sub
|
|
|
|
|
|
Private Function CreateGridsAndColumns(pSchema As Schemas.Schema) As List(Of GridControl)
|
|
Dim oGrids As New List(Of GridControl)
|
|
Dim oTableCounter = 0
|
|
|
|
For Each oTable In pSchema.Tables
|
|
If oTableCounter = 0 Then
|
|
Dim oGrid = GridLoader.GetGridFromElement(oTable)
|
|
AddHandler oGrid.DoubleClick, AddressOf Grid_DoubleClick
|
|
SplitContainerControl3.Panel1.Controls.Add(oGrid)
|
|
oGrids.Add(oGrid)
|
|
End If
|
|
|
|
If oTableCounter = 1 Then
|
|
Dim oGrid = GridLoader.GetGridFromElement(oTable)
|
|
AddHandler oGrid.DoubleClick, AddressOf Grid_DoubleClick
|
|
SplitContainerControl3.Panel2.Controls.Add(oGrid)
|
|
oGrids.Add(oGrid)
|
|
End If
|
|
|
|
If oTableCounter = 2 Then
|
|
Dim oGrid = GridLoader.GetGridFromElement(oTable)
|
|
AddHandler oGrid.DoubleClick, AddressOf Grid_DoubleClick
|
|
SplitContainerControl4.Panel1.Controls.Add(oGrid)
|
|
oGrids.Add(oGrid)
|
|
End If
|
|
|
|
If oTableCounter = 3 Then
|
|
Dim oGrid = GridLoader.GetGridFromElement(oTable)
|
|
AddHandler oGrid.DoubleClick, AddressOf Grid_DoubleClick
|
|
SplitContainerControl4.Panel2.Controls.Add(oGrid)
|
|
oGrids.Add(oGrid)
|
|
End If
|
|
|
|
If oTableCounter > 3 Then
|
|
MsgBox("Only 4 Tables are allowed currently!", MsgBoxStyle.Exclamation, Text)
|
|
End If
|
|
|
|
oTableCounter += 1
|
|
Next
|
|
|
|
If oTableCounter < 3 Then
|
|
SplitContainerControl2.PanelVisibility = DevExpress.XtraEditors.SplitPanelVisibility.Panel1
|
|
End If
|
|
|
|
Return oGrids
|
|
End Function
|
|
|
|
Private Sub Grid_DoubleClick(sender As Object, e As EventArgs)
|
|
Dim oGrid As GridControl = DirectCast(sender, GridControl)
|
|
Dim oView As GridView = DirectCast(oGrid.FocusedView, GridView)
|
|
Dim oRow As DataRow = oView.GetDataRow(oView.FocusedRowHandle)
|
|
Dim oColumns = oView.Columns.Select(Function(c) c.FieldName).ToList()
|
|
|
|
Dim oForm As New frmRowEditor(oRow, oColumns)
|
|
oForm.Showdialog()
|
|
End Sub
|
|
|
|
Private Sub BarButtonItem1_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItem1.ItemClick
|
|
If DocumentLoader.LoadFiles(ConfigManager.Config.InputDirectory) Then
|
|
GridControlFiles.DataSource = DocumentLoader.Files
|
|
End If
|
|
End Sub
|
|
|
|
Private Sub GridViewFiles_FocusedRowChanged(sender As Object, e As Views.Base.FocusedRowChangedEventArgs) Handles GridViewFiles.FocusedRowChanged
|
|
|
|
Dim oDocument As Document = GridViewFiles.GetRow(e.FocusedRowHandle)
|
|
Dim oDatasources As New Dictionary(Of String, DataTable)
|
|
|
|
For Each oRow In oDocument.Rows
|
|
Dim oGrid As GridControl = Grids.
|
|
Where(Function(g) g.Name = oRow.Name).
|
|
SingleOrDefault()
|
|
|
|
If Not oDatasources.ContainsKey(oRow.Name) Then
|
|
Dim oTable As New DataTable()
|
|
|
|
For Each ofield In oRow.Fields
|
|
oTable.Columns.Add(New DataColumn(ofield.Key))
|
|
Next
|
|
oDatasources.Add(oRow.Name, oTable)
|
|
|
|
oGrid.DataSource = oTable
|
|
End If
|
|
|
|
Dim oDataTable = oDatasources.Item(oRow.Name)
|
|
Dim oDataRow = oDataTable.NewRow()
|
|
|
|
For Each oField In oRow.Fields
|
|
oDataRow.Item(oField.Key) = oField.Value
|
|
Next
|
|
|
|
oDataTable.Rows.Add(oDataRow)
|
|
oDataTable.AcceptChanges()
|
|
Next
|
|
End Sub
|
|
|
|
Private Sub BarButtonItem2_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItem2.ItemClick
|
|
Dim oDocument As Document = GridViewFiles.GetRow(GridViewFiles.FocusedRowHandle)
|
|
|
|
Using oStream As New MemoryStream()
|
|
Dim w = XmlWriter.Create(oStream)
|
|
|
|
w.WriteStartDocument()
|
|
|
|
w.WriteStartElement("MESOWebService")
|
|
w.WriteAttributeString("Template", oDocument.TemplateName)
|
|
w.WriteAttributeString("TemplateType", oDocument.TemplateType)
|
|
w.WriteAttributeString("option", oDocument.Option)
|
|
w.WriteAttributeString("printVoucher", oDocument.PrintVoucher)
|
|
|
|
For Each oRow In oDocument.Rows
|
|
w.WriteStartElement(oRow.Name)
|
|
|
|
For Each oField As KeyValuePair(Of String, String) In oRow.Fields
|
|
w.WriteStartElement(oField.Key)
|
|
w.WriteValue(oField.Value)
|
|
w.WriteEndElement() ' Field
|
|
Next
|
|
|
|
w.WriteEndElement() ' Row
|
|
Next
|
|
|
|
|
|
w.WriteEndElement() ' MESOWebService
|
|
|
|
|
|
w.WriteEndDocument() ' Document
|
|
|
|
w.Close()
|
|
|
|
File.WriteAllBytes(ConfigManager.Config.OutputDirectory, oStream.ToArray)
|
|
End Using
|
|
|
|
|
|
|
|
End Sub
|
|
End Class |