106 lines
3.3 KiB
C#
106 lines
3.3 KiB
C#
// Copyright (c) 2020-present schick Informatik
|
|
// Description:
|
|
|
|
using System;
|
|
using System.Data;
|
|
using System.Data.SqlClient;
|
|
using System.Collections.Generic;
|
|
using Newtonsoft.Json;
|
|
|
|
namespace bsmd.database
|
|
{
|
|
public class TreatmentFacilityProvider : DatabaseEntity, ISublistElement
|
|
{
|
|
|
|
public TreatmentFacilityProvider()
|
|
{
|
|
this.tablename = "[dbo].[TreatmentFacilityProvider]";
|
|
}
|
|
|
|
#region Properties
|
|
|
|
[JsonIgnore]
|
|
public WAS_RCPT WAS_RCPT { get; set; }
|
|
|
|
[ShowReport]
|
|
[MaxLength(70)]
|
|
[ENI2Validation]
|
|
[Validation(ValidationCode.STRING_MAXLEN, 70)]
|
|
public string TreatmentFacilityProviderName { get; set; }
|
|
|
|
public string Identifier { get; set; }
|
|
|
|
[JsonIgnore]
|
|
public string SublistCollectionKey { get { return "tfp"; } }
|
|
|
|
#endregion
|
|
|
|
#region DatabaseEntity implementation
|
|
|
|
public override void PrepareSave(System.Data.IDbCommand cmd)
|
|
{
|
|
|
|
SqlCommand scmd = cmd as SqlCommand;
|
|
|
|
scmd.Parameters.AddWithValue("@P1", this.WAS_RCPT.Id);
|
|
scmd.Parameters.AddWithNullableValue("@P2", this.TreatmentFacilityProviderName);
|
|
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, WAS_RCPTId, TreatmentFacilityProviderName, Identifier) " +
|
|
"VALUES ( @ID, @P1, @P2, @P3 )", this.Tablename);
|
|
}
|
|
else
|
|
{
|
|
scmd.Parameters.AddWithValue("ID", this.Id);
|
|
scmd.CommandText = string.Format("UPDATE {0} SET TreatmentFacilityProviderName = @P2 " +
|
|
"WHERE Id = @ID", this.Tablename);
|
|
}
|
|
}
|
|
|
|
public override void PrepareLoadCommand(System.Data.IDbCommand cmd, Message.LoadFilter filter, params object[] criteria)
|
|
{
|
|
string query = string.Format("SELECT Id, TreatmentFacilityProviderName, Identifier FROM {0}", this.Tablename);
|
|
|
|
switch (filter)
|
|
{
|
|
case Message.LoadFilter.WASRCPT_ID:
|
|
query += "WHERE WAS_RCPTId = @WASRCPTID";
|
|
((SqlCommand)cmd).Parameters.AddWithValue("@WASRCPTID", criteria[0]);
|
|
break;
|
|
case Message.LoadFilter.ALL:
|
|
default:
|
|
|
|
break;
|
|
}
|
|
|
|
query += " ORDER BY CAST(Identifier AS INT)";
|
|
|
|
cmd.CommandText = query;
|
|
}
|
|
|
|
public override List<DatabaseEntity> LoadList(System.Data.IDataReader reader)
|
|
{
|
|
List<DatabaseEntity> result = new List<DatabaseEntity>();
|
|
|
|
while (reader.Read())
|
|
{
|
|
TreatmentFacilityProvider tfp = new TreatmentFacilityProvider();
|
|
|
|
tfp.id = reader.GetGuid(0);
|
|
if (!reader.IsDBNull(1)) tfp.TreatmentFacilityProviderName = reader.GetString(1);
|
|
if (!reader.IsDBNull(2)) tfp.Identifier = reader.GetString(2);
|
|
result.Add(tfp);
|
|
}
|
|
reader.Close();
|
|
return result;
|
|
}
|
|
|
|
#endregion
|
|
|
|
}
|
|
}
|