git_bsmd/nsw/Source/bsmd.database/WAS.cs
Daniel Schick f4b3d3caf0 Stand nach Live-Schaltung (noch keine Übermittlung Richtung DBH/Dakosy)
Aktiv ist Herberg FormService und der Report Generator
30.Mai 2015
2015-05-30 18:56:16 +00:00

151 lines
5.4 KiB
C#

//
// Class: WAS
// Current CLR: 4.0.30319.34209
// System: Microsoft Visual Studio 10.0
// Author: dani
// Created: 4/2/2015 7:38:45 PM
//
// Copyright (c) 2015 Informatikbüro Daniel Schick. All rights reserved.
using System;
using System.Data;
using System.Data.SqlClient;
using System.Collections.Generic;
namespace bsmd.database
{
public class WAS : DatabaseEntity, ISublistContainer
{
private List<WasteDisposalServiceProvider> wdsp = new List<WasteDisposalServiceProvider>();
private List<Waste> waste = new List<Waste>();
public WAS()
{
this.tablename = "[dbo].[WAS]";
}
#region Properties
[ShowReport]
public bool? WasteDisposalValidExemption { get; set; }
[ShowReport]
public string LastWasteDisposalPort { get; set; }
[ShowReport]
public bool? ConfirmationOfCorrectness { get; set; }
[ShowReport]
public DateTime? LastWasteDisposalDate { get; set; }
[ShowReport]
public byte? WasteDisposalDelivery { get; set; }
public List<Waste> Waste { get { return this.waste; } }
public List<WasteDisposalServiceProvider> WasteDisposalServiceProvider { get { return this.wdsp; } }
#endregion
#region DatabaseEntity implementation
public override void PrepareSave(System.Data.IDbCommand cmd)
{
SqlCommand scmd = cmd as SqlCommand;
scmd.Parameters.AddWithValue("@P1", this.MessageHeader.Id);
scmd.Parameters.AddWithNullableValue("@P2", this.WasteDisposalValidExemption);
scmd.Parameters.AddWithNullableValue("@P3", this.LastWasteDisposalPort);
scmd.Parameters.AddWithNullableValue("@P4", this.ConfirmationOfCorrectness);
scmd.Parameters.AddWithNullableValue("@P5", this.LastWasteDisposalDate);
scmd.Parameters.AddWithNullableValue("@P6", this.WasteDisposalDelivery);
if (this.IsNew)
{
this.CreateId();
scmd.Parameters.AddWithValue("@ID", this.Id);
scmd.CommandText = string.Format("INSERT INTO {0} (Id, MessageHeaderId, WasteDisposalValidExemption, " +
"LastWasteDisposalPort, ConfirmationOfCorrectness, LastWasteDisposalDate, WasteDisposalDelivery) " +
"VALUES ( @ID, @P1, @P2, @P3, @P4, @P5, @P6 )", this.Tablename);
}
else
{
scmd.Parameters.AddWithValue(@"ID", this.Id);
scmd.CommandText = string.Format("UPDATE {0} SET WasteDisposalValidExemption = @P2, LastWasteDisposalPort = @P3, " +
"ConfirmationOfCorrectness = @P4, LastWasteDisposalDate = @P5, WasteDisposalDelivery = @P6 " +
"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, WasteDisposalValidExemption, LastWasteDisposalPort, ConfirmationOfCorrectness, LastWasteDisposalDate, WasteDisposalDelivery " +
"FROM {0} ", this.Tablename);
switch (filter)
{
case Message.LoadFilter.MESSAGEHEADER:
query += " WHERE MessageHeaderId = @MHID";
((SqlCommand)cmd).Parameters.AddWithValue("@MHID", 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())
{
WAS was = new WAS();
was.id = reader.GetGuid(0);
if (!reader.IsDBNull(1)) was.WasteDisposalValidExemption = reader.GetBoolean(1);
if (!reader.IsDBNull(2)) was.LastWasteDisposalPort = reader.GetString(2);
if (!reader.IsDBNull(3)) was.ConfirmationOfCorrectness = reader.GetBoolean(3);
if (!reader.IsDBNull(4)) was.LastWasteDisposalDate = reader.GetDateTime(4);
if (!reader.IsDBNull(5)) was.WasteDisposalDelivery = reader.GetByte(5);
result.Add(was);
}
reader.Close();
return result;
}
#endregion
#region ISublistContainer implementation
public ISublistElement GetSublistElementWithIdentifier(string identifier)
{
foreach (Waste waste in this.Waste)
{
if (waste.Identifier.Equals(identifier))
return waste;
}
return null;
}
#endregion
#region IMessageParagraph implementation
public override List<IMessageParagraph> ChildParagraphs
{
get
{
List<IMessageParagraph> result = new List<IMessageParagraph>();
foreach (IMessageParagraph imp in this.Waste)
result.Add(imp);
return result;
}
}
#endregion
}
}