314 lines
14 KiB
C#
314 lines
14 KiB
C#
//
|
|
// Class: STAT
|
|
// Current CLR: 4.0.30319.34209
|
|
// System: Microsoft Visual Studio 10.0
|
|
// Author: dani
|
|
// Created: 3/19/2015 8:59:21 PM
|
|
//
|
|
// Copyright (c) 2015 Informatikbüro Daniel Schick. All rights reserved.
|
|
|
|
using System;
|
|
using System.Data;
|
|
using System.Data.SqlClient;
|
|
using System.Collections.Generic;
|
|
|
|
namespace bsmd.database
|
|
{
|
|
public class STAT : DatabaseEntity
|
|
{
|
|
|
|
public STAT()
|
|
{
|
|
this.tablename = "[dbo].[STAT]";
|
|
}
|
|
|
|
#region Properties
|
|
|
|
[ShowReport]
|
|
[Validation(ValidationCode.NOT_NULL)]
|
|
[LookupName("STAT.ShipName")]
|
|
[MaxLength(100)]
|
|
[ENI2Validation]
|
|
public string ShipName { get; set; }
|
|
|
|
[ShowReport]
|
|
[Validation(ValidationCode.FRZ)]
|
|
[MaxLength(50)]
|
|
[ENI2Validation]
|
|
public string CallSign { get; set; }
|
|
|
|
[ShowReport]
|
|
[Validation(ValidationCode.MMSI)]
|
|
[MaxLength(50)]
|
|
[ENI2Validation]
|
|
public string MMSINumber { get; set; }
|
|
|
|
[ShowReport]
|
|
[Validation(ValidationCode.FLAG_CODE)]
|
|
[MaxLength(2)]
|
|
[ENI2Validation]
|
|
public string Flag { get; set; }
|
|
|
|
[ShowReport]
|
|
[Validation(ValidationCode.DOUBLE_GT_ZERO)]
|
|
[LookupName("STAT.LengthOverall_MTR")]
|
|
[ENI2Validation]
|
|
public double? LengthOverall_MTR { get; set; }
|
|
|
|
[ShowReport]
|
|
[Validation(ValidationCode.DOUBLE_GT_ZERO)]
|
|
[LookupName("STAT.Beam_MTR")]
|
|
[ENI2Validation]
|
|
public double? Beam_MTR { get; set; }
|
|
|
|
[ShowReport]
|
|
[Validation(ValidationCode.DOUBLE_GT_ZERO)]
|
|
[LookupName("STAT.GrossTonnage")]
|
|
[ENI2Validation]
|
|
public int? GrossTonnage { get; set; }
|
|
|
|
[ShowReport]
|
|
[Validation(ValidationCode.LOCODE_NOPORT)]
|
|
[MaxLength(5)]
|
|
[ENI2Validation]
|
|
public string PortOfRegistry { get; set; }
|
|
|
|
[ShowReport]
|
|
[LookupName("STAT.InmarsatCallNumber")]
|
|
[MaxLength(100)]
|
|
[ENI2Validation]
|
|
public string InmarsatCallNumber { get; set; }
|
|
|
|
/// <summary>
|
|
/// UNECE Rec.19 Code (http://www.unece.org/fileadmin/DAM/cefact/recommendations/rec19/rec19_ecetrd138.pdf)
|
|
/// </summary>
|
|
[Validation(ValidationCode.NOT_NULL)]
|
|
[MaxLength(1)]
|
|
[ENI2Validation]
|
|
public string TransportMode { get; set; }
|
|
|
|
[ShowReport]
|
|
public string TransportModeDisplay
|
|
{
|
|
get
|
|
{
|
|
if (!this.TransportMode.IsNullOrEmpty())
|
|
{
|
|
if (this.TransportMode == "1") return "Maritime transport";
|
|
if (this.TransportMode == "8") return "Inland water transport";
|
|
}
|
|
return string.Empty;
|
|
}
|
|
}
|
|
|
|
[ShowReport]
|
|
[Validation(ValidationCode.VESSEL_TYPE)]
|
|
[LookupName("STAT.ShipType")]
|
|
[MaxLength(5)]
|
|
[ENI2Validation]
|
|
public string ShipType { get; set; }
|
|
|
|
[ShowReport]
|
|
[LookupName("STAT.ISMCompanyName")]
|
|
[MaxLength(100)]
|
|
[ENI2Validation]
|
|
public string ISMCompanyName { get; set; }
|
|
|
|
[ShowReport]
|
|
[Validation(ValidationCode.STRING_EXACT_LEN, 7)]
|
|
[MaxLength(10)]
|
|
[ENI2Validation]
|
|
public string ISMCompanyId { get; set; }
|
|
|
|
[ShowReport]
|
|
[LookupName("STAT.ISMCompanyStreetAndNumber")]
|
|
[MaxLength(100)]
|
|
[ENI2Validation]
|
|
public string ISMCompanyStreetAndNumber { get; set; }
|
|
|
|
[ShowReport]
|
|
[LookupName("STAT.ISMCompanyPostalCode")]
|
|
[MaxLength(24)]
|
|
[ENI2Validation]
|
|
public string ISMCompanyPostalCode { get; set; }
|
|
|
|
[ShowReport]
|
|
[LookupName("STAT.ISMCompanyCity")]
|
|
[MaxLength(100)]
|
|
[ENI2Validation]
|
|
public string ISMCompanyCity { get; set; }
|
|
|
|
[ShowReport]
|
|
[LookupName("STAT.ISMCompanyCountry")]
|
|
[MaxLength(100)]
|
|
[ENI2Validation]
|
|
public string ISMCompanyCountry { get; set; }
|
|
|
|
public override string Subtitle
|
|
{
|
|
get
|
|
{
|
|
return "Vessel details";
|
|
}
|
|
}
|
|
|
|
[LookupName("STAT.NetTonnage")]
|
|
[ENI2Validation]
|
|
public double? NetTonnage { get; set; }
|
|
|
|
[LookupName("STAT.RegistryDate")]
|
|
[ENI2Validation]
|
|
public DateTime? RegistryDate { get; set; }
|
|
|
|
[LookupName("STAT.CertificateOfRegistryNumber")]
|
|
[MaxLength(35)]
|
|
[ENI2Validation]
|
|
public string CertificateOfRegistryNumber { get; set; }
|
|
|
|
public static Dictionary<string, string> VesselTypeDict { get; set; }
|
|
|
|
public static Dictionary<string, string> TransportModeDict { get; set; }
|
|
|
|
#endregion
|
|
|
|
#region abstract class implementation
|
|
|
|
public override void PrepareLoadCommand(IDbCommand cmd, Message.LoadFilter filter, params object[] criteria)
|
|
{
|
|
string query = string.Format("SELECT Id, ShipName, Callsign, MMSINumber, Flag, LengthOverall_MTR, Beam_MTR, " +
|
|
"GrossTonnage, PortOfRegistry, InmarsatCallNumber, ShipType, ISMCompanyName, ISMCompanyId, ISMCompanyStreetAndNumber, " +
|
|
"ISMCompanyPostalCode, ISMCompanyCity, ISMCompanyCountry, TransportMode, NetTonnage, RegistryDate, " +
|
|
"CertificateOfRegistryNumber 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<DatabaseEntity> LoadList(System.Data.IDataReader reader)
|
|
{
|
|
List<DatabaseEntity> result = new List<DatabaseEntity>();
|
|
|
|
while(reader.Read())
|
|
{
|
|
STAT stat = new STAT();
|
|
|
|
stat.id = reader.GetGuid(0);
|
|
|
|
if (!reader.IsDBNull(1)) stat.ShipName = reader.GetString(1);
|
|
if (!reader.IsDBNull(2)) stat.CallSign = reader.GetString(2);
|
|
if (!reader.IsDBNull(3)) stat.MMSINumber = reader.GetString(3);
|
|
if (!reader.IsDBNull(4)) stat.Flag = reader.GetString(4);
|
|
if (!reader.IsDBNull(5)) stat.LengthOverall_MTR = (float) reader.GetDouble(5);
|
|
if (!reader.IsDBNull(6)) stat.Beam_MTR = (float) reader.GetDouble(6);
|
|
if (!reader.IsDBNull(7)) stat.GrossTonnage = reader.GetInt32(7);
|
|
if (!reader.IsDBNull(8)) stat.PortOfRegistry = reader.GetString(8);
|
|
if (!reader.IsDBNull(9)) stat.InmarsatCallNumber = reader.GetString(9);
|
|
if (!reader.IsDBNull(10)) stat.ShipType = reader.GetString(10);
|
|
if (!reader.IsDBNull(11)) stat.ISMCompanyName = reader.GetString(11);
|
|
if (!reader.IsDBNull(12)) stat.ISMCompanyId = reader.GetString(12);
|
|
if (!reader.IsDBNull(13)) stat.ISMCompanyStreetAndNumber = reader.GetString(13);
|
|
if (!reader.IsDBNull(14)) stat.ISMCompanyPostalCode = reader.GetString(14);
|
|
if (!reader.IsDBNull(15)) stat.ISMCompanyCity = reader.GetString(15);
|
|
if (!reader.IsDBNull(16)) stat.ISMCompanyCountry = reader.GetString(16);
|
|
if (!reader.IsDBNull(17)) stat.TransportMode = reader.GetString(17);
|
|
if (!reader.IsDBNull(18)) stat.NetTonnage = (float) reader.GetDouble(18);
|
|
if (!reader.IsDBNull(19)) stat.RegistryDate = reader.GetDateTime(19);
|
|
if (!reader.IsDBNull(20)) stat.CertificateOfRegistryNumber = reader.GetString(20);
|
|
|
|
result.Add(stat);
|
|
}
|
|
reader.Close();
|
|
return result;
|
|
}
|
|
|
|
public override void PrepareSave(IDbCommand cmd)
|
|
{
|
|
SqlCommand scmd = cmd as SqlCommand;
|
|
|
|
scmd.Parameters.AddWithValue("@P1", this.MessageHeader.Id);
|
|
if (this.ShipName != null) scmd.Parameters.AddWithValue("@P2", this.ShipName);
|
|
else scmd.Parameters.AddWithValue("@P2", DBNull.Value);
|
|
if (this.CallSign != null) scmd.Parameters.AddWithValue("@P3", this.CallSign);
|
|
else scmd.Parameters.AddWithValue("@P3", DBNull.Value);
|
|
if (this.MMSINumber != null) scmd.Parameters.AddWithValue("@P4", this.MMSINumber);
|
|
else scmd.Parameters.AddWithValue("@P4", DBNull.Value);
|
|
if (this.Flag != null) scmd.Parameters.AddWithValue("@P5", this.Flag);
|
|
else scmd.Parameters.AddWithValue("@P5", DBNull.Value);
|
|
if (this.LengthOverall_MTR.HasValue) scmd.Parameters.AddWithValue("@P6", (double) this.LengthOverall_MTR.Value);
|
|
else scmd.Parameters.AddWithValue("@P6", DBNull.Value);
|
|
if (this.Beam_MTR.HasValue) scmd.Parameters.AddWithValue("@P7", (double) this.Beam_MTR.Value);
|
|
else scmd.Parameters.AddWithValue("@P7", DBNull.Value);
|
|
if (this.GrossTonnage.HasValue) scmd.Parameters.AddWithValue("@P8", this.GrossTonnage.Value);
|
|
else scmd.Parameters.AddWithValue("@P8", DBNull.Value);
|
|
if (this.PortOfRegistry != null) scmd.Parameters.AddWithValue("@P9", this.PortOfRegistry);
|
|
else scmd.Parameters.AddWithValue("@P9", DBNull.Value);
|
|
if (this.InmarsatCallNumber != null) scmd.Parameters.AddWithValue("@P10", this.InmarsatCallNumber);
|
|
else scmd.Parameters.AddWithValue("@P10", DBNull.Value);
|
|
if (this.ShipType != null) scmd.Parameters.AddWithValue("@P11", this.ShipType);
|
|
else scmd.Parameters.AddWithValue("@P11", DBNull.Value);
|
|
if (this.ISMCompanyName != null) scmd.Parameters.AddWithValue("@P12", this.ISMCompanyName);
|
|
else scmd.Parameters.AddWithValue("@P12", DBNull.Value);
|
|
if (this.ISMCompanyId != null) scmd.Parameters.AddWithValue("@P13", this.ISMCompanyId);
|
|
else scmd.Parameters.AddWithValue("@P13", DBNull.Value);
|
|
if (this.ISMCompanyStreetAndNumber != null) scmd.Parameters.AddWithValue("@P14", this.ISMCompanyStreetAndNumber);
|
|
else scmd.Parameters.AddWithValue("@P14", DBNull.Value);
|
|
if (this.ISMCompanyPostalCode != null) scmd.Parameters.AddWithValue("@P15", this.ISMCompanyPostalCode);
|
|
else scmd.Parameters.AddWithValue("@P15", DBNull.Value);
|
|
if (this.ISMCompanyCity != null) scmd.Parameters.AddWithValue("@P16", this.ISMCompanyCity);
|
|
else scmd.Parameters.AddWithValue("@P16", DBNull.Value);
|
|
if (this.ISMCompanyCountry != null) scmd.Parameters.AddWithValue("@P17", this.ISMCompanyCountry);
|
|
else scmd.Parameters.AddWithValue("@P17", DBNull.Value);
|
|
if (this.TransportMode != null) scmd.Parameters.AddWithValue("@P18", this.TransportMode);
|
|
else scmd.Parameters.AddWithValue("@P18", DBNull.Value);
|
|
scmd.Parameters.AddWithNullableValue("@P19", this.NetTonnage);
|
|
scmd.Parameters.AddWithNullableValue("@P20", this.RegistryDate);
|
|
scmd.Parameters.AddWithNullableValue("@P21", this.CertificateOfRegistryNumber);
|
|
|
|
if (this.IsNew)
|
|
{
|
|
this.CreateId();
|
|
scmd.Parameters.AddWithValue("@ID", this.Id);
|
|
cmd.CommandText = string.Format("INSERT INTO {0} (Id, MessageHeaderId, ShipName, CallSign, MMSINumber, " +
|
|
"Flag, LengthOverall_MTR, Beam_MTR, GrossTonnage, PortOfRegistry, InmarsatCallNumber, ShipType, " +
|
|
"ISMCompanyName, ISMCompanyId, ISMCompanyStreetAndNumber, ISMCompanyPostalCode, ISMCompanyCity, " +
|
|
"ISMCompanyCountry, TransportMode, NetTonnage, RegistryDate, CertificateOfRegistryNumber) " +
|
|
"VALUES (@ID, @P1, @P2, @P3, @P4, @P5, @P6, @P7, @P8, @P9, @P10, @P11, " +
|
|
" @P12, @P13, @P14, @P15, @P16, @P17, @P18, @P19, @P20, @P21)", this.Tablename);
|
|
}
|
|
else
|
|
{
|
|
cmd.CommandText = string.Format("UPDATE {0} SET ShipName = @P2, CallSign = @P3, MMSINumber = @P4, Flag = @P5, " +
|
|
"LengthOverall_MTR = @P6, Beam_MTR = @P7, GrossTonnage = @P8, PortOfRegistry = @P9, InmarsatCallNumber = @P10, " +
|
|
"ShipType = @P11, ISMCompanyName = @P12, ISMCompanyId = @P13, ISMCompanyStreetAndNumber = @P14, " +
|
|
"ISMCompanyPostalCode = @P15, ISMCompanyCity = @P16, ISMCompanyCountry = @P17, TransportMode = @P18, " +
|
|
"NetTonnage = @P19, RegistryDate = @P20, CertificateOfRegistryNumber = @P21 WHERE Id = @ID", this.Tablename);
|
|
scmd.Parameters.AddWithValue("@ID", this.Id);
|
|
}
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Validation
|
|
|
|
public override void Validate(List<MessageError> errors, List<MessageViolation> violations)
|
|
{
|
|
if ((this.GrossTonnage.HasValue && (this.GrossTonnage.Value >= 500)) && (this.ISMCompanyName.IsNullOrEmpty() || this.ISMCompanyId.IsNullOrEmpty()))
|
|
violations.Add(RuleEngine.CreateViolation(ValidationCode.V821, "ISMCompanyId/Name must be provided", null, this.Title, null, this.Tablename));
|
|
}
|
|
|
|
#endregion
|
|
|
|
}
|
|
}
|