145 lines
4.5 KiB
C#
145 lines
4.5 KiB
C#
//
|
|
// Class: CallPurpose
|
|
// Current CLR: 4.0.30319.34209
|
|
// System: Microsoft Visual Studio 10.0
|
|
// Author: dani
|
|
// Created: 5/20/2015 8:16:09 PM
|
|
//
|
|
// Copyright (c) 2015 Informatikbüro Daniel Schick. All rights reserved.
|
|
|
|
using System;
|
|
using System.Data;
|
|
using System.Data.SqlClient;
|
|
using System.Collections.Generic;
|
|
using Newtonsoft.Json;
|
|
using System.ComponentModel;
|
|
using System.Runtime.Serialization;
|
|
|
|
namespace bsmd.database
|
|
{
|
|
|
|
[TypeConverter(typeof(MessageClassConverter<CallPurpose>))]
|
|
[JsonConverter(typeof(NoTypeConverterJsonConverter<CallPurpose>))]
|
|
[DataContract]
|
|
public class CallPurpose : DatabaseEntity, ISublistElement
|
|
{
|
|
|
|
public CallPurpose()
|
|
{
|
|
this.tablename = "[dbo].[CallPurpose]";
|
|
}
|
|
|
|
#region Properties
|
|
|
|
[JsonIgnore]
|
|
[Browsable(false)]
|
|
public NOA_NOD NOA_NOD { get; set; }
|
|
|
|
// [ShowReport]
|
|
[ENI2Validation]
|
|
[DataMember]
|
|
public int CallPurposeCode { get; set; }
|
|
|
|
[ShowReport]
|
|
[MaxLength(99)]
|
|
[ENI2Validation]
|
|
[Validation(ValidationCode.STRING_MAXLEN, 99)]
|
|
[DataMember]
|
|
public string CallPurposeDescription { get; set; }
|
|
|
|
public string Identifier { get; set; }
|
|
|
|
[JsonIgnore]
|
|
public string SublistCollectionKey { get { return "callpurpose"; } }
|
|
|
|
#endregion
|
|
|
|
#region DatabaseEntity implementation
|
|
|
|
public override void PrepareSave(System.Data.IDbCommand cmd)
|
|
{
|
|
SqlCommand scmd = cmd as SqlCommand;
|
|
|
|
scmd.Parameters.AddWithValue("@P1", this.NOA_NOD.Id);
|
|
scmd.Parameters.AddWithNullableValue("@P2", this.CallPurposeCode);
|
|
scmd.Parameters.AddWithNullableValue("@P3", this.CallPurposeDescription);
|
|
scmd.Parameters.AddWithNullableValue("@P4", this.Identifier);
|
|
|
|
if (this.IsNew)
|
|
{
|
|
this.CreateId();
|
|
scmd.Parameters.AddWithValue("@ID", this.Id);
|
|
scmd.CommandText = string.Format("INSERT INTO {0} (Id, NOA_NODId, CallPurposeCode, CallPurposeDescription, Identifier) " +
|
|
" VALUES (@ID, @P1, @P2, @P3, @P4 )", this.Tablename);
|
|
}
|
|
else
|
|
{
|
|
scmd.Parameters.AddWithValue("@ID", this.Id);
|
|
scmd.CommandText = string.Format("UPDATE {0} SET CallPurposeCode = @P2, CallPurposeDescription = @P3, Identifier = @P4 " +
|
|
"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, CallPurposeCode, CallPurposeDescription, Identifier FROM {0} ", this.Tablename);
|
|
|
|
switch (filter)
|
|
{
|
|
case Message.LoadFilter.NOA_NODID:
|
|
query += " WHERE NOA_NODId = @NNID ";
|
|
((SqlCommand)cmd).Parameters.AddWithValue("@NNID", criteria[0]);
|
|
break;
|
|
case Message.LoadFilter.ALL:
|
|
default:
|
|
|
|
break;
|
|
}
|
|
|
|
cmd.CommandText = query;
|
|
}
|
|
|
|
public override List<DatabaseEntity> LoadList(System.Data.IDataReader reader)
|
|
{
|
|
List<DatabaseEntity> result = new List<DatabaseEntity>();
|
|
|
|
while (reader.Read())
|
|
{
|
|
CallPurpose cp = new CallPurpose();
|
|
|
|
cp.id = reader.GetGuid(0);
|
|
if (!reader.IsDBNull(1)) cp.CallPurposeCode = reader.GetInt32(1);
|
|
if (!reader.IsDBNull(2)) cp.CallPurposeDescription = reader.GetString(2);
|
|
if (!reader.IsDBNull(3)) cp.Identifier = reader.GetString(3);
|
|
result.Add(cp);
|
|
}
|
|
reader.Close();
|
|
result.Sort();
|
|
return result;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region public overrides
|
|
|
|
public override string ToString()
|
|
{
|
|
return string.Format("{0} - {1}", this.CallPurposeCode, this.CallPurposeDescription ?? "");
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region IComparable implementation
|
|
|
|
public int CompareTo(object obj)
|
|
{
|
|
if (obj is null)
|
|
return 1;
|
|
return this.Identifier.CompareTo(((CallPurpose)obj).Identifier);
|
|
}
|
|
|
|
#endregion
|
|
|
|
}
|
|
}
|