// // Class: Waste // Current CLR: 4.0.30319.34209 // System: Microsoft Visual Studio 10.0 // Author: dani // Created: 4/2/2015 7:44:03 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 Waste : DatabaseEntity, ISublistElement { public Waste() { this.tablename = "[dbo].[Waste]"; } #region Properties public WAS WAS { get; set; } public byte? WasteType { get; set; } public string WasteDescription { get; set; } public float? WasteDisposalAmount_MTQ { get; set; } public float? WasteCapacity_MTQ { get; set; } public float? WasteAmountRetained_MTQ { get; set; } public string WasteDisposalPort { get; set; } public float? WasteAmountGeneratedTillNextPort_MTQ { get; set; } public string Identifier { get; set; } #endregion #region DatabaseEntity implementation public override void PrepareSave(System.Data.IDbCommand cmd) { SqlCommand scmd = cmd as SqlCommand; scmd.Parameters.AddWithValue("@P1", this.WAS.Id); scmd.Parameters.AddWithNullableValue("@P2", this.WasteType); scmd.Parameters.AddWithNullableValue("@P3", this.WasteDescription); scmd.Parameters.AddWithNullableValue("@P4", this.WasteDisposalAmount_MTQ); scmd.Parameters.AddWithNullableValue("@P5", this.WasteCapacity_MTQ); scmd.Parameters.AddWithNullableValue("@P6", this.WasteAmountRetained_MTQ); scmd.Parameters.AddWithNullableValue("@P7", this.WasteDisposalPort); scmd.Parameters.AddWithNullableValue("@P8", this.WasteAmountGeneratedTillNextPort_MTQ); scmd.Parameters.AddWithNullableValue("@P9", this.Identifier); if (this.IsNew) { scmd.CommandText = string.Format("INSERT INTO {0} (WASId, WasteType, WasteDescription, " + "WasteDisposalAmount_MTQ, WasteCapacity_MTQ, WasteAmountRetained_MTQ, WasteDisposalPort, " + "WasteAmountGeneratedTillNextPort_MTQ, Identifier) " + " VALUES ( @P1, @P2, @P3, @P4, @P5, @P6, @P7, @P8, @P9 )", this.Tablename); } else { scmd.Parameters.AddWithValue(@"ID", this.Id); scmd.CommandText = string.Format("UPDATE {0} SET WasteType = @P2, WasteDescription = @P3, " + "WasteDisposalAmount_MTQ = @P4, WasteCapacity_MTQ = @P5, WasteAmountRetained_MTQ = @P6," + "WasteDisposalPort = @P7, WasteAmountGeneratedTillNextPort_MTQ = @P8 " + "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, WasteType, WasteDescription, WasteDisposalAmount_MTQ, " + "WasteCapacity_MTQ, WasteAmountRetained_MTQ, WasteDisposalPort, WasteAmountGeneratedTillNextPort_MTQ, Identifier " + " FROM {0} ", this.Tablename); switch (filter) { case Message.LoadFilter.WAS_ID: query += " WHERE WASId = @WDID"; ((SqlCommand)cmd).Parameters.AddWithValue("@WDID", criteria[0]); break; case Message.LoadFilter.ALL: default: break; } cmd.CommandText = query; } public override List LoadList(System.Data.IDataReader reader) { List result = new List(); while (reader.Read()) { Waste waste = new Waste(); waste.id = reader.GetGuid(0); if (!reader.IsDBNull(1)) waste.WasteType = reader.GetByte(1); if (!reader.IsDBNull(2)) waste.WasteDescription = reader.GetString(2); if (!reader.IsDBNull(3)) waste.WasteDisposalAmount_MTQ = (float) reader.GetDouble(3); if (!reader.IsDBNull(4)) waste.WasteCapacity_MTQ = (float) reader.GetDouble(4); if (!reader.IsDBNull(5)) waste.WasteAmountRetained_MTQ = (float) reader.GetDouble(5); if (!reader.IsDBNull(6)) waste.WasteDisposalPort = reader.GetString(6); if (!reader.IsDBNull(7)) waste.WasteAmountGeneratedTillNextPort_MTQ = (float) reader.GetDouble(7); if (!reader.IsDBNull(8)) waste.Identifier = reader.GetString(8); result.Add(waste); } reader.Close(); return result; } #endregion } }