140 lines
5.0 KiB
C#
140 lines
5.0 KiB
C#
//
|
|
// Class: PortOfCallLast30Days
|
|
// Current CLR: 4.0.30319.34209
|
|
// System: Microsoft Visual Studio 10.0
|
|
// Author: dani
|
|
// Created: 3/22/2015 8:29:02 AM
|
|
//
|
|
// 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 PortOfCallLast30Days : DatabaseEntity, ISublistElement, ISublistContainer
|
|
{
|
|
|
|
private List<PortOfCallLast30DaysCrewJoinedShip> poc30Crew = new List<PortOfCallLast30DaysCrewJoinedShip>();
|
|
|
|
public PortOfCallLast30Days()
|
|
{
|
|
this.tablename = "[dbo].[PortOfCallLast30Days]";
|
|
}
|
|
|
|
#region Properties
|
|
|
|
public MDH MDH { get; set; }
|
|
|
|
public List<PortOfCallLast30DaysCrewJoinedShip> CrewJoinedShip { get { return this.poc30Crew; } }
|
|
[ShowReport]
|
|
public string PortOfCallLast30DaysLocode { get; set; }
|
|
[ShowReport]
|
|
public DateTime? PortOfCallLast30DaysDateOfDeparture { get; set; }
|
|
[ShowReport]
|
|
public bool? PortOfCallLast30DaysCrewMembersJoined { get; set; }
|
|
|
|
public string Identifier { get; set; }
|
|
|
|
#endregion
|
|
|
|
#region abstract class implementation
|
|
|
|
public override void PrepareSave(IDbCommand cmd)
|
|
{
|
|
SqlCommand scmd = cmd as SqlCommand;
|
|
|
|
scmd.Parameters.AddWithNullableValue("@P1", this.MDH.Id);
|
|
scmd.Parameters.AddWithNullableValue("@P2", this.PortOfCallLast30DaysLocode);
|
|
scmd.Parameters.AddWithNullableValue("@P3", this.PortOfCallLast30DaysDateOfDeparture);
|
|
scmd.Parameters.AddWithNullableValue("@P4", this.PortOfCallLast30DaysCrewMembersJoined);
|
|
scmd.Parameters.AddWithNullableValue("@P5", this.Identifier);
|
|
|
|
if (this.IsNew)
|
|
{
|
|
this.CreateId();
|
|
scmd.Parameters.AddWithValue("@ID", this.Id);
|
|
scmd.CommandText = string.Format("INSERT INTO {0} (Id, MDH_Id, PortOfCallLast30DaysLocode, PortOfCallLast30DaysDateOfDeparture, " +
|
|
"PortOfCallLast30DaysCrewMembersJoined, Identifier) VALUES (@ID, @P1, @P2, @P3, @P4, @P5)", this.Tablename);
|
|
}
|
|
else
|
|
{
|
|
scmd.CommandText = string.Format("UPDATE {0} SET PortOfCallLast30DaysLocode = @P2, PortOfCallLast30DaysDateOfDeparture = @P3, " +
|
|
"PortOfCallLast30DaysCrewMembersJoined = @P4 WHERE Id = @ID", this.Tablename);
|
|
scmd.Parameters.AddWithNullableValue("@ID", this.Id);
|
|
}
|
|
}
|
|
|
|
public override void PrepareLoadCommand(IDbCommand cmd, Message.LoadFilter filter, params object[] criteria)
|
|
{
|
|
|
|
string query = string.Format("SELECT Id, PortOfCallLast30DaysLocode, PortOfCallLast30DaysDateOfDeparture, " +
|
|
"PortOfCallLast30DaysCrewMembersJoined, Identifier FROM {0} ", this.Tablename);
|
|
|
|
switch (filter)
|
|
{
|
|
case Message.LoadFilter.MDH_ID:
|
|
query += "WHERE MDH_Id = @MDHID";
|
|
((SqlCommand)cmd).Parameters.AddWithValue("@MDHID", 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())
|
|
{
|
|
PortOfCallLast30Days poc = new PortOfCallLast30Days();
|
|
poc.id = reader.GetGuid(0);
|
|
if (!reader.IsDBNull(1)) poc.PortOfCallLast30DaysLocode = reader.GetString(1);
|
|
if (!reader.IsDBNull(2)) poc.PortOfCallLast30DaysDateOfDeparture = reader.GetDateTime(2);
|
|
if (!reader.IsDBNull(3)) poc.PortOfCallLast30DaysCrewMembersJoined = reader.GetBoolean(3);
|
|
if (!reader.IsDBNull(4)) poc.Identifier = reader.GetString(4);
|
|
result.Add(poc);
|
|
}
|
|
|
|
reader.Close();
|
|
return result;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region ISublistElement implementation
|
|
|
|
public ISublistElement GetSublistElementWithIdentifier(string identifier)
|
|
{
|
|
foreach (ISublistElement sElem in this.CrewJoinedShip)
|
|
if (sElem.Identifier.Equals(identifier))
|
|
return sElem;
|
|
return null;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region IMessageParagraph implementation
|
|
|
|
public override List<IMessageParagraph> ChildParagraphs
|
|
{
|
|
get
|
|
{
|
|
List<IMessageParagraph> result = new List<IMessageParagraph>();
|
|
foreach (IMessageParagraph imp in this.CrewJoinedShip)
|
|
result.Add(imp);
|
|
return result;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
}
|
|
}
|