181 lines
5.9 KiB
C#
181 lines
5.9 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;
|
|
using Newtonsoft.Json;
|
|
using System.ComponentModel;
|
|
|
|
namespace bsmd.database
|
|
{
|
|
|
|
[TypeConverter(typeof(MessageClassConverter<SanitaryMeasuresDetail>))]
|
|
[JsonConverter(typeof(NoTypeConverterJsonConverter<SanitaryMeasuresDetail>))]
|
|
public class SanitaryMeasuresDetail : DatabaseEntity, ISublistElement
|
|
{
|
|
|
|
public SanitaryMeasuresDetail()
|
|
{
|
|
this.tablename = "[dbo].[SanitaryMeasuresDetail]";
|
|
}
|
|
|
|
#region Properties
|
|
|
|
[JsonIgnore]
|
|
public MDH MDH { get; set; }
|
|
|
|
[ShowReport]
|
|
[MaxLength(99)]
|
|
[ENI2Validation]
|
|
[Validation2(ValidationCode.NOT_NULL_MAX_LEN, 99)]
|
|
public string SanitaryMeasuresType { get; set; }
|
|
|
|
[ShowReport]
|
|
[MaxLength(99)]
|
|
[ENI2Validation]
|
|
[Validation2(ValidationCode.NOT_NULL_MAX_LEN, 99)]
|
|
public string SanitaryMeasuresLocation { get; set; }
|
|
|
|
[ShowReport]
|
|
[ENI2Validation]
|
|
[Validation2(ValidationCode.NOT_NULL)]
|
|
public DateTime? SanitaryMeasuresDate { get; set; }
|
|
|
|
public string Identifier { get; set; }
|
|
|
|
[JsonIgnore]
|
|
[Browsable(false)]
|
|
public string SublistCollectionKey { get { return "smd"; } }
|
|
|
|
#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, Identifier = @P5 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;
|
|
}
|
|
|
|
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();
|
|
result.Sort();
|
|
return result;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Validation
|
|
|
|
public override ValidationBlock GetValidationBlock()
|
|
{
|
|
return ValidationBlock.BLOCK2;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region IComparable implementation
|
|
|
|
public int CompareTo(object obj)
|
|
{
|
|
if (object.ReferenceEquals(obj, null))
|
|
return 1;
|
|
return this.Identifier.CompareTo(((SanitaryMeasuresDetail)obj).Identifier);
|
|
}
|
|
|
|
#endregion
|
|
|
|
}
|
|
|
|
#region class SanitaryMeasuresDetailConverter
|
|
|
|
public class SanitaryMeasuresDetailConverter : TypeConverter
|
|
{
|
|
public override bool CanConvertFrom(ITypeDescriptorContext context, System.Type sourceType)
|
|
{
|
|
if (sourceType == typeof(string))
|
|
{
|
|
return true;
|
|
}
|
|
return base.CanConvertFrom(context, sourceType);
|
|
}
|
|
|
|
public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
|
|
{
|
|
if (value is string)
|
|
{
|
|
string s = value.ToString();
|
|
//s = s.Replace("\\", "");
|
|
return JsonConvert.DeserializeObject<SanitaryMeasuresDetail>(s);
|
|
}
|
|
return base.ConvertFrom(context, culture, value);
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
}
|