Started working on list for globally saved new hazard items

This commit is contained in:
Daniel Schick 2026-02-06 13:05:10 +01:00
parent fbf595ffd4
commit 50ab9c95f5
13 changed files with 625 additions and 91 deletions

View File

@ -0,0 +1,58 @@
<UserControl x:Class="ENI2.Controls.HazardMaterialControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:ENI2.Controls"
xmlns:p="clr-namespace:ENI2.Properties"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="900">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="28" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Label Grid.Row="0" Content="Hazard materials" />
<GroupBox Header="" Grid.Row="1">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="28" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid Grid.Row="0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="120" />
<ColumnDefinition Width="120" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Button x:Name="buttonSave" Grid.Column="0" Margin="2" Content="Save all changes" Click="buttonSave_Click" />
<Button x:Name="buttonAdd" Grid.Column="1" Margin="2" Content="Add new" Click="buttonAdd_Click" />
</Grid>
<local:ENIDataGrid Grid.Row="1" Margin="2,8,2,2" x:Name="dataGridHazardMaterial" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch"
SelectionMode="Extended" AutoGenerateColumns="False" CellEditEnding="dataGridHazardMaterial_CellEditEnding" CanUserAddRows="False">
<DataGrid.Columns>
<DataGridTextColumn Header="Description" Binding="{Binding Description, Mode=TwoWay}" Width="2*" />
<DataGridComboBoxColumn x:Name="columnHazard" Header="Hazard" SelectedValueBinding="{Binding HazardIndex, Mode=TwoWay}" SelectedValuePath="Key" DisplayMemberPath="Value" Width="*" />
<DataGridTextColumn Header="FP" Binding="{Binding FP, Mode=TwoWay}" Width="*" />
<DataGridComboBoxColumn x:Name="columnFlashpoint" Header="Flashpoint" SelectedValueBinding="{Binding FlashpointIndex, Mode=TwoWay}" SelectedValuePath="Key" DisplayMemberPath="Value" Width="*" />
<DataGridCheckBoxColumn Header="15.19?" Binding="{Binding SpecRef15_19, Mode=TwoWay}" Width="*" />
<DataGridComboBoxColumn x:Name="columnTemplateType" Header="Type" SelectedItemBinding="{Binding TemplateType, Mode=TwoWay}" Width="*" />
<DataGridTextColumn Header="IMSBC" Binding="{Binding IMSBC, Mode=TwoWay}" Width="*" />
<DataGridCheckBoxColumn Header="MHB" Binding="{Binding MHB, Mode=TwoWay}" Width="*" />
<DataGridTextColumn Header="IMSBC_MHB" Binding="{Binding IMSBC_MHB, Mode=TwoWay}" Width="*" />
<DataGridTextColumn Header="Group" Binding="{Binding Group, Mode=TwoWay}" Width="*" />
<DataGridComboBoxColumn x:Name="columnIMSBC_HAZ" Header="IMSBC_HAZ" SelectedValueBinding="{Binding IMSBC_HAZ_Index, Mode=TwoWay}" SelectedValuePath="Key" DisplayMemberPath="Value" Width="*" />
<DataGridTextColumn Header="UN-Nr." Binding="{Binding UNNr, Mode=TwoWay}" Width="*" />
<DataGridTextColumn Header="IMO-Cl." Binding="{Binding IMOClass, Mode=TwoWay}" Width="*" />
<DataGridTextColumn Header="IBC" Binding="{Binding IBC, Mode=TwoWay}" Width="*" />
<DataGridComboBoxColumn x:Name="columnPollution" Header="Pollution" SelectedValueBinding="{Binding PollutionCategoryIndex, Mode=TwoWay}" SelectedValuePath="Key" DisplayMemberPath="Value" Width="*" />
<DataGridTextColumn Header="MARPOL" Binding="{Binding MARPOL, Mode=TwoWay}" Width="*" />
<DataGridTextColumn Header="IGC" Binding="{Binding IGC, Mode=TwoWay}" Width="*" />
<DataGridTextColumn Header="FP_IBC" Binding="{Binding FP_IBC, Mode=TwoWay}" Width="*" />
<DataGridTextColumn Header="Remarks" Binding="{Binding Comment, Mode=TwoWay}" Width="2*" />
</DataGrid.Columns>
</local:ENIDataGrid>
</Grid>
</GroupBox>
</Grid>
</UserControl>

View File

@ -0,0 +1,133 @@
using bsmd.database;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
namespace ENI2.Controls
{
/// <summary>
/// Interaction logic for HazardMaterialControl.xaml
/// </summary>
public partial class HazardMaterialControl : UserControl
{
public HazardMaterialControl()
{
InitializeComponent();
this.dataGridHazardMaterial.ItemsSource = HAZPosTemplate.Templates;
var view = CollectionViewSource.GetDefaultView(HAZPosTemplate.Templates);
view.SortDescriptions.Add(new SortDescription(nameof(HAZPosTemplate.Description), ListSortDirection.Ascending));
_ = HAZPosTemplate.EnsureLoadedAsync();
this.columnHazard.ItemsSource = BuildEnumItems(IBCPosition.hazards);
this.columnFlashpoint.ItemsSource = BuildEnumItems(IBCPosition.flashpointInformations);
this.columnPollution.ItemsSource = BuildEnumItems(IBCPosition.pollutionCategories);
this.columnIMSBC_HAZ.ItemsSource = BuildEnumItems(IMSBCPosition.hazardClass);
this.columnTemplateType.ItemsSource = Enum.GetValues(typeof(HAZPosTemplate.SublistType));
this.dataGridHazardMaterial.ContextMenu = new ContextMenu();
MenuItem addItem = new MenuItem
{
Header = Properties.Resources.textAdd,
Icon = new System.Windows.Controls.Image { Source = new System.Windows.Media.Imaging.BitmapImage(new Uri("pack://application:,,,/Resources/add.png")) }
};
addItem.Click += AddItem_Click;
this.dataGridHazardMaterial.ContextMenu.Items.Add(addItem);
MenuItem delItem = new MenuItem
{
Header = Properties.Resources.textDelete,
Icon = new System.Windows.Controls.Image { Source = new System.Windows.Media.Imaging.BitmapImage(new Uri("pack://application:,,,/Resources/delete.png")) }
};
delItem.Click += DelItem_Click;
this.dataGridHazardMaterial.ContextMenu.Items.Add(delItem);
}
private void buttonSave_Click(object sender, RoutedEventArgs e)
{
_ = SaveTemplatesAsync();
}
private void buttonAdd_Click(object sender, RoutedEventArgs e)
{
AddNewTemplate();
}
private void dataGridHazardMaterial_CellEditEnding(object sender, DataGridCellEditEndingEventArgs e)
{
if (e.Row?.Item is HAZPosTemplate template)
{
template.IsDirty = true;
}
}
private void AddItem_Click(object sender, RoutedEventArgs e)
{
AddNewTemplate();
}
private async void DelItem_Click(object sender, RoutedEventArgs e)
{
if (this.dataGridHazardMaterial.SelectedItems.Count > 0)
{
if (MessageBox.Show("Are you sure to delete the selected values?", Properties.Resources.textConfirmation, MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.No) ==
MessageBoxResult.Yes)
{
var selectedItems = new List<HAZPosTemplate>();
foreach (HAZPosTemplate item in this.dataGridHazardMaterial.SelectedItems)
selectedItems.Add(item);
foreach (HAZPosTemplate item in selectedItems)
{
int result = await DBManagerAsync.DeleteAsync(item);
if (result == 1 || item.IsNew)
{
HAZPosTemplate.Templates.Remove(item);
}
}
}
}
}
private void AddNewTemplate()
{
var template = new HAZPosTemplate
{
TemplateType = HAZPosTemplate.SublistType.IMSBC,
IsDirty = true
};
HAZPosTemplate.Templates.Add(template);
this.dataGridHazardMaterial.SelectedItem = template;
this.dataGridHazardMaterial.ScrollIntoView(template);
}
private async Task SaveTemplatesAsync()
{
int totalSaves = 0;
foreach (var template in HAZPosTemplate.Templates)
{
if (template.IsNew || template.IsDirty)
{
totalSaves += await DBManagerAsync.SaveAsync(template);
}
}
if (totalSaves > 0)
{
MessageBox.Show($"{totalSaves} hazard materials saved", "Success", MessageBoxButton.OK, MessageBoxImage.Information);
}
}
private static List<KeyValuePair<int, string>> BuildEnumItems(IReadOnlyList<string> values)
{
var items = new List<KeyValuePair<int, string>>(values.Count);
for (int i = 0; i < values.Count; i++)
{
items.Add(new KeyValuePair<int, string>(i, values[i]));
}
return items;
}
}
}

View File

@ -835,12 +835,12 @@ namespace ENI2.DetailViewControls
case HAZPosTemplate.SublistType.IBC: case HAZPosTemplate.SublistType.IBC:
this.tabControlPositions.SelectedIndex = 1; this.tabControlPositions.SelectedIndex = 1;
IBCPosition ibcPos = new IBCPosition(); IBCPosition ibcPos = new IBCPosition();
ibcPos.FlashpointInformation = selectedTemplate.Flashpoint; ibcPos.FlashpointInformation = (byte) selectedTemplate.Flashpoint;
ibcPos.Flashpoint_CEL = selectedTemplate.FP_IBC; ibcPos.Flashpoint_CEL = selectedTemplate.FP_IBC;
ibcPos.SpecRef15_19 = selectedTemplate.SpecRef15_19; ibcPos.SpecRef15_19 = selectedTemplate.SpecRef15_19;
ibcPos.Hazards = selectedTemplate.Hazard; ibcPos.Hazards = (byte) selectedTemplate.Hazard;
ibcPos.Identifier = DatabaseEntity.GetNewIdentifier(haz.IBCPositions, "IBC-"); ibcPos.Identifier = DatabaseEntity.GetNewIdentifier(haz.IBCPositions, "IBC-");
ibcPos.PollutionCategory = selectedTemplate.PollutionCategory; ibcPos.PollutionCategory = (byte) selectedTemplate.PollutionCategory;
ibcPos.HAZ = haz; ibcPos.HAZ = haz;
haz.IBCPositions.Add(ibcPos); haz.IBCPositions.Add(ibcPos);
this.dataGridIBCItems.Items.Refresh(); this.dataGridIBCItems.Items.Refresh();
@ -861,7 +861,7 @@ namespace ENI2.DetailViewControls
this.tabControlPositions.SelectedIndex = 3; this.tabControlPositions.SelectedIndex = 3;
IMSBCPosition imsbcPos = new IMSBCPosition(); IMSBCPosition imsbcPos = new IMSBCPosition();
imsbcPos.Identifier = DatabaseEntity.GetNewIdentifier(haz.IMSBCPositions, "IMSBC-"); imsbcPos.Identifier = DatabaseEntity.GetNewIdentifier(haz.IMSBCPositions, "IMSBC-");
imsbcPos.IMOHazardClass = selectedTemplate.IMSBC_HAZ; imsbcPos.IMOHazardClass = (byte) selectedTemplate.IMSBC_HAZ;
imsbcPos.UNNumber = selectedTemplate.UNNr; imsbcPos.UNNumber = selectedTemplate.UNNr;
imsbcPos.IMOClass = selectedTemplate.IMOClass; imsbcPos.IMOClass = selectedTemplate.IMOClass;
imsbcPos.MHB = selectedTemplate.MHB ?? false; imsbcPos.MHB = selectedTemplate.MHB ?? false;
@ -873,7 +873,7 @@ namespace ENI2.DetailViewControls
case HAZPosTemplate.SublistType.MARPOL: case HAZPosTemplate.SublistType.MARPOL:
this.tabControlPositions.SelectedIndex = 4; this.tabControlPositions.SelectedIndex = 4;
MARPOL_Annex_I_Position marpolPos = new MARPOL_Annex_I_Position(); MARPOL_Annex_I_Position marpolPos = new MARPOL_Annex_I_Position();
marpolPos.FlashpointInformation = selectedTemplate.Flashpoint; marpolPos.FlashpointInformation = (byte) selectedTemplate.Flashpoint;
marpolPos.Identifier = DatabaseEntity.GetNewIdentifier(haz.MARPOLPositions, "MARPOL-"); marpolPos.Identifier = DatabaseEntity.GetNewIdentifier(haz.MARPOLPositions, "MARPOL-");
marpolPos.HAZ = haz; marpolPos.HAZ = haz;
haz.MARPOLPositions.Add(marpolPos); haz.MARPOLPositions.Add(marpolPos);

View File

@ -36,8 +36,8 @@
<MinimumRequiredVersion>5.4.0.0</MinimumRequiredVersion> <MinimumRequiredVersion>5.4.0.0</MinimumRequiredVersion>
<CreateWebPageOnPublish>true</CreateWebPageOnPublish> <CreateWebPageOnPublish>true</CreateWebPageOnPublish>
<WebPage>publish.html</WebPage> <WebPage>publish.html</WebPage>
<ApplicationRevision>2</ApplicationRevision> <ApplicationRevision>1</ApplicationRevision>
<ApplicationVersion>7.2.15.0</ApplicationVersion> <ApplicationVersion>7.2.15.1</ApplicationVersion>
<UseApplicationTrust>false</UseApplicationTrust> <UseApplicationTrust>false</UseApplicationTrust>
<CreateDesktopShortcut>true</CreateDesktopShortcut> <CreateDesktopShortcut>true</CreateDesktopShortcut>
<PublishWizardCompleted>true</PublishWizardCompleted> <PublishWizardCompleted>true</PublishWizardCompleted>
@ -330,6 +330,9 @@
<Compile Include="Controls\ValueMappingsControl.xaml.cs"> <Compile Include="Controls\ValueMappingsControl.xaml.cs">
<DependentUpon>ValueMappingsControl.xaml</DependentUpon> <DependentUpon>ValueMappingsControl.xaml</DependentUpon>
</Compile> </Compile>
<Compile Include="Controls\HazardMaterialControl.xaml.cs">
<DependentUpon>HazardMaterialControl.xaml</DependentUpon>
</Compile>
<Compile Include="Controls\WASExemptionsControl.xaml.cs"> <Compile Include="Controls\WASExemptionsControl.xaml.cs">
<DependentUpon>WASExemptionsControl.xaml</DependentUpon> <DependentUpon>WASExemptionsControl.xaml</DependentUpon>
</Compile> </Compile>
@ -652,6 +655,10 @@
<SubType>Designer</SubType> <SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
</Page> </Page>
<Page Include="Controls\HazardMaterialControl.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Controls\WASExemptionsControl.xaml"> <Page Include="Controls\WASExemptionsControl.xaml">
<SubType>Designer</SubType> <SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>

View File

@ -7,6 +7,7 @@ using ENI2.Controls;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
@ -33,10 +34,10 @@ namespace ENI2.EditControls
} }
} }
private void EditWindowBase_Loaded(object sender, RoutedEventArgs e) private async void EditWindowBase_Loaded(object sender, RoutedEventArgs e)
{ {
// load combo boxes // load combo boxes
_data = LocalizedLookup.LoadHAZTemplates(); _data = await DBManagerAsync.LoadHAZTemplatesAsync();
this.listBoxDescription.ItemsSource = _data; this.listBoxDescription.ItemsSource = _data;
this.comboBoxType.ItemsSource = Enum.GetValues(typeof(HAZPosTemplate.SublistType)); this.comboBoxType.ItemsSource = Enum.GetValues(typeof(HAZPosTemplate.SublistType));
this.OkVisible = false; this.OkVisible = false;

View File

@ -263,15 +263,6 @@ namespace ENI2
return results; return results;
} }
public static List<HAZPosTemplate> LoadHAZTemplates()
{
SQLiteCommand cmd = new SQLiteCommand(HAZPosTemplate.GetQuery(), _con);
IDataReader reader = cmd.ExecuteReader();
List<HAZPosTemplate> result = HAZPosTemplate.LoadList(reader);
reader.Close();
return result;
}
public static List<KeyValuePair<string, string>> GetNST2007List() public static List<KeyValuePair<string, string>> GetNST2007List()
{ {
List<KeyValuePair<string, string>> result = new List<KeyValuePair<string, string>>(); List<KeyValuePair<string, string>> result = new List<KeyValuePair<string, string>>();

View File

@ -103,6 +103,11 @@
<Image Source="Resources/garbage.png" /> <Image Source="Resources/garbage.png" />
</MenuItem.Icon> </MenuItem.Icon>
</MenuItem> </MenuItem>
<MenuItem x:Name="menuItemHazardMaterials" Header="Hazard materials" Click="radioButton_Click">
<MenuItem.Icon>
<Image Source="Resources/sign_warning.png" />
</MenuItem.Icon>
</MenuItem>
</MenuItem> </MenuItem>
<MenuItem x:Name="menuItemMaersk" Header="{x:Static p:Resources.textPOLists}" Click="radioButton_Click" Visibility="Hidden" /> <MenuItem x:Name="menuItemMaersk" Header="{x:Static p:Resources.textPOLists}" Click="radioButton_Click" Visibility="Hidden" />
<MenuItem x:Name="menuItemValueMappings" Header="{x:Static p:Resources.textExcelValueMappings}" Click="radioButton_Click" Visibility="Hidden" /> <MenuItem x:Name="menuItemValueMappings" Header="{x:Static p:Resources.textExcelValueMappings}" Click="radioButton_Click" Visibility="Hidden" />

View File

@ -41,6 +41,7 @@ namespace ENI2
private CompareExcelDialog compareExcelDialog; private CompareExcelDialog compareExcelDialog;
private EasyPeasyControl easyPeasyControl; private EasyPeasyControl easyPeasyControl;
private WASExemptionsControl wasExemptionsControl; private WASExemptionsControl wasExemptionsControl;
private HazardMaterialControl hazardMaterialControl;
private bool dbConnected; private bool dbConnected;
private readonly ScaleTransform _transform = new ScaleTransform(1.0, 1.0); private readonly ScaleTransform _transform = new ScaleTransform(1.0, 1.0);
@ -342,6 +343,14 @@ namespace ENI2
} }
this.rootContainer.Children.Add(this.wasExemptionsControl); this.rootContainer.Children.Add(this.wasExemptionsControl);
} }
else if (sender == this.menuItemHazardMaterials)
{
if (this.hazardMaterialControl == null)
{
this.hazardMaterialControl = new HazardMaterialControl();
}
this.rootContainer.Children.Add(this.hazardMaterialControl);
}
} }
private void buttonCompareSheets_Click(object sender, RoutedEventArgs ev) private void buttonCompareSheets_Click(object sender, RoutedEventArgs ev)

View File

@ -368,12 +368,12 @@ namespace ENI2.SheetDisplayControls
{ {
case HAZPosTemplate.SublistType.IBC: case HAZPosTemplate.SublistType.IBC:
IBCPosition ibcPos = new IBCPosition(); IBCPosition ibcPos = new IBCPosition();
ibcPos.FlashpointInformation = selectedTemplate.Flashpoint; ibcPos.FlashpointInformation = (byte) selectedTemplate.Flashpoint;
ibcPos.Flashpoint_CEL = selectedTemplate.FP_IBC; ibcPos.Flashpoint_CEL = selectedTemplate.FP_IBC;
ibcPos.SpecRef15_19 = selectedTemplate.SpecRef15_19; ibcPos.SpecRef15_19 = selectedTemplate.SpecRef15_19;
ibcPos.Hazards = selectedTemplate.Hazard; ibcPos.Hazards = (byte)selectedTemplate.Hazard;
ibcPos.Identifier = DatabaseEntity.GetNewIdentifier(haz.IBCPositions, "IBC-"); ibcPos.Identifier = DatabaseEntity.GetNewIdentifier(haz.IBCPositions, "IBC-");
ibcPos.PollutionCategory = selectedTemplate.PollutionCategory; ibcPos.PollutionCategory = (byte?)selectedTemplate.PollutionCategory;
ibcPos.HAZ = haz; ibcPos.HAZ = haz;
haz.IBCPositions.Add(ibcPos); haz.IBCPositions.Add(ibcPos);
this.dataGridIBCItems.Items.Refresh(); this.dataGridIBCItems.Items.Refresh();
@ -392,7 +392,7 @@ namespace ENI2.SheetDisplayControls
case HAZPosTemplate.SublistType.IMSBC: case HAZPosTemplate.SublistType.IMSBC:
IMSBCPosition imsbcPos = new IMSBCPosition(); IMSBCPosition imsbcPos = new IMSBCPosition();
imsbcPos.Identifier = DatabaseEntity.GetNewIdentifier(haz.IMSBCPositions, "IMSBC-"); imsbcPos.Identifier = DatabaseEntity.GetNewIdentifier(haz.IMSBCPositions, "IMSBC-");
imsbcPos.IMOHazardClass = selectedTemplate.IMSBC_HAZ; imsbcPos.IMOHazardClass = (int?)selectedTemplate.IMSBC_HAZ;
imsbcPos.UNNumber = selectedTemplate.UNNr; imsbcPos.UNNumber = selectedTemplate.UNNr;
imsbcPos.IMOClass = selectedTemplate.IMOClass; imsbcPos.IMOClass = selectedTemplate.IMOClass;
imsbcPos.MHB = selectedTemplate.MHB ?? false; imsbcPos.MHB = selectedTemplate.MHB ?? false;
@ -403,7 +403,7 @@ namespace ENI2.SheetDisplayControls
break; break;
case HAZPosTemplate.SublistType.MARPOL: case HAZPosTemplate.SublistType.MARPOL:
MARPOL_Annex_I_Position marpolPos = new MARPOL_Annex_I_Position(); MARPOL_Annex_I_Position marpolPos = new MARPOL_Annex_I_Position();
marpolPos.FlashpointInformation = selectedTemplate.Flashpoint; marpolPos.FlashpointInformation = (byte?) selectedTemplate.Flashpoint;
marpolPos.Identifier = DatabaseEntity.GetNewIdentifier(haz.MARPOLPositions, "MARPOL-"); marpolPos.Identifier = DatabaseEntity.GetNewIdentifier(haz.MARPOLPositions, "MARPOL-");
marpolPos.HAZ = haz; marpolPos.HAZ = haz;
haz.MARPOLPositions.Add(marpolPos); haz.MARPOLPositions.Add(marpolPos);

View File

@ -16,3 +16,54 @@ BEGIN
PRINT N'Table [dbo].[WASExemption] created.'; PRINT N'Table [dbo].[WASExemption] created.';
END END
GO GO
PRINT N'Creating [dbo].[HazardMaterial] if missing...';
GO
IF OBJECT_ID(N'dbo.HazardMaterial', N'U') IS NULL
BEGIN
CREATE TABLE [dbo].[HazardMaterial] (
[Id] UNIQUEIDENTIFIER NOT NULL,
[Description] NVARCHAR (100) NULL,
[Hazard_Enum] INT NULL,
[FP] NVARCHAR (100) NULL,
[FP_Enum] INT NULL,
[15_19] NVARCHAR (100) NULL,
[Typ] NVARCHAR (100) NULL,
[IMSBC] NVARCHAR (100) NULL,
[MHB] NVARCHAR (100) NULL,
[IMSBC_MHB] INT NULL,
[Group] NVARCHAR (100) NULL,
[IMSBC_HAZ] INT NULL,
[UN_Nr] NVARCHAR (100) NULL,
[IMO_CL] NVARCHAR (100) NULL,
[IBC] NVARCHAR (100) NULL,
[Pollution_Category_Enum] INT NULL,
[MARPOL] NVARCHAR (100) NULL,
[IGC] NVARCHAR (100) NULL,
[FP_IBC] NVARCHAR (100) NULL,
[Remarks] NVARCHAR (255) NULL,
PRIMARY KEY CLUSTERED ([Id] ASC)
);
PRINT N'Table [dbo].[HazardMaterial] created.';
END
GO
PRINT N'Creating [dbo].[PortAreaHelper] if missing...';
GO
IF OBJECT_ID(N'dbo.PortAreaHelper', N'U') IS NULL
BEGIN
CREATE TABLE [dbo].[PortAreaHelper] (
[Id] UNIQUEIDENTIFIER NOT NULL,
[Locode] NCHAR (5) NOT NULL,
[Agency] NVARCHAR (100) NULL,
[Ships] NVARCHAR (100) NULL,
[Berth] NVARCHAR (100) NULL,
[PortArea] NVARCHAR (100) NULL,
[PortArea_Code] NVARCHAR (10) NULL,
[Remarks] NVARCHAR (255) NULL,
PRIMARY KEY CLUSTERED ([Id] ASC)
);
PRINT N'Table [dbo].[PortAreaHelper] created.';
END
GO

View File

@ -112,6 +112,15 @@ namespace bsmd.database
return (await was.LoadListAsync(reader)).ConvertAll(x => (WASExemption)x); return (await was.LoadListAsync(reader)).ConvertAll(x => (WASExemption)x);
} }
public static async Task<List<HAZPosTemplate>> LoadHAZTemplatesAsync()
{
SqlCommand cmd = new SqlCommand();
HAZPosTemplate hpt = new HAZPosTemplate();
hpt.PrepareLoadCommand(cmd, Message.LoadFilter.ALL);
SqlDataReader reader = await PerformCommandAsync(cmd);
return (await hpt.LoadListAsync(reader)).ConvertAll(x => (HAZPosTemplate)x);
}
public static async Task<List<AGNT_Template>> GetAGNTTemplatesAsync() public static async Task<List<AGNT_Template>> GetAGNTTemplatesAsync()
{ {
SqlCommand cmd = new SqlCommand(); SqlCommand cmd = new SqlCommand();

View File

@ -1,9 +1,14 @@
// Copyright (c) 2020-present schick Informatik // Copyright (c) 2020-present schick Informatik
// Description: Container for HAZA subclass templates // Description: Container for HAZA subclass templates
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Data; using System.Data;
using System.Data.SqlClient;
using System.Threading.Tasks;
using Newtonsoft.Json;
namespace bsmd.database namespace bsmd.database
{ {
@ -12,7 +17,7 @@ namespace bsmd.database
/// Instances of this class will be offered to users as templates and respective DG entries created on them: /// 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) /// IGC, IMSBC, IBC and MARPOL (not! IMDG)
/// </summary> /// </summary>
public class HAZPosTemplate public class HAZPosTemplate : DatabaseEntityAsync, IComparable
{ {
#region enums #region enums
@ -25,114 +30,379 @@ namespace bsmd.database
MARPOL MARPOL
} }
public enum PollutionCategoryEnum
{
X = 0,
Y,
Z,
OS
}
public enum HazardsEnum
{
P = 0,
S,
S_P
}
public enum FlashpointEnum
{
NF = 0,
GT60CEL,
LE60CEL
}
public enum IMO_HAZ_ClassEnum
{
A = 0,
B,
A_B
}
#endregion #endregion
#region Properties #region Properties
private static ObservableCollection<HAZPosTemplate> _templates;
private static Task _loadTask;
public static ObservableCollection<HAZPosTemplate> Templates
{
get
{
if (_templates == null)
{
_templates = new ObservableCollection<HAZPosTemplate>();
_ = EnsureLoadedAsync();
}
return _templates;
}
}
public string Description { get; set; } public string Description { get; set; }
public byte? Hazard { get; set; } public HazardsEnum? Hazard { get; set; }
public byte? Flashpoint { get; set; } [JsonIgnore]
[Browsable(false)]
public int? HazardIndex
{
get { return this.Hazard.HasValue ? (int)this.Hazard.Value : (int?)null; }
set { this.Hazard = value.HasValue ? (HazardsEnum?)value.Value : null; }
}
public string FP { get; set; }
public FlashpointEnum? Flashpoint { get; set; }
[JsonIgnore]
[Browsable(false)]
public int? FlashpointIndex
{
get { return this.Flashpoint.HasValue ? (int)this.Flashpoint.Value : (int?)null; }
set { this.Flashpoint = value.HasValue ? (FlashpointEnum?)value.Value : null; }
}
public bool? SpecRef15_19 { get; set; } = false; public bool? SpecRef15_19 { get; set; } = false;
public string IMSBC { get; set; }
public bool? MHB { get; set; } public bool? MHB { get; set; }
public byte? IMSBC_HAZ { get; set; } public int? IMSBC_MHB { get; set; }
public string Group { get; set; }
public IMO_HAZ_ClassEnum? IMSBC_HAZ { get; set; }
[JsonIgnore]
[Browsable(false)]
public int? IMSBC_HAZ_Index
{
get { return this.IMSBC_HAZ.HasValue ? (int)this.IMSBC_HAZ.Value : (int?)null; }
set { this.IMSBC_HAZ = value.HasValue ? (IMO_HAZ_ClassEnum?)value.Value : null; }
}
public string UNNr { get; set; } public string UNNr { get; set; }
public string IMOClass { get; set; } public string IMOClass { get; set; }
public string IBC { get; set; }
public string Comment { get; set; } public string Comment { get; set; }
public SublistType TemplateType { get; set; } public SublistType TemplateType { get; set; }
public byte? PollutionCategory { get; set; } public PollutionCategoryEnum? PollutionCategory { get; set; }
[JsonIgnore]
[Browsable(false)]
public int? PollutionCategoryIndex
{
get { return this.PollutionCategory.HasValue ? (int)this.PollutionCategory.Value : (int?)null; }
set { this.PollutionCategory = value.HasValue ? (PollutionCategoryEnum?)value.Value : null; }
}
public string MARPOL { get; set; }
public string IGC { get; set; }
public string FP_IBC { get; set; } public string FP_IBC { get; set; }
#endregion #endregion
#region static storage helper classes #region DatabaseEntity implementation
public static string GetQuery() public HAZPosTemplate()
{ {
return "SELECT Beschreibung, HAZARD_ENUM, FP_ENUM, \"15.19?\", Typ, MHB, IMSBC_HAZ, \"UN-Nr.\", \"IMO-Cl.\", POLLUTION_CATEGORY_ENUM, Bemerkung, FP_IBC FROM GEFAHRGUTLISTE ORDER BY Beschreibung"; this.tablename = "[dbo].[HazardMaterial]";
} }
public static List<HAZPosTemplate> LoadList(IDataReader reader) public override void PrepareSave(IDbCommand cmd)
{ {
List<HAZPosTemplate> result = new List<HAZPosTemplate>(); SqlCommand scmd = cmd as SqlCommand;
while(reader.Read()) scmd.Parameters.AddWithNullableValue("@P1", this.Description);
{ scmd.Parameters.AddWithNullableValue("@P2", this.Hazard.HasValue ? (int?)this.Hazard.Value : null);
string type = ""; scmd.Parameters.AddWithNullableValue("@P3", this.FP);
if (!reader.IsDBNull(4)) scmd.Parameters.AddWithNullableValue("@P4", this.Flashpoint.HasValue ? (int?)this.Flashpoint.Value : null);
type = reader.GetString(4); scmd.Parameters.AddWithNullableValue("@P5", this.SpecRef15_19.HasValue ? (this.SpecRef15_19.Value ? "Yes" : "No") : null);
scmd.Parameters.AddWithNullableValue("@P6", this.TemplateType.ToString());
scmd.Parameters.AddWithNullableValue("@P7", this.IMSBC);
scmd.Parameters.AddWithNullableValue("@P8", this.MHB.HasValue ? (this.MHB.Value ? "y" : "n") : null);
scmd.Parameters.AddWithNullableValue("@P9", this.IMSBC_MHB);
scmd.Parameters.AddWithNullableValue("@P10", this.Group);
scmd.Parameters.AddWithNullableValue("@P11", this.IMSBC_HAZ.HasValue ? (int?)this.IMSBC_HAZ.Value : null);
scmd.Parameters.AddWithNullableValue("@P12", this.UNNr);
scmd.Parameters.AddWithNullableValue("@P13", this.IMOClass);
scmd.Parameters.AddWithNullableValue("@P14", this.IBC);
scmd.Parameters.AddWithNullableValue("@P15", this.PollutionCategory.HasValue ? (int?)this.PollutionCategory.Value : null);
scmd.Parameters.AddWithNullableValue("@P16", this.MARPOL);
scmd.Parameters.AddWithNullableValue("@P17", this.IGC);
scmd.Parameters.AddWithNullableValue("@P18", this.FP_IBC);
scmd.Parameters.AddWithNullableValue("@P19", this.Comment);
HAZPosTemplate hpt = new HAZPosTemplate(); if (this.IsNew)
hpt.Description = reader.GetString(0);
if (!reader.IsDBNull(1))
hpt.Hazard = (byte) reader.GetByte(1);
if (!reader.IsDBNull(2))
hpt.Flashpoint = (byte) reader.GetByte(2);
if (!reader.IsDBNull(3))
{ {
string specRefString = reader.GetString(3); this.CreateId();
if (specRefString.Equals("JA", StringComparison.OrdinalIgnoreCase) || specRefString.Equals("Yes", StringComparison.OrdinalIgnoreCase)) hpt.SpecRef15_19 = true; scmd.Parameters.AddWithValue("@ID", this.Id);
if (specRefString.Equals("NEIN", StringComparison.OrdinalIgnoreCase) || specRefString.Equals("No", StringComparison.OrdinalIgnoreCase)) hpt.SpecRef15_19 = false; cmd.CommandText = string.Format(
"INSERT INTO {0} (Id, Description, Hazard_Enum, FP, FP_Enum, [15_19], Typ, IMSBC, MHB, IMSBC_MHB, [Group], IMSBC_HAZ, UN_Nr, IMO_CL, IBC, Pollution_Category_Enum, MARPOL, IGC, FP_IBC, Remarks) " +
"VALUES (@ID, @P1, @P2, @P3, @P4, @P5, @P6, @P7, @P8, @P9, @P10, @P11, @P12, @P13, @P14, @P15, @P16, @P17, @P18, @P19)",
this.Tablename);
}
else
{
cmd.CommandText = string.Format(
"UPDATE {0} SET Description = @P1, Hazard_Enum = @P2, FP = @P3, FP_Enum = @P4, [15_19] = @P5, Typ = @P6, " +
"IMSBC = @P7, MHB = @P8, IMSBC_MHB = @P9, [Group] = @P10, IMSBC_HAZ = @P11, UN_Nr = @P12, IMO_CL = @P13, " +
"IBC = @P14, Pollution_Category_Enum = @P15, MARPOL = @P16, IGC = @P17, FP_IBC = @P18, Remarks = @P19 WHERE Id = @ID",
this.Tablename);
scmd.Parameters.AddWithValue("@ID", this.Id);
}
} }
switch(type) public override void PrepareLoadCommand(IDbCommand cmd, Message.LoadFilter filter, params object[] criteria)
{ {
case "IBC": hpt.TemplateType = SublistType.IBC; break; string query = string.Format(
case "IGC": hpt.TemplateType = SublistType.IGC; break; "SELECT Id, Description, Hazard_Enum, FP, FP_Enum, [15_19], Typ, IMSBC, MHB, IMSBC_MHB, [Group], IMSBC_HAZ, UN_Nr, IMO_CL, IBC, Pollution_Category_Enum, MARPOL, IGC, FP_IBC, Remarks FROM {0}",
case "IMSBC": hpt.TemplateType = SublistType.IMSBC ; break; this.Tablename);
case "MARPOL": hpt.TemplateType = SublistType.MARPOL; break;
switch (filter)
{
case Message.LoadFilter.ALL:
default: default:
break; break;
} }
if(!reader.IsDBNull(5)) cmd.CommandText = query;
{
string mhbstring = reader.GetString(5);
if (mhbstring.Equals("y", StringComparison.OrdinalIgnoreCase))
hpt.MHB = true;
} }
if (!reader.IsDBNull(6)) public override List<DatabaseEntity> LoadList(IDataReader reader)
hpt.IMSBC_HAZ = (byte)reader.GetByte(6); {
List<DatabaseEntity> result = new List<DatabaseEntity>();
while (reader.Read())
{
HAZPosTemplate hpt = new HAZPosTemplate();
hpt.id = reader.GetGuid(0);
if (!reader.IsDBNull(1))
hpt.Description = reader.GetString(1);
if (!reader.IsDBNull(2))
hpt.Hazard = (HazardsEnum)reader.GetInt32(2);
if (!reader.IsDBNull(3))
hpt.FP = reader.GetString(3);
if (!reader.IsDBNull(4))
hpt.Flashpoint = (FlashpointEnum)reader.GetInt32(4);
if (!reader.IsDBNull(5))
{
string specRefString = reader.GetString(5);
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;
}
if (!reader.IsDBNull(6) && Enum.TryParse<SublistType>(reader.GetString(6), out SublistType templateType))
{
hpt.TemplateType = templateType;
}
if (!reader.IsDBNull(7)) if (!reader.IsDBNull(7))
hpt.UNNr = reader.GetString(7); hpt.IMSBC = reader.GetString(7);
if(!reader.IsDBNull(8)) if (!reader.IsDBNull(8))
hpt.IMOClass = reader.GetString(8); {
string mhbstring = reader.GetString(8);
if (mhbstring.Equals("y", StringComparison.OrdinalIgnoreCase))
hpt.MHB = true;
else if (mhbstring.Equals("n", StringComparison.OrdinalIgnoreCase))
hpt.MHB = false;
}
if (!reader.IsDBNull(9)) if (!reader.IsDBNull(9))
hpt.PollutionCategory = (byte)reader.GetByte(9); hpt.IMSBC_MHB = reader.GetInt32(9);
if (!reader.IsDBNull(10)) if (!reader.IsDBNull(10))
hpt.Comment = reader.GetString(10); hpt.Group = reader.GetString(10);
if (!reader.IsDBNull(11)) if (!reader.IsDBNull(11))
hpt.FP_IBC = reader.GetString(11); hpt.IMSBC_HAZ = (IMO_HAZ_ClassEnum)reader.GetInt32(11);
if (!reader.IsDBNull(12))
hpt.UNNr = reader.GetString(12);
if (!reader.IsDBNull(13))
hpt.IMOClass = reader.GetString(13);
if (!reader.IsDBNull(14))
hpt.IBC = reader.GetString(14);
if (!reader.IsDBNull(15))
hpt.PollutionCategory = (PollutionCategoryEnum)reader.GetInt32(15);
if (!reader.IsDBNull(16))
hpt.MARPOL = reader.GetString(16);
if (!reader.IsDBNull(17))
hpt.IGC = reader.GetString(17);
if (!reader.IsDBNull(18))
hpt.FP_IBC = reader.GetString(18);
if (!reader.IsDBNull(19))
hpt.Comment = reader.GetString(19);
result.Add(hpt); result.Add(hpt);
} }
reader.Close();
return result; return result;
} }
protected override DatabaseEntityAsync ReadRowFromReader(IDataReader reader)
{
HAZPosTemplate hpt = null;
if (reader != null)
{
hpt = new HAZPosTemplate();
hpt.id = reader.GetGuid(0);
if (!reader.IsDBNull(1))
hpt.Description = reader.GetString(1);
if (!reader.IsDBNull(2))
hpt.Hazard = (HazardsEnum)reader.GetInt32(2);
if (!reader.IsDBNull(3))
hpt.FP = reader.GetString(3);
if (!reader.IsDBNull(4))
hpt.Flashpoint = (FlashpointEnum)reader.GetInt32(4);
if (!reader.IsDBNull(5))
{
string specRefString = reader.GetString(5);
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;
}
if (!reader.IsDBNull(6) && Enum.TryParse<SublistType>(reader.GetString(6), out SublistType templateType))
{
hpt.TemplateType = templateType;
}
if (!reader.IsDBNull(7))
hpt.IMSBC = reader.GetString(7);
if (!reader.IsDBNull(8))
{
string mhbstring = reader.GetString(8);
if (mhbstring.Equals("y", StringComparison.OrdinalIgnoreCase))
hpt.MHB = true;
else if (mhbstring.Equals("n", StringComparison.OrdinalIgnoreCase))
hpt.MHB = false;
}
if (!reader.IsDBNull(9))
hpt.IMSBC_MHB = reader.GetInt32(9);
if (!reader.IsDBNull(10))
hpt.Group = reader.GetString(10);
if (!reader.IsDBNull(11))
hpt.IMSBC_HAZ = (IMO_HAZ_ClassEnum)reader.GetInt32(11);
if (!reader.IsDBNull(12))
hpt.UNNr = reader.GetString(12);
if (!reader.IsDBNull(13))
hpt.IMOClass = reader.GetString(13);
if (!reader.IsDBNull(14))
hpt.IBC = reader.GetString(14);
if (!reader.IsDBNull(15))
hpt.PollutionCategory = (PollutionCategoryEnum)reader.GetInt32(15);
if (!reader.IsDBNull(16))
hpt.MARPOL = reader.GetString(16);
if (!reader.IsDBNull(17))
hpt.IGC = reader.GetString(17);
if (!reader.IsDBNull(18))
hpt.FP_IBC = reader.GetString(18);
if (!reader.IsDBNull(19))
hpt.Comment = reader.GetString(19);
}
return hpt;
}
#endregion
#region Static loading
public static async Task EnsureLoadedAsync()
{
if (_templates == null)
{
_templates = new ObservableCollection<HAZPosTemplate>();
}
if (_loadTask != null)
{
await _loadTask;
return;
}
_loadTask = LoadInternalAsync();
await _loadTask;
}
private static async Task LoadInternalAsync()
{
var list = await DBManagerAsync.LoadHAZTemplatesAsync();
_templates.Clear();
foreach (var item in list)
{
_templates.Add(item);
}
}
#endregion #endregion
#region overrides #region overrides
public override string ToString() public override string ToString()
{ {
if(string.IsNullOrEmpty(this.Description))
return base.ToString();
if (this.Description.Length > 75) if (this.Description.Length > 75)
return string.Format("{0}...", this.Description.Substring(0, 75)); return string.Format("{0}...", this.Description.Substring(0, 75));
return Description; return Description;
} }
#endregion #endregion
#region IComparable implementation
public int CompareTo(object obj)
{
if (obj is HAZPosTemplate other)
{
return this.Description?.CompareTo(other.Description ?? "") ?? 0;
}
return 0;
}
#endregion
} }
} }