224 lines
8.6 KiB
C#
224 lines
8.6 KiB
C#
//
|
|
// Class: Waste
|
|
// Current CLR: 4.0.30319.34209
|
|
// System: Microsoft Visual Studio 10.0
|
|
// Author: dani
|
|
// Created: 4/2/2015 7:44:03 PM
|
|
//
|
|
// Copyright (c) 2015 Informatikbüro Daniel Schick. All rights reserved.
|
|
|
|
using System.Data.SqlClient;
|
|
using System.Collections.Generic;
|
|
|
|
namespace bsmd.database
|
|
{
|
|
public class Waste : DatabaseEntity, ISublistElement
|
|
{
|
|
|
|
public Waste()
|
|
{
|
|
this.tablename = "[dbo].[Waste]";
|
|
}
|
|
|
|
#region Properties
|
|
|
|
public WAS WAS { get; set; }
|
|
|
|
[ShowReport]
|
|
public string WasteTypeDisplay
|
|
{
|
|
get
|
|
{
|
|
if (!WasteType.HasValue) return "";
|
|
switch (WasteType.Value)
|
|
{
|
|
case 1: return "WASTE_OILS-SLUDGE";
|
|
case 2: return "WASTE_OILS-BILGE_WATER";
|
|
case 3: return "WASTE_OILS-OTHERS";
|
|
case 4: return "GARBAGE-FOOD_WASTE";
|
|
case 5: return "GARBATE-PLASTIC";
|
|
case 6: return "GARBAGE-OTHER";
|
|
case 7: return "SEWAGE";
|
|
case 8: return "CARGO-ASSOCIATED_WASTE";
|
|
case 9: return "CARGO-RESIDUES";
|
|
default: return "";
|
|
}
|
|
}
|
|
}
|
|
|
|
[ShowReport]
|
|
public string WasteTypeDisplayV4
|
|
{
|
|
get
|
|
{
|
|
if (!WasteType.HasValue) return "";
|
|
switch(WasteType.Value)
|
|
{
|
|
case 1100: return "Oily residues (sludge)";
|
|
case 1200: return "Oily bilge water";
|
|
case 1300: return "Waste oil - others (specify)";
|
|
case 2100: return "Food waste";
|
|
case 2200: return "Plastic";
|
|
case 2300: return "Domestic wastes";
|
|
case 2311: return "Cooking oil";
|
|
case 2308: return "Incinerator ashes";
|
|
case 2600: return "Operational wastes";
|
|
case 2309: return "Animal carcass(es)";
|
|
case 3000: return "Sewage";
|
|
case 5100: return "Cargo residues - Marpol Annex I";
|
|
case 5200: return "Cargo residues - Marpol Annex II";
|
|
case 5300: return "Cargo residues - Marpol Annex V";
|
|
|
|
default: return "Others (specify)";
|
|
}
|
|
}
|
|
}
|
|
|
|
public string WasteTypeDisplayGrid
|
|
{
|
|
get
|
|
{
|
|
return string.Format("{0} {1}", WasteType, WasteTypeDisplayV4);
|
|
}
|
|
}
|
|
|
|
[Validation(ValidationCode.NOT_NULL)]
|
|
[ENI2Validation]
|
|
public int? WasteType { get; set; }
|
|
|
|
[ShowReport]
|
|
[Validation(ValidationCode.NOT_NULL)]
|
|
[MaxLength(100)]
|
|
[ENI2Validation]
|
|
public string WasteDescription { get; set; }
|
|
|
|
[ShowReport]
|
|
[Validation(ValidationCode.NOT_NULL)]
|
|
[ENI2Validation]
|
|
public double? WasteDisposalAmount_MTQ { get; set; }
|
|
|
|
[ShowReport]
|
|
[ENI2Validation]
|
|
public double? WasteCapacity_MTQ { get; set; }
|
|
|
|
[ShowReport]
|
|
[ENI2Validation]
|
|
public double? WasteAmountRetained_MTQ { get; set; }
|
|
|
|
[ShowReport]
|
|
[MaxLength(5)]
|
|
[ENI2Validation]
|
|
public string WasteDisposalPort { get; set; }
|
|
|
|
[ShowReport]
|
|
[ENI2Validation]
|
|
public double? WasteAmountGeneratedTillNextPort_MTQ { get; set; }
|
|
|
|
// "dänisches" Zusatzfeld
|
|
[ENI2Validation]
|
|
public double? WasteDisposedAtLastPort_MTQ { get; set; }
|
|
|
|
public string Identifier { get; set; }
|
|
|
|
#endregion
|
|
|
|
#region DatabaseEntity implementation
|
|
|
|
public override void PrepareSave(System.Data.IDbCommand cmd)
|
|
{
|
|
|
|
SqlCommand scmd = cmd as SqlCommand;
|
|
|
|
scmd.Parameters.AddWithValue("@P1", this.WAS.Id);
|
|
scmd.Parameters.AddWithNullableValue("@P2", this.WasteType);
|
|
scmd.Parameters.AddWithNullableValue("@P3", this.WasteDescription);
|
|
scmd.Parameters.AddWithNullableValue("@P4", this.WasteDisposalAmount_MTQ);
|
|
scmd.Parameters.AddWithNullableValue("@P5", this.WasteCapacity_MTQ);
|
|
scmd.Parameters.AddWithNullableValue("@P6", this.WasteAmountRetained_MTQ);
|
|
scmd.Parameters.AddWithNullableValue("@P7", this.WasteDisposalPort);
|
|
scmd.Parameters.AddWithNullableValue("@P8", this.WasteAmountGeneratedTillNextPort_MTQ);
|
|
scmd.Parameters.AddWithNullableValue("@P9", this.WasteDisposedAtLastPort_MTQ);
|
|
scmd.Parameters.AddWithNullableValue("@P10", this.Identifier);
|
|
|
|
if (this.IsNew)
|
|
{
|
|
scmd.CommandText = string.Format("INSERT INTO {0} (WASId, WasteType, WasteDescription, " +
|
|
"WasteDisposalAmount_MTQ, WasteCapacity_MTQ, WasteAmountRetained_MTQ, WasteDisposalPort, " +
|
|
"WasteAmountGeneratedTillNextPort_MTQ, WasteDisposedAtLastPort_MTQ, Identifier) " +
|
|
" VALUES ( @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 WasteType = @P2, WasteDescription = @P3, " +
|
|
"WasteDisposalAmount_MTQ = @P4, WasteCapacity_MTQ = @P5, WasteAmountRetained_MTQ = @P6," +
|
|
"WasteDisposalPort = @P7, WasteAmountGeneratedTillNextPort_MTQ = @P8, WasteDisposedAtLastPort_MTQ = @P9, " +
|
|
"Identifier = @P10 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, WasteType, WasteDescription, WasteDisposalAmount_MTQ, " +
|
|
"WasteCapacity_MTQ, WasteAmountRetained_MTQ, WasteDisposalPort, WasteAmountGeneratedTillNextPort_MTQ, " +
|
|
"WasteDisposedAtLastPort_MTQ, Identifier FROM {0} ", this.Tablename);
|
|
|
|
switch (filter)
|
|
{
|
|
case Message.LoadFilter.WAS_ID:
|
|
query += " WHERE WASId = @WDID";
|
|
((SqlCommand)cmd).Parameters.AddWithValue("@WDID", criteria[0]);
|
|
break;
|
|
case Message.LoadFilter.ALL:
|
|
default:
|
|
|
|
break;
|
|
}
|
|
query += " ORDER BY CAST(Identifier AS INT)";
|
|
|
|
cmd.CommandText = query;
|
|
}
|
|
|
|
public override List<DatabaseEntity> LoadList(System.Data.IDataReader reader)
|
|
{
|
|
List<DatabaseEntity> result = new List<DatabaseEntity>();
|
|
|
|
while (reader.Read())
|
|
{
|
|
Waste waste = new Waste();
|
|
|
|
waste.id = reader.GetGuid(0);
|
|
if (!reader.IsDBNull(1)) waste.WasteType = reader.GetInt32(1);
|
|
if (!reader.IsDBNull(2)) waste.WasteDescription = reader.GetString(2);
|
|
if (!reader.IsDBNull(3)) waste.WasteDisposalAmount_MTQ = (float) reader.GetDouble(3);
|
|
if (!reader.IsDBNull(4)) waste.WasteCapacity_MTQ = (float) reader.GetDouble(4);
|
|
if (!reader.IsDBNull(5)) waste.WasteAmountRetained_MTQ = (float) reader.GetDouble(5);
|
|
if (!reader.IsDBNull(6)) waste.WasteDisposalPort = reader.GetString(6);
|
|
if (!reader.IsDBNull(7)) waste.WasteAmountGeneratedTillNextPort_MTQ = (float) reader.GetDouble(7);
|
|
if (!reader.IsDBNull(8)) waste.WasteDisposedAtLastPort_MTQ = (float)reader.GetDouble(8);
|
|
if (!reader.IsDBNull(9)) waste.Identifier = reader.GetString(9);
|
|
result.Add(waste);
|
|
}
|
|
reader.Close();
|
|
return result;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Validation
|
|
|
|
public override void Validate(List<MessageError> errors, List<MessageViolation> violations)
|
|
{
|
|
if (this.WasteType.HasValue &&
|
|
((this.WasteType.Value == (int)3) || (this.WasteType.Value == (int)8) || (this.WasteType.Value == (int)9)) &&
|
|
this.WasteDescription.IsNullOrEmpty())
|
|
violations.Add(RuleEngine.CreateViolation(ValidationCode.V781, "WasteDescription", null, this.Title, this.Identifier));
|
|
|
|
// TODO: 782
|
|
}
|
|
|
|
#endregion
|
|
|
|
}
|
|
}
|