Added templates for WAS_RCPT the same as for WAS. Templates are shared between these controls
This commit is contained in:
parent
d4db41de2c
commit
e0ca7a9074
@ -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");
|
||||
|
||||
@ -14,6 +14,7 @@
|
||||
<RowDefinition Height="28" />
|
||||
<RowDefinition Height="28" />
|
||||
<RowDefinition Height="28" />
|
||||
<RowDefinition Height="28" />
|
||||
<RowDefinition Height="56" />
|
||||
<RowDefinition Height="28" />
|
||||
<RowDefinition Height="28" />
|
||||
@ -30,16 +31,48 @@
|
||||
<Label Name="labelIdentificationNumber" Grid.Row="0" Grid.Column="0" Content="{x:Static p:Resources.textIdentificationNumber}" />
|
||||
<Label Name="labelPortReceptionFacilityName" Grid.Row="1" Grid.Column="0" Content="{x:Static p:Resources.textPortReceptionFacilityName}" />
|
||||
<Label Name="labelPortReceptionFacilityProviderName" Grid.Row="2" Grid.Column="0" Content="{x:Static p:Resources.textPortReceptionFacilityProviderName}" />
|
||||
<Label Name="labelTreatmentFacilityProvider" Grid.Row="3" Grid.Column="0" Content="{x:Static p:Resources.textTreatmentFacilityProviderDisplay}" />
|
||||
<Label Name="labelWasteDeliveryDateFrom" Grid.Row="4" Grid.Column="0" Content="{x:Static p:Resources.textWasteDeliveryDateFrom}" />
|
||||
<Label Name="labelWasteDeliveryDateTo" Grid.Row="5" Grid.Column="0" Content="{x:Static p:Resources.textWasteDeliveryDateTo}" />
|
||||
<Label Name="labelTemplate" Grid.Row="3" Grid.Column="0" Content="{x:Static p:Resources.textAgentTemplate}" />
|
||||
<Label Name="labelTreatmentFacilityProvider" Grid.Row="4" Grid.Column="0" Content="{x:Static p:Resources.textTreatmentFacilityProviderDisplay}" />
|
||||
<Label Name="labelWasteDeliveryDateFrom" Grid.Row="5" Grid.Column="0" Content="{x:Static p:Resources.textWasteDeliveryDateFrom}" />
|
||||
<Label Name="labelWasteDeliveryDateTo" Grid.Row="6" Grid.Column="0" Content="{x:Static p:Resources.textWasteDeliveryDateTo}" />
|
||||
|
||||
<TextBox Name="textIdentificationNumber" Grid.Row="0" Grid.Column="1" Width="auto" MaxLength="20" TextWrapping="Wrap" Margin="2" VerticalContentAlignment="Center"/>
|
||||
<TextBox Name="textBoxPortReceptionFacilityName" Grid.Row="1" Grid.Column="1" Width="auto" MaxLength="70" TextWrapping="Wrap" Margin="2" VerticalContentAlignment="Center"/>
|
||||
<TextBox Name="textBoxPortReceptionFacilityProviderName" Grid.Row="2" Grid.Column="1" Width="auto" MaxLength="70" TextWrapping="Wrap" Margin="2" VerticalContentAlignment="Center"/>
|
||||
<TextBox Name="textBoxTreatmentFacilityProvider" Grid.Row="3" Grid.Column="1" Height="56" VerticalContentAlignment="Top" Margin="2"/>
|
||||
<xctk:DateTimePicker Grid.Row="4" Grid.Column="1" Name="dateTimePickerWasteDeliveryDateFrom" Format="Custom" FormatString="dd.MM.yyyy HH:mm" ShowButtonSpinner="False" VerticalContentAlignment="Center" Margin="2" AllowTextInput="True" ContextMenu="{DynamicResource ClearContextMenu}" TextAlignment="Left" Minimum="1899.12.31 00:00" Maximum="2100.12.31 00:00" PreviewKeyUp="DateTimePicker_PreviewKeyUp"/>
|
||||
<xctk:DateTimePicker Grid.Row="5" Grid.Column="1" Name="dateTimePickerWasteDeliveryDateTo" Format="Custom" FormatString="dd.MM.yyyy HH:mm" ShowButtonSpinner="False" VerticalContentAlignment="Center" Margin="2" AllowTextInput="True" ContextMenu="{DynamicResource ClearContextMenu}" TextAlignment="Left" Minimum="1899.12.31 00:00" Maximum="2100.12.31 00:00" PreviewKeyUp="DateTimePicker_PreviewKeyUp"/>
|
||||
<Grid Grid.Row="3" Grid.Column="1" Grid.ColumnSpan="1" Name="gridTemplateControls" Visibility="Visible">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width=".5*"/>
|
||||
<ColumnDefinition Width=".5*"/>
|
||||
<!-- Name -->
|
||||
<ColumnDefinition Width="26"/>
|
||||
<!-- Save button -->
|
||||
<ColumnDefinition Width="26"/>
|
||||
<!-- Delete button -->
|
||||
<ColumnDefinition Width="52"/>
|
||||
<!-- Undo button -->
|
||||
</Grid.ColumnDefinitions>
|
||||
<ComboBox Grid.Column="0" Name="comboBox_WSDPTemplate" Margin="2" SelectedValuePath="Id" DisplayMemberPath="Remark" SelectionChanged="comboBox_WSDPTemplate_SelectionChanged" />
|
||||
<TextBox Grid.Column="1" Margin="2" Name="textBoxTemplateTitle" VerticalContentAlignment="Center"/>
|
||||
<Button Name="buttonSaveTemplate" Grid.Column="2" Grid.Row="0" Margin="2" Click="buttonSaveTemplate_Click" BorderThickness="0" Background="Transparent" ToolTip="Save template">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<Image Source="../Resources/floppy_disk_blue.png" Margin="0,0,0,0" Height="20" Width="20" />
|
||||
</StackPanel>
|
||||
</Button>
|
||||
<Button Name="buttonDeleteTemplate" Grid.Column="3" Grid.Row="0" Margin="2" Click="buttonDeleteTemplate_Click" BorderThickness="0" Background="Transparent" ToolTip="Delete template" IsEnabled="False">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<Image Source="../Resources/delete.png" Margin="0,0,0,0" Height="20" Width="20" />
|
||||
</StackPanel>
|
||||
</Button>
|
||||
<Button Name="buttonUndoTemplate" Grid.Column="4" Grid.Row="0" Margin="22,2,2,2" Click="buttonUndoTemplate_Click" BorderThickness="0" Background="Transparent" ToolTip="Undo last overwrite" IsEnabled="False">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<Image Source="../Resources/undo.png" Margin="0,0,0,0" Height="20" Width="20" />
|
||||
</StackPanel>
|
||||
</Button>
|
||||
</Grid>
|
||||
|
||||
<TextBox Name="textBoxTreatmentFacilityProvider" Grid.Row="4" Grid.Column="1" Height="56" VerticalContentAlignment="Top" Margin="2"/>
|
||||
<xctk:DateTimePicker Grid.Row="5" Grid.Column="1" Name="dateTimePickerWasteDeliveryDateFrom" Format="Custom" FormatString="dd.MM.yyyy HH:mm" ShowButtonSpinner="False" VerticalContentAlignment="Center" Margin="2" AllowTextInput="True" ContextMenu="{DynamicResource ClearContextMenu}" TextAlignment="Left" Minimum="1899.12.31 00:00" Maximum="2100.12.31 00:00" PreviewKeyUp="DateTimePicker_PreviewKeyUp"/>
|
||||
<xctk:DateTimePicker Grid.Row="6" Grid.Column="1" Name="dateTimePickerWasteDeliveryDateTo" Format="Custom" FormatString="dd.MM.yyyy HH:mm" ShowButtonSpinner="False" VerticalContentAlignment="Center" Margin="2" AllowTextInput="True" ContextMenu="{DynamicResource ClearContextMenu}" TextAlignment="Left" Minimum="1899.12.31 00:00" Maximum="2100.12.31 00:00" PreviewKeyUp="DateTimePicker_PreviewKeyUp"/>
|
||||
|
||||
<!--Button x:Name="buttonAddEntries" Grid.Column="1" Grid.Row="7" Margin="2" Click="buttonAddEntries_Click" Width="170" Content="Add waste received entries" HorizontalAlignment="Left"/-->
|
||||
|
||||
|
||||
@ -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
|
||||
/// </summary>
|
||||
public partial class EditWasteReceiptDialog : EditWindowBase
|
||||
{
|
||||
|
||||
// TODO: "unstatic" the templates and take care they are synchronized between controls
|
||||
|
||||
private List<WasteDisposalServiceProvider_Template> _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 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;
|
||||
}
|
||||
}
|
||||
|
||||
// private void buttonAddEntries_Click(object sender, RoutedEventArgs e)
|
||||
// {
|
||||
// this.WAS_RCPT.AddMissingWasteReceived();
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user