diff --git a/ENI-2/ENI2/ENI2/DetailViewControls/MaritimeHealthDeclarationDetailControl.xaml.cs b/ENI-2/ENI2/ENI2/DetailViewControls/MaritimeHealthDeclarationDetailControl.xaml.cs index 0fbe3188..debe1323 100644 --- a/ENI-2/ENI2/ENI2/DetailViewControls/MaritimeHealthDeclarationDetailControl.xaml.cs +++ b/ENI-2/ENI2/ENI2/DetailViewControls/MaritimeHealthDeclarationDetailControl.xaml.cs @@ -291,7 +291,7 @@ namespace ENI2.DetailViewControls } catch (Exception ex) { - MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); + MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); return; } @@ -305,27 +305,37 @@ namespace ENI2.DetailViewControls { while (reader.Read()) { - if (reader.FieldCount < 2) + if (reader.FieldCount < 3) { - throw new InvalidDataException("Sheet must have at least 2 Columns of data"); + throw new InvalidDataException("Sheet must have at least 3 Columns of data"); } PortOfCallLast30Days poc30 = new PortOfCallLast30Days(); if (reader.IsDBNull(0) && reader.IsDBNull(1)) continue; if (!reader.IsDBNull(0)) poc30.PortOfCallLast30DaysLocode = reader.GetString(0); if (!reader.IsDBNull(1)) poc30.PortOfCallLast30DaysDateOfDeparture = reader.GetDateTime(1); - // if (DateTime.TryParse(reader.GetString(1), out DateTime dateOfDep)) - // poc30.PortOfCallLast30DaysDateOfDeparture = dateOfDep; - if (!reader.IsDBNull(2) && !reader.GetString(2).IsNullOrEmpty()) poc30.PortOfCallLast30DaysCrewMembersJoined = true; - - for (int colIndex = 2; (colIndex < reader.FieldCount) && !reader.IsDBNull(colIndex); colIndex++) + string boolString = ""; + if (!reader.IsDBNull(2)) boolString = reader.GetString(2); + poc30.PortOfCallLast30DaysCrewMembersJoined = (boolString.Equals("y", StringComparison.OrdinalIgnoreCase) || (boolString.Equals("yes", StringComparison.OrdinalIgnoreCase)) || + (boolString.Equals("j", StringComparison.OrdinalIgnoreCase))); + + if(reader.FieldCount > 3) { - string crewName = reader.GetString(colIndex); - if (crewName.IsNullOrEmpty()) break; - PortOfCallLast30DaysCrewJoinedShip poc30Crew = new PortOfCallLast30DaysCrewJoinedShip(); - poc30Crew.PortOfCallLast30DaysCrewJoinedShipName = crewName; - poc30Crew.PortOfCallLast30Days = poc30; - poc30.CrewJoinedShip.Add(poc30Crew); - } + string allNewCrew = reader.GetString(3)?.Trim(); + if(!allNewCrew.IsNullOrEmpty()) + { + string[] crewNames = allNewCrew.Split(',', ';'); + for(int i=0;i - + + + + + diff --git a/ENI-2/ENI2/ENI2/EditControls/MessageHistoryDialog.xaml.cs b/ENI-2/ENI2/ENI2/EditControls/MessageHistoryDialog.xaml.cs index 36b5432c..2a4a176d 100644 --- a/ENI-2/ENI2/ENI2/EditControls/MessageHistoryDialog.xaml.cs +++ b/ENI-2/ENI2/ENI2/EditControls/MessageHistoryDialog.xaml.cs @@ -4,17 +4,11 @@ using System; using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; -using System.Windows.Data; -using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; -using System.Windows.Shapes; using bsmd.database; using ENI2.Controls; using log4net; @@ -29,11 +23,22 @@ namespace ENI2.EditControls private static readonly ILog _log = LogManager.GetLogger(typeof(MessageHistoryDialog)); + private readonly Dictionary groupColorDict = new Dictionary(); + public MessageHistoryDialog() { InitializeComponent(); Loaded += (o, e) => { + // "color-code" (Group) the message histories + + foreach(MessageHistory mh in this.MessageHistories) + { + if (!groupColorDict.ContainsKey(mh.EntityId)) + groupColorDict[mh.EntityId] = new SolidColorBrush(Util.UIHelper.GetRandomBrightColor()); + mh.GroupColorBrush = groupColorDict[mh.EntityId]; + } + this.dataGridMessageHistories.ItemsSource = this.MessageHistories; this.dataGridMessageHistories.ContextMenu = new ContextMenu(); @@ -94,7 +99,7 @@ namespace ENI2.EditControls foreach (Message aMessage in this.Messages) { if (aMessage.MessageNotificationClassDisplay.Equals(selectedHistory.EntityName) || - (aMessage.MessageNotificationClassDisplay.Equals("BKRA") && selectedHistory.EntityName.Equals("BRKA")) || + (aMessage.MessageNotificationClassDisplay.Equals("BKRA") && selectedHistory.EntityName.Equals("BRKA")) || // blöder Schreibfehler beachten (aMessage.MessageNotificationClassDisplay.Equals("BKRD") && selectedHistory.EntityName.Equals("BRKD")) ) { diff --git a/ENI-2/ENI2/ENI2/Util/UIHelper.cs b/ENI-2/ENI2/ENI2/Util/UIHelper.cs index 34f56f5b..354677b0 100644 --- a/ENI-2/ENI2/ENI2/Util/UIHelper.cs +++ b/ENI-2/ENI2/ENI2/Util/UIHelper.cs @@ -7,6 +7,7 @@ using System; using System.Reflection; using System.Windows; using System.Windows.Input; +using System.Windows.Media; using System.Windows.Threading; namespace ENI2.Util @@ -15,6 +16,7 @@ namespace ENI2.Util { private static bool isBusy; + private static readonly Random r = new Random(); public static void SetBusyState() { @@ -37,8 +39,7 @@ namespace ENI2.Util private static void dispatcherTimer_Tick(object sender, EventArgs e) { - DispatcherTimer timer = sender as DispatcherTimer; - if(timer != null) + if (sender is DispatcherTimer timer) { SetBusyState(false); timer.Stop(); @@ -50,5 +51,10 @@ namespace ENI2.Util return (bool)typeof(Window).GetField("_showingAsDialog", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(window); } + public static Color GetRandomBrightColor() + { + return Color.FromRgb((byte) r.Next(150, 255), (byte) r.Next(150, 255), (byte) r.Next(150, 255)); + } + } } diff --git a/Stundensheet.xlsx b/Stundensheet.xlsx index 1cc6b60b..d2bea148 100644 Binary files a/Stundensheet.xlsx and b/Stundensheet.xlsx differ diff --git a/nsw/Source/bsmd.database/DBManager.cs b/nsw/Source/bsmd.database/DBManager.cs index cb183cb6..333f8b49 100644 --- a/nsw/Source/bsmd.database/DBManager.cs +++ b/nsw/Source/bsmd.database/DBManager.cs @@ -795,7 +795,7 @@ namespace bsmd.database } // 3. MessageHistory Element speichern - // TODO: das könnte auch in einem Background Thread passieren, da der Wert erst irgendwann gelesen wird und aktuell nicht relevant ist + /// TODO: das könnte auch in einem Background Thread passieren, da der Wert erst irgendwann gelesen wird und aktuell nicht relevant ist using (SqlCommand cmd = new SqlCommand()) { mh.PrepareSave(cmd); diff --git a/nsw/Source/bsmd.database/MessageHistory.cs b/nsw/Source/bsmd.database/MessageHistory.cs index b6e09fac..fe9f2476 100644 --- a/nsw/Source/bsmd.database/MessageHistory.cs +++ b/nsw/Source/bsmd.database/MessageHistory.cs @@ -6,8 +6,7 @@ using System; using System.Collections.Generic; using System.Data; using System.Data.SqlClient; -using System.Linq; -using System.Text; +using System.Windows.Media; namespace bsmd.database { @@ -38,6 +37,11 @@ namespace bsmd.database public int Identifier { get; set; } + /// + /// Helper property for display grid + /// + public Brush GroupColorBrush { get; set; } + /// /// ENI Grid helper property /// diff --git a/nsw/Source/bsmd.database/WasteDisposalServiceProvider.cs b/nsw/Source/bsmd.database/WasteDisposalServiceProvider.cs index 12c5f794..4ee9de11 100644 --- a/nsw/Source/bsmd.database/WasteDisposalServiceProvider.cs +++ b/nsw/Source/bsmd.database/WasteDisposalServiceProvider.cs @@ -31,7 +31,7 @@ namespace bsmd.database [ShowReport] [MaxLength(99)] [ENI2Validation] - [Validation(ValidationCode.NOT_NULL_MAX_LEN, 99)] + [Validation(ValidationCode.STRING_MAXLEN, 99)] public string WasteDisposalServiceProviderName { get; set; } [Obsolete] diff --git a/nsw/Source/bsmd.database/bsmd.database.csproj b/nsw/Source/bsmd.database/bsmd.database.csproj index 92383c70..0bc6a1b7 100644 --- a/nsw/Source/bsmd.database/bsmd.database.csproj +++ b/nsw/Source/bsmd.database/bsmd.database.csproj @@ -47,6 +47,7 @@ ..\..\..\ENI-2\ENI2\ENI2\packages\Newtonsoft.Json.12.0.2\lib\net45\Newtonsoft.Json.dll + diff --git a/nsw/Source/bsmd.dbh/Request.cs b/nsw/Source/bsmd.dbh/Request.cs index db34f5cc..268d54e3 100644 --- a/nsw/Source/bsmd.dbh/Request.cs +++ b/nsw/Source/bsmd.dbh/Request.cs @@ -19,7 +19,7 @@ namespace bsmd.dbh public class Request { - private static ILog _log = LogManager.GetLogger(typeof(Request)); + private static readonly ILog _log = LogManager.GetLogger(typeof(Request)); public static bool SendCancelCore(MessageCore core, bool useTest) { @@ -31,7 +31,7 @@ namespace bsmd.dbh return false; } - RootType rootType = RootType.CANCEL; + const RootType rootType = RootType.CANCEL; Dbh_Osis_Answ_Ws client = new Dbh_Osis_Answ_Ws(); if (useTest) @@ -57,7 +57,7 @@ namespace bsmd.dbh { object[] items = new object[1]; DateTime timestamp = DateTime.Now; - string version = "3.0"; + const string version = "3.0"; object item = null; string senderReference = core.Id.Value.ToString("N"); items[0] = item; @@ -76,7 +76,7 @@ namespace bsmd.dbh _log.InfoFormat("Send Url: {0}", client.Url); - RootVersion rootVersion = RootVersion.Item50; + const RootVersion rootVersion = RootVersion.Item50; string result = client.Root( rootVersion, @@ -101,6 +101,10 @@ namespace bsmd.dbh return false; } + finally + { + client.Dispose(); + } return true; } @@ -150,7 +154,7 @@ namespace bsmd.dbh rp.RPType = (ReportingPartyRPType) message.ReportingParty.ReportingPartyType.Value; DateTime timestamp = DateTime.Now; - string version = "3.0"; + const string version = "3.0"; object item = null; string senderReference = message.Id.Value.ToString("N"); @@ -219,8 +223,7 @@ namespace bsmd.dbh #region NOA_NOD case Message.NotificationClass.NOA_NOD: { - NOA_NOD noa_nod = message.Elements[0] as NOA_NOD; - if (noa_nod != null) + if (message.Elements[0] is NOA_NOD noa_nod) { RootNOA_NOD rootNoaNod = new RootNOA_NOD(); @@ -233,10 +236,10 @@ namespace bsmd.dbh // rootNoaNod.ETDFromLastPortSpecified = noa_nod.ETDFromLastPort.HasValue; rootNoaNod.LastPort = noa_nod.LastPort; - rootNoaNod.NextPort = noa_nod.NextPort; + rootNoaNod.NextPort = noa_nod.NextPort; List choiceList = new List(); - List choices = new List(); + List choices = new List(); if (message.MessageCore.IsTransit) { @@ -272,11 +275,11 @@ namespace bsmd.dbh RootNOA_NODCallPurpose rnncp = new RootNOA_NODCallPurpose(); CallPurpose callPurpose = noa_nod.CallPurposes[i] as CallPurpose; rnncp.CallPurposeCode = callPurpose.CallPurposeCode; - if(callPurpose.CallPurposeDescription != string.Empty) + if (callPurpose.CallPurposeDescription != string.Empty) rnncp.CallPurposeDescription = callPurpose.CallPurposeDescription; choices.Add(rnncp); } - } + } rootNoaNod.Items = choices.ToArray(); rootNoaNod.ItemsElementName = choiceList.ToArray(); @@ -291,8 +294,7 @@ namespace bsmd.dbh case Message.NotificationClass.AGNT: { - AGNT agnt = message.Elements[0] as AGNT; - if (agnt != null) + if (message.Elements[0] is AGNT agnt) { RootAGNT rootAGNT = new RootAGNT(); rootAGNT.AgentCity = agnt.AgentCity; @@ -306,7 +308,7 @@ namespace bsmd.dbh rootAGNT.AgentPostalCode = agnt.AgentPostalCode; rootAGNT.AgentStreetAndNumber = agnt.AgentStreetAndNumber; item = rootAGNT; - } + } break; } @@ -315,8 +317,7 @@ namespace bsmd.dbh #region ATA case Message.NotificationClass.ATA: { - ATA ata = message.Elements[0] as ATA; - if (ata != null) + if (message.Elements[0] is ATA ata) { RootATA rootATA = new RootATA(); if (ata.ATAPortOfCall.HasValue) @@ -330,8 +331,7 @@ namespace bsmd.dbh #region ATD case Message.NotificationClass.ATD: { - ATD atd = message.Elements[0] as ATD; - if (atd != null) + if (message.Elements[0] is ATD atd) { RootATD rootATD = new RootATD(); rootATD.ATDPortOfCall = atd.ATDPortOfCall.Value.ToDBHDateString(); @@ -476,8 +476,7 @@ namespace bsmd.dbh #region BPOL case Message.NotificationClass.BPOL: { - BPOL bpol = message.Elements[0] as BPOL; - if (bpol != null) + if (message.Elements[0] is BPOL bpol) { RootBPOL rootBPOL = new RootBPOL(); RootBPOLPortOfItinerary[] poiArray = new RootBPOLPortOfItinerary[bpol.PortOfItineraries.Count]; @@ -858,6 +857,7 @@ namespace bsmd.dbh if (!mdh.MDHSimplification.HasValue) { _log.ErrorFormat("MDH {0} doesnt have MDHSimplification field set, aborting message", mdh.Id); + client.Dispose(); return false; } if (mdh.MDHSimplification.Value) @@ -873,9 +873,11 @@ namespace bsmd.dbh { // der blöde Teil List mdhItems = new List(); - List choiceTypes2 = new List(); - - choiceTypes2.Add(ItemsChoiceType2.NonAccidentialDeathsDuringVoyage); + List choiceTypes2 = new List + { + ItemsChoiceType2.NonAccidentialDeathsDuringVoyage + }; + mdhItems.Add((mdh.NonAccidentalDeathsDuringVoyage ?? false) ? RootSECValidISSCOnBoard.Y : RootSECValidISSCOnBoard.N); if (mdh.NonAccidentalDeathsDuringVoyage ?? false) @@ -1021,9 +1023,10 @@ namespace bsmd.dbh // ACHTUNG hier ist die Reihenfolge entscheidend! (siehe XSD) List wasteItems = new List(); - List choiceType3s = new List(); - - choiceType3s.Add(ItemsChoiceType3.LastWasteDisposalPort); + List choiceType3s = new List + { + ItemsChoiceType3.LastWasteDisposalPort + }; wasteItems.Add(was.LastWasteDisposalPort); if (was.LastWasteDisposalDate.HasValue) @@ -1262,8 +1265,10 @@ namespace bsmd.dbh rootIMDG.GeneralCargoIBCSpecified = imdgPos.GeneralCargoIBC.HasValue; if (imdgPos.GeneralCargoIBC.HasValue) rootIMDG.GeneralCargoIBC = imdgPos.GeneralCargoIBC.Value ? DBHWebReference.RootSECValidISSCOnBoard.Y : DBHWebReference.RootSECValidISSCOnBoard.N; - rootIMDG.ContainerNumber = imdgPos.ContainerNumber; - rootIMDG.VehicleLicenseNumber = imdgPos.VehicleLicenseNumber; + if(!imdgPos.ContainerNumber.IsNullOrEmpty()) + rootIMDG.ContainerNumber = imdgPos.ContainerNumber; + if(!imdgPos.VehicleLicenseNumber.IsNullOrEmpty()) + rootIMDG.VehicleLicenseNumber = imdgPos.VehicleLicenseNumber; if (imdgPos.StowagePosition.IsNullOrEmpty()) { @@ -1519,8 +1524,10 @@ namespace bsmd.dbh rootIMDG.GeneralCargoIBCSpecified = imdgPos.GeneralCargoIBC.HasValue; if (imdgPos.GeneralCargoIBC.HasValue) rootIMDG.GeneralCargoIBC = imdgPos.GeneralCargoIBC.Value ? RootSECValidISSCOnBoard.Y : RootSECValidISSCOnBoard.N; - rootIMDG.ContainerNumber = imdgPos.ContainerNumber; - rootIMDG.VehicleLicenseNumber = imdgPos.VehicleLicenseNumber; + if(!imdgPos.ContainerNumber.IsNullOrEmpty()) + rootIMDG.ContainerNumber = imdgPos.ContainerNumber; + if(!imdgPos.VehicleLicenseNumber.IsNullOrEmpty()) + rootIMDG.VehicleLicenseNumber = imdgPos.VehicleLicenseNumber; if (imdgPos.StowagePosition.IsNullOrEmpty()) { @@ -1676,6 +1683,7 @@ namespace bsmd.dbh default: { _log.ErrorFormat("DBH send message: message type {0} not implemented", message.MessageNotificationClass); + client.Dispose(); return false; } #endregion @@ -1706,7 +1714,7 @@ namespace bsmd.dbh _log.InfoFormat("Send Url: {0}", client.Url); - RootVersion rootVersion = RootVersion.Item50; + const RootVersion rootVersion = RootVersion.Item50; string result = client.Root( rootVersion, @@ -1731,6 +1739,10 @@ namespace bsmd.dbh returnval = false; } + finally + { + client.Dispose(); + } return returnval; }