diff --git a/MultiTool.Form/MyApplication.vb b/MultiTool.Form/MyApplication.vb index fa316aa..10ddee5 100644 --- a/MultiTool.Form/MyApplication.vb +++ b/MultiTool.Form/MyApplication.vb @@ -6,5 +6,6 @@ Namespace My Friend Property TemplateConfiguration As TemplateConfig Friend Property MappingConfiguration As MappingConfig Friend Property MandatorConfiguration As MandatorConfig + Friend Property GeneralConfiguration As GeneralConfig End Module End Namespace diff --git a/MultiTool.Form/frmConfig.vb b/MultiTool.Form/frmConfig.vb index 2f7aa17..2590d25 100644 --- a/MultiTool.Form/frmConfig.vb +++ b/MultiTool.Form/frmConfig.vb @@ -30,29 +30,19 @@ Public Class frmConfig TBEDI_XML_ITEMSTableAdapter.Connection.ConnectionString = oBuilder.ToString() TBEDI_XML_ITEMSTableAdapter.Fill(Me.DS_DD_ECM.TBEDI_XML_ITEMS) - txtInputDir.EditValue = Config.InputDirectory - txtOutputDir.EditValue = Config.OutputDirectory - txtSchemaDir.EditValue = Config.SchemaDirectory + txtInputDir.EditValue = My.GeneralConfiguration.InputDirectory + txtOutputDir.EditValue = My.GeneralConfiguration.OutputDirectory + txtSchemaDir.EditValue = My.GeneralConfiguration.TemplateDirectory - txtBaseURL.EditValue = Config.Webservice.BaseUrl - txtUsername.EditValue = Config.Webservice.Username - txtPassword.EditValue = Config.Webservice.Password - txtImportBasePath.EditValue = Config.Webservice.ImportBasePath - txtImportRelativePath.EditValue = Config.Webservice.ImportRelativePath + txtBaseURL.EditValue = My.GeneralConfiguration.Webservice.BaseUrl + txtUsername.EditValue = My.GeneralConfiguration.Webservice.Username + txtPassword.EditValue = My.GeneralConfiguration.Webservice.Password + txtImportBasePath.EditValue = My.GeneralConfiguration.Webservice.ImportBasePath + txtImportRelativePath.EditValue = My.GeneralConfiguration.Webservice.ImportRelativePath End Sub Private Sub BarButtonItem1_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItem1.ItemClick - Config.Webservice.BaseUrl = txtBaseURL.EditValue - Config.Webservice.Username = txtUsername.EditValue - Config.Webservice.Password = txtPassword.EditValue - Config.Webservice.ImportBasePath = txtImportBasePath.EditValue - Config.Webservice.ImportRelativePath = txtImportRelativePath.EditValue - Config.InputDirectory = txtInputDir.EditValue - Config.OutputDirectory = txtOutputDir.EditValue - Config.SchemaDirectory = txtSchemaDir.EditValue - - ConfigManager.Save() Try TBEDIXMLITEMSBindingSource.EndEdit() diff --git a/MultiTool.Form/frmImportMain.vb b/MultiTool.Form/frmImportMain.vb index 9bae092..a28a792 100644 --- a/MultiTool.Form/frmImportMain.vb +++ b/MultiTool.Form/frmImportMain.vb @@ -76,8 +76,8 @@ Public Class frmImportMain GridViewFiles.OptionsView.ShowAutoFilterRow = False FileEx = New DigitalData.Modules.Filesystem.File(LogConfig) - Winline = New WinlineData(LogConfig, Database, ConfigManager.Config, My.MappingConfiguration, My.MandatorConfiguration) - WebService = New WebServiceData(LogConfig, ConfigManager.Config, Application.UserAppDataPath) + Winline = New WinlineData(LogConfig, Database, My.GeneralConfiguration, My.MappingConfiguration, My.MandatorConfiguration) + WebService = New WebServiceData(LogConfig, My.GeneralConfiguration.Webservice, Application.UserAppDataPath) AddHandler WebService.WebServiceProgress, AddressOf WebService_Progress Catch ex As Exception @@ -239,7 +239,7 @@ Public Class frmImportMain End Sub If DocumentLoader.LoadFiles( - ConfigManager.Config.InputDirectory, + My.GeneralConfiguration.InputDirectory, CurrentTemplate, lookupMandator.EditValue ) Then @@ -418,7 +418,7 @@ Public Class frmImportMain End Sub Private Sub btnOpenInputDirectory_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnOpenInputDirectory.ItemClick - TryOpenDirectory(ConfigManager.Config.InputDirectory, My.Resources.frmImportMainExtra.Eingangsverzeichnis) + TryOpenDirectory(My.GeneralConfiguration.InputDirectory, My.Resources.frmImportMainExtra.Eingangsverzeichnis) End Sub Private Sub btnOpenOutputDirectory_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnOpenOutputDirectory.ItemClick @@ -427,7 +427,7 @@ Public Class frmImportMain End Sub Private Sub btnOpenSchemaDirectory_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnOpenSchemaDirectory.ItemClick - TryOpenDirectory(ConfigManager.Config.SchemaDirectory, My.Resources.frmImportMainExtra.Vorlagenverzeichnis) + TryOpenDirectory(My.GeneralConfiguration.TemplateDirectory, My.Resources.frmImportMainExtra.Vorlagenverzeichnis) End Sub Private Sub TryOpenDirectory(pPath As String, pDisplayName As String) diff --git a/MultiTool.Form/frmMain.vb b/MultiTool.Form/frmMain.vb index cd5c5cd..114d360 100644 --- a/MultiTool.Form/frmMain.vb +++ b/MultiTool.Form/frmMain.vb @@ -53,6 +53,7 @@ Public Class frmMain ' Initialize Schemas TemplateLoader = New TemplateLoader(LogConfig, Database) + Await TemplateLoader.LoadGeneralConfiguration() Await TemplateLoader.LoadTemplates() Await TemplateLoader.LoadTemplateConfiguration() Await TemplateLoader.LoadMappingConfiguration() @@ -62,6 +63,7 @@ Public Class frmMain My.MappingConfiguration = TemplateLoader.MappingConfiguration My.TemplateConfiguration = TemplateLoader.TemplateConfiguration My.MandatorConfiguration = TemplateLoader.MandatorConfiguration + My.GeneralConfiguration = TemplateLoader.GeneralConfiguration Dim oBindingSource = New BindingList(Of Template) For Each oTemplate As Template In TemplateLoader.TemplateList @@ -84,7 +86,7 @@ Public Class frmMain Exit Sub End If - oTemplate = TemplateLoader.UpdateTemplateFromFile(oTemplate, ConfigManager.Config.SchemaDirectory) + oTemplate = TemplateLoader.UpdateTemplateFromFile(oTemplate, My.GeneralConfiguration.TemplateDirectory) oTemplate = TemplateLoader.UpdateTemplateFromDatabase(oTemplate, TemplateLoader.TemplateConfiguration) If oTemplate.IsImport Then diff --git a/MultiTool.Shared/Config.vb b/MultiTool.Shared/Config.vb index b6bf8e9..99c7f16 100644 --- a/MultiTool.Shared/Config.vb +++ b/MultiTool.Shared/Config.vb @@ -3,36 +3,4 @@ Public Class Config Public Property ConnectionString As String = "" - - Public Property Mandators As New List(Of MandatorConfig) - - Public Property InputDirectory As String = "" - Public Property OutputDirectory As String = "" - Public Property SchemaDirectory As String = "" - - Public Property Webservice As New WebServiceConfig() - Public Property DefaultYearOverride As Integer = 0 - - Public Class WebServiceConfig - Public Property BaseUrl As String = "http://127.0.0.1/EWL" - Public Property Username As String = "Username" - Public Property Password As String = "Password" - Public Property ImportBasePath As String = "" - Public Property ImportRelativePath As String = "" - End Class - - Public Class MandatorConfig - Public Property Order As Integer - Public Property Name As String - Public Property ArticleRegex As String - End Class - - - Public Function GetYear() As Integer - If DefaultYearOverride > 0 Then - Return DefaultYearOverride - End If - - Return Now.Year - End Function End Class diff --git a/MultiTool.Shared/Documents/DocumentLoader.vb b/MultiTool.Shared/Documents/DocumentLoader.vb index 98e50bf..ec2affb 100644 --- a/MultiTool.Shared/Documents/DocumentLoader.vb +++ b/MultiTool.Shared/Documents/DocumentLoader.vb @@ -306,48 +306,25 @@ Namespace Documents End If If oFunctionName = "EAN" Then - Dim oNumberItem As DocumentRow.FieldValue = oRow.Fields.GetOrDefault(oField.Key) - Dim oArticleNumber = Winline.TryGetArticleNumber(oNumberItem.Original, pMandator) - If oArticleNumber IsNot Nothing Then - oNumberItem.External = oArticleNumber - oNumberItem.Final = oArticleNumber - Else - oNumberItem.Error = DocumentRow.FieldError.ArticleNotFound - End If + SetArticleByEAN(oRow, pMandator, oField.Key) End If Next Next - 'Dim oHead As DocumentRow = pDocument.Rows. - ' Where(Function(r) r.Name.ToUpper.EndsWith("T025")). - ' SetValue(Sub(r As DocumentRow) SetAccountByGLN(r, pMandator, "Fakt_Kontonummer", "Fakt_Name")). - ' SetValue(Sub(r As DocumentRow) SetAccountByGLN(r, pMandator, "Lief_Kontonummer", "Lief_Name")). - ' FirstOrDefault() - - 'Dim oPositions As List(Of DocumentRow) = pDocument.Rows. - ' Where(Function(r) r.Name.ToUpper.EndsWith("T026")). - ' SetValue(Sub(oRow As DocumentRow) - ' Dim oNumberItem As DocumentRow.FieldValue = oRow.Fields.GetOrDefault("Artikelnummer") - ' If oNumberItem Is Nothing Then - ' Exit Sub - ' End If - - ' Dim oArticleNumber = Winline.TryGetArticleNumber(oNumberItem.Original, pMandator) - ' If oArticleNumber IsNot Nothing Then - ' oNumberItem.External = oArticleNumber - ' oNumberItem.Final = oArticleNumber - ' Else - ' oNumberItem.Error = DocumentRow.FieldError.ArticleNotFound - ' End If - ' End Sub). - ' ToList() - - 'Dim oList As New List(Of DocumentRow) From {oHead} - 'pDocument.Rows = oList.Concat(oPositions).ToList() - Return pDocument End Function + Private Sub SetArticleByEAN(pRow As DocumentRow, pMandator As Mandator, pArticleField As String) + Dim oNumberItem As DocumentRow.FieldValue = pRow.Fields.GetOrDefault(pArticleField) + Dim oArticleNumber = Winline.TryGetArticleNumber(oNumberItem.Original, pMandator) + If oArticleNumber IsNot Nothing Then + oNumberItem.External = oArticleNumber + oNumberItem.Final = oArticleNumber + Else + oNumberItem.Error = DocumentRow.FieldError.ArticleNotFound + End If + End Sub + Private Sub SetAccountByGLN(oRow As DocumentRow, pMandator As Mandator, pNumberField As String, pNameField As String) ' Try to read the Account number (which is a GLN really) and account Name Dim oNumberItem As DocumentRow.FieldValue = oRow.Fields.GetOrDefault(pNumberField) diff --git a/MultiTool.Shared/MultiTool.Shared.vbproj b/MultiTool.Shared/MultiTool.Shared.vbproj index cf4345a..5c37bd3 100644 --- a/MultiTool.Shared/MultiTool.Shared.vbproj +++ b/MultiTool.Shared/MultiTool.Shared.vbproj @@ -124,6 +124,7 @@ Settings.settings True + diff --git a/MultiTool.Shared/Templates/GeneralConfig.vb b/MultiTool.Shared/Templates/GeneralConfig.vb new file mode 100644 index 0000000..6147c78 --- /dev/null +++ b/MultiTool.Shared/Templates/GeneralConfig.vb @@ -0,0 +1,27 @@ +Namespace Templates + Public Class GeneralConfig + Public Property InputDirectory As String = "" + Public Property OutputDirectory As String = "" + Public Property TemplateDirectory As String = "" + + Public Property Webservice As New WebServiceConfig() + Public Property DefaultYearOverride As Integer = 0 + + Public Class WebServiceConfig + Public Property BaseUrl As String = "http://127.0.0.1/EWL" + Public Property Username As String = "Username" + Public Property Password As String = "Password" + Public Property ImportBasePath As String = "" + Public Property ImportRelativePath As String = "" + End Class + + + Public Function GetYear() As Integer + If DefaultYearOverride > 0 Then + Return DefaultYearOverride + End If + + Return Now.Year + End Function + End Class +End Namespace diff --git a/MultiTool.Shared/Templates/TemplateLoader.vb b/MultiTool.Shared/Templates/TemplateLoader.vb index ef9c737..0d1b561 100644 --- a/MultiTool.Shared/Templates/TemplateLoader.vb +++ b/MultiTool.Shared/Templates/TemplateLoader.vb @@ -12,13 +12,15 @@ Namespace Templates Public Property TemplateConfiguration As New TemplateConfig Public Property MappingConfiguration As New MappingConfig Public Property MandatorConfiguration As New MandatorConfig + Public Property GeneralConfiguration As New GeneralConfig Private ReadOnly Database As MSSQLServer - Private Const VWEDI_XML_ITEMS = "VWEDI_XML_ITEMS" - Private Const VWEDI_XML_MAPPING = "VWEDI_XML_MAPPING" - Private Const TBEDI_XML_MANDATORS = "TBEDI_XML_MANDATORS" - Private Const TBEDI_XML_TEMPLATES = "TBEDI_XML_TEMPLATES" + Private Const SQL_VWEDI_XML_ITEMS = "SELECT * FROM [DD_ECM].[dbo].[VWEDI_XML_ITEMS]" + Private Const SQL_VWEDI_XML_MAPPING = "SELECT * FROM [DD_ECM].[dbo].[VWEDI_XML_MAPPING]" + Private Const SQL_TBEDI_XML_MANDATORS = "SELECT * FROM [DD_ECM].[dbo].[TBEDI_XML_MANDATORS] ORDER BY ORDER_KEY" + Private Const SQL_TBEDI_XML_CONFIG = "SELECT * FROM [DD_ECM].[dbo].[TBEDI_XML_CONFIG]" + Private Const SQL_TBEDI_XML_TEMPLATES = "SELECT * FROM [DD_ECM].[dbo].[TBEDI_XML_TEMPLATES]" Public Sub New(pLogConfig As LogConfig, pMSSQL As MSSQLServer) MyBase.New(pLogConfig, pLogConfig.GetLogger) @@ -27,8 +29,7 @@ Namespace Templates Public Async Function LoadTemplates() As Task(Of Boolean) Try - Dim oSql = $"SELECT * FROM [DD_ECM].[dbo].[{TBEDI_XML_TEMPLATES}]" - Dim oTable As DataTable = Await Database.GetDatatableAsync(oSql) + Dim oTable As DataTable = Await Database.GetDatatableAsync(SQL_TBEDI_XML_TEMPLATES) Dim oTemplates As New List(Of Template) For Each oRow As DataRow In oTable.Rows @@ -52,10 +53,58 @@ Namespace Templates End Try End Function + Public Async Function LoadGeneralConfiguration() As Task(Of Boolean) + Try + Dim oTable As DataTable = Await Database.GetDatatableAsync(SQL_TBEDI_XML_CONFIG) + Dim oGeneralConfig As New GeneralConfig + + For Each oRow As DataRow In oTable.Rows + Dim oValue As String = oRow.ItemEx("VALUE", String.Empty) + + Select Case oRow.Item("KEY") + Case "YEAR_OVERRIDE" + oGeneralConfig.DefaultYearOverride = oRow.ItemEx("VALUE", 0) + + Case "WEBSERVICE_BASEURL" + oGeneralConfig.Webservice.BaseUrl = oValue + + Case "WEBSERVICE_USERNAME" + oGeneralConfig.Webservice.Username = oValue + + Case "WEBSERIVCE_PASSWORD" + oGeneralConfig.Webservice.Password = oValue + + Case "WEBSERVICE_IMPORT_BASE_PATH" + oGeneralConfig.Webservice.ImportBasePath = oValue + + Case "WEBSERVICE_IMPORT_RELATIVE_PATH" + oGeneralConfig.Webservice.ImportRelativePath = oValue + + Case "INPUT_DIRECTORY" + oGeneralConfig.InputDirectory = oValue + + Case "OUTPUT_DIRECTORY" + oGeneralConfig.OutputDirectory = oValue + + Case "TEMPLATE_DIRECTORY" + oGeneralConfig.TemplateDirectory = oValue + + End Select + Next + + GeneralConfiguration = oGeneralConfig + + Return True + Catch ex As Exception + Logger.Error(ex) + Return False + + End Try + End Function + Public Async Function LoadMappingConfiguration() As Task(Of Boolean) Try - Dim oSql = $"SELECT * FROM [DD_ECM].[dbo].[{VWEDI_XML_MAPPING}]" - Dim oTable As DataTable = Await Database.GetDatatableAsync(oSql) + Dim oTable As DataTable = Await Database.GetDatatableAsync(SQL_VWEDI_XML_MAPPING) Dim oMappingConfig As New MappingConfig For Each oRow As DataRow In oTable.Rows @@ -84,8 +133,7 @@ Namespace Templates Public Async Function LoadMandatorConfiguration() As Task(Of Boolean) Try - Dim oSql = $"SELECT * FROM [DD_ECM].[dbo].[{TBEDI_XML_MANDATORS}] ORDER BY ORDER_KEY" - Dim oTable As DataTable = Await Database.GetDatatableAsync(oSql) + Dim oTable As DataTable = Await Database.GetDatatableAsync(SQL_TBEDI_XML_MANDATORS) Dim oMandatorConfig As New MandatorConfig For Each oRow As DataRow In oTable.Rows @@ -109,8 +157,7 @@ Namespace Templates Public Async Function LoadTemplateConfiguration() As Task(Of Boolean) Try - Dim oSql = $"SELECT * FROM [DD_ECM].[dbo].[{VWEDI_XML_ITEMS}]" - Dim oTable As DataTable = Await Database.GetDatatableAsync(oSql) + Dim oTable As DataTable = Await Database.GetDatatableAsync(SQL_VWEDI_XML_ITEMS) Dim oItems As New List(Of TemplateConfigItem) For Each oRow As DataRow In oTable.Rows diff --git a/MultiTool.Shared/Winline/WebServiceData.vb b/MultiTool.Shared/Winline/WebServiceData.vb index a82f2d2..7a5e760 100644 --- a/MultiTool.Shared/Winline/WebServiceData.vb +++ b/MultiTool.Shared/Winline/WebServiceData.vb @@ -3,28 +3,29 @@ Imports System.Text Imports System.Net.Http Imports DigitalData.Modules.Logging Imports MultiTool.Shared.Documents +Imports MultiTool.Shared.Templates.GeneralConfig Imports MultiTool.Shared.Winline.Entities Namespace Winline Public Class WebServiceData Inherits BaseClass - Private ReadOnly Config As Config + Private ReadOnly Config As WebServiceConfig Private ReadOnly Serializer As Serializer Private ReadOnly AppDataPath As String Public Event WebServiceProgress As EventHandler(Of String) - Public Sub New(pLogConfig As LogConfig, pConfig As Config, pAppDataPath As String) + Public Sub New(pLogConfig As LogConfig, pWebserviceConfig As WebServiceConfig, pAppDataPath As String) MyBase.New(pLogConfig, pLogConfig.GetLogger()) Serializer = New Serializer(pLogConfig) - Config = pConfig + Config = pWebserviceConfig AppDataPath = pAppDataPath End Sub Public Async Function TransferDocumentToWinline(pDocument As Document, pMandator As Mandator, Optional pIsTest As Boolean = False) As Task(Of Boolean) Dim oBytes As Byte() = GetBytesFromDocument(pDocument) - Dim oWS As Config.WebServiceConfig = Config.Webservice + Dim oWS = Config ' --- Get and create path for request/response files @@ -41,10 +42,10 @@ Namespace Winline Dim oFileName = GetXmlFilenameWithSuffix(oBaseFileName, "Request", "xml") ' Relative Path for Webservice Call - Dim oImportRelativeFilePath = IO.Path.Combine(GetDateSubDirectoryPath(Config.Webservice.ImportRelativePath), oFileName) + Dim oImportRelativeFilePath = IO.Path.Combine(GetDateSubDirectoryPath(oWS.ImportRelativePath), oFileName) ' Absolute Path to copy Request file - Dim oImportAbsolutePath = IO.Path.Combine(Config.Webservice.ImportBasePath, Config.Webservice.ImportRelativePath) + Dim oImportAbsolutePath = IO.Path.Combine(oWS.ImportBasePath, oWS.ImportRelativePath) Dim oImportAbsoluteFilePath = IO.Path.Combine(GetDateSubDirectoryPath(oImportAbsolutePath), oFileName) ' --- Serialize Data into XML string diff --git a/MultiTool.Shared/Winline/WinlineData.vb b/MultiTool.Shared/Winline/WinlineData.vb index 7338164..7b94c28 100644 --- a/MultiTool.Shared/Winline/WinlineData.vb +++ b/MultiTool.Shared/Winline/WinlineData.vb @@ -9,19 +9,19 @@ Namespace Winline Public Class WinlineData Inherits BaseClass - Private ReadOnly Database As MSSQLServer - Private ReadOnly Config As Config - Private ReadOnly MandatorConfig As MandatorConfig - Private ReadOnly MappingConfig As MappingConfig + Private ReadOnly Property Database As MSSQLServer + Private ReadOnly Property Config As GeneralConfig + Private ReadOnly Property MandatorConfig As MandatorConfig + Private ReadOnly Property MappingConfig As MappingConfig - Public Articles As New List(Of Article) - Public Accounts As New List(Of Account) - Public Mandators As New List(Of Mandator) - Public DocumentKinds As New List(Of DocumentKind) + Public Property Articles As New List(Of Article) + Public Property Accounts As New List(Of Account) + Public Property Mandators As New List(Of Mandator) + Public Property DocumentKinds As New List(Of DocumentKind) Public Years As List(Of Integer) - Public Sub New(pLogConfig As LogConfig, pDatabase As MSSQLServer, pConfig As Config, pMappingConfig As MappingConfig, pMandatorConfig As MandatorConfig) + Public Sub New(pLogConfig As LogConfig, pDatabase As MSSQLServer, pConfig As GeneralConfig, pMappingConfig As MappingConfig, pMandatorConfig As MandatorConfig) MyBase.New(pLogConfig, pLogConfig.GetLogger()) Database = pDatabase Config = pConfig