150 lines
5.4 KiB
C#
150 lines
5.4 KiB
C#
//
|
|
// Class: IGCPosition
|
|
// Current CLR: 4.0.30319.34209
|
|
// System: Microsoft Visual Studio 10.0
|
|
// Author: dani
|
|
// Created: 5/27/2015 9:28:19 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 IGCPosition : DatabaseEntity, ISublistElement
|
|
{
|
|
|
|
public IGCPosition()
|
|
{
|
|
this.tablename = "[dbo].[IGCPosition]";
|
|
}
|
|
|
|
#region Properties
|
|
|
|
public HAZ HAZ { get; set; }
|
|
|
|
[ShowReport]
|
|
[MaxLength(4)]
|
|
public string UNNumber { get; set; }
|
|
|
|
[ShowReport]
|
|
[MaxLength(10)]
|
|
public string IMOClass { get; set; }
|
|
|
|
[ShowReport]
|
|
[Validation(ValidationCode.NOT_NULL)]
|
|
[MaxLength(255)]
|
|
public string ProductName { 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(System.Data.IDbCommand cmd)
|
|
{
|
|
SqlCommand scmd = cmd as SqlCommand;
|
|
|
|
scmd.Parameters.AddWithValue("@P1", this.HAZ.Id);
|
|
scmd.Parameters.AddWithNullableValue("@P2", this.UNNumber);
|
|
scmd.Parameters.AddWithNullableValue("@P3", this.IMOClass);
|
|
scmd.Parameters.AddWithNullableValue("@P4", this.ProductName);
|
|
scmd.Parameters.AddWithNullableValue("@P5", this.Quantity_KGM);
|
|
scmd.Parameters.AddWithNullableValue("@P6", this.StowagePosition);
|
|
scmd.Parameters.AddWithNullableValue("@P7", this.PortOfLoading);
|
|
scmd.Parameters.AddWithNullableValue("@P8", this.PortOfDischarge);
|
|
scmd.Parameters.AddWithNullableValue("@P9", this.Remarks);
|
|
scmd.Parameters.AddWithNullableValue("@P10", this.Identifier);
|
|
|
|
if (this.IsNew)
|
|
{
|
|
scmd.CommandText = string.Format("INSERT INTO {0} (HAZId, UNNumber, IMOClass, ProductName, Quantity_KGM, " +
|
|
"StowagePosition, PortOfLoading, PortOfDischarge, Remarks, 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 UNNumber = @P2, IMOClass = @P3, ProductName = @P4, " +
|
|
"Quantity_KGM = @P5, StowagePosition = @P6, PortOfLoading = @P7, PortOfDischarge = @P8, Remarks = @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, UNNumber, IMOClass, " +
|
|
"ProductName, 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(System.Data.IDataReader reader)
|
|
{
|
|
List<DatabaseEntity> result = new List<DatabaseEntity>();
|
|
|
|
while (reader.Read())
|
|
{
|
|
IGCPosition igc = new IGCPosition();
|
|
igc.id = reader.GetGuid(0);
|
|
if (!reader.IsDBNull(1)) igc.UNNumber = reader.GetString(1);
|
|
if (!reader.IsDBNull(2)) igc.IMOClass = reader.GetString(2);
|
|
if (!reader.IsDBNull(3)) igc.ProductName = reader.GetString(3);
|
|
if (!reader.IsDBNull(4)) igc.Quantity_KGM = reader.GetDouble(4);
|
|
if (!reader.IsDBNull(5)) igc.StowagePosition = reader.GetString(5);
|
|
if (!reader.IsDBNull(6)) igc.PortOfLoading = reader.GetString(6);
|
|
if (!reader.IsDBNull(7)) igc.PortOfDischarge = reader.GetString(7);
|
|
if (!reader.IsDBNull(8)) igc.Remarks = reader.GetString(8);
|
|
if (!reader.IsDBNull(9)) igc.Identifier = reader.GetString(9);
|
|
|
|
result.Add(igc);
|
|
}
|
|
reader.Close();
|
|
return result;
|
|
}
|
|
|
|
#endregion
|
|
|
|
}
|
|
}
|