diff --git a/src/RoleEditor/ENIDataGrid.cs b/src/RoleEditor/ENIDataGrid.cs
new file mode 100644
index 0000000..3d670e0
--- /dev/null
+++ b/src/RoleEditor/ENIDataGrid.cs
@@ -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
+{
+ ///
+ /// 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.
+ ///
+ ///
+ ///
+ ///
+ 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? EditRequested;
+ public event Action? DeleteRequested;
+ public event Action? CreateRequested;
+ public event Action? RefreshGrid;
+
+ public event Action? PrintRequested;
+ public event Action? ExportRequested;
+ public event Action? 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(row);
+
+ if (presenter == null)
+ {
+ this.ScrollIntoView(row, this.Columns[column]);
+ presenter = GetVisualChild(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 deleteList = new List();
+ 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(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(v);
+ }
+ if (child != null)
+ {
+ break;
+ }
+ }
+ return child;
+ }
+
+ #endregion
+
+ }
+}
diff --git a/src/RoleEditor/EditBerthDialog.xaml b/src/RoleEditor/EditBerthDialog.xaml
new file mode 100644
index 0000000..d143baf
--- /dev/null
+++ b/src/RoleEditor/EditBerthDialog.xaml
@@ -0,0 +1,32 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/RoleEditor/EditBerthDialog.xaml.cs b/src/RoleEditor/EditBerthDialog.xaml.cs
new file mode 100644
index 0000000..a8648aa
--- /dev/null
+++ b/src/RoleEditor/EditBerthDialog.xaml.cs
@@ -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
+{
+ ///
+ /// Interaction logic for EditBerthDialog.xaml
+ ///
+ 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;
+ }
+ }
+}
diff --git a/src/RoleEditor/EditShipDialog.xaml b/src/RoleEditor/EditShipDialog.xaml
new file mode 100644
index 0000000..b389a7a
--- /dev/null
+++ b/src/RoleEditor/EditShipDialog.xaml
@@ -0,0 +1,12 @@
+
+
+
+
+
diff --git a/src/RoleEditor/EditShipDialog.xaml.cs b/src/RoleEditor/EditShipDialog.xaml.cs
new file mode 100644
index 0000000..f018e6e
--- /dev/null
+++ b/src/RoleEditor/EditShipDialog.xaml.cs
@@ -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
+{
+ ///
+ /// Interaction logic for EditShipDialog.xaml
+ ///
+ public partial class EditShipDialog : Window
+ {
+ public EditShipDialog()
+ {
+ InitializeComponent();
+ }
+ }
+}
diff --git a/src/RoleEditor/MainWindow.xaml b/src/RoleEditor/MainWindow.xaml
index a8662ba..ca78039 100644
--- a/src/RoleEditor/MainWindow.xaml
+++ b/src/RoleEditor/MainWindow.xaml
@@ -7,232 +7,278 @@
mc:Ignorable="d"
Title="Bremen calling admin editor" Height="600" Width="800" Icon="Resources/lock_preferences.ico" Loaded="Window_Loaded">
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/RoleEditor/MainWindow.xaml.cs b/src/RoleEditor/MainWindow.xaml.cs
index ea7d758..99f9b1a 100644
--- a/src/RoleEditor/MainWindow.xaml.cs
+++ b/src/RoleEditor/MainWindow.xaml.cs
@@ -1,11 +1,17 @@
using System;
+using System.Collections.Generic;
using System.Collections.ObjectModel;
+using System.Globalization;
+using System.IO;
+using System.Linq;
using System.Security.Cryptography;
using System.Text;
+using System.Threading;
using System.Windows;
using System.Windows.Controls;
-
+using System.Windows.Media.Animation;
+using System.Windows.Media.Imaging;
using brecal.model;
using brecal.mysql;
@@ -24,6 +30,8 @@ namespace RoleEditor
private readonly ObservableCollection _users = new ObservableCollection();
private readonly ObservableCollection _assignedRoles = new ObservableCollection();
private readonly ObservableCollection _assignedSecurables = new ObservableCollection();
+ private readonly ObservableCollection _berths = new ObservableCollection();
+ private readonly ObservableCollection _ships = new ObservableCollection();
private DBManager _dbManager;
#endregion
@@ -38,11 +46,13 @@ namespace RoleEditor
private async void Window_Loaded(object sender, RoutedEventArgs e)
{
+
// try database connection
try
- {
+ {
// load all participants
- foreach(Participant p in await Participant.LoadAll(_dbManager))
+ List participants = await Participant.LoadAll(_dbManager);
+ foreach(Participant p in participants)
_participants.Add(p);
this.listBoxParticipant.ItemsSource = _participants;
@@ -56,6 +66,39 @@ namespace RoleEditor
_securables.Add(s);
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)
this.listBoxUser.ItemsSource = _users;
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
#region button callbacks
@@ -408,6 +507,42 @@ namespace RoleEditor
}
#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
+
}
}
diff --git a/src/RoleEditor/Resources.Designer.cs b/src/RoleEditor/Resources.Designer.cs
index b62f446..a6500a8 100644
--- a/src/RoleEditor/Resources.Designer.cs
+++ b/src/RoleEditor/Resources.Designer.cs
@@ -100,6 +100,16 @@ namespace RoleEditor {
}
}
+ ///
+ /// Looks up a localized resource of type System.Byte[].
+ ///
+ internal static byte[] delete {
+ get {
+ object obj = ResourceManager.GetObject("delete", resourceCulture);
+ return ((byte[])(obj));
+ }
+ }
+
///
/// Looks up a localized resource of type System.Byte[].
///
@@ -120,6 +130,36 @@ namespace RoleEditor {
}
}
+ ///
+ /// Looks up a localized resource of type System.Byte[].
+ ///
+ internal static byte[] document_plain {
+ get {
+ object obj = ResourceManager.GetObject("document_plain", resourceCulture);
+ return ((byte[])(obj));
+ }
+ }
+
+ ///
+ /// Looks up a localized resource of type System.Byte[].
+ ///
+ internal static byte[] edit {
+ get {
+ object obj = ResourceManager.GetObject("edit", resourceCulture);
+ return ((byte[])(obj));
+ }
+ }
+
+ ///
+ /// Looks up a localized resource of type System.Byte[].
+ ///
+ internal static byte[] floppy_disk_blue {
+ get {
+ object obj = ResourceManager.GetObject("floppy_disk_blue", resourceCulture);
+ return ((byte[])(obj));
+ }
+ }
+
///
/// Looks up a localized resource of type System.Byte[].
///
@@ -160,6 +200,16 @@ namespace RoleEditor {
}
}
+ ///
+ /// Looks up a localized resource of type System.Byte[].
+ ///
+ internal static byte[] printer {
+ get {
+ object obj = ResourceManager.GetObject("printer", resourceCulture);
+ return ((byte[])(obj));
+ }
+ }
+
///
/// Looks up a localized resource of type System.Byte[].
///
@@ -169,5 +219,59 @@ namespace RoleEditor {
return ((byte[])(obj));
}
}
+
+ ///
+ /// Looks up a localized string similar to Add.
+ ///
+ internal static string textAdd {
+ get {
+ return ResourceManager.GetString("textAdd", resourceCulture);
+ }
+ }
+
+ ///
+ /// Looks up a localized string similar to Delete.
+ ///
+ internal static string textDelete {
+ get {
+ return ResourceManager.GetString("textDelete", resourceCulture);
+ }
+ }
+
+ ///
+ /// Looks up a localized string similar to Edit.
+ ///
+ internal static string textEdit {
+ get {
+ return ResourceManager.GetString("textEdit", resourceCulture);
+ }
+ }
+
+ ///
+ /// Looks up a localized string similar to Export.
+ ///
+ internal static string textExport {
+ get {
+ return ResourceManager.GetString("textExport", resourceCulture);
+ }
+ }
+
+ ///
+ /// Looks up a localized string similar to Print.
+ ///
+ internal static string textPrint {
+ get {
+ return ResourceManager.GetString("textPrint", resourceCulture);
+ }
+ }
+
+ ///
+ /// Looks up a localized string similar to _Show as text.
+ ///
+ internal static string textShowAsText {
+ get {
+ return ResourceManager.GetString("textShowAsText", resourceCulture);
+ }
+ }
}
}
diff --git a/src/RoleEditor/Resources.resx b/src/RoleEditor/Resources.resx
index 2d7da8b..fb61f98 100644
--- a/src/RoleEditor/Resources.resx
+++ b/src/RoleEditor/Resources.resx
@@ -130,12 +130,24 @@
Resources\businessman.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+ Resources\delete.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
Resources\delete2.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
Resources\disk_blue.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+ Resources\document_plain.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ Resources\edit.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ Resources\floppy_disk_blue.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
Resources\id_card.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
@@ -148,7 +160,28 @@
Resources\lock_preferences.ico;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+ Resources\printer.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
Resources\safe.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+ Add
+
+
+ Delete
+
+
+ Edit
+
+
+ Export
+
+
+ Print
+
+
+ _Show as text
+
\ No newline at end of file
diff --git a/src/RoleEditor/Resources/delete.png b/src/RoleEditor/Resources/delete.png
new file mode 100644
index 0000000..23d04fb
Binary files /dev/null and b/src/RoleEditor/Resources/delete.png differ
diff --git a/src/RoleEditor/Resources/document_plain.png b/src/RoleEditor/Resources/document_plain.png
new file mode 100644
index 0000000..9f61bac
Binary files /dev/null and b/src/RoleEditor/Resources/document_plain.png differ
diff --git a/src/RoleEditor/Resources/edit.png b/src/RoleEditor/Resources/edit.png
new file mode 100644
index 0000000..9a43d58
Binary files /dev/null and b/src/RoleEditor/Resources/edit.png differ
diff --git a/src/RoleEditor/Resources/floppy_disk_blue.png b/src/RoleEditor/Resources/floppy_disk_blue.png
new file mode 100644
index 0000000..d70e4fd
Binary files /dev/null and b/src/RoleEditor/Resources/floppy_disk_blue.png differ
diff --git a/src/RoleEditor/Resources/printer.png b/src/RoleEditor/Resources/printer.png
new file mode 100644
index 0000000..96567d3
Binary files /dev/null and b/src/RoleEditor/Resources/printer.png differ
diff --git a/src/RoleEditor/RoleEditor.csproj b/src/RoleEditor/RoleEditor.csproj
index 936e6bb..8cede2c 100644
--- a/src/RoleEditor/RoleEditor.csproj
+++ b/src/RoleEditor/RoleEditor.csproj
@@ -13,11 +13,16 @@
+
+
+
+
+
@@ -35,11 +40,16 @@
+
+
+
+
+
diff --git a/src/RoleEditor/Util.cs b/src/RoleEditor/Util.cs
new file mode 100644
index 0000000..6667207
--- /dev/null
+++ b/src/RoleEditor/Util.cs
@@ -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;
+ }
+ }
+}
diff --git a/src/brecal.model/Berth.cs b/src/brecal.model/Berth.cs
new file mode 100644
index 0000000..11d675b
--- /dev/null
+++ b/src/brecal.model/Berth.cs
@@ -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> LoadAll(IDBManager manager)
+ {
+ List loadResultList = await manager.Load(SetLoadQuery, LoadElems);
+ List result = new();
+ foreach (Berth b in loadResultList.Cast())
+ 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 LoadElems(IDataReader reader)
+ {
+ List result = new List();
+ 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
+
+ }
+}
diff --git a/src/brecal.model/Participant.cs b/src/brecal.model/Participant.cs
index e2a1d88..10118e8 100644
--- a/src/brecal.model/Participant.cs
+++ b/src/brecal.model/Participant.cs
@@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Data;
using System.Linq;
+using System.Reflection.PortableExecutable;
using System.Text;
using System.Threading.Tasks;
@@ -9,6 +10,22 @@ namespace brecal.model
{
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
public string? Name { get; set; }
@@ -132,5 +149,20 @@ namespace brecal.model
#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
+
}
}
diff --git a/src/brecal.model/Ship.cs b/src/brecal.model/Ship.cs
new file mode 100644
index 0000000..5800ca2
--- /dev/null
+++ b/src/brecal.model/Ship.cs
@@ -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> LoadAll(IDBManager manager)
+ {
+ List loadResultList = await manager.Load(SetLoadQuery, LoadElems);
+ List result = new();
+ foreach (Ship s in loadResultList.Cast())
+ 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 LoadElems(IDataReader reader)
+ {
+ List result = new List();
+ 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
+
+ }
+}
diff --git a/src/brecal.mysql/DBManager.cs b/src/brecal.mysql/DBManager.cs
index 054caa9..e3a1dc3 100644
--- a/src/brecal.mysql/DBManager.cs
+++ b/src/brecal.mysql/DBManager.cs
@@ -9,7 +9,7 @@ namespace brecal.mysql
public class DBManager : IDBManager
{
// 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> Load(QueryFunc prepareAction, LoadFunc loadAction, params object?[] args)
{