121 lines
3.7 KiB
C#
121 lines
3.7 KiB
C#
//
|
|
// Class: SubsidiaryRisks
|
|
// Current CLR: 4.0.30319.34209
|
|
// System: Microsoft Visual Studio 10.0
|
|
// Author: dani
|
|
// Created: 5/31/2015 10:00:57 AM
|
|
//
|
|
// Copyright (c) 2015 Informatikbüro Daniel Schick. All rights reserved.
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Data.SqlClient;
|
|
using Newtonsoft.Json;
|
|
|
|
namespace bsmd.database
|
|
{
|
|
public class SubsidiaryRisks : DatabaseEntity, ISublistElement
|
|
{
|
|
|
|
public SubsidiaryRisks()
|
|
{
|
|
this.tablename = "[dbo].[SubsidiaryRisks]";
|
|
}
|
|
|
|
#region Properties
|
|
|
|
[JsonIgnore]
|
|
public IMDGPosition IMDGPosition { get; set; }
|
|
|
|
[ShowReport]
|
|
[MaxLength(11)]
|
|
[ENI2Validation]
|
|
public string SubsidiaryRisk { get; set; }
|
|
|
|
public string Identifier { get; set; }
|
|
|
|
[JsonIgnore]
|
|
public string SublistCollectionKey { get { return "subsidiaryrisks"; } }
|
|
|
|
#endregion
|
|
|
|
#region DatabaseEntity implementation
|
|
|
|
public override void PrepareSave(IDbCommand cmd)
|
|
{
|
|
SqlCommand scmd = cmd as SqlCommand;
|
|
|
|
scmd.Parameters.AddWithValue("@P1", this.IMDGPosition.Id);
|
|
scmd.Parameters.AddWithNullableValue("@P2", this.SubsidiaryRisk);
|
|
scmd.Parameters.AddWithNullableValue("@P3", this.Identifier);
|
|
|
|
if (this.IsNew)
|
|
{
|
|
this.CreateId();
|
|
scmd.Parameters.AddWithValue("@ID", this.Id);
|
|
cmd.CommandText = string.Format("INSERT INTO {0} (Id, IMDGPositionId, SubsidiaryRisk, Identifier) " +
|
|
"VALUES (@ID, @P1, @P2, @P3)", this.Tablename);
|
|
}
|
|
else
|
|
{
|
|
cmd.CommandText = string.Format("UPDATE {0} SET SubsidiaryRisk = @P2, Identifier = @P3 WHERE Id = @ID", this.Tablename);
|
|
scmd.Parameters.AddWithValue("@ID", this.Id);
|
|
}
|
|
}
|
|
|
|
public override void PrepareLoadCommand(IDbCommand cmd, Message.LoadFilter filter, params object[] criteria)
|
|
{
|
|
string query = string.Format("SELECT Id, SubsidiaryRisk, Identifier FROM {0}",
|
|
this.Tablename);
|
|
|
|
switch (filter)
|
|
{
|
|
case Message.LoadFilter.IMDG_ID:
|
|
query += "WHERE IMDGPositionId = @IMDGID";
|
|
((SqlCommand)cmd).Parameters.AddWithValue("@IMDGID", 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())
|
|
{
|
|
SubsidiaryRisks sRisks = new SubsidiaryRisks();
|
|
sRisks.id = reader.GetGuid(0);
|
|
if (!reader.IsDBNull(1)) sRisks.SubsidiaryRisk = reader.GetString(1);
|
|
if (!reader.IsDBNull(2)) sRisks.Identifier = reader.GetString(2);
|
|
result.Add(sRisks);
|
|
}
|
|
|
|
reader.Close();
|
|
result.Sort();
|
|
return result;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region IComparable implementation
|
|
|
|
public int CompareTo(object obj)
|
|
{
|
|
if (this.Identifier == null) return 1;
|
|
if ((obj is null) || (((SubsidiaryRisks)obj).Identifier == null))
|
|
return 1;
|
|
return this.Identifier.CompareTo(((SubsidiaryRisks)obj).Identifier);
|
|
}
|
|
|
|
#endregion
|
|
|
|
}
|
|
}
|