// // Class: TIEFA // Current CLR: 4.0.30319.34209 // System: Microsoft Visual Studio 10.0 // Author: dani // Created: 4/1/2015 10:00:47 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 TIEFA : DatabaseEntity { public TIEFA() { this.tablename = "[dbo].[TIEFA]"; } #region Properties [ShowReport] [Validation(ValidationCode.NOT_NULL)] [LookupName("TIEFA.DraughtUponArrival_DMT")] [ENI2Validation] public double? DraughtUponArrival_DMT { get; set; } public override string Subtitle { get { return "Draught at arrival notification"; } } #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.DraughtUponArrival_DMT); if (this.IsNew) { this.CreateId(); scmd.Parameters.AddWithValue("@ID", this.Id); scmd.CommandText = string.Format("INSERT INTO {0} (Id, MessageHeaderId, DraughtUponArrival_DMT) VALUES ( @ID, @P1, @P2 )", this.Tablename); } else { scmd.Parameters.AddWithValue("@ID", this.Id); scmd.CommandText = string.Format("UPDATE {0} SET DraughtUponArrival_DMT = @P2 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, DraughtUponArrival_DMT 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 LoadList(System.Data.IDataReader reader) { List result = new List(); while (reader.Read()) { TIEFA tiefa = new TIEFA(); tiefa.id = reader.GetGuid(0); if (!reader.IsDBNull(1)) tiefa.DraughtUponArrival_DMT = reader.GetDouble(1); result.Add(tiefa); } reader.Close(); return result; } #endregion #region Validation public override void Validate(List errors, List violations) { if(this.DraughtUponArrival_DMT.HasValue && ((this.DraughtUponArrival_DMT.Value < 10) || (this.DraughtUponArrival_DMT.Value > 200))) violations.Add(RuleEngine.CreateViolation(ValidationCode.IMPLAUSIBLE, "Check draught on arrival", null, this.Title, null, this.Tablename)); } #endregion } }