122 lines
4.1 KiB
C#
122 lines
4.1 KiB
C#
//
|
|
// Class: SanitaryMeasuresDetail
|
|
// 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;
|
|
|
|
namespace bsmd.database
|
|
{
|
|
public class SanitaryMeasuresDetail : DatabaseEntity, ISublistElement
|
|
{
|
|
|
|
public SanitaryMeasuresDetail()
|
|
{
|
|
this.tablename = "[dbo].[SanitaryMeasuresDetail]";
|
|
}
|
|
|
|
#region Properties
|
|
|
|
public MDH MDH { get; set; }
|
|
|
|
[ShowReport]
|
|
[MaxLength(255)]
|
|
[ENI2Validation]
|
|
public string SanitaryMeasuresType { get; set; }
|
|
|
|
[ShowReport]
|
|
[MaxLength(255)]
|
|
[ENI2Validation]
|
|
public string SanitaryMeasuresLocation { get; set; }
|
|
|
|
[ShowReport]
|
|
[ENI2Validation]
|
|
public DateTime? SanitaryMeasuresDate { get; set; }
|
|
|
|
public string Identifier { get; set; }
|
|
|
|
#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.SanitaryMeasuresType);
|
|
scmd.Parameters.AddWithNullableValue("@P3", this.SanitaryMeasuresLocation);
|
|
scmd.Parameters.AddWithNullableValue("@P4", this.SanitaryMeasuresDate);
|
|
scmd.Parameters.AddWithNullableValue("@P5", this.Identifier);
|
|
|
|
if (this.IsNew)
|
|
{
|
|
this.CreateId();
|
|
scmd.Parameters.AddWithValue("@ID", this.Id);
|
|
scmd.CommandText = string.Format("INSERT INTO {0} (Id, MDH_Id, SanitaryMeasuresType, SanitaryMeasuresLocation, " +
|
|
"SanitaryMeasuresDate, Identifier) VALUES (@ID, @P1, @P2, @P3, @P4, @P5)", this.Tablename);
|
|
}
|
|
else
|
|
{
|
|
scmd.CommandText = string.Format("UPDATE {0} SET SanitaryMeasuresType = @P2, SanitaryMeasuresLocation = @P3, " +
|
|
"SanitaryMeasuresDate = @P4 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, SanitaryMeasuresType, SanitaryMeasuresLocation, " +
|
|
"SanitaryMeasuresDate, 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;
|
|
}
|
|
|
|
query += " ORDER BY CAST(Identifier AS INT)";
|
|
|
|
cmd.CommandText = query;
|
|
}
|
|
|
|
public override List<DatabaseEntity> LoadList(IDataReader reader)
|
|
{
|
|
List<DatabaseEntity> result = new List<DatabaseEntity>();
|
|
|
|
while (reader.Read())
|
|
{
|
|
SanitaryMeasuresDetail smd = new SanitaryMeasuresDetail();
|
|
smd.id = reader.GetGuid(0);
|
|
if (!reader.IsDBNull(1)) smd.SanitaryMeasuresType = reader.GetString(1);
|
|
if (!reader.IsDBNull(2)) smd.SanitaryMeasuresLocation = reader.GetString(2);
|
|
if (!reader.IsDBNull(3)) smd.SanitaryMeasuresDate = reader.GetDateTime(3);
|
|
if (!reader.IsDBNull(4)) smd.Identifier = reader.GetString(4);
|
|
result.Add(smd);
|
|
}
|
|
|
|
reader.Close();
|
|
return result;
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
}
|
|
}
|