156 lines
4.8 KiB
C#
156 lines
4.8 KiB
C#
//
|
|
// Class: BRKD
|
|
// Current CLR: 4.0.30319.34209
|
|
// System: Microsoft Visual Studio 10.0
|
|
// Author: dani
|
|
// Created: 4/1/2015 10:13:01 PM
|
|
//
|
|
// Copyright (c) 2015 Informatikbüro Daniel Schick. All rights reserved.
|
|
|
|
using System;
|
|
using System.Data;
|
|
using System.Data.SqlClient;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
|
|
namespace bsmd.database
|
|
{
|
|
public class BRKD : DatabaseEntity, ISublistElement
|
|
{
|
|
|
|
public BRKD()
|
|
{
|
|
this.tablename = "[dbo].[BKRD]";
|
|
}
|
|
|
|
#region Properties
|
|
|
|
[ShowReport]
|
|
[Validation(ValidationCode.NOT_NULL)]
|
|
[MaxLength(100)]
|
|
[ENI2Validation]
|
|
public string BunkerFuelType { get; set; }
|
|
|
|
[ShowReport]
|
|
[Validation(ValidationCode.DOUBLE_GT_ZERO)]
|
|
[ENI2Validation]
|
|
public double? BunkerFuelQuantity_TNE { get; set; }
|
|
|
|
public string Identifier { get; set; }
|
|
|
|
[Browsable(false)]
|
|
public string SublistCollectionKey { get { return "bkrd"; } }
|
|
|
|
#endregion
|
|
|
|
#region DatabaseEntity implementation
|
|
|
|
public override string Subtitle
|
|
{
|
|
get
|
|
{
|
|
return "Bunker fuel on departure";
|
|
}
|
|
}
|
|
|
|
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.BunkerFuelType);
|
|
scmd.Parameters.AddWithNullableValue("@P3", this.BunkerFuelQuantity_TNE);
|
|
scmd.Parameters.AddWithNullableValue("@P4", this.Identifier);
|
|
|
|
if (this.IsNew)
|
|
{
|
|
this.CreateId();
|
|
scmd.Parameters.AddWithValue("@ID", this.Id);
|
|
scmd.CommandText = string.Format("INSERT INTO {0} (Id, MessageHeaderId, BunkerFuelType, BunkerFuelQuantity_TNE, Identifier) " +
|
|
"VALUES ( @ID, @P1, @P2, @P3, @P4 )", this.Tablename);
|
|
}
|
|
else
|
|
{
|
|
scmd.Parameters.AddWithValue("ID", this.Id);
|
|
scmd.CommandText = string.Format("UPDATE {0} SET BunkerFuelType = @P2, BunkerFuelQuantity_TNE = @P3, Identifier = @P4 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, BunkerFuelType, BunkerFuelQuantity_TNE, Identifier 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())
|
|
{
|
|
BRKD bkrd = new BRKD();
|
|
|
|
bkrd.id = reader.GetGuid(0);
|
|
if (!reader.IsDBNull(1)) bkrd.BunkerFuelType = reader.GetString(1);
|
|
if (!reader.IsDBNull(2)) bkrd.BunkerFuelQuantity_TNE = reader.GetDouble(2);
|
|
if (!reader.IsDBNull(3)) bkrd.Identifier = reader.GetString(3);
|
|
result.Add(bkrd);
|
|
}
|
|
reader.Close();
|
|
result.Sort();
|
|
return result;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Validation
|
|
|
|
public override void Validate(List<MessageError> errors, List<MessageViolation> violations)
|
|
{
|
|
if (this.BunkerFuelQuantity_TNE.HasValue && this.BunkerFuelQuantity_TNE > 10000)
|
|
{
|
|
violations.Add(RuleEngine.CreateViolation(ValidationCode.IMPLAUSIBLE, "Bunker quantity too high?", null, this.Title, this.Identifier, "BKRD"));
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region public funcs
|
|
|
|
public void CopyFromBKRA(BRKA brka)
|
|
{
|
|
if (brka == null) return;
|
|
this.BunkerFuelType = brka.BunkerFuelType;
|
|
this.BunkerFuelQuantity_TNE = brka.BunkerFuelQuantity_TNE;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region IComparable implementation
|
|
|
|
public int CompareTo(object obj)
|
|
{
|
|
if (object.ReferenceEquals(obj, null))
|
|
return 1;
|
|
return this.Identifier.CompareTo(((BRKD)obj).Identifier);
|
|
}
|
|
|
|
#endregion
|
|
|
|
}
|
|
}
|