290 lines
11 KiB
C#
290 lines
11 KiB
C#
//
|
|
// Class: HAZ
|
|
// Current CLR: 4.0.30319.34209
|
|
// System: Microsoft Visual Studio 10.0
|
|
// Author: dani
|
|
// Created: 5/26/2015 8:13:35 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 HAZ : DatabaseEntity, ISublistContainer
|
|
{
|
|
|
|
private List<IMDGPosition> imdgPositions = new List<IMDGPosition>();
|
|
private List<IBCPosition> ibcPositions = new List<IBCPosition>();
|
|
private List<IGCPosition> igcPositions = new List<IGCPosition>();
|
|
private List<IMSBCPosition> imsbcPositions = new List<IMSBCPosition>();
|
|
private List<MARPOL_Annex_I_Position> marpolPositions = new List<MARPOL_Annex_I_Position>();
|
|
|
|
public HAZ()
|
|
{
|
|
this.tablename = "[dbo].[HAZA]"; // muss noch umschaltbar
|
|
}
|
|
|
|
#region Properties
|
|
|
|
[ShowReport]
|
|
[Validation(ValidationCode.NOT_NULL)]
|
|
public bool? NoDPGOnBoardOnArrival { get; set; }
|
|
|
|
[ShowReport]
|
|
[Validation(ValidationCode.NOT_NULL)]
|
|
public bool? DPGManifestOnBoardOnArrival { get; set; }
|
|
|
|
[ShowReport]
|
|
public byte? INFShipClass { get; set; }
|
|
|
|
[ShowReport]
|
|
public bool? DPGClassificationIMDG { get; set; }
|
|
|
|
[ShowReport]
|
|
public bool? DPGClassificationIGC { get; set; }
|
|
|
|
[ShowReport]
|
|
public bool? DPGClassificationIBC { get; set; }
|
|
|
|
[ShowReport]
|
|
public bool? DPGClassificationIMSBC { get; set; }
|
|
|
|
[ShowReport]
|
|
public bool? DPGClassificationMARPOL_ANNEX_I { get; set; }
|
|
|
|
public List<IMDGPosition> IMDGPositions { get { return this.imdgPositions; } }
|
|
|
|
public List<IBCPosition> IBCPositions { get { return this.ibcPositions; } }
|
|
|
|
public List<IGCPosition> IGCPositions { get { return this.igcPositions; } }
|
|
|
|
public List<IMSBCPosition> IMSBCPositions { get { return this.imsbcPositions; } }
|
|
|
|
public List<MARPOL_Annex_I_Position> MARPOLPositions { get { return this.marpolPositions; } }
|
|
|
|
[ShowReport]
|
|
public bool IsDeparture { get; set; } // selektor HAZA / HAZD
|
|
|
|
#endregion
|
|
|
|
#region DatabaseEntity implementation
|
|
|
|
public override void PrepareSave(System.Data.IDbCommand cmd)
|
|
{
|
|
SqlCommand scmd = cmd as SqlCommand;
|
|
|
|
scmd.Parameters.AddWithValue("@P1", this.MessageHeader.Id);
|
|
scmd.Parameters.AddWithNullableValue("@P2", this.NoDPGOnBoardOnArrival);
|
|
scmd.Parameters.AddWithNullableValue("@P3", this.DPGManifestOnBoardOnArrival);
|
|
scmd.Parameters.AddWithNullableValue("@P4", this.INFShipClass);
|
|
scmd.Parameters.AddWithNullableValue("@P5", this.DPGClassificationIMDG);
|
|
scmd.Parameters.AddWithNullableValue("@P6", this.DPGClassificationIGC);
|
|
scmd.Parameters.AddWithNullableValue("@P7", this.DPGClassificationIBC);
|
|
scmd.Parameters.AddWithNullableValue("@P8", this.DPGClassificationIMSBC);
|
|
scmd.Parameters.AddWithNullableValue("@P9", this.DPGClassificationMARPOL_ANNEX_I);
|
|
|
|
if (this.IsNew)
|
|
{
|
|
this.CreateId();
|
|
scmd.Parameters.AddWithValue("@ID", this.Id);
|
|
scmd.CommandText = string.Format("INSERT INTO {0} (Id, MessageHeaderId, NoDPGOnBoardOnArrival, DPGManifestOnBoardOnArrival, " +
|
|
"INFShipClass, DPGClassificationIMDG, DPGClassificationIGC, DPGClassificationIBC, DPGClassificationIMSBC, " +
|
|
"DPGClassificationMARPOL_ANNEX_I) VALUES (@ID, @P1, @P2, @P3, @P4, @P5, @P6, @P7, @P8, @P9)", this.Tablename);
|
|
}
|
|
else
|
|
{
|
|
scmd.Parameters.AddWithValue("@ID", this.Id);
|
|
scmd.CommandText = string.Format("UPDATE {0} SET NODPGOnBoardOnArrival = @P2, DPGManifestOnBoardOnArrival = @P3, " +
|
|
"INFShipClass = @P4, DPGClassificationIMDG = @P5, DPGClassificationIGC = @P6, DPGClassificationIBC = @P7, " +
|
|
"DPGClassificationIMSBC = @P8, DPGClassificationMARPOL_ANNEX_I = @P9 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, NoDPGOnBoardOnArrival, DPGManifestOnBoardOnArrival, INFShipClass, " +
|
|
"DPGClassificationIMDG, DPGClassificationIGC, DPGClassificationIBC, DPGClassificationIMSBC, " +
|
|
"DPGClassificationMARPOL_ANNEX_I 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())
|
|
{
|
|
HAZ haz = new HAZ();
|
|
|
|
haz.id = reader.GetGuid(0);
|
|
if (!reader.IsDBNull(1)) haz.NoDPGOnBoardOnArrival = reader.GetBoolean(1);
|
|
if (!reader.IsDBNull(2)) haz.DPGManifestOnBoardOnArrival = reader.GetBoolean(2);
|
|
if (!reader.IsDBNull(3)) haz.INFShipClass = reader.GetByte(3);
|
|
if (!reader.IsDBNull(4)) haz.DPGClassificationIMDG = reader.GetBoolean(4);
|
|
if (!reader.IsDBNull(5)) haz.DPGClassificationIGC = reader.GetBoolean(5);
|
|
if (!reader.IsDBNull(6)) haz.DPGClassificationIBC = reader.GetBoolean(6);
|
|
if (!reader.IsDBNull(7)) haz.DPGClassificationIMSBC = reader.GetBoolean(7);
|
|
if (!reader.IsDBNull(8)) haz.DPGClassificationMARPOL_ANNEX_I = reader.GetBoolean(8);
|
|
|
|
result.Add(haz);
|
|
}
|
|
reader.Close();
|
|
return result;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region ISublistContainer implementation
|
|
|
|
public ISublistElement GetSublistElementWithIdentifier(string identifier)
|
|
{
|
|
|
|
foreach (ISublistElement sublist in this.IMDGPositions)
|
|
{
|
|
if (sublist.Identifier.Equals(identifier))
|
|
return sublist;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public IGCPosition GetIGCPositionWithIdentifier(string identifier)
|
|
{
|
|
foreach (IGCPosition igcPosition in this.IGCPositions)
|
|
if (igcPosition.Identifier.Equals(identifier))
|
|
return igcPosition;
|
|
return null;
|
|
}
|
|
|
|
public IMDGPosition GetIMDGPositionWithIdentifier(string identifier)
|
|
{
|
|
foreach (IMDGPosition imdgPosition in this.IMDGPositions)
|
|
if (imdgPosition.Identifier.Equals(identifier))
|
|
return imdgPosition;
|
|
return null;
|
|
}
|
|
|
|
public IBCPosition GetIBCPositionWithIdentifier(string identifier)
|
|
{
|
|
foreach (IBCPosition ibcPosition in this.IBCPositions)
|
|
if (ibcPosition.Identifier.Equals(identifier))
|
|
return ibcPosition;
|
|
return null;
|
|
}
|
|
|
|
public IMSBCPosition GetIMSBCPositionWithIdentifier(string identifier)
|
|
{
|
|
foreach (IMSBCPosition imsbcPosition in this.IMSBCPositions)
|
|
if (imsbcPosition.Identifier.Equals(identifier))
|
|
return imsbcPosition;
|
|
return null;
|
|
}
|
|
|
|
public MARPOL_Annex_I_Position GetMARPOLPositionWithIdentifier(string identifier)
|
|
{
|
|
foreach (MARPOL_Annex_I_Position marpolPosition in this.MARPOLPositions)
|
|
if (marpolPosition.Identifier.Equals(identifier))
|
|
return marpolPosition;
|
|
return null;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region IMessageParagraph implementation
|
|
|
|
public override string Subtitle
|
|
{
|
|
get
|
|
{
|
|
return this.IsDeparture ? "Hazardous items on departure" : "Hazardous items on arrival";
|
|
}
|
|
}
|
|
|
|
public override List<IMessageParagraph> ChildParagraphs
|
|
{
|
|
get
|
|
{
|
|
List<IMessageParagraph> result = new List<IMessageParagraph>();
|
|
foreach (IMessageParagraph imp in this.IMDGPositions)
|
|
result.Add(imp);
|
|
foreach (IMessageParagraph imp in this.IBCPositions)
|
|
result.Add(imp);
|
|
foreach (IMessageParagraph imp in this.IGCPositions)
|
|
result.Add(imp);
|
|
foreach (IMessageParagraph imp in this.IMSBCPositions)
|
|
result.Add(imp);
|
|
foreach (IMessageParagraph imp in this.MARPOLPositions)
|
|
result.Add(imp);
|
|
return result;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Validation
|
|
|
|
public override DatabaseEntity.ValidationBlock GetValidationBlock()
|
|
{
|
|
return (this.NoDPGOnBoardOnArrival ?? false) ? ValidationBlock.BLOCK1 : ValidationBlock.BLOCK2;
|
|
}
|
|
|
|
public override void Validate(List<MessageError> errors, List<MessageViolation> violations)
|
|
{
|
|
if (this.GetValidationBlock() == ValidationBlock.BLOCK2)
|
|
{
|
|
if ((this.IMDGPositions.Count == 0) && (this.IBCPositions.Count == 0) && (this.IGCPositions.Count == 0) &&
|
|
(this.IMSBCPositions.Count == 0) && (this.MARPOLPositions.Count == 0))
|
|
violations.Add(RuleEngine.CreateViolation(ValidationCode.V805, "At least one DPG item has to be provided!", null));
|
|
|
|
foreach (IMDGPosition imdg in this.IMDGPositions)
|
|
{
|
|
RuleEngine.ValidateProperties(imdg, errors);
|
|
imdg.Validate(errors, violations);
|
|
}
|
|
|
|
foreach(IBCPosition ibc in this.IBCPositions)
|
|
{
|
|
RuleEngine.ValidateProperties(ibc, errors);
|
|
ibc.Validate(errors, violations);
|
|
}
|
|
|
|
foreach(IGCPosition igc in this.IGCPositions)
|
|
{
|
|
RuleEngine.ValidateProperties(igc, errors);
|
|
}
|
|
|
|
foreach(IMSBCPosition imsbc in this.IMSBCPositions)
|
|
{
|
|
RuleEngine.ValidateProperties(imsbc, errors);
|
|
imsbc.Validate(errors, violations);
|
|
}
|
|
|
|
foreach(MARPOL_Annex_I_Position marpol in this.MARPOLPositions)
|
|
{
|
|
RuleEngine.ValidateProperties(marpol, errors);
|
|
marpol.Validate(errors, violations);
|
|
}
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
}
|
|
}
|