// // Class: StowawaysJoiningLocation // 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; namespace bsmd.database { public class StowawaysJoiningLocation : DatabaseEntity, ISublistElement { public StowawaysJoiningLocation() { this.tablename = "[dbo].[StowawaysJoiningLocation]"; } #region Properties public MDH MDH { get; set; } [ShowReport] [MaxLength(99)] [ENI2Validation] [Validation2(ValidationCode.STRING_MAXLEN, 99)] public string StowawayJoiningLocation { get; set; } public string Identifier { get; set; } public string SublistCollectionKey { get { return "stowaways"; } } #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.StowawayJoiningLocation); scmd.Parameters.AddWithNullableValue("@P3", this.Identifier); if (this.IsNew) { this.CreateId(); scmd.Parameters.AddWithValue("@ID", this.Id); scmd.CommandText = string.Format("INSERT INTO {0} (Id, MDH_Id, StowawaysJoiningLocation, " + "Identifier) VALUES (@ID, @P1, @P2, @P3)", this.Tablename); } else { scmd.CommandText = string.Format("UPDATE {0} SET StowawaysJoiningLocation = @P2, Identifier = @P3 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, StowawaysJoiningLocation, 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; } query += " ORDER BY CAST(Identifier AS INT)"; cmd.CommandText = query; } public override List LoadList(IDataReader reader) { List result = new List(); while (reader.Read()) { StowawaysJoiningLocation sjl = new StowawaysJoiningLocation(); sjl.id = reader.GetGuid(0); if (!reader.IsDBNull(1)) sjl.StowawayJoiningLocation = reader.GetString(1); if (!reader.IsDBNull(2)) sjl.Identifier = reader.GetString(2); result.Add(sjl); } reader.Close(); return result; } #endregion } }