Extending the role editor pt. 1
This commit is contained in:
parent
bbc705cf63
commit
de7a9a05f2
@ -6,7 +6,7 @@
|
|||||||
xmlns:local="clr-namespace:RoleEditor"
|
xmlns:local="clr-namespace:RoleEditor"
|
||||||
xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
|
xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
|
||||||
mc:Ignorable="d"
|
mc:Ignorable="d"
|
||||||
Title="Bremen calling admin editor" Height="670" Width="800" Icon="Resources/lock_preferences.ico" Loaded="Window_Loaded">
|
Title="Bremen calling admin editor" Height="670" Width="1024" Icon="Resources/lock_preferences.ico" Loaded="Window_Loaded">
|
||||||
<Grid>
|
<Grid>
|
||||||
<TabControl>
|
<TabControl>
|
||||||
<TabItem Header="Participant, users and roles">
|
<TabItem Header="Participant, users and roles">
|
||||||
@ -16,8 +16,9 @@
|
|||||||
<RowDefinition Height=".5*" />
|
<RowDefinition Height=".5*" />
|
||||||
</Grid.RowDefinitions>
|
</Grid.RowDefinitions>
|
||||||
<Grid.ColumnDefinitions>
|
<Grid.ColumnDefinitions>
|
||||||
<ColumnDefinition Width=".5*" />
|
<ColumnDefinition Width=".4*" />
|
||||||
<ColumnDefinition Width=".5*" />
|
<ColumnDefinition Width=".3*" />
|
||||||
|
<ColumnDefinition Width=".3*" />
|
||||||
</Grid.ColumnDefinitions>
|
</Grid.ColumnDefinitions>
|
||||||
<GroupBox Header="Participant" Margin="2">
|
<GroupBox Header="Participant" Margin="2">
|
||||||
<Grid>
|
<Grid>
|
||||||
@ -82,6 +83,52 @@
|
|||||||
</Button>
|
</Button>
|
||||||
</Grid>
|
</Grid>
|
||||||
</GroupBox>
|
</GroupBox>
|
||||||
|
<GroupBox Header="Port Assignment" Margin="2" Grid.Row="0" Grid.Column="1">
|
||||||
|
<xctk:CheckListBox x:Name="checkListBoxPortAssignment" Margin="2" />
|
||||||
|
</GroupBox>
|
||||||
|
<GroupBox Header="Ports" Margin="2" Grid.Row="0" Grid.Column="2">
|
||||||
|
<Grid>
|
||||||
|
<Grid.RowDefinitions>
|
||||||
|
<RowDefinition Height="28"/>
|
||||||
|
<RowDefinition Height="28"/>
|
||||||
|
<RowDefinition Height="28"/>
|
||||||
|
<RowDefinition Height="*"/>
|
||||||
|
</Grid.RowDefinitions>
|
||||||
|
<Grid.ColumnDefinitions>
|
||||||
|
<ColumnDefinition Width="160" />
|
||||||
|
<ColumnDefinition Width=".38*" />
|
||||||
|
<ColumnDefinition Width=".62*" />
|
||||||
|
</Grid.ColumnDefinitions>
|
||||||
|
<ListBox x:Name="listBoxPort" Margin="2" Grid.RowSpan="4" SelectionChanged="listBoxPort_SelectionChanged">
|
||||||
|
<ListBox.ContextMenu>
|
||||||
|
<ContextMenu>
|
||||||
|
<MenuItem x:Name="menuItemNewPort" Header="New.." Click="menuItemNewPort_Click">
|
||||||
|
<MenuItem.Icon>
|
||||||
|
<Image Source="Resources/add.png" />
|
||||||
|
</MenuItem.Icon>
|
||||||
|
</MenuItem>
|
||||||
|
<MenuItem x:Name="menuItemDeletePort" Header="Delete" Click="menuItemDeletePort_Click">
|
||||||
|
<MenuItem.Icon>
|
||||||
|
<Image Source="Resources/delete2.png" />
|
||||||
|
</MenuItem.Icon>
|
||||||
|
</MenuItem>
|
||||||
|
</ContextMenu>
|
||||||
|
</ListBox.ContextMenu>
|
||||||
|
</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" />
|
||||||
|
|
||||||
|
<Button x:Name="buttonPortSave" Grid.Row="2" Grid.Column="2" Click="buttonPortSave_Click" Margin="2">
|
||||||
|
<DockPanel>
|
||||||
|
<Image Source="./Resources/disk_blue.png" Margin="0,0,5,0" Height="24" DockPanel.Dock="Left" Width="16"/>
|
||||||
|
<TextBlock Text="Save" VerticalAlignment="Center" DockPanel.Dock="Right"/>
|
||||||
|
</DockPanel>
|
||||||
|
</Button>
|
||||||
|
</Grid>
|
||||||
|
|
||||||
|
</GroupBox>
|
||||||
<GroupBox Header="User" Margin="2" Grid.Row="1">
|
<GroupBox Header="User" Margin="2" Grid.Row="1">
|
||||||
<Grid>
|
<Grid>
|
||||||
<Grid.RowDefinitions>
|
<Grid.RowDefinitions>
|
||||||
@ -145,7 +192,7 @@
|
|||||||
</Button>
|
</Button>
|
||||||
</Grid>
|
</Grid>
|
||||||
</GroupBox>
|
</GroupBox>
|
||||||
<GroupBox Header="Role" Margin="2" Grid.Column="1">
|
<GroupBox Header="Role" Margin="2" Grid.Column="1" Grid.Row="1">
|
||||||
<Grid>
|
<Grid>
|
||||||
<Grid.RowDefinitions>
|
<Grid.RowDefinitions>
|
||||||
<RowDefinition Height="28"/>
|
<RowDefinition Height="28"/>
|
||||||
@ -199,7 +246,7 @@
|
|||||||
</Button>
|
</Button>
|
||||||
</Grid>
|
</Grid>
|
||||||
</GroupBox>
|
</GroupBox>
|
||||||
<GroupBox Header="Securable" Margin="2" Grid.Row="1" Grid.Column="1">
|
<GroupBox Header="Securable" Margin="2" Grid.Row="1" Grid.Column="2">
|
||||||
<Grid>
|
<Grid>
|
||||||
<Grid.RowDefinitions>
|
<Grid.RowDefinitions>
|
||||||
<RowDefinition Height="28"/>
|
<RowDefinition Height="28"/>
|
||||||
|
|||||||
@ -802,5 +802,24 @@ namespace RoleEditor
|
|||||||
|
|
||||||
#endregion
|
#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)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
106
src/brecal.model/Port.cs
Normal file
106
src/brecal.model/Port.cs
Normal file
@ -0,0 +1,106 @@
|
|||||||
|
// Copyright (c) 2023- schick Informatik
|
||||||
|
// Description: Port entity
|
||||||
|
|
||||||
|
using System.Data;
|
||||||
|
|
||||||
|
namespace brecal.model
|
||||||
|
{
|
||||||
|
public class Port : DbEntity
|
||||||
|
{
|
||||||
|
|
||||||
|
#region Properties
|
||||||
|
|
||||||
|
public string? Name { get; set; }
|
||||||
|
|
||||||
|
public string? Locode { get; set; }
|
||||||
|
|
||||||
|
public bool ? IsDeleted { get; set; }
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region overrides
|
||||||
|
|
||||||
|
public override void SetCreate(IDbCommand cmd)
|
||||||
|
{
|
||||||
|
cmd.CommandText = "INSERT INTO role (name, locode) VALUES ( @NAME, @LOCODE)";
|
||||||
|
this.SetParameters(cmd);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void SetDelete(IDbCommand cmd)
|
||||||
|
{
|
||||||
|
cmd.CommandText = "UPDATE port SET deleted = 1 WHERE id = @ID";
|
||||||
|
IDataParameter idParam = cmd.CreateParameter();
|
||||||
|
idParam.ParameterName = "ID";
|
||||||
|
idParam.Value = this.Id;
|
||||||
|
cmd.Parameters.Add(idParam);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void SetUpdate(IDbCommand cmd)
|
||||||
|
{
|
||||||
|
cmd.CommandText = "UPDATE port set name = @NAME, locode = @LOCODE WHERE id = @ID";
|
||||||
|
this.SetParameters(cmd);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region public static methods
|
||||||
|
|
||||||
|
public static async Task<List<Port>> LoadAll(IDBManager manager)
|
||||||
|
{
|
||||||
|
List<DbEntity> loadResultList = await manager.Load(SetLoadQuery, LoadElems);
|
||||||
|
List<Port> result = new();
|
||||||
|
foreach (Port p in loadResultList.Cast<Port>())
|
||||||
|
result.Add(p);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void SetLoadQuery(IDbCommand cmd, params object?[] list)
|
||||||
|
{
|
||||||
|
cmd.CommandText = "SELECT id, name, locode, created, modified, deleted FROM port";
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<DbEntity> LoadElems(IDataReader reader)
|
||||||
|
{
|
||||||
|
List<DbEntity> result = new List<DbEntity>();
|
||||||
|
while (reader.Read())
|
||||||
|
{
|
||||||
|
Port p = new();
|
||||||
|
p.Id = (uint)reader.GetInt32(0);
|
||||||
|
if (!reader.IsDBNull(1)) p.Name = reader.GetString(1);
|
||||||
|
if (!reader.IsDBNull(2)) p.Locode = reader.GetString(2);
|
||||||
|
if (!reader.IsDBNull(3)) p.Created = reader.GetDateTime(3);
|
||||||
|
if (!reader.IsDBNull(4)) p.Modified = reader.GetDateTime(4);
|
||||||
|
if (!reader.IsDBNull(5)) p.IsDeleted = reader.GetBoolean(5);
|
||||||
|
result.Add(p);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region private methods
|
||||||
|
|
||||||
|
private void SetParameters(IDbCommand cmd)
|
||||||
|
{
|
||||||
|
IDbDataParameter name = cmd.CreateParameter();
|
||||||
|
name.ParameterName = "NAME";
|
||||||
|
name.Value = this.Name;
|
||||||
|
cmd.Parameters.Add(name);
|
||||||
|
|
||||||
|
IDbDataParameter desc = cmd.CreateParameter();
|
||||||
|
desc.ParameterName = "LOCODE";
|
||||||
|
desc.Value = this.Locode;
|
||||||
|
cmd.Parameters.Add(desc);
|
||||||
|
|
||||||
|
IDataParameter idParam = cmd.CreateParameter();
|
||||||
|
idParam.ParameterName = "ID";
|
||||||
|
idParam.Value = this.Id;
|
||||||
|
cmd.Parameters.Add(idParam);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
111
src/brecal.model/PortAssignment.cs
Normal file
111
src/brecal.model/PortAssignment.cs
Normal file
@ -0,0 +1,111 @@
|
|||||||
|
// Copyright (c) 2023- schick Informatik
|
||||||
|
// Description: Participant Port Map Entity
|
||||||
|
|
||||||
|
using System.Data;
|
||||||
|
|
||||||
|
namespace brecal.model
|
||||||
|
{
|
||||||
|
public class PortAssignment : DbEntity
|
||||||
|
{
|
||||||
|
#region Properties
|
||||||
|
|
||||||
|
public int? ParticipantId { get; set; }
|
||||||
|
|
||||||
|
public int? PortId { get; set; }
|
||||||
|
|
||||||
|
public Participant? AssignedParticipant { get; set; }
|
||||||
|
|
||||||
|
public Port? AssignedPort { get; set; }
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region public static methods
|
||||||
|
|
||||||
|
public static async Task<List<PortAssignment>> LoadForParticipant(Participant? p, IDBManager manager)
|
||||||
|
{
|
||||||
|
List<DbEntity> loadResultList = await manager.Load(SetLoadQuery, LoadElems, args: p);
|
||||||
|
List<PortAssignment> result = new();
|
||||||
|
foreach (PortAssignment pa in loadResultList.Cast<PortAssignment>())
|
||||||
|
{
|
||||||
|
pa.AssignedParticipant = p;
|
||||||
|
result.Add(pa);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
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))
|
||||||
|
throw new ArgumentException("loader needs single participant as argument");
|
||||||
|
IDataParameter pid = cmd.CreateParameter();
|
||||||
|
pid.ParameterName = "PID";
|
||||||
|
if (args[0] is Participant p)
|
||||||
|
pid.Value = p.Id;
|
||||||
|
cmd.Parameters.Add(pid);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<DbEntity> LoadElems(IDataReader reader)
|
||||||
|
{
|
||||||
|
List<DbEntity> result = new List<DbEntity>();
|
||||||
|
while (reader.Read())
|
||||||
|
{
|
||||||
|
PortAssignment ra = new();
|
||||||
|
ra.Id = (uint)reader.GetInt32(0);
|
||||||
|
if (!reader.IsDBNull(1)) ra.ParticipantId = reader.GetInt32(1);
|
||||||
|
if (!reader.IsDBNull(2)) ra.PortId = reader.GetInt32(2);
|
||||||
|
result.Add(ra);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region overrides
|
||||||
|
|
||||||
|
public override void SetUpdate(IDbCommand cmd)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void SetCreate(IDbCommand cmd)
|
||||||
|
{
|
||||||
|
cmd.CommandText = "INSERT INTO participant_port_map (participant_id, port_id) VALUES (@PID, @PORTID)";
|
||||||
|
|
||||||
|
IDbDataParameter participantId = cmd.CreateParameter();
|
||||||
|
participantId.ParameterName = "pID";
|
||||||
|
participantId.Value = this.ParticipantId;
|
||||||
|
cmd.Parameters.Add(participantId);
|
||||||
|
|
||||||
|
IDbDataParameter portId = cmd.CreateParameter();
|
||||||
|
portId.ParameterName = "PORTID";
|
||||||
|
portId.Value = this.PortId;
|
||||||
|
cmd.Parameters.Add(portId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void SetDelete(IDbCommand cmd)
|
||||||
|
{
|
||||||
|
cmd.CommandText = "DELETE FROM participant_port_map WHERE id = @ID";
|
||||||
|
|
||||||
|
IDataParameter idParam = cmd.CreateParameter();
|
||||||
|
idParam.ParameterName = "ID";
|
||||||
|
idParam.Value = this.Id;
|
||||||
|
cmd.Parameters.Add(idParam);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
if (this.AssignedPort == null)
|
||||||
|
{
|
||||||
|
return $"{Id}: <defunct port>";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return AssignedPort.Name ?? AssignedPort.Id.ToString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,9 +1,7 @@
|
|||||||
using System;
|
// Copyright (c) 2023- schick Informatik
|
||||||
using System.Collections.Generic;
|
// Description: Role Entity
|
||||||
|
|
||||||
using System.Data;
|
using System.Data;
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace brecal.model
|
namespace brecal.model
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user