Added the port reference to management of berths incl. excel import
This commit is contained in:
parent
6cfd311bbb
commit
76995a84e4
@ -13,7 +13,7 @@ INSERT INTO port (id, name, locode) VALUES (1, 'Bremen', 'DEBRE');
|
||||
|
||||
-- Adding new ref column to berth
|
||||
ALTER TABLE `bremen_calling_devel`.`berth`
|
||||
ADD COLUMN `port_id` INT UNSIGNED NOT NULL DEFAULT 1 AFTER `authority_id`;
|
||||
ADD COLUMN `port_id` INT UNSIGNED DEFAULT NULL AFTER `authority_id`;
|
||||
ALTER TABLE `bremen_calling_devel`.`berth` ALTER INDEX `FK_AUTHORITY_PART_idx` INVISIBLE;
|
||||
|
||||
-- adding a foreign key berth.port_id -> port.id
|
||||
@ -52,3 +52,6 @@ CREATE TABLE `participant_port_map` (
|
||||
CONSTRAINT `FK_PP_PARTICIPANT` FOREIGN KEY (`participant_id`) REFERENCES `participant` (`id`),
|
||||
CONSTRAINT `FK_PP_PORT` FOREIGN KEY (`port_id`) REFERENCES `port` (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Mapping table that assigns participants to a port';
|
||||
|
||||
-- all existing berths shall default to "bremen"
|
||||
UPDATE berth SET port_id = 1;
|
||||
@ -5,7 +5,7 @@
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:local="clr-namespace:RoleEditor"
|
||||
mc:Ignorable="d"
|
||||
Title="Edit berth" Height="188" Width="450" Loaded="Window_Loaded">
|
||||
Title="Edit berth" Height="216" Width="450" Loaded="Window_Loaded">
|
||||
<Grid x:Name="berthGrid">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width=".3*" />
|
||||
@ -16,6 +16,7 @@
|
||||
<RowDefinition Height="28" />
|
||||
<RowDefinition Height="28" />
|
||||
<RowDefinition Height="28" />
|
||||
<RowDefinition Height="28" />
|
||||
<RowDefinition Height="*" />
|
||||
<RowDefinition Height="28" />
|
||||
</Grid.RowDefinitions>
|
||||
@ -45,7 +46,9 @@
|
||||
</Grid>
|
||||
<Label Content="Uses lock" HorizontalAlignment="Right" Grid.Row="3" />
|
||||
<CheckBox x:Name="checkBoxLock" Grid.Row="3" Grid.Column="1" VerticalAlignment="Center" Margin="2" IsChecked="{Binding Path=Lock, Mode=OneWay}"/>
|
||||
<StackPanel Grid.Column="1" Grid.Row="5" Orientation="Horizontal" FlowDirection="RightToLeft">
|
||||
<Label Content="Port" HorizontalAlignment="Right" Grid.Row="4" />
|
||||
<ComboBox Name="comboBoxPorts" Margin="2" Grid.Column="1" Grid.Row="4" SelectedItem="{Binding Port, Mode=OneWay}" />
|
||||
<StackPanel Grid.Column="1" Grid.Row="6" Orientation="Horizontal" FlowDirection="RightToLeft">
|
||||
<Button x:Name="buttonCancel" Width="80" Content="Cancel" Margin="2" Click="buttonCancel_Click" />
|
||||
<Button x:Name="buttonOK" Width="80" Content="OK" Margin="2" Click="buttonOK_Click"/>
|
||||
</StackPanel>
|
||||
|
||||
@ -20,6 +20,8 @@ namespace RoleEditor
|
||||
|
||||
public List<Participant> Authorities { get; } = new List<Participant>();
|
||||
|
||||
public List<Port> Ports { get; } = new List<Port>();
|
||||
|
||||
private void buttonCancel_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
this.DialogResult = false;
|
||||
@ -52,6 +54,7 @@ namespace RoleEditor
|
||||
this.DataContext = this.Berth;
|
||||
this.comboBoxParticipants.ItemsSource = this.Owners;
|
||||
this.comboBoxAuthorities.ItemsSource = this.Authorities;
|
||||
this.comboBoxPorts.ItemsSource = this.Ports;
|
||||
}
|
||||
|
||||
private void buttonResetParticipant_Click(object sender, RoutedEventArgs e)
|
||||
|
||||
@ -340,6 +340,7 @@
|
||||
<DataGridCheckBoxColumn Header="Lock" Binding="{Binding Path=Lock}" IsReadOnly="True"/>
|
||||
<DataGridTextColumn Header="Terminal" Binding="{Binding Path=Terminal, Mode=OneWay}" IsReadOnly="True"/>
|
||||
<DataGridTextColumn Header="Authority" Binding="{Binding Path=Authority_Text, Mode=OneWay}" IsReadOnly="True" />
|
||||
<DataGridTextColumn Header="Port" Binding="{Binding Path=Port}" IsReadOnly="True" />
|
||||
<DataGridTextColumn Header="Deleted" Binding="{Binding Path=Deleted, Mode=OneWay}" IsReadOnly="True" />
|
||||
</DataGrid.Columns>
|
||||
</local:ENIDataGrid>
|
||||
|
||||
@ -79,6 +79,10 @@ namespace RoleEditor
|
||||
_securables.Add(s);
|
||||
this.listBoxSecurables.ItemsSource = _securables;
|
||||
|
||||
// load all ports
|
||||
foreach (Port port in await Port.LoadAll(_dbManager)) _ports.Add(port);
|
||||
this.listBoxPort.ItemsSource = _ports;
|
||||
|
||||
// load all berths
|
||||
foreach (Berth b in await Berth.LoadAll(_dbManager))
|
||||
{
|
||||
@ -91,6 +95,10 @@ namespace RoleEditor
|
||||
{
|
||||
b.Authority = participants.Where(p => p.Id == b.Authority_Id).FirstOrDefault();
|
||||
}
|
||||
if (b.Port_Id != null)
|
||||
{
|
||||
b.Port = _ports.Where(p => p.Id == b.Port_Id).FirstOrDefault();
|
||||
}
|
||||
}
|
||||
this.dataGridBerths.Initialize();
|
||||
this.dataGridBerths.ItemsSource = _berths;
|
||||
@ -114,11 +122,7 @@ namespace RoleEditor
|
||||
|
||||
this.dataGridShips.CreateRequested += DataGridShips_CreateRequested;
|
||||
this.dataGridShips.EditRequested += DataGridShips_EditRequested;
|
||||
this.dataGridShips.DeleteRequested += DataGridShips_DeleteRequested;
|
||||
|
||||
// load all ports
|
||||
foreach(Port port in await Port.LoadAll(_dbManager)) _ports.Add(port);
|
||||
this.listBoxPort.ItemsSource = _ports;
|
||||
this.dataGridShips.DeleteRequested += DataGridShips_DeleteRequested;
|
||||
|
||||
|
||||
// set other item sources (filled later after selection)
|
||||
@ -200,6 +204,7 @@ namespace RoleEditor
|
||||
ebd.Berth = b;
|
||||
ebd.Owners.AddRange(this._terminals);
|
||||
ebd.Authorities.AddRange(this._authorities);
|
||||
ebd.Ports.AddRange(this._ports.Where(p => !p.IsDeleted));
|
||||
if (ebd.ShowDialog() ?? false)
|
||||
{
|
||||
await b.Save(_dbManager);
|
||||
@ -216,6 +221,7 @@ namespace RoleEditor
|
||||
ebd.Berth = b;
|
||||
ebd.Owners.AddRange(this._terminals);
|
||||
ebd.Authorities.AddRange(this._authorities);
|
||||
ebd.Ports.AddRange(_ports.Where(p => !p.IsDeleted));
|
||||
if (ebd.ShowDialog() ?? false)
|
||||
{
|
||||
_berths.Add(b);
|
||||
@ -738,7 +744,7 @@ namespace RoleEditor
|
||||
{
|
||||
if (reader.FieldCount < 2)
|
||||
{
|
||||
throw new InvalidDataException("Sheet must have at least 2 Columns of data");
|
||||
throw new InvalidDataException("Sheet must have at least 3 Columns of data");
|
||||
}
|
||||
|
||||
if (reader.IsDBNull(0) && reader.IsDBNull(1)) continue;
|
||||
@ -753,8 +759,20 @@ namespace RoleEditor
|
||||
if (_berths.Any(predicate: x => (x.Name != null) && x.Name.Equals(berth_name, StringComparison.OrdinalIgnoreCase)))
|
||||
continue;
|
||||
|
||||
string port_name = "";
|
||||
if (!reader.IsDBNull(2)) port_name = reader.GetString(2);
|
||||
|
||||
// find port in list
|
||||
if(!_ports.Any(x => (x.Name != null) && x.Name.Equals(port_name, StringComparison.OrdinalIgnoreCase)))
|
||||
continue;
|
||||
|
||||
Port port = _ports.First(x => (x.Name != null) && x.Name.Equals(port_name, StringComparison.OrdinalIgnoreCase));
|
||||
|
||||
Berth b = new Berth();
|
||||
b.Name = berth_name;
|
||||
b.Port = port;
|
||||
b.Port_Id = port.Id;
|
||||
|
||||
bool found_participant = false;
|
||||
|
||||
foreach(Participant p in this._participants)
|
||||
|
||||
@ -1,12 +1,7 @@
|
||||
// Copyright (c) 2023- schick Informatik
|
||||
// Description: Model class for berth entity
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace brecal.model
|
||||
{
|
||||
@ -23,10 +18,14 @@ namespace brecal.model
|
||||
|
||||
public uint? Authority_Id { get; set; }
|
||||
|
||||
public uint? Port_Id { get; set; }
|
||||
|
||||
public Participant? Owner { get; set; }
|
||||
|
||||
public Participant? Authority { get; set; }
|
||||
|
||||
public Port? Port { get; set; }
|
||||
|
||||
public string? Terminal { get { if (Owner != null) return Owner.Name; else return "n/a"; } }
|
||||
|
||||
public string? Authority_Text { get { if (Authority != null) return Authority.Name; else return "n/a"; } }
|
||||
@ -48,12 +47,12 @@ namespace brecal.model
|
||||
|
||||
public static void SetLoadQuery(IDbCommand cmd, params object?[] list)
|
||||
{
|
||||
cmd.CommandText = "SELECT id, name, owner_id, authority_id, `lock`, created, modified, deleted FROM berth";
|
||||
cmd.CommandText = "SELECT id, name, owner_id, authority_id, port_id, `lock`, created, modified, deleted FROM berth";
|
||||
}
|
||||
|
||||
public static List<DbEntity> LoadElems(IDataReader reader)
|
||||
{
|
||||
List<DbEntity> result = new List<DbEntity>();
|
||||
List<DbEntity> result = new();
|
||||
while (reader.Read())
|
||||
{
|
||||
Berth b = new();
|
||||
@ -61,10 +60,11 @@ namespace brecal.model
|
||||
if (!reader.IsDBNull(1)) b.Name = reader.GetString(1);
|
||||
if (!reader.IsDBNull(2)) b.Owner_Id = (uint) reader.GetInt32(2);
|
||||
if (!reader.IsDBNull(3)) b.Authority_Id = (uint) reader.GetInt32(3);
|
||||
if (!reader.IsDBNull(4)) b.Lock = reader.GetBoolean(4);
|
||||
if (!reader.IsDBNull(5)) b.Created = reader.GetDateTime(5);
|
||||
if (!reader.IsDBNull(6)) b.Modified = reader.GetDateTime(6);
|
||||
if (!reader.IsDBNull(7)) b.Deleted = reader.GetInt16(7);
|
||||
if (!reader.IsDBNull(4)) b.Port_Id = (uint) reader.GetInt32(4);
|
||||
if (!reader.IsDBNull(5)) b.Lock = reader.GetBoolean(5);
|
||||
if (!reader.IsDBNull(6)) b.Created = reader.GetDateTime(6);
|
||||
if (!reader.IsDBNull(7)) b.Modified = reader.GetDateTime(7);
|
||||
if (!reader.IsDBNull(8)) b.Deleted = reader.GetInt16(8);
|
||||
result.Add(b);
|
||||
}
|
||||
return result;
|
||||
@ -76,7 +76,7 @@ namespace brecal.model
|
||||
|
||||
public override void SetCreate(IDbCommand cmd)
|
||||
{
|
||||
cmd.CommandText = "INSERT INTO berth (owner_id, authority_id, name, `lock`) VALUES ( @PID, @AID, @NAME, @LOCK)";
|
||||
cmd.CommandText = "INSERT INTO berth (owner_id, authority_id, port_id, name, `lock`) VALUES ( @PID, @AID, @PO_ID, @NAME, @LOCK)";
|
||||
this.SetParameters(cmd);
|
||||
}
|
||||
|
||||
@ -92,7 +92,7 @@ namespace brecal.model
|
||||
|
||||
public override void SetUpdate(IDbCommand cmd)
|
||||
{
|
||||
cmd.CommandText = "UPDATE berth SET name = @NAME, owner_id = @PID, authority_id = @AID, `lock` = @LOCK WHERE id = @ID";
|
||||
cmd.CommandText = "UPDATE berth SET name = @NAME, owner_id = @PID, authority_id = @AID, port_id = @PO_ID, `lock` = @LOCK WHERE id = @ID";
|
||||
this.SetParameters(cmd);
|
||||
}
|
||||
|
||||
@ -109,14 +109,19 @@ namespace brecal.model
|
||||
|
||||
IDbDataParameter pid = cmd.CreateParameter();
|
||||
pid.ParameterName = "PID";
|
||||
pid.Value = this.Owner_Id;
|
||||
pid.Value = this.Owner_Id.HasValue ? this.Owner_Id.Value : DBNull.Value;
|
||||
cmd.Parameters.Add(pid);
|
||||
|
||||
IDbDataParameter aid = cmd.CreateParameter();
|
||||
aid.ParameterName = "AID";
|
||||
aid.Value = this.Authority_Id;
|
||||
aid.Value = this.Authority_Id.HasValue ? this.Authority_Id.Value : DBNull.Value;
|
||||
cmd.Parameters.Add(aid);
|
||||
|
||||
IDbDataParameter poid = cmd.CreateParameter();
|
||||
poid.ParameterName = "PO_ID";
|
||||
poid.Value = this.Port_Id.HasValue ? this.Port_Id.Value : DBNull.Value;
|
||||
cmd.Parameters.Add(poid);
|
||||
|
||||
IDbDataParameter name = cmd.CreateParameter();
|
||||
name.ParameterName = "NAME";
|
||||
name.Value = this.Name;
|
||||
|
||||
@ -14,7 +14,7 @@ namespace brecal.model
|
||||
|
||||
public string? Locode { get; set; }
|
||||
|
||||
public bool ? IsDeleted { get; set; }
|
||||
public bool IsDeleted { get; set; } = false;
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user