226 lines
8.4 KiB
C#
226 lines
8.4 KiB
C#
//
|
|
// Class: MARPOL_Annex_I_Position
|
|
// Current CLR: 4.0.30319.34209
|
|
// System: Microsoft Visual Studio 10.0
|
|
// Author: dani
|
|
// Created: 5/27/2015 9:59:28 AM
|
|
//
|
|
// Copyright (c) 2015 Informatikbüro Daniel Schick. All rights reserved.
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Data.SqlClient;
|
|
using System.Text.RegularExpressions;
|
|
using Newtonsoft.Json;
|
|
|
|
namespace bsmd.database
|
|
{
|
|
|
|
[TypeConverter(typeof(MessageClassConverter<MARPOL_Annex_I_Position>))]
|
|
[JsonConverter(typeof(NoTypeConverterJsonConverter<MARPOL_Annex_I_Position>))]
|
|
public class MARPOL_Annex_I_Position : DatabaseEntity, ISublistElement
|
|
{
|
|
|
|
public MARPOL_Annex_I_Position()
|
|
{
|
|
this.tablename = "[dbo].[MARPOL_Annex_IPosition]";
|
|
}
|
|
|
|
#region Properties
|
|
|
|
[JsonIgnore]
|
|
[Browsable(false)]
|
|
public HAZ HAZ { get; set; }
|
|
|
|
[ShowReport]
|
|
[Validation(ValidationCode.NOT_NULL)]
|
|
[MaxLength(255)]
|
|
[ENI2Validation]
|
|
public string Name { get; set; }
|
|
|
|
[Validation(ValidationCode.NOT_NULL)]
|
|
[ENI2Validation]
|
|
public byte? FlashpointInformation { get; set; }
|
|
|
|
[ShowReport]
|
|
[ReportDisplayName("FlashpointInformation")]
|
|
public string FlashpointInformationDisplay
|
|
{
|
|
get
|
|
{
|
|
if (this.FlashpointInformation.HasValue && (this.FlashpointInformation.Value < IBCPosition.flashpointInformations.Length))
|
|
return IBCPosition.flashpointInformations[this.FlashpointInformation.Value];
|
|
return "";
|
|
}
|
|
}
|
|
|
|
[ShowReport]
|
|
[MaxLength(10)]
|
|
[ENI2Validation]
|
|
[Validation(ValidationCode.DOT_NO_COMMA)]
|
|
public string Flashpoint_CEL { get; set; }
|
|
|
|
[ShowReport]
|
|
[Validation(ValidationCode.DOUBLE_GT_ZERO)]
|
|
[ENI2Validation]
|
|
public double? Quantity_KGM { get; set; }
|
|
|
|
[ShowReport]
|
|
[Validation(ValidationCode.NOT_NULL)]
|
|
[MaxLength(24)]
|
|
[ENI2Validation]
|
|
public string StowagePosition { get; set; }
|
|
|
|
[ShowReport]
|
|
[Validation(ValidationCode.LOCODE)]
|
|
[MaxLength(5)]
|
|
[ENI2Validation]
|
|
public string PortOfLoading { get; set; }
|
|
|
|
[ShowReport]
|
|
[Validation(ValidationCode.LOCODE)]
|
|
[ENI2Validation]
|
|
[MaxLength(5)]
|
|
public string PortOfDischarge { get; set; }
|
|
|
|
[ShowReport]
|
|
[MaxLength(255)]
|
|
[ENI2Validation]
|
|
public string Remarks { get; set; }
|
|
|
|
public string Identifier { get; set; }
|
|
|
|
[JsonIgnore]
|
|
[Browsable(false)]
|
|
public string SublistCollectionKey { get { return "marpol"; } }
|
|
|
|
#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.Name);
|
|
scmd.Parameters.AddWithNullableValue("@P3", this.FlashpointInformation);
|
|
scmd.Parameters.AddWithNullableValue("@P4", this.Flashpoint_CEL);
|
|
scmd.Parameters.AddWithNullableValue("@P5", this.Quantity_KGM);
|
|
scmd.Parameters.AddWithNullableValue("@P6", this.StowagePosition);
|
|
scmd.Parameters.AddWithNullableValue("@P7", this.PortOfLoading);
|
|
scmd.Parameters.AddWithNullableValue("@P8", this.PortOfDischarge);
|
|
scmd.Parameters.AddWithNullableValue("@P9", this.Remarks);
|
|
scmd.Parameters.AddWithNullableValue("@P10", this.Identifier);
|
|
|
|
if (this.IsNew)
|
|
{
|
|
this.CreateId();
|
|
scmd.Parameters.AddWithValue("@ID", this.Id);
|
|
scmd.CommandText = string.Format("INSERT INTO {0} (Id, HAZId, Name, FlashpointInformation, Flashpoint_CEL, " +
|
|
"Quantity_KGM, StowagePosition, PortOfLoading, PortOfDischarge, Remarks, Identifier) VALUES " +
|
|
"(@ID, @P1, @P2, @P3, @P4, @P5, @P6, @P7, @P8, @P9, @P10)", this.Tablename);
|
|
}
|
|
else
|
|
{
|
|
scmd.Parameters.AddWithValue("@ID", this.Id);
|
|
scmd.CommandText = string.Format("UPDATE {0} SET Name = @P2, FlashpointInformation= @P3, Flashpoint_CEL = @P4, " +
|
|
"Quantity_KGM = @P5, StowagePosition = @P6, PortOfLoading = @P7, PortOfDischarge = @P8, Remarks = @P9, " +
|
|
"Identifier = @P10 WHERE Id = @ID", this.Tablename);
|
|
}
|
|
|
|
}
|
|
|
|
public override void PrepareLoadCommand(IDbCommand cmd, Message.LoadFilter filter, params object[] criteria)
|
|
{
|
|
string query = string.Format("SELECT Id, Name, FlashpointInformation, Flashpoint_CEL, Quantity_KGM, " +
|
|
"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;
|
|
}
|
|
|
|
query += " ORDER BY Identifier";
|
|
|
|
cmd.CommandText = query;
|
|
|
|
}
|
|
|
|
public override List<DatabaseEntity> LoadList(IDataReader reader)
|
|
{
|
|
List<DatabaseEntity> result = new List<DatabaseEntity>();
|
|
|
|
while (reader.Read())
|
|
{
|
|
MARPOL_Annex_I_Position map = new MARPOL_Annex_I_Position();
|
|
map.id = reader.GetGuid(0);
|
|
if (!reader.IsDBNull(1)) map.Name = reader.GetString(1);
|
|
if (!reader.IsDBNull(2)) map.FlashpointInformation = reader.GetByte(2);
|
|
if (!reader.IsDBNull(3)) map.Flashpoint_CEL = reader.GetString(3);
|
|
if (!reader.IsDBNull(4)) map.Quantity_KGM = reader.GetDouble(4);
|
|
if (!reader.IsDBNull(5)) map.StowagePosition = reader.GetString(5);
|
|
if (!reader.IsDBNull(6)) map.PortOfLoading = reader.GetString(6);
|
|
if (!reader.IsDBNull(7)) map.PortOfDischarge = reader.GetString(7);
|
|
if (!reader.IsDBNull(8)) map.Remarks = reader.GetString(8);
|
|
if (!reader.IsDBNull(9)) map.Identifier = reader.GetString(9);
|
|
|
|
result.Add(map);
|
|
}
|
|
reader.Close();
|
|
return result;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Validation
|
|
|
|
public override void Validate(List<MessageError> errors, List<MessageViolation> violations)
|
|
{
|
|
if (this.FlashpointInformation.HasValue && (this.FlashpointInformation.Value == 2) &&
|
|
this.Flashpoint_CEL.IsNullOrEmpty())
|
|
violations.Add(RuleEngine.CreateViolation(ValidationCode.V804, "Flashpoint_CEL", null, this.Title, this.Identifier,
|
|
this.HAZ.IsDeparture ? "HAZD" : "HAZA"));
|
|
|
|
if (!this.Flashpoint_CEL.IsNullOrEmpty())
|
|
{
|
|
const string pattern = @"^[<>]?\-?[0-9]+(\.[0-9]+)?$";
|
|
Regex regex = new Regex(pattern);
|
|
|
|
if (!regex.IsMatch(this.Flashpoint_CEL))
|
|
errors.Add(RuleEngine.CreateError(ValidationCode.IMPLAUSIBLE, "Flashpoint_CEL", null, this.Title, this.Identifier, this.HAZ.IsDeparture ? "HAZD" : "HAZA"));
|
|
}
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region public methods
|
|
|
|
public void CopyFromMARPOL(MARPOL_Annex_I_Position selectedMARPOL)
|
|
{
|
|
if (selectedMARPOL == null) return;
|
|
this.FlashpointInformation = selectedMARPOL.FlashpointInformation;
|
|
this.Flashpoint_CEL = selectedMARPOL.Flashpoint_CEL;
|
|
this.Name = selectedMARPOL.Name;
|
|
this.PortOfDischarge = selectedMARPOL.PortOfDischarge;
|
|
this.PortOfLoading = selectedMARPOL.PortOfLoading;
|
|
this.Quantity_KGM = selectedMARPOL.Quantity_KGM;
|
|
this.Remarks = selectedMARPOL.Remarks;
|
|
this.StowagePosition = selectedMARPOL.StowagePosition;
|
|
}
|
|
|
|
#endregion
|
|
|
|
}
|
|
}
|