diff --git a/ENI2/DetailViewControls/WasteDetailControl.xaml.cs b/ENI2/DetailViewControls/WasteDetailControl.xaml.cs
index 861b0782..6bcf8b99 100644
--- a/ENI2/DetailViewControls/WasteDetailControl.xaml.cs
+++ b/ENI2/DetailViewControls/WasteDetailControl.xaml.cs
@@ -185,12 +185,8 @@ namespace ENI2.DetailViewControls
#region init WSDP provider
- if(_wsdpTemplates == null)
- {
- _wsdpTemplates = await DBManagerAsync.GetWastDisposalServiceProviderTemplatesAsync();
- _wsdpTemplates.Sort();
- Trace.WriteLine($"{_wsdpTemplates.Count} WSDP templates loaded");
- }
+ InitTemplates();
+
this.comboBox_WSDPTemplate.ItemsSource = _wsdpTemplates;
#endregion
@@ -230,6 +226,7 @@ namespace ENI2.DetailViewControls
this.dataGridWasteReceived.ItemsSource = null;
dataGridWasteReceipt_SelectionChanged(this, null);
}
+ InitTemplates(); // templates might have changed in the dialog
}
private void DataGridWasteReceipt_DeleteRequested(DatabaseEntity obj)
@@ -275,6 +272,7 @@ namespace ENI2.DetailViewControls
this.dataGridWasteReceipt.Items.Refresh();
this.SublistElementChanged(Message.NotificationClass.WAS_RCPT);
dataGridWasteReceipt_SelectionChanged(this, null);
+ InitTemplates(); // templates might have changed in the dialog
}
private void DataGridWasteReceipt_AddingNewItem(object sender, AddingNewItemEventArgs e)
@@ -601,6 +599,15 @@ namespace ENI2.DetailViewControls
#region Waste disposal Service Provider templates event handler
+ private async void InitTemplates()
+ {
+ _wsdpTemplates = await DBManagerAsync.GetWastDisposalServiceProviderTemplatesAsync();
+ _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");
diff --git a/ENI2/EditControls/EditWasteReceiptDialog.xaml b/ENI2/EditControls/EditWasteReceiptDialog.xaml
index 9a5e8ec3..3179da1b 100644
--- a/ENI2/EditControls/EditWasteReceiptDialog.xaml
+++ b/ENI2/EditControls/EditWasteReceiptDialog.xaml
@@ -14,6 +14,7 @@
+
@@ -30,16 +31,48 @@
-
-
-
+
+
+
+
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/ENI2/EditControls/EditWasteReceiptDialog.xaml.cs b/ENI2/EditControls/EditWasteReceiptDialog.xaml.cs
index b0c994ce..aac2580f 100644
--- a/ENI2/EditControls/EditWasteReceiptDialog.xaml.cs
+++ b/ENI2/EditControls/EditWasteReceiptDialog.xaml.cs
@@ -3,6 +3,8 @@
//
using System;
+using System.Collections.Generic;
+using System.Diagnostics;
using System.Windows;
using bsmd.database;
@@ -15,6 +17,13 @@ namespace ENI2.EditControls
///
public partial class EditWasteReceiptDialog : EditWindowBase
{
+
+ // TODO: "unstatic" the templates and take care they are synchronized between controls
+
+ private List _wsdpTemplates = null;
+ private WasteDisposalServiceProvider_Template _currentTemplate;
+ private string _undoTemplate;
+
public EditWasteReceiptDialog()
{
InitializeComponent();
@@ -24,7 +33,7 @@ namespace ENI2.EditControls
public WAS_RCPT WAS_RCPT { get; set; }
- private void EditWasteReceiptDialog_Loaded(object sender, RoutedEventArgs e)
+ private async void EditWasteReceiptDialog_Loaded(object sender, RoutedEventArgs e)
{
this.textIdentificationNumber.Text = this.WAS_RCPT.IdentificationNumber;
this.textBoxPortReceptionFacilityName.Text = this.WAS_RCPT.PortReceptionFacilityName;
@@ -35,6 +44,12 @@ namespace ENI2.EditControls
OKClicked += EditWasteReceiptDialog_OKClicked;
this.AddVisible = true;
+
+ _wsdpTemplates = await DBManagerAsync.GetWastDisposalServiceProviderTemplatesAsync();
+ _wsdpTemplates.Sort();
+ Trace.WriteLine($"{_wsdpTemplates.Count} WSDP templates loaded");
+
+ this.comboBox_WSDPTemplate.ItemsSource = _wsdpTemplates;
}
public void CopyValuesToEntity()
{
@@ -52,10 +67,87 @@ namespace ENI2.EditControls
this.CopyValuesToEntity();
}
-
- // private void buttonAddEntries_Click(object sender, RoutedEventArgs e)
- // {
- // this.WAS_RCPT.AddMissingWasteReceived();
- // }
+ private void comboBox_WSDPTemplate_SelectionChanged(object sender, System.Windows.Controls.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._currentTemplate = wdsp_t;
+ this._undoTemplate = this.textBoxPortReceptionFacilityProviderName.Text.Trim();
+ this.buttonUndoTemplate.IsEnabled = this._undoTemplate.Length > 0;
+ this.textBoxPortReceptionFacilityProviderName.Text = wdsp_t.WasteDisposalServiceProviderName;
+ }
+ }
+
+ private async void buttonSaveTemplate_Click(object sender, RoutedEventArgs e)
+ {
+ string currentWSDPProviderName = this.textBoxPortReceptionFacilityProviderName.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 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_WSDPTemplate.SelectedItem = null;
+ this.comboBox_WSDPTemplate.ItemsSource = null;
+ DBManager.Instance.Delete(_currentTemplate);
+ _wsdpTemplates.Remove(_currentTemplate);
+ this.textBoxTemplateTitle.Text = null;
+ this.buttonDeleteTemplate.IsEnabled = false;
+ this.comboBox_WSDPTemplate.ItemsSource = _wsdpTemplates;
+ }
+ }
+ }
+
+ private void buttonUndoTemplate_Click(object sender, RoutedEventArgs e)
+ {
+ if (this._undoTemplate != null)
+ {
+ this.textBoxPortReceptionFacilityProviderName.Text = this._undoTemplate;
+ this.buttonUndoTemplate.IsEnabled = false;
+ this._undoTemplate = null;
+ this.comboBox_WSDPTemplate.SelectedItem = null;
+ }
+ }
+
}
}