From 4cf91200df0d417072eb24d882d89958d42eb788 Mon Sep 17 00:00:00 2001 From: Daniel Schick Date: Wed, 2 Mar 2022 10:30:23 +0100 Subject: [PATCH] Fehlerkorrekturen bei WAS und INFO --- ENI2/DetailRootControl.xaml.cs | 68 ++++++++------- .../WasteDetailControl.xaml.cs | 84 ++++++++++--------- ENI2/Excel/ExcelWriter.cs | 7 +- bsmd.database/DBManager.cs | 2 +- bsmd.database/Util.cs | 4 +- bsmd.database/WAS.cs | 8 ++ bsmd.database/Waste.cs | 65 ++++---------- 7 files changed, 115 insertions(+), 123 deletions(-) diff --git a/ENI2/DetailRootControl.xaml.cs b/ENI2/DetailRootControl.xaml.cs index 2f0ffe98..a96c79ef 100644 --- a/ENI2/DetailRootControl.xaml.cs +++ b/ENI2/DetailRootControl.xaml.cs @@ -745,25 +745,28 @@ namespace ENI2 } } - if (crewdMessage.Elements.Count > 0) + if (crewdMessage != null) { - CREWD crewdFirst = crewdMessage.Elements[0] as CREWD; - bool crewdIsSchengen = crewdFirst.NotificationSchengen ?? false; - if (!((crewdFirst.NotificationPAX ?? false) || crewdIsSchengen)) // mindestens eins der beiden + if (crewdMessage.Elements.Count > 0) { - MessageViolation mv = RuleEngine.CreateViolation(ValidationCode.V181, "Wrong selection", null, "CREWD", null, "CREWD"); - mv.MessageGroupName = Properties.Resources.textOverview; - vViolations.Add(mv); - } - - foreach (CREWD crewd in crewdMessage.Elements) - { - if (crewdIsSchengen && !crewd.HasSchengenDetails) + CREWD crewdFirst = crewdMessage.Elements[0] as CREWD; + bool crewdIsSchengen = crewdFirst.NotificationSchengen ?? false; + if (!((crewdFirst.NotificationPAX ?? false) || crewdIsSchengen)) // mindestens eins der beiden { - MessageViolation mv = RuleEngine.CreateViolation(ValidationCode.V182, "No Schengen details", null, "CREWD", crewd.Identifier, "CREWD"); + MessageViolation mv = RuleEngine.CreateViolation(ValidationCode.V181, "Wrong selection", null, "CREWD", null, "CREWD"); mv.MessageGroupName = Properties.Resources.textOverview; vViolations.Add(mv); } + + foreach (CREWD crewd in crewdMessage.Elements) + { + if (crewdIsSchengen && !crewd.HasSchengenDetails) + { + MessageViolation mv = RuleEngine.CreateViolation(ValidationCode.V182, "No Schengen details", null, "CREWD", crewd.Identifier, "CREWD"); + mv.MessageGroupName = Properties.Resources.textOverview; + vViolations.Add(mv); + } + } } } @@ -796,31 +799,34 @@ namespace ENI2 } } - if (pasdMessage.Elements.Count > 0) + if (pasdMessage != null) { - PASD pasdFirst = pasdMessage.Elements[0] as PASD; - bool pasdIsSchengen = pasdFirst.NotificationSchengen ?? false; - bool pasdIsPAX = pasdFirst.NotificationPAX ?? false; - if (!(pasdIsPAX || pasdIsSchengen)) // mindestens eins der beiden + if (pasdMessage.Elements.Count > 0) { - MessageViolation mv = RuleEngine.CreateViolation(ValidationCode.V201, "Wrong selection", null, "PASD", null, "PASD"); - mv.MessageGroupName = Properties.Resources.textOverview; - vViolations.Add(mv); - } - - foreach (PASD pasd in pasdMessage.Elements) - { - if (pasdIsSchengen && !pasd.HasSchengenDetails) + PASD pasdFirst = pasdMessage.Elements[0] as PASD; + bool pasdIsSchengen = pasdFirst.NotificationSchengen ?? false; + bool pasdIsPAX = pasdFirst.NotificationPAX ?? false; + if (!(pasdIsPAX || pasdIsSchengen)) // mindestens eins der beiden { - MessageViolation mv = RuleEngine.CreateViolation(ValidationCode.V202, "No Schengen details", null, "PASD", pasd.Identifier, "PASD"); + MessageViolation mv = RuleEngine.CreateViolation(ValidationCode.V201, "Wrong selection", null, "PASD", null, "PASD"); mv.MessageGroupName = Properties.Resources.textOverview; vViolations.Add(mv); } - if (pasdIsPAX && !pasd.HasPAXDetails) + + foreach (PASD pasd in pasdMessage.Elements) { - MessageViolation mv = RuleEngine.CreateViolation(ValidationCode.V203, "No PAX details", null, "PASD", pasd.Identifier, "PASD"); - mv.MessageGroupName = Properties.Resources.textOverview; - vViolations.Add(mv); + if (pasdIsSchengen && !pasd.HasSchengenDetails) + { + MessageViolation mv = RuleEngine.CreateViolation(ValidationCode.V202, "No Schengen details", null, "PASD", pasd.Identifier, "PASD"); + mv.MessageGroupName = Properties.Resources.textOverview; + vViolations.Add(mv); + } + if (pasdIsPAX && !pasd.HasPAXDetails) + { + MessageViolation mv = RuleEngine.CreateViolation(ValidationCode.V203, "No PAX details", null, "PASD", pasd.Identifier, "PASD"); + mv.MessageGroupName = Properties.Resources.textOverview; + vViolations.Add(mv); + } } } } diff --git a/ENI2/DetailViewControls/WasteDetailControl.xaml.cs b/ENI2/DetailViewControls/WasteDetailControl.xaml.cs index 803d53a1..75d5cf38 100644 --- a/ENI2/DetailViewControls/WasteDetailControl.xaml.cs +++ b/ENI2/DetailViewControls/WasteDetailControl.xaml.cs @@ -466,54 +466,62 @@ namespace ENI2.DetailViewControls { do { - // skip first two rows + // skip first three rows + reader.Read(); reader.Read(); reader.Read(); int cnt = 0; object o = null; - while (reader.Read() && (cnt < 15)) - { - if (((IExcelDataReader)reader).FieldCount < 10) - { - throw new InvalidDataException("Sheet must have 10 Columns of data"); - } - Waste waste = new Waste(); + // Diese Funktion kann das "alte" Sheet Format nicht mehr einlesen! + while (reader.Read() && (cnt < 35)) + { + if (reader.FieldCount < 9) + { + throw new InvalidDataException("Sheet must have 9 Columns of data"); + } if (!reader.IsDBNull(1)) o = reader.GetValue(1); else o = null; - if (o != null) + if ((o != null) && Int32.TryParse(o.ToString(), out int wasteType)) { - waste.WasteType = Convert.ToInt32(o); - if (waste.WasteType == 2313) waste.WasteType = 2600; + Waste waste = _was.GetWasteForType(wasteType); + if (waste == null) + { + waste = new Waste(); + waste.WasteType = wasteType; + waste.WAS = this._was; + waste.IsDirty = true; + waste.Identifier = Waste.GetNewIdentifier(this._was.Waste); + this._was.Waste.Add(waste); + } + else + { + waste.IsDirty = true; + } + + if (!reader.IsDBNull(4)) waste.WasteDescription = reader.GetString(4); + if (waste.WasteDescription.IsNullOrEmpty()) + waste.WasteDescription = "-"; + + if (!reader.IsDBNull(5)) o = reader.GetValue(5); else o = null; + if (o != null) waste.WasteDisposalAmount_MTQ = Convert.ToDouble(o); + + if (!reader.IsDBNull(6)) o = reader.GetValue(6); else o = null; + if (o != null) waste.WasteCapacity_MTQ = Convert.ToDouble(o); + + if (!reader.IsDBNull(7)) o = reader.GetValue(7); else o = null; + if (o != null) waste.WasteAmountRetained_MTQ = Convert.ToDouble(o); + + if (!reader.IsDBNull(8)) waste.WasteDisposalPort = reader.GetString(8); + + if (!reader.IsDBNull(9)) o = reader.GetValue(9); else o = null; + if (o != null) waste.WasteAmountGeneratedTillNextPort_MTQ = Convert.ToDouble(o); + + importWasteList.Add(waste); + cnt++; } - - if (!reader.IsDBNull(3)) waste.WasteDescription = reader.GetString(3); - - if (!reader.IsDBNull(4)) o = reader.GetValue(4); else o = null; - if (o != null) waste.WasteDisposalAmount_MTQ = Convert.ToDouble(o); - - if (!reader.IsDBNull(5)) o = reader.GetValue(5); else o = null; - if (o != null) waste.WasteCapacity_MTQ = Convert.ToDouble(o); - - if (!reader.IsDBNull(6)) o = reader.GetValue(6); else o = null; - if (o != null) waste.WasteAmountRetained_MTQ = Convert.ToDouble(o); - - if (!reader.IsDBNull(7)) waste.WasteDisposalPort = reader.GetString(7); - - if (!reader.IsDBNull(8)) o = reader.GetValue(8); else o = null; - if (o != null) waste.WasteAmountGeneratedTillNextPort_MTQ = Convert.ToDouble(o); - - if (!reader.IsDBNull(9)) o = reader.GetValue(9); else o = null; - if (o != null) waste.WasteDisposedAtLastPort_MTQ = Convert.ToDouble(o); - - waste.WAS = this._was; - waste.IsDirty = true; - waste.Identifier = Waste.GetNewIdentifier(this._was.Waste); - this._was.Waste.Add(waste); - importWasteList.Add(waste); - cnt++; } } while (reader.NextResult()); @@ -526,7 +534,7 @@ namespace ENI2.DetailViewControls if (importWasteList.Count > 0) { this.dataGridWaste.Items.Refresh(); - this.SublistElementChanged(Message.NotificationClass.SEC); + this.SublistElementChanged(Message.NotificationClass.WAS); MessageBox.Show(String.Format(Properties.Resources.textWasteImported, importWasteList.Count), Properties.Resources.textCaptionInformation, MessageBoxButton.OK, MessageBoxImage.Information); } } diff --git a/ENI2/Excel/ExcelWriter.cs b/ENI2/Excel/ExcelWriter.cs index 14b6a540..46560291 100644 --- a/ENI2/Excel/ExcelWriter.cs +++ b/ENI2/Excel/ExcelWriter.cs @@ -1038,9 +1038,12 @@ namespace ENI2.Excel Waste waste = was.Waste[i]; - if(waste.WasteType.HasValue) + if (waste.WasteType.HasValue) + { WriteNumber(wasteCode, waste.WasteType.Value); - WriteText(wastetype, waste.WasteTypeDisplay); + if (WAS.WasteCodeDict.ContainsKey(waste.WasteType.Value.ToString())) + WriteText(wastetype, WAS.WasteCodeDict[waste.WasteType.Value.ToString()]); + } WriteText(wasteDescription, waste.WasteDescription); if (waste.WasteDisposalAmount_MTQ.HasValue) WriteNumber(wasteAmount, waste.WasteDisposalAmount_MTQ.Value); diff --git a/bsmd.database/DBManager.cs b/bsmd.database/DBManager.cs index 8e50efb5..0f08da6d 100644 --- a/bsmd.database/DBManager.cs +++ b/bsmd.database/DBManager.cs @@ -427,7 +427,7 @@ namespace bsmd.database List portAreas = pa.LoadList(reader); DBManager.allPortAreas = new Dictionary(); foreach (PortArea aPa in portAreas) - DBManager.allPortAreas.Add(aPa.Code, aPa); + DBManager.allPortAreas[aPa.Code] = aPa; // TODO da gibt es doppelte Einträge } return DBManager.allPortAreas; } diff --git a/bsmd.database/Util.cs b/bsmd.database/Util.cs index a4c51e83..f775941a 100644 --- a/bsmd.database/Util.cs +++ b/bsmd.database/Util.cs @@ -150,9 +150,7 @@ namespace bsmd.database { if(isDE) { - if ((notificationClass == Message.NotificationClass.CREWD) || - (notificationClass == Message.NotificationClass.PASD) || - (notificationClass == Message.NotificationClass.STO)) continue; + if (notificationClass == Message.NotificationClass.STO) continue; } if(isDK) { diff --git a/bsmd.database/WAS.cs b/bsmd.database/WAS.cs index 58183261..51a690c3 100644 --- a/bsmd.database/WAS.cs +++ b/bsmd.database/WAS.cs @@ -516,6 +516,14 @@ namespace bsmd.database #region public convenience method + public Waste GetWasteForType(int wasteType) + { + foreach (Waste waste in this.Waste) + if (waste.WasteType.HasValue && waste.WasteType.Value == wasteType) + return waste; + return null; + } + public List AddRemainingWasteTypes() { List result = new List(); diff --git a/bsmd.database/Waste.cs b/bsmd.database/Waste.cs index 62ec7243..fb4c660a 100644 --- a/bsmd.database/Waste.cs +++ b/bsmd.database/Waste.cs @@ -30,31 +30,7 @@ namespace bsmd.database [JsonIgnore] [Browsable(false)] - public WAS WAS { get; set; } - - [JsonIgnore] - [Browsable(false)] - [ShowReport] - public string WasteTypeDisplay - { - get - { - if (!WasteType.HasValue) return ""; - switch (WasteType.Value) - { - case 1: return "WASTE_OILS-SLUDGE"; - case 2: return "WASTE_OILS-BILGE_WATER"; - case 3: return "WASTE_OILS-OTHERS"; - case 4: return "GARBAGE-FOOD_WASTE"; - case 5: return "GARBATE-PLASTIC"; - case 6: return "GARBAGE-OTHER"; - case 7: return "SEWAGE"; - case 8: return "CARGO-ASSOCIATED_WASTE"; - case 9: return "CARGO-RESIDUES"; - default: return ""; - } - } - } + public WAS WAS { get; set; } [ShowReport] [JsonIgnore] @@ -62,9 +38,10 @@ namespace bsmd.database { get { - if (!WasteType.HasValue) return ""; + if (!WasteType.HasValue) return string.Empty; switch(WasteType.Value) { + // "old" waste codes (pre V7), used to display old data case 1100: return "Oily residues (sludge)"; case 1200: return "Oily bilge water"; case 1300: return "Waste oil - others (specify)"; @@ -79,9 +56,9 @@ namespace bsmd.database case 3000: return "Sewage"; case 5100: return "Cargo residues - Marpol Annex I"; case 5200: return "Cargo residues - Marpol Annex II"; - case 5300: return "Cargo residues - Marpol Annex V"; + case 5300: return "Cargo residues - Marpol Annex V"; - default: return "Others (specify)"; + default: return string.Empty; } } } @@ -91,7 +68,14 @@ namespace bsmd.database { get { - return string.Format("{0} {1}", WasteType, WasteTypeDisplayV4); + if (!this.WasteType.HasValue) return string.Empty; + string code = WasteTypeDisplayV4; + if(code.IsNullOrEmpty()) + { + if (WAS.WasteCodeDict.ContainsKey(this.WasteType.ToString())) + code = WAS.WasteCodeDict[this.WasteType.ToString()]; + } + return string.Format("{0} {1}", WasteType, code); } } @@ -149,27 +133,12 @@ namespace bsmd.database get { if (!this.WasteType.HasValue) return false; - switch(this.WasteType.Value) + foreach(string wasteCode in WAS.WasteCodes) { - case 1100: - case 1200: - case 1300: - case 2100: - case 2200: - case 2300: - case 2311: - case 2308: - case 2313: - case 2600: - case 2309: - case 3000: - case 5100: - case 5200: - case 5300: + if (wasteCode.Equals(this.WasteType.Value.ToString())) return true; - default: - return false; - } + } + return false; } }