Extension of role editor to allow authority entry for berths
This commit is contained in:
parent
bf54b0e9d8
commit
d807b95020
@ -5,7 +5,7 @@
|
|||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
xmlns:local="clr-namespace:RoleEditor"
|
xmlns:local="clr-namespace:RoleEditor"
|
||||||
mc:Ignorable="d"
|
mc:Ignorable="d"
|
||||||
Title="Edit berth" Height="160" Width="450" Loaded="Window_Loaded">
|
Title="Edit berth" Height="188" Width="450" Loaded="Window_Loaded">
|
||||||
<Grid x:Name="berthGrid">
|
<Grid x:Name="berthGrid">
|
||||||
<Grid.ColumnDefinitions>
|
<Grid.ColumnDefinitions>
|
||||||
<ColumnDefinition Width=".3*" />
|
<ColumnDefinition Width=".3*" />
|
||||||
@ -15,25 +15,37 @@
|
|||||||
<RowDefinition Height="28" />
|
<RowDefinition Height="28" />
|
||||||
<RowDefinition Height="28" />
|
<RowDefinition Height="28" />
|
||||||
<RowDefinition Height="28" />
|
<RowDefinition Height="28" />
|
||||||
|
<RowDefinition Height="28" />
|
||||||
<RowDefinition Height="*" />
|
<RowDefinition Height="*" />
|
||||||
<RowDefinition Height="28" />
|
<RowDefinition Height="28" />
|
||||||
</Grid.RowDefinitions>
|
</Grid.RowDefinitions>
|
||||||
<Label Content="Name" HorizontalAlignment="Right" />
|
<Label Content="Name" HorizontalAlignment="Right" />
|
||||||
<TextBox x:Name="textBoxName" Grid.Column="1" Margin="2" VerticalContentAlignment="Center" Text="{Binding Name, Mode=OneWay}" />
|
<TextBox x:Name="textBoxName" Grid.Column="1" Margin="2" VerticalContentAlignment="Center" Text="{Binding Name, Mode=OneWay}" />
|
||||||
<Label Content="Participant / Terminal" HorizontalAlignment="Right" Grid.Row="1" />
|
<Label Content="Owner / Terminal" HorizontalAlignment="Right" Grid.Row="1" />
|
||||||
<Grid Grid.Row="1" Grid.Column="1">
|
<Grid Grid.Row="1" Grid.Column="1">
|
||||||
<Grid.ColumnDefinitions>
|
<Grid.ColumnDefinitions>
|
||||||
<ColumnDefinition Width="*" />
|
<ColumnDefinition Width="*" />
|
||||||
<ColumnDefinition Width="28" />
|
<ColumnDefinition Width="28" />
|
||||||
</Grid.ColumnDefinitions>
|
</Grid.ColumnDefinitions>
|
||||||
<ComboBox x:Name="comboBoxParticipants" Margin="2" SelectedItem="{Binding Participant, Mode=OneWay}" />
|
<ComboBox x:Name="comboBoxParticipants" Margin="2" SelectedItem="{Binding Owner, Mode=OneWay}" />
|
||||||
<Button x:Name="buttonResetParticipant" Grid.Column="1" Margin="2" Click="buttonResetParticipant_Click">
|
<Button x:Name="buttonResetParticipant" Grid.Column="1" Margin="2" Click="buttonResetParticipant_Click">
|
||||||
<Image Source="./Resources/delete2.png"/>
|
<Image Source="./Resources/delete2.png"/>
|
||||||
</Button>
|
</Button>
|
||||||
</Grid>
|
</Grid>
|
||||||
<Label Content="Uses lock" HorizontalAlignment="Right" Grid.Row="2" />
|
<Label Content="Authority" HorizontalAlignment="Right" Grid.Row="2" />
|
||||||
<CheckBox x:Name="checkBoxLock" Grid.Row="2" Grid.Column="1" VerticalAlignment="Center" Margin="2" IsChecked="{Binding Path=Lock, Mode=OneWay}"/>
|
<Grid Grid.Row="2" Grid.Column="1">
|
||||||
<StackPanel Grid.Column="1" Grid.Row="4" Orientation="Horizontal" FlowDirection="RightToLeft">
|
<Grid.ColumnDefinitions>
|
||||||
|
<ColumnDefinition Width="*" />
|
||||||
|
<ColumnDefinition Width="28" />
|
||||||
|
</Grid.ColumnDefinitions>
|
||||||
|
<ComboBox x:Name="comboBoxAuthorities" Margin="2" SelectedItem="{Binding Authority, Mode=OneWay}" />
|
||||||
|
<Button x:Name="buttonResetAuthority" Grid.Column="1" Margin="2" Click="buttonResetAuthority_Click">
|
||||||
|
<Image Source="./Resources/delete2.png"/>
|
||||||
|
</Button>
|
||||||
|
</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">
|
||||||
<Button x:Name="buttonCancel" Width="80" Content="Cancel" Margin="2" Click="buttonCancel_Click" />
|
<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"/>
|
<Button x:Name="buttonOK" Width="80" Content="OK" Margin="2" Click="buttonOK_Click"/>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
|
|||||||
@ -16,7 +16,9 @@ namespace RoleEditor
|
|||||||
|
|
||||||
public Berth Berth { get; set; } = new Berth();
|
public Berth Berth { get; set; } = new Berth();
|
||||||
|
|
||||||
public List<Participant> Participants { get; } = new List<Participant>();
|
public List<Participant> Owners { get; } = new List<Participant>();
|
||||||
|
|
||||||
|
public List<Participant> Authorities { get; } = new List<Participant>();
|
||||||
|
|
||||||
private void buttonCancel_Click(object sender, RoutedEventArgs e)
|
private void buttonCancel_Click(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
@ -28,11 +30,19 @@ namespace RoleEditor
|
|||||||
{
|
{
|
||||||
this.Berth.Name = this.textBoxName.Text.Trim();
|
this.Berth.Name = this.textBoxName.Text.Trim();
|
||||||
this.Berth.Lock = this.checkBoxLock.IsChecked;
|
this.Berth.Lock = this.checkBoxLock.IsChecked;
|
||||||
this.Berth.Participant = this.comboBoxParticipants.SelectedItem as Participant;
|
|
||||||
if (this.Berth.Participant != null)
|
this.Berth.Owner = this.comboBoxParticipants.SelectedItem as Participant;
|
||||||
this.Berth.Participant_Id = this.Berth.Participant.Id;
|
if (this.Berth.Owner != null)
|
||||||
|
this.Berth.Owner_Id = this.Berth.Owner.Id;
|
||||||
else
|
else
|
||||||
this.Berth.Participant_Id = null;
|
this.Berth.Owner_Id = null;
|
||||||
|
|
||||||
|
this.Berth.Authority = this.comboBoxAuthorities.SelectedItem as Participant;
|
||||||
|
if (this.Berth.Authority != null)
|
||||||
|
this.Berth.Authority_Id = this.Berth.Authority.Id;
|
||||||
|
else
|
||||||
|
this.Berth.Authority_Id = null;
|
||||||
|
|
||||||
this.DialogResult = true;
|
this.DialogResult = true;
|
||||||
this.Close();
|
this.Close();
|
||||||
}
|
}
|
||||||
@ -40,12 +50,18 @@ namespace RoleEditor
|
|||||||
private void Window_Loaded(object sender, RoutedEventArgs e)
|
private void Window_Loaded(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
this.DataContext = this.Berth;
|
this.DataContext = this.Berth;
|
||||||
this.comboBoxParticipants.ItemsSource = this.Participants;
|
this.comboBoxParticipants.ItemsSource = this.Owners;
|
||||||
|
this.comboBoxAuthorities.ItemsSource = this.Authorities;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void buttonResetParticipant_Click(object sender, RoutedEventArgs e)
|
private void buttonResetParticipant_Click(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
this.comboBoxParticipants.SelectedItem = null;
|
this.comboBoxParticipants.SelectedItem = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void buttonResetAuthority_Click(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
this.comboBoxAuthorities.SelectedItem = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -261,6 +261,7 @@
|
|||||||
<DataGridTextColumn Header="Name" Binding="{Binding Path=Name}" IsReadOnly="True"/>
|
<DataGridTextColumn Header="Name" Binding="{Binding Path=Name}" IsReadOnly="True"/>
|
||||||
<DataGridCheckBoxColumn Header="Lock" Binding="{Binding Path=Lock}" IsReadOnly="True"/>
|
<DataGridCheckBoxColumn Header="Lock" Binding="{Binding Path=Lock}" IsReadOnly="True"/>
|
||||||
<DataGridTextColumn Header="Terminal" Binding="{Binding Path=Terminal, Mode=OneWay}" 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" />
|
||||||
</DataGrid.Columns>
|
</DataGrid.Columns>
|
||||||
</local:ENIDataGrid>
|
</local:ENIDataGrid>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|||||||
@ -28,6 +28,9 @@ namespace RoleEditor
|
|||||||
#region private fields
|
#region private fields
|
||||||
|
|
||||||
private readonly ObservableCollection<Participant> _participants = new ObservableCollection<Participant>();
|
private readonly ObservableCollection<Participant> _participants = new ObservableCollection<Participant>();
|
||||||
|
private readonly ObservableCollection<Participant> _terminals = new ObservableCollection<Participant>();
|
||||||
|
private readonly ObservableCollection<Participant> _authorities = new ObservableCollection<Participant>();
|
||||||
|
|
||||||
private readonly ObservableCollection<Role> _roles = new ObservableCollection<Role>();
|
private readonly ObservableCollection<Role> _roles = new ObservableCollection<Role>();
|
||||||
private readonly ObservableCollection<Securable> _securables = new ObservableCollection<Securable>();
|
private readonly ObservableCollection<Securable> _securables = new ObservableCollection<Securable>();
|
||||||
private readonly ObservableCollection<User> _users = new ObservableCollection<User>();
|
private readonly ObservableCollection<User> _users = new ObservableCollection<User>();
|
||||||
@ -56,8 +59,12 @@ namespace RoleEditor
|
|||||||
|
|
||||||
// load all participants
|
// load all participants
|
||||||
List<Participant> participants = await Participant.LoadAll(_dbManager);
|
List<Participant> participants = await Participant.LoadAll(_dbManager);
|
||||||
foreach(Participant p in participants)
|
foreach (Participant p in participants)
|
||||||
|
{
|
||||||
_participants.Add(p);
|
_participants.Add(p);
|
||||||
|
if(p.IsTypeFlagSet(Participant.ParticipantType.TERMINAL)) { _terminals.Add(p); }
|
||||||
|
if(p.IsTypeFlagSet(Participant.ParticipantType.PORT_ADMINISTRATION)) { _authorities.Add(p); }
|
||||||
|
}
|
||||||
this.listBoxParticipant.ItemsSource = _participants;
|
this.listBoxParticipant.ItemsSource = _participants;
|
||||||
|
|
||||||
// load all roles
|
// load all roles
|
||||||
@ -74,9 +81,13 @@ namespace RoleEditor
|
|||||||
foreach (Berth b in await Berth.LoadAll(_dbManager))
|
foreach (Berth b in await Berth.LoadAll(_dbManager))
|
||||||
{
|
{
|
||||||
_berths.Add(b);
|
_berths.Add(b);
|
||||||
if(b.Participant_Id != null)
|
if (b.Owner_Id != null)
|
||||||
{
|
{
|
||||||
b.Participant = participants.Where( p => p.Id== b.Participant_Id ).FirstOrDefault();
|
b.Owner = participants.Where(p => p.Id == b.Owner_Id).FirstOrDefault();
|
||||||
|
}
|
||||||
|
if (b.Authority_Id != null)
|
||||||
|
{
|
||||||
|
b.Authority = participants.Where(p => p.Id == b.Authority_Id).FirstOrDefault();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.dataGridBerths.Initialize();
|
this.dataGridBerths.Initialize();
|
||||||
@ -173,7 +184,8 @@ namespace RoleEditor
|
|||||||
{
|
{
|
||||||
EditBerthDialog ebd = new();
|
EditBerthDialog ebd = new();
|
||||||
ebd.Berth = b;
|
ebd.Berth = b;
|
||||||
ebd.Participants.AddRange(this._participants);
|
ebd.Owners.AddRange(this._terminals);
|
||||||
|
ebd.Authorities.AddRange(this._authorities);
|
||||||
if (ebd.ShowDialog() ?? false)
|
if (ebd.ShowDialog() ?? false)
|
||||||
{
|
{
|
||||||
await b.Save(_dbManager);
|
await b.Save(_dbManager);
|
||||||
@ -188,7 +200,8 @@ namespace RoleEditor
|
|||||||
Berth b = new();
|
Berth b = new();
|
||||||
EditBerthDialog ebd = new();
|
EditBerthDialog ebd = new();
|
||||||
ebd.Berth = b;
|
ebd.Berth = b;
|
||||||
ebd.Participants.AddRange(this._participants);
|
ebd.Owners.AddRange(this._terminals);
|
||||||
|
ebd.Authorities.AddRange(this._authorities);
|
||||||
if (ebd.ShowDialog() ?? false)
|
if (ebd.ShowDialog() ?? false)
|
||||||
{
|
{
|
||||||
_berths.Add(b);
|
_berths.Add(b);
|
||||||
@ -634,7 +647,7 @@ namespace RoleEditor
|
|||||||
{
|
{
|
||||||
if ((p.Name != null) && p.Name.Contains(participant_name, StringComparison.OrdinalIgnoreCase))
|
if ((p.Name != null) && p.Name.Contains(participant_name, StringComparison.OrdinalIgnoreCase))
|
||||||
{
|
{
|
||||||
b.Participant_Id = p.Id;
|
b.Owner_Id = p.Id;
|
||||||
found_participant = true;
|
found_participant = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -649,7 +662,7 @@ namespace RoleEditor
|
|||||||
await p.Save(_dbManager);
|
await p.Save(_dbManager);
|
||||||
_participants.Add(p);
|
_participants.Add(p);
|
||||||
pCounter++;
|
pCounter++;
|
||||||
b.Participant_Id = p.Id;
|
b.Owner_Id = p.Id;
|
||||||
}
|
}
|
||||||
|
|
||||||
await b.Save(_dbManager);
|
await b.Save(_dbManager);
|
||||||
|
|||||||
@ -1,4 +1,7 @@
|
|||||||
using System;
|
// Copyright (c) 2023- schick Informatik
|
||||||
|
// Description: Model class for berth entity
|
||||||
|
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Data;
|
using System.Data;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@ -16,11 +19,17 @@ namespace brecal.model
|
|||||||
|
|
||||||
public bool? Lock { get; set; }
|
public bool? Lock { get; set; }
|
||||||
|
|
||||||
public uint? Participant_Id { get; set; }
|
public uint? Owner_Id { get; set; }
|
||||||
|
|
||||||
public Participant? Participant { get; set; }
|
public uint? Authority_Id { get; set; }
|
||||||
|
|
||||||
public string? Terminal { get { if (Participant != null) return Participant.Name; else return "n/a"; } }
|
public Participant? Owner { get; set; }
|
||||||
|
|
||||||
|
public Participant? Authority { 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"; } }
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@ -37,7 +46,7 @@ namespace brecal.model
|
|||||||
|
|
||||||
public static void SetLoadQuery(IDbCommand cmd, params object?[] list)
|
public static void SetLoadQuery(IDbCommand cmd, params object?[] list)
|
||||||
{
|
{
|
||||||
cmd.CommandText = "SELECT id, name, participant_id, `lock`, created, modified FROM berth";
|
cmd.CommandText = "SELECT id, name, owner_id, authority_id, `lock`, created, modified FROM berth";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<DbEntity> LoadElems(IDataReader reader)
|
public static List<DbEntity> LoadElems(IDataReader reader)
|
||||||
@ -48,10 +57,11 @@ namespace brecal.model
|
|||||||
Berth b = new();
|
Berth b = new();
|
||||||
b.Id = (uint)reader.GetInt32(0);
|
b.Id = (uint)reader.GetInt32(0);
|
||||||
if (!reader.IsDBNull(1)) b.Name = reader.GetString(1);
|
if (!reader.IsDBNull(1)) b.Name = reader.GetString(1);
|
||||||
if (!reader.IsDBNull(2)) b.Participant_Id = (uint) reader.GetInt32(2);
|
if (!reader.IsDBNull(2)) b.Owner_Id = (uint) reader.GetInt32(2);
|
||||||
if (!reader.IsDBNull(3)) b.Lock = reader.GetBoolean(3);
|
if (!reader.IsDBNull(3)) b.Authority_Id = (uint) reader.GetInt32(3);
|
||||||
if (!reader.IsDBNull(4)) b.Created = reader.GetDateTime(4);
|
if (!reader.IsDBNull(4)) b.Lock = reader.GetBoolean(4);
|
||||||
if (!reader.IsDBNull(5)) b.Modified = reader.GetDateTime(5);
|
if (!reader.IsDBNull(5)) b.Created = reader.GetDateTime(5);
|
||||||
|
if (!reader.IsDBNull(6)) b.Modified = reader.GetDateTime(6);
|
||||||
result.Add(b);
|
result.Add(b);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
@ -63,7 +73,7 @@ namespace brecal.model
|
|||||||
|
|
||||||
public override void SetCreate(IDbCommand cmd)
|
public override void SetCreate(IDbCommand cmd)
|
||||||
{
|
{
|
||||||
cmd.CommandText = "INSERT INTO berth (participant_id, name, `lock`) VALUES ( @PID, @NAME, @LOCK)";
|
cmd.CommandText = "INSERT INTO berth (owner_id, authority_id, name, `lock`) VALUES ( @PID, @AID, @NAME, @LOCK)";
|
||||||
this.SetParameters(cmd);
|
this.SetParameters(cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -79,7 +89,7 @@ namespace brecal.model
|
|||||||
|
|
||||||
public override void SetUpdate(IDbCommand cmd)
|
public override void SetUpdate(IDbCommand cmd)
|
||||||
{
|
{
|
||||||
cmd.CommandText = "UPDATE berth SET name = @NAME, participant_id = @PID, `lock` = @LOCK WHERE id = @ID";
|
cmd.CommandText = "UPDATE berth SET name = @NAME, owner_id = @PID, authority_id = @AID, `lock` = @LOCK WHERE id = @ID";
|
||||||
this.SetParameters(cmd);
|
this.SetParameters(cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -96,9 +106,14 @@ namespace brecal.model
|
|||||||
|
|
||||||
IDbDataParameter pid = cmd.CreateParameter();
|
IDbDataParameter pid = cmd.CreateParameter();
|
||||||
pid.ParameterName = "PID";
|
pid.ParameterName = "PID";
|
||||||
pid.Value = this.Participant_Id;
|
pid.Value = this.Owner_Id;
|
||||||
cmd.Parameters.Add(pid);
|
cmd.Parameters.Add(pid);
|
||||||
|
|
||||||
|
IDbDataParameter aid = cmd.CreateParameter();
|
||||||
|
aid.ParameterName = "AID";
|
||||||
|
aid.Value = this.Authority_Id;
|
||||||
|
cmd.Parameters.Add(aid);
|
||||||
|
|
||||||
IDbDataParameter name = cmd.CreateParameter();
|
IDbDataParameter name = cmd.CreateParameter();
|
||||||
name.ParameterName = "NAME";
|
name.ParameterName = "NAME";
|
||||||
name.Value = this.Name;
|
name.Value = this.Name;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user