285 lines
14 KiB
C#
285 lines
14 KiB
C#
//
|
|
// Class: IMDGPosition
|
|
// Current CLR: 4.0.30319.34209
|
|
// System: Microsoft Visual Studio 10.0
|
|
// Author: dani
|
|
// Created: 5/26/2015 8:56:57 PM
|
|
//
|
|
// Copyright (c) 2015 Informatikbüro Daniel Schick. All rights reserved.
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Data.SqlClient;
|
|
|
|
namespace bsmd.database
|
|
{
|
|
public class IMDGPosition : DatabaseEntity, ISublistElement
|
|
{
|
|
|
|
private List<SubsidiaryRisks> subsidiaryRisksList = new List<SubsidiaryRisks>();
|
|
|
|
public IMDGPosition()
|
|
{
|
|
this.tablename = "[dbo].[IMDGPosition]";
|
|
}
|
|
|
|
#region Properties
|
|
|
|
public HAZ HAZ { get; set; }
|
|
[ShowReport]
|
|
[Validation(ValidationCode.NOT_NULL)]
|
|
public string UNNumber { get; set; }
|
|
[ShowReport]
|
|
public byte? PackingGroup { get; set; }
|
|
[ShowReport]
|
|
[Validation(ValidationCode.NOT_NULL)]
|
|
public string ProperShippingName { get; set; }
|
|
[ShowReport]
|
|
[Validation(ValidationCode.NOT_NULL)]
|
|
public string IMOClass { get; set; }
|
|
[ShowReport]
|
|
public string CompatibilityGroup { get; set; }
|
|
[ShowReport]
|
|
public string TechnicalName { get; set; }
|
|
[ShowReport]
|
|
public double? NetExplosiveMass_KGM { get; set; }
|
|
[ShowReport]
|
|
public string Flashpoint_CEL { get; set; }
|
|
[ShowReport]
|
|
public string Class7NuclideName { get; set; }
|
|
[ShowReport]
|
|
public double? Class7MaxActivity_BQL { get; set; }
|
|
[ShowReport]
|
|
public int? Class7Category { get; set; }
|
|
[ShowReport]
|
|
public double? Class7TransportIndex { get; set; }
|
|
[ShowReport]
|
|
public int? Class7CSI { get; set; }
|
|
[ShowReport]
|
|
public double? ControlTemperature_CEL { get; set; }
|
|
[ShowReport]
|
|
public double? EmergencyTemperature_CEL { get; set; }
|
|
[ShowReport]
|
|
[Validation(ValidationCode.NOT_NULL)]
|
|
public bool? MarinePollutant { get; set; }
|
|
[ShowReport]
|
|
[Validation(ValidationCode.NOT_NULL)]
|
|
public int? NumberOfPackages { get; set; }
|
|
[ShowReport]
|
|
[Validation(ValidationCode.NOT_NULL)]
|
|
public string PackageType { get; set; }
|
|
[ShowReport]
|
|
[Validation(ValidationCode.NOT_NULL)]
|
|
public bool? LimitedQuantities { get; set; }
|
|
[ShowReport]
|
|
[Validation(ValidationCode.NOT_NULL)]
|
|
public bool? ExceptedQuantities { get; set; }
|
|
[ShowReport]
|
|
public double? NetQuantity_KGM { get; set; }
|
|
[ShowReport]
|
|
public double? GrossQuantity_KGM { get; set; }
|
|
[ShowReport]
|
|
public double? Volume_MTQ { get; set; }
|
|
[ShowReport]
|
|
public bool? GeneralCargoIBC { get; set; }
|
|
[ShowReport]
|
|
public string ContainerNumber { get; set; }
|
|
[ShowReport]
|
|
public string VehicleLicenseNumber { get; set; }
|
|
[ShowReport]
|
|
[Validation(ValidationCode.NOT_NULL)]
|
|
public string StowagePosition { get; set; }
|
|
[ShowReport]
|
|
[Validation(ValidationCode.LOCODE)]
|
|
public string PortOfLoading { get; set; }
|
|
[ShowReport]
|
|
[Validation(ValidationCode.LOCODE)]
|
|
public string PortOfDischarge { get; set; }
|
|
[ShowReport]
|
|
public string Remarks { get; set; }
|
|
|
|
public List<SubsidiaryRisks> SubsidiaryRiskList { get { return this.subsidiaryRisksList; } }
|
|
|
|
public string Identifier { get; set; }
|
|
|
|
#endregion
|
|
|
|
#region DatabaseEntity implementation
|
|
|
|
public override void PrepareSave(IDbCommand cmd)
|
|
{
|
|
SqlCommand scmd = cmd as SqlCommand;
|
|
|
|
scmd.Parameters.AddWithValue("@P1", this.HAZ.Id);
|
|
scmd.Parameters.AddWithNullableValue("@P2", this.UNNumber);
|
|
scmd.Parameters.AddWithNullableValue("@P3", this.PackingGroup);
|
|
scmd.Parameters.AddWithNullableValue("@P4", this.ProperShippingName);
|
|
scmd.Parameters.AddWithNullableValue("@P5", this.IMOClass);
|
|
scmd.Parameters.AddWithNullableValue("@P6", this.CompatibilityGroup);
|
|
scmd.Parameters.AddWithNullableValue("@P7", this.TechnicalName);
|
|
scmd.Parameters.AddWithNullableValue("@P8", this.NetExplosiveMass_KGM);
|
|
scmd.Parameters.AddWithNullableValue("@P9", this.Flashpoint_CEL);
|
|
scmd.Parameters.AddWithNullableValue("@P10", this.Class7NuclideName);
|
|
scmd.Parameters.AddWithNullableValue("@P11", this.Class7MaxActivity_BQL);
|
|
scmd.Parameters.AddWithNullableValue("@P12", this.Class7Category);
|
|
scmd.Parameters.AddWithNullableValue("@P13", this.Class7TransportIndex);
|
|
scmd.Parameters.AddWithNullableValue("@P14", this.Class7CSI);
|
|
scmd.Parameters.AddWithNullableValue("@P15", this.ControlTemperature_CEL);
|
|
scmd.Parameters.AddWithNullableValue("@P16", this.EmergencyTemperature_CEL);
|
|
scmd.Parameters.AddWithNullableValue("@P17", this.MarinePollutant);
|
|
scmd.Parameters.AddWithNullableValue("@P18", this.NumberOfPackages);
|
|
scmd.Parameters.AddWithNullableValue("@P19", this.PackageType);
|
|
scmd.Parameters.AddWithNullableValue("@P20", this.LimitedQuantities);
|
|
scmd.Parameters.AddWithNullableValue("@P21", this.ExceptedQuantities);
|
|
scmd.Parameters.AddWithNullableValue("@P22", this.NetQuantity_KGM);
|
|
scmd.Parameters.AddWithNullableValue("@P23", this.GrossQuantity_KGM);
|
|
scmd.Parameters.AddWithNullableValue("@P24", this.Volume_MTQ);
|
|
scmd.Parameters.AddWithNullableValue("@P25", this.GeneralCargoIBC);
|
|
scmd.Parameters.AddWithNullableValue("@P26", this.ContainerNumber);
|
|
scmd.Parameters.AddWithNullableValue("@P27", this.VehicleLicenseNumber);
|
|
scmd.Parameters.AddWithNullableValue("@P28", this.StowagePosition);
|
|
scmd.Parameters.AddWithNullableValue("@P29", this.PortOfLoading);
|
|
scmd.Parameters.AddWithNullableValue("@P30", this.PortOfDischarge);
|
|
scmd.Parameters.AddWithNullableValue("@P31", this.Remarks);
|
|
scmd.Parameters.AddWithNullableValue("@P32", this.Identifier);
|
|
|
|
if (this.IsNew)
|
|
{
|
|
this.CreateId();
|
|
scmd.Parameters.AddWithValue("@ID", this.Id);
|
|
scmd.CommandText = string.Format("INSERT INTO {0} (HAZId, UNNumber, " +
|
|
"PackingGroup, ProperShippingName, IMOClass, CompatibilityGroup, TechnicalName, NetExplosiveMass_KGM," +
|
|
"Flashpoint_CEL, Class7NuclideName, Class7MaxActivity_BQL, Class7Category, Class7TransportIndex, " +
|
|
"Class7CSI, ControlTemperature_CEL, EmergencyTemperature_CEL, MarinePollutant, NumberOfPackages, " +
|
|
"PackageType, LimitedQuantities, ExceptedQuantities, NetQuantity_KGM, GrossQuantity_KGM, Volume_MTQ, " +
|
|
"GeneralCargoIBC, ContainerNumber, VehicleLicenseNumber, StowagePosition, PortOfLoading, PortOfDischarge, " +
|
|
"Remarks, Identifier) VALUES (@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, @P26, @P27, @P28, @P29, @P30, " +
|
|
"@P31, @P32)", this.Tablename);
|
|
}
|
|
else
|
|
{
|
|
scmd.Parameters.AddWithValue(@"ID", this.Id);
|
|
scmd.CommandText = string.Format("UPDATE {0} SET UNNumber = @P2, PackingGroup = @P3, ProperShippingName = @P4, " +
|
|
"IMOClass = @P5, CompatibilityGroup = @P6, TechnicalName = @P7, NetExplosiveMass_KGM = @P8, " +
|
|
"Flashpoint_CEL = @P9, Class7NuclideName = @P10, Class7MaxActivity_BQL = @P11, Class7Category = @P12, " +
|
|
"Class7TransportIndex = @P13, Class7CSI = @P14, ControlTemperature_CEL = @P15, EmergencyTemperature_CEL = @P16, " +
|
|
"MarinePollutant = @P17, NumberOfPackages = @P18, PackageType = @P19, LimitedQuantities = @P20, ExceptedQuantities = @P21, " +
|
|
"NetQuantity_KGM = @P22, GrossQuantity_KGM = @P23, Volume_MTQ = @P24, GeneralCargoIBC = @P25, ContainerNumber = @P26, " +
|
|
"VehicleLicenseNumber = @P27, StowagePosition = @P28, PortOfLoading = @P29, PortOfDischarge = @P30, Remarks = @P31, " +
|
|
"Identifier = @P32 WHERE Id = @ID", this.Tablename);
|
|
}
|
|
|
|
}
|
|
|
|
public override void PrepareLoadCommand(IDbCommand cmd, Message.LoadFilter filter, params object[] criteria)
|
|
{
|
|
string query = string.Format("SELECT Id, UNNumber, PackingGroup, ProperShippingName, IMOClass, CompatibilityGroup, " +
|
|
"TechnicalName, NetExplosiveMass_KGM, Flashpoint_CEL, Class7NuclideName, Class7MaxActivity_BQL, Class7Category, " +
|
|
"Class7TransportIndex, Class7CSI, ControlTemperature_CEL, EmergencyTemperature_CEL, MarinePollutant, NumberOfPackages, " +
|
|
"PackageType, LimitedQuantities, ExceptedQuantities, NetQuantity_KGM, GrossQuantity_KGM, Volume_MTQ, GeneralCargoIBC, " +
|
|
"ContainerNumber, VehicleLicenseNumber, StowagePosition, PortOfLoading, PortOfDischarge, Remarks, Identifier " +
|
|
"FROM {0} ", this.Tablename);
|
|
|
|
switch (filter)
|
|
{
|
|
case Message.LoadFilter.HAZ_ID:
|
|
query += " WHERE HAZId = @HAZID";
|
|
((SqlCommand)cmd).Parameters.AddWithValue("@HAZID", criteria[0]);
|
|
break;
|
|
case Message.LoadFilter.ALL:
|
|
default:
|
|
|
|
break;
|
|
}
|
|
|
|
cmd.CommandText = query;
|
|
}
|
|
|
|
public override List<DatabaseEntity> LoadList(IDataReader reader)
|
|
{
|
|
List<DatabaseEntity> result = new List<DatabaseEntity>();
|
|
|
|
while (reader.Read())
|
|
{
|
|
IMDGPosition imdg = new IMDGPosition();
|
|
|
|
imdg.id = reader.GetGuid(0);
|
|
if(!reader.IsDBNull(1)) imdg.UNNumber = reader.GetString(1);
|
|
if (!reader.IsDBNull(2)) imdg.PackingGroup = reader.GetByte(2);
|
|
if (!reader.IsDBNull(3)) imdg.ProperShippingName = reader.GetString(3);
|
|
if (!reader.IsDBNull(4)) imdg.IMOClass = reader.GetString(4);
|
|
if (!reader.IsDBNull(5)) imdg.CompatibilityGroup = reader.GetString(5);
|
|
if (!reader.IsDBNull(6)) imdg.TechnicalName = reader.GetString(6);
|
|
if (!reader.IsDBNull(7)) imdg.NetExplosiveMass_KGM = reader.GetDouble(7);
|
|
if (!reader.IsDBNull(8)) imdg.Flashpoint_CEL = reader.GetString(8);
|
|
if (!reader.IsDBNull(9)) imdg.Class7NuclideName = reader.GetString(9);
|
|
if (!reader.IsDBNull(10)) imdg.Class7MaxActivity_BQL = reader.GetDouble(10);
|
|
if (!reader.IsDBNull(11)) imdg.Class7Category = reader.GetInt32(11);
|
|
if (!reader.IsDBNull(12)) imdg.Class7TransportIndex = reader.GetDouble(12);
|
|
if (!reader.IsDBNull(13)) imdg.Class7CSI = reader.GetInt32(13);
|
|
if (!reader.IsDBNull(14)) imdg.ControlTemperature_CEL = reader.GetDouble(14);
|
|
if (!reader.IsDBNull(15)) imdg.EmergencyTemperature_CEL = reader.GetDouble(15);
|
|
if (!reader.IsDBNull(16)) imdg.MarinePollutant = reader.GetBoolean(16);
|
|
if (!reader.IsDBNull(17)) imdg.NumberOfPackages = reader.GetInt32(17);
|
|
if (!reader.IsDBNull(18)) imdg.PackageType = reader.GetString(18);
|
|
if (!reader.IsDBNull(19)) imdg.LimitedQuantities = reader.GetBoolean(19);
|
|
if (!reader.IsDBNull(20)) imdg.ExceptedQuantities = reader.GetBoolean(20);
|
|
if (!reader.IsDBNull(21)) imdg.NetQuantity_KGM = reader.GetDouble(21);
|
|
if (!reader.IsDBNull(22)) imdg.GrossQuantity_KGM = reader.GetDouble(22);
|
|
if (!reader.IsDBNull(23)) imdg.Volume_MTQ = reader.GetDouble(23);
|
|
if (!reader.IsDBNull(24)) imdg.GeneralCargoIBC = reader.GetBoolean(24);
|
|
if (!reader.IsDBNull(25)) imdg.ContainerNumber = reader.GetString(25);
|
|
if (!reader.IsDBNull(26)) imdg.VehicleLicenseNumber = reader.GetString(26);
|
|
if (!reader.IsDBNull(27)) imdg.StowagePosition = reader.GetString(27);
|
|
if (!reader.IsDBNull(28)) imdg.PortOfLoading = reader.GetString(28);
|
|
if (!reader.IsDBNull(29)) imdg.PortOfDischarge = reader.GetString(29);
|
|
if (!reader.IsDBNull(30)) imdg.Remarks = reader.GetString(30);
|
|
if (!reader.IsDBNull(31)) imdg.Identifier = reader.GetString(31);
|
|
|
|
result.Add(imdg);
|
|
}
|
|
reader.Close();
|
|
return result;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region IMessageParagraph implementation
|
|
|
|
public override List<IMessageParagraph> ChildParagraphs
|
|
{
|
|
get
|
|
{
|
|
List<IMessageParagraph> result = new List<IMessageParagraph>();
|
|
foreach (IMessageParagraph imp in this.SubsidiaryRiskList)
|
|
result.Add(imp);
|
|
return result;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Validation
|
|
|
|
public override void Validate(List<MessageError> errors, List<MessageViolation> violations)
|
|
{
|
|
|
|
if (!this.NetQuantity_KGM.HasValue && !this.GrossQuantity_KGM.HasValue && !this.Volume_MTQ.HasValue)
|
|
violations.Add(RuleEngine.CreateViolation(ValidationCode.V802,
|
|
"at least on of NetQuantity, Grossquantity or Volume_MTQ has to be provided", null));
|
|
|
|
if ((this.GeneralCargoIBC ?? false) && this.ContainerNumber.IsNullOrEmpty() && this.VehicleLicenseNumber.IsNullOrEmpty())
|
|
violations.Add(RuleEngine.CreateViolation(ValidationCode.V808,
|
|
"at least Container number or Vehicle license number has to be provided for GeneralCargoIBC", null));
|
|
|
|
foreach (SubsidiaryRisks sr in this.SubsidiaryRiskList)
|
|
RuleEngine.ValidateProperties(sr, errors);
|
|
}
|
|
|
|
#endregion
|
|
|
|
}
|
|
}
|