git_bsmd/nsw/Source/bsmd.database/STAT.cs

270 lines
12 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)]
public string ShipName { get; set; }
[ShowReport]
[Validation(ValidationCode.NOT_NULL)]
[LookupName("STAT.CallSign")]
[MaxLength(50)]
public string CallSign { get; set; }
[ShowReport]
[Validation(ValidationCode.NOT_NULL)]
[LookupName("STAT.MMSINumber")]
[MaxLength(50)]
public string MMSINumber { get; set; }
[ShowReport]
[Validation(ValidationCode.FLAG_CODE)]
[LookupName("STAT.Flag")]
[MaxLength(2)]
public string Flag { get; set; }
[ShowReport]
[Validation(ValidationCode.DOUBLE_GT_ZERO)]
[LookupName("STAT.LengthOverall_MTR")]
public double? LengthOverall_MTR { get; set; }
[ShowReport]
[Validation(ValidationCode.DOUBLE_GT_ZERO)]
[LookupName("STAT.Beam_MTR")]
public double? Beam_MTR { get; set; }
[ShowReport]
[Validation(ValidationCode.DOUBLE_GT_ZERO)]
[LookupName("STAT.GrossTonnage")]
public int? GrossTonnage { get; set; }
[ShowReport]
[Validation(ValidationCode.LOCODE)]
[LookupName("STAT.PortOfRegistry")]
[MaxLength(5)]
public string PortOfRegistry { get; set; }
[ShowReport]
[MaxLength(100)]
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)]
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.NOT_NULL)]
[LookupName("STAT.ShipType")]
[MaxLength(5)]
public string ShipType { get; set; }
[ShowReport]
[LookupName("STAT.ISMCompanyName")]
[MaxLength(100)]
public string ISMCompanyName { get; set; }
[ShowReport]
[Validation(ValidationCode.STRING_EXACT_LEN, 7)]
[LookupName("STAT.ISMCompanyId")]
[MaxLength(10)]
public string ISMCompanyId { get; set; }
[ShowReport]
[MaxLength(100)]
public string ISMCompanyStreetAndNumber { get; set; }
[ShowReport]
[MaxLength(24)]
public string ISMCompanyPostalCode { get; set; }
[ShowReport]
[MaxLength(100)]
public string ISMCompanyCity { get; set; }
[ShowReport]
[MaxLength(100)]
public string ISMCompanyCountry { get; set; }
public override string Subtitle
{
get
{
return "Vessel details";
}
}
#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 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);
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);
if (this.IsNew)
{
cmd.CommandText = string.Format("INSERT INTO {0} (MessageHeaderId, ShipName, CallSign, MMSINumber, " +
"Flag, LengthOverall_MTR, Beam_MTR, GrossTonnage, PortOfRegistry, InmarsatCallNumber, ShipType, " +
"ISMCompanyName, ISMCompanyId, ISMCompanyStreetAndNumber, ISMCompanyPostalCode, ISMCompanyCity, " +
"ISMCompanyCountry, TransportMode) VALUES (@P1, @P2, @P3, @P4, @P5, @P6, @P7, @P8, @P9, @P10, @P11, " +
" @P12, @P13, @P14, @P15, @P16, @P17, @P18)", 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 " +
"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.ISMCompanyName.IsNullOrEmpty() || this.ISMCompanyId.IsNullOrEmpty())
violations.Add(RuleEngine.CreateViolation(ValidationCode.V821, "For BRZ > 500 ISM company information must be provider", null));
}
#endregion
}
}