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

@ -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();
}
@ -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,7 +153,8 @@ 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))
@ -173,7 +173,7 @@ namespace ENI2.Excel
result = 0;
}
}
if(result == null)
if (result == null)
{
_log.ErrorFormat("error reading gender on {0}", lookup);
}
@ -243,7 +243,7 @@ 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;
@ -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;
@ -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))
{
@ -377,7 +377,7 @@ namespace ENI2.Excel
{
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;
@ -402,7 +402,7 @@ namespace ENI2.Excel
internal DateTime? ReadBirthDate(string lookup)
{
DateTime? result = this.ReadDate(lookup);
if(result.HasValue)
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();
@ -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
@ -578,7 +579,7 @@ namespace ENI2.Excel
internal double ReadNumberDefaultZero(string lookup)
{
double? result = this.ReadNumber(lookup);
if(!result.HasValue)
if (!result.HasValue)
{
result = 0;
}
@ -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)
@ -718,7 +731,6 @@ namespace ENI2.Excel
}
#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>