Korrekturen lt Rückmeldung

This commit is contained in:
Daniel Schick 2022-12-14 16:18:44 +01:00
parent a0bcbe4ccf
commit 5118ed8aaf
7 changed files with 655 additions and 507 deletions

View File

@ -119,7 +119,7 @@ namespace ENI2.Controls
{
var grid = sender as ENIDataGrid;
if (Key.Delete == e.Key)
this.deleteItem(null, null);
this.deleteItem(null, null);
}
}

View File

@ -104,7 +104,7 @@ namespace ENI2.Controls
{
DBManager.Instance.GetReportingPartyDict().Add(Guid.NewGuid(), rp);
this.ReportingParties.Add(rp);
this.dataGridReportingParties.Items.Refresh();
this.dataGridReportingParties.Items.Refresh();
}
}

View File

@ -7,27 +7,25 @@
//
// Copyright (c) 2015 Informatikbüro Daniel Schick. All rights reserved.
using log4net;
using bsmd.database;
using ENI2.Locode;
using Microsoft.Office.Interop.Excel;
using System;
using System.Collections.Generic;
using System.Data;
using System.Globalization;
using System.Linq;
using System.Runtime.InteropServices;
using ENI2.Locode;
using bsmd.database;
using System.Text.RegularExpressions;
namespace ENI2.Excel
{
internal class ExcelReader : ExcelBase
{
internal enum ReadState
{ NONE, OK, WARN, FAIL };
internal enum ReadState { NONE, OK, WARN, FAIL };
internal enum SheetTypeEnum { BSMD, DAKOSY };
internal enum SheetTypeEnum
{ BSMD, DAKOSY };
private readonly SheetTypeEnum _sheetType = SheetTypeEnum.BSMD;
@ -36,15 +34,16 @@ namespace ENI2.Excel
public ExcelReader(string filePath, bool openReadonly = true, bool createNameFields = true)
{
this._workBook = _excelWorkbooks.Open(filePath, 0, openReadonly, 5, "", "", false, XlPlatform.xlWindows, "", false, false, 0, false, false, false);
if(createNameFields)
if (createNameFields)
this.InitNameFields();
// Determine if this is a Dakosy or BSMD Sheet
if(createNameFields)
if (createNameFields)
_sheetType = (_nameDict.Count > 10) ? SheetTypeEnum.BSMD : SheetTypeEnum.DAKOSY;
}
public SheetTypeEnum SheetType { get { return _sheetType; } }
public SheetTypeEnum SheetType
{ get { return _sheetType; } }
internal static void SaveMessage(Message message)
{
@ -80,7 +79,7 @@ namespace ENI2.Excel
if (result != null)
{
result = result.Trim();
if(result.Length > 0)
if (result.Length > 0)
{
result = result.Clean();
}
@ -120,7 +119,7 @@ namespace ENI2.Excel
if (!val.IsNullOrEmpty())
{
val = val.ToUpper();
string portName = LocodeDB.SSNPortNameFromLocode(val);
string portName = LocodeDB.SSNPortNameFromLocode(val);
if (portName.IsNullOrEmpty())
{
_log.WarnFormat("unknown Locode {0}", val);
@ -135,7 +134,7 @@ namespace ENI2.Excel
string val = ReadText(lookup);
if (val.IsNullOrEmpty()) return null;
if(int.TryParse(val, out int result))
if (int.TryParse(val, out int result))
{
if ((result < 10) || (result > 99))
_log.WarnFormat("invalid cargo LA code {0}", result);
@ -154,16 +153,17 @@ namespace ENI2.Excel
string val = this.ReadText(lookup);
if (val != null)
{
if (val.Equals("m", StringComparison.CurrentCultureIgnoreCase) || val.Equals("male", StringComparison.CurrentCultureIgnoreCase)) {
if (val.Equals("m", StringComparison.CurrentCultureIgnoreCase) || val.Equals("male", StringComparison.CurrentCultureIgnoreCase))
{
result = 1;
}
else if (val.Equals("f", StringComparison.CurrentCultureIgnoreCase) || val.Equals("female", StringComparison.CurrentCultureIgnoreCase))
{
result = 2;
}
else if (val.Equals("n", StringComparison.CurrentCultureIgnoreCase) ||
val.Equals("not applicable", StringComparison.CurrentCultureIgnoreCase) ||
val.Equals("d", StringComparison.CurrentCultureIgnoreCase) ||
else if (val.Equals("n", StringComparison.CurrentCultureIgnoreCase) ||
val.Equals("not applicable", StringComparison.CurrentCultureIgnoreCase) ||
val.Equals("d", StringComparison.CurrentCultureIgnoreCase) ||
val.Equals("diverse", StringComparison.CurrentCultureIgnoreCase))
{
result = 9;
@ -173,7 +173,7 @@ namespace ENI2.Excel
result = 0;
}
}
if(result == null)
if (result == null)
{
_log.ErrorFormat("error reading gender on {0}", lookup);
}
@ -192,7 +192,7 @@ namespace ENI2.Excel
if (val.Equals("picture_id", StringComparison.CurrentCultureIgnoreCase) || val.Equals("picture id", StringComparison.CurrentCultureIgnoreCase) || val.Equals("4")) result = 3;
if (val.Equals("residental_permit", StringComparison.CurrentCultureIgnoreCase) || val.Equals("residental permit", StringComparison.CurrentCultureIgnoreCase) || val.Equals("5")) result = 4;
if (val.Equals("other_legal_identity_document", StringComparison.CurrentCultureIgnoreCase) || val.Equals("other legal identity document", StringComparison.CurrentCultureIgnoreCase) || val.Equals("6")) result = 5;
if (val.Equals("ic", StringComparison.CurrentCultureIgnoreCase)) result = 0;
if (val.Equals("ic", StringComparison.CurrentCultureIgnoreCase)) result = 0;
}
if (!result.HasValue)
@ -243,11 +243,11 @@ namespace ENI2.Excel
string val = this.ReadText(lookup);
byte? result = null;
if(val != null)
if (val != null)
{
if ((val.IndexOf("load", StringComparison.OrdinalIgnoreCase) >= 0) || val.Equals("1")) result = 0;
if ((val.IndexOf("discharge", StringComparison.OrdinalIgnoreCase) >= 0) || val.Equals("2")) result = 1;
if ((val.IndexOf("transit", StringComparison.OrdinalIgnoreCase) >= 0) || val.Equals("3")) result = 2;
if ((val.IndexOf("transit", StringComparison.OrdinalIgnoreCase) >= 0) || val.Equals("3")) result = 2;
}
if (!result.HasValue)
@ -275,7 +275,7 @@ namespace ENI2.Excel
_log.ErrorFormat("Wrong ISO code {0}", val);
val = "";
}
}
}
}
return val;
}
@ -302,7 +302,7 @@ namespace ENI2.Excel
string val = this.ReadText(lookup);
byte? result = null;
if(val!= null)
if (val != null)
{
if (val == "I") result = 0;
if (val == "1") result = 0;
@ -310,7 +310,7 @@ namespace ENI2.Excel
if (val == "2") result = 1;
if (val == "III") result = 2;
if (val == "3") result = 2;
if (val.Equals("NONE", StringComparison.OrdinalIgnoreCase)) result = 0;
if (val.Equals("NONE", StringComparison.OrdinalIgnoreCase)) result = 0;
}
if (!result.HasValue)
@ -323,7 +323,7 @@ namespace ENI2.Excel
{
string val = this.ReadText(lookup);
bool isValid = false;
if(!val.IsNullOrEmpty())
if (!val.IsNullOrEmpty())
{
if (int.TryParse(val, out int typeVal))
{
@ -371,13 +371,13 @@ namespace ENI2.Excel
_log.ErrorFormat("cannot read delivery {0}", lookup);
return result;
}
}
internal byte? ReadHazards(string lookup)
{
string val = this.ReadText(lookup);
byte? result = null;
if(val != null)
if (val != null)
{
if (val.Equals("p", StringComparison.OrdinalIgnoreCase)) return 0;
if (val.Equals("s", StringComparison.OrdinalIgnoreCase)) return 1;
@ -390,7 +390,7 @@ namespace ENI2.Excel
{
string val = this.ReadText(lookup);
byte? result = null;
if(val != null)
if (val != null)
{
if (val.Equals("a", StringComparison.OrdinalIgnoreCase)) return 0;
if (val.Equals("b", StringComparison.OrdinalIgnoreCase)) return 1;
@ -401,8 +401,8 @@ namespace ENI2.Excel
internal DateTime? ReadBirthDate(string lookup)
{
DateTime? result = this.ReadDate(lookup);
if(result.HasValue)
DateTime? result = this.ReadDate(lookup);
if (result.HasValue)
{
if (result.Value > DateTime.Now)
_log.WarnFormat("Birth date implausible for {0} : {1}", lookup, result);
@ -430,7 +430,7 @@ namespace ENI2.Excel
date = DateTime.FromOADate(val);
}
catch (ArgumentException) { /* .. */ }
if(date == null)
if (date == null)
{
CultureInfo provider = CultureInfo.InvariantCulture;
string dateString = val.ToString();
@ -465,7 +465,7 @@ namespace ENI2.Excel
{
if ((date.Value < new DateTime(1899, 1, 1)) || (date.Value > new DateTime(2130, 1, 1)))
{
date = null; // this can't be right
date = null; // this can't be right
}
}
}
@ -485,26 +485,26 @@ namespace ENI2.Excel
DateTime? etaDate = this.ReadDate(dateField);
DateTime? etaTime = this.ReadTime(timeField);
if (etaDate != null)
{
{
if (etaTime != null)
{
result = new DateTime(etaDate.Value.Year, etaDate.Value.Month, etaDate.Value.Day, etaTime.Value.Hour, etaTime.Value.Minute, etaTime.Value.Second, DateTimeKind.Local);
result = result.Value.ToUniversalTime();
}
}
else
{
result = new DateTime(etaDate.Value.Year, etaDate.Value.Month, etaDate.Value.Day, 0, 0, 0, DateTimeKind.Local);
result = result.Value.ToUniversalTime();
}
}
return result;
}
internal DateTime? ReadTime(string lookup)
{
DateTime? result = null;
try
{
if (_nameDict.ContainsKey(lookup))
@ -520,7 +520,7 @@ namespace ENI2.Excel
{
result = DateTime.FromOADate(val);
}
catch(ArgumentException) { }
catch (ArgumentException) { }
if (result == null)
{
@ -535,7 +535,8 @@ namespace ENI2.Excel
}
}
if (val is string) {
if (val is string)
{
if (((string)val).EndsWith("lt", StringComparison.OrdinalIgnoreCase))
val = ((string)val).Substring(0, ((string)val).Length - 2).Trim();
else
@ -564,21 +565,21 @@ namespace ENI2.Excel
if (DateTime.TryParseExact(dateString, format, provider, DateTimeStyles.None, out DateTime tmpDate))
result = tmpDate;
}
}
}
}
}
catch (Exception)
{
_log.WarnFormat("error reading time for lookup {0}", lookup);
{
_log.WarnFormat("error reading time for lookup {0}", lookup);
}
return result;
}
}
internal double ReadNumberDefaultZero(string lookup)
{
double? result = this.ReadNumber(lookup);
if(!result.HasValue)
if (!result.HasValue)
{
result = 0;
}
@ -588,9 +589,9 @@ namespace ENI2.Excel
internal bool? ReadBoolean(string lookup)
{
string val = this.ReadText(lookup);
if (val == null)
if (val == null)
return null;
if ((val == "y") || (val == "Y") || val.Equals("yes", StringComparison.OrdinalIgnoreCase) || (val == "1") || (val == "x") || (val == "X"))
return true;
@ -599,17 +600,30 @@ namespace ENI2.Excel
#region Dakosy-specific functions
internal bool HasWorksheetNamed(string sheetName)
{
try
{
Worksheet theWorkSheet = _workBook.Worksheets[sheetName];
return theWorkSheet != null;
}
catch (Exception)
{
return false;
}
}
internal string ReadCellAsText(string sheetName, string range)
{
try
{
Worksheet workSheet = (Worksheet) _workBook.Worksheets[sheetName];
Worksheet workSheet = (Worksheet)_workBook.Worksheets[sheetName];
string result = workSheet.Range[range].Text.ToString();
if (!result.IsNullOrEmpty())
result = result.Trim().Clean();
return result;
}
catch(Exception e)
catch (Exception e)
{
_log.Warn(e.Message);
}
@ -642,7 +656,6 @@ namespace ENI2.Excel
Range aRange = workSheet.Range[range];
if (aRange != null)
{
}
}
catch (Exception e)
@ -713,12 +726,11 @@ namespace ENI2.Excel
return tmpDate2;
return null;
}
else
else
return null;
}
#endregion
#endregion Dakosy-specific functions
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -212,6 +212,7 @@ namespace ENI2
{
if(drc.HasCriticalInfoMissing(out string missingClass))
{
_log.WarnFormat("set close warning because at least {0} is missing from BRE/BRV arrival", missingClass);
if (MessageBox.Show(string.Format(Properties.Resources.textSpecialCaseBREBRV, missingClass), Properties.Resources.textConfirmation, MessageBoxButton.YesNo,
MessageBoxImage.Question, MessageBoxResult.No) == MessageBoxResult.No)
e.Cancel = true;

View File

@ -4552,7 +4552,7 @@ namespace ENI2.Properties {
}
/// <summary>
/// Looks up a localized string similar to One or more important classes haven&apos;t been sent for DEBRE/DEBRV: {0} Close anyway?.
/// Looks up a localized string similar to At least one of NOA_NOD, AGNT, INFO, SEC, TIEFA hasn&apos;t been sent for DEBRE/DEBRV: ({0}) Close anyway?.
/// </summary>
public static string textSpecialCaseBREBRV {
get {

View File

@ -1859,6 +1859,6 @@
<value>Search NST2007 list</value>
</data>
<data name="textSpecialCaseBREBRV" xml:space="preserve">
<value>One or more important classes haven't been sent for DEBRE/DEBRV: {0} Close anyway?</value>
<value>At least one of NOA_NOD, AGNT, INFO, SEC, TIEFA hasn't been sent for DEBRE/DEBRV: ({0}) Close anyway?</value>
</data>
</root>