Maersk Import komplett abbrechen wenn eine ungültige IMO dabei ist

This commit is contained in:
Daniel Schick 2023-03-22 09:52:33 +01:00
parent 8d94534021
commit ce5327821b
2 changed files with 17 additions and 21 deletions

View File

@ -30,8 +30,7 @@ namespace ENI2.Controls
#region Fields
private readonly ObservableCollection<MaerskData> maerskDataList = new ObservableCollection<MaerskData>();
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<MaerskData> maerskDataList = new ObservableCollection<MaerskData>();
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<MaerskData> importData = new List<MaerskData>();
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();

View File

@ -36,7 +36,7 @@
<MinimumRequiredVersion>5.4.0.0</MinimumRequiredVersion>
<CreateWebPageOnPublish>true</CreateWebPageOnPublish>
<WebPage>publish.html</WebPage>
<ApplicationRevision>4</ApplicationRevision>
<ApplicationRevision>5</ApplicationRevision>
<ApplicationVersion>7.10.0.%2a</ApplicationVersion>
<UseApplicationTrust>false</UseApplicationTrust>
<CreateDesktopShortcut>true</CreateDesktopShortcut>