git_bsmd/nsw/Source/bsmd.database/INFO.cs
2015-04-30 06:31:56 +00:00

116 lines
4.5 KiB
C#

//
// Class: INFO
// Current CLR: 4.0.30319.34209
// System: Microsoft Visual Studio 10.0
// Author: dani
// Created: 4/2/2015 6:59:19 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 INFO : DatabaseEntity
{
public INFO()
{
this.tablename = "[dbo].[INFO]";
}
#region Properties
public byte? ShippingArea { get; set; }
public string RequestedPositionInPortOfCall { get; set; }
public string SpecialRequirementsOfShipAtBerth { get; set; }
public string ConstructionCharacteristicsOfShip { get; set; }
public byte? FumigatedBulkCargo { get; set; }
public float? DeplacementSummerDraught_TNE { get; set; }
#endregion
#region DatabaseEntity implementation
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.ShippingArea);
scmd.Parameters.AddWithNullableValue("@P3", this.RequestedPositionInPortOfCall);
scmd.Parameters.AddWithNullableValue("@P4", this.SpecialRequirementsOfShipAtBerth);
scmd.Parameters.AddWithNullableValue("@P5", this.ConstructionCharacteristicsOfShip);
scmd.Parameters.AddWithNullableValue("@P6", this.FumigatedBulkCargo);
scmd.Parameters.AddWithNullableValue("@P7", this.DeplacementSummerDraught_TNE);
if (this.IsNew)
{
scmd.CommandText = string.Format("INSERT INTO {0} (MessageHeaderId, ShippingArea, RequestedPositionInPortOfCall, " +
"SpecialRequirementsOfShipAtBerth, ConstructionCharacteristicsOfShip, FumigatedBulkCargo, DeplacementSummerDraught_TNE) " +
"VALUES ( @P1, @P2, @P3, @P4, @P5, @P6, @P7 )", this.Tablename);
}
else
{
scmd.Parameters.AddWithValue(@"ID", this.Id);
scmd.CommandText = string.Format("UPDATE {0} SET ShippingArea = @P2, RequestedPositionInPortOfCall = @P3, " +
"SpecialRequirementsOfShipAtBerth = @P4, ConstructionCharacteristicsOfShip = @P5, FumigatedBulkCargo = @P6," +
"DeplacementSummerDraught_TNE = @P7 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, ShippingArea, RequestedPositionInPortOfCall, SpecialRequirementsOfShipAtBerth, " +
"ConstructionCharacteristicsOfShip, FumigatedBulkCargo, DeplacementSummerDraught_TNE 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())
{
INFO info = new INFO();
info.id = reader.GetGuid(0);
if (!reader.IsDBNull(1)) info.ShippingArea = reader.GetByte(1);
if (!reader.IsDBNull(2)) info.RequestedPositionInPortOfCall = reader.GetString(2);
if (!reader.IsDBNull(3)) info.SpecialRequirementsOfShipAtBerth = reader.GetString(3);
if (!reader.IsDBNull(4)) info.ConstructionCharacteristicsOfShip = reader.GetString(4);
if (!reader.IsDBNull(5)) info.FumigatedBulkCargo = reader.GetByte(5);
if (!reader.IsDBNull(6)) info.DeplacementSummerDraught_TNE = reader.GetFloat(6);
result.Add(info);
}
reader.Close();
return result;
}
#endregion
}
}