267 lines
11 KiB
C#
267 lines
11 KiB
C#
//
|
|
// Class: LADG
|
|
// Current CLR: 4.0.30319.34209
|
|
// System: Microsoft Visual Studio 10.0
|
|
// Author: dani
|
|
// Created: 4/2/2015 6:48:58 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 LADG : DatabaseEntity, ISublistElement
|
|
{
|
|
|
|
#region static definition
|
|
|
|
private static readonly Lazy<Dictionary<int, string>> laCodes =
|
|
new Lazy<Dictionary<int, string>>(() => new Dictionary<int, string>
|
|
{
|
|
{ 10, "unverpacktes Flüssiggut" },
|
|
{ 20, "unverpacktes Schüttgut" },
|
|
{ 30, "unverpacktes oder konventionell verpacktes Stückgut (Stückgut nicht in Containern >= 20 Fuß und nicht auf Ro-Ro-Einheiten)" },
|
|
{ 31, "Kfz als Handelsgüter" },
|
|
{ 32, "lebende Tiere als Handelsgüter" },
|
|
{ 41, "20-Fuß-Container" },
|
|
{ 42, "40-Fuß-Container" },
|
|
{ 43, "Container zwischen 20 und 40 Fuß" },
|
|
{ 44, "Container größer als 40 Fuß" },
|
|
{ 51, "Straßengüterfahrzeuge einschl. deren Anhänger" },
|
|
{ 52, "Pkw einschl. deren Anhänger, Krafträder" },
|
|
{ 53, "Omnibusse" },
|
|
{ 61, "Anhänger / Sattelauflieger für Straßengüterfahrzeuge" },
|
|
{ 62, "Sonstige Anhänger von Straßenfahrzeugen (ohne Zugmaschine) und nicht selbstfahrende Straßenfahrzeuge" },
|
|
{ 63, "Rolltrailer (Anhänger für die Güterbeförderung auf See)" },
|
|
{ 64, "Trägerschiffsleichter" },
|
|
{ 65, "Wechselbrücken / -behälter" },
|
|
{ 66, "Eisenbahngüterwagen" },
|
|
{ 67, "Reisezugwagen und Triebwagen" }
|
|
});
|
|
|
|
#endregion
|
|
|
|
public LADG()
|
|
{
|
|
this.tablename = "[dbo].[LADG]";
|
|
}
|
|
|
|
#region Properties
|
|
|
|
[ShowReport]
|
|
[Validation(ValidationCode.NOT_NULL)]
|
|
[ENI2Validation]
|
|
public byte? CargoHandlingType { get; set; }
|
|
|
|
/// <summary>
|
|
/// ENI-2 display value
|
|
/// </summary>
|
|
public string CargoHandlingTypeDisplay {
|
|
get {
|
|
if(this.CargoHandlingType.HasValue)
|
|
{
|
|
if (CargoHandlingDict.ContainsKey(this.CargoHandlingType.Value))
|
|
return CargoHandlingDict[this.CargoHandlingType.Value];
|
|
return string.Empty;
|
|
}
|
|
return string.Empty;
|
|
}
|
|
}
|
|
|
|
[ShowReport]
|
|
[Validation(ValidationCode.TWO_DIGIT)]
|
|
[MaxLength(5)]
|
|
[ENI2Validation]
|
|
public string CargoCodeNST { get; set; }
|
|
|
|
[ShowReport]
|
|
[ENI2Validation]
|
|
public int? CargoLACode { get; set; }
|
|
|
|
[ShowReport]
|
|
[ENI2Validation]
|
|
public int? CargoNumberOfItems { get; set; }
|
|
|
|
[ShowReport]
|
|
[Validation(ValidationCode.DOUBLE_GT_ZERO)]
|
|
[ENI2Validation]
|
|
public double? CargoGrossQuantity_TNE { get; set; }
|
|
|
|
[MaxLength(5)]
|
|
//[Validation(ValidationCode.LOCODE)]
|
|
[ENI2Validation]
|
|
public string PortOfLoading { get; set; }
|
|
|
|
[MaxLength(5)]
|
|
//[Validation(ValidationCode.LOCODE)]
|
|
[ENI2Validation]
|
|
public string PortOfDischarge { get; set; }
|
|
|
|
[MaxLength(1)]
|
|
[ShowReport]
|
|
[ENI2Validation]
|
|
public string CargoCodeNST_3 { get; set; }
|
|
|
|
public string Identifier { get; set; }
|
|
|
|
public string SublistCollectionKey { get { return "ladg"; } }
|
|
|
|
public static Dictionary<int, string> LACodes { get; set; }
|
|
|
|
public static Dictionary<string, string> CargoCodesNST { get; set; }
|
|
|
|
public static List<KeyValuePair<string, string>> CargoCodesNST3 { get; set; }
|
|
|
|
|
|
public static Dictionary<int, string> CargoHandlingDict { get; } = new Dictionary<int, string>();
|
|
|
|
public static List<string> MVSHLocodes { get; } = new List<string>();
|
|
|
|
#endregion
|
|
|
|
#region DatabaseEntity implementation
|
|
|
|
public override string Subtitle
|
|
{
|
|
get
|
|
{
|
|
return "Cargo information";
|
|
}
|
|
}
|
|
|
|
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.CargoHandlingType);
|
|
scmd.Parameters.AddWithNullableValue("@P3", this.CargoCodeNST);
|
|
scmd.Parameters.AddWithNullableValue("@P4", this.CargoNumberOfItems);
|
|
scmd.Parameters.AddWithNullableValue("@P5", this.CargoGrossQuantity_TNE);
|
|
scmd.Parameters.AddWithNullableValue("@P6", this.PortOfLoading);
|
|
scmd.Parameters.AddWithNullableValue("@P7", this.PortOfDischarge);
|
|
scmd.Parameters.AddWithNullableValue("@P8", this.Identifier);
|
|
scmd.Parameters.AddWithNullableValue("@P9", this.CargoLACode);
|
|
scmd.Parameters.AddWithNullableValue("@P10", this.CargoCodeNST_3);
|
|
|
|
if (this.IsNew)
|
|
{
|
|
this.CreateId();
|
|
scmd.Parameters.AddWithValue("@ID", this.Id);
|
|
scmd.CommandText = string.Format("INSERT INTO {0} (Id, MessageHeaderId, CargoHandlingType, CargoCodeNST, " +
|
|
"CargoNumberOfItems, CargoGrossQuantity_TNE, PortOfLoading, PortOfDischarge, Identifier, CargoLACode, CargoCodeNST_3) 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 CargoHandlingType = @P2, CargoCodeNST = @P3, CargoNumberOfItems = @P4, " +
|
|
"CargoGrossQuantity_TNE = @P5, PortOfLoading = @P6, PortOfDischarge = @P7, CargoLACode = @P9, CargoCodeNST_3 = @P10, " +
|
|
"Identifier = @P8 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, CargoHandlingType, CargoCodeNST, CargoNumberOfItems, CargoGrossQuantity_TNE, " +
|
|
"PortOfLoading, PortOfDischarge, Identifier, CargoLACode, CargoCodeNST_3 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())
|
|
{
|
|
LADG ladg = new LADG();
|
|
|
|
ladg.id = reader.GetGuid(0);
|
|
if (!reader.IsDBNull(1)) ladg.CargoHandlingType = reader.GetByte(1);
|
|
if (!reader.IsDBNull(2)) ladg.CargoCodeNST = reader.GetString(2);
|
|
if (!reader.IsDBNull(3)) ladg.CargoNumberOfItems = reader.GetInt32(3);
|
|
if (!reader.IsDBNull(4)) ladg.CargoGrossQuantity_TNE = reader.GetDouble(4);
|
|
if (!reader.IsDBNull(5)) ladg.PortOfLoading = reader.GetString(5);
|
|
if (!reader.IsDBNull(6)) ladg.PortOfDischarge = reader.GetString(6);
|
|
if (!reader.IsDBNull(7)) ladg.Identifier = reader.GetString(7);
|
|
if (!reader.IsDBNull(8)) ladg.CargoLACode = reader.GetInt32(8);
|
|
if (!reader.IsDBNull(9)) ladg.CargoCodeNST_3 = reader.GetString(9);
|
|
result.Add(ladg);
|
|
}
|
|
reader.Close();
|
|
result.Sort();
|
|
return result;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Validation
|
|
|
|
public override void Validate(List<MessageError> errors, List<MessageViolation> violations)
|
|
{
|
|
if ((this.CargoCodeNST != null) &&
|
|
(this.CargoCodeNST.Equals("11") || this.CargoCodeNST.Equals("12") || this.CargoCodeNST.Equals("16") ||
|
|
this.CargoCodeNST.Equals("19")) &&
|
|
!this.CargoNumberOfItems.HasValue)
|
|
violations.Add(RuleEngine.CreateViolation(ValidationCode.V721, "CargoNumberOfItems" , null, this.Title, this.Identifier, this.Tablename));
|
|
|
|
if (RuleEngine.LocodeChecker != null && !this.PortOfDischarge.IsNullOrEmpty())
|
|
{
|
|
if (!RuleEngine.LocodeChecker.Invoke(this.PortOfDischarge, RuleEngine.LocodeMode.STANDARD))
|
|
errors.Add(RuleEngine.CreateError(ValidationCode.LOCODE, "PortOfDischarge", this.PortOfDischarge, this.Title, this.Identifier, this.Tablename));
|
|
}
|
|
|
|
if (RuleEngine.LocodeChecker != null && !this.PortOfLoading.IsNullOrEmpty())
|
|
{
|
|
if (!RuleEngine.LocodeChecker.Invoke(this.PortOfLoading, RuleEngine.LocodeMode.STANDARD))
|
|
errors.Add(RuleEngine.CreateError(ValidationCode.LOCODE, "PortOfLoading", this.PortOfLoading, this.Title, this.Identifier, this.Tablename));
|
|
}
|
|
|
|
if(LADG.MVSHLocodes.Contains(this.MessageCore.PoC))
|
|
{
|
|
if (this.CargoCodeNST_3.IsNullOrEmpty())
|
|
violations.Add(RuleEngine.CreateViolation(ValidationCode.IMPLAUSIBLE, "CargoCodeNST_3 empty", this.CargoCodeNST_3, this.Title, this.Identifier, this.Tablename));
|
|
|
|
if(!this.CargoLACode.HasValue)
|
|
violations.Add(RuleEngine.CreateViolation(ValidationCode.IMPLAUSIBLE, "CargoLACode empty", "not set", this.Title, this.Identifier, this.Tablename));
|
|
}
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region IComparable implementation
|
|
|
|
public int CompareTo(object obj)
|
|
{
|
|
if (this.Identifier == null) return 1;
|
|
if ((obj is null) || (((LADG)obj).Identifier == null))
|
|
return 1;
|
|
if (Int32.TryParse(((LADG)obj).Identifier, out int i1) && Int32.TryParse(this.Identifier, out int i2))
|
|
return i2.CompareTo(i1);
|
|
return this.Identifier.CompareTo(((LADG)obj).Identifier);
|
|
}
|
|
|
|
#endregion
|
|
|
|
}
|
|
} |