From 7f817ffce1173e17dee1ea398a9fd0b4048c0743 Mon Sep 17 00:00:00 2001 From: Jonathan Jenne Date: Mon, 28 Feb 2022 11:59:10 +0100 Subject: [PATCH] add button for Price calculation --- MultiTool.Form/frmImportMain.Designer.vb | 17 +++--- MultiTool.Form/frmImportMain.resx | 12 ++--- MultiTool.Form/frmImportMain.vb | 67 ++++++++++++++++++------ 3 files changed, 66 insertions(+), 30 deletions(-) diff --git a/MultiTool.Form/frmImportMain.Designer.vb b/MultiTool.Form/frmImportMain.Designer.vb index 5417547..cffe338 100644 --- a/MultiTool.Form/frmImportMain.Designer.vb +++ b/MultiTool.Form/frmImportMain.Designer.vb @@ -55,6 +55,7 @@ Partial Class frmImportMain Me.BarButtonItem1 = New DevExpress.XtraBars.BarButtonItem() Me.btnDebugExportReport = New DevExpress.XtraBars.BarButtonItem() Me.btnEditRow = New DevExpress.XtraBars.BarButtonItem() + Me.btnCalculatePrices = New DevExpress.XtraBars.BarButtonItem() Me.RibbonPage1 = New DevExpress.XtraBars.Ribbon.RibbonPage() Me.RibbonPageGroup1 = New DevExpress.XtraBars.Ribbon.RibbonPageGroup() Me.RibbonPageGroup4 = New DevExpress.XtraBars.Ribbon.RibbonPageGroup() @@ -86,7 +87,6 @@ Partial Class frmImportMain Me.WorkspaceManager1 = New DevExpress.Utils.WorkspaceManager(Me.components) Me.BehaviorManager = New DevExpress.Utils.Behaviors.BehaviorManager(Me.components) Me.SplashScreenManager = New DevExpress.XtraSplashScreen.SplashScreenManager(Me, GetType(Global.MultiTool.Form.frmWaitForm), True, True) - Me.btnCalculatePrices = New DevExpress.XtraBars.BarButtonItem() CType(Me.SplitContainerMain, System.ComponentModel.ISupportInitialize).BeginInit() CType(Me.SplitContainerMain.Panel1, System.ComponentModel.ISupportInitialize).BeginInit() Me.SplitContainerMain.Panel1.SuspendLayout() @@ -373,6 +373,14 @@ Partial Class frmImportMain Me.btnEditRow.ImageOptions.SvgImage = Global.MultiTool.Form.My.Resources.Resources.editquery Me.btnEditRow.Name = "btnEditRow" ' + 'btnCalculatePrices + ' + resources.ApplyResources(Me.btnCalculatePrices, "btnCalculatePrices") + Me.btnCalculatePrices.Enabled = False + Me.btnCalculatePrices.Id = 36 + Me.btnCalculatePrices.ImageOptions.SvgImage = Global.MultiTool.Form.My.Resources.Resources.bo_sale + Me.btnCalculatePrices.Name = "btnCalculatePrices" + ' 'RibbonPage1 ' Me.RibbonPage1.Groups.AddRange(New DevExpress.XtraBars.Ribbon.RibbonPageGroup() {Me.RibbonPageGroup1, Me.RibbonPageGroup4, Me.RibbonPageGroup3, Me.RibbonPageGroup7}) @@ -600,13 +608,6 @@ Partial Class frmImportMain ' Me.SplashScreenManager.ClosingDelay = 500 ' - 'btnCalculatePrices - ' - resources.ApplyResources(Me.btnCalculatePrices, "btnCalculatePrices") - Me.btnCalculatePrices.Id = 36 - Me.btnCalculatePrices.ImageOptions.SvgImage = Global.MultiTool.Form.My.Resources.Resources.bo_sale - Me.btnCalculatePrices.Name = "btnCalculatePrices" - ' 'frmImportMain ' resources.ApplyResources(Me, "$this") diff --git a/MultiTool.Form/frmImportMain.resx b/MultiTool.Form/frmImportMain.resx index bb9ad53..8b198ef 100644 --- a/MultiTool.Form/frmImportMain.resx +++ b/MultiTool.Form/frmImportMain.resx @@ -935,6 +935,12 @@ DevExpress.XtraBars.BarButtonItem, DevExpress.XtraBars.v21.2, Version=21.2.4.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a + + btnCalculatePrices + + + DevExpress.XtraBars.BarButtonItem, DevExpress.XtraBars.v21.2, Version=21.2.4.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a + RibbonPage1 @@ -1055,12 +1061,6 @@ DevExpress.XtraSplashScreen.SplashScreenManager, DevExpress.XtraEditors.v21.2, Version=21.2.4.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a - - btnCalculatePrices - - - DevExpress.XtraBars.BarButtonItem, DevExpress.XtraBars.v21.2, Version=21.2.4.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a - frmImportMain diff --git a/MultiTool.Form/frmImportMain.vb b/MultiTool.Form/frmImportMain.vb index 2381909..be98694 100644 --- a/MultiTool.Form/frmImportMain.vb +++ b/MultiTool.Form/frmImportMain.vb @@ -1,6 +1,5 @@ Imports System.IO Imports System.Net.Http -Imports DevExpress.Utils.Behaviors.Common Imports DevExpress.XtraGrid Imports DevExpress.XtraGrid.Views.Grid Imports DevExpress.XtraReports.UI @@ -15,8 +14,7 @@ Imports MultiTool.Shared.Winline Imports MultiTool.Shared.Winline.Entities Imports MultiTool.Shared.Constants Imports MultiTool.Shared.Exceptions -Imports Document = MultiTool.Shared.Documents.Document -Imports DevExpress.XtraGrid.Views.Grid.ViewInfo +Imports MultiTool.Shared.Documents.Document Public Class frmImportMain Public LogConfig As LogConfig @@ -131,7 +129,10 @@ Public Class frmImportMain Dim oRow As DataRow = oView.GetFocusedDataRow() - EditRow(oRow, oView) + Dim oModifiedRow = EditRow(oRow, oView) + If oModifiedRow IsNot Nothing Then + ReloadRow(oModifiedRow) + End If End Sub Private Sub btnEditRow_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnEditRow.ItemClick @@ -143,10 +144,13 @@ Public Class frmImportMain Exit Sub End If - EditRow(oRow, oView) + Dim oModifiedRow = EditRow(oRow, oView) + If oModifiedRow IsNot Nothing Then + ReloadRow(oModifiedRow) + End If End Sub - Private Sub EditRow(pRow As DataRow, pView As GridView) + 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. @@ -164,22 +168,19 @@ Public Class frmImportMain Winline, oTemplateTable ) - If oForm.ShowDialog() = DialogResult.OK Then - Dim oModifiedRow = oForm.DocumentRow - Dim oIndex = CurrentDocument.Rows.IndexOf(oModifiedRow) - - CurrentDocument.Rows.Item(oIndex) = oModifiedRow - LoadDocument(CurrentDocument) - ' Refresh Files to update Row color - GridViewFiles.RefreshData() + 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 Sub + End Function Private Sub btnLoadFiles_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnLoadFiles.ItemClick @@ -570,7 +571,15 @@ Public Class frmImportMain txtCurrentFile.Caption = String.Format(My.Resources.frmImportMainExtra.Aktuelle_Datei___0_, pDocument.FileName) CurrentDocument = pDocument + SetDocumentButtonsEnabled(True) + + If CurrentDocument.HasErrors = True Then + btnCalculatePrices.Enabled = False + Else + btnCalculatePrices.Enabled = True + End If + Catch ex As Exception SetDocumentButtonsEnabled(False) Logger.Error(ex) @@ -578,6 +587,17 @@ Public Class frmImportMain End Try End Sub + Private Sub ReloadRow(pRow As DocumentRow) + Dim oModifiedRow = pRow + Dim oIndex = CurrentDocument.Rows.IndexOf(oModifiedRow) + + CurrentDocument.Rows.Item(oIndex) = oModifiedRow + LoadDocument(CurrentDocument) + + ' Refresh Files to update Row color + GridViewFiles.RefreshData() + End Sub + Private Sub LoadFiles() Try BeginLoadingUI() @@ -604,6 +624,8 @@ Public Class frmImportMain End Try End Sub + + Private Async Function TransferFile(pDocument As Document, Optional pIsTest As Boolean = False) As Task(Of Boolean) ' Check for errors and abort If pDocument.HasErrors = True Then @@ -699,7 +721,7 @@ Public Class frmImportMain End Sub Private Sub TryOpenFile(pPath As String, pDisplayName As String) - If File.Exists(pPath) Then + If IO.File.Exists(pPath) Then Process.Start(pPath) Else Dim oMessage = String.Format(My.Resources.frmImportMainExtra._0__nicht_konfiguriert_oder_nicht_gefunden, pDisplayName) @@ -733,5 +755,18 @@ Public Class frmImportMain btnEditRow.Enabled = pEnabled End Sub + Private 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 oNewDocument = DocumentLoader.MaybeApplyPriceFunctions(CurrentDocument, oCurrentMandator, CurrentTemplate) + + DocumentLoader.ReplaceDocument(oNewDocument) + LoadDocument(oNewDocument) + End Sub + #End Region End Class \ No newline at end of file