Extending the role editor pt.2
This commit is contained in:
parent
de7a9a05f2
commit
8b4c9e2590
@ -84,7 +84,24 @@
|
||||
</Grid>
|
||||
</GroupBox>
|
||||
<GroupBox Header="Port Assignment" Margin="2" Grid.Row="0" Grid.Column="1">
|
||||
<xctk:CheckListBox x:Name="checkListBoxPortAssignment" Margin="2" />
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="28" />
|
||||
<RowDefinition Height="28" />
|
||||
<RowDefinition Height="*" />
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="60" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<ListBox x:Name="listBoxPortAssignment" Margin="2" Grid.Row="0" Grid.Column="0" Grid.RowSpan="3" />
|
||||
<Button x:Name="buttonAddPortAssignment" Margin="2" Grid.Row="0" Grid.Column="1" Click="buttonAddPortAssignment_Click">
|
||||
<Image Source="./Resources/arrow_left_green.png"/>
|
||||
</Button>
|
||||
<Button x:Name="buttonRemovePortAssignment" Margin="2" Grid.Row="1" Grid.Column="1" Click="buttonRemovePortAssignment_Click">
|
||||
<Image Source="./Resources/delete2.png"/>
|
||||
</Button>
|
||||
</Grid>
|
||||
</GroupBox>
|
||||
<GroupBox Header="Ports" Margin="2" Grid.Row="0" Grid.Column="2">
|
||||
<Grid>
|
||||
@ -117,8 +134,8 @@
|
||||
</ListBox>
|
||||
<Label Grid.Row="0" Grid.Column="1" Content="Name" HorizontalAlignment="Right"/>
|
||||
<Label Grid.Row="1" Grid.Column="1" Content="Locode" HorizontalAlignment="Right"/>
|
||||
<TextBox x:Name="textBoxPortName" Grid.Row="0" Grid.Column="2" Margin="2" VerticalContentAlignment="Center" />
|
||||
<TextBox x:Name="textBoxPortLocode" Grid.Row="1" Grid.Column="2" Margin="2" VerticalContentAlignment="Center" />
|
||||
<TextBox x:Name="textBoxPortName" Grid.Row="0" Grid.Column="2" Margin="2" VerticalContentAlignment="Center" MaxLength="128"/>
|
||||
<TextBox x:Name="textBoxPortLocode" Grid.Row="1" Grid.Column="2" Margin="2" VerticalContentAlignment="Center" MaxLength="5" />
|
||||
|
||||
<Button x:Name="buttonPortSave" Grid.Row="2" Grid.Column="2" Click="buttonPortSave_Click" Margin="2">
|
||||
<DockPanel>
|
||||
|
||||
@ -38,6 +38,8 @@ namespace RoleEditor
|
||||
private readonly ObservableCollection<SecurableAssignment> _assignedSecurables = new ObservableCollection<SecurableAssignment>();
|
||||
private readonly ObservableCollection<Berth> _berths = new ObservableCollection<Berth>();
|
||||
private readonly ObservableCollection<Ship> _ships = new ObservableCollection<Ship>();
|
||||
private readonly ObservableCollection<Port> _ports = new ObservableCollection<Port>();
|
||||
private readonly ObservableCollection<PortAssignment> _assignedPorts = new ObservableCollection<PortAssignment>();
|
||||
private DBManager _dbManager;
|
||||
|
||||
#endregion
|
||||
@ -114,10 +116,16 @@ namespace RoleEditor
|
||||
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;
|
||||
|
||||
|
||||
// set other item sources (filled later after selection)
|
||||
this.listBoxUser.ItemsSource = _users;
|
||||
this.listBoxRoleSecurables.ItemsSource = _assignedSecurables;
|
||||
this.listBoxUserRoles.ItemsSource = _assignedRoles;
|
||||
this.listBoxPortAssignment.ItemsSource = _assignedPorts;
|
||||
|
||||
this.comboBoxParticipantType.ItemsSource = EnumHelper.GetAllValuesAndDescription(typeof(Participant.ParticipantType));
|
||||
|
||||
@ -386,6 +394,59 @@ namespace RoleEditor
|
||||
}
|
||||
}
|
||||
|
||||
private async void buttonPortSave_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Port? p = this.listBoxPort.SelectedItem as Port;
|
||||
if (p != null)
|
||||
{
|
||||
p.Name = this.textBoxPortName.Text.Trim();
|
||||
p.Locode = this.textBoxPortLocode.Text.Trim();
|
||||
await p.Save(_dbManager);
|
||||
this.listBoxPort.ItemsSource = null;
|
||||
this.listBoxPort.ItemsSource = _ports;
|
||||
this.listBoxPort.SelectedItem = p;
|
||||
}
|
||||
}
|
||||
|
||||
private async void buttonAddPortAssignment_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if ((this.listBoxPort.SelectedItem is Port p) && (this.listBoxParticipant.SelectedItem is Participant pa))
|
||||
{
|
||||
// test if assignment is already present
|
||||
bool foundMatchingAssignment = false;
|
||||
foreach (PortAssignment portAssignment in _assignedPorts)
|
||||
{
|
||||
if ((portAssignment.PortId == p.Id) && (portAssignment.ParticipantId == pa.Id))
|
||||
{
|
||||
foundMatchingAssignment = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!foundMatchingAssignment)
|
||||
{
|
||||
PortAssignment portAssignment = new PortAssignment();
|
||||
portAssignment.PortId = (int)p.Id;
|
||||
portAssignment.ParticipantId = (int)pa.Id;
|
||||
portAssignment.AssignedParticipant = pa;
|
||||
portAssignment.AssignedPort = p;
|
||||
await portAssignment.Save(_dbManager);
|
||||
_assignedPorts.Add(portAssignment);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private async void buttonRemovePortAssignment_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
PortAssignment? pa = this.listBoxPortAssignment.SelectedItem as PortAssignment;
|
||||
if (pa != null)
|
||||
{
|
||||
await pa.Delete(_dbManager);
|
||||
if (_assignedPorts.Contains(pa))
|
||||
_assignedPorts.Remove(pa);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region listbox selection callbacks
|
||||
@ -430,6 +491,19 @@ namespace RoleEditor
|
||||
foreach (User u in await User.LoadForParticipant(p, _dbManager))
|
||||
_users.Add(u);
|
||||
}
|
||||
|
||||
// -> load port assignments for this participant selection
|
||||
this._assignedPorts.Clear();
|
||||
if(p != null)
|
||||
{
|
||||
foreach (PortAssignment pa in await PortAssignment.LoadForParticipant(p, this._dbManager))
|
||||
{
|
||||
foreach (Port port in this._ports)
|
||||
if (pa.PortId == port.Id)
|
||||
pa.AssignedPort = port;
|
||||
_assignedPorts.Add(pa);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private async void listBoxRoles_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||
@ -496,6 +570,13 @@ namespace RoleEditor
|
||||
this.textBoxSecurableName.Text = (s != null) ? s.Name : string.Empty;
|
||||
}
|
||||
|
||||
private void listBoxPort_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||
{
|
||||
Port? p = this.listBoxPort.SelectedItem as Port;
|
||||
this.textBoxPortName.Text = (p != null) ? p.Name : string.Empty;
|
||||
this.textBoxPortLocode.Text = (p != null) ? p.Locode : string.Empty;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region menuitem callbacks
|
||||
@ -597,6 +678,29 @@ namespace RoleEditor
|
||||
}
|
||||
}
|
||||
|
||||
private void menuItemNewPort_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Port p = new();
|
||||
this._ports.Add(p);
|
||||
this.listBoxPort.SelectedItem = p;
|
||||
}
|
||||
|
||||
private async void menuItemDeletePort_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (this.listBoxPort.SelectedItem is Port p)
|
||||
{
|
||||
await p.Delete(_dbManager);
|
||||
this._ports.Remove(p);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Excel import
|
||||
@ -801,25 +905,6 @@ namespace RoleEditor
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private void menuItemNewPort_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void listBoxPort_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void menuItemDeletePort_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void buttonPortSave_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
6
src/RoleEditor/Properties/Settings.Designer.cs
generated
6
src/RoleEditor/Properties/Settings.Designer.cs
generated
@ -12,7 +12,7 @@ namespace RoleEditor.Properties {
|
||||
|
||||
|
||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.5.0.0")]
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.10.0.0")]
|
||||
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
|
||||
|
||||
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
|
||||
@ -25,8 +25,8 @@ namespace RoleEditor.Properties {
|
||||
|
||||
[global::System.Configuration.ApplicationScopedSettingAttribute()]
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
[global::System.Configuration.DefaultSettingValueAttribute("Server=localhost;User ID=ds;Password=HalloWach_2323XXL!!;Database=bremen_calling;" +
|
||||
"Port=33306")]
|
||||
[global::System.Configuration.DefaultSettingValueAttribute("Server=localhost;User ID=ds;Password=HalloWach_2323XXL!!;Database=bremen_calling_" +
|
||||
"devel;Port=33306")]
|
||||
public string ConnectionString {
|
||||
get {
|
||||
return ((string)(this["ConnectionString"]));
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
<Profiles />
|
||||
<Settings>
|
||||
<Setting Name="ConnectionString" Type="System.String" Scope="Application">
|
||||
<Value Profile="(Default)">Server=localhost;User ID=ds;Password=HalloWach_2323XXL!!;Database=bremen_calling;Port=33306</Value>
|
||||
<Value Profile="(Default)">Server=localhost;User ID=ds;Password=HalloWach_2323XXL!!;Database=bremen_calling_devel;Port=33306</Value>
|
||||
</Setting>
|
||||
</Settings>
|
||||
</SettingsFile>
|
||||
@ -70,7 +70,7 @@ namespace brecal.model
|
||||
|
||||
public static List<DbEntity> LoadElems(IDataReader reader)
|
||||
{
|
||||
List<DbEntity> result = new List<DbEntity>();
|
||||
List<DbEntity> result = new();
|
||||
while (reader.Read())
|
||||
{
|
||||
Participant p = new();
|
||||
|
||||
@ -22,7 +22,7 @@ namespace brecal.model
|
||||
|
||||
public override void SetCreate(IDbCommand cmd)
|
||||
{
|
||||
cmd.CommandText = "INSERT INTO role (name, locode) VALUES ( @NAME, @LOCODE)";
|
||||
cmd.CommandText = "INSERT INTO port (name, locode) VALUES ( @NAME, @LOCODE)";
|
||||
this.SetParameters(cmd);
|
||||
}
|
||||
|
||||
@ -56,12 +56,12 @@ namespace brecal.model
|
||||
|
||||
public static void SetLoadQuery(IDbCommand cmd, params object?[] list)
|
||||
{
|
||||
cmd.CommandText = "SELECT id, name, locode, created, modified, deleted FROM port";
|
||||
cmd.CommandText = "SELECT id, name, locode, created, modified, deleted FROM port WHERE deleted = 0";
|
||||
}
|
||||
|
||||
public static List<DbEntity> LoadElems(IDataReader reader)
|
||||
{
|
||||
List<DbEntity> result = new List<DbEntity>();
|
||||
List<DbEntity> result = new();
|
||||
while (reader.Read())
|
||||
{
|
||||
Port p = new();
|
||||
@ -100,6 +100,15 @@ namespace brecal.model
|
||||
|
||||
#endregion
|
||||
|
||||
#region overrides
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{Name} ({Locode})";
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -36,7 +36,7 @@ namespace brecal.model
|
||||
public static void SetLoadQuery(IDbCommand cmd, params object?[] args)
|
||||
{
|
||||
cmd.CommandText = "SELECT id, participant_id, port_id FROM participant_port_map WHERE participant_id = @PID";
|
||||
if (args.Length != 1 || !(args[0] is Participant))
|
||||
if (args.Length != 1 || args[0] is not Participant)
|
||||
throw new ArgumentException("loader needs single participant as argument");
|
||||
IDataParameter pid = cmd.CreateParameter();
|
||||
pid.ParameterName = "PID";
|
||||
@ -47,7 +47,7 @@ namespace brecal.model
|
||||
|
||||
public static List<DbEntity> LoadElems(IDataReader reader)
|
||||
{
|
||||
List<DbEntity> result = new List<DbEntity>();
|
||||
List<DbEntity> result = new();
|
||||
while (reader.Read())
|
||||
{
|
||||
PortAssignment ra = new();
|
||||
|
||||
@ -17,7 +17,7 @@ namespace brecal.mysql
|
||||
|
||||
public async Task<List<DbEntity>> Load(QueryFunc prepareAction, LoadFunc<IDataReader> loadAction, params object?[] args)
|
||||
{
|
||||
await using MySqlConnection connection = new MySqlConnection(_connectionString);
|
||||
await using MySqlConnection connection = new(_connectionString);
|
||||
await connection.OpenAsync();
|
||||
|
||||
using MySqlCommand cmd = new();
|
||||
@ -31,7 +31,7 @@ namespace brecal.mysql
|
||||
|
||||
public async Task<object?> ExecuteScalar(Action<IDbCommand> prepareAction)
|
||||
{
|
||||
await using MySqlConnection connection = new MySqlConnection(_connectionString);
|
||||
await using MySqlConnection connection = new(_connectionString);
|
||||
await connection.OpenAsync();
|
||||
|
||||
using MySqlCommand cmd = new();
|
||||
|
||||
Reference in New Issue
Block a user