editing berths and ships Pt. 1
This commit is contained in:
parent
0ca62d7e80
commit
4e9151f8c8
288
src/RoleEditor/ENIDataGrid.cs
Normal file
288
src/RoleEditor/ENIDataGrid.cs
Normal file
@ -0,0 +1,288 @@
|
|||||||
|
// Copyright (c) 2017 schick Informatik
|
||||||
|
// Description: DataGrid mit etwas "verbesserten" Funktionen
|
||||||
|
//
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Windows;
|
||||||
|
using System.Windows.Controls;
|
||||||
|
using System.Windows.Input;
|
||||||
|
using System.Windows.Media;
|
||||||
|
using System.Windows.Media.Imaging;
|
||||||
|
|
||||||
|
using System.Windows.Controls.Primitives;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using brecal.model;
|
||||||
|
using System.Globalization;
|
||||||
|
using System.Threading;
|
||||||
|
|
||||||
|
namespace RoleEditor
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Follow steps 1a or 1b and then 2 to use this custom control in a XAML file.
|
||||||
|
///
|
||||||
|
/// Step 1a) Using this custom control in a XAML file that exists in the current project.
|
||||||
|
/// Add this XmlNamespace attribute to the root element of the markup file where it is
|
||||||
|
/// to be used:
|
||||||
|
///
|
||||||
|
/// xmlns:enictrl="clr-namespace:ENI2.Controls"
|
||||||
|
///
|
||||||
|
///
|
||||||
|
/// Step 1b) Using this custom control in a XAML file that exists in a different project.
|
||||||
|
/// Add this XmlNamespace attribute to the root element of the markup file where it is
|
||||||
|
/// to be used:
|
||||||
|
///
|
||||||
|
/// xmlns:enictrl="clr-namespace:ENI2.Controls;assembly=ENI2.Controls"
|
||||||
|
///
|
||||||
|
/// You will also need to add a project reference from the project where the XAML file lives
|
||||||
|
/// to this project and Rebuild to avoid compilation errors:
|
||||||
|
///
|
||||||
|
/// Right click on the target project in the Solution Explorer and
|
||||||
|
/// "Add Reference"->"Projects"->[Browse to and select this project]
|
||||||
|
///
|
||||||
|
///
|
||||||
|
/// Step 2)
|
||||||
|
/// Go ahead and use your control in the XAML file.
|
||||||
|
///
|
||||||
|
/// <MyNamespace:ENIDataGrid/>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
public class ENIDataGrid : DataGrid
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
static ENIDataGrid()
|
||||||
|
{
|
||||||
|
DefaultStyleKeyProperty.OverrideMetadata(typeof(ENIDataGrid), new FrameworkPropertyMetadata(typeof(ENIDataGrid)));
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
// das hier bildet 1:1 das Kontext-Menü des ANSW ab
|
||||||
|
|
||||||
|
public event Action<DbEntity>? EditRequested;
|
||||||
|
public event Action<DbEntity>? DeleteRequested;
|
||||||
|
public event Action? CreateRequested;
|
||||||
|
public event Action? RefreshGrid;
|
||||||
|
|
||||||
|
public event Action<DbEntity>? PrintRequested;
|
||||||
|
public event Action<DbEntity>? ExportRequested;
|
||||||
|
public event Action<DbEntity>? ShowTextRequested;
|
||||||
|
|
||||||
|
public void Initialize()
|
||||||
|
{
|
||||||
|
|
||||||
|
this.MouseDoubleClick += dataGrid_MouseDoubleClick;
|
||||||
|
this.PreviewKeyDown += ENIDataGrid_PreviewKeyDown;
|
||||||
|
|
||||||
|
this.ContextMenu = new ContextMenu();
|
||||||
|
this.CanUserAddRows = false;
|
||||||
|
this.IsReadOnly = false;
|
||||||
|
|
||||||
|
MenuItem addItem = new MenuItem();
|
||||||
|
|
||||||
|
addItem.Header = RoleEditor.Resources.ResourceManager.GetString("textAdd");
|
||||||
|
addItem.Icon = new Image { Source = Util.LoadImage(RoleEditor.Resources.add) };
|
||||||
|
addItem.Click += new RoutedEventHandler(this.addItem);
|
||||||
|
this.ContextMenu.Items.Add(addItem);
|
||||||
|
|
||||||
|
MenuItem deleteItem = new MenuItem();
|
||||||
|
deleteItem.Header = RoleEditor.Resources.ResourceManager.GetString("textDelete");
|
||||||
|
deleteItem.Icon = new Image { Source = Util.LoadImage(RoleEditor.Resources.delete) };
|
||||||
|
deleteItem.Click += this.deleteItem;
|
||||||
|
this.ContextMenu.Items.Add(deleteItem);
|
||||||
|
|
||||||
|
MenuItem editItem = new MenuItem();
|
||||||
|
editItem.Header = RoleEditor.Resources.ResourceManager.GetString("textEdit");
|
||||||
|
editItem.Icon = new Image { Source = Util.LoadImage(RoleEditor.Resources.edit) };
|
||||||
|
editItem.Click += this.editItem;
|
||||||
|
this.ContextMenu.Items.Add(editItem);
|
||||||
|
|
||||||
|
/*
|
||||||
|
this.ContextMenu.Items.Add(new Separator());
|
||||||
|
|
||||||
|
MenuItem printItem = new MenuItem();
|
||||||
|
printItem.Header = RoleEditor.Resources.ResourceManager.GetString("textPrint");
|
||||||
|
printItem.Icon = new Image { Source = Util.LoadImage(RoleEditor.Resources.printer) };
|
||||||
|
printItem.Click += this.printItem;
|
||||||
|
this.ContextMenu.Items.Add(printItem);
|
||||||
|
|
||||||
|
MenuItem exportItem = new MenuItem();
|
||||||
|
exportItem.Header = RoleEditor.Resources.ResourceManager.GetString("textExport");
|
||||||
|
exportItem.Icon = new Image { Source = Util.LoadImage(RoleEditor.Resources.floppy_disk_blue) };
|
||||||
|
exportItem.Click += this.exportItem;
|
||||||
|
this.ContextMenu.Items.Add(exportItem);
|
||||||
|
|
||||||
|
MenuItem showTextItem = new MenuItem();
|
||||||
|
showTextItem.Header = RoleEditor.Resources.ResourceManager.GetString("textShowAsText");
|
||||||
|
showTextItem.Icon = new Image { Source = Util.LoadImage(RoleEditor.Resources.document_plain) };
|
||||||
|
showTextItem.Click += this.showTextItem;
|
||||||
|
this.ContextMenu.Items.Add(showTextItem);
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ENIDataGrid_PreviewKeyDown(object sender, KeyEventArgs e)
|
||||||
|
{
|
||||||
|
if(sender is ENIDataGrid)
|
||||||
|
{
|
||||||
|
var grid = sender as ENIDataGrid;
|
||||||
|
if (Key.Delete == e.Key)
|
||||||
|
this.deleteItem(null, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#region public
|
||||||
|
|
||||||
|
public DataGridRow GetRow(int index)
|
||||||
|
{
|
||||||
|
DataGridRow row = (DataGridRow)this.ItemContainerGenerator.ContainerFromIndex(index);
|
||||||
|
if(row == null)
|
||||||
|
{
|
||||||
|
this.UpdateLayout();
|
||||||
|
this.ScrollIntoView(this.Items[index]);
|
||||||
|
row = (DataGridRow)this.ItemContainerGenerator.ContainerFromIndex(index);
|
||||||
|
}
|
||||||
|
return row;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DataGridCell? GetCell(DataGridRow row, int column)
|
||||||
|
{
|
||||||
|
if (row != null)
|
||||||
|
{
|
||||||
|
DataGridCellsPresenter? presenter = GetVisualChild<DataGridCellsPresenter>(row);
|
||||||
|
|
||||||
|
if (presenter == null)
|
||||||
|
{
|
||||||
|
this.ScrollIntoView(row, this.Columns[column]);
|
||||||
|
presenter = GetVisualChild<DataGridCellsPresenter>(row);
|
||||||
|
}
|
||||||
|
|
||||||
|
DataGridCell? cell = (DataGridCell?)presenter?.ItemContainerGenerator.ContainerFromIndex(column);
|
||||||
|
return cell;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DataGridCell? GetCell(int rowIndex, int columnIndex)
|
||||||
|
{
|
||||||
|
DataGridRow row = this.GetRow(rowIndex);
|
||||||
|
return this.GetCell(row, columnIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region protected
|
||||||
|
|
||||||
|
protected void addItem(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-us");
|
||||||
|
if (!this.IsReadOnly)
|
||||||
|
{
|
||||||
|
this.CreateRequested?.Invoke();
|
||||||
|
}
|
||||||
|
e.Handled = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void deleteItem(object? sender, RoutedEventArgs? e)
|
||||||
|
{
|
||||||
|
if((this.SelectedItems != null) && (this.SelectedItems.Count > 0) && !this.IsReadOnly)
|
||||||
|
{
|
||||||
|
MessageBoxResult result = MessageBox.Show("Are your sure?", "Please confirm", MessageBoxButton.YesNo, MessageBoxImage.Question);
|
||||||
|
if (result == MessageBoxResult.Yes)
|
||||||
|
{
|
||||||
|
List<DbEntity> deleteList = new List<DbEntity>();
|
||||||
|
foreach (DbEntity deleteItem in this.SelectedItems)
|
||||||
|
deleteList.Add(deleteItem);
|
||||||
|
|
||||||
|
foreach (DbEntity deleteItem in deleteList)
|
||||||
|
{
|
||||||
|
if (deleteItem != null)
|
||||||
|
{
|
||||||
|
this.DeleteRequested?.Invoke(deleteItem);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.RefreshGrid?.Invoke();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void editItem(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
if((this.SelectedItems != null) && (this.SelectedItems.Count == 1) && !this.IsReadOnly)
|
||||||
|
{
|
||||||
|
if (this.SelectedItems[0] is DbEntity selectedEntity)
|
||||||
|
this.EditRequested?.Invoke(selectedEntity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void printItem(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
if ((this.SelectedItems != null) && (this.SelectedItems.Count == 1) )
|
||||||
|
{
|
||||||
|
if (this.SelectedItems[0] is DbEntity selectedEntity)
|
||||||
|
this.PrintRequested?.Invoke(selectedEntity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void exportItem(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
if ((this.SelectedItems != null) && (this.SelectedItems.Count == 1))
|
||||||
|
{
|
||||||
|
if (this.SelectedItems[0] is DbEntity selectedEntity)
|
||||||
|
this.ExportRequested?.Invoke(selectedEntity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void showTextItem(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
if ((this.SelectedItems != null) && (this.SelectedItems.Count == 1))
|
||||||
|
{
|
||||||
|
if (this.SelectedItems[0] is DbEntity selectedEntity)
|
||||||
|
this.ShowTextRequested?.Invoke(selectedEntity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region private
|
||||||
|
|
||||||
|
private void dataGrid_MouseDoubleClick(object sender, MouseButtonEventArgs e)
|
||||||
|
{
|
||||||
|
if (sender != null)
|
||||||
|
{
|
||||||
|
if ((sender is DataGrid grid) && (grid.SelectedItems != null) && (grid.SelectedItems.Count == 1) && !this.IsReadOnly)
|
||||||
|
{
|
||||||
|
DataGridRow? dgr = grid.ItemContainerGenerator.ContainerFromItem(grid.SelectedItem) as DataGridRow;
|
||||||
|
if (grid.SelectedItem is DbEntity selectedEntity)
|
||||||
|
this.EditRequested?.Invoke(selectedEntity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region private static
|
||||||
|
|
||||||
|
private static T? GetVisualChild<T>(Visual parent) where T : Visual
|
||||||
|
{
|
||||||
|
T? child = default;
|
||||||
|
int numVisuals = VisualTreeHelper.GetChildrenCount(parent);
|
||||||
|
for (int i = 0; i < numVisuals; i++)
|
||||||
|
{
|
||||||
|
Visual? v = (Visual)VisualTreeHelper.GetChild(parent, i);
|
||||||
|
child = v as T;
|
||||||
|
if (child == null)
|
||||||
|
{
|
||||||
|
child = GetVisualChild<T>(v);
|
||||||
|
}
|
||||||
|
if (child != null)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return child;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
32
src/RoleEditor/EditBerthDialog.xaml
Normal file
32
src/RoleEditor/EditBerthDialog.xaml
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
<Window x:Class="RoleEditor.EditBerthDialog"
|
||||||
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
|
xmlns:local="clr-namespace:RoleEditor"
|
||||||
|
mc:Ignorable="d"
|
||||||
|
Title="Edit berth" Height="150" Width="450" Loaded="Window_Loaded">
|
||||||
|
<Grid x:Name="berthGrid">
|
||||||
|
<Grid.ColumnDefinitions>
|
||||||
|
<ColumnDefinition Width=".3*" />
|
||||||
|
<ColumnDefinition Width=".6*" />
|
||||||
|
</Grid.ColumnDefinitions>
|
||||||
|
<Grid.RowDefinitions>
|
||||||
|
<RowDefinition Height="28" />
|
||||||
|
<RowDefinition Height="28" />
|
||||||
|
<RowDefinition Height="28" />
|
||||||
|
<RowDefinition Height="*" />
|
||||||
|
<RowDefinition Height="28" />
|
||||||
|
</Grid.RowDefinitions>
|
||||||
|
<Label Content="Name" HorizontalAlignment="Right" />
|
||||||
|
<TextBox x:Name="textBoxName" Grid.Column="1" Margin="2" VerticalContentAlignment="Center" Text="{Binding Name}" />
|
||||||
|
<Label Content="Participant / Terminal" HorizontalAlignment="Right" Grid.Row="1" />
|
||||||
|
<ComboBox x:Name="comboBoxParticipants" Grid.Row="1" Grid.Column="1" Margin="2" SelectedItem="{Binding Participant}" />
|
||||||
|
<Label Content="Uses lock" HorizontalAlignment="Right" Grid.Row="2" />
|
||||||
|
<CheckBox x:Name="checkBoxLock" Grid.Row="2" Grid.Column="1" VerticalAlignment="Center" Margin="2" IsChecked="{Binding Path=Lock, Mode=TwoWay}"/>
|
||||||
|
<StackPanel Grid.Column="1" Grid.Row="4" 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>
|
||||||
|
</Grid>
|
||||||
|
</Window>
|
||||||
52
src/RoleEditor/EditBerthDialog.xaml.cs
Normal file
52
src/RoleEditor/EditBerthDialog.xaml.cs
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
using brecal.model;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows;
|
||||||
|
using System.Windows.Controls;
|
||||||
|
using System.Windows.Data;
|
||||||
|
using System.Windows.Documents;
|
||||||
|
using System.Windows.Input;
|
||||||
|
using System.Windows.Media;
|
||||||
|
using System.Windows.Media.Imaging;
|
||||||
|
using System.Windows.Shapes;
|
||||||
|
|
||||||
|
namespace RoleEditor
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Interaction logic for EditBerthDialog.xaml
|
||||||
|
/// </summary>
|
||||||
|
public partial class EditBerthDialog : Window
|
||||||
|
{
|
||||||
|
public EditBerthDialog()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Berth Berth { get; set; } = new Berth();
|
||||||
|
|
||||||
|
private void buttonCancel_Click(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
this.DialogResult = false;
|
||||||
|
this.Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void buttonOK_Click(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
this.Berth.Name = this.textBoxName.Text.Trim();
|
||||||
|
this.Berth.Lock = this.checkBoxLock.IsChecked;
|
||||||
|
this.Berth.Participant = this.comboBoxParticipants.SelectedItem as Participant;
|
||||||
|
if(this.Berth.Participant != null)
|
||||||
|
this.Berth.Participant_Id = this.Berth.Participant.Id;
|
||||||
|
this.DialogResult = true;
|
||||||
|
this.Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Window_Loaded(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
this.DataContext = this.Berth;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
12
src/RoleEditor/EditShipDialog.xaml
Normal file
12
src/RoleEditor/EditShipDialog.xaml
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
<Window x:Class="RoleEditor.EditShipDialog"
|
||||||
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
|
xmlns:local="clr-namespace:RoleEditor"
|
||||||
|
mc:Ignorable="d"
|
||||||
|
Title="Edit ship" Height="450" Width="800">
|
||||||
|
<Grid>
|
||||||
|
|
||||||
|
</Grid>
|
||||||
|
</Window>
|
||||||
27
src/RoleEditor/EditShipDialog.xaml.cs
Normal file
27
src/RoleEditor/EditShipDialog.xaml.cs
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows;
|
||||||
|
using System.Windows.Controls;
|
||||||
|
using System.Windows.Data;
|
||||||
|
using System.Windows.Documents;
|
||||||
|
using System.Windows.Input;
|
||||||
|
using System.Windows.Media;
|
||||||
|
using System.Windows.Media.Imaging;
|
||||||
|
using System.Windows.Shapes;
|
||||||
|
|
||||||
|
namespace RoleEditor
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Interaction logic for EditShipDialog.xaml
|
||||||
|
/// </summary>
|
||||||
|
public partial class EditShipDialog : Window
|
||||||
|
{
|
||||||
|
public EditShipDialog()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -6,6 +6,9 @@
|
|||||||
xmlns:local="clr-namespace:RoleEditor"
|
xmlns:local="clr-namespace:RoleEditor"
|
||||||
mc:Ignorable="d"
|
mc:Ignorable="d"
|
||||||
Title="Bremen calling admin editor" Height="600" Width="800" Icon="Resources/lock_preferences.ico" Loaded="Window_Loaded">
|
Title="Bremen calling admin editor" Height="600" Width="800" Icon="Resources/lock_preferences.ico" Loaded="Window_Loaded">
|
||||||
|
<Grid>
|
||||||
|
<TabControl>
|
||||||
|
<TabItem Header="Participant, users and roles">
|
||||||
<Grid>
|
<Grid>
|
||||||
<Grid.RowDefinitions>
|
<Grid.RowDefinitions>
|
||||||
<RowDefinition Height=".5*" />
|
<RowDefinition Height=".5*" />
|
||||||
@ -235,4 +238,47 @@
|
|||||||
</Grid>
|
</Grid>
|
||||||
</GroupBox>
|
</GroupBox>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
</TabItem>
|
||||||
|
<TabItem Header="Berths">
|
||||||
|
<Grid>
|
||||||
|
<Grid.RowDefinitions>
|
||||||
|
<RowDefinition Height="28" />
|
||||||
|
<RowDefinition Height="*" />
|
||||||
|
</Grid.RowDefinitions>
|
||||||
|
<Button Content="Import excel" Margin="2" x:Name="buttonImportBerths" Click="buttonImportBerths_Click" Width="100" HorizontalAlignment="Left" Grid.Row="0"/>
|
||||||
|
<local:ENIDataGrid x:Name="dataGridBerths" Grid.Row="1" SelectionMode="Single" IsReadOnly="True" AlternatingRowBackground="LightBlue" AutoGenerateColumns="False"
|
||||||
|
CanUserAddRows="False" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch">
|
||||||
|
<DataGrid.Columns>
|
||||||
|
<DataGridTextColumn Header="Id" Binding="{Binding Path=Id}" />
|
||||||
|
<DataGridTextColumn Header="Name" Binding="{Binding Path=Name}" />
|
||||||
|
<DataGridCheckBoxColumn Header="Lock" Binding="{Binding Path=Lock}" />
|
||||||
|
<DataGridTextColumn Header="Terminal" Binding="{Binding Path=Terminal}" />
|
||||||
|
</DataGrid.Columns>
|
||||||
|
</local:ENIDataGrid>
|
||||||
|
</Grid>
|
||||||
|
</TabItem>
|
||||||
|
<TabItem Header="Ships">
|
||||||
|
<Grid>
|
||||||
|
<Grid.RowDefinitions>
|
||||||
|
<RowDefinition Height="28" />
|
||||||
|
<RowDefinition Height="*" />
|
||||||
|
</Grid.RowDefinitions>
|
||||||
|
<Button Content="Import excel" Margin="2" x:Name="buttonImportShipss" Click="buttonImportShipss_Click" Width="100" HorizontalAlignment="Left" Grid.Row="0"/>
|
||||||
|
<local:ENIDataGrid x:Name="dataGridShips" Grid.Row="1" SelectionMode="Single" IsReadOnly="True" AlternatingRowBackground="LightBlue" AutoGenerateColumns="False"
|
||||||
|
CanUserAddRows="False" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch">
|
||||||
|
<DataGrid.Columns>
|
||||||
|
<DataGridTextColumn Header="Id" Binding="{Binding Path=Id}" />
|
||||||
|
<DataGridTextColumn Header="Name" Binding="{Binding Path=Name}" />
|
||||||
|
<DataGridCheckBoxColumn Header="Tug" Binding="{Binding Path=IsTug}" />
|
||||||
|
<DataGridTextColumn Header="Tug company" Binding="{Binding Path=TugCompany}" />
|
||||||
|
<DataGridTextColumn Header="IMO" Binding="{Binding Path=Name}" />
|
||||||
|
<DataGridTextColumn Header="Callsign" Binding="{Binding Path=Name}" />
|
||||||
|
<DataGridTextColumn Header="Length" Binding="{Binding Path=Name}" />
|
||||||
|
<DataGridTextColumn Header="Width" Binding="{Binding Path=Name}" />
|
||||||
|
</DataGrid.Columns>
|
||||||
|
</local:ENIDataGrid>
|
||||||
|
</Grid>
|
||||||
|
</TabItem>
|
||||||
|
</TabControl>
|
||||||
|
</Grid>
|
||||||
</Window>
|
</Window>
|
||||||
|
|||||||
@ -1,11 +1,17 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
|
using System.Globalization;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
using System.Security.Cryptography;
|
using System.Security.Cryptography;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using System.Threading;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Controls;
|
using System.Windows.Controls;
|
||||||
|
using System.Windows.Media.Animation;
|
||||||
|
using System.Windows.Media.Imaging;
|
||||||
using brecal.model;
|
using brecal.model;
|
||||||
using brecal.mysql;
|
using brecal.mysql;
|
||||||
|
|
||||||
@ -24,6 +30,8 @@ namespace RoleEditor
|
|||||||
private readonly ObservableCollection<User> _users = new ObservableCollection<User>();
|
private readonly ObservableCollection<User> _users = new ObservableCollection<User>();
|
||||||
private readonly ObservableCollection<RoleAssignment> _assignedRoles = new ObservableCollection<RoleAssignment>();
|
private readonly ObservableCollection<RoleAssignment> _assignedRoles = new ObservableCollection<RoleAssignment>();
|
||||||
private readonly ObservableCollection<SecurableAssignment> _assignedSecurables = new ObservableCollection<SecurableAssignment>();
|
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 DBManager _dbManager;
|
private DBManager _dbManager;
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
@ -38,11 +46,13 @@ namespace RoleEditor
|
|||||||
|
|
||||||
private async void Window_Loaded(object sender, RoutedEventArgs e)
|
private async void Window_Loaded(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
|
|
||||||
// try database connection
|
// try database connection
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// load all participants
|
// load all participants
|
||||||
foreach(Participant p in await Participant.LoadAll(_dbManager))
|
List<Participant> participants = await Participant.LoadAll(_dbManager);
|
||||||
|
foreach(Participant p in participants)
|
||||||
_participants.Add(p);
|
_participants.Add(p);
|
||||||
this.listBoxParticipant.ItemsSource = _participants;
|
this.listBoxParticipant.ItemsSource = _participants;
|
||||||
|
|
||||||
@ -56,6 +66,39 @@ namespace RoleEditor
|
|||||||
_securables.Add(s);
|
_securables.Add(s);
|
||||||
this.listBoxSecurables.ItemsSource = _securables;
|
this.listBoxSecurables.ItemsSource = _securables;
|
||||||
|
|
||||||
|
// load all berths
|
||||||
|
foreach (Berth b in await Berth.LoadAll(_dbManager))
|
||||||
|
{
|
||||||
|
_berths.Add(b);
|
||||||
|
if(b.Participant_Id != null)
|
||||||
|
{
|
||||||
|
b.Participant = participants.Where( p => p.Id== b.Participant_Id ).FirstOrDefault();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.dataGridBerths.Initialize();
|
||||||
|
this.dataGridBerths.ItemsSource = _berths;
|
||||||
|
|
||||||
|
this.dataGridBerths.CreateRequested += DataGridBerths_CreateRequested;
|
||||||
|
this.dataGridBerths.EditRequested += DataGridBerths_EditRequested;
|
||||||
|
this.dataGridBerths.DeleteRequested += DataGridBerths_DeleteRequested;
|
||||||
|
|
||||||
|
|
||||||
|
// load all ships
|
||||||
|
foreach (Ship s in await Ship.LoadAll(_dbManager))
|
||||||
|
{
|
||||||
|
_ships.Add(s);
|
||||||
|
if(s.Participant_Id != null)
|
||||||
|
{
|
||||||
|
s.Participant = participants.Where( p => p.Id == s.Participant_Id ).FirstOrDefault();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.dataGridShips.Initialize();
|
||||||
|
this.dataGridShips.ItemsSource = _ships;
|
||||||
|
|
||||||
|
this.dataGridShips.CreateRequested += DataGridShips_CreateRequested;
|
||||||
|
this.dataGridShips.EditRequested += DataGridShips_EditRequested;
|
||||||
|
this.dataGridShips.DeleteRequested += DataGridShips_DeleteRequested;
|
||||||
|
|
||||||
// set other item sources (filled later after selection)
|
// set other item sources (filled later after selection)
|
||||||
this.listBoxUser.ItemsSource = _users;
|
this.listBoxUser.ItemsSource = _users;
|
||||||
this.listBoxRoleSecurables.ItemsSource = _assignedSecurables;
|
this.listBoxRoleSecurables.ItemsSource = _assignedSecurables;
|
||||||
@ -68,6 +111,62 @@ namespace RoleEditor
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#region ship context menu callbacks
|
||||||
|
|
||||||
|
private void DataGridShips_DeleteRequested(DbEntity obj)
|
||||||
|
{
|
||||||
|
if(obj is Ship s)
|
||||||
|
this._ships.Remove(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void DataGridShips_EditRequested(DbEntity obj)
|
||||||
|
{
|
||||||
|
if(obj is Ship s)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void DataGridShips_CreateRequested()
|
||||||
|
{
|
||||||
|
Ship s = new Ship();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region berth context menu callbacks
|
||||||
|
|
||||||
|
private void DataGridBerths_DeleteRequested(DbEntity obj)
|
||||||
|
{
|
||||||
|
if(obj is Berth b)
|
||||||
|
this._berths.Remove(b);
|
||||||
|
}
|
||||||
|
|
||||||
|
private async void DataGridBerths_EditRequested(DbEntity obj)
|
||||||
|
{
|
||||||
|
if(obj is Berth b)
|
||||||
|
{
|
||||||
|
EditBerthDialog ebd = new EditBerthDialog();
|
||||||
|
ebd.Berth = b;
|
||||||
|
if (ebd.ShowDialog() ?? false)
|
||||||
|
await b.Save(_dbManager);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async void DataGridBerths_CreateRequested()
|
||||||
|
{
|
||||||
|
Berth b = new Berth();
|
||||||
|
EditBerthDialog ebd = new EditBerthDialog();
|
||||||
|
ebd.Berth = b;
|
||||||
|
if(ebd.ShowDialog() ?? false)
|
||||||
|
{
|
||||||
|
_berths.Add(b);
|
||||||
|
await b.Save(_dbManager);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region button callbacks
|
#region button callbacks
|
||||||
@ -409,5 +508,41 @@ namespace RoleEditor
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region Excel import
|
||||||
|
|
||||||
|
private void buttonImportBerths_Click(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void buttonImportShipss_Click(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region private static helper
|
||||||
|
|
||||||
|
private static BitmapImage? LoadImage(byte[] imageData)
|
||||||
|
{
|
||||||
|
if (imageData == null || imageData.Length == 0) return null;
|
||||||
|
var image = new BitmapImage();
|
||||||
|
using (var mem = new MemoryStream(imageData))
|
||||||
|
{
|
||||||
|
mem.Position = 0;
|
||||||
|
image.BeginInit();
|
||||||
|
image.CreateOptions = BitmapCreateOptions.PreservePixelFormat;
|
||||||
|
image.CacheOption = BitmapCacheOption.OnLoad;
|
||||||
|
image.UriSource = null;
|
||||||
|
image.StreamSource = mem;
|
||||||
|
image.EndInit();
|
||||||
|
}
|
||||||
|
image.Freeze();
|
||||||
|
return image;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
104
src/RoleEditor/Resources.Designer.cs
generated
104
src/RoleEditor/Resources.Designer.cs
generated
@ -100,6 +100,16 @@ namespace RoleEditor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized resource of type System.Byte[].
|
||||||
|
/// </summary>
|
||||||
|
internal static byte[] delete {
|
||||||
|
get {
|
||||||
|
object obj = ResourceManager.GetObject("delete", resourceCulture);
|
||||||
|
return ((byte[])(obj));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Looks up a localized resource of type System.Byte[].
|
/// Looks up a localized resource of type System.Byte[].
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -120,6 +130,36 @@ namespace RoleEditor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized resource of type System.Byte[].
|
||||||
|
/// </summary>
|
||||||
|
internal static byte[] document_plain {
|
||||||
|
get {
|
||||||
|
object obj = ResourceManager.GetObject("document_plain", resourceCulture);
|
||||||
|
return ((byte[])(obj));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized resource of type System.Byte[].
|
||||||
|
/// </summary>
|
||||||
|
internal static byte[] edit {
|
||||||
|
get {
|
||||||
|
object obj = ResourceManager.GetObject("edit", resourceCulture);
|
||||||
|
return ((byte[])(obj));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized resource of type System.Byte[].
|
||||||
|
/// </summary>
|
||||||
|
internal static byte[] floppy_disk_blue {
|
||||||
|
get {
|
||||||
|
object obj = ResourceManager.GetObject("floppy_disk_blue", resourceCulture);
|
||||||
|
return ((byte[])(obj));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Looks up a localized resource of type System.Byte[].
|
/// Looks up a localized resource of type System.Byte[].
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -160,6 +200,16 @@ namespace RoleEditor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized resource of type System.Byte[].
|
||||||
|
/// </summary>
|
||||||
|
internal static byte[] printer {
|
||||||
|
get {
|
||||||
|
object obj = ResourceManager.GetObject("printer", resourceCulture);
|
||||||
|
return ((byte[])(obj));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Looks up a localized resource of type System.Byte[].
|
/// Looks up a localized resource of type System.Byte[].
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -169,5 +219,59 @@ namespace RoleEditor {
|
|||||||
return ((byte[])(obj));
|
return ((byte[])(obj));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string similar to Add.
|
||||||
|
/// </summary>
|
||||||
|
internal static string textAdd {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("textAdd", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string similar to Delete.
|
||||||
|
/// </summary>
|
||||||
|
internal static string textDelete {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("textDelete", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string similar to Edit.
|
||||||
|
/// </summary>
|
||||||
|
internal static string textEdit {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("textEdit", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string similar to Export.
|
||||||
|
/// </summary>
|
||||||
|
internal static string textExport {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("textExport", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string similar to Print.
|
||||||
|
/// </summary>
|
||||||
|
internal static string textPrint {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("textPrint", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string similar to _Show as text.
|
||||||
|
/// </summary>
|
||||||
|
internal static string textShowAsText {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("textShowAsText", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -130,12 +130,24 @@
|
|||||||
<data name="businessman" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
<data name="businessman" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||||
<value>Resources\businessman.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
<value>Resources\businessman.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="delete" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||||
|
<value>Resources\delete.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</data>
|
||||||
<data name="delete2" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
<data name="delete2" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||||
<value>Resources\delete2.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
<value>Resources\delete2.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="disk_blue" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
<data name="disk_blue" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||||
<value>Resources\disk_blue.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
<value>Resources\disk_blue.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="document_plain" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||||
|
<value>Resources\document_plain.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</data>
|
||||||
|
<data name="edit" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||||
|
<value>Resources\edit.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</data>
|
||||||
|
<data name="floppy_disk_blue" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||||
|
<value>Resources\floppy_disk_blue.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</data>
|
||||||
<data name="id_card" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
<data name="id_card" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||||
<value>Resources\id_card.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
<value>Resources\id_card.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
</data>
|
</data>
|
||||||
@ -148,7 +160,28 @@
|
|||||||
<data name="lock_preferences" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
<data name="lock_preferences" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||||
<value>Resources\lock_preferences.ico;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
<value>Resources\lock_preferences.ico;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="printer" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||||
|
<value>Resources\printer.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</data>
|
||||||
<data name="safe" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
<data name="safe" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||||
<value>Resources\safe.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
<value>Resources\safe.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="textAdd" xml:space="preserve">
|
||||||
|
<value>Add</value>
|
||||||
|
</data>
|
||||||
|
<data name="textDelete" xml:space="preserve">
|
||||||
|
<value>Delete</value>
|
||||||
|
</data>
|
||||||
|
<data name="textEdit" xml:space="preserve">
|
||||||
|
<value>Edit</value>
|
||||||
|
</data>
|
||||||
|
<data name="textExport" xml:space="preserve">
|
||||||
|
<value>Export</value>
|
||||||
|
</data>
|
||||||
|
<data name="textPrint" xml:space="preserve">
|
||||||
|
<value>Print</value>
|
||||||
|
</data>
|
||||||
|
<data name="textShowAsText" xml:space="preserve">
|
||||||
|
<value>_Show as text</value>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
||||||
BIN
src/RoleEditor/Resources/delete.png
Normal file
BIN
src/RoleEditor/Resources/delete.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.2 KiB |
BIN
src/RoleEditor/Resources/document_plain.png
Normal file
BIN
src/RoleEditor/Resources/document_plain.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 674 B |
BIN
src/RoleEditor/Resources/edit.png
Normal file
BIN
src/RoleEditor/Resources/edit.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.6 KiB |
BIN
src/RoleEditor/Resources/floppy_disk_blue.png
Normal file
BIN
src/RoleEditor/Resources/floppy_disk_blue.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.1 KiB |
BIN
src/RoleEditor/Resources/printer.png
Normal file
BIN
src/RoleEditor/Resources/printer.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.6 KiB |
@ -13,11 +13,16 @@
|
|||||||
<None Remove="Resources\add.png" />
|
<None Remove="Resources\add.png" />
|
||||||
<None Remove="Resources\arrow_left_green.png" />
|
<None Remove="Resources\arrow_left_green.png" />
|
||||||
<None Remove="Resources\businessman.png" />
|
<None Remove="Resources\businessman.png" />
|
||||||
|
<None Remove="Resources\delete.png" />
|
||||||
<None Remove="Resources\delete2.png" />
|
<None Remove="Resources\delete2.png" />
|
||||||
<None Remove="Resources\disk_blue.png" />
|
<None Remove="Resources\disk_blue.png" />
|
||||||
|
<None Remove="Resources\document_plain.png" />
|
||||||
|
<None Remove="Resources\edit.png" />
|
||||||
|
<None Remove="Resources\floppy_disk_blue.png" />
|
||||||
<None Remove="Resources\id_card.png" />
|
<None Remove="Resources\id_card.png" />
|
||||||
<None Remove="Resources\key1.png" />
|
<None Remove="Resources\key1.png" />
|
||||||
<None Remove="Resources\key1_add.png" />
|
<None Remove="Resources\key1_add.png" />
|
||||||
|
<None Remove="Resources\printer.png" />
|
||||||
<None Remove="Resources\safe.png" />
|
<None Remove="Resources\safe.png" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
@ -35,11 +40,16 @@
|
|||||||
<Resource Include="Resources\add.png" />
|
<Resource Include="Resources\add.png" />
|
||||||
<Resource Include="Resources\arrow_left_green.png" />
|
<Resource Include="Resources\arrow_left_green.png" />
|
||||||
<Resource Include="Resources\businessman.png" />
|
<Resource Include="Resources\businessman.png" />
|
||||||
|
<Resource Include="Resources\delete.png" />
|
||||||
<Resource Include="Resources\delete2.png" />
|
<Resource Include="Resources\delete2.png" />
|
||||||
<Resource Include="Resources\disk_blue.png" />
|
<Resource Include="Resources\disk_blue.png" />
|
||||||
|
<Resource Include="Resources\document_plain.png" />
|
||||||
|
<Resource Include="Resources\edit.png" />
|
||||||
|
<Resource Include="Resources\floppy_disk_blue.png" />
|
||||||
<Resource Include="Resources\id_card.png" />
|
<Resource Include="Resources\id_card.png" />
|
||||||
<Resource Include="Resources\key1.png" />
|
<Resource Include="Resources\key1.png" />
|
||||||
<Resource Include="Resources\key1_add.png" />
|
<Resource Include="Resources\key1_add.png" />
|
||||||
|
<Resource Include="Resources\printer.png" />
|
||||||
<Resource Include="Resources\safe.png" />
|
<Resource Include="Resources\safe.png" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|||||||
31
src/RoleEditor/Util.cs
Normal file
31
src/RoleEditor/Util.cs
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows.Media.Imaging;
|
||||||
|
|
||||||
|
namespace RoleEditor
|
||||||
|
{
|
||||||
|
public static class Util
|
||||||
|
{
|
||||||
|
public static BitmapImage? LoadImage (byte[] imageData)
|
||||||
|
{
|
||||||
|
if (imageData == null || imageData.Length == 0) return null;
|
||||||
|
var image = new BitmapImage();
|
||||||
|
using (var mem = new MemoryStream(imageData))
|
||||||
|
{
|
||||||
|
mem.Position = 0;
|
||||||
|
image.BeginInit();
|
||||||
|
image.CreateOptions = BitmapCreateOptions.PreservePixelFormat;
|
||||||
|
image.CacheOption = BitmapCacheOption.OnLoad;
|
||||||
|
image.UriSource = null;
|
||||||
|
image.StreamSource = mem;
|
||||||
|
image.EndInit();
|
||||||
|
}
|
||||||
|
image.Freeze();
|
||||||
|
return image;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
116
src/brecal.model/Berth.cs
Normal file
116
src/brecal.model/Berth.cs
Normal file
@ -0,0 +1,116 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Data;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace brecal.model
|
||||||
|
{
|
||||||
|
public class Berth : DbEntity
|
||||||
|
{
|
||||||
|
|
||||||
|
#region Properties
|
||||||
|
|
||||||
|
public string? Name { get; set; }
|
||||||
|
|
||||||
|
public bool? Lock { get; set; }
|
||||||
|
|
||||||
|
public uint? Participant_Id { get; set; }
|
||||||
|
|
||||||
|
public Participant? Participant { get; set; }
|
||||||
|
|
||||||
|
public string? Terminal { get { if (Participant != null) return Participant.Name; else return "n/a"; } }
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region public static methods
|
||||||
|
|
||||||
|
public static async Task<List<Berth>> LoadAll(IDBManager manager)
|
||||||
|
{
|
||||||
|
List<DbEntity> loadResultList = await manager.Load(SetLoadQuery, LoadElems);
|
||||||
|
List<Berth> result = new();
|
||||||
|
foreach (Berth b in loadResultList.Cast<Berth>())
|
||||||
|
result.Add(b);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void SetLoadQuery(IDbCommand cmd, params object?[] list)
|
||||||
|
{
|
||||||
|
cmd.CommandText = "SELECT id, name, participant_id, `lock`, created, modified FROM berth";
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<DbEntity> LoadElems(IDataReader reader)
|
||||||
|
{
|
||||||
|
List<DbEntity> result = new List<DbEntity>();
|
||||||
|
while (reader.Read())
|
||||||
|
{
|
||||||
|
Berth b = new();
|
||||||
|
b.Id = (uint)reader.GetInt32(0);
|
||||||
|
if (!reader.IsDBNull(1)) b.Name = reader.GetString(1);
|
||||||
|
if (!reader.IsDBNull(2)) b.Participant_Id = (uint) reader.GetInt32(2);
|
||||||
|
if (!reader.IsDBNull(3)) b.Lock = reader.GetBoolean(3);
|
||||||
|
if (!reader.IsDBNull(4)) b.Created = reader.GetDateTime(4);
|
||||||
|
if (!reader.IsDBNull(5)) b.Modified = reader.GetDateTime(5);
|
||||||
|
result.Add(b);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region DbEntity implementation
|
||||||
|
|
||||||
|
public override void SetCreate(IDbCommand cmd)
|
||||||
|
{
|
||||||
|
cmd.CommandText = "INSERT INTO berth (participant_id, name, `lock`) VALUES ( @PID, @NAME, @LOCK)";
|
||||||
|
this.SetParameters(cmd);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void SetDelete(IDbCommand cmd)
|
||||||
|
{
|
||||||
|
cmd.CommandText = "DELETE FROM berth 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 berth SET name = @NAME, participant_id = @PID, `lock` = @LOCK WHERE id = @ID";
|
||||||
|
this.SetParameters(cmd);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region private methods
|
||||||
|
|
||||||
|
private void SetParameters(IDbCommand cmd)
|
||||||
|
{
|
||||||
|
IDbDataParameter id = cmd.CreateParameter();
|
||||||
|
id.ParameterName = "ID";
|
||||||
|
id.Value = this.Id;
|
||||||
|
cmd.Parameters.Add(id);
|
||||||
|
|
||||||
|
IDbDataParameter pid = cmd.CreateParameter();
|
||||||
|
pid.ParameterName = "PID";
|
||||||
|
pid.Value = this.Participant_Id;
|
||||||
|
cmd.Parameters.Add(pid);
|
||||||
|
|
||||||
|
IDbDataParameter name = cmd.CreateParameter();
|
||||||
|
name.ParameterName = "NAME";
|
||||||
|
name.Value = this.Name;
|
||||||
|
cmd.Parameters.Add(name);
|
||||||
|
|
||||||
|
IDbDataParameter lockparam = cmd.CreateParameter();
|
||||||
|
lockparam.ParameterName = "LOCK";
|
||||||
|
lockparam.Value = this.Lock;
|
||||||
|
cmd.Parameters.Add(lockparam);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -2,6 +2,7 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Data;
|
using System.Data;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Reflection.PortableExecutable;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
@ -9,6 +10,22 @@ namespace brecal.model
|
|||||||
{
|
{
|
||||||
public class Participant : DbEntity
|
public class Participant : DbEntity
|
||||||
{
|
{
|
||||||
|
#region Enumerations
|
||||||
|
|
||||||
|
[Flags]
|
||||||
|
public enum ParticipantType
|
||||||
|
{
|
||||||
|
NONE = 0,
|
||||||
|
BSMD = 1,
|
||||||
|
TERMINAL = 2,
|
||||||
|
PILOT = 4,
|
||||||
|
AGENCY = 8,
|
||||||
|
MOORING = 16,
|
||||||
|
PORT_ADMINISTRATION = 32,
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
#region Properties
|
#region Properties
|
||||||
|
|
||||||
public string? Name { get; set; }
|
public string? Name { get; set; }
|
||||||
@ -132,5 +149,20 @@ namespace brecal.model
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region public type flag funcs
|
||||||
|
|
||||||
|
public bool IsFlagSet(ParticipantType flag)
|
||||||
|
{
|
||||||
|
return (this.Flags & (uint)flag) != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetFlag(bool value, ParticipantType flag)
|
||||||
|
{
|
||||||
|
if (value) this.Flags |= (uint)flag;
|
||||||
|
else this.Flags &= (uint)~flag;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
145
src/brecal.model/Ship.cs
Normal file
145
src/brecal.model/Ship.cs
Normal file
@ -0,0 +1,145 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Data;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace brecal.model
|
||||||
|
{
|
||||||
|
public class Ship : DbEntity
|
||||||
|
{
|
||||||
|
|
||||||
|
#region Properties
|
||||||
|
|
||||||
|
public string? Name { get; set; }
|
||||||
|
|
||||||
|
public int? IMO { get; set; }
|
||||||
|
|
||||||
|
public string? Callsign { get; set; }
|
||||||
|
|
||||||
|
public uint? Participant_Id { get; set; }
|
||||||
|
|
||||||
|
public Participant? Participant { get; set; }
|
||||||
|
|
||||||
|
public double? Length { get; set; }
|
||||||
|
|
||||||
|
public double? Width { get; set; }
|
||||||
|
|
||||||
|
public bool IsTug { get { return Participant_Id != null; } }
|
||||||
|
|
||||||
|
public string? TugCompany
|
||||||
|
{
|
||||||
|
get { if (Participant != null) return Participant.Name; else return ""; }
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region public static methods
|
||||||
|
|
||||||
|
public static async Task<List<Ship>> LoadAll(IDBManager manager)
|
||||||
|
{
|
||||||
|
List<DbEntity> loadResultList = await manager.Load(SetLoadQuery, LoadElems);
|
||||||
|
List<Ship> result = new();
|
||||||
|
foreach (Ship s in loadResultList.Cast<Ship>())
|
||||||
|
result.Add(s);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void SetLoadQuery(IDbCommand cmd, params object?[] list)
|
||||||
|
{
|
||||||
|
cmd.CommandText = "SELECT id, name, imo, callsign, participant_id, length, width, created, modified FROM ship";
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<DbEntity> LoadElems(IDataReader reader)
|
||||||
|
{
|
||||||
|
List<DbEntity> result = new List<DbEntity>();
|
||||||
|
while (reader.Read())
|
||||||
|
{
|
||||||
|
Ship s = new();
|
||||||
|
s.Id = (uint)reader.GetInt32(0);
|
||||||
|
if (!reader.IsDBNull(1)) s.Name = reader.GetString(1);
|
||||||
|
if (!reader.IsDBNull(2)) s.IMO = reader.GetInt32(2);
|
||||||
|
if (!reader.IsDBNull(3)) s.Callsign = reader.GetString(3);
|
||||||
|
if (!reader.IsDBNull(4)) s.Participant_Id = (uint)reader.GetInt32(4);
|
||||||
|
if (!reader.IsDBNull(5)) s.Length = reader.GetFloat(5);
|
||||||
|
if (!reader.IsDBNull(6)) s.Width = reader.GetFloat(6);
|
||||||
|
if (!reader.IsDBNull(7)) s.Created = reader.GetDateTime(7);
|
||||||
|
if (!reader.IsDBNull(8)) s.Modified = reader.GetDateTime(8);
|
||||||
|
result.Add(s);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region DbEntity implementation
|
||||||
|
|
||||||
|
public override void SetCreate(IDbCommand cmd)
|
||||||
|
{
|
||||||
|
cmd.CommandText = "INSERT INTO ship (name, imo, callsign, participant_id, length, width) VALUES ( @NAME, @IMO, @CALLSIGN, @PID, @LENGTH, @WIDTH)";
|
||||||
|
this.SetParameters(cmd);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void SetDelete(IDbCommand cmd)
|
||||||
|
{
|
||||||
|
cmd.CommandText = "DELETE FROM ship 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 ship SET name = @NAME, imo = @IMO, callsign = @CALLSIGN, participant_id = @PID, length = @LENGTH, widht = @WIDTH WHERE id = @ID";
|
||||||
|
this.SetParameters(cmd);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region private methods
|
||||||
|
|
||||||
|
private void SetParameters(IDbCommand cmd)
|
||||||
|
{
|
||||||
|
IDbDataParameter id = cmd.CreateParameter();
|
||||||
|
id.ParameterName = "ID";
|
||||||
|
id.Value = this.Id;
|
||||||
|
cmd.Parameters.Add(id);
|
||||||
|
|
||||||
|
IDbDataParameter pid = cmd.CreateParameter();
|
||||||
|
pid.ParameterName = "PID";
|
||||||
|
pid.Value = this.Participant_Id;
|
||||||
|
cmd.Parameters.Add(pid);
|
||||||
|
|
||||||
|
IDbDataParameter name = cmd.CreateParameter();
|
||||||
|
name.ParameterName = "NAME";
|
||||||
|
name.Value = this.Name;
|
||||||
|
cmd.Parameters.Add(name);
|
||||||
|
|
||||||
|
IDbDataParameter imoparam = cmd.CreateParameter();
|
||||||
|
imoparam.ParameterName = "IMO";
|
||||||
|
imoparam.Value = this.IMO;
|
||||||
|
cmd.Parameters.Add(imoparam);
|
||||||
|
|
||||||
|
IDataParameter callsign = cmd.CreateParameter();
|
||||||
|
callsign.ParameterName = "CALLSIGN";
|
||||||
|
callsign.Value = this.Callsign;
|
||||||
|
cmd.Parameters.Add(callsign);
|
||||||
|
|
||||||
|
IDataParameter length = cmd.CreateParameter();
|
||||||
|
length.ParameterName = "LENGTH";
|
||||||
|
length.Value = this.Length;
|
||||||
|
cmd.Parameters.Add(length);
|
||||||
|
|
||||||
|
IDataParameter width = cmd.CreateParameter();
|
||||||
|
width.ParameterName = "WIDTH";
|
||||||
|
width.Value = this.Width;
|
||||||
|
cmd.Parameters.Add(width);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -9,7 +9,7 @@ namespace brecal.mysql
|
|||||||
public class DBManager : IDBManager
|
public class DBManager : IDBManager
|
||||||
{
|
{
|
||||||
// TODO: remove this and use external configuration
|
// TODO: remove this and use external configuration
|
||||||
private static readonly string _connectionString = "Server=localhost;User ID=ds;Password=HalloWach23;Database=bremen_calling";
|
private static readonly string _connectionString = "Server=lager;User ID=ds;Password=HalloWach23;Database=bremen_calling";
|
||||||
|
|
||||||
public async Task<List<DbEntity>> Load(QueryFunc prepareAction, LoadFunc<IDataReader> loadAction, params object?[] args)
|
public async Task<List<DbEntity>> Load(QueryFunc prepareAction, LoadFunc<IDataReader> loadAction, params object?[] args)
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user