156 lines
5.7 KiB
C#
156 lines
5.7 KiB
C#
//
|
|
// Class: IMSBCPosition
|
|
// Current CLR: 4.0.30319.34209
|
|
// System: Microsoft Visual Studio 10.0
|
|
// Author: dani
|
|
// Created: 5/27/2015 9:43:58 AM
|
|
//
|
|
// 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 IMSBCPosition : DatabaseEntity, ISublistElement
|
|
{
|
|
|
|
public IMSBCPosition()
|
|
{
|
|
this.tablename = "[dbo].[IMSBCPosition]";
|
|
}
|
|
|
|
#region Properties
|
|
|
|
public HAZ HAZ { get; set; }
|
|
|
|
[ShowReport]
|
|
[Validation(ValidationCode.NOT_NULL)]
|
|
[MaxLength(255)]
|
|
public string BulkCargoShippingName { get; set; }
|
|
|
|
[ShowReport]
|
|
[Validation(ValidationCode.NOT_NULL)]
|
|
public bool? MHB { get; set; }
|
|
|
|
[ShowReport]
|
|
[MaxLength(4)]
|
|
public string UNNumber { get; set; }
|
|
|
|
[ShowReport]
|
|
[MaxLength(10)]
|
|
public string IMOClass { get; set; }
|
|
|
|
[ShowReport]
|
|
[Validation(ValidationCode.DOUBLE_GT_ZERO)]
|
|
public double? Quantity_KGM { get; set; }
|
|
|
|
[ShowReport]
|
|
[Validation(ValidationCode.NOT_NULL)]
|
|
[MaxLength(24)]
|
|
public string StowagePosition { get; set; }
|
|
|
|
[ShowReport]
|
|
[Validation(ValidationCode.LOCODE)]
|
|
[MaxLength(5)]
|
|
public string PortOfLoading { get; set; }
|
|
|
|
[ShowReport]
|
|
[Validation(ValidationCode.LOCODE)]
|
|
[MaxLength(5)]
|
|
public string PortOfDischarge { get; set; }
|
|
|
|
[ShowReport]
|
|
[MaxLength(255)]
|
|
public string Remarks { get; set; }
|
|
|
|
public string Identifier { get; set; }
|
|
|
|
#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.BulkCargoShippingName);
|
|
scmd.Parameters.AddWithNullableValue("@P3", this.MHB);
|
|
scmd.Parameters.AddWithNullableValue("@P4", this.UNNumber);
|
|
scmd.Parameters.AddWithNullableValue("@P5", this.IMOClass);
|
|
scmd.Parameters.AddWithNullableValue("@P6", this.Quantity_KGM);
|
|
scmd.Parameters.AddWithNullableValue("@P7", this.StowagePosition);
|
|
scmd.Parameters.AddWithNullableValue("@P8", this.PortOfLoading);
|
|
scmd.Parameters.AddWithNullableValue("@P9", this.PortOfDischarge);
|
|
scmd.Parameters.AddWithNullableValue("@P10", this.Remarks);
|
|
scmd.Parameters.AddWithNullableValue("@P11", this.Identifier);
|
|
|
|
if(this.IsNew)
|
|
{
|
|
scmd.CommandText = string.Format("INSERT INTO {0} (HAZId, BulkCargoShippingName, MHB, UNNumber, " +
|
|
"IMOClass, Quantity_KGM, StowagePosition, PortOfLoading, PortOfDischarge, Remarks, Identifier) " +
|
|
" VALUES (@P1, @P2, @P3, @P4, @P5, @P6, @P7, @P8, @P9, @P10, @P11)", this.Tablename);
|
|
}
|
|
else
|
|
{
|
|
scmd.Parameters.AddWithValue("@ID", this.Id);
|
|
scmd.CommandText = string.Format("UPDATE {0} SET BulkCargoShippingName = @P2, MHB = @P3, UNNumber = @P4, " +
|
|
"IMOClass = @P5, Quantity_KGM = @P6, StowagePosition = @P7, PortOfLoading = @P8, PortOfDischarge = @P9, " +
|
|
"Remarks = @P10, Identifier = @P11 WHERE Id = @ID", this.Tablename);
|
|
}
|
|
}
|
|
|
|
public override void PrepareLoadCommand(IDbCommand cmd, Message.LoadFilter filter, params object[] criteria)
|
|
{
|
|
string query = string.Format("SELECT Id, BulkCargoShippingName, MHB, " +
|
|
"UNNumber, IMOClass, 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;
|
|
}
|
|
|
|
cmd.CommandText = query;
|
|
}
|
|
|
|
public override List<DatabaseEntity> LoadList(IDataReader reader)
|
|
{
|
|
List<DatabaseEntity> result = new List<DatabaseEntity>();
|
|
|
|
while (reader.Read())
|
|
{
|
|
IMSBCPosition imsbc = new IMSBCPosition();
|
|
imsbc.id = reader.GetGuid(0);
|
|
if (!reader.IsDBNull(1)) imsbc.BulkCargoShippingName = reader.GetString(1);
|
|
if (!reader.IsDBNull(2)) imsbc.MHB = reader.GetBoolean(2);
|
|
if (!reader.IsDBNull(3)) imsbc.UNNumber = reader.GetString(3);
|
|
if (!reader.IsDBNull(4)) imsbc.IMOClass = reader.GetString(4);
|
|
if (!reader.IsDBNull(5)) imsbc.Quantity_KGM = reader.GetDouble(5);
|
|
if (!reader.IsDBNull(6)) imsbc.StowagePosition = reader.GetString(6);
|
|
if (!reader.IsDBNull(7)) imsbc.PortOfLoading = reader.GetString(7);
|
|
if (!reader.IsDBNull(8)) imsbc.PortOfDischarge = reader.GetString(8);
|
|
if (!reader.IsDBNull(9)) imsbc.Remarks = reader.GetString(9);
|
|
if (!reader.IsDBNull(10)) imsbc.Identifier = reader.GetString(10);
|
|
|
|
result.Add(imsbc);
|
|
}
|
|
reader.Close();
|
|
return result;
|
|
}
|
|
|
|
#endregion
|
|
|
|
}
|
|
}
|