126 lines
4.0 KiB
C#
126 lines
4.0 KiB
C#
//
|
|
// Class: StowawaysJoiningLocation
|
|
// Current CLR: 4.0.30319.34209
|
|
// System: Microsoft Visual Studio 14.0
|
|
// Author: dani
|
|
// Created: 2/23/2016 8:35:02 AM
|
|
//
|
|
// Copyright (c) 2016 Informatikbüro Daniel Schick. All rights reserved.
|
|
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data.SqlClient;
|
|
using System.Data;
|
|
using Newtonsoft.Json;
|
|
using System.ComponentModel;
|
|
|
|
namespace bsmd.database
|
|
{
|
|
|
|
[TypeConverter(typeof(MessageClassConverter<StowawaysJoiningLocation>))]
|
|
[JsonConverter(typeof(NoTypeConverterJsonConverter<StowawaysJoiningLocation>))]
|
|
public class StowawaysJoiningLocation : DatabaseEntity, ISublistElement
|
|
{
|
|
|
|
public StowawaysJoiningLocation()
|
|
{
|
|
this.tablename = "[dbo].[StowawaysJoiningLocation]";
|
|
}
|
|
|
|
#region Properties
|
|
|
|
[JsonIgnore]
|
|
[Browsable(false)]
|
|
public MDH MDH { get; set; }
|
|
|
|
[ShowReport]
|
|
[MaxLength(99)]
|
|
[ENI2Validation]
|
|
[Validation2(ValidationCode.STRING_MAXLEN, 99)]
|
|
public string StowawayJoiningLocation { get; set; }
|
|
|
|
public string Identifier { get; set; }
|
|
|
|
[JsonIgnore]
|
|
public string SublistCollectionKey { get { return "stowaways"; } }
|
|
|
|
#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.StowawayJoiningLocation);
|
|
scmd.Parameters.AddWithNullableValue("@P3", this.Identifier);
|
|
|
|
if (this.IsNew)
|
|
{
|
|
this.CreateId();
|
|
scmd.Parameters.AddWithValue("@ID", this.Id);
|
|
scmd.CommandText = string.Format("INSERT INTO {0} (Id, MDH_Id, StowawaysJoiningLocation, " +
|
|
"Identifier) VALUES (@ID, @P1, @P2, @P3)", this.Tablename);
|
|
}
|
|
else
|
|
{
|
|
scmd.CommandText = string.Format("UPDATE {0} SET StowawaysJoiningLocation = @P2, Identifier = @P3 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, StowawaysJoiningLocation, Identifier FROM {0} ", this.Tablename);
|
|
|
|
switch (filter)
|
|
{
|
|
case Message.LoadFilter.MDH_ID:
|
|
query += "WHERE MDH_Id = @MDHID";
|
|
if (!cmd.Parameters.Contains("@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())
|
|
{
|
|
StowawaysJoiningLocation sjl = new StowawaysJoiningLocation();
|
|
sjl.id = reader.GetGuid(0);
|
|
if (!reader.IsDBNull(1)) sjl.StowawayJoiningLocation = reader.GetString(1);
|
|
if (!reader.IsDBNull(2)) sjl.Identifier = reader.GetString(2);
|
|
result.Add(sjl);
|
|
}
|
|
|
|
reader.Close();
|
|
result.Sort();
|
|
return result;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region IComparable implementation
|
|
|
|
public int CompareTo(object obj)
|
|
{
|
|
if (object.ReferenceEquals(obj, null))
|
|
return 1;
|
|
return this.Identifier.CompareTo(((StowawaysJoiningLocation)obj).Identifier);
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|