Korrekturen lt Rückmeldung
This commit is contained in:
parent
a0bcbe4ccf
commit
5118ed8aaf
@ -7,27 +7,25 @@
|
|||||||
//
|
//
|
||||||
// Copyright (c) 2015 Informatikbüro Daniel Schick. All rights reserved.
|
// Copyright (c) 2015 Informatikbüro Daniel Schick. All rights reserved.
|
||||||
|
|
||||||
using log4net;
|
using bsmd.database;
|
||||||
|
using ENI2.Locode;
|
||||||
using Microsoft.Office.Interop.Excel;
|
using Microsoft.Office.Interop.Excel;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Data;
|
using System.Data;
|
||||||
|
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using ENI2.Locode;
|
|
||||||
using bsmd.database;
|
|
||||||
using System.Text.RegularExpressions;
|
|
||||||
|
|
||||||
namespace ENI2.Excel
|
namespace ENI2.Excel
|
||||||
{
|
{
|
||||||
internal class ExcelReader : ExcelBase
|
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;
|
private readonly SheetTypeEnum _sheetType = SheetTypeEnum.BSMD;
|
||||||
|
|
||||||
@ -36,15 +34,16 @@ namespace ENI2.Excel
|
|||||||
public ExcelReader(string filePath, bool openReadonly = true, bool createNameFields = true)
|
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);
|
this._workBook = _excelWorkbooks.Open(filePath, 0, openReadonly, 5, "", "", false, XlPlatform.xlWindows, "", false, false, 0, false, false, false);
|
||||||
if(createNameFields)
|
if (createNameFields)
|
||||||
this.InitNameFields();
|
this.InitNameFields();
|
||||||
|
|
||||||
// Determine if this is a Dakosy or BSMD Sheet
|
// Determine if this is a Dakosy or BSMD Sheet
|
||||||
if(createNameFields)
|
if (createNameFields)
|
||||||
_sheetType = (_nameDict.Count > 10) ? SheetTypeEnum.BSMD : SheetTypeEnum.DAKOSY;
|
_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)
|
internal static void SaveMessage(Message message)
|
||||||
{
|
{
|
||||||
@ -80,7 +79,7 @@ namespace ENI2.Excel
|
|||||||
if (result != null)
|
if (result != null)
|
||||||
{
|
{
|
||||||
result = result.Trim();
|
result = result.Trim();
|
||||||
if(result.Length > 0)
|
if (result.Length > 0)
|
||||||
{
|
{
|
||||||
result = result.Clean();
|
result = result.Clean();
|
||||||
}
|
}
|
||||||
@ -135,7 +134,7 @@ namespace ENI2.Excel
|
|||||||
string val = ReadText(lookup);
|
string val = ReadText(lookup);
|
||||||
if (val.IsNullOrEmpty()) return null;
|
if (val.IsNullOrEmpty()) return null;
|
||||||
|
|
||||||
if(int.TryParse(val, out int result))
|
if (int.TryParse(val, out int result))
|
||||||
{
|
{
|
||||||
if ((result < 10) || (result > 99))
|
if ((result < 10) || (result > 99))
|
||||||
_log.WarnFormat("invalid cargo LA code {0}", result);
|
_log.WarnFormat("invalid cargo LA code {0}", result);
|
||||||
@ -154,7 +153,8 @@ namespace ENI2.Excel
|
|||||||
string val = this.ReadText(lookup);
|
string val = this.ReadText(lookup);
|
||||||
if (val != null)
|
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;
|
result = 1;
|
||||||
}
|
}
|
||||||
else if (val.Equals("f", StringComparison.CurrentCultureIgnoreCase) || val.Equals("female", StringComparison.CurrentCultureIgnoreCase))
|
else if (val.Equals("f", StringComparison.CurrentCultureIgnoreCase) || val.Equals("female", StringComparison.CurrentCultureIgnoreCase))
|
||||||
@ -173,7 +173,7 @@ namespace ENI2.Excel
|
|||||||
result = 0;
|
result = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(result == null)
|
if (result == null)
|
||||||
{
|
{
|
||||||
_log.ErrorFormat("error reading gender on {0}", lookup);
|
_log.ErrorFormat("error reading gender on {0}", lookup);
|
||||||
}
|
}
|
||||||
@ -243,7 +243,7 @@ namespace ENI2.Excel
|
|||||||
string val = this.ReadText(lookup);
|
string val = this.ReadText(lookup);
|
||||||
byte? result = null;
|
byte? result = null;
|
||||||
|
|
||||||
if(val != null)
|
if (val != null)
|
||||||
{
|
{
|
||||||
if ((val.IndexOf("load", StringComparison.OrdinalIgnoreCase) >= 0) || val.Equals("1")) result = 0;
|
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("discharge", StringComparison.OrdinalIgnoreCase) >= 0) || val.Equals("2")) result = 1;
|
||||||
@ -302,7 +302,7 @@ namespace ENI2.Excel
|
|||||||
string val = this.ReadText(lookup);
|
string val = this.ReadText(lookup);
|
||||||
byte? result = null;
|
byte? result = null;
|
||||||
|
|
||||||
if(val!= null)
|
if (val != null)
|
||||||
{
|
{
|
||||||
if (val == "I") result = 0;
|
if (val == "I") result = 0;
|
||||||
if (val == "1") result = 0;
|
if (val == "1") result = 0;
|
||||||
@ -323,7 +323,7 @@ namespace ENI2.Excel
|
|||||||
{
|
{
|
||||||
string val = this.ReadText(lookup);
|
string val = this.ReadText(lookup);
|
||||||
bool isValid = false;
|
bool isValid = false;
|
||||||
if(!val.IsNullOrEmpty())
|
if (!val.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
if (int.TryParse(val, out int typeVal))
|
if (int.TryParse(val, out int typeVal))
|
||||||
{
|
{
|
||||||
@ -377,7 +377,7 @@ namespace ENI2.Excel
|
|||||||
{
|
{
|
||||||
string val = this.ReadText(lookup);
|
string val = this.ReadText(lookup);
|
||||||
byte? result = null;
|
byte? result = null;
|
||||||
if(val != null)
|
if (val != null)
|
||||||
{
|
{
|
||||||
if (val.Equals("p", StringComparison.OrdinalIgnoreCase)) return 0;
|
if (val.Equals("p", StringComparison.OrdinalIgnoreCase)) return 0;
|
||||||
if (val.Equals("s", StringComparison.OrdinalIgnoreCase)) return 1;
|
if (val.Equals("s", StringComparison.OrdinalIgnoreCase)) return 1;
|
||||||
@ -390,7 +390,7 @@ namespace ENI2.Excel
|
|||||||
{
|
{
|
||||||
string val = this.ReadText(lookup);
|
string val = this.ReadText(lookup);
|
||||||
byte? result = null;
|
byte? result = null;
|
||||||
if(val != null)
|
if (val != null)
|
||||||
{
|
{
|
||||||
if (val.Equals("a", StringComparison.OrdinalIgnoreCase)) return 0;
|
if (val.Equals("a", StringComparison.OrdinalIgnoreCase)) return 0;
|
||||||
if (val.Equals("b", StringComparison.OrdinalIgnoreCase)) return 1;
|
if (val.Equals("b", StringComparison.OrdinalIgnoreCase)) return 1;
|
||||||
@ -402,7 +402,7 @@ namespace ENI2.Excel
|
|||||||
internal DateTime? ReadBirthDate(string lookup)
|
internal DateTime? ReadBirthDate(string lookup)
|
||||||
{
|
{
|
||||||
DateTime? result = this.ReadDate(lookup);
|
DateTime? result = this.ReadDate(lookup);
|
||||||
if(result.HasValue)
|
if (result.HasValue)
|
||||||
{
|
{
|
||||||
if (result.Value > DateTime.Now)
|
if (result.Value > DateTime.Now)
|
||||||
_log.WarnFormat("Birth date implausible for {0} : {1}", lookup, result);
|
_log.WarnFormat("Birth date implausible for {0} : {1}", lookup, result);
|
||||||
@ -430,7 +430,7 @@ namespace ENI2.Excel
|
|||||||
date = DateTime.FromOADate(val);
|
date = DateTime.FromOADate(val);
|
||||||
}
|
}
|
||||||
catch (ArgumentException) { /* .. */ }
|
catch (ArgumentException) { /* .. */ }
|
||||||
if(date == null)
|
if (date == null)
|
||||||
{
|
{
|
||||||
CultureInfo provider = CultureInfo.InvariantCulture;
|
CultureInfo provider = CultureInfo.InvariantCulture;
|
||||||
string dateString = val.ToString();
|
string dateString = val.ToString();
|
||||||
@ -520,7 +520,7 @@ namespace ENI2.Excel
|
|||||||
{
|
{
|
||||||
result = DateTime.FromOADate(val);
|
result = DateTime.FromOADate(val);
|
||||||
}
|
}
|
||||||
catch(ArgumentException) { }
|
catch (ArgumentException) { }
|
||||||
|
|
||||||
if (result == null)
|
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))
|
if (((string)val).EndsWith("lt", StringComparison.OrdinalIgnoreCase))
|
||||||
val = ((string)val).Substring(0, ((string)val).Length - 2).Trim();
|
val = ((string)val).Substring(0, ((string)val).Length - 2).Trim();
|
||||||
else
|
else
|
||||||
@ -578,7 +579,7 @@ namespace ENI2.Excel
|
|||||||
internal double ReadNumberDefaultZero(string lookup)
|
internal double ReadNumberDefaultZero(string lookup)
|
||||||
{
|
{
|
||||||
double? result = this.ReadNumber(lookup);
|
double? result = this.ReadNumber(lookup);
|
||||||
if(!result.HasValue)
|
if (!result.HasValue)
|
||||||
{
|
{
|
||||||
result = 0;
|
result = 0;
|
||||||
}
|
}
|
||||||
@ -599,17 +600,30 @@ namespace ENI2.Excel
|
|||||||
|
|
||||||
#region Dakosy-specific functions
|
#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)
|
internal string ReadCellAsText(string sheetName, string range)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Worksheet workSheet = (Worksheet) _workBook.Worksheets[sheetName];
|
Worksheet workSheet = (Worksheet)_workBook.Worksheets[sheetName];
|
||||||
string result = workSheet.Range[range].Text.ToString();
|
string result = workSheet.Range[range].Text.ToString();
|
||||||
if (!result.IsNullOrEmpty())
|
if (!result.IsNullOrEmpty())
|
||||||
result = result.Trim().Clean();
|
result = result.Trim().Clean();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
catch(Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
_log.Warn(e.Message);
|
_log.Warn(e.Message);
|
||||||
}
|
}
|
||||||
@ -642,7 +656,6 @@ namespace ENI2.Excel
|
|||||||
Range aRange = workSheet.Range[range];
|
Range aRange = workSheet.Range[range];
|
||||||
if (aRange != null)
|
if (aRange != null)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
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
@ -212,6 +212,7 @@ namespace ENI2
|
|||||||
{
|
{
|
||||||
if(drc.HasCriticalInfoMissing(out string missingClass))
|
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,
|
if (MessageBox.Show(string.Format(Properties.Resources.textSpecialCaseBREBRV, missingClass), Properties.Resources.textConfirmation, MessageBoxButton.YesNo,
|
||||||
MessageBoxImage.Question, MessageBoxResult.No) == MessageBoxResult.No)
|
MessageBoxImage.Question, MessageBoxResult.No) == MessageBoxResult.No)
|
||||||
e.Cancel = true;
|
e.Cancel = true;
|
||||||
|
|||||||
2
ENI2/Properties/Resources.Designer.cs
generated
2
ENI2/Properties/Resources.Designer.cs
generated
@ -4552,7 +4552,7 @@ namespace ENI2.Properties {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Looks up a localized string similar to One or more important classes haven'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't been sent for DEBRE/DEBRV: ({0}) Close anyway?.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static string textSpecialCaseBREBRV {
|
public static string textSpecialCaseBREBRV {
|
||||||
get {
|
get {
|
||||||
|
|||||||
@ -1859,6 +1859,6 @@
|
|||||||
<value>Search NST2007 list</value>
|
<value>Search NST2007 list</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="textSpecialCaseBREBRV" xml:space="preserve">
|
<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>
|
</data>
|
||||||
</root>
|
</root>
|
||||||
Loading…
Reference in New Issue
Block a user