From ce5327821b0f299c3ae37fcd96009a39408052f9 Mon Sep 17 00:00:00 2001 From: Daniel Schick Date: Wed, 22 Mar 2023 09:52:33 +0100 Subject: [PATCH] =?UTF-8?q?Maersk=20Import=20komplett=20abbrechen=20wenn?= =?UTF-8?q?=20eine=20ung=C3=BCltige=20IMO=20dabei=20ist?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ENI2/Controls/MaerskListControl.xaml.cs | 36 +++++++++++-------------- ENI2/ENI2.csproj | 2 +- 2 files changed, 17 insertions(+), 21 deletions(-) diff --git a/ENI2/Controls/MaerskListControl.xaml.cs b/ENI2/Controls/MaerskListControl.xaml.cs index b9a50030..57647754 100644 --- a/ENI2/Controls/MaerskListControl.xaml.cs +++ b/ENI2/Controls/MaerskListControl.xaml.cs @@ -30,8 +30,7 @@ namespace ENI2.Controls #region Fields - private readonly ObservableCollection maerskDataList = new ObservableCollection(); - private const uint MAX_EMPTY_ROWS_ON_IMPORT = 3; // import breaks if more than this count of empty rows have been read + private readonly ObservableCollection maerskDataList = new ObservableCollection(); private readonly DatabaseEntityWatchdog _dbWatchDog; #endregion @@ -306,8 +305,7 @@ namespace ENI2.Controls if (reader.GetFieldType(fieldNum) == typeof(int)) return reader.GetInt32(fieldNum).ToString(); if (reader.GetFieldType(fieldNum) == typeof(double)) - return ((int) reader.GetDouble(fieldNum)).ToString(); - Type theType = reader.GetFieldType(fieldNum); + return ((int) reader.GetDouble(fieldNum)).ToString(); return null; } @@ -375,9 +373,10 @@ namespace ENI2.Controls using (IExcelDataReader reader = ExcelReaderFactory.CreateReader(stream)) { List importData = new List(); - uint emptyRowCnt = 0; + bool isFirstRow = true; int currentRow = 1; + bool imosAreOkay = true; try { @@ -431,28 +430,25 @@ namespace ENI2.Controls if (!reader.IsDBNull(11)) md.ColL = ReadFieldAsString(reader, 11); if (!reader.IsDBNull(12)) md.ColM = ReadFieldAsString(reader, 12); if (!reader.IsDBNull(13)) md.Remark = ReadFieldAsString(reader, 13); - - bool imoIsOkay = false; + if(!md.ColF.IsNullOrEmpty()) { if (Int32.TryParse(md.ColF, out int imo)) { - if ((imo > 1000000) && (imo < 9999999)) + if ((imo < 1000000) && (imo > 9999999)) { - imoIsOkay = true; + imosAreOkay = false; } } - if(!imoIsOkay) + if(!imosAreOkay) { - MessageBox.Show($"Invalid IMO in row {currentRow}, skipping entry", Properties.Resources.textCaptionError, MessageBoxButton.OK, MessageBoxImage.Error); + MessageBox.Show($"Invalid IMO in row {currentRow}, aborting import", Properties.Resources.textCaptionError, MessageBoxButton.OK, MessageBoxImage.Error); + break; } } - - if (imoIsOkay) - importData.Add(md); - else - emptyRowCnt++; - if (emptyRowCnt > MAX_EMPTY_ROWS_ON_IMPORT) break; + + importData.Add(md); + if (isFirstRow) isFirstRow = false; currentRow++; } @@ -462,7 +458,7 @@ namespace ENI2.Controls MessageBox.Show("Error reading Excel: " + ex.Message, Properties.Resources.textCaptionError, MessageBoxButton.OK, MessageBoxImage.Error); } - if (importData.Count > 0) + if (imosAreOkay && importData.Count > 0) { busyControl.BusyState = Util.UIHelper.BusyStateEnum.BUSY; @@ -491,9 +487,9 @@ namespace ENI2.Controls this.TimeFilterItemSource(); // this.SortItemSource(); busyControl.BusyState = Util.UIHelper.BusyStateEnum.NEUTRAL; - } - this.dataGridPOCores.Items.Refresh(); + this.dataGridPOCores.Items.Refresh(); + } } stream.Close(); diff --git a/ENI2/ENI2.csproj b/ENI2/ENI2.csproj index 0282d09d..8141c294 100644 --- a/ENI2/ENI2.csproj +++ b/ENI2/ENI2.csproj @@ -36,7 +36,7 @@ 5.4.0.0 true publish.html - 4 + 5 7.10.0.%2a false true