131 lines
4.1 KiB
C#
131 lines
4.1 KiB
C#
// Copyright (c) 2026-present schick Informatik
|
|
// Description: WAS Exemption entries
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Data.SqlClient;
|
|
|
|
namespace bsmd.database
|
|
{
|
|
public class WASExemption : DatabaseEntityAsync, IComparable
|
|
{
|
|
#region Construction
|
|
|
|
public WASExemption()
|
|
{
|
|
this.tablename = "[dbo].[WASExemption]";
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Properties
|
|
|
|
[MaxLength(7)]
|
|
public string IMO { get; set; }
|
|
|
|
[MaxLength(100)]
|
|
public string ShipName { get; set; }
|
|
|
|
[MaxLength(70)]
|
|
public string Port { get; set; }
|
|
|
|
public DateTime ValidUntil { get; set; }
|
|
|
|
#endregion
|
|
|
|
#region DatabaseEntity implementation
|
|
|
|
public override void PrepareSave(IDbCommand cmd)
|
|
{
|
|
SqlCommand scmd = cmd as SqlCommand;
|
|
|
|
if (this.IMO != null) scmd.Parameters.AddWithValue("@P1", this.IMO);
|
|
else scmd.Parameters.AddWithValue("@P1", DBNull.Value);
|
|
if (this.ShipName != null) scmd.Parameters.AddWithValue("@P2", this.ShipName);
|
|
else scmd.Parameters.AddWithValue("@P2", DBNull.Value);
|
|
if (this.Port != null) scmd.Parameters.AddWithValue("@P3", this.Port);
|
|
else scmd.Parameters.AddWithValue("@P3", DBNull.Value);
|
|
scmd.Parameters.AddWithValue("@P4", this.ValidUntil);
|
|
|
|
if (this.IsNew)
|
|
{
|
|
this.CreateId();
|
|
scmd.Parameters.AddWithValue("@ID", this.Id);
|
|
cmd.CommandText = string.Format(
|
|
"INSERT INTO {0} (Id, IMO, ShipName, Port, ValidUntil) VALUES (@ID, @P1, @P2, @P3, @P4)",
|
|
this.Tablename);
|
|
}
|
|
else
|
|
{
|
|
cmd.CommandText = string.Format(
|
|
"UPDATE {0} SET IMO = @P1, ShipName = @P2, Port = @P3, ValidUntil = @P4 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, IMO, ShipName, Port, ValidUntil FROM {0}", this.Tablename);
|
|
|
|
switch (filter)
|
|
{
|
|
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())
|
|
{
|
|
WASExemption was = new WASExemption();
|
|
was.id = reader.GetGuid(0);
|
|
if (!reader.IsDBNull(1)) was.IMO = reader.GetString(1);
|
|
if (!reader.IsDBNull(2)) was.ShipName = reader.GetString(2);
|
|
if (!reader.IsDBNull(3)) was.Port = reader.GetString(3);
|
|
if (!reader.IsDBNull(4)) was.ValidUntil = reader.GetDateTime(4);
|
|
|
|
result.Add(was);
|
|
}
|
|
reader.Close();
|
|
return result;
|
|
}
|
|
|
|
protected override DatabaseEntityAsync ReadRowFromReader(IDataReader reader)
|
|
{
|
|
WASExemption was = null;
|
|
if (reader != null)
|
|
{
|
|
was = new WASExemption();
|
|
was.id = reader.GetGuid(0);
|
|
if (!reader.IsDBNull(1)) was.IMO = reader.GetString(1);
|
|
if (!reader.IsDBNull(2)) was.ShipName = reader.GetString(2);
|
|
if (!reader.IsDBNull(3)) was.Port = reader.GetString(3);
|
|
if (!reader.IsDBNull(4)) was.ValidUntil = reader.GetDateTime(4);
|
|
}
|
|
return was;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region IComparable implementation
|
|
|
|
public int CompareTo(object obj)
|
|
{
|
|
if (obj is WASExemption exemption)
|
|
{
|
|
return this.ShipName?.CompareTo(exemption.ShipName ?? "") ?? 0;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|