// // Class: ShipToShipActivitiesDuringLastTenPortFacilitiesCalled // Current CLR: 4.0.30319.34209 // System: Microsoft Visual Studio 10.0 // Author: dani // Created: 4/3/2015 12:01:28 PM // // Copyright (c) 2015 Informatikbüro Daniel Schick. All rights reserved. using System; using System.Data; using System.Data.SqlClient; using System.Collections.Generic; using Newtonsoft.Json; using System.ComponentModel; namespace bsmd.database { [TypeConverter(typeof(MessageClassConverter))] [JsonConverter(typeof(NoTypeConverterJsonConverter))] public class ShipToShipActivitiesDuringLastTenPortFacilitiesCalled : DatabaseEntity, ISublistElement { public ShipToShipActivitiesDuringLastTenPortFacilitiesCalled() { this.tablename = "[dbo].[ShipToShipActivitiesDuringLastTenPortFacilitiesCalled]"; } #region Properties [JsonIgnore] [Browsable(false)] public SEC SEC { get; set; } [ShowReport] [MaxLength(255)] [ENI2Validation] public string ShipToShipActivityLocationName { get; set; } [ShowReport] [MaxLength(5)] [ENI2Validation] public string ShipToShipActivityLocationLoCode { get; set; } [ShowReport] [ENI2Validation] public int? ShipToShipActivityLocationCoordinatesLatitude { get; set; } [ShowReport] [ENI2Validation] public int? ShipToShipActivityLocationCoordinatesLongitude { get; set; } [ShowReport] [Validation2(ValidationCode.NOT_NULL)] [ENI2Validation] public DateTime? ShipToShipActivityDateFrom { get; set; } [ShowReport] [Validation2(ValidationCode.NOT_NULL)] [ENI2Validation] public DateTime? ShipToShipActivityDateTo { get; set; } [ShowReport] [Validation2(ValidationCode.NOT_NULL)] [ENI2Validation] public int? ShipToShipActivityTypeCode { get; set; } [ShowReport] [MaxLength(255)] [ENI2Validation] public string ShipToShipActivityType { get; set; } public string ShipToShipActivityTypeDisplay { get { return string.Format("{0} {1}", ShipToShipActivityTypeCode.HasValue ? ShipToShipActivityTypeCode.ToString() : "", ShipToShipActivityType); } } [ShowReport] [MaxLength(255)] [ENI2Validation] public string ShipToShipActivitySecurityMattersToReport { get; set; } public string Identifier { get; set; } [JsonIgnore] [Browsable(false)] public string SublistCollectionKey { get { return "s2s"; } } #endregion #region DatabaseEntity implementation public override void PrepareSave(System.Data.IDbCommand cmd) { SqlCommand scmd = cmd as SqlCommand; scmd.Parameters.AddWithValue("@P1", this.SEC.Id); scmd.Parameters.AddWithNullableValue("@P2", this.ShipToShipActivityLocationName); scmd.Parameters.AddWithNullableValue("@P3", this.ShipToShipActivityLocationLoCode); scmd.Parameters.AddWithNullableValue("@P4", this.ShipToShipActivityLocationCoordinatesLatitude); scmd.Parameters.AddWithNullableValue("@P5", this.ShipToShipActivityLocationCoordinatesLongitude); scmd.Parameters.AddWithNullableValue("@P6", this.ShipToShipActivityDateFrom); scmd.Parameters.AddWithNullableValue("@P7", this.ShipToShipActivityDateTo); scmd.Parameters.AddWithNullableValue("@P8", this.ShipToShipActivityType); scmd.Parameters.AddWithNullableValue("@P9", this.ShipToShipActivitySecurityMattersToReport); scmd.Parameters.AddWithNullableValue("@P10", this.Identifier); scmd.Parameters.AddWithNullableValue("@P11", this.ShipToShipActivityTypeCode); if (this.IsNew) { this.CreateId(); scmd.Parameters.AddWithValue("@ID", this.Id); scmd.CommandText = string.Format("INSERT INTO {0} (Id, SEC_Id, ShipToShipActivityLocationName, ShipToShipActivityLocationLoCode, " + "ShipToShipActivityLocationCoordinatesLatitude, ShipToShipActivityLocationCoordinatesLongitude, ShipToShipActivityDateFrom, ShipToShipActivityDateTo, " + "ShipToShipActivityType, ShipToShipActivitySecurityMattersToReport, Identifier, ShipToShipActivityTypeCode) VALUES ( " + "@ID, @P1, @P2, @P3, @P4, @P5, @P6, @P7, @P8, @P9, @P10, @P11)", this.Tablename); } else { scmd.Parameters.AddWithValue("@ID", this.Id); scmd.CommandText = string.Format("UPDATE {0} SET ShipToShipActivityLocationName = @P2, ShipToShipActivityLocationLoCode = @P3, " + "ShipToShipActivityLocationCoordinatesLatitude = @P4, ShipToShipActivityLocationCoordinatesLongitude = @P5, ShipToShipActivityDateFrom = @P6," + "ShipToShipActivityDateTo = @P7, ShipToShipActivityType = @P8, ShipToShipActivitySecurityMattersToReport = @P9, Identifier = @P10, " + "ShipToShipActivityTypeCode = @P11 WHERE Id = @ID", this.Tablename); } } public override void PrepareLoadCommand(System.Data.IDbCommand cmd, Message.LoadFilter filter, params object[] criteria) { string query = string.Format("SELECT Id, ShipToShipActivityLocationName, ShipToShipActivityLocationLoCode, ShipToShipActivityLocationCoordinatesLatitude, " + "ShipToShipActivityLocationCoordinatesLongitude, ShipToShipActivityDateFrom, ShipToShipActivityDateTo, ShipToShipActivityType, " + "ShipToShipActivitySecurityMattersToReport, ShipToShipActivityTypeCode, Identifier FROM {0}", this.Tablename); switch (filter) { case Message.LoadFilter.SEC_ID: query += " WHERE SEC_Id = @SECID"; ((SqlCommand)cmd).Parameters.AddWithValue("@SECID", criteria[0]); break; case Message.LoadFilter.ALL: default: break; } query += " ORDER BY ShipToShipActivityDateFrom DESC"; // jüngster Eintrag zuerst cmd.CommandText = query; } public override List LoadList(System.Data.IDataReader reader) { List result = new List(); while (reader.Read()) { ShipToShipActivitiesDuringLastTenPortFacilitiesCalled sts = new ShipToShipActivitiesDuringLastTenPortFacilitiesCalled(); sts.id = reader.GetGuid(0); if (!reader.IsDBNull(1)) sts.ShipToShipActivityLocationName = reader.GetString(1); if (!reader.IsDBNull(2)) sts.ShipToShipActivityLocationLoCode = reader.GetString(2); if (!reader.IsDBNull(3)) sts.ShipToShipActivityLocationCoordinatesLatitude = reader.GetInt32(3); if (!reader.IsDBNull(4)) sts.ShipToShipActivityLocationCoordinatesLongitude = reader.GetInt32(4); if (!reader.IsDBNull(5)) sts.ShipToShipActivityDateFrom = reader.GetDateTime(5); if (!reader.IsDBNull(6)) sts.ShipToShipActivityDateTo = reader.GetDateTime(6); if (!reader.IsDBNull(7)) sts.ShipToShipActivityType = reader.GetString(7); if (!reader.IsDBNull(8)) sts.ShipToShipActivitySecurityMattersToReport = reader.GetString(8); if (!reader.IsDBNull(9)) sts.ShipToShipActivityTypeCode = reader.GetInt32(9); if (!reader.IsDBNull(10)) sts.Identifier = reader.GetString(10); result.Add(sts); } reader.Close(); return result; } #endregion #region overrides public override ValidationBlock GetValidationBlock() { return ValidationBlock.BLOCK2; } #endregion #region Validate public override void Validate(List errors, List violations) { // check violation 701 bool locationInsufficient = this.ShipToShipActivityLocationLoCode.IsNullOrEmpty() && this.ShipToShipActivityLocationName.IsNullOrEmpty() && !(this.ShipToShipActivityLocationCoordinatesLatitude.HasValue && (this.ShipToShipActivityLocationCoordinatesLatitude.Value != 0) && this.ShipToShipActivityLocationCoordinatesLongitude.HasValue && (this.ShipToShipActivityLocationCoordinatesLongitude.Value != 0)); if (locationInsufficient) { violations.Add(RuleEngine.CreateViolation(ValidationCode.V701, "ShipToShipActivity", null , this.Title, this.Identifier, this.SEC.Tablename)); } if(!this.ShipToShipActivityLocationLoCode.IsNullOrEmpty() && (RuleEngine.LocodeChecker != null)) { if (!RuleEngine.LocodeChecker(this.ShipToShipActivityLocationLoCode, RuleEngine.LocodeMode.STANDARD)) errors.Add(RuleEngine.CreateError(ValidationCode.LOCODE, "ShipToShipActivityLocationLoCode", this.ShipToShipActivityLocationLoCode, this.Title, this.Identifier, this.SEC.Tablename)); } if(this.ShipToShipActivityTypeCode.HasValue) { if ((this.ShipToShipActivityTypeCode.Value < 1) || ((this.ShipToShipActivityTypeCode.Value > 23) && (this.ShipToShipActivityTypeCode.Value != 98))) errors.Add(RuleEngine.CreateError(ValidationCode.IMPLAUSIBLE, "ShipToShipActivityType", this.ShipToShipActivityTypeCode.ToString(), this.Title, this.Identifier, this.SEC.Tablename)); } } #endregion } }