From 1bef72d65c6c888de27f4f305c213d900383e4c2 Mon Sep 17 00:00:00 2001 From: Jonathan Jenne Date: Tue, 19 Apr 2022 15:33:44 +0200 Subject: [PATCH] Show Errors, Make grids usable when no mandator is selected, move completed files also when reloading --- MultiTool.Common/Constants.vb | 4 + MultiTool.Common/Documents/Document.vb | 24 + MultiTool.Common/Documents/DocumentCleaner.vb | 18 + MultiTool.Common/Documents/DocumentLoader.vb | 23 +- MultiTool.Common/Documents/DocumentRow.vb | 12 +- MultiTool.Form/MultiTool.Form.vbproj | 1 + .../My Project/Resources.Designer.vb | 10 + MultiTool.Form/My Project/Resources.resx | 27 +- MultiTool.Form/Resources/highimportance.svg | 19 + MultiTool.Form/frmImportMain.Designer.vb | 35 +- MultiTool.Form/frmImportMain.resx | 22 +- MultiTool.Form/frmImportMain.vb | 542 ++++++++++-------- 12 files changed, 448 insertions(+), 289 deletions(-) create mode 100644 MultiTool.Form/Resources/highimportance.svg diff --git a/MultiTool.Common/Constants.vb b/MultiTool.Common/Constants.vb index 44065a8..322950c 100644 --- a/MultiTool.Common/Constants.vb +++ b/MultiTool.Common/Constants.vb @@ -63,6 +63,10 @@ ArticleNotFound End Enum + Public Enum DocumentError + MandatorNotFound + End Enum + Public Enum XmlFunction None = 0 GLN = 1 diff --git a/MultiTool.Common/Documents/Document.vb b/MultiTool.Common/Documents/Document.vb index be40524..f525463 100644 --- a/MultiTool.Common/Documents/Document.vb +++ b/MultiTool.Common/Documents/Document.vb @@ -1,4 +1,5 @@ Imports System.IO +Imports MultiTool.Common.Constants Imports MultiTool.Common.Templates Imports MultiTool.Common.Winline.Entities @@ -27,6 +28,18 @@ Namespace Documents End Get End Property + Public ReadOnly Property Errors As List(Of String) + Get + Dim oRowErrors = Rows.SelectMany(Function(row) row.Errors).ToList() + Dim oDocumentErrors As List(Of String) = GetDocumentErrors(). + Select(Function(err) err.ToString()). + ToList() + Return oDocumentErrors. + Concat(oRowErrors). + ToList() + End Get + End Property + Public ReadOnly Property MandatorId As String Get Return Mandator?.Id @@ -69,6 +82,17 @@ Namespace Documents Public Overrides Function Equals(obj As Object) As Boolean Return FullName = DirectCast(obj, Document).FullName End Function + + Private Function GetDocumentErrors() As List(Of DocumentError) + Dim oErrors As New List(Of DocumentError) + + If Mandator Is Nothing Then + oErrors.Add(DocumentError.MandatorNotFound) + End If + + Return oErrors + End Function + End Class End Namespace \ No newline at end of file diff --git a/MultiTool.Common/Documents/DocumentCleaner.vb b/MultiTool.Common/Documents/DocumentCleaner.vb index cba43b0..caf84b7 100644 --- a/MultiTool.Common/Documents/DocumentCleaner.vb +++ b/MultiTool.Common/Documents/DocumentCleaner.vb @@ -22,11 +22,23 @@ Namespace Documents Where(Function(doc) doc.Imported = True). ToList() + If oImportedDocuments.Count = 0 Then + Logger.Debug("No exported files found. Skipping.") + Return True + End If + + Logger.Debug("Cleaning [{0}] exported files, moving to [{1}]", oImportedDocuments.Count, oOutputDirectory) + + Dim oRemovedDocuments As New List(Of Document) + For Each oDocument As Document In oImportedDocuments Try Dim oFileinfo = New FileInfo(oDocument.FullName) Dim oDestination = Path.Combine(oOutputDirectory, oFileinfo.Name) File.Move(oFileinfo.FullName, oDestination) + oRemovedDocuments.Add(oDocument) + + Logger.Debug("File [{0}] successfully moved.", oFileinfo.Name) Catch ex As Exception Logger.Warn("File [{0}] could not be moved to output directory!", oDocument.FullName) Logger.Error(ex) @@ -34,6 +46,12 @@ Namespace Documents End Try Next + Logger.Debug("Moved [{0}] files successfully.", oRemovedDocuments.Count) + + pDocuments = pDocuments. + Except(oRemovedDocuments). + ToList() + Return oResult End Function End Class diff --git a/MultiTool.Common/Documents/DocumentLoader.vb b/MultiTool.Common/Documents/DocumentLoader.vb index f1fb948..b3e50f6 100644 --- a/MultiTool.Common/Documents/DocumentLoader.vb +++ b/MultiTool.Common/Documents/DocumentLoader.vb @@ -314,6 +314,10 @@ Namespace Documents Dim oFunctionName = oColumn.Config.FunctionName Dim oFunctionParams = oColumn.Config.FunctionParams + + Logger.Debug("Running Function: [{0}]", oFunctionName) + Logger.Debug("With Parameters: [{0}]", oFunctionParams) + Dim oParamsDict = ParseFunctionParamsAsDict(oFunctionParams) If oFunctionName = Constants.FUNCTION_PRICE Then @@ -468,13 +472,26 @@ Namespace Documents Dim oPriceItem As DocumentRow.FieldValue = pRow.Fields.GetOrDefault(pPriceField) ' These fields are fetched from the current row - Dim oArticleNumberField As String = oFieldMap.GetOrDefault("Article", Nothing) + Const PARAMETER_ARTICLE = "Article" + Dim oArticleNumberField As String = oFieldMap.GetOrDefault(PARAMETER_ARTICLE, Nothing) + If oArticleNumberField Is Nothing Then + Logger.Warn("Parameter '{0}' not found for Function PRICE", PARAMETER_ARTICLE) + End If + + If pRow.Fields.ContainsKey(oArticleNumberField) = False Then + Logger.Warn("Value '{0}' for Parameter '{1}' not found for Function PRICE", oArticleNumberField, PARAMETER_ARTICLE) + End If Dim oArticleNumber As String = pRow.Fields.Item(oArticleNumberField).Final - Dim oQuantityField As String = oFieldMap.GetOrDefault("Quantity", Nothing) + Const PARAMETER_QUANTITY = "Quantity" + Dim oQuantityField As String = oFieldMap.GetOrDefault(PARAMETER_QUANTITY, Nothing) + If oQuantityField Is Nothing Then + Logger.Warn("Parameter '{0}' not found for Function PRICE", PARAMETER_QUANTITY) + End If + Dim oQuantity As Integer = 1 If Integer.TryParse(pRow.Fields.Item(oQuantityField).Final, oQuantity) = False Then - Logger.Warn("Value for parameter Quantity could not be parsed. Setting to 1.") + Logger.Warn("Value for parameter '{0}' could not be parsed. Setting to 1.", PARAMETER_QUANTITY) End If ' These fields a fetched from the head row, ie. the first row diff --git a/MultiTool.Common/Documents/DocumentRow.vb b/MultiTool.Common/Documents/DocumentRow.vb index 3c2fb15..15e6e6e 100644 --- a/MultiTool.Common/Documents/DocumentRow.vb +++ b/MultiTool.Common/Documents/DocumentRow.vb @@ -39,7 +39,7 @@ Namespace Documents Get Return Fields. Where(Function(f) f.Value.HasError). - Select(Function(f) f.Key).ToList() + Select(Function(f) $"{f.Key} has Error: {f.Value.Error}").ToList() End Get End Property @@ -56,7 +56,7 @@ Namespace Documents Private _External As String = "" Private _Original As String = "" - Public Property DataType As Constants.ColumnType = Constants.ColumnType.String + Public Property DataType As ColumnType = ColumnType.String Public Property [Error] As FieldError = FieldError.None Public Sub New() @@ -117,7 +117,7 @@ Namespace Documents Return Final End Function - Private Function FormatValue(pValue As String, pType As Constants.ColumnType) As String + Private Function FormatValue(pValue As String, pType As ColumnType) As String Select Case pType Case ColumnType.Decimal Return FormatDecimalValue(pValue) @@ -131,11 +131,11 @@ Namespace Documents ''' This function will capture values like below and format them according to winline format values ''' ''' 1000 - ''' 1.000.000 - ''' 1.000.000,00 + ''' 1.000 + ''' 1.000,00 ''' ''' A string value that represents a number - ''' A string value which contains at dot (.) as the decimal divider + ''' A string value which contains at dot (.) as the decimal divider, ex. 1000.00 Private Function FormatDecimalValue(pValue As String) As String If Not pValue.Contains(","c) Then Return pValue diff --git a/MultiTool.Form/MultiTool.Form.vbproj b/MultiTool.Form/MultiTool.Form.vbproj index e5e9d83..690dccc 100644 --- a/MultiTool.Form/MultiTool.Form.vbproj +++ b/MultiTool.Form/MultiTool.Form.vbproj @@ -338,6 +338,7 @@ + diff --git a/MultiTool.Form/My Project/Resources.Designer.vb b/MultiTool.Form/My Project/Resources.Designer.vb index 0e11d24..d2268c6 100644 --- a/MultiTool.Form/My Project/Resources.Designer.vb +++ b/MultiTool.Form/My Project/Resources.Designer.vb @@ -360,6 +360,16 @@ Namespace My.Resources End Get End Property + ''' + ''' Sucht eine lokalisierte Ressource vom Typ DevExpress.Utils.Svg.SvgImage. + ''' + Friend ReadOnly Property highimportance() As DevExpress.Utils.Svg.SvgImage + Get + Dim obj As Object = ResourceManager.GetObject("highimportance", resourceCulture) + Return CType(obj,DevExpress.Utils.Svg.SvgImage) + End Get + End Property + ''' ''' Sucht eine lokalisierte Ressource vom Typ DevExpress.Utils.Svg.SvgImage. ''' diff --git a/MultiTool.Form/My Project/Resources.resx b/MultiTool.Form/My Project/Resources.resx index b95784e..c6d7b3f 100644 --- a/MultiTool.Form/My Project/Resources.resx +++ b/MultiTool.Form/My Project/Resources.resx @@ -142,6 +142,9 @@ ..\Resources\tilelabels.svg;DevExpress.Utils.Svg.SvgImage, DevExpress.Data.v21.2, Version=21.2.4.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a + + ..\Resources\refreshpivottable.svg;DevExpress.Utils.Svg.SvgImage, DevExpress.Data.v21.2, Version=21.2.4.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a + ..\Resources\squarified1.svg;DevExpress.Utils.Svg.SvgImage, DevExpress.Data.v21.2, Version=21.2.4.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a @@ -196,9 +199,6 @@ ..\Resources\open3.svg;DevExpress.Utils.Svg.SvgImage, DevExpress.Data.v21.2, Version=21.2.4.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a - - ..\Resources\bo_sale.svg;DevExpress.Utils.Svg.SvgImage, DevExpress.Data.v21.2, Version=21.2.4.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a - ..\Resources\actions_checkcircled.svg;DevExpress.Utils.Svg.SvgImage, DevExpress.Data.v21.2, Version=21.2.4.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a @@ -220,6 +220,9 @@ ..\Resources\actions_send1.svg;DevExpress.Utils.Svg.SvgImage, DevExpress.Data.v21.2, Version=21.2.4.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a + + ..\Resources\actions_send4.svg;DevExpress.Utils.Svg.SvgImage, DevExpress.Data.v21.2, Version=21.2.4.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a + ..\Resources\actions_send2.svg;DevExpress.Utils.Svg.SvgImage, DevExpress.Data.v21.2, Version=21.2.4.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a @@ -235,6 +238,9 @@ ..\Resources\open23.svg;DevExpress.Utils.Svg.SvgImage, DevExpress.Data.v21.2, Version=21.2.4.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a + + ..\Resources\insertpagecount.svg;DevExpress.Utils.Svg.SvgImage, DevExpress.Data.v21.2, Version=21.2.4.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a + ..\Resources\actions_reload1.svg;DevExpress.Utils.Svg.SvgImage, DevExpress.Data.v21.2, Version=21.2.4.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a @@ -268,9 +274,6 @@ ..\Resources\paymentrefund.svg;DevExpress.Utils.Svg.SvgImage, DevExpress.Data.v21.2, Version=21.2.4.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a - - ..\Resources\squarified.svg;DevExpress.Utils.Svg.SvgImage, DevExpress.Data.v21.2, Version=21.2.4.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a - ..\Resources\support.svg;DevExpress.Utils.Svg.SvgImage, DevExpress.Data.v21.2, Version=21.2.4.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a @@ -286,8 +289,8 @@ ..\Resources\preview.svg;DevExpress.Utils.Svg.SvgImage, DevExpress.Data.v21.2, Version=21.2.4.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a - - ..\Resources\insertpagecount.svg;DevExpress.Utils.Svg.SvgImage, DevExpress.Data.v21.2, Version=21.2.4.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a + + ..\Resources\bo_sale.svg;DevExpress.Utils.Svg.SvgImage, DevExpress.Data.v21.2, Version=21.2.4.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a ..\Resources\exporttopdf.svg;DevExpress.Utils.Svg.SvgImage, DevExpress.Data.v21.2, Version=21.2.4.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a @@ -313,8 +316,8 @@ ..\Resources\actions_addcircled.svg;DevExpress.Utils.Svg.SvgImage, DevExpress.Data.v21.2, Version=21.2.4.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a - - ..\Resources\actions_send4.svg;DevExpress.Utils.Svg.SvgImage, DevExpress.Data.v21.2, Version=21.2.4.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a + + ..\Resources\squarified.svg;DevExpress.Utils.Svg.SvgImage, DevExpress.Data.v21.2, Version=21.2.4.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a ..\Resources\logical2.svg;DevExpress.Utils.Svg.SvgImage, DevExpress.Data.v21.2, Version=21.2.4.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a @@ -331,7 +334,7 @@ ..\Resources\actions_checkcircled2.svg;DevExpress.Utils.Svg.SvgImage, DevExpress.Data.v21.2, Version=21.2.4.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a - - ..\Resources\refreshpivottable.svg;DevExpress.Utils.Svg.SvgImage, DevExpress.Data.v21.2, Version=21.2.4.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a + + ..\Resources\highimportance.svg;DevExpress.Utils.Svg.SvgImage, DevExpress.Data.v21.2, Version=21.2.4.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a \ No newline at end of file diff --git a/MultiTool.Form/Resources/highimportance.svg b/MultiTool.Form/Resources/highimportance.svg new file mode 100644 index 0000000..7f7764c --- /dev/null +++ b/MultiTool.Form/Resources/highimportance.svg @@ -0,0 +1,19 @@ + + + + + + + \ No newline at end of file diff --git a/MultiTool.Form/frmImportMain.Designer.vb b/MultiTool.Form/frmImportMain.Designer.vb index 0d9886d..b625c4e 100644 --- a/MultiTool.Form/frmImportMain.Designer.vb +++ b/MultiTool.Form/frmImportMain.Designer.vb @@ -56,7 +56,8 @@ Partial Class frmImportMain Me.btnDebugExportReport = New DevExpress.XtraBars.BarButtonItem() Me.btnEditRow = New DevExpress.XtraBars.BarButtonItem() Me.btnCalculatePrices = New DevExpress.XtraBars.BarButtonItem() - Me.BarButtonItem2 = New DevExpress.XtraBars.BarButtonItem() + Me.btnOpenLogDirectory2 = New DevExpress.XtraBars.BarButtonItem() + Me.txtErrors = New DevExpress.XtraBars.BarStaticItem() Me.RibbonPage1 = New DevExpress.XtraBars.Ribbon.RibbonPage() Me.RibbonPageGroupLoad = New DevExpress.XtraBars.Ribbon.RibbonPageGroup() Me.RibbonPageGroupReport = New DevExpress.XtraBars.Ribbon.RibbonPageGroup() @@ -222,9 +223,9 @@ Partial Class frmImportMain 'RibbonControl ' Me.RibbonControl.ExpandCollapseItem.Id = 0 - Me.RibbonControl.Items.AddRange(New DevExpress.XtraBars.BarItem() {Me.RibbonControl.ExpandCollapseItem, Me.RibbonControl.SearchEditItem, Me.txtFilesLoaded, Me.btnLoadFiles, Me.btnTransferFile, Me.btnOpenInputDirectory, Me.btnOpenOutputDirectory, Me.btnOpenSchemaDirectory, Me.btnReloadFile, Me.btnTransferAllFiles, Me.btnOpenReport, Me.btnShowXml, Me.btnOpenLogDirectory, Me.btnOpenConfigDirectory, Me.txtCurrentFile, Me.btnConfig, Me.btnRemoveRow, Me.btnTestTransferFile, Me.BarButtonItem1, Me.btnDebugExportReport, Me.btnEditRow, Me.btnCalculatePrices, Me.BarButtonItem2}) + Me.RibbonControl.Items.AddRange(New DevExpress.XtraBars.BarItem() {Me.RibbonControl.ExpandCollapseItem, Me.RibbonControl.SearchEditItem, Me.txtFilesLoaded, Me.btnLoadFiles, Me.btnTransferFile, Me.btnOpenInputDirectory, Me.btnOpenOutputDirectory, Me.btnOpenSchemaDirectory, Me.btnReloadFile, Me.btnTransferAllFiles, Me.btnOpenReport, Me.btnShowXml, Me.btnOpenLogDirectory, Me.btnOpenConfigDirectory, Me.txtCurrentFile, Me.btnConfig, Me.btnRemoveRow, Me.btnTestTransferFile, Me.BarButtonItem1, Me.btnDebugExportReport, Me.btnEditRow, Me.btnCalculatePrices, Me.btnOpenLogDirectory2, Me.txtErrors}) resources.ApplyResources(Me.RibbonControl, "RibbonControl") - Me.RibbonControl.MaxItemId = 38 + Me.RibbonControl.MaxItemId = 39 Me.RibbonControl.Name = "RibbonControl" Me.RibbonControl.Pages.AddRange(New DevExpress.XtraBars.Ribbon.RibbonPage() {Me.RibbonPage1, Me.RibbonPage2}) Me.RibbonControl.RepositoryItems.AddRange(New DevExpress.XtraEditors.Repository.RepositoryItem() {Me.RepositoryItemComboBox1, Me.RepositoryItemProgressBar1}) @@ -383,12 +384,21 @@ Partial Class frmImportMain Me.btnCalculatePrices.ImageOptions.SvgImage = Global.MultiTool.Form.My.Resources.Resources.bo_sale Me.btnCalculatePrices.Name = "btnCalculatePrices" ' - 'BarButtonItem2 + 'btnOpenLogDirectory2 ' - resources.ApplyResources(Me.BarButtonItem2, "BarButtonItem2") - Me.BarButtonItem2.Id = 37 - Me.BarButtonItem2.ImageOptions.SvgImage = Global.MultiTool.Form.My.Resources.Resources.logical2 - Me.BarButtonItem2.Name = "BarButtonItem2" + resources.ApplyResources(Me.btnOpenLogDirectory2, "btnOpenLogDirectory2") + Me.btnOpenLogDirectory2.Id = 37 + Me.btnOpenLogDirectory2.ImageOptions.SvgImage = Global.MultiTool.Form.My.Resources.Resources.logical2 + Me.btnOpenLogDirectory2.Name = "btnOpenLogDirectory2" + ' + 'txtErrors + ' + resources.ApplyResources(Me.txtErrors, "txtErrors") + Me.txtErrors.Id = 38 + Me.txtErrors.ImageOptions.SvgImage = Global.MultiTool.Form.My.Resources.Resources.highimportance + Me.txtErrors.Name = "txtErrors" + Me.txtErrors.PaintStyle = DevExpress.XtraBars.BarItemPaintStyle.CaptionGlyph + Me.txtErrors.Tag = "Fehler: {0}" ' 'RibbonPage1 ' @@ -438,7 +448,7 @@ Partial Class frmImportMain Me.RibbonPageGroup5.ItemLinks.Add(Me.btnOpenInputDirectory) Me.RibbonPageGroup5.ItemLinks.Add(Me.btnOpenOutputDirectory) Me.RibbonPageGroup5.ItemLinks.Add(Me.btnOpenSchemaDirectory) - Me.RibbonPageGroup5.ItemLinks.Add(Me.BarButtonItem2) + Me.RibbonPageGroup5.ItemLinks.Add(Me.btnOpenLogDirectory2) Me.RibbonPageGroup5.Name = "RibbonPageGroup5" resources.ApplyResources(Me.RibbonPageGroup5, "RibbonPageGroup5") ' @@ -465,6 +475,7 @@ Partial Class frmImportMain ' Me.RibbonStatusBar.ItemLinks.Add(Me.txtFilesLoaded) Me.RibbonStatusBar.ItemLinks.Add(Me.txtCurrentFile) + Me.RibbonStatusBar.ItemLinks.Add(Me.txtErrors) resources.ApplyResources(Me.RibbonStatusBar, "RibbonStatusBar") Me.RibbonStatusBar.Name = "RibbonStatusBar" Me.RibbonStatusBar.Ribbon = Me.RibbonControl @@ -488,7 +499,10 @@ Partial Class frmImportMain resources.ApplyResources(Me.lookupMandator, "lookupMandator") Me.lookupMandator.MenuManager = Me.RibbonControl Me.lookupMandator.Name = "lookupMandator" + Me.lookupMandator.Properties.Appearance.BackColor = System.Drawing.Color.White + Me.lookupMandator.Properties.Appearance.Options.UseBackColor = True Me.lookupMandator.Properties.Buttons.AddRange(New DevExpress.XtraEditors.Controls.EditorButton() {New DevExpress.XtraEditors.Controls.EditorButton(CType(resources.GetObject("lookupMandator.Properties.Buttons"), DevExpress.XtraEditors.Controls.ButtonPredefines))}) + Me.lookupMandator.Properties.NullText = resources.GetString("lookupMandator.Properties.NullText") Me.lookupMandator.Properties.PopupView = Me.GridLookUpEdit1View ' 'GridLookUpEdit1View @@ -744,5 +758,6 @@ Partial Class frmImportMain Friend WithEvents GridBand2 As DevExpress.XtraGrid.Views.BandedGrid.GridBand Friend WithEvents btnEditRow As DevExpress.XtraBars.BarButtonItem Friend WithEvents btnCalculatePrices As DevExpress.XtraBars.BarButtonItem - Friend WithEvents BarButtonItem2 As DevExpress.XtraBars.BarButtonItem + Friend WithEvents btnOpenLogDirectory2 As DevExpress.XtraBars.BarButtonItem + Friend WithEvents txtErrors As DevExpress.XtraBars.BarStaticItem End Class diff --git a/MultiTool.Form/frmImportMain.resx b/MultiTool.Form/frmImportMain.resx index 711dd62..92d4451 100644 --- a/MultiTool.Form/frmImportMain.resx +++ b/MultiTool.Form/frmImportMain.resx @@ -250,9 +250,12 @@ Preiskalkulation ausführen - + Logverzeichnis öffnen + + Fehler: 0 + 0, 0 @@ -376,6 +379,9 @@ Combo + + [Mandant auswählen] + Id @@ -780,7 +786,7 @@ - {0} - WebService Multitool für WinLine + {0} - Import - WebService Multitool für WinLine GridViewFiles @@ -944,12 +950,18 @@ DevExpress.XtraBars.BarButtonItem, DevExpress.XtraBars.v21.2, Version=21.2.4.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a - - BarButtonItem2 + + btnOpenLogDirectory2 - + DevExpress.XtraBars.BarButtonItem, DevExpress.XtraBars.v21.2, Version=21.2.4.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a + + txtErrors + + + DevExpress.XtraBars.BarStaticItem, DevExpress.XtraBars.v21.2, Version=21.2.4.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a + RibbonPage1 diff --git a/MultiTool.Form/frmImportMain.vb b/MultiTool.Form/frmImportMain.vb index 241fb27..5a0c36d 100644 --- a/MultiTool.Form/frmImportMain.vb +++ b/MultiTool.Form/frmImportMain.vb @@ -14,7 +14,6 @@ Imports MultiTool.Common.Winline Imports MultiTool.Common.Winline.Entities Imports MultiTool.Common.Constants Imports MultiTool.Common.Exceptions -Imports MultiTool.Common.Documents.Document Public Class frmImportMain Public LogConfig As LogConfig @@ -39,6 +38,7 @@ Public Class frmImportMain ' Runtime variables Private CurrentGrid As GridControl = Nothing Private CurrentDocument As Document = Nothing + Private CurrentDocumentReadOnly As Boolean = False Public Sub New(pLogConfig As LogConfig, pConfigManager As ConfigManager(Of Config), pTemplate As Template) InitializeComponent() @@ -48,6 +48,12 @@ Public Class frmImportMain CurrentTemplate = pTemplate End Sub + Private Sub WebService_Progress(sender As Object, e As String) + SplashScreenManager.SetWaitFormDescription(e) + End Sub + +#Region "Form Events" + Private Sub frmImportMain_Load(sender As Object, e As EventArgs) Handles MyBase.Load Try Logger = LogConfig.GetLogger() @@ -114,120 +120,86 @@ Public Class frmImportMain End Try End Sub - Private Sub Grid_Focus(sender As GridControl, e As EventArgs) - CurrentGrid = sender - End Sub - - Private Sub Grid_MouseDoubleClick(sender As Object, e As MouseEventArgs) - Dim oGrid As GridControl = DirectCast(sender, GridControl) - Dim oView As GridView = DirectCast(oGrid.FocusedView, GridView) - Dim oHitInfo = oView.CalcHitInfo(e.Location) - - If Not oHitInfo.InDataRow Then - Exit Sub + Private Async Function frmImportMain_KeyDown(sender As Object, e As KeyEventArgs) As Task Handles MyBase.KeyDown + If e.KeyCode = Keys.F5 Then + Await LoadFiles() End If + End Function - Dim oRow As DataRow = oView.GetFocusedDataRow() - - Dim oModifiedRow = EditRow(oRow, oView) - If oModifiedRow IsNot Nothing Then - ReloadRow(oModifiedRow) + Private Sub txtCurrentFile_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles txtCurrentFile.ItemClick + If CurrentDocument IsNot Nothing Then + TryOpenFile(CurrentDocument.FullName, My.Resources.frmImportMainExtra.Aktuelle_Datei) End If End Sub - Private Sub btnEditRow_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnEditRow.ItemClick - Dim oGrid As GridControl = DirectCast(CurrentGrid, GridControl) - Dim oView As GridView = DirectCast(oGrid.FocusedView, GridView) - Dim oRow As DataRow = oView.GetFocusedDataRow() +#End Region - If oRow Is Nothing Then - Exit Sub +#Region "Grid Events" + Private Sub GridViewFiles_CustomDrawCell(sender As Object, e As Views.Base.RowCellCustomDrawEventArgs) Handles GridViewFiles.CustomDrawCell + Dim oDocument As Document = GridViewFiles.GetRow(e.RowHandle) + + If oDocument.HasErrors Then + e.Appearance.Options.UseBackColor = True + e.Appearance.BackColor = Color.LightCoral End If - Dim oModifiedRow = EditRow(oRow, oView) - If oModifiedRow IsNot Nothing Then - ReloadRow(oModifiedRow) + If oDocument.Imported Then + e.Appearance.Options.UseBackColor = True + e.Appearance.BackColor = Color.LightGreen End If End Sub - Private Function EditRow(pRow As DataRow, pView As GridView) As DocumentRow - Try - Dim oColumns = pView.Columns.Select(Function(c) c.FieldName).ToList() - Dim oDocumentRow = CurrentDocument.Rows. - Where(Function(r) r.Id.ToString = pRow.Item(COLUMN_GUID)). - SingleOrDefault() - Dim oTemplateTable = CurrentTemplate.Tables. - Where(Function(t) t.Name = pView.GridControl.Name). - SingleOrDefault() - - Dim oForm As New frmRowEditor( - LogConfig, - oColumns, - oDocumentRow, - CurrentDocument.Mandator, - Winline, - oTemplateTable - ) - - If oForm.ShowDialog() = DialogResult.OK Then - Return oForm.DocumentRow - Else - Return Nothing - End If - - Catch ex As Exception - FormHelper.ShowError(ex, My.Resources.frmImportMainExtra.Laden_der_Detailzeilen) - Return Nothing - - End Try - End Function + Private Sub GridView_CustomDrawCell(sender As Object, e As Views.Base.RowCellCustomDrawEventArgs) + Dim oView As GridView = sender + If e.RowHandle < 0 Or CurrentDocument Is Nothing Then + Exit Sub + End If - Private Async Function btnLoadFiles_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) As Task Handles btnLoadFiles.ItemClick - Await LoadFiles() - End Function + Dim oObject As DataRowView = oView.GetRow(e.RowHandle) + Dim oGuid = oObject.Row.Item(COLUMN_GUID) - Private Async Function frmImportMain_KeyDown(sender As Object, e As KeyEventArgs) As Task Handles MyBase.KeyDown - If e.KeyCode = Keys.F5 Then - Await LoadFiles() - End If - End Function + Dim oRow As DocumentRow = CurrentDocument.Rows. + Where(Function(r) r.Id.ToString = oGuid). + SingleOrDefault() - Private Async Sub btnReloadFile_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnReloadFile.ItemClick - Dim oCurrentMandator As Mandator = TryCast(lookupMandator.EditValue, Mandator) - If oCurrentMandator Is Nothing Then - MsgBox(My.Resources.frmImportMainExtra.Bitte_wählen_Sie_einen_Mandanten_aus__bevor_Sie_fortfahren, MsgBoxStyle.Exclamation, Text) + If oRow Is Nothing Then Exit Sub End If - Dim oMessage = String.Format(My.Resources.frmImportMainExtra.Wollen_Sie_wirklich_die_aktuelle_Datei_neu_laden, oCurrentMandator) - Dim oResult As DialogResult = MsgBox(oMessage, MsgBoxStyle.Question Or MsgBoxStyle.YesNo, Text) - - Try - BeginLoadingUI() + If oRow.HasErrors Then - If oResult = DialogResult.Yes Then - Dim oDocument As Document = GridViewFiles.GetRow(GridViewFiles.FocusedRowHandle) - Dim oNewDocument = Await DocumentLoader.LoadFile(oDocument.File, CurrentTemplate, lookupMandator.EditValue) - Dim oIndex = DocumentLoader.Files.IndexOf(oDocument) - DocumentLoader.Files.Item(oIndex) = oNewDocument + Dim oColumName = e.Column.FieldName + Dim oErrorField = oRow.Fields.Where(Function(field) field.Value.HasError).FirstOrDefault() - LoadDocument(oNewDocument) + If Not IsNothing(oErrorField) AndAlso oColumName = oErrorField.Key Then + e.Appearance.Options.UseBackColor = True + e.Appearance.BackColor = Color.LightCoral End If - Catch ex As NoMandatorException - FormHelper.ShowError(ex, My.Resources.frmImportMainExtra.Neuladen_des_Dokuments, My.Resources.frmImportMainExtra.Es_konnte_kein_passender_Mandant_ermittelt_werden) + End If + End Sub - Catch ex As MissingAttributeException - FormHelper.ShowError(ex, My.Resources.frmImportMainExtra.Neuladen_des_Dokuments, "Ein benötigtes Attribut wurde nicht gefunden.") - Catch ex As Exception - FormHelper.ShowError(ex, My.Resources.frmImportMainExtra.Neuladen_des_Dokuments) + Private Sub Grid_Focus(sender As GridControl, e As EventArgs) + CurrentGrid = sender + End Sub - Finally - EndLoadingUI() + Private Sub Grid_MouseDoubleClick(sender As Object, e As MouseEventArgs) + Dim oGrid As GridControl = DirectCast(sender, GridControl) + Dim oView As GridView = DirectCast(oGrid.FocusedView, GridView) + Dim oHitInfo = oView.CalcHitInfo(e.Location) - End Try + If Not oHitInfo.InDataRow Then + Exit Sub + End If + + Dim oRow As DataRow = oView.GetFocusedDataRow() + + Dim oModifiedRow = EditRow(oRow, oView) + If oModifiedRow IsNot Nothing Then + ReloadRow(oModifiedRow) + End If End Sub Private Sub GridViewFiles_FocusedRowChanged(sender As Object, e As Views.Base.FocusedRowChangedEventArgs) Handles GridViewFiles.FocusedRowChanged @@ -239,16 +211,9 @@ Public Class frmImportMain Exit Sub End If + If oDocument.Mandator Is Nothing Then lookupMandator.EditValue = Nothing - SplitContainerMain.Panel2.Enabled = False - - For Each oGrid In Grids - oGrid.DataSource = Nothing - Next - - MsgBox("Für die aktuelle Datei konnte kein Mandant zugeordnet werden! Bitte wählen Sie einen aus und laden Sie dann die Datei erneut.", MsgBoxStyle.Exclamation, Text) - Exit Sub End If lookupMandator.EditValue = oDocument.Mandator @@ -258,141 +223,51 @@ Public Class frmImportMain End Try End Sub - Private Sub WebService_Progress(sender As Object, e As String) - SplashScreenManager.SetWaitFormDescription(e) - End Sub - - Private Sub btnOpenInputDirectory_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnOpenInputDirectory.ItemClick - FormHelper.TryOpenDirectory(CurrentTemplate.InputDirectory, My.Resources.frmImportMainExtra.Eingangsverzeichnis) - End Sub - - Private Sub btnOpenOutputDirectory_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnOpenOutputDirectory.ItemClick - FormHelper.TryOpenDirectory(CurrentTemplate.OutputDirectory, My.Resources.frmImportMainExtra.Ausgabeverzeichnis) - End Sub - - Private Sub btnOpenSchemaDirectory_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnOpenSchemaDirectory.ItemClick - FormHelper.TryOpenDirectory(My.GeneralConfiguration.TemplateDirectory, My.Resources.frmImportMainExtra.Vorlagenverzeichnis) - End Sub - - Private Sub btnShowXml_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnShowXml.ItemClick - Dim oForm As New frmXmlEditor With {.FileName = CurrentDocument.FullName} - oForm.Show() - End Sub - - Private Sub txtCurrentFile_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles txtCurrentFile.ItemClick - If CurrentDocument IsNot Nothing Then - TryOpenFile(CurrentDocument.FullName, My.Resources.frmImportMainExtra.Aktuelle_Datei) - End If - End Sub +#End Region - Private Sub btnRemoveRow_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnRemoveRow.ItemClick - If CurrentGrid Is Nothing Then +#Region "Ribbon Events" + Private Async Sub btnCalculatePrices_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnCalculatePrices.ItemClick + Dim oCurrentMandator As Mandator = TryCast(lookupMandator.EditValue, Mandator) + If oCurrentMandator Is Nothing Then + MsgBox(My.Resources.frmImportMainExtra.Bitte_wählen_Sie_einen_Mandanten_aus__bevor_Sie_fortfahren, MsgBoxStyle.Exclamation, Text) Exit Sub End If - Dim oMessage As String = My.Resources.frmImportMainExtra.Wollen_Sie_die_ausgewählte_Zeile_wirklich_löschen_ - If MsgBox(oMessage, MsgBoxStyle.Question Or MsgBoxStyle.YesNo, Text) = MsgBoxResult.Yes Then - ' Get GUID of currently selected row - Dim oView As GridView = CurrentGrid.FocusedView - Dim oRow As DataRowView = oView.GetRow(oView.FocusedRowHandle) - Dim oGuid = oRow.Row.Item(COLUMN_GUID) - - ' Get currently selected document - Dim oDocument As Document = GridViewFiles.GetRow(GridViewFiles.FocusedRowHandle) - - Dim oNewRows = oDocument.Rows. - Where(Function(r) r.Id.ToString <> oGuid). - ToList() - oDocument.Rows = oNewRows - - Dim oIndex = DocumentLoader.Files.IndexOf(oDocument) - DocumentLoader.Files.Item(oIndex) = oDocument - - lookupMandator.EditValue = oDocument.Mandator - LoadDocument(oDocument) - End If - End Sub + BeginLoadingUI() + SplashScreenManager.SetWaitFormDescription("Lade Preisinformationen..") - Private Sub btnOpenReport_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnOpenReport.ItemClick + Dim oStopWatch As New Stopwatch() Try - SplashScreenManager.ShowWaitForm() - SplashScreenManager.SetWaitFormDescription(My.Resources.frmImportMainExtra.Erstellen_der_Berichtsvorschau) - SetDocumentButtonsEnabled(False) - GridControlFiles.Enabled = False - btnLoadFiles.Enabled = False - SplitContainerGrids.Enabled = False - - Dim oDocument As Document = GridViewFiles.GetRow(GridViewFiles.FocusedRowHandle) - Dim oReportGenerator = New ReportGenerator(Of OrderReport)(LogConfig, Database, - My.TemplateConfiguration, - My.GeneralConfiguration) - - - - Dim oReport As OrderReport = oReportGenerator.GenerateReport(oDocument, CurrentTemplate) - Dim oPrintTool As New ReportPrintTool(oReport) - oPrintTool.Report.CreateDocument(False) - oPrintTool.ShowPreview() + oStopWatch.Start() + Dim oNewDocument = Await DocumentLoader.MaybeApplyPriceFunctions(CurrentDocument, oCurrentMandator, CurrentTemplate) + oStopWatch.Stop() - SplitContainerGrids.Enabled = True - btnLoadFiles.Enabled = True - GridControlFiles.Enabled = True - SetDocumentButtonsEnabled(True) - SplashScreenManager.CloseWaitForm() + DocumentLoader.ReplaceDocument(oNewDocument) + LoadDocument(oNewDocument) Catch ex As Exception - FormHelper.ShowError(ex, My.Resources.frmImportMainExtra.Erstellen_der_Berichtsvorschau) - + FormHelper.ShowError(ex, "Laden der Preisinformationen") + Finally + EndLoadingUI() + Logger.Debug("Loading Priceinfo took [{0}] ms", oStopWatch.ElapsedMilliseconds) End Try End Sub - - Private Sub GridViewFiles_CustomDrawCell(sender As Object, e As Views.Base.RowCellCustomDrawEventArgs) Handles GridViewFiles.CustomDrawCell - Dim oDocument As Document = GridViewFiles.GetRow(e.RowHandle) - - If oDocument.HasErrors Then - e.Appearance.Options.UseBackColor = True - e.Appearance.BackColor = Color.LightCoral - End If - - If oDocument.Imported Then - e.Appearance.Options.UseBackColor = True - e.Appearance.BackColor = Color.LightGreen - End If + Private Sub btnOpenLogDirectory2_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnOpenLogDirectory2.ItemClick + FormHelper.TryOpenDirectory(LogConfig.LogDirectory, My.Resources.frmImportMainExtra.Logverzeichnis) End Sub - Private Sub GridView_CustomDrawCell(sender As Object, e As Views.Base.RowCellCustomDrawEventArgs) - Dim oView As GridView = sender - - If e.RowHandle < 0 Or CurrentDocument Is Nothing Then - Exit Sub - End If - - Dim oObject As DataRowView = oView.GetRow(e.RowHandle) - Dim oGuid = oObject.Row.Item(COLUMN_GUID) - - Dim oRow As DocumentRow = CurrentDocument.Rows. - Where(Function(r) r.Id.ToString = oGuid). - SingleOrDefault() - - If oRow Is Nothing Then - Exit Sub - End If - - If oRow.HasErrors Then - - Dim oColumName = e.Column.FieldName - Dim oErrorField = oRow.Fields.Where(Function(field) field.Value.HasError).FirstOrDefault() + Private Sub btnDebugExportReport_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnDebugExportReport.ItemClick + ' Get the document + Dim oDocument As Document = GridViewFiles.GetRow(GridViewFiles.FocusedRowHandle) - If Not IsNothing(oErrorField) AndAlso oColumName = oErrorField.Key Then - e.Appearance.Options.UseBackColor = True - e.Appearance.BackColor = Color.LightCoral - End If + ' Generate the report + Dim oReport = ReportGenerator.GenerateReport(oDocument, CurrentTemplate) + Dim oFilePath = ReportGenerator.GetReportFilePath(oDocument, CurrentTemplate) - End If + ' Export it to pdf + oReport.ExportToPdf(oFilePath) End Sub - - Private Async Sub btnTestTransferFile_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnTestTransferFile.ItemClick Try BeginLoadingUI() @@ -509,18 +384,147 @@ Public Class frmImportMain End Try End Sub - Private Sub btnDebugExportReport_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnDebugExportReport.ItemClick - ' Get the document - Dim oDocument As Document = GridViewFiles.GetRow(GridViewFiles.FocusedRowHandle) + Private Sub btnEditRow_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnEditRow.ItemClick + Dim oGrid As GridControl = DirectCast(CurrentGrid, GridControl) + Dim oView As GridView = DirectCast(oGrid.FocusedView, GridView) + Dim oRow As DataRow = oView.GetFocusedDataRow() - ' Generate the report - Dim oReport = ReportGenerator.GenerateReport(oDocument, CurrentTemplate) - Dim oFilePath = ReportGenerator.GetReportFilePath(oDocument, CurrentTemplate) + If oRow Is Nothing Then + Exit Sub + End If - ' Export it to pdf - oReport.ExportToPdf(oFilePath) + Dim oModifiedRow = EditRow(oRow, oView) + If oModifiedRow IsNot Nothing Then + ReloadRow(oModifiedRow) + End If End Sub + + + Private Async Function btnLoadFiles_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) As Task Handles btnLoadFiles.ItemClick + Await LoadFiles() + End Function + + Private Async Sub btnReloadFile_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnReloadFile.ItemClick + Dim oCurrentMandator As Mandator = TryCast(lookupMandator.EditValue, Mandator) + If oCurrentMandator Is Nothing Then + MsgBox(My.Resources.frmImportMainExtra.Bitte_wählen_Sie_einen_Mandanten_aus__bevor_Sie_fortfahren, MsgBoxStyle.Exclamation, Text) + Exit Sub + End If + + Dim oMessage = String.Format(My.Resources.frmImportMainExtra.Wollen_Sie_wirklich_die_aktuelle_Datei_neu_laden, oCurrentMandator) + Dim oResult As DialogResult = MsgBox(oMessage, MsgBoxStyle.Question Or MsgBoxStyle.YesNo, Text) + + Try + BeginLoadingUI() + + If oResult = DialogResult.Yes Then + Dim oDocument As Document = GridViewFiles.GetRow(GridViewFiles.FocusedRowHandle) + Dim oNewDocument = Await DocumentLoader.LoadFile(oDocument.File, CurrentTemplate, lookupMandator.EditValue) + Dim oIndex = DocumentLoader.Files.IndexOf(oDocument) + DocumentLoader.Files.Item(oIndex) = oNewDocument + + LoadDocument(oNewDocument) + End If + + Catch ex As NoMandatorException + FormHelper.ShowError(ex, My.Resources.frmImportMainExtra.Neuladen_des_Dokuments, My.Resources.frmImportMainExtra.Es_konnte_kein_passender_Mandant_ermittelt_werden) + + Catch ex As MissingAttributeException + FormHelper.ShowError(ex, My.Resources.frmImportMainExtra.Neuladen_des_Dokuments, "Ein benötigtes Attribut wurde nicht gefunden.") + + Catch ex As Exception + FormHelper.ShowError(ex, My.Resources.frmImportMainExtra.Neuladen_des_Dokuments) + + Finally + EndLoadingUI() + + End Try + End Sub + + Private Sub btnOpenInputDirectory_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnOpenInputDirectory.ItemClick + FormHelper.TryOpenDirectory(CurrentTemplate.InputDirectory, My.Resources.frmImportMainExtra.Eingangsverzeichnis) + End Sub + + Private Sub btnOpenOutputDirectory_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnOpenOutputDirectory.ItemClick + FormHelper.TryOpenDirectory(CurrentTemplate.OutputDirectory, My.Resources.frmImportMainExtra.Ausgabeverzeichnis) + End Sub + + Private Sub btnOpenSchemaDirectory_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnOpenSchemaDirectory.ItemClick + FormHelper.TryOpenDirectory(My.GeneralConfiguration.TemplateDirectory, My.Resources.frmImportMainExtra.Vorlagenverzeichnis) + End Sub + + Private Sub btnShowXml_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnShowXml.ItemClick + Dim oForm As New frmXmlEditor With {.FileName = CurrentDocument.FullName} + oForm.Show() + End Sub + + Private Sub btnRemoveRow_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnRemoveRow.ItemClick + If CurrentGrid Is Nothing Then + Exit Sub + End If + + Dim oMessage As String = My.Resources.frmImportMainExtra.Wollen_Sie_die_ausgewählte_Zeile_wirklich_löschen_ + If MsgBox(oMessage, MsgBoxStyle.Question Or MsgBoxStyle.YesNo, Text) = MsgBoxResult.Yes Then + ' Get GUID of currently selected row + Dim oView As GridView = CurrentGrid.FocusedView + Dim oRow As DataRowView = oView.GetRow(oView.FocusedRowHandle) + Dim oGuid = oRow.Row.Item(COLUMN_GUID) + + ' Get currently selected document + Dim oDocument As Document = GridViewFiles.GetRow(GridViewFiles.FocusedRowHandle) + + Dim oNewRows = oDocument.Rows. + Where(Function(r) r.Id.ToString <> oGuid). + ToList() + oDocument.Rows = oNewRows + + Dim oIndex = DocumentLoader.Files.IndexOf(oDocument) + DocumentLoader.Files.Item(oIndex) = oDocument + + lookupMandator.EditValue = oDocument.Mandator + LoadDocument(oDocument) + End If + End Sub + + Private Sub btnOpenReport_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnOpenReport.ItemClick + Try + If CurrentDocumentReadOnly = True Then + FormHelper.ShowWarning("Bitte wählen Sie zunächst einen Mandanten aus, bevor Sie diese Datei exportieren!") + Exit Sub + End If + + SplashScreenManager.ShowWaitForm() + SplashScreenManager.SetWaitFormDescription(My.Resources.frmImportMainExtra.Erstellen_der_Berichtsvorschau) + SetDocumentButtonsEnabled(False) + GridControlFiles.Enabled = False + btnLoadFiles.Enabled = False + SplitContainerGrids.Enabled = False + + Dim oDocument As Document = GridViewFiles.GetRow(GridViewFiles.FocusedRowHandle) + Dim oReportGenerator = New ReportGenerator(Of OrderReport)(LogConfig, Database, + My.TemplateConfiguration, + My.GeneralConfiguration) + + + + Dim oReport As OrderReport = oReportGenerator.GenerateReport(oDocument, CurrentTemplate) + Dim oPrintTool As New ReportPrintTool(oReport) + oPrintTool.Report.CreateDocument(False) + oPrintTool.ShowPreview() + + SplitContainerGrids.Enabled = True + btnLoadFiles.Enabled = True + GridControlFiles.Enabled = True + SetDocumentButtonsEnabled(True) + SplashScreenManager.CloseWaitForm() + Catch ex As Exception + FormHelper.ShowError(ex, My.Resources.frmImportMainExtra.Erstellen_der_Berichtsvorschau) + + End Try + End Sub +#End Region + #Region "Methods" Private Sub LoadDocument(pDocument As Document) Try @@ -577,6 +581,7 @@ Public Class frmImportMain Next txtCurrentFile.Caption = String.Format(My.Resources.frmImportMainExtra.Aktuelle_Datei___0_, pDocument.FileName) + txtErrors.Caption = String.Format("Fehler: {0}", pDocument.Errors.Count) CurrentDocument = pDocument @@ -588,6 +593,18 @@ Public Class frmImportMain btnCalculatePrices.Enabled = True End If + If CurrentDocument.Mandator Is Nothing Then + RibbonPageGroupEdit.Enabled = False + RibbonPageGroupTransfer.Enabled = False + CurrentDocumentReadOnly = True + + MsgBox("Für die aktuelle Datei konnte kein Mandant zugeordnet werden! Bitte wählen Sie einen aus und laden Sie dann die Datei erneut.", MsgBoxStyle.Critical, Text) + Else + RibbonPageGroupEdit.Enabled = True + RibbonPageGroupTransfer.Enabled = True + CurrentDocumentReadOnly = False + End If + Catch ex As Exception SetDocumentButtonsEnabled(False) Logger.Error(ex) @@ -610,17 +627,20 @@ Public Class frmImportMain Try BeginLoadingUI() + DocumentCleaner.CleanImportedDocuments(DocumentLoader.Files) + + Logger.Debug("Loading [{0}] files", DocumentLoader.Files.Count) + AddHandler DocumentLoader.FileLoadComplete, Sub(_sender As Object, _e As Documents.DocumentLoader.FileLoadInfo) Dim oMessage = String.Format("Lade Dateien ({0}/{1})", _e.FilesLoaded, _e.FilesTotal) - SplashScreenManager.SetWaitFormDescription(oMessage) + SplashScreenManager.SetWaitFormCaption(oMessage) End Sub AddHandler DocumentLoader.FileLoadProgress, Sub(_sender As Object, _e As Documents.DocumentLoader.FileLoadProgressInfo) - Dim oMessage = String.Format("Lade Dateien ({0}/{1}): {2}", _e.FilesLoaded, _e.FilesTotal, _e.RunningFunction) - SplashScreenManager.SetWaitFormDescription(oMessage) + SplashScreenManager.SetWaitFormDescription(_e.RunningFunction) End Sub - SplashScreenManager.SetWaitFormDescription(String.Format("Lade Dateien ({0}/{1})", 0, DocumentLoader.Files.Count)) + SplashScreenManager.SetWaitFormCaption(String.Format("Lade Dateien ({0}/{1})", 0, DocumentLoader.Files.Count)) If Await DocumentLoader.LoadFiles(CurrentTemplate, lookupMandator.EditValue) Then GridControlFiles.DataSource = Nothing @@ -639,7 +659,42 @@ Public Class frmImportMain End Try End Function + Private Function EditRow(pRow As DataRow, pView As GridView) As DocumentRow + Try + If CurrentDocumentReadOnly = True Then + FormHelper.ShowWarning("Bitte wählen Sie zunächst einen Mandanten aus, bevor Sie diese Datei bearbeiten!") + Return Nothing + End If + + Dim oColumns = pView.Columns.Select(Function(c) c.FieldName).ToList() + Dim oDocumentRow = CurrentDocument.Rows. + Where(Function(r) r.Id.ToString = pRow.Item(COLUMN_GUID)). + SingleOrDefault() + Dim oTemplateTable = CurrentTemplate.Tables. + Where(Function(t) t.Name = pView.GridControl.Name). + SingleOrDefault() + + Dim oForm As New frmRowEditor( + LogConfig, + oColumns, + oDocumentRow, + CurrentDocument.Mandator, + Winline, + oTemplateTable + ) + + If oForm.ShowDialog() = DialogResult.OK Then + Return oForm.DocumentRow + Else + Return Nothing + End If + Catch ex As Exception + FormHelper.ShowError(ex, My.Resources.frmImportMainExtra.Laden_der_Detailzeilen) + Return Nothing + + End Try + End Function Private Async Function TransferFile(pDocument As Document, Optional pIsTest As Boolean = False) As Task(Of Boolean) ' Check for errors and abort @@ -778,35 +833,16 @@ Public Class frmImportMain btnEditRow.Enabled = pEnabled End Sub - Private Async Sub btnCalculatePrices_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnCalculatePrices.ItemClick - Dim oCurrentMandator As Mandator = TryCast(lookupMandator.EditValue, Mandator) - If oCurrentMandator Is Nothing Then - MsgBox(My.Resources.frmImportMainExtra.Bitte_wählen_Sie_einen_Mandanten_aus__bevor_Sie_fortfahren, MsgBoxStyle.Exclamation, Text) - Exit Sub + Private Sub lookupMandator_EditValueChanged(sender As Object, e As EventArgs) Handles lookupMandator.EditValueChanged + If lookupMandator.EditValue Is Nothing Then + lookupMandator.BackColor = Color.LightCoral + Else + lookupMandator.BackColor = Nothing End If - - BeginLoadingUI() - SplashScreenManager.SetWaitFormDescription("Lade Preisinformationen..") - - Dim oStopWatch As New Stopwatch() - Try - oStopWatch.Start() - Dim oNewDocument = Await DocumentLoader.MaybeApplyPriceFunctions(CurrentDocument, oCurrentMandator, CurrentTemplate) - oStopWatch.Stop() - - DocumentLoader.ReplaceDocument(oNewDocument) - LoadDocument(oNewDocument) - Catch ex As Exception - FormHelper.ShowError(ex, "Laden der Preisinformationen") - Finally - EndLoadingUI() - Logger.Debug("Loading Priceinfo took [{0}] ms", oStopWatch.ElapsedMilliseconds) - End Try End Sub - Private Sub BarButtonItem2_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItem2.ItemClick - FormHelper.TryOpenDirectory(LogConfig.LogDirectory, My.Resources.frmImportMainExtra.Logverzeichnis) - End Sub + #End Region + End Class \ No newline at end of file