// // Class: IBCPosition // Current CLR: 4.0.30319.34209 // System: Microsoft Visual Studio 10.0 // Author: dani // Created: 5/27/2015 8:55:22 AM // // Copyright (c) 2015 Informatikbüro Daniel Schick. All rights reserved. using System; using System.Collections.Generic; using System.Data; using System.Data.SqlClient; namespace bsmd.database { public class IBCPosition : DatabaseEntity, ISublistElement { public IBCPosition() { this.tablename = "[dbo].[IBCPosition]"; } #region Properties public HAZ HAZ { get; set; } [ShowReport] [Validation(ValidationCode.NOT_NULL)] public string ProductName { get; set; } [ShowReport] [Validation(ValidationCode.NOT_NULL)] public byte? PollutionCategory { get; set; } [ShowReport] public byte? Hazards { get; set; } [ShowReport] [Validation(ValidationCode.NOT_NULL)] public byte? FlashpointInformation { get; set; } [ShowReport] public string Flashpoint_CEL { get; set; } [ShowReport] [Validation(ValidationCode.DOUBLE_GT_ZERO)] public double? Quantity_KGM { get; set; } [ShowReport] [Validation(ValidationCode.NOT_NULL)] public string StowagePosition { get; set; } [ShowReport] [Validation(ValidationCode.LOCODE)] public string PortOfLoading { get; set; } [ShowReport] [Validation(ValidationCode.LOCODE)] public string PortOfDischarge { get; set; } [ShowReport] public bool? SpecRef15_19 { get; set; } [ShowReport] public string Remarks { 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.HAZ.Id); scmd.Parameters.AddWithNullableValue("@P2", this.ProductName); scmd.Parameters.AddWithNullableValue("@P3", this.PollutionCategory); scmd.Parameters.AddWithNullableValue("@P4", this.Hazards); scmd.Parameters.AddWithNullableValue("@P5", this.FlashpointInformation); scmd.Parameters.AddWithNullableValue("@P6", this.Flashpoint_CEL); scmd.Parameters.AddWithNullableValue("@P7", this.Quantity_KGM); scmd.Parameters.AddWithNullableValue("@P8", this.StowagePosition); scmd.Parameters.AddWithNullableValue("@P9", this.PortOfLoading); scmd.Parameters.AddWithNullableValue("@P10", this.PortOfDischarge); scmd.Parameters.AddWithNullableValue("@P11", this.SpecRef15_19); scmd.Parameters.AddWithNullableValue("@P12", this.Remarks); scmd.Parameters.AddWithNullableValue("@P13", this.Identifier); if (this.IsNew) { scmd.CommandText = string.Format("INSERT INTO {0} (HAZId, ProductName, PollutionCategory, Hazards, " + "FlashpointInformation, Flashpoint_CEL, Quantity_KGM, StowagePosition, PortOfLoading, PortOfDischarge, " + "SpecRef15_19, Remarks, Identifier) VALUES (@P1, @P2, @P3, @P4, @P5, @P6, @P7, @P8, @P9, @P10, " + "@P11, @P12, @P13)", this.Tablename); } else { scmd.Parameters.AddWithValue(@"ID", this.Id); scmd.CommandText = string.Format("UPDATE {0} SET ProductName = @P2, PollutionCategory = @P3, Hazards = @P4, " + "FlashpointInformation = @P5, Flashpoint_CEL = @P6, Quantity_KGM = @P7, StowagePosition = @P8, " + "PortOfLoading = @P9, PortOfDischarge = @P10, SpecRef15_19 = @P11, Remarks = @P12, Identifier = @P13 " + "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, ProductName, PollutionCategory, " + "Hazards, FlashpointInformation, Flashpoint_CEL, Quantity_KGM, StowagePosition, PortOfLoading, " + "PortOfDischarge, SpecRef15_19, Remarks, Identifier FROM {0} ", this.Tablename); switch (filter) { case Message.LoadFilter.HAZ_ID: query += " WHERE HAZId = @HAZID"; ((SqlCommand)cmd).Parameters.AddWithValue("@HAZID", 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()) { IBCPosition ibc = new IBCPosition(); ibc.id = reader.GetGuid(0); if (!reader.IsDBNull(1)) ibc.ProductName = reader.GetString(1); if (!reader.IsDBNull(2)) ibc.PollutionCategory = reader.GetByte(2); if (!reader.IsDBNull(3)) ibc.Hazards = reader.GetByte(3); if (!reader.IsDBNull(4)) ibc.FlashpointInformation = reader.GetByte(4); if (!reader.IsDBNull(5)) ibc.Flashpoint_CEL = reader.GetString(5); if (!reader.IsDBNull(6)) ibc.Quantity_KGM = reader.GetDouble(6); if (!reader.IsDBNull(7)) ibc.StowagePosition = reader.GetString(7); if (!reader.IsDBNull(8)) ibc.PortOfLoading = reader.GetString(8); if (!reader.IsDBNull(9)) ibc.PortOfDischarge = reader.GetString(9); if (!reader.IsDBNull(10)) ibc.SpecRef15_19 = reader.GetBoolean(10); if (!reader.IsDBNull(11)) ibc.Remarks = reader.GetString(11); if (!reader.IsDBNull(12)) ibc.Identifier = reader.GetString(12); result.Add(ibc); } reader.Close(); return result; } #endregion #region Validation public override void Validate(List errors, List violations) { if (this.FlashpointInformation.HasValue && (this.FlashpointInformation.Value == 2) && this.Flashpoint_CEL.IsNullOrEmpty()) violations.Add(RuleEngine.CreateViolation(ValidationCode.V804, "flashpoint information missing", null)); } #endregion } }