// // Class: MDH // Current CLR: 4.0.30319.34209 // System: Microsoft Visual Studio 10.0 // Author: dani // Created: 3/21/2015 10:56:30 AM // // Copyright (c) 2015 Informatikbüro Daniel Schick. All rights reserved. using System; using System.Data.SqlClient; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Text; using System.ComponentModel; using Newtonsoft.Json; namespace bsmd.database { [TypeConverter(typeof(MessageClassConverter))] [JsonConverter(typeof(NoTypeConverterJsonConverter))] public class MDH : DatabaseEntity, ISublistContainer { public MDH() { this.tablename = "[dbo].[MDH]"; this.MDHSimplification = false; } #region Properties public ObservableCollection PortOfCallLast30Days { get; private set; } = new ObservableCollection(); public ObservableCollection SanitaryMeasuresDetails { get; private set; } = new ObservableCollection(); public ObservableCollection StowawaysJoiningLocations { get; private set; } = new ObservableCollection(); public ObservableCollection InfectedAreas { get; private set; } = new ObservableCollection(); [ShowReport] [Validation1(ValidationCode.NOT_NULL)] [ENI2Validation] public bool? MDHSimplification { get; set; } [ShowReport] [Validation1(ValidationCode.LOCODE_GER)] [MaxLength(5)] [ENI2Validation] public string PortOfCallWhereCompleteMDHNotified { get; set; } [ShowReport] [Validation2(ValidationCode.NOT_NULL)] [LookupName("MDH.NonAccidentialDeathsDuringVoyage")] [ENI2Validation] public bool? NonAccidentalDeathsDuringVoyage { get; set; } [ShowReport] [LookupName("MDH.NonAccidentialDeathsDuringVoyageCount")] [ENI2Validation] public int? NonAccidentalDeathsDuringVoyageCount { get; set; } [ShowReport] [Validation2(ValidationCode.NOT_NULL)] [LookupName("MDH.SuspisionInfectiousNature")] [ENI2Validation] public bool? SuspisionInfectiousNature { get; set; } [ShowReport] [Validation2(ValidationCode.NOT_NULL)] [LookupName("MDH.NumberOfIllPersonsHigherThanExpected")] [ENI2Validation] public bool? NumberOfIllPersonsHigherThanExpected { get; set; } [ShowReport] [LookupName("MDH.NumberOfIllPersons")] [ENI2Validation] public int? NumberOfIllPersons { get; set; } [ShowReport] [Validation2(ValidationCode.NOT_NULL)] [LookupName("MDH.SickPersonsOnBoard")] [ENI2Validation] public bool? SickPersonsOnBoard { get; set; } [ShowReport] [Validation2(ValidationCode.NOT_NULL)] [LookupName("MDH.MedicalConsulted")] [ENI2Validation] public bool? MedicalConsulted { get; set; } [ShowReport] [Validation2(ValidationCode.NOT_NULL)] [LookupName("MDH.AwareOfConditionsForFurtherInfections")] [ENI2Validation] public bool? AwareOfFurtherInfections { get; set; } [ShowReport] [Validation2(ValidationCode.NOT_NULL)] [LookupName("MDH.SanitaryMeasuresApplied")] [ENI2Validation] public bool? SanitaryMeasuresApplied { get; set; } [LookupName("MDH.SanitaryMeasuresType_1")] // TODO: NSW 3.0: wird ein Array [MaxLength(100)] [ENI2Validation] public string SanitaryMeasuresType { get; set; } [LookupName("MDH.SanitaryMeasuresLocation_1")] [MaxLength(100)] [ENI2Validation] public string SanitaryMeasuresLocation { get; set; } [LookupName("MDH.SanitaryMeasuresDate_1")] [ENI2Validation] public DateTime? SanitaryMeasuresDate { get; set; } [ShowReport] [Validation2(ValidationCode.NOT_NULL)] [LookupName("MDH.StowawaysDetected")] [ENI2Validation] public bool? StowawaysDetected { get; set; } [ShowReport] [LookupName("MDH.StowawaysJoiningLocation_1")] // TODO: NSW 3.0: wird ein Array [MaxLength(100)] [ENI2Validation] public string StowawaysJoiningLocation { get; set; } [ShowReport] [Validation2(ValidationCode.NOT_NULL)] [LookupName("MDH.SickAnimalOrPetOnBoard")] [ENI2Validation] public bool? SickAnimalOrPetOnBoard { get; set; } [ShowReport] [Validation2(ValidationCode.NOT_NULL)] [LookupName("MDH.ValidSanitaryControlExemptionOrCertificateOnBoard")] [ENI2Validation] public bool? ValidSanitaryControlExemptionOrCertificateOnBoard { get; set; } [ShowReport] [LookupName("MDH.PlaceOfIssue")] [MaxLength(99)] [Validation2(ValidationCode.STRING_MAXLEN, 99)] [ENI2Validation] public string PlaceOfIssue { get; set; } [ShowReport] [LookupName("MDH.DateOfIssue")] [ENI2Validation] [DateOnly] public DateTime? DateOfIssue { get; set; } [ShowReport] [Validation2(ValidationCode.NOT_NULL)] [LookupName("MDH.SanitaryControlReinspectionRequired")] [ENI2Validation] public bool? SanitaryControlReinspectionRequired { get; set; } [ShowReport] [Validation2(ValidationCode.NOT_NULL)] [LookupName("MDH.InfectedAreaVisited")] [ENI2Validation] public bool? InfectedAreaVisited { get; set; } [LookupName("MDH.InfectedAreaPort_1")] // TODO: NSW 3.0: wird ein Array [MaxLength(100)] [ENI2Validation] public string InfectedAreaPort { get; set; } [LookupName("MDH.InfectedAreaDate_1")] [ENI2Validation] public DateTime? InfectedAreaDate { get; set; } /// /// Hilfsproperty, um eine kommaseparierte Liste von JoiningLocation (analog ANSW) im ENI-2 anzuzeigen, /// [ENI2Validation] public string StowawaysJoiningLocationText { get { StringBuilder sb = new StringBuilder(); for (int i = 0; i < this.StowawaysJoiningLocations.Count; i++) { if (i > 0) sb.Append(", "); sb.Append(((StowawaysJoiningLocation)this.StowawaysJoiningLocations[i]).StowawayJoiningLocation); } return sb.ToString(); } set { if (value.IsNullOrEmpty()) { foreach (StowawaysJoiningLocation wdsp in this.StowawaysJoiningLocations) DBManager.Instance.Delete(wdsp); this.StowawaysJoiningLocations.Clear(); } else { string[] joiningLocations = value.Split(','); List foundList = new List(); for (int i = 0; i < joiningLocations.Length; i++) { string jLocation = joiningLocations[i].Trim(); if (jLocation.Length > 0) { StowawaysJoiningLocation matchingLocation = null; foreach (StowawaysJoiningLocation wdsp in this.StowawaysJoiningLocations) { if (wdsp.StowawayJoiningLocation.Equals(jLocation, StringComparison.OrdinalIgnoreCase)) { matchingLocation = wdsp; break; } } if (matchingLocation != null) { foundList.Add(matchingLocation); this.StowawaysJoiningLocations.Remove(matchingLocation); } else { StowawaysJoiningLocation newLocation = new StowawaysJoiningLocation(); newLocation.MDH = this; newLocation.StowawayJoiningLocation = jLocation; foundList.Add(newLocation); } } } // remove remaining location (no longer valid) foreach (StowawaysJoiningLocation remainingLocation in this.StowawaysJoiningLocations) DBManager.Instance.Delete(remainingLocation); this.StowawaysJoiningLocations.Clear(); // add existing and new crew foreach (StowawaysJoiningLocation sjl in foundList) this.StowawaysJoiningLocations.Add(sjl); } } } #endregion #region public helper internal void SetBoolsToFalse() { this.AwareOfFurtherInfections = false; this.InfectedAreaVisited = false; this.MDHSimplification = false; this.MedicalConsulted = false; this.NonAccidentalDeathsDuringVoyage = false; this.NumberOfIllPersonsHigherThanExpected = false; this.SanitaryControlReinspectionRequired = false; this.SanitaryMeasuresApplied = false; this.SickAnimalOrPetOnBoard = false; this.SickPersonsOnBoard = false; this.StowawaysDetected = false; this.SuspisionInfectiousNature = false; this.ValidSanitaryControlExemptionOrCertificateOnBoard = false; } #endregion #region abstract method implementation public override void PrepareSave(System.Data.IDbCommand cmd) { SqlCommand scmd = cmd as SqlCommand; scmd.Parameters.AddWithNullableValue("@P1", this.MessageHeader.Id); scmd.Parameters.AddWithNullableValue("@P2", this.MDHSimplification); scmd.Parameters.AddWithNullableValue("@P3", this.PortOfCallWhereCompleteMDHNotified); scmd.Parameters.AddWithNullableValue("@P4", this.NonAccidentalDeathsDuringVoyage); scmd.Parameters.AddWithNullableValue("@P5", this.NonAccidentalDeathsDuringVoyageCount); scmd.Parameters.AddWithNullableValue("@P6", this.SuspisionInfectiousNature); scmd.Parameters.AddWithNullableValue("@P7", this.NumberOfIllPersonsHigherThanExpected); scmd.Parameters.AddWithNullableValue("@P8", this.NumberOfIllPersons); scmd.Parameters.AddWithNullableValue("@P9", this.SickPersonsOnBoard); scmd.Parameters.AddWithNullableValue("@P10", this.MedicalConsulted); scmd.Parameters.AddWithNullableValue("@P11", this.AwareOfFurtherInfections); scmd.Parameters.AddWithNullableValue("@P12", this.SanitaryMeasuresApplied); scmd.Parameters.AddWithNullableValue("@P13", this.SanitaryMeasuresType); scmd.Parameters.AddWithNullableValue("@P14", this.SanitaryMeasuresLocation); scmd.Parameters.AddWithNullableValue("@P15", this.SanitaryMeasuresDate); scmd.Parameters.AddWithNullableValue("@P16", this.StowawaysDetected); scmd.Parameters.AddWithNullableValue("@P17", this.StowawaysJoiningLocation); scmd.Parameters.AddWithNullableValue("@P18", this.SickAnimalOrPetOnBoard); scmd.Parameters.AddWithNullableValue("@P19", this.ValidSanitaryControlExemptionOrCertificateOnBoard); scmd.Parameters.AddWithNullableValue("@P20", this.PlaceOfIssue); scmd.Parameters.AddWithNullableValue("@P21", this.DateOfIssue); scmd.Parameters.AddWithNullableValue("@P22", this.SanitaryControlReinspectionRequired); scmd.Parameters.AddWithNullableValue("@P23", this.InfectedAreaVisited); scmd.Parameters.AddWithNullableValue("@P24", this.InfectedAreaPort); scmd.Parameters.AddWithNullableValue("@P25", this.InfectedAreaDate); if (this.IsNew) { this.CreateId(); scmd.Parameters.AddWithValue("@ID", this.Id); scmd.CommandText = string.Format("INSERT INTO {0} (Id, MessageHeaderId, MDHSimplification, PortOfCallWhereCompleteMDHNotified, " + "NonAccidentalDeathsDuringVoyage, NonAccidentalDeathsDuringVoyageCount, SuspisionInfectiousNature, NumberOfIllPersonsHigherThanExpected, " + "NumberOfIllPersons, SickPersonsOnBoard, MedicalConsulted, AwareOfFurtherInfections, SanitaryMeasuresApplied, SanitaryMeasuresType, " + "SanitaryMeasuresLocation, SanitaryMeasuresDate, StowawaysDetected, StowawaysJoiningLocation, SickAnimalOrPetOnBoard, " + "ValidSanitaryControlExemptionOrCertificateOnBoard, PlaceOfIssue, DateOfIssue, SanitaryControlReinspectionRequired, " + "InfectedAreaVisited, InfectedAreaPort, InfectedAreaDate) VALUES (@ID, @P1, @P2, @P3, @P4, @P5, @P6, @P7, @P8, @P9, @P10, @P11, @P12, " + "@P13, @P14, @P15, @P16, @P17, @P18, @P19, @P20, @P21, @P22, @P23, @P24, @P25)", this.Tablename); } else { scmd.CommandText = string.Format("UPDATE {0} SET MDHSimplification = @P2, PortOfCallWhereCompleteMDHNotified = @P3, " + "NonAccidentalDeathsDuringVoyage = @P4, NonAccidentalDeathsDuringVoyageCount = @P5, SuspisionInfectiousNature = @P6, " + "NumberOfIllPersonsHigherThanExpected = @P7, NumberOfIllPersons = @P8, SickPersonsOnBoard = @P9, MedicalConsulted = @P10, " + "AwareOfFurtherInfections = @P11, SanitaryMeasuresApplied = @P12, SanitaryMeasuresType = @P13, SanitaryMeasuresLocation = @P14, " + "SanitaryMeasuresDate = @P15, StowawaysDetected = @P16, StowawaysJoiningLocation = @P17, SickAnimalOrPetOnBoard = @P18, " + "ValidSanitaryControlExemptionOrCertificateOnBoard = @P19, PlaceofIssue = @P20, DateOfIssue = @P21, SanitaryControlReinspectionRequired = @P22, " + "InfectedAreaVisited = @P23, InfectedAreaPort = @P24, InfectedAreaDate = @P25 WHERE Id = @ID", this.Tablename); scmd.Parameters.AddWithValue("@ID", this.Id); } } public override void PrepareLoadCommand(System.Data.IDbCommand cmd, Message.LoadFilter filter, params object[] criteria) { string query = string.Format("SELECT Id, MDHSimplification, PortOfCallWhereCompleteMDHNotified, " + "NonAccidentalDeathsDuringVoyage, NonAccidentalDeathsDuringVoyageCount, SuspisionInfectiousNature, " + "NumberOfIllPersonsHigherThanExpected, NumberOfIllPersons, SickPersonsOnBoard, MedicalConsulted, AwareOfFurtherInfections, " + "SanitaryMeasuresApplied, SanitaryMeasuresType, SanitaryMeasuresLocation, SanitaryMeasuresDate, StowawaysDetected, " + "StowawaysJoiningLocation, SickAnimalOrPetOnBoard, ValidSanitaryControlExemptionOrCertificateOnBoard, " + "PlaceOfIssue, DateOfIssue, SanitaryControlReinspectionRequired, InfectedAreaVisited, InfectedAreaPort, InfectedAreaDate " + "FROM {0} ", this.Tablename); switch (filter) { case Message.LoadFilter.MESSAGEHEADER: query += "WHERE MessageHeaderId = @MHID"; ((SqlCommand)cmd).Parameters.AddWithValue("@MHID", criteria[0]); break; case Message.LoadFilter.ALL: default: break; } cmd.CommandText = query; } public override List LoadList(System.Data.IDataReader reader) { List result = new List(); while (reader.Read()) { MDH mdh = new MDH(); mdh.id = reader.GetGuid(0); if (!reader.IsDBNull(1)) mdh.MDHSimplification = reader.GetBoolean(1); if (!reader.IsDBNull(2)) mdh.PortOfCallWhereCompleteMDHNotified = reader.GetString(2); if (!reader.IsDBNull(3)) mdh.NonAccidentalDeathsDuringVoyage = reader.GetBoolean(3); if (!reader.IsDBNull(4)) mdh.NonAccidentalDeathsDuringVoyageCount = reader.GetInt32(4); if (!reader.IsDBNull(5)) mdh.SuspisionInfectiousNature = reader.GetBoolean(5); if (!reader.IsDBNull(6)) mdh.NumberOfIllPersonsHigherThanExpected = reader.GetBoolean(6); if (!reader.IsDBNull(7)) mdh.NumberOfIllPersons = reader.GetInt32(7); if (!reader.IsDBNull(8)) mdh.SickPersonsOnBoard = reader.GetBoolean(8); if (!reader.IsDBNull(9)) mdh.MedicalConsulted = reader.GetBoolean(9); if (!reader.IsDBNull(10)) mdh.AwareOfFurtherInfections = reader.GetBoolean(10); if (!reader.IsDBNull(11)) mdh.SanitaryMeasuresApplied = reader.GetBoolean(11); if (!reader.IsDBNull(12)) mdh.SanitaryMeasuresType = reader.GetString(12); if (!reader.IsDBNull(13)) mdh.SanitaryMeasuresLocation = reader.GetString(13); if (!reader.IsDBNull(14)) mdh.SanitaryMeasuresDate = reader.GetDateTime(14); if (!reader.IsDBNull(15)) mdh.StowawaysDetected = reader.GetBoolean(15); if (!reader.IsDBNull(16)) mdh.StowawaysJoiningLocation = reader.GetString(16); if (!reader.IsDBNull(17)) mdh.SickAnimalOrPetOnBoard = reader.GetBoolean(17); if (!reader.IsDBNull(18)) mdh.ValidSanitaryControlExemptionOrCertificateOnBoard = reader.GetBoolean(18); if (!reader.IsDBNull(19)) mdh.PlaceOfIssue = reader.GetString(19); if (!reader.IsDBNull(20)) mdh.DateOfIssue = reader.GetDateTime(20); if (!reader.IsDBNull(21)) mdh.SanitaryControlReinspectionRequired = reader.GetBoolean(21); if (!reader.IsDBNull(22)) mdh.InfectedAreaVisited = reader.GetBoolean(22); if (!reader.IsDBNull(23)) mdh.InfectedAreaPort = reader.GetString(23); if (!reader.IsDBNull(24)) mdh.InfectedAreaDate = reader.GetDateTime(24); result.Add(mdh); } reader.Close(); return result; } #endregion #region overrides public override void OverwriteWith(DatabaseEntity otherEntity) { if (otherEntity is MDH otherMDH) { base.OverwriteWith(otherEntity); // PortOfCallLast30Days foreach (PortOfCallLast30Days poc in this.PortOfCallLast30Days) DBManager.Instance.Delete(poc); this.PortOfCallLast30Days.Clear(); foreach (PortOfCallLast30Days poc in otherMDH.PortOfCallLast30Days) { PortOfCallLast30Days newPOC = poc.Clone() as PortOfCallLast30Days; newPOC.MDH = this; DBManager.Instance.Save(newPOC); this.PortOfCallLast30Days.Add(newPOC); } // SanitaryMeasuresDetails foreach (SanitaryMeasuresDetail san in this.SanitaryMeasuresDetails) DBManager.Instance.Delete(san); this.SanitaryMeasuresDetails.Clear(); foreach (SanitaryMeasuresDetail san in otherMDH.SanitaryMeasuresDetails) { SanitaryMeasuresDetail newSAN = san.Clone() as SanitaryMeasuresDetail; newSAN.MDH = this; DBManager.Instance.Save(newSAN); this.SanitaryMeasuresDetails.Add(newSAN); } // StowawaysJoiningLocations foreach (StowawaysJoiningLocation sjl in this.StowawaysJoiningLocations) DBManager.Instance.Delete(sjl); this.StowawaysJoiningLocations.Clear(); foreach (StowawaysJoiningLocation sjl in otherMDH.StowawaysJoiningLocations) { StowawaysJoiningLocation newSJL = sjl.Clone() as StowawaysJoiningLocation; newSJL.MDH = this; DBManager.Instance.Save(newSJL); this.StowawaysJoiningLocations.Add(newSJL); } // InfectedAreas foreach (InfectedArea ia in this.InfectedAreas) DBManager.Instance.Delete(ia); this.InfectedAreas.Clear(); foreach (InfectedArea ia in otherMDH.InfectedAreas) { InfectedArea newIA = ia.Clone() as InfectedArea; newIA.MDH = this; DBManager.Instance.Save(newIA); this.InfectedAreas.Add(newIA); } } } #endregion #region ISublistContainer implementation public ISublistElement GetSublistElementWithIdentifier(string identifier) { foreach(ISublistElement sElem in this.PortOfCallLast30Days) { if (sElem.Identifier.Equals(identifier)) return sElem; } return null; } [Browsable(false)] [JsonIgnore] public int NumberOfExcelRows { get { return 37; } } public void SaveElements() { foreach(PortOfCallLast30Days poc30d in this.PortOfCallLast30Days) { DBManager.Instance.Save(poc30d); ((ISublistContainer)poc30d).SaveElements(); } foreach(SanitaryMeasuresDetail smd in this.SanitaryMeasuresDetails) { DBManager.Instance.Save(smd); } foreach(StowawaysJoiningLocation sjl in this.StowawaysJoiningLocations) { DBManager.Instance.Save(sjl); } foreach(InfectedArea ia in this.InfectedAreas) { DBManager.Instance.Save(ia); } } public void DeleteElements() { foreach (PortOfCallLast30Days poc30d in this.PortOfCallLast30Days) { ((ISublistContainer)poc30d).DeleteElements(); DBManager.Instance.Delete(poc30d); } this.PortOfCallLast30Days.Clear(); foreach (SanitaryMeasuresDetail smd in this.SanitaryMeasuresDetails) { DBManager.Instance.Delete(smd); } this.SanitaryMeasuresDetails.Clear(); foreach (StowawaysJoiningLocation sjl in this.StowawaysJoiningLocations) { DBManager.Instance.Delete(sjl); } this.StowawaysJoiningLocations.Clear(); foreach (InfectedArea ia in this.InfectedAreas) { DBManager.Instance.Delete(ia); } this.InfectedAreas.Clear(); } public SanitaryMeasuresDetail GetSanitaryMeasuresDetailWithIdentifier(string identifier) { foreach (SanitaryMeasuresDetail sd in this.SanitaryMeasuresDetails) if (sd.Identifier.Equals(identifier)) return sd; return null; } public StowawaysJoiningLocation GetStowawaysJoiningLocationWithIdentifier(string identifier) { foreach (StowawaysJoiningLocation sj in this.StowawaysJoiningLocations) if (sj.Identifier.Equals(identifier)) return sj; return null; } public InfectedArea GetInfectedAreaWithIdentifier(string identifier) { foreach (InfectedArea ia in this.InfectedAreas) if (ia.Identifier.Equals(identifier)) return ia; return null; } #endregion #region IMessageParagraph implementation public override string Subtitle { get { return "Medical declaration of health"; } } [Browsable(false)] [JsonIgnore] public override List ChildParagraphs { get { List result = new List(); foreach (IMessageParagraph imp in this.PortOfCallLast30Days) result.Add(imp); return result; } } #endregion #region Validation public override DatabaseEntity.ValidationBlock GetValidationBlock() { return (this.MDHSimplification ?? false) ? DatabaseEntity.ValidationBlock.BLOCK1 : DatabaseEntity.ValidationBlock.BLOCK2; } public override void Validate(List errors, List violations) { if (this.GetValidationBlock() == ValidationBlock.BLOCK1) { if (this.PortOfCallWhereCompleteMDHNotified.IsNullOrEmpty()) violations.Add(RuleEngine.CreateViolation(ValidationCode.V768, "PortOfCallWhereCompleteMDHNotified missing", null, this.Title, null, this.Tablename)); } else { if ((this.NonAccidentalDeathsDuringVoyage ?? false) && ((this.NonAccidentalDeathsDuringVoyageCount ?? 0) == 0)) violations.Add(RuleEngine.CreateViolation(ValidationCode.V761, "NonAccidentalDeathsDuringVoyageCount missing", null, this.Title, null, this.Tablename)); if ((this.NumberOfIllPersonsHigherThanExpected ?? false) && ((this.NumberOfIllPersons ?? 0) == 0)) violations.Add(RuleEngine.CreateViolation(ValidationCode.V762, "Number of ill persons missing", null, this.Title, null, this.Tablename)); if ((this.SanitaryMeasuresApplied ?? false) && this.SanitaryMeasuresDetails.IsNullOrEmpty()) violations.Add(RuleEngine.CreateViolation(ValidationCode.V763, "Sanitary measure details missing", null, this.Title, null, this.Tablename)); if ((this.StowawaysDetected ?? false) && this.StowawaysJoiningLocation.IsNullOrEmpty()) violations.Add(RuleEngine.CreateViolation(ValidationCode.V764, "Stowaways joining location missing", null, this.Title, null, this.Tablename)); if ((this.ValidSanitaryControlExemptionOrCertificateOnBoard ?? false) && (this.PlaceOfIssue.IsNullOrEmpty() || !this.DateOfIssue.HasValue)) violations.Add(RuleEngine.CreateViolation(ValidationCode.V765, "Cert. Place or Date of issue missing", null, this.Title, null, this.Tablename)); if ((this.InfectedAreaVisited ?? false) && this.InfectedAreas.IsNullOrEmpty()) violations.Add(RuleEngine.CreateViolation(ValidationCode.V766, "Infected area date or port missing", null, this.Title, null, this.Tablename)); if ((this.DateOfIssue.HasValue) && (this.DateOfIssue.Value < DateTime.Today.AddMonths(-6))) violations.Add(RuleEngine.CreateViolation(ValidationCode.TIME_IMPLAUSIBLE, "Date of issue might be too old", null, this.Title, null, this.Tablename)); if ((this.DateOfIssue.HasValue) && (this.DateOfIssue.Value > DateTime.Today)) violations.Add(RuleEngine.CreateViolation(ValidationCode.TIME_IMPLAUSIBLE, "Date of issue is in the future", null, this.Title, null, this.Tablename)); if (this.PortOfCallLast30Days.Count == 0) { errors.Add(RuleEngine.CreateError(ValidationCode.NOT_NULL, "Port of Call last 30 day list is EMPTY", null, this.Title, null, this.Tablename)); } foreach (PortOfCallLast30Days poc30d in this.PortOfCallLast30Days) { RuleEngine.ValidateProperties(poc30d, errors, violations); poc30d.Validate(errors, violations); } foreach (SanitaryMeasuresDetail smd in this.SanitaryMeasuresDetails) { RuleEngine.ValidateProperties(smd, errors, violations); } } } #endregion #region ICloneable implementation public override object Clone() { MDH mdh = this.MemberwiseClone() as MDH; mdh.id = null; mdh.InfectedAreas = new ObservableCollection(); mdh.PortOfCallLast30Days = new ObservableCollection(); mdh.SanitaryMeasuresDetails = new ObservableCollection(); mdh.StowawaysJoiningLocations = new ObservableCollection(); foreach (InfectedArea ia in this.InfectedAreas) { InfectedArea clonedIA = ia.Clone() as InfectedArea; clonedIA.MDH = mdh; mdh.InfectedAreas.Add(clonedIA); } foreach (PortOfCallLast30Days poc in this.PortOfCallLast30Days) { PortOfCallLast30Days clonedPOC = poc.Clone() as PortOfCallLast30Days; clonedPOC.MDH = mdh; mdh.PortOfCallLast30Days.Add(clonedPOC); } foreach (SanitaryMeasuresDetail smd in this.SanitaryMeasuresDetails) { SanitaryMeasuresDetail clonedSMD = smd.Clone() as SanitaryMeasuresDetail; clonedSMD.MDH = mdh; mdh.SanitaryMeasuresDetails.Add(clonedSMD); } foreach (StowawaysJoiningLocation sjl in this.StowawaysJoiningLocations) { StowawaysJoiningLocation clonedSJL = sjl.Clone() as StowawaysJoiningLocation; clonedSJL.MDH = mdh; mdh.StowawaysJoiningLocations.Add(clonedSJL); } return mdh; } #endregion } #region class MDHConverter public class MDHConverter : TypeConverter { public override bool CanConvertFrom(ITypeDescriptorContext context, System.Type sourceType) { if (sourceType == typeof(string)) { return true; } return base.CanConvertFrom(context, sourceType); } public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) { if (value is string) { string s = value.ToString(); //s = s.Replace("\\", ""); return JsonConvert.DeserializeObject(s); } return base.ConvertFrom(context, culture, value); } } #endregion }