Excel: changed 2 subtables of SEC and a subtable of MDH to Dakosy read mode

This commit is contained in:
Daniel Schick 2025-08-04 19:01:31 +02:00
parent 9ad543e705
commit 1df95d2807

View File

@ -1438,64 +1438,66 @@ namespace ENI2.Excel
}
else // "normal mode", aus den Zellen lesen
{
// POC last 30 days
for (int i = 0; i < mdh.NumberOfExcelRows; i++)
string sheetTitle = "1. VOYAGE";
// 4.8.25: Changed this area to work like reading from a Dakosy Sheet (by values in rows, not cell names)
if (reader.HasWorksheetNamed(sheetTitle))
{
string portName = string.Format("MDH.PortOfCallLast30DaysPort_{0}", i + 1);
string portCountry = string.Format("MDH.PortOfCallLast30DaysCountry_{0}", i + 1);
string locode = string.Format("MDH.PortOfCallLast30DaysLocode_{0}", i + 1);
string crewJoined = string.Format("MDH.PortOfCallLast30DaysCrewMembersJoined_{0}", i + 1);
string crewName = string.Format("MDH.PortOfCallLast30DaysCrewJoinedShipName_{0}", i + 1);
string depDate = string.Format("MDH.PortOfCallLast30DaysDateOfDeparture_{0}", i + 1);
if (!(mdh.GetSublistElementWithIdentifier((i + 1).ToString()) is PortOfCallLast30Days poc30d))
{
poc30d = new PortOfCallLast30Days();
poc30d.Identifier = (i + 1).ToString();
poc30d.MDH = mdh;
mdh.PortOfCallLast30Days.Add(poc30d);
}
// POC last 30 days
for (int i = 0; i < mdh.NumberOfExcelRows; i++)
{
string pName = reader.ReadText(portName);
string pCountry = reader.ReadText(portCountry);
poc30d.PortOfCallLast30DaysDateOfDeparture = reader.ReadDate(depDate);
poc30d.PortOfCallLast30DaysLocode = reader.ReadLoCode(locode);
// Verbesserungsvorschlag Jul/21: CrewMembersJoined Häkchen abhängig von den Namen in der Spalte
bool? PortOfCallLast30DaysCrewMembersJoinedFlag = reader.ReadBoolean(crewJoined);
string crewNameString = reader.ReadText(crewName);
poc30d.PortOfCallLast30DaysCrewMembersJoined = !crewNameString.IsNullOrEmpty();
// if crew members joined is set explicitly to true and the name is empty, still set the field to true
if (!(poc30d.PortOfCallLast30DaysCrewMembersJoined ?? false) && (PortOfCallLast30DaysCrewMembersJoinedFlag ?? false))
poc30d.PortOfCallLast30DaysCrewMembersJoined = true;
if (!crewNameString.IsNullOrEmpty() && (poc30d.PortOfCallLast30DaysCrewMembersJoined ?? false))
{
// try different separators
string[] crew = crewNameString.Split(';');
if (crew.Length == 1)
crew = crewNameString.Split(',');
for (int j = 0; j < crew.Length; j++)
if (!(mdh.GetSublistElementWithIdentifier((i + 1).ToString()) is PortOfCallLast30Days poc30d))
{
if (!(poc30d.GetSublistElementWithIdentifier((j + 1).ToString()) is PortOfCallLast30DaysCrewJoinedShip poc30dCrew))
{
poc30dCrew = new PortOfCallLast30DaysCrewJoinedShip();
poc30dCrew.Identifier = (j + 1).ToString();
poc30dCrew.PortOfCallLast30Days = poc30d;
poc30d.CrewJoinedShip.Add(poc30dCrew);
}
poc30dCrew.PortOfCallLast30DaysCrewJoinedShipName = crew[j];
poc30d = new PortOfCallLast30Days();
poc30d.Identifier = (i + 1).ToString();
poc30d.MDH = mdh;
mdh.PortOfCallLast30Days.Add(poc30d);
}
}
// Leer/def. Zeilen entfernen
if (!poc30d.PortOfCallLast30DaysDateOfDeparture.HasValue && (poc30d.PortOfCallLast30DaysLocode == null))
mdh.PortOfCallLast30Days.Remove(poc30d);
string pName = reader.ReadCellAsText(sheetTitle, string.Format("C{0}", 81 + i));
string pCountry = reader.ReadCellAsText(sheetTitle, string.Format("E{0}", 81 + i));
poc30d.PortOfCallLast30DaysDateOfDeparture = reader.ReadCellAsDateTime(sheetTitle, string.Format("G{0}", 81 + i));
poc30d.PortOfCallLast30DaysLocode = reader.ReadCellAsText(sheetTitle, string.Format("F{0}", 81 + i));
if (LocodeDB.PortNameFromLocode(poc30d.PortOfCallLast30DaysLocode).IsNullOrEmpty()) poc30d.PortOfCallLast30DaysLocode = "";
// Verbesserungsvorschlag Jul/21: CrewMembersJoined Häkchen abhängig von den Namen in der Spalte
bool? PortOfCallLast30DaysCrewMembersJoinedFlag = reader.ReadCellAsBool(sheetTitle, string.Format("H{0}", 81 + i));
string crewNameString = reader.ReadCellAsText(sheetTitle, string.Format("I{0}", 81 + i));
poc30d.PortOfCallLast30DaysCrewMembersJoined = !crewNameString.IsNullOrEmpty();
// if crew members joined is set explicitly to true and the name is empty, still set the field to true
if (!(poc30d.PortOfCallLast30DaysCrewMembersJoined ?? false) && (PortOfCallLast30DaysCrewMembersJoinedFlag ?? false))
poc30d.PortOfCallLast30DaysCrewMembersJoined = true;
if (!crewNameString.IsNullOrEmpty() && (poc30d.PortOfCallLast30DaysCrewMembersJoined ?? false))
{
// try different separators
string[] crew = crewNameString.Split(';');
if (crew.Length == 1)
crew = crewNameString.Split(',');
for (int j = 0; j < crew.Length; j++)
{
if (!(poc30d.GetSublistElementWithIdentifier((j + 1).ToString()) is PortOfCallLast30DaysCrewJoinedShip poc30dCrew))
{
poc30dCrew = new PortOfCallLast30DaysCrewJoinedShip();
poc30dCrew.Identifier = (j + 1).ToString();
poc30dCrew.PortOfCallLast30Days = poc30d;
poc30d.CrewJoinedShip.Add(poc30dCrew);
}
poc30dCrew.PortOfCallLast30DaysCrewJoinedShipName = crew[j];
}
}
// Leer/def. Zeilen entfernen
if (!poc30d.PortOfCallLast30DaysDateOfDeparture.HasValue && (poc30d.PortOfCallLast30DaysLocode == null))
mdh.PortOfCallLast30Days.Remove(poc30d);
}
}
}
@ -1658,97 +1660,87 @@ namespace ENI2.Excel
if (!sec.KielCanalPassagePlannedIncomming.HasValue && !sec.KielCanalPassagePlannedOutgoing.HasValue)
sec.KielCanalPassagePlanned = false;
// Last10PortFacilitesCalled
for (int i = 1; i <= 10; i++)
{
string portName = string.Format("SEC.PortFacilityPortName_{0}", i);
string portCountry = string.Format("SEC.PortFacilityPortCountry_{0}", i);
string portLocode = string.Format("SEC.PortFacilityPortLoCode_{0}", i);
string portDateOfArrival = string.Format("SEC.PortFacilityDateOfArrival_{0}", i);
string portDateOfDeparture = string.Format("SEC.PortFacilityDateOfDeparture_{0}", i);
string portShipSecLevel = string.Format("SEC.PortFacilityShipSecurityLevel_{0}", i);
string portGISISCode = string.Format("SEC.PortFacilityGISISCode_{0}", i);
string portSecMatters = string.Format("SEC.PortFacilitySecurityMattersToReport_{0}", i);
string sheetTitle = "1. VOYAGE";
// 4.8.25: Changed this area to work like reading from a Dakosy Sheet (by values in rows, not cell names)
if (reader.HasWorksheetNamed(sheetTitle))
{
// Last10PortFacilitesCalled
for (int i = 0; i < 10; i++)
{
if (!(sec.GetPortFacilityWithIdentifier(i.ToString()) is LastTenPortFacilitiesCalled l10fc))
{
l10fc = new LastTenPortFacilitiesCalled();
l10fc.Identifier = i.ToString();
l10fc.SEC = sec;
sec.LastTenPortFacilitesCalled.Add(l10fc);
if (!(sec.GetPortFacilityWithIdentifier(i.ToString()) is LastTenPortFacilitiesCalled l10fc))
{
l10fc = new LastTenPortFacilitiesCalled();
l10fc.Identifier = i.ToString();
l10fc.SEC = sec;
sec.LastTenPortFacilitesCalled.Add(l10fc);
}
l10fc.PortFacilityPortName = reader.ReadCellAsText(sheetTitle, string.Format("C{0}", 54 + i), 99);
l10fc.PortFacilityPortCountry = reader.ReadCellAsText(sheetTitle, string.Format("E{0}", 54 + i), 99);
l10fc.PortFacilityPortLoCode = reader.ReadCellAsText(sheetTitle, string.Format("F{0}", 54 + i), 5);
if (LocodeDB.PortNameFromLocode(l10fc.PortFacilityPortLoCode).IsNullOrEmpty()) l10fc.PortFacilityPortLoCode = "";
l10fc.PortFacilityDateOfArrival = reader.ReadCellAsDateTime(sheetTitle, string.Format("G{0}", 54 + i));
l10fc.PortFacilityDateOfDeparture = reader.ReadCellAsDateTime(sheetTitle, string.Format("H{0}", 54 + i));
string sLevel = reader.ReadCellAsText(sheetTitle, string.Format("I{0}", 54 + i), 1);
if (!sLevel.IsNullOrEmpty())
{
if (sLevel.Contains('1')) l10fc.PortFacilityShipSecurityLevel = 1;
if (sLevel.Contains('2')) l10fc.PortFacilityShipSecurityLevel = 2;
if (sLevel.Contains('3')) l10fc.PortFacilityShipSecurityLevel = 3;
}
l10fc.PortFacilityGISISCode = reader.ReadCellAsText(sheetTitle, string.Format("J{0}", 54 + i), 4);
if (l10fc.PortFacilityGISISCode.IsNullOrEmpty() || l10fc.PortFacilityGISISCode == "0")
l10fc.PortFacilityGISISCode = "0000";
if (l10fc.PortFacilityGISISCode?.Length < 4)
{
while (l10fc.PortFacilityGISISCode.Length < 4) l10fc.PortFacilityGISISCode = "0" + l10fc.PortFacilityGISISCode;
}
l10fc.PortFacilitySecurityMattersToReport = reader.ReadCellAsText(sheetTitle, string.Format("K{0}", 54 + i), 255);
// keinen "leeren" Hafen anlegen, wenn der Eintrag leer war (trifft anscheinend bei Neubauten zu, siehe E-Mail Christin vom 20./22.6.17
if (l10fc.PortFacilityPortName.IsNullOrEmpty() && l10fc.PortFacilityPortLoCode.IsNullOrEmpty() && l10fc.PortFacilityPortCountry.IsNullOrEmpty())
sec.LastTenPortFacilitesCalled.Remove(l10fc);
}
l10fc.PortFacilityPortName = reader.ReadText(portName);
l10fc.PortFacilityPortCountry = reader.ReadText(portCountry);
l10fc.PortFacilityPortLoCode = reader.ReadLoCode(portLocode);
l10fc.PortFacilityDateOfArrival = reader.ReadDate(portDateOfArrival);
l10fc.PortFacilityDateOfDeparture = reader.ReadDate(portDateOfDeparture);
// Ship2ShipActivities
for (int i = 0; i < 10; i++)
{
string sLevel = reader.ReadText(portShipSecLevel);
if (!sLevel.IsNullOrEmpty())
{
if (sLevel.Contains('1')) l10fc.PortFacilityShipSecurityLevel = 1;
if (sLevel.Contains('2')) l10fc.PortFacilityShipSecurityLevel = 2;
if (sLevel.Contains('3')) l10fc.PortFacilityShipSecurityLevel = 3;
if (!(sec.GetShipToShipWithIdentifier(i.ToString()) is ShipToShipActivitiesDuringLastTenPortFacilitiesCalled s2sActivity))
{
s2sActivity = new ShipToShipActivitiesDuringLastTenPortFacilitiesCalled();
s2sActivity.Identifier = i.ToString();
s2sActivity.SEC = sec;
sec.ShipToShipActivitiesDuringLastTenPortFacilitiesCalled.Add(s2sActivity);
}
s2sActivity.ShipToShipActivityLocationName = reader.ReadCellAsText(sheetTitle, string.Format("C{0}", 68 + i), 255);
if (s2sActivity.ShipToShipActivityLocationName.IsNullOrEmpty())
{
sec.ShipToShipActivitiesDuringLastTenPortFacilitiesCalled.Remove(s2sActivity);
continue;
}
s2sActivity.ShipToShipActivityLocationLoCode = reader.ReadCellAsText(sheetTitle, string.Format("E{0}", 68 + i), 5);
if (LocodeDB.PortNameFromLocode(s2sActivity.ShipToShipActivityLocationLoCode).IsNullOrEmpty()) s2sActivity.ShipToShipActivityLocationLoCode = "";
s2sActivity.ShipToShipActivityLocationCoordinatesLatitude = (int?) reader.ReadCellAsDecimal(sheetTitle, string.Format("F{0}", 68 + i));
// keine "0" (d.h. fehlerhafte Koordinaten) ins ANSW übergeben falls im Sheet nichts ist aber der Reader das aus irgendeinem Grund liest
if (s2sActivity.ShipToShipActivityLocationCoordinatesLatitude == 0)
s2sActivity.ShipToShipActivityLocationCoordinatesLatitude = null;
s2sActivity.ShipToShipActivityLocationCoordinatesLongitude = (int?)reader.ReadCellAsDecimal(sheetTitle, string.Format("G{0}", 68 + i));
if (s2sActivity.ShipToShipActivityLocationCoordinatesLongitude == 0)
s2sActivity.ShipToShipActivityLocationCoordinatesLongitude = null;
s2sActivity.ShipToShipActivityDateFrom = reader.ReadCellAsDateTime(sheetTitle, string.Format("H{0}", 68 + i));
s2sActivity.ShipToShipActivityDateTo = reader.ReadCellAsDateTime(sheetTitle, string.Format("I{0}", 68 + i));
s2sActivity.ShipToShipActivityTypeCode = (int?)reader.ReadCellAsDecimal(sheetTitle, string.Format("J{0}", 68 + i));
s2sActivity.ShipToShipActivitySecurityMattersToReport = reader.ReadCellAsText(sheetTitle, string.Format("K{0}", 68 + i), 255);
}
l10fc.PortFacilityGISISCode = reader.ReadTextNoWhitespace(portGISISCode);
if (l10fc.PortFacilityGISISCode.IsNullOrEmpty() || l10fc.PortFacilityGISISCode == "0")
l10fc.PortFacilityGISISCode = "0000";
if (l10fc.PortFacilityGISISCode?.Length < 4)
{
while (l10fc.PortFacilityGISISCode.Length < 4) l10fc.PortFacilityGISISCode = "0" + l10fc.PortFacilityGISISCode;
}
l10fc.PortFacilitySecurityMattersToReport = reader.ReadText(portSecMatters);
// keinen "leeren" Hafen anlegen, wenn der Eintrag leer war (trifft anscheinend bei Neubauten zu, siehe E-Mail Christin vom 20./22.6.17
if (l10fc.PortFacilityPortName.IsNullOrEmpty() && l10fc.PortFacilityPortLoCode.IsNullOrEmpty() && l10fc.PortFacilityPortCountry.IsNullOrEmpty())
sec.LastTenPortFacilitesCalled.Remove(l10fc);
}
// Ship2ShipActivities
for (int i = 1; i <= 10; i++)
{
string s2sName = string.Format("SEC.ShipToShipActivityLocationName_{0}", i);
string s2sLocode = string.Format("SEC.ShipToShipActivityLocationLoCode_{0}", i);
string s2sLatitude = string.Format("SEC.ShipToShipActivityLocationCoordinatesLatitude_{0}", i);
string s2sLongitude = string.Format("SEC.ShipToShipActivityLocationCoordinatesLongitude_{0}", i);
string s2sFromDate = string.Format("SEC.ShipToShipActivityDateFrom_{0}", i);
string s2sToDate = string.Format("SEC.ShipToShipActivityDateTo_{0}", i);
string s2sSec = string.Format("SEC.ShipToShipActivitySecurityMattersToReport_{0}", i);
string s2sActivityString = string.Format("SEC.ShipToShipActivityType_{0}", i);
if (!(sec.GetShipToShipWithIdentifier(i.ToString()) is ShipToShipActivitiesDuringLastTenPortFacilitiesCalled s2sActivity))
{
s2sActivity = new ShipToShipActivitiesDuringLastTenPortFacilitiesCalled();
s2sActivity.Identifier = i.ToString();
s2sActivity.SEC = sec;
sec.ShipToShipActivitiesDuringLastTenPortFacilitiesCalled.Add(s2sActivity);
}
s2sActivity.ShipToShipActivityLocationName = reader.ReadText(s2sName);
if (s2sActivity.ShipToShipActivityLocationName.IsNullOrEmpty())
{
sec.ShipToShipActivitiesDuringLastTenPortFacilitiesCalled.Remove(s2sActivity);
continue;
}
s2sActivity.ShipToShipActivityLocationLoCode = reader.ReadLoCode(s2sLocode);
s2sActivity.ShipToShipActivityLocationCoordinatesLatitude = (int?)reader.ReadNumber(s2sLatitude);
// keine "0" (d.h. fehlerhafte Koordinaten) ins ANSW übergeben falls im Sheet nichts ist aber der Reader das aus irgendeinem Grund liest
if (s2sActivity.ShipToShipActivityLocationCoordinatesLatitude == 0)
s2sActivity.ShipToShipActivityLocationCoordinatesLatitude = null;
s2sActivity.ShipToShipActivityLocationCoordinatesLongitude = (int?)reader.ReadNumber(s2sLongitude);
if (s2sActivity.ShipToShipActivityLocationCoordinatesLongitude == 0)
s2sActivity.ShipToShipActivityLocationCoordinatesLongitude = null;
s2sActivity.ShipToShipActivityDateFrom = reader.ReadDate(s2sFromDate);
s2sActivity.ShipToShipActivityDateTo = reader.ReadDate(s2sToDate);
s2sActivity.ShipToShipActivityTypeCode = (int?)reader.ReadNumber(s2sActivityString);
reader.ReadShip2ShipActivityType(s2sActivityString); // 24.8.21 nicht Code dem Klartext zuordnen, nur das Feld kolorieren
s2sActivity.ShipToShipActivitySecurityMattersToReport = reader.ReadText(s2sSec);
}
return true;