git_bsmd/ENI2/SheetDisplayControls/PortControl.xaml.cs

1253 lines
56 KiB
C#

// Copyright (c) 2025 - schick Informatik
// Description: Display control of formsheet Tab 2. Port
//
using bsmd.database;
using ENI2.EditControls;
using ExcelDataReader;
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
namespace ENI2.SheetDisplayControls
{
/// <summary>
/// Interaction logic for PortControl.xaml
/// </summary>
public partial class PortControl : DetailBaseControl
{
#region Fields
private Message _ladgMessage;
private Message _servMessage;
private NOA_NOD _noa_nod;
private INFO _info;
private PRE72H _pre72H;
private AGNT _agnt;
private SEC _sec;
private WAS _was;
private Message _stoMessage;
private Dictionary<string, string> portAreas = null;
private static List<AGNT_Template> _agntTemplates = null;
private AGNT_Template _currentTemplate;
private AGNT_Template _undoTemplate;
private static List<SERV_Template> _servTemplates = null;
private SERV_Template _currentSERVTemplate;
private static List<WasteDisposalServiceProvider_Template> _wsdpTemplates = null;
private WasteDisposalServiceProvider_Template _currentWSDPTemplate;
private string _undoWSDPTemplate;
private static readonly string[] cargoDescriptions = {
"Container",
"Vehicles",
"Conventional general cargo",
"Dry bulk cargo",
"Liquid bulk cargo",
"In ballast"
};
private static readonly string[] conditionCargoTanks =
{
Properties.Resources.textFull,
Properties.Resources.textEmpty,
Properties.Resources.textInert
};
#endregion
#region Construction
public PortControl()
{
InitializeComponent();
Loaded += PortControl_Loaded;
}
#endregion
#region public override
public async override void Initialize()
{
base.Initialize();
foreach (Message aMessage in this.Messages)
{
if (aMessage.MessageNotificationClass == Message.NotificationClass.LADG) { this._ladgMessage = aMessage; this.ControlMessages.Add(aMessage); }
if (aMessage.MessageNotificationClass == Message.NotificationClass.SERV) { this._servMessage = aMessage; this.ControlMessages.Add(aMessage); }
if (aMessage.MessageNotificationClass == Message.NotificationClass.NOA_NOD) { this._noa_nod = aMessage.Elements[0] as NOA_NOD; this.ControlMessages.Add(aMessage); }
if (aMessage.MessageNotificationClass == Message.NotificationClass.SEC) { this._sec = aMessage.Elements[0] as SEC; this.ControlMessages.Add(aMessage); }
if (aMessage.MessageNotificationClass == Message.NotificationClass.INFO) { this._info = aMessage.Elements[0] as INFO; this.ControlMessages.Add(aMessage); }
if (aMessage.MessageNotificationClass == Message.NotificationClass.PRE72H) { this._pre72H = aMessage.Elements[0] as PRE72H; this.ControlMessages.Add(aMessage); }
if (aMessage.MessageNotificationClass == Message.NotificationClass.AGNT) { this._agnt = aMessage.Elements[0] as AGNT; this.ControlMessages.Add(aMessage); }
if (aMessage.MessageNotificationClass == Message.NotificationClass.WAS) { this._was = aMessage.Elements[0] as WAS; this.ControlMessages.Add(aMessage); }
if (aMessage.MessageNotificationClass == Message.NotificationClass.STO) { this._stoMessage = aMessage; this.ControlMessages.Add(aMessage); }
// if (aMessage.MessageNotificationClass == Message.NotificationClass.CREWA) { this._crewMessage = aMessage; this.ControlMessages.Add(aMessage); }
}
// 2.1
this.textBoxDisplayId.Text = this.Core.DisplayId;
this.textBoxTicketNo.DataContext = this.Core;
// 2.2
this.dataGridCallPurposes.Initialize();
this.dataGridCallPurposes.ItemsSource = _noa_nod.CallPurposes;
this.dataGridCallPurposes.EditRequested += DataGridCallPurposes_EditRequested;
this.dataGridCallPurposes.AddingNewItem += DataGridCallPurposes_AddingNewItem;
this.dataGridCallPurposes.CreateRequested += DataGridCallPurposes_CreateRequested;
this.dataGridCallPurposes.DeleteRequested += DataGridCallPurposes_DeleteRequested;
portAreas = LocalizedLookup.getPortAreasForLocode(this.Core.PoC);
this.comboBoxPortArea.ItemsSource = portAreas;
this.comboBoxPortArea.DataContext = this._info;
this.textRequestedPostionInPortOfCall.DataContext = this._info;
this.textSpecialRequirements.DataContext = this._info;
this.textConstructionCharacteristics.DataContext = this._info;
this.textBoxPlannedOperations.DataContext = this._pre72H;
this.textBoxPlannedWorks.DataContext = this._pre72H;
// 2.3
this.textBox_AgentCity.DataContext = this._agnt;
this.textBox_AgentCompanyName.DataContext = this._agnt;
this.textBox_AgentCountry.DataContext = this._agnt;
this.textBox_AgentEMail.DataContext = this._agnt;
this.textBox_AgentFax.DataContext = this._agnt;
this.textBox_AgentFirstName.DataContext = this._agnt;
this.textBox_AgentLastName.DataContext = this._agnt;
this.textBox_AgentPhone.DataContext = this._agnt;
this.textBox_AgentPostalCode.DataContext = this._agnt;
this.textBox_AgentStreetAndNumber.DataContext = this._agnt;
this.textBox_WasteDisposalServiceProvider.DataContext = this._was;
if (_agntTemplates == null)
{
_agntTemplates = await DBManagerAsync.GetAGNTTemplatesAsync(); // inital full load
_agntTemplates.Sort();
Trace.WriteLine(string.Format("{0} agent templates loaded", _agntTemplates.Count));
}
this.comboBox_AgentTemplate.ItemsSource = _agntTemplates;
// 2.4
#region init helper Maersk / SeaGo Field
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;
#endregion
this.dataGridSERV.Initialize();
this.dataGridSERV.ItemsSource = this._servMessage.Elements;
this.dataGridSERV.AddingNewItem += DataGridSERV_AddingNewItem;
this.dataGridSERV.EditRequested += DataGridSERV_EditRequested;
this.dataGridSERV.DeleteRequested += DataGridSERV_DeleteRequested;
this.dataGridSERV.CreateRequested += DataGridSERV_CreateRequested;
// 2.5
this.comboBoxGeneralDescriptionOfCargo.ItemsSource = cargoDescriptions;
this.comboBoxGeneralDescriptionOfCargo.DataContext = _sec;
this.checkBoxFumigatedBulkCargo.DataContext = this._info;
this.comboBoxConditionCargoBallastTanks.ItemsSource = conditionCargoTanks;
this.comboBoxConditionCargoBallastTanks.DataContext = this._pre72H;
this.textBoxNatureOfCargo.DataContext = this._pre72H;
this.doubleUpDownVolumeOfCargo.DataContext = this._pre72H;
this.checkBoxTanker.DataContext = this._pre72H;
// 2.6
this.dataGridLADG.Initialize();
this.dataGridLADG.ItemsSource = this._ladgMessage.Elements;
this.dataGridLADG.AddingNewItem += DataGridLADG_AddingNewItem;
this.dataGridLADG.EditRequested += DataGridLADG_EditRequested;
this.dataGridLADG.DeleteRequested += DataGridLADG_DeleteRequested;
this.dataGridLADG.CreateRequested += DataGridLADG_CreateRequested;
// 2.7
this.checkBoxValidExemption.Checked += CheckBoxValidExemption_Checked;
this.checkBoxValidExemption.Unchecked += CheckBoxValidExemption_Checked;
this.checkBoxAccurateCorrectDetails.DataContext = _was;
this.checkBoxValidExemption.DataContext = _was;
this.dataGridWaste.Initialize();
this.dataGridWaste.ItemsSource = _was.Waste;
this.dataGridWaste.AddingNewItem += DataGridWaste_AddingNewItem;
this.dataGridWaste.EditRequested += DataGridWaste_EditRequested;
this.dataGridWaste.DeleteRequested += DataGridWaste_DeleteRequested;
this.dataGridWaste.CreateRequested += DataGridWaste_CreateRequested;
this.locodeCtrlLastWastePort.DataContext = _was;
this.locodeCtrlNextWastePort.DataContext = _was;
this.datePickerDateLastDisposal.DataContext = _was;
this.textBoxWasteDisposalServiceProviders.DataContext = _was;
await InitTemplates();
this.comboBox_WSDPTemplate.ItemsSource = _wsdpTemplates;
// 2.8
if (_stoMessage != null)
{
// this.dataGridSTO.Initialize();
// this.dataGridSTO.ItemsSource = _stoMessage.Elements;
}
// 2.9
// this.dataGridEffects.Initialize();
// this.dataGridEffects.ItemsSource = _crewMessage.Elements;
#region init SERV templates
if (_servTemplates == null)
{
_servTemplates = await DBManagerAsync.GetSERVTemplatesAsync(); // initial load
_servTemplates.Sort();
Trace.WriteLine($"{_servTemplates.Count} SERV templates loaded");
}
this.comboBoxGroup.ItemsSource = _servTemplates;
this.buttonDeleteSERVTemplate.Visibility = DBManager.Instance.GetReportingPartyDict()[App.UserId.Value].IsEditor ? Visibility.Visible : Visibility.Hidden;
this.buttonEditSERVTemplate.Visibility = DBManager.Instance.GetReportingPartyDict()[App.UserId.Value].IsEditor ? Visibility.Visible : Visibility.Hidden;
this.buttonNewSERVTemplate.Visibility = DBManager.Instance.GetReportingPartyDict()[App.UserId.Value].IsEditor ? Visibility.Visible : Visibility.Hidden;
#endregion
}
public override int SelectedTabIndex
{
get { return this.mainTabControl.SelectedIndex; }
set { this.mainTabControl.SelectedIndex = value; }
}
public override void SetEnabled(bool enabled)
{
base.SetEnabled(enabled);
this.portCallGroupBox.IsEnabled = enabled;
}
#endregion
#region event hander
private void PortControl_Loaded(object sender, RoutedEventArgs e)
{
// 2.1
this.textBoxTicketNo.TextChanged += CoreTextBox_TextChanged;
this.textBoxDisplayId.TextChanged += CoreTextBox_TextChanged;
// 2.3
this.RegisterComboboxValueChange(this.comboBoxPortArea, Message.NotificationClass.INFO);
this.RegisterTextboxChange(this.textRequestedPostionInPortOfCall, Message.NotificationClass.INFO);
this.RegisterTextboxChange(this.textSpecialRequirements, Message.NotificationClass.INFO);
this.RegisterTextboxChange(this.textConstructionCharacteristics, Message.NotificationClass.INFO);
this.RegisterTextboxChange(this.textBoxPlannedOperations, Message.NotificationClass.PRE72H);
this.RegisterTextboxChange(this.textBoxPlannedWorks, Message.NotificationClass.PRE72H);
// 2.4
this.RegisterTextboxChange(this.textBox_AgentCity, Message.NotificationClass.AGNT);
this.RegisterTextboxChange(this.textBox_AgentCompanyName, Message.NotificationClass.AGNT);
this.RegisterTextboxChange(this.textBox_AgentEMail, Message.NotificationClass.AGNT);
this.RegisterTextboxChange(this.textBox_AgentFax, Message.NotificationClass.AGNT);
this.RegisterTextboxChange(this.textBox_AgentFirstName, Message.NotificationClass.AGNT);
this.RegisterTextboxChange(this.textBox_AgentLastName, Message.NotificationClass.AGNT);
this.RegisterTextboxChange(this.textBox_AgentPhone, Message.NotificationClass.AGNT);
this.RegisterTextboxChange(this.textBox_AgentPostalCode, Message.NotificationClass.AGNT);
this.RegisterTextboxChange(this.textBox_AgentStreetAndNumber, Message.NotificationClass.AGNT);
this.RegisterTextboxChange(this.textBox_AgentCountry, Message.NotificationClass.AGNT);
this.buttonSaveTemplate.IsEnabled = DBManager.Instance.GetReportingPartyDict()[App.UserId.Value].IsEditor;
this.buttonDeleteTemplate.IsEnabled = DBManager.Instance.GetReportingPartyDict()[App.UserId.Value].IsEditor;
// 2.5
this.RegisterComboboxIndexChange(this.comboBoxGeneralDescriptionOfCargo, Message.NotificationClass.SEC);
this.RegisterCheckboxChange(this.checkBoxFumigatedBulkCargo, Message.NotificationClass.INFO);
this.RegisterComboboxIndexChange(this.comboBoxConditionCargoBallastTanks, Message.NotificationClass.PRE72H);
this.RegisterTextboxChange(this.textBoxNatureOfCargo, Message.NotificationClass.PRE72H);
this.RegisterDoubleUpDownChange(this.doubleUpDownVolumeOfCargo, Message.NotificationClass.PRE72H);
// 2.6
this.dataGridLADG.CellEditEnding += (obj, ev) => { this.OnNotificationClassChanged(Message.NotificationClass.LADG); };
// 2.7
this.RegisterLocodeChange(this.locodeCtrlLastWastePort, Message.NotificationClass.WAS);
this.RegisterLocodeChange(this.locodeCtrlNextWastePort, Message.NotificationClass.WAS);
this.RegisterTextboxChange(this.textBoxWasteDisposalServiceProviders, Message.NotificationClass.WAS);
this.RegisterDatePickerChange(this.datePickerDateLastDisposal, Message.NotificationClass.WAS);
}
private void CheckBoxValidExemption_Checked(object sender, RoutedEventArgs e)
{
bool on = !(this.checkBoxValidExemption.IsChecked ?? false);
this.checkBoxAccurateCorrectDetails.IsEnabled = on;
this.locodeCtrlLastWastePort.IsEnabled = on;
this.datePickerDateLastDisposal.IsEnabled = on;
this.textBoxWasteDisposalServiceProviders.IsEnabled = on;
this.gridWasteControls.IsEnabled = on;
this.dataGridWaste.IsEnabled = on;
}
private void buttonSearchPortArea_Click(object sender, RoutedEventArgs e)
{
if (portAreas != null)
{
SelectPortAreaDialog spad = new SelectPortAreaDialog(this.Core.PoC);
if (spad.ShowDialog() ?? false)
{
if (spad.SelectedArea != null)
{
if (portAreas.ContainsKey(spad.SelectedArea))
{
var pair = portAreas.SingleOrDefault(p => p.Key == spad.SelectedArea);
this.comboBoxPortArea.SelectedItem = pair;
}
}
}
}
}
private void CoreTextBox_TextChanged(object sender, TextChangedEventArgs e)
{
this.OnNotificationClassChanged(null);
}
private void comboBox_AgentTemplate_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
Trace.WriteLine("combo selection changed");
if (this.comboBox_AgentTemplate.SelectedItem is AGNT_Template at)
{
this.textBoxTemplateTitle.Text = at.AgentTitle;
this.buttonDeleteTemplate.IsEnabled = true;
this.buttonSetTemplate.IsEnabled = true;
this._currentTemplate = at;
}
}
private void buttonSetTemplate_Click(object sender, RoutedEventArgs e)
{
if (this._currentTemplate == null) return;
// confirm overwrite of waste disposal service provider
if (this.textBox_WasteDisposalServiceProvider.Text.Length > 0)
{
string message = string.Format(Properties.Resources.textConfirmWSDPOverwrite, this.textBox_WasteDisposalServiceProvider.Text, this._currentTemplate.WasteDisposalServiceProviderName);
if (MessageBox.Show(message, Properties.Resources.textConfirmation, MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.No)
== MessageBoxResult.No) { return; }
}
this._undoTemplate = createFromCurrentText(null, null);
this.textBox_AgentCity.Text = this._currentTemplate.AgentCity;
this.textBox_AgentCity.GetBindingExpression(TextBox.TextProperty).UpdateSource();
this.textBox_AgentCompanyName.Text = this._currentTemplate.AgentCompanyName;
this.textBox_AgentCompanyName.GetBindingExpression(TextBox.TextProperty).UpdateSource();
this.textBox_AgentCountry.Text = this._currentTemplate.AgentCountry;
this.textBox_AgentCountry.GetBindingExpression(TextBox.TextProperty).UpdateSource();
this.textBox_AgentEMail.Text = this._currentTemplate.AgentEMail;
this.textBox_AgentEMail.GetBindingExpression(TextBox.TextProperty).UpdateSource();
this.textBox_AgentFax.Text = this._currentTemplate.AgentFax;
this.textBox_AgentFax.GetBindingExpression(TextBox.TextProperty).UpdateSource();
this.textBox_AgentFirstName.Text = this._currentTemplate.AgentFirstName;
this.textBox_AgentFirstName.GetBindingExpression(TextBox.TextProperty).UpdateSource();
this.textBox_AgentLastName.Text = this._currentTemplate.AgentLastName;
this.textBox_AgentLastName.GetBindingExpression(TextBox.TextProperty).UpdateSource();
this.textBox_AgentPhone.Text = this._currentTemplate.AgentPhone;
this.textBox_AgentPhone.GetBindingExpression(TextBox.TextProperty).UpdateSource();
this.textBox_AgentPostalCode.Text = this._currentTemplate.AgentPostalCode;
this.textBox_AgentPostalCode.GetBindingExpression(TextBox.TextProperty).UpdateSource();
this.textBox_AgentStreetAndNumber.Text = this._currentTemplate.AgentStreetAndNumber;
this.textBox_AgentStreetAndNumber.GetBindingExpression(TextBox.TextProperty).UpdateSource();
if (this._currentTemplate.WasteDisposalServiceProviderName != this.textBox_WasteDisposalServiceProvider.Text)
{
this.textBox_WasteDisposalServiceProvider.Text = this._currentTemplate.WasteDisposalServiceProviderName;
this.textBox_WasteDisposalServiceProvider.GetBindingExpression(TextBox.TextProperty).UpdateSource();
this.SublistElementChanged(Message.NotificationClass.WAS);
}
this.buttonUndoTemplate.IsEnabled = true;
this.buttonSetTemplate.IsEnabled = false;
this.comboBox_AgentTemplate.SelectedItem = null;
this.textBoxTemplateTitle.Text = "";
this._currentTemplate = null;
}
private void buttonSaveTemplate_Click(object sender, RoutedEventArgs e)
{
string title = this.textBoxTemplateTitle.Text.Trim();
if (title.IsNullOrEmpty())
{
MessageBox.Show("Title may not be empty", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
return;
}
AGNT_Template existingTemplate = null;
foreach (AGNT_Template anExistingTemplate in _agntTemplates)
{
if (anExistingTemplate.AgentTitle.Equals(title, StringComparison.OrdinalIgnoreCase))
{
existingTemplate = anExistingTemplate;
break;
}
}
if (existingTemplate != null)
{
if (MessageBox.Show("A template with this name already exists, overwrite?", "Confirmation", MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.No) == MessageBoxResult.No)
return;
}
this._currentTemplate = createFromCurrentText(title, existingTemplate);
DBManager.Instance.Save(this._currentTemplate);
if (existingTemplate == null)
{
comboBox_AgentTemplate.ItemsSource = null;
_agntTemplates.Add(this._currentTemplate);
_agntTemplates.Sort();
comboBox_AgentTemplate.ItemsSource = _agntTemplates;
}
MessageBox.Show("Template saved", "OK", MessageBoxButton.OK, MessageBoxImage.Information);
}
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.comboBox_AgentTemplate.SelectedItem = null;
this.comboBox_AgentTemplate.ItemsSource = null;
DBManager.Instance.Delete(_currentTemplate);
_agntTemplates.Remove(_currentTemplate);
this.textBoxTemplateTitle.Text = null;
this.buttonDeleteTemplate.IsEnabled = false;
this.comboBox_AgentTemplate.ItemsSource = _agntTemplates;
this.buttonSetTemplate.IsEnabled = false;
}
}
}
private void buttonUndoTemplate_Click(object sender, RoutedEventArgs e)
{
this.textBox_AgentCity.Text = this._undoTemplate.AgentCity;
this.textBox_AgentCity.GetBindingExpression(TextBox.TextProperty).UpdateSource();
this.textBox_AgentCompanyName.Text = this._undoTemplate.AgentCompanyName;
this.textBox_AgentCompanyName.GetBindingExpression(TextBox.TextProperty).UpdateSource();
this.textBox_AgentCountry.Text = this._undoTemplate.AgentCountry;
this.textBox_AgentCountry.GetBindingExpression(TextBox.TextProperty).UpdateSource();
this.textBox_AgentEMail.Text = this._undoTemplate.AgentEMail;
this.textBox_AgentEMail.GetBindingExpression(TextBox.TextProperty).UpdateSource();
this.textBox_AgentFax.Text = this._undoTemplate.AgentFax;
this.textBox_AgentFax.GetBindingExpression(TextBox.TextProperty).UpdateSource();
this.textBox_AgentFirstName.Text = this._undoTemplate.AgentFirstName;
this.textBox_AgentFirstName.GetBindingExpression(TextBox.TextProperty).UpdateSource();
this.textBox_AgentLastName.Text = this._undoTemplate.AgentLastName;
this.textBox_AgentLastName.GetBindingExpression(TextBox.TextProperty).UpdateSource();
this.textBox_AgentPhone.Text = this._undoTemplate.AgentPhone;
this.textBox_AgentPhone.GetBindingExpression(TextBox.TextProperty).UpdateSource();
this.textBox_AgentPostalCode.Text = this._undoTemplate.AgentPostalCode;
this.textBox_AgentPostalCode.GetBindingExpression(TextBox.TextProperty).UpdateSource();
this.textBox_AgentStreetAndNumber.Text = this._undoTemplate.AgentStreetAndNumber;
this.textBox_AgentStreetAndNumber.GetBindingExpression(TextBox.TextProperty).UpdateSource();
this.textBox_WasteDisposalServiceProvider.Text = this._undoTemplate.WasteDisposalServiceProviderName;
this.textBox_WasteDisposalServiceProvider.GetBindingExpression(TextBox.TextProperty).UpdateSource();
this.SublistElementChanged(Message.NotificationClass.WAS);
this.buttonUndoTemplate.IsEnabled = false; // can't undo after undo
}
private AGNT_Template createFromCurrentText(string title, AGNT_Template existingTemplate)
{
AGNT_Template at = new AGNT_Template();
if (existingTemplate != null)
at = existingTemplate;
at.AgentTitle = title;
at.AgentCity = this.textBox_AgentCity.Text;
at.AgentCompanyName = this.textBox_AgentCompanyName.Text;
at.AgentCountry = this.textBox_AgentCountry.Text;
at.AgentEMail = this.textBox_AgentEMail.Text;
at.AgentFax = this.textBox_AgentFax.Text;
at.AgentFirstName = this.textBox_AgentFirstName.Text;
at.AgentLastName = this.textBox_AgentLastName.Text;
at.AgentPhone = this.textBox_AgentPhone.Text;
at.AgentPostalCode = this.textBox_AgentPostalCode.Text;
at.AgentStreetAndNumber = textBox_AgentStreetAndNumber.Text;
at.WasteDisposalServiceProviderName = textBox_WasteDisposalServiceProvider.Text;
return at;
}
private void buttonAddMissingEntries_Click(object sender, RoutedEventArgs e)
{
this._was.AddMissingWaste();
if (this._was.Waste.Count < 15)
{
Waste newWaste = new Waste
{
Identifier = DatabaseEntity.GetNewIdentifier(this._was.Waste),
WAS = this._was,
WasteAmountGeneratedTillNextPort_MTQ = 0,
WasteAmountRetained_MTQ = 0,
WasteCapacity_MTQ = 0,
WasteDescription = "",
WasteDisposalAmount_MTQ = 0,
WasteDisposalPort = "ZZUKN"
};
this._was.Waste.Add(newWaste);
}
this.SublistElementChanged(Message.NotificationClass.WAS);
this.dataGridWaste.Items.Refresh();
}
private void buttonImportFromExcel_Click(object sender, RoutedEventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "Excel Files|*.xls;*.xlsx";
if (ofd.ShowDialog() ?? false)
{
FileStream stream;
try
{
stream = File.Open(ofd.FileName, FileMode.Open, FileAccess.Read);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
return;
}
using (var reader = ExcelReaderFactory.CreateReader(stream))
{
List<Waste> importWasteList = new List<Waste>();
try
{
do
{
// skip first three rows
reader.Read();
reader.Read();
reader.Read();
int cnt = 0;
object o = null;
// Diese Funktion kann das "alte" Sheet Format nicht mehr einlesen!
while (reader.Read() && (cnt < 35))
{
if (reader.FieldCount < 9)
{
throw new InvalidDataException("Sheet must have 9 Columns of data");
}
if (!reader.IsDBNull(1)) o = reader.GetValue(1); else o = null;
if ((o != null) && Int32.TryParse(o.ToString(), out int wasteType))
{
Waste waste = _was.GetWasteForType(wasteType);
if (waste == null)
{
waste = new Waste();
waste.WasteType = wasteType;
waste.WAS = this._was;
waste.IsDirty = true;
waste.Identifier = Waste.GetNewIdentifier(this._was.Waste);
this._was.Waste.Add(waste);
}
else
{
waste.IsDirty = true;
}
if (!reader.IsDBNull(4)) waste.WasteDescription = reader.GetString(4);
if (waste.WasteDescription.IsNullOrEmpty())
waste.WasteDescription = "-";
if (!reader.IsDBNull(5)) o = reader.GetValue(5); else o = null;
if (o != null) waste.WasteDisposalAmount_MTQ = Convert.ToDouble(o);
if (!reader.IsDBNull(6)) o = reader.GetValue(6); else o = null;
if (o != null) waste.WasteCapacity_MTQ = Convert.ToDouble(o);
if (!reader.IsDBNull(7)) o = reader.GetValue(7); else o = null;
if (o != null) waste.WasteAmountRetained_MTQ = Convert.ToDouble(o);
if (!reader.IsDBNull(8)) waste.WasteDisposalPort = reader.GetString(8).ToUpper();
if (!reader.IsDBNull(9)) o = reader.GetValue(9); else o = null;
if (o != null) waste.WasteAmountGeneratedTillNextPort_MTQ = Convert.ToDouble(o);
importWasteList.Add(waste);
cnt++;
}
}
} while (reader.NextResult());
}
catch (Exception ex)
{
MessageBox.Show("Error reading Excel: " + ex.Message, Properties.Resources.textCaptionError, MessageBoxButton.OK, MessageBoxImage.Error);
}
if (importWasteList.Count > 0)
{
this.dataGridWaste.Items.Refresh();
this.SublistElementChanged(Message.NotificationClass.WAS);
MessageBox.Show(String.Format(Properties.Resources.textWasteImported, importWasteList.Count), Properties.Resources.textCaptionInformation, MessageBoxButton.OK, MessageBoxImage.Information);
}
}
stream.Close();
}
}
#endregion
#region special entry ship service check
private void CheckServiceEntryMaerskBHV()
{
bool found = false;
foreach (SERV serv in _servMessage.Elements.Cast<SERV>())
{
if (serv.ServiceBeneficiary.Equals("Maersk A/S, Esplanaden 50, DK-1263 Copenhagen K, VAT-ID: DK53139655"))
found = true;
}
if (!found)
{
SERV newServ = new SERV();
newServ.ServiceBeneficiary = "Maersk A/S, Esplanaden 50, DK-1263 Copenhagen K, VAT-ID: DK53139655";
newServ.ServiceInvoiceRecipient = "Maersk Deutschland A/S & Co.KG, Johanniswall 7, 20095 Hamburg";
newServ.ServiceName = "Maersk BHV";
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 CheckServiceEntrySeaGoBHV()
{
bool found = false;
foreach (SERV serv in _servMessage.Elements.Cast<SERV>())
{
if (serv.ServiceBeneficiary.Equals("Sealand Europe A/S, Dampfaergevej 10, 3.tv, DK- 2100 Copenhagen, VAT-ID: DK53139655"))
found = true;
}
if (!found)
{
SERV newServ = new SERV();
newServ.ServiceBeneficiary = "Sealand Europe A/S, Dampfaergevej 10, 3.tv, DK- 2100 Copenhagen, VAT-ID: DK53139655";
newServ.ServiceInvoiceRecipient = "Maersk Deutschland A/S & Co. KG on behalf of Sealand Europe A/S, Johanniswall 7, 20095 Hamburg";
newServ.ServiceName = "SeaGo BHV";
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 CheckServiceEntryHoegh()
{
bool found = false;
foreach (SERV serv in _servMessage.Elements.Cast<SERV>())
{
if (serv.ServiceBeneficiary.Equals("Höegh Autoliners AS, Oslo, Norway"))
found = true;
}
if (!found)
{
SERV newServ = new SERV();
newServ.ServiceBeneficiary = "Höegh Autoliners AS, Oslo, Norway";
newServ.ServiceInvoiceRecipient = " PWL Port Services GmbH & Co. KG";
newServ.ServiceName = "HOEGH BHV";
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 CheckServiceEntryFctJunge()
{
bool found = false;
foreach (SERV serv in _servMessage.Elements.Cast<SERV>())
{
if (serv.ServiceName.Equals("Fct Junge - Hamburg"))
found = true;
}
if (!found)
{
SERV newServ = new SERV();
newServ.ServiceBeneficiary = "";
newServ.ServiceInvoiceRecipient = " Frachtcontor Junge & Co. GmbH";
newServ.ServiceName = "Fct Junge - Hamburg";
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 CheckServiceEntryElbeBulk()
{
bool found = false;
foreach (SERV serv in _servMessage.Elements.Cast<SERV>())
{
if (serv.ServiceName.Equals("Elbe Bulk Schiffe - Hamburg"))
found = true;
}
if (!found)
{
SERV newServ = new SERV();
newServ.ServiceBeneficiary = "";
newServ.ServiceInvoiceRecipient = " Division Elbe Bulk, Frachtcontor Junge & Co. GmbH";
newServ.ServiceName = "Elbe Bulk Schiffe - Hamburg";
newServ.MessageHeader = this._servMessage;
newServ.Identifier = SERV.GetNewIdentifier(_servMessage.Elements);
this._servMessage.Elements.Add(newServ);
this.dataGridSERV.Items.Refresh();
this.SublistElementChanged(Message.NotificationClass.SERV);
}
}
#endregion
#region Templates
private async Task InitTemplates()
{
_wsdpTemplates = await DBManagerAsync.GetWasteDisposalServiceProviderTemplatesAsync();
_wsdpTemplates.Sort();
this.comboBox_WSDPTemplate.ItemsSource = null;
this.comboBox_WSDPTemplate.ItemsSource = _wsdpTemplates;
Trace.WriteLine($"{_wsdpTemplates.Count} WSDP templates loaded");
}
private void comboBox_WSDPTemplate_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
Trace.WriteLine("WSDP combo selection changed");
if (this.comboBox_WSDPTemplate.SelectedItem is WasteDisposalServiceProvider_Template wdsp_t)
{
this.textBoxTemplateTitle.Text = wdsp_t.Remark;
this.buttonDeleteTemplate.IsEnabled = true;
this._currentWSDPTemplate = wdsp_t;
this._undoWSDPTemplate = this.textBoxWasteDisposalServiceProviders.Text.Trim();
this.buttonUndoTemplate.IsEnabled = this._undoWSDPTemplate.Length > 0;
this.textBoxWasteDisposalServiceProviders.Text = wdsp_t.WasteDisposalServiceProviderName;
}
}
private async void buttonSaveWasteTemplate_Click(object sender, RoutedEventArgs e)
{
string currentWSDPProviderName = this.textBoxWasteDisposalServiceProviders.Text.Trim();
string currentRemark = this.textBoxTemplateTitle.Text.Trim();
if ((currentWSDPProviderName.Length == 0) || (currentRemark.Length == 0)) return;
WasteDisposalServiceProvider_Template existingTemplate = null;
foreach (WasteDisposalServiceProvider_Template wdsp_template in _wsdpTemplates)
{
// bei gefundenem Match wird ggf. der Remark überschrieben
if (wdsp_template.Remark.Equals(currentRemark))
{
existingTemplate = wdsp_template;
break;
}
}
if (existingTemplate != null)
{
if (MessageBox.Show("A template with this name already exists, overwrite?", "Confirmation", MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.No) == MessageBoxResult.No)
return;
existingTemplate.WasteDisposalServiceProviderName = currentWSDPProviderName;
await DBManagerAsync.SaveAsync(existingTemplate);
return;
}
WasteDisposalServiceProvider_Template newTemplate = new WasteDisposalServiceProvider_Template();
newTemplate.WasteDisposalServiceProviderName = currentWSDPProviderName;
newTemplate.Remark = currentRemark;
await DBManagerAsync.SaveAsync(newTemplate);
comboBox_WSDPTemplate.ItemsSource = null;
_wsdpTemplates.Add(newTemplate);
_wsdpTemplates.Sort();
comboBox_WSDPTemplate.ItemsSource = _wsdpTemplates;
MessageBox.Show("Template saved", "OK", MessageBoxButton.OK, MessageBoxImage.Information);
}
private void buttonDeleteWasteTemplate_Click(object sender, RoutedEventArgs e)
{
if (_currentWSDPTemplate != null)
{
if (MessageBox.Show("Delete this template?", "Confirmation", MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.No) == MessageBoxResult.Yes)
{
this.comboBox_WSDPTemplate.SelectedItem = null;
this.comboBox_WSDPTemplate.ItemsSource = null;
DBManager.Instance.Delete(_currentTemplate);
_wsdpTemplates.Remove(_currentWSDPTemplate);
this.textBoxTemplateTitle.Text = null;
this.buttonDeleteTemplate.IsEnabled = false;
this.comboBox_WSDPTemplate.ItemsSource = _wsdpTemplates;
}
}
}
private void buttonUndoWasteTemplate_Click(object sender, RoutedEventArgs e)
{
if (this._undoWSDPTemplate != null)
{
this.textBoxWasteDisposalServiceProviders.Text = this._undoWSDPTemplate;
this.buttonUndoTemplate.IsEnabled = false;
this._undoWSDPTemplate = null;
this.comboBox_WSDPTemplate.SelectedItem = null;
}
}
#endregion
#region datagrid call purposes
private void DataGridCallPurposes_DeleteRequested(DatabaseEntity obj)
{
if (obj is CallPurpose cp)
{
// are you sure dialog is in base class
_noa_nod.CallPurposes.Remove(cp);
DBManager.GetSingleCon(Properties.Settings.Default.ConnectionString).Delete(cp);
DatabaseEntity.ResetIdentifiers(new List<DatabaseEntity>(_noa_nod.CallPurposes));
this.SublistElementChanged(Message.NotificationClass.NOA_NOD);
this.dataGridCallPurposes.Items.Refresh();
}
}
private void DataGridCallPurposes_CreateRequested()
{
EditCallPurposeDialog ecpd = new EditCallPurposeDialog();
ecpd.AddClicked += () =>
{
ecpd.CopyValuesToEntity();
if (!_noa_nod.CallPurposes.Contains(ecpd.CallPurpose))
_noa_nod.CallPurposes.Add(ecpd.CallPurpose);
this.dataGridCallPurposes.Items.Refresh();
ecpd.CallPurpose = new CallPurpose();
ecpd.CallPurpose.Identifier = CallPurpose.GetNewIdentifier(_noa_nod.CallPurposes);
ecpd.CallPurpose.NOA_NOD = this._noa_nod;
this.SublistElementChanged(Message.NotificationClass.NOA_NOD);
};
ecpd.CallPurpose = new CallPurpose();
ecpd.CallPurpose.Identifier = CallPurpose.GetNewIdentifier(_noa_nod.CallPurposes);
ecpd.CallPurpose.NOA_NOD = this._noa_nod;
if (ecpd.ShowDialog() ?? false)
{
if (!_noa_nod.CallPurposes.Contains(ecpd.CallPurpose))
_noa_nod.CallPurposes.Add(ecpd.CallPurpose);
this.dataGridCallPurposes.Items.Refresh();
// signal up
this.SublistElementChanged(Message.NotificationClass.NOA_NOD);
}
}
private void DataGridCallPurposes_AddingNewItem(object sender, AddingNewItemEventArgs e)
{
this.DataGridCallPurposes_CreateRequested();
}
private void DataGridCallPurposes_EditRequested(DatabaseEntity obj)
{
EditCallPurposeDialog ecpd = new EditCallPurposeDialog();
ecpd.CallPurpose = obj as CallPurpose;
ecpd.AddClicked += () =>
{
ecpd.CopyValuesToEntity();
if (!_noa_nod.CallPurposes.Contains(ecpd.CallPurpose))
_noa_nod.CallPurposes.Add(ecpd.CallPurpose);
this.dataGridCallPurposes.Items.Refresh();
ecpd.CallPurpose = new CallPurpose();
ecpd.CallPurpose.Identifier = CallPurpose.GetNewIdentifier(_noa_nod.CallPurposes);
ecpd.CallPurpose.NOA_NOD = this._noa_nod;
this.SublistElementChanged(Message.NotificationClass.NOA_NOD);
};
if (ecpd.ShowDialog() ?? false)
{
if (!_noa_nod.CallPurposes.Contains(ecpd.CallPurpose))
_noa_nod.CallPurposes.Add(ecpd.CallPurpose);
this.dataGridCallPurposes.Items.Refresh();
// signal up
this.SublistElementChanged(Message.NotificationClass.NOA_NOD);
}
}
#endregion
#region datagrid SERV
private void DataGridSERV_CreateRequested()
{
EditSERVDialog esd = new EditSERVDialog();
esd.SERV = new SERV();
esd.SERV.Identifier = SERV.GetNewIdentifier(_servMessage.Elements);
esd.SERV.MessageHeader = _servMessage;
esd.AddClicked += () =>
{
esd.CopyValuesToEntity();
if (!_servMessage.Elements.Contains(esd.SERV))
_servMessage.Elements.Add(esd.SERV);
this.dataGridSERV.Items.Refresh();
esd.SERV = new SERV();
esd.SERV.MessageHeader = _servMessage;
esd.SERV.Identifier = SERV.GetNewIdentifier(_servMessage.Elements);
this.SublistElementChanged(Message.NotificationClass.SERV);
};
if (esd.ShowDialog() ?? false)
{
if (!_servMessage.Elements.Contains(esd.SERV))
_servMessage.Elements.Add(esd.SERV);
this.dataGridSERV.Items.Refresh();
this.SublistElementChanged(Message.NotificationClass.SERV);
}
}
private void DataGridSERV_DeleteRequested(DatabaseEntity obj)
{
if (obj is SERV serv)
{
// are you sure dialog is in base class
_servMessage.Elements.Remove(serv);
DBManager.GetSingleCon(Properties.Settings.Default.ConnectionString).Delete(serv);
DatabaseEntity.ResetIdentifiers(_servMessage.Elements);
this.SublistElementChanged(Message.NotificationClass.SERV);
this.dataGridSERV.Items.Refresh();
}
}
private void DataGridSERV_EditRequested(DatabaseEntity obj)
{
EditSERVDialog esd = new EditSERVDialog();
esd.SERV = obj as SERV;
esd.AddClicked += () =>
{
esd.CopyValuesToEntity();
if (!_servMessage.Elements.Contains(esd.SERV))
_servMessage.Elements.Add(esd.SERV);
this.dataGridSERV.Items.Refresh();
esd.SERV = new SERV();
esd.SERV.Identifier = SERV.GetNewIdentifier(_servMessage.Elements);
esd.SERV.MessageHeader = _servMessage;
this.SublistElementChanged(Message.NotificationClass.SERV);
};
if (esd.ShowDialog() ?? false)
{
if (!_servMessage.Elements.Contains(esd.SERV))
_servMessage.Elements.Add(esd.SERV);
this.dataGridSERV.Items.Refresh();
this.SublistElementChanged(Message.NotificationClass.SERV);
}
}
private void DataGridSERV_AddingNewItem(object sender, AddingNewItemEventArgs e)
{
this.DataGridSERV_CreateRequested();
}
#endregion
#region datagrid LADG
private void DataGridLADG_CreateRequested()
{
this.dataGridLADG.CancelEdit();
this.dataGridLADG.CancelEdit();
EditLADGDialog eld = new EditLADGDialog();
eld.LADG = new LADG();
eld.LADG.MessageHeader = _ladgMessage;
eld.LADG.Identifier = LADG.GetNewIdentifier(_ladgMessage.Elements);
eld.Core = this.Core;
eld.AddClicked += () =>
{
eld.CopyValuesToEntity();
if (!this._ladgMessage.Elements.Contains(eld.LADG))
this._ladgMessage.Elements.Add(eld.LADG);
this.dataGridLADG.Items.Refresh();
eld.LADG = new LADG();
eld.LADG.MessageHeader = _ladgMessage;
eld.LADG.Identifier = LADG.GetNewIdentifier(_ladgMessage.Elements);
this.SublistElementChanged(Message.NotificationClass.LADG);
};
if (eld.ShowDialog() ?? false)
{
if (!_ladgMessage.Elements.Contains(eld.LADG))
_ladgMessage.Elements.Add(eld.LADG);
this.dataGridLADG.Items.Refresh();
this.SublistElementChanged(Message.NotificationClass.LADG);
}
}
private void DataGridLADG_DeleteRequested(DatabaseEntity obj)
{
if (obj is LADG ladg)
{
this.dataGridLADG.CancelEdit();
this.dataGridLADG.CancelEdit();
// are you sure dialog is in base class
this._ladgMessage.Elements.Remove(ladg);
DBManager.GetSingleCon(Properties.Settings.Default.ConnectionString).Delete(ladg);
DatabaseEntity.ResetIdentifiers(_ladgMessage.Elements);
this.SublistElementChanged(Message.NotificationClass.LADG);
this.dataGridLADG.Items.Refresh();
}
}
private void DataGridLADG_EditRequested(DatabaseEntity obj)
{
this.dataGridLADG.CancelEdit();
this.dataGridLADG.CancelEdit();
LADG ladg = obj as LADG;
EditLADGDialog eld = new EditLADGDialog();
eld.Core = this.Core;
eld.LADG = ladg;
eld.AddClicked += () =>
{
eld.CopyValuesToEntity();
if (!_ladgMessage.Elements.Contains(eld.LADG))
_ladgMessage.Elements.Add(eld.LADG);
this.dataGridLADG.Items.Refresh();
eld.LADG = new LADG();
eld.LADG.Identifier = LADG.GetNewIdentifier(_ladgMessage.Elements);
eld.LADG.MessageHeader = _ladgMessage;
this.SublistElementChanged(Message.NotificationClass.LADG);
};
if (eld.ShowDialog() ?? false)
{
if (!_ladgMessage.Elements.Contains(eld.LADG))
_ladgMessage.Elements.Add(eld.LADG);
this.dataGridLADG.Items.Refresh();
this.SublistElementChanged(Message.NotificationClass.LADG);
}
}
private void DataGridLADG_AddingNewItem(object sender, AddingNewItemEventArgs e)
{
this.DataGridLADG_CreateRequested();
}
#endregion
#region Waste grid event handler
private void DataGridWaste_CreateRequested()
{
EditWasteDialog epd = new EditWasteDialog();
epd.Waste = new Waste();
epd.Waste.Identifier = Waste.GetNewIdentifier(_was.Waste);
epd.Waste.WAS = this._was;
epd.AddClicked += () =>
{
epd.CopyValuesToEntity();
if (!this._was.Waste.Any(w => w.WasteType == epd.Waste.WasteType))
{
this._was.Waste.Add(epd.Waste);
this.dataGridWaste.Items.Refresh();
epd.Waste = new Waste();
epd.Waste.WAS = this._was;
epd.Waste.Identifier = Waste.GetNewIdentifier(_was.Waste);
this.SublistElementChanged(Message.NotificationClass.WAS);
}
};
if (epd.ShowDialog() ?? false)
{
if (!this._was.Waste.Any(w => w.WasteType == epd.Waste.WasteType))
{
_was.Waste.Add(epd.Waste);
this.dataGridWaste.Items.Refresh();
this.SublistElementChanged(Message.NotificationClass.WAS);
}
}
}
private void DataGridWaste_DeleteRequested(DatabaseEntity obj)
{
if (obj is Waste waste)
{
// are you sure dialog is in base class
_was.Waste.Remove(waste);
DBManager.GetSingleCon(Properties.Settings.Default.ConnectionString).Delete(waste);
DatabaseEntity.ResetIdentifiers(new List<DatabaseEntity>(_was.Waste));
this.SublistElementChanged(Message.NotificationClass.WAS);
this.dataGridWaste.Items.Refresh();
}
}
private void DataGridWaste_EditRequested(DatabaseEntity obj)
{
EditWasteDialog epd = new EditWasteDialog();
epd.Waste = obj as Waste;
epd.AddClicked += () =>
{
epd.CopyValuesToEntity();
if (!_was.Waste.Any(w => w.WasteType == epd.Waste.WasteType))
{
_was.Waste.Add(epd.Waste);
this.dataGridWaste.Items.Refresh();
epd.Waste = new Waste();
epd.Waste.Identifier = Waste.GetNewIdentifier(_was.Waste);
epd.Waste.WAS = _was;
this.SublistElementChanged(Message.NotificationClass.WAS);
}
};
if (epd.ShowDialog() ?? false)
{
if (!_was.Waste.Contains(epd.Waste))
_was.Waste.Add(epd.Waste);
this.dataGridWaste.Items.Refresh();
this.SublistElementChanged(Message.NotificationClass.WAS);
}
}
private void DataGridWaste_AddingNewItem(object sender, AddingNewItemEventArgs e)
{
this.DataGridWaste_CreateRequested();
}
#endregion
#region SERV template button event handler
private void comboBoxGroup_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (this.comboBoxGroup.SelectedItem is SERV_Template st)
{
this.buttonDeleteSERVTemplate.IsEnabled = true;
this.buttonSetSERVTemplate.IsEnabled = true;
this._currentSERVTemplate = st;
}
}
private void buttonSetSERVTemplate_Click(object sender, RoutedEventArgs e)
{
if (this.comboBoxGroup.SelectedItem is SERV_Template st)
{
bool found = false;
foreach (SERV serv in _servMessage.Elements.Cast<SERV>())
{
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 buttonEditSERVTemplate_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 buttonNewSERVTemplate_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 buttonDeleteSERVTemplate_Click(object sender, RoutedEventArgs e)
{
if (_currentSERVTemplate != 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(_currentSERVTemplate);
this.buttonDeleteSERVTemplate.IsEnabled = false;
this.comboBoxGroup.ItemsSource = _servTemplates;
this.buttonSetSERVTemplate.IsEnabled = false;
}
}
}
#endregion
}
}