diff --git a/ENI2/App.config b/ENI2/App.config
index 289893b6..fcd86780 100644
--- a/ENI2/App.config
+++ b/ENI2/App.config
@@ -11,7 +11,7 @@
-
+
@@ -85,7 +85,7 @@
-
+
diff --git a/ENI2/DetailViewControls/PortNotificationDetailControl.xaml b/ENI2/DetailViewControls/PortNotificationDetailControl.xaml
index da7a1c00..66f0794a 100644
--- a/ENI2/DetailViewControls/PortNotificationDetailControl.xaml
+++ b/ENI2/DetailViewControls/PortNotificationDetailControl.xaml
@@ -101,11 +101,40 @@
-
+
+
+
+
+
+
+
-
+
+
+
+
+
+
+
diff --git a/ENI2/DetailViewControls/PortNotificationDetailControl.xaml.cs b/ENI2/DetailViewControls/PortNotificationDetailControl.xaml.cs
index 571d7a40..f3772511 100644
--- a/ENI2/DetailViewControls/PortNotificationDetailControl.xaml.cs
+++ b/ENI2/DetailViewControls/PortNotificationDetailControl.xaml.cs
@@ -16,6 +16,8 @@ using ENI2.EditControls;
using ENI2.Util;
using bsmd.database;
+using System.Threading.Tasks;
+using System.Diagnostics;
namespace ENI2.DetailViewControls
{
@@ -25,12 +27,18 @@ namespace ENI2.DetailViewControls
public partial class PortNotificationDetailControl : DetailBaseControl
{
+ #region Fields
+
private Message _nameMessage;
private Message _infoMessage;
private Message _servMessage;
private Message _ladgMessage;
private Message _crewaMessage;
private Dictionary portAreas = null;
+ private static List _servTemplates = null;
+ private SERV_Template _currentTemplate;
+
+ #endregion
private static readonly string[] shippingAreas = {
Properties.Resources.textShippingAreaNORTHBALTIC,
@@ -60,7 +68,7 @@ namespace ENI2.DetailViewControls
this.dataGridLADG.CellEditEnding += (obj, ev) => { this.OnNotificationClassChanged(Message.NotificationClass.LADG); };
}
- public override void Initialize()
+ public override async void Initialize()
{
base.Initialize();
@@ -157,16 +165,22 @@ namespace ENI2.DetailViewControls
this.dataGridLADG.DeleteRequested += DataGridLADG_DeleteRequested;
this.dataGridLADG.CreateRequested += DataGridLADG_CreateRequested;
- #endregion
+ #endregion
- #region init helper Maersk / SeaGo Field
+ #region init SERV templates
- if (this.Core.IsFlagSet(MessageCore.CoreFlags.MAERSK_BHV)) this.comboBoxGroup.SelectedIndex = 1;
- if (this.Core.IsFlagSet(MessageCore.CoreFlags.SEAGO_BHV)) this.comboBoxGroup.SelectedIndex = 2;
- if (this.Core.IsFlagSet(MessageCore.CoreFlags.SEAGO_WHV)) this.comboBoxGroup.SelectedIndex = 3;
- if (this.Core.IsFlagSet(MessageCore.CoreFlags.HOEGH)) this.comboBoxGroup.SelectedIndex = 4;
- if (this.Core.IsFlagSet(MessageCore.CoreFlags.ELBE_BULK)) this.comboBoxGroup.SelectedIndex = 5;
- if (this.Core.IsFlagSet(MessageCore.CoreFlags.FCT_JUNGE)) this.comboBoxGroup.SelectedIndex = 6;
+ if(_servTemplates == null)
+ {
+ _servTemplates = await DBManagerAsync.GetSERVTemplatesAsync(); // initial load
+ _servTemplates.Sort();
+ Trace.WriteLine($"{_servTemplates.Count} SERV templates loaded");
+ }
+
+ this.comboBoxGroup.ItemsSource = _servTemplates;
+
+ this.buttonDeleteTemplate.Visibility = DBManager.Instance.GetReportingPartyDict()[App.UserId.Value].IsEditor ? Visibility.Visible : Visibility.Hidden;
+ this.buttonEditTemplate.Visibility = DBManager.Instance.GetReportingPartyDict()[App.UserId.Value].IsEditor ? Visibility.Visible : Visibility.Hidden;
+ this.buttonNewTemplate.Visibility = DBManager.Instance.GetReportingPartyDict()[App.UserId.Value].IsEditor ? Visibility.Visible : Visibility.Hidden;
#endregion
@@ -371,35 +385,93 @@ namespace ENI2.DetailViewControls
private void comboBoxGroup_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
- // clear all
- this.Core.SetFlag(false, MessageCore.CoreFlags.MAERSK_BHV);
- this.Core.SetFlag(false, MessageCore.CoreFlags.SEAGO_BHV);
- this.Core.SetFlag(false, MessageCore.CoreFlags.SEAGO_WHV);
- this.Core.SetFlag(false, MessageCore.CoreFlags.HOEGH);
- this.Core.SetFlag(false, MessageCore.CoreFlags.ELBE_BULK);
- this.Core.SetFlag(false, MessageCore.CoreFlags.FCT_JUNGE);
-
- if (this.comboBoxGroup.SelectedItem == null)
- {
- this.comboBoxGroup.SelectedIndex = 0;
- DBManager.Instance.Save(this.Core);
+ if(this.comboBoxGroup.SelectedItem is SERV_Template st)
+ {
+ this.buttonDeleteTemplate.IsEnabled = true;
+ this.buttonSetTemplate.IsEnabled = true;
+ this._currentTemplate = st;
}
- else
+ }
+
+ private void buttonSetTemplate_Click(object sender, RoutedEventArgs e)
+ {
+ if (this.comboBoxGroup.SelectedItem is SERV_Template st)
{
- DictionaryEntry selectedItem = (DictionaryEntry)this.comboBoxGroup.SelectedItem;
- if (Int32.TryParse((string)selectedItem.Value, out int selectedValue))
+ bool found = false;
+ foreach (SERV serv in _servMessage.Elements.Cast())
{
- if (selectedValue == (int)MessageCore.CoreFlags.MAERSK_BHV) CheckServiceEntryMaerskBHV();
- if (selectedValue == (int)MessageCore.CoreFlags.SEAGO_BHV) CheckServiceEntrySeaGoBHV();
- if (selectedValue == (int)MessageCore.CoreFlags.HOEGH) CheckServiceEntryHoegh();
- if (selectedValue == (int)MessageCore.CoreFlags.ELBE_BULK) CheckServiceEntryElbeBulk();
- if (selectedValue == (int)MessageCore.CoreFlags.FCT_JUNGE) CheckServiceEntryFctJunge();
- this.Core.SetFlag(true, (MessageCore.CoreFlags)selectedValue);
- DBManager.Instance.Save(this.Core);
+ if (serv.ServiceName.Equals(st.ServiceName))
+ {
+ found = true; break;
+ }
+ }
+
+ if (!found)
+ {
+ SERV newServ = new SERV();
+ newServ.ServiceName = st.ServiceName;
+ newServ.ServiceBeneficiary = st.ServiceBeneficiary;
+ newServ.ServiceInvoiceRecipient = st.ServiceInvoiceRecipient;
+
+ newServ.MessageHeader = this._servMessage;
+ newServ.Identifier = SERV.GetNewIdentifier(_servMessage.Elements);
+ this._servMessage.Elements.Add(newServ);
+ this.dataGridSERV.Items.Refresh();
+ this.SublistElementChanged(Message.NotificationClass.SERV);
}
}
}
+ private void buttonNewTemplate_Click(object sender, RoutedEventArgs e)
+ {
+ SERV_Template newTemplate = new SERV_Template();
+ EditSERVDialog esd = new EditSERVDialog();
+ esd.AddVisible = false;
+ esd.SERV_Template = newTemplate;
+ if(esd.ShowDialog() ?? false)
+ {
+ _ = DBManagerAsync.SaveAsync(esd.SERV_Template);
+ this.comboBoxGroup.ItemsSource = null;
+ _servTemplates.Add(newTemplate);
+ _servTemplates.Sort();
+ this.comboBoxGroup.ItemsSource = _servTemplates;
+ }
+ }
+
+ private void buttonEditTemplate_Click(object sender, RoutedEventArgs e)
+ {
+ if (this.comboBoxGroup.SelectedItem is SERV_Template st)
+ {
+ EditSERVDialog editSERVDialog = new EditSERVDialog();
+ editSERVDialog.AddVisible = false;
+ editSERVDialog.SERV_Template = st;
+ if (editSERVDialog.ShowDialog() ?? false)
+ {
+ _ = DBManagerAsync.SaveAsync(st);
+ this.comboBoxGroup.ItemsSource = null;
+ _servTemplates.Sort();
+ this.comboBoxGroup.ItemsSource = _servTemplates;
+ }
+ }
+ }
+
+ private void buttonDeleteTemplate_Click(object sender, RoutedEventArgs e)
+ {
+ if (_currentTemplate != null)
+ {
+ if (MessageBox.Show("Delete this template?", "Confirmation", MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.No) == MessageBoxResult.Yes)
+ {
+ this.comboBoxGroup.SelectedItem = null;
+ this.comboBoxGroup.ItemsSource = null;
+ _ = DBManagerAsync.DeleteAsync(_currentTemplate);
+ _servTemplates.Remove(_currentTemplate);
+ this.buttonDeleteTemplate.IsEnabled = false;
+ this.comboBoxGroup.ItemsSource = _servTemplates;
+ this.buttonSetTemplate.IsEnabled = false;
+ }
+ }
+ }
+
#endregion
#region special entry ship service check
@@ -538,17 +610,7 @@ namespace ENI2.DetailViewControls
}
}
- #endregion
-
- private void MenuItem_Click(object sender, RoutedEventArgs e)
- {
-
- }
-
- private void contextMenuClearMaersk_Click(object sender, RoutedEventArgs e)
- {
-
- }
+ #endregion
private void buttonCopyNameFromCREWA_Click(object sender, RoutedEventArgs e)
{
@@ -568,5 +630,6 @@ namespace ENI2.DetailViewControls
this.SublistElementChanged(Message.NotificationClass.NAME);
}
}
+
}
}
diff --git a/ENI2/ENI2.csproj b/ENI2/ENI2.csproj
index c7fad5c7..df77abc1 100644
--- a/ENI2/ENI2.csproj
+++ b/ENI2/ENI2.csproj
@@ -1047,6 +1047,7 @@
PreserveNewest
+
Always
diff --git a/ENI2/EditControls/EditSERVDialog.xaml.cs b/ENI2/EditControls/EditSERVDialog.xaml.cs
index c2284d7f..e66f03a5 100644
--- a/ENI2/EditControls/EditSERVDialog.xaml.cs
+++ b/ENI2/EditControls/EditSERVDialog.xaml.cs
@@ -1,5 +1,5 @@
// Copyright (c) 2017 schick Informatik
-// Description:
+// Description: Edit SERV and SERV_template entities
//
using System.Windows;
@@ -14,36 +14,78 @@ namespace ENI2.EditControls
///
public partial class EditSERVDialog : EditWindowBase
{
+
+ #region Construction
+
public EditSERVDialog()
{
InitializeComponent();
Loaded += EditSERVDialog_Loaded;
}
+ #endregion
+
+ #region Properties
+
+ public SERV SERV { get; set; }
+
+ public SERV_Template SERV_Template { get; set; }
+
+ #endregion
+
+ #region event handler
+
private void EditSERVDialog_Loaded(object sender, RoutedEventArgs e)
{
this.OKClicked += EditSERVDialog_OKClicked;
// copy into fields
- this.textBoxServiceName.Text = this.SERV.ServiceName;
- this.textBoxServiceBeneficiary.Text = this.SERV.ServiceBeneficiary;
- this.textBoxServiceInvoiceRecipient.Text = this.SERV.ServiceInvoiceRecipient;
- this.AddVisible = true;
+ if (this.SERV != null)
+ {
+ this.textBoxServiceName.Text = this.SERV.ServiceName;
+ this.textBoxServiceBeneficiary.Text = this.SERV.ServiceBeneficiary;
+ this.textBoxServiceInvoiceRecipient.Text = this.SERV.ServiceInvoiceRecipient;
+ this.AddVisible = true;
+ }
+
+ if (this.SERV_Template != null)
+ {
+ this.textBoxServiceName.Text = this.SERV_Template.ServiceName;
+ this.textBoxServiceBeneficiary.Text = this.SERV_Template.ServiceBeneficiary;
+ this.textBoxServiceInvoiceRecipient.Text = this.SERV_Template.ServiceInvoiceRecipient;
+ }
}
+ private void EditSERVDialog_OKClicked()
+ {
+ this.CopyValuesToEntity();
+ }
+
+ #endregion
+
+ #region public methods
public void CopyValuesToEntity()
{
- // copy back
- this.SERV.ServiceName = this.textBoxServiceName.Text.Trim();
- this.SERV.ServiceBeneficiary = this.textBoxServiceBeneficiary.Text.Trim();
- this.SERV.ServiceInvoiceRecipient = this.textBoxServiceInvoiceRecipient.Text.Trim();
+
+ if (this.SERV != null)
+ {
+ // copy back
+ this.SERV.ServiceName = this.textBoxServiceName.Text.Trim();
+ this.SERV.ServiceBeneficiary = this.textBoxServiceBeneficiary.Text.Trim();
+ this.SERV.ServiceInvoiceRecipient = this.textBoxServiceInvoiceRecipient.Text.Trim();
+ }
+
+ if (this.SERV_Template != null)
+ {
+ // copy back
+ this.SERV_Template.ServiceName = this.textBoxServiceName.Text.Trim();
+ this.SERV_Template.ServiceBeneficiary = this.textBoxServiceBeneficiary.Text.Trim();
+ this.SERV_Template.ServiceInvoiceRecipient = this.textBoxServiceInvoiceRecipient.Text.Trim();
+ }
+
}
- private void EditSERVDialog_OKClicked()
- {
- this.CopyValuesToEntity();
- }
-
- public SERV SERV { get; set; }
+ #endregion
+
}
}
diff --git a/ENI2/Properties/Resources.Designer.cs b/ENI2/Properties/Resources.Designer.cs
index 326852b9..86c7a834 100644
--- a/ENI2/Properties/Resources.Designer.cs
+++ b/ENI2/Properties/Resources.Designer.cs
@@ -750,6 +750,16 @@ namespace ENI2.Properties {
}
}
+ ///
+ /// Looks up a localized resource of type System.Drawing.Bitmap.
+ ///
+ public static System.Drawing.Bitmap pencil {
+ get {
+ object obj = ResourceManager.GetObject("pencil", resourceCulture);
+ return ((System.Drawing.Bitmap)(obj));
+ }
+ }
+
///
/// Looks up a localized resource of type System.Drawing.Bitmap.
///
diff --git a/ENI2/Properties/Resources.resx b/ENI2/Properties/Resources.resx
index 5d43fddf..89059ac3 100644
--- a/ENI2/Properties/Resources.resx
+++ b/ENI2/Properties/Resources.resx
@@ -2242,4 +2242,7 @@
SERV-Template
+
+ ..\Resources\pencil.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
+
\ No newline at end of file
diff --git a/ENI2/Resources/pencil.png b/ENI2/Resources/pencil.png
new file mode 100644
index 00000000..68f35048
Binary files /dev/null and b/ENI2/Resources/pencil.png differ
diff --git a/SQL/SERV_template.sql b/SQL/SERV_template.sql
new file mode 100644
index 00000000..2038fa1d
--- /dev/null
+++ b/SQL/SERV_template.sql
@@ -0,0 +1,25 @@
+PRINT N'Creating [dbo].[SERV_template]...';
+
+GO
+CREATE TABLE [dbo].[SERV_template] (
+ [Id] UNIQUEIDENTIFIER NOT NULL,
+ [ServiceName] NVARCHAR (100) NULL,
+ [ServiceBeneficiary] NVARCHAR (256) NULL,
+ [ServiceInvoiceRecipient] NVARCHAR (256) NULL,
+ [Created] DATETIME NULL DEFAULT CURRENT_TIMESTAMP,
+ [Changed] DATETIME NULL,
+ PRIMARY KEY CLUSTERED ([Id] ASC)
+);
+
+GO
+
+CREATE TRIGGER SERV_template_Trigger_Change_Log
+ON
+ dbo.SERV_template
+ FOR UPDATE
+ AS
+ SET NOCOUNT ON
+ IF NOT UPDATE([Changed])
+ UPDATE SERV_template SET [Changed] = GETDATE() WHERE Id IN (SELECT Id FROM [inserted])
+
+GO
\ No newline at end of file
diff --git a/bsmd.database/DBManagerAsync.cs b/bsmd.database/DBManagerAsync.cs
index 3f5202d2..acd8d9ae 100644
--- a/bsmd.database/DBManagerAsync.cs
+++ b/bsmd.database/DBManagerAsync.cs
@@ -112,6 +112,16 @@ namespace bsmd.database
return (await at.LoadListAsync(reader)).ConvertAll(x => (AGNT_Template)x);
}
+ public static async Task> GetSERVTemplatesAsync()
+ {
+ SqlCommand cmd = new SqlCommand();
+ SERV_Template st = new SERV_Template();
+ st.PrepareLoadCommand(cmd, Message.LoadFilter.ALL);
+ SqlDataReader reader = await PerformCommandAsync(cmd);
+ return (await st.LoadListAsync(reader)).ConvertAll(x => (SERV_Template)x);
+ }
+
+
public static async Task> GetWastDisposalServiceProviderTemplatesAsync()
{
SqlCommand cmd = new SqlCommand();
diff --git a/bsmd.database/SERV_Template.cs b/bsmd.database/SERV_Template.cs
new file mode 100644
index 00000000..8e47d51a
--- /dev/null
+++ b/bsmd.database/SERV_Template.cs
@@ -0,0 +1,128 @@
+// Copyright (c) 2024-present schick Informatik
+// Description:
+
+using System;
+using System.Collections.Generic;
+using System.Data;
+using System.Data.SqlClient;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace bsmd.database
+{
+ public class SERV_Template : DatabaseEntityAsync, IComparable
+ {
+ #region Construction
+
+ public SERV_Template()
+ {
+ this.tablename = "[dbo].[SERV_template]";
+ }
+
+ #endregion
+
+ #region Properties
+
+ [MaxLength(99)]
+ public string ServiceName { get; set; }
+
+ [MaxLength(255)]
+ public string ServiceBeneficiary { get; set; }
+
+ [MaxLength(255)]
+ public string ServiceInvoiceRecipient { get; set; }
+
+ #endregion
+
+ #region DatabaseEntity implementation
+
+ public override void PrepareSave(IDbCommand cmd)
+ {
+ SqlCommand scmd = cmd as SqlCommand;
+
+ if (this.ServiceName != null) scmd.Parameters.AddWithValue("@P1", this.ServiceName);
+ else scmd.Parameters.AddWithValue("@P1", DBNull.Value);
+ if (this.ServiceBeneficiary != null) scmd.Parameters.AddWithValue(@"P2", this.ServiceBeneficiary);
+ else scmd.Parameters.AddWithValue("@P2", DBNull.Value);
+ if (this.ServiceInvoiceRecipient != null) scmd.Parameters.AddWithValue("@P3", this.ServiceInvoiceRecipient);
+ else scmd.Parameters.AddWithValue("@P3", DBNull.Value);
+
+ if (this.IsNew)
+ {
+ this.CreateId();
+ cmd.CommandText = string.Format("INSERT INTO {0} (Id, ServiceName, ServiceBeneficiary, ServiceInvoiceRecipient) VALUES " +
+ "(@ID, @P1, @P2, @P3)", this.Tablename);
+ }
+ else
+ {
+ cmd.CommandText = string.Format("UPDATE {0} SET ServiceName = @P1, ServiceBeneficiary = @P2, ServiceInvoiceRecipient = @P3 WHERE Id = @ID", this.Tablename);
+ }
+ scmd.Parameters.AddWithValue("@ID", this.Id);
+ }
+
+ public override void PrepareLoadCommand(IDbCommand cmd, Message.LoadFilter filter, params object[] criteria)
+ {
+ string query = string.Format("SELECT Id, ServiceName, ServiceBeneficiary, ServiceInvoiceRecipient FROM {0}", this.Tablename);
+
+ switch (filter)
+ {
+ case Message.LoadFilter.ALL:
+ default:
+
+ break;
+ }
+ cmd.CommandText = query;
+ }
+
+ public override List LoadList(System.Data.IDataReader reader)
+ {
+ List result = new List();
+
+ while (reader.Read())
+ {
+ SERV_Template serv_t = new SERV_Template();
+ serv_t.id = reader.GetGuid(0);
+ if (!reader.IsDBNull(1)) serv_t.ServiceName = reader.GetString(1);
+ if (!reader.IsDBNull(2)) serv_t.ServiceBeneficiary = reader.GetString(2);
+ if (!reader.IsDBNull(3)) serv_t.ServiceInvoiceRecipient = reader.GetString(3);
+
+ result.Add(serv_t);
+ }
+ reader.Close();
+ return result;
+ }
+
+ protected override DatabaseEntityAsync ReadRowFromReader(IDataReader reader)
+ {
+ SERV_Template serv_t = null;
+ if (reader != null)
+ {
+ serv_t = new SERV_Template();
+ serv_t.id = reader.GetGuid(0);
+ if (!reader.IsDBNull(1)) serv_t.ServiceName = reader.GetString(1);
+ if (!reader.IsDBNull(2)) serv_t.ServiceBeneficiary = reader.GetString(2);
+ if (!reader.IsDBNull(3)) serv_t.ServiceInvoiceRecipient = reader.GetString(3);
+
+ }
+ return serv_t;
+ }
+
+ #endregion
+
+
+ #region IComparable implementation
+
+ public int CompareTo(object obj)
+ {
+ if (obj is SERV_Template template)
+ {
+ return this.ServiceName.CompareTo(template.ServiceName);
+ }
+ return 0;
+ }
+
+ #endregion
+
+ }
+}
diff --git a/bsmd.database/bsmd.database.csproj b/bsmd.database/bsmd.database.csproj
index 1fbac158..a947e177 100644
--- a/bsmd.database/bsmd.database.csproj
+++ b/bsmd.database/bsmd.database.csproj
@@ -173,6 +173,7 @@
+