146 lines
4.6 KiB
C#
146 lines
4.6 KiB
C#
// Copyright (c) 2020-present schick Informatik
|
|
// Description: Element für WAS_RCPT
|
|
|
|
using System.Data.SqlClient;
|
|
using System.Collections.Generic;
|
|
using Newtonsoft.Json;
|
|
using System.ComponentModel;
|
|
using System;
|
|
using System.Data;
|
|
|
|
namespace bsmd.database
|
|
{
|
|
|
|
[TypeConverter(typeof(MessageClassConverter<WasteReceived>))]
|
|
[JsonConverter(typeof(NoTypeConverterJsonConverter<WasteReceived>))]
|
|
public class WasteReceived : DatabaseEntity, ISublistElement
|
|
{
|
|
|
|
public WasteReceived()
|
|
{
|
|
this.tablename = "[dbo].[WasteReceived]";
|
|
}
|
|
|
|
#region ISublistElement implementation
|
|
|
|
[JsonIgnore]
|
|
[Browsable(false)]
|
|
public string SublistCollectionKey { get { return "wasteReceived"; } }
|
|
|
|
public string Identifier { get; set; }
|
|
|
|
#endregion
|
|
|
|
#region Properties
|
|
|
|
[JsonIgnore]
|
|
[Browsable(false)]
|
|
public WAS_RCPT WAS_RCPT { get; set; }
|
|
|
|
[ShowReport]
|
|
[MaxLength(3)]
|
|
[ENI2Validation]
|
|
public string WasteCode { get; set; }
|
|
|
|
[JsonIgnore]
|
|
public string WasteTypeDisplayGrid
|
|
{
|
|
get
|
|
{
|
|
return string.Format("{0} {1}", WasteCode, WAS.WasteCodeDict[WasteCode]);
|
|
}
|
|
}
|
|
|
|
[ShowReport]
|
|
[MaxLength(256)]
|
|
[ENI2Validation]
|
|
public string WasteDescription { get; set; }
|
|
|
|
[ShowReport]
|
|
[Validation(ValidationCode.NOT_NULL)]
|
|
[ENI2Validation]
|
|
public double? AmountWasteReceived_MTQ { get; set; }
|
|
|
|
#endregion
|
|
|
|
#region DatabaseEntity implementation
|
|
|
|
public override List<DatabaseEntity> LoadList(IDataReader reader)
|
|
{
|
|
List<DatabaseEntity> result = new List<DatabaseEntity>();
|
|
|
|
while (reader.Read())
|
|
{
|
|
WasteReceived wasteReceived = new WasteReceived();
|
|
|
|
wasteReceived.id = reader.GetGuid(0);
|
|
if (!reader.IsDBNull(1)) wasteReceived.WasteCode = reader.GetString(1);
|
|
if (!reader.IsDBNull(2)) wasteReceived.WasteDescription = reader.GetString(2);
|
|
if (!reader.IsDBNull(3)) wasteReceived.AmountWasteReceived_MTQ = (float)reader.GetDouble(3);
|
|
if (!reader.IsDBNull(4)) wasteReceived.Identifier = reader.GetString(4);
|
|
result.Add(wasteReceived);
|
|
}
|
|
reader.Close();
|
|
return result;
|
|
}
|
|
|
|
public override void PrepareLoadCommand(IDbCommand cmd, Message.LoadFilter filter, params object[] criteria)
|
|
{
|
|
string query = string.Format("SELECT Id, WasteCode, WasteDescription, AmountWasteReceived_MTQ, Identifier FROM {0} ", this.Tablename);
|
|
|
|
switch (filter)
|
|
{
|
|
case Message.LoadFilter.WASRCPT_ID:
|
|
query += " WHERE WAS_RCPTId = @WDID";
|
|
((SqlCommand)cmd).Parameters.AddWithValue("@WDID", criteria[0]);
|
|
break;
|
|
case Message.LoadFilter.ALL:
|
|
default:
|
|
|
|
break;
|
|
}
|
|
query += " ORDER BY CAST(Identifier AS INT)";
|
|
|
|
cmd.CommandText = query;
|
|
}
|
|
|
|
public override void PrepareSave(IDbCommand cmd)
|
|
{
|
|
SqlCommand scmd = cmd as SqlCommand;
|
|
|
|
scmd.Parameters.AddWithValue("@P1", this.WAS_RCPT.Id);
|
|
scmd.Parameters.AddWithNullableValue("@P2", this.WasteCode);
|
|
scmd.Parameters.AddWithNullableValue("@P3", this.WasteDescription);
|
|
scmd.Parameters.AddWithNullableValue("@P4", this.AmountWasteReceived_MTQ);
|
|
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, WAS_RCPTId, WasteCode, WasteDescription, " +
|
|
"AmountWasteReceived_MTQ, Identifier) " +
|
|
" VALUES ( @ID, @P1, @P2, @P3, @P4, @P5 )", this.Tablename);
|
|
}
|
|
else
|
|
{
|
|
scmd.Parameters.AddWithValue("@ID", this.Id);
|
|
scmd.CommandText = string.Format("UPDATE {0} SET WasteCode = @P2, WasteDescription = @P3, " +
|
|
"AmountWasteReceived_MTQ = @P4, Identifier = @P5 WHERE Id = @ID", this.Tablename);
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Validation
|
|
|
|
public override void Validate(List<MessageError> errors, List<MessageViolation> violations)
|
|
{
|
|
|
|
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|