115 lines
3.2 KiB
C#
115 lines
3.2 KiB
C#
// Copyright (c) 2026 schick Informatik
|
|
// Description: DB entity for LADG NST2007 lookup
|
|
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Data.SqlClient;
|
|
|
|
namespace bsmd.database
|
|
{
|
|
public class LADG_NST2007 : DatabaseEntity
|
|
{
|
|
public LADG_NST2007()
|
|
{
|
|
this.tablename = "[dbo].[LADG_NST2007]";
|
|
}
|
|
|
|
#region Properties
|
|
|
|
[MaxLength(100)]
|
|
[ENI2Validation]
|
|
public string Description { get; set; }
|
|
|
|
[MaxLength(3)]
|
|
[ENI2Validation]
|
|
public string NST2007 { get; set; }
|
|
|
|
#endregion
|
|
|
|
#region public static methods
|
|
|
|
public static bool NST2007Exists(string nst2007)
|
|
{
|
|
if (nst2007.IsNullOrEmpty())
|
|
return false;
|
|
|
|
return DBManagerAsync.GetLADGNST2007Dict().ContainsKey(nst2007);
|
|
}
|
|
|
|
public static string GetDescription(string nst2007)
|
|
{
|
|
if (nst2007.IsNullOrEmpty())
|
|
return null;
|
|
|
|
if (DBManagerAsync.GetLADGNST2007Dict().TryGetValue(nst2007, out LADG_NST2007 value))
|
|
return value.Description;
|
|
|
|
return null;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region abstract method implementation
|
|
|
|
public override List<DatabaseEntity> LoadList(IDataReader reader)
|
|
{
|
|
List<DatabaseEntity> result = new List<DatabaseEntity>();
|
|
while (reader.Read())
|
|
{
|
|
LADG_NST2007 item = new LADG_NST2007();
|
|
item.id = reader.GetGuid(0);
|
|
if (!reader.IsDBNull(1)) item.Description = reader.GetString(1);
|
|
if (!reader.IsDBNull(2)) item.NST2007 = reader.GetString(2);
|
|
result.Add(item);
|
|
}
|
|
reader.Close();
|
|
return result;
|
|
}
|
|
|
|
public override void PrepareLoadCommand(IDbCommand cmd, Message.LoadFilter filter, params object[] criteria)
|
|
{
|
|
string query = string.Format("SELECT Id, Description, NST2007 FROM {0} ", this.Tablename);
|
|
|
|
switch (filter)
|
|
{
|
|
case Message.LoadFilter.ALL:
|
|
default:
|
|
break;
|
|
}
|
|
|
|
cmd.CommandText = query;
|
|
}
|
|
|
|
public override void PrepareSave(IDbCommand cmd)
|
|
{
|
|
SqlCommand scmd = cmd as SqlCommand;
|
|
|
|
scmd.Parameters.AddWithNullableValue("@DESCRIPTION", this.Description);
|
|
scmd.Parameters.AddWithNullableValue("@NST2007", this.NST2007);
|
|
|
|
if (this.IsNew)
|
|
{
|
|
this.CreateId();
|
|
scmd.Parameters.AddWithValue("@ID", this.Id);
|
|
scmd.CommandText = string.Format("INSERT INTO {0} (Id, Description, NST2007) VALUES (@ID, @DESCRIPTION, @NST2007)", this.Tablename);
|
|
}
|
|
else
|
|
{
|
|
scmd.Parameters.AddWithValue("@ID", this.Id);
|
|
scmd.CommandText = string.Format("UPDATE {0} SET Description = @DESCRIPTION, NST2007 = @NST2007 WHERE Id = @ID", this.Tablename);
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region override
|
|
|
|
public override string ToString()
|
|
{
|
|
return string.Format("{0} {1}", this.NST2007, this.Description);
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|