// Copyright (c) 2020-present schick Informatik
// Description: Container for HAZA subclass templates
using System;
using System.Collections.Generic;
using System.Data;
namespace bsmd.database
{
///
/// Container for a dangerous goods template description which is imported from SQLite / Excel DB
/// Instances of this class will be offered to users as templates and respective DG entries created on them:
/// IGC, IMSBC, IBC and MARPOL (not! IMDG)
///
public class HAZPosTemplate
{
#region enums
public enum SublistType
{
IBC,
IGC,
IMSBC,
MARPOL
}
#endregion
#region Properties
public string Description { get; set; }
public byte? Hazard { get; set; }
public byte? Flashpoint { get; set; }
public bool? SpecRef15_19 { get; set; }
public bool? MHB { get; set; }
public byte? IMSBC_HAZ { get; set; }
public string UNNr { get; set; }
public string IMOClass { get; set; }
public string Comment { get; set; }
public SublistType TemplateType { get; set; }
public byte? PollutionCategory { get; set; }
#endregion
#region static storage helper classes
public static string GetQuery()
{
return "SELECT Beschreibung, HAZARD_ENUM, FP_ENUM, \"15.19?\", Typ, MHB, IMSBC_HAZ, \"UN-Nr.\", \"IMO-Cl.\", POLLUTION_CATEGORY_ENUM, Bemerkung FROM GEFAHRGUTLISTE ORDER BY Beschreibung";
}
public static List LoadList(IDataReader reader)
{
List result = new List();
while(reader.Read())
{
if (reader.IsDBNull(4)) continue; // this row has no type -> ignore
HAZPosTemplate hpt = new HAZPosTemplate();
hpt.Description = reader.GetString(0);
if (!reader.IsDBNull(1))
hpt.Hazard = (byte) reader.GetDouble(1);
if (!reader.IsDBNull(2))
hpt.Flashpoint = (byte) reader.GetDouble(2);
if (!reader.IsDBNull(3))
{
string specRefString = reader.GetString(3);
if (specRefString.Equals("JA", StringComparison.OrdinalIgnoreCase) || specRefString.Equals("Yes", StringComparison.OrdinalIgnoreCase)) hpt.SpecRef15_19 = true;
if (specRefString.Equals("NEIN", StringComparison.OrdinalIgnoreCase) || specRefString.Equals("No", StringComparison.OrdinalIgnoreCase)) hpt.SpecRef15_19 = false;
}
string type = reader.GetString(4);
switch(type)
{
case "IBC": hpt.TemplateType = SublistType.IBC; break;
case "IGC": hpt.TemplateType = SublistType.IGC; break;
case "IMSBC": hpt.TemplateType = SublistType.IMSBC ; break;
case "MARPOL": hpt.TemplateType = SublistType.MARPOL; break;
default:
continue; // ignore this thing
}
if(!reader.IsDBNull(5))
{
string mhbstring = reader.GetString(5);
if (mhbstring.Equals("y", StringComparison.OrdinalIgnoreCase))
hpt.MHB = true;
}
if (!reader.IsDBNull(6))
hpt.IMSBC_HAZ = (byte)reader.GetDouble(6);
if (!reader.IsDBNull(7))
hpt.UNNr = reader.GetString(7);
if(!reader.IsDBNull(8))
hpt.IMOClass = reader.GetString(8);
if (!reader.IsDBNull(9))
hpt.PollutionCategory = (byte) reader.GetDouble(9);
if (!reader.IsDBNull(10))
hpt.Comment = reader.GetString(10);
result.Add(hpt);
}
return result;
}
#endregion
#region overrides
public override string ToString()
{
if (this.Description.Length > 75)
return string.Format("{0}...", this.Description.Substring(0, 75));
return Description;
}
#endregion
}
}