// Copyright (c) 2017 schick Informatik // Description: Detailansicht Müllmeldung // using System.Linq; using System.Collections.Generic; using System.Windows; using System.Windows.Controls; using ENI2.EditControls; using ENI2.Util; using bsmd.database; using ExcelDataReader; using System.IO; using System; using Microsoft.Win32; using System.Diagnostics; namespace ENI2.DetailViewControls { /// /// Interaction logic for WasteDetailControl.xaml /// public partial class WasteDetailControl : DetailBaseControl { private Message _wasMessage; private WAS _was; private Message _wasRcptMessage; private WAS_RCPT _selectedWAS_RCPT; private static List _wsdpTemplates = null; private WasteDisposalServiceProvider_Template _currentTemplate; private string _undoTemplate; private static readonly string[] _wasteDeliveryList = { "ALL", "SOME", "NONE" }; public WasteDetailControl() { InitializeComponent(); Loaded += WasteDetailControl_Loaded; } private void WasteDetailControl_Loaded(object sender, RoutedEventArgs e) { this.RegisterLocodeChange(this.locodeCtrlLastWastePort, Message.NotificationClass.WAS); this.RegisterLocodeChange(this.locodeCtrlNextWastePort, Message.NotificationClass.WAS); this.RegisterCheckboxChange(this.checkBoxAccurateCorrectDetails, Message.NotificationClass.WAS); this.RegisterCheckboxChange(this.checkBoxValidExemption, Message.NotificationClass.WAS); this.RegisterDatePickerChange(this.datePickerDateLastDisposal, Message.NotificationClass.WAS); this.RegisterTextboxChange(this.textBoxWasteDisposalServiceProviders, Message.NotificationClass.WAS); } private void CheckBoxValidExemption_Checked(object sender, RoutedEventArgs e) { bool on = !(this.checkBoxValidExemption.IsChecked ?? false); this.checkBoxAccurateCorrectDetails.IsEnabled = on; this.locodeCtrlNextWastePort.IsEnabled = on; this.textBoxWasteDisposalServiceProviders.IsEnabled = on; this.dataGridWaste.IsEnabled = on; this.locodeCtrlLastWastePort.IsEnabled = on; this.datePickerDateLastDisposal.IsEnabled = on; } private void buttonAddMissingEntries_Click(object sender, RoutedEventArgs e) { // TODO: Das muss noch für NSW 7.0 gefixt werden, alles doppelt etc. 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 buttonWasteReceivedAddMissingEntries_Click(object sender, RoutedEventArgs e) { if (this._selectedWAS_RCPT != null) { this._selectedWAS_RCPT.AddMissingWasteReceived(); this.SublistElementChanged(Message.NotificationClass.WAS_RCPT); this.dataGridWasteReceived.Items.Refresh(); } } public async override void Initialize() { base.Initialize(); foreach (Message aMessage in this.Messages) { if (aMessage.MessageNotificationClass == Message.NotificationClass.WAS) { this._wasMessage = aMessage; this.ControlMessages.Add(aMessage); } if(aMessage.MessageNotificationClass == Message.NotificationClass.WAS_RCPT) { this._wasRcptMessage = aMessage; this.ControlMessages.Add(aMessage); } } #region init WAS if (this._wasMessage == null) { this._wasMessage = this.Core.CreateMessage(Message.NotificationClass.WAS); this.Messages.Add(this._wasMessage); } WAS was = null; if (this._wasMessage.Elements.Count > 0) was = this._wasMessage.Elements[0] as WAS; if (was == null) { was = new WAS(); was.MessageCore = this.Core; was.MessageHeader = this._wasMessage; _wasMessage.Elements.Add(was); } else { // remove "old" Waste Entries from display (not deleted in the DB!) for(int i = (was.Waste.Count - 1); i >= 0; i--) { if (was.Waste[i].WasteType > 999) was.Waste.RemoveAt(i); } } this.wasGroupBox.DataContext = was; this._was = 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.checkBoxValidExemption.Checked += CheckBoxValidExemption_Checked; this.checkBoxValidExemption.Unchecked += CheckBoxValidExemption_Checked; #endregion #region init WAS_RCPT if(this._wasRcptMessage == null) { this._wasRcptMessage = this.Core.CreateMessage(Message.NotificationClass.WAS_RCPT); this.Messages.Add(this._wasRcptMessage); } this.dataGridWasteReceipt.Initialize(); this.dataGridWasteReceipt.ItemsSource = this._wasRcptMessage.Elements; this.dataGridWasteReceipt.AddingNewItem += DataGridWasteReceipt_AddingNewItem; this.dataGridWasteReceipt.EditRequested += DataGridWasteReceipt_EditRequested; this.dataGridWasteReceipt.DeleteRequested += DataGridWasteReceipt_DeleteRequested; this.dataGridWasteReceipt.CreateRequested += DataGridWasteReceipt_CreateRequested; this.dataGridWasteReceived.Initialize(); this.dataGridWasteReceived.AddingNewItem += DataGridWasteReceived_AddingNewItem; this.dataGridWasteReceived.EditRequested += DataGridWasteReceived_EditRequested; this.dataGridWasteReceived.DeleteRequested += DataGridWasteReceived_DeleteRequested; this.dataGridWasteReceived.CreateRequested += DataGridWasteReceived_CreateRequested; if(this._wasRcptMessage.Elements.Count > 0) { this.dataGridWasteReceipt.SelectedItem = this._wasRcptMessage.Elements[0]; this.dataGridWasteReceipt_SelectionChanged(null, null); } #endregion #region init WSDP provider InitTemplates(); this.comboBox_WSDPTemplate.ItemsSource = _wsdpTemplates; #endregion } #region Waste receipt grid event handler private void DataGridWasteReceipt_CreateRequested() { EditWasteReceiptDialog epd = new EditWasteReceiptDialog(); epd.WAS_RCPT = new WAS_RCPT(); epd.WAS_RCPT.MessageHeader = _wasRcptMessage; epd.WAS_RCPT.Identifier = WAS_RCPT.GetNewIdentifier(_wasRcptMessage.Elements); epd.WAS_RCPT.AddMissingWasteReceived(); epd.AddClicked += () => { epd.CopyValuesToEntity(); if (!this._wasRcptMessage.Elements.Contains(epd.WAS_RCPT)) this._wasRcptMessage.Elements.Add(epd.WAS_RCPT); this.dataGridWasteReceipt.Items.Refresh(); epd.WAS_RCPT = new WAS_RCPT(); epd.WAS_RCPT.MessageHeader = _wasRcptMessage; epd.WAS_RCPT.Identifier = WAS_RCPT.GetNewIdentifier(_wasRcptMessage.Elements); epd.WAS_RCPT.AddMissingWasteReceived(); this.SublistElementChanged(Message.NotificationClass.WAS_RCPT); }; if (epd.ShowDialog() ?? false) { if (!this._wasRcptMessage.Elements.Contains(epd.WAS_RCPT)) _wasRcptMessage.Elements.Add(epd.WAS_RCPT); this.dataGridWasteReceipt.Items.Refresh(); this.dataGridWasteReceipt.SelectedItem = epd.WAS_RCPT; this.SublistElementChanged(Message.NotificationClass.WAS_RCPT); this.dataGridWasteReceived.ItemsSource = null; dataGridWasteReceipt_SelectionChanged(this, null); } InitTemplates(); // templates might have changed in the dialog } private void DataGridWasteReceipt_DeleteRequested(DatabaseEntity obj) { if (obj is WAS_RCPT wasRCPT) { // are you sure dialog is in base class _wasRcptMessage.Elements.Remove(wasRCPT); wasRCPT.DeleteElements(); DBManager.GetSingleCon(Properties.Settings.Default.ConnectionString).Delete(wasRCPT); DatabaseEntity.ResetIdentifiers(new List(_wasRcptMessage.Elements)); this.SublistElementChanged(Message.NotificationClass.WAS_RCPT); this.dataGridWasteReceipt.Items.Refresh(); this.dataGridWasteReceived.ItemsSource = null; this._selectedWAS_RCPT = null; } } private void DataGridWasteReceipt_EditRequested(DatabaseEntity obj) { EditWasteReceiptDialog epd = new EditWasteReceiptDialog(); epd.WAS_RCPT = obj as WAS_RCPT; epd.AddClicked += () => { epd.CopyValuesToEntity(); if (!_wasRcptMessage.Elements.Contains(epd.WAS_RCPT)) _wasRcptMessage.Elements.Add(epd.WAS_RCPT); this.dataGridWasteReceipt.Items.Refresh(); epd.WAS_RCPT = new WAS_RCPT(); epd.WAS_RCPT.Identifier = WAS_RCPT.GetNewIdentifier(_wasRcptMessage.Elements); epd.WAS_RCPT.MessageHeader = _wasRcptMessage; epd.WAS_RCPT.AddMissingWasteReceived(); this.SublistElementChanged(Message.NotificationClass.WAS_RCPT); }; if (epd.ShowDialog() ?? false) { if (!_wasRcptMessage.Elements.Contains(epd.WAS_RCPT)) _wasRcptMessage.Elements.Add(epd.WAS_RCPT); } this.dataGridWasteReceipt.SelectedItem = epd.WAS_RCPT; 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) { this.DataGridWasteReceipt_CreateRequested(); } private void dataGridWasteReceipt_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (this.dataGridWasteReceipt.SelectedItem is WAS_RCPT was_rcpt) { this.dataGridWasteReceived.ItemsSource = was_rcpt.WasteReceived; this._selectedWAS_RCPT = was_rcpt; } } #endregion #region Waste received grid event handler private void DataGridWasteReceived_DeleteRequested(DatabaseEntity obj) { if (obj is WasteReceived wasteReceived) { // are you sure dialog is in base class _selectedWAS_RCPT.WasteReceived.Remove(wasteReceived); DBManager.GetSingleCon(Properties.Settings.Default.ConnectionString).Delete(wasteReceived); DatabaseEntity.ResetIdentifiers(new List(_selectedWAS_RCPT.WasteReceived)); this.SublistElementChanged(Message.NotificationClass.WAS_RCPT); this.dataGridWasteReceived.Items.Refresh(); } } private void DataGridWasteReceived_CreateRequested() { if (_selectedWAS_RCPT == null) return; EditWasteReceivedDialog ewrd = new EditWasteReceivedDialog(); ewrd.WasteReceived = new WasteReceived(); ewrd.WasteReceived.WAS_RCPT = _selectedWAS_RCPT; ewrd.WasteReceived.Identifier = WasteReceived.GetNewIdentifier(_selectedWAS_RCPT.WasteReceived); ewrd.AddClicked += () => { ewrd.CopyValuesToEntity(); if ((ewrd.WasteReceived.WasteCode != null) && !this._selectedWAS_RCPT.WasteReceived.Any(wr => wr.WasteCode == ewrd.WasteReceived.WasteCode)) { this._selectedWAS_RCPT.WasteReceived.Add(ewrd.WasteReceived); this.dataGridWasteReceived.Items.Refresh(); ewrd.WasteReceived = new WasteReceived(); ewrd.WasteReceived.WAS_RCPT = _selectedWAS_RCPT; ewrd.WasteReceived.Identifier = WasteReceived.GetNewIdentifier(_selectedWAS_RCPT.WasteReceived); this.SublistElementChanged(Message.NotificationClass.WAS_RCPT); } }; if (ewrd.ShowDialog() ?? false) { if ((ewrd.WasteReceived.WasteCode != null) && !this._selectedWAS_RCPT.WasteReceived.Any(wr => wr.WasteCode == ewrd.WasteReceived.WasteCode)) { this._selectedWAS_RCPT.WasteReceived.Add(ewrd.WasteReceived); this.dataGridWasteReceived.Items.Refresh(); this.SublistElementChanged(Message.NotificationClass.WAS_RCPT); } } } private void DataGridWasteReceived_EditRequested(DatabaseEntity obj) { EditWasteReceivedDialog ewrd = new EditWasteReceivedDialog(); ewrd.WasteReceived = obj as WasteReceived; ewrd.AddClicked += () => { ewrd.CopyValuesToEntity(); if ((ewrd.WasteReceived.WasteCode != null) && !this._selectedWAS_RCPT.WasteReceived.Any(wr => wr.WasteCode == ewrd.WasteReceived.WasteCode)) { _selectedWAS_RCPT.WasteReceived.Add(ewrd.WasteReceived); this.dataGridWasteReceived.Items.Refresh(); ewrd.WasteReceived = new WasteReceived(); ewrd.WasteReceived.Identifier = WasteReceived.GetNewIdentifier(_selectedWAS_RCPT.WasteReceived); ewrd.WasteReceived.WAS_RCPT = _selectedWAS_RCPT; this.SublistElementChanged(Message.NotificationClass.WAS_RCPT); } }; if (ewrd.ShowDialog() ?? false) { if ((ewrd.WasteReceived.WasteCode != null) && !_selectedWAS_RCPT.WasteReceived.Any(wr => wr.WasteCode == ewrd.WasteReceived.WasteCode)) { _selectedWAS_RCPT.WasteReceived.Add(ewrd.WasteReceived); } this.dataGridWasteReceived.Items.Refresh(); this.SublistElementChanged(Message.NotificationClass.WAS_RCPT); } } private void DataGridWasteReceived_AddingNewItem(object sender, AddingNewItemEventArgs e) { DataGridWasteReceived_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(_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 Highlighting public override void HighlightErrorMessageContainer() { if (this._wasMessage.HasErrors) { HighlightService.HighlightControl(this.wasGroupBox, HighlightService.HighlightStyle.ERROR, this._wasMessage); } } public override void HighlightViolationMessageContainer() { if (this._wasMessage.HasViolations) HighlightService.HighlightControl(this.wasGroupBox, HighlightService.HighlightStyle.VIOLATION, this._wasMessage); } #endregion #region mouse wheel private void ScrollViewer_PreviewMouseWheel(object sender, System.Windows.Input.MouseWheelEventArgs e) { ScrollViewer scv = (ScrollViewer)sender; scv.ScrollToVerticalOffset(scv.VerticalOffset - e.Delta); e.Handled = true; } #endregion #region Excel file import 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 importWasteList = new List(); 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 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"); 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.textBoxWasteDisposalServiceProviders.Text.Trim(); this.buttonUndoTemplate.IsEnabled = this._undoTemplate.Length > 0; this.textBoxWasteDisposalServiceProviders.Text = wdsp_t.WasteDisposalServiceProviderName; } } private async void buttonSaveTemplate_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 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.textBoxWasteDisposalServiceProviders.Text = this._undoTemplate; this.buttonUndoTemplate.IsEnabled = false; this._undoTemplate = null; this.comboBox_WSDPTemplate.SelectedItem = null; } } #endregion #region Copy WAS to WAS_RCPT handler private void buttonCopyFromWAS_Click(object sender, RoutedEventArgs e) { if (_selectedWAS_RCPT == null) return; if(MessageBox.Show(Properties.Resources.textCopyToWASConfirmation, Properties.Resources.textConfirmation, MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.No) == MessageBoxResult.Yes) { foreach(Waste waste in _was.Waste) { if(waste.WasteDisposalAmount_MTQ.HasValue && waste.WasteDisposalAmount_MTQ > 0) { // find matching WAS_RCPT entry foreach(WasteReceived wasteReceived in _selectedWAS_RCPT.WasteReceived) { if(wasteReceived.WasteCode.Equals(waste.WasteType.ToString())) { wasteReceived.AmountWasteReceived_MTQ = waste.WasteDisposalAmount_MTQ; break; } } } } this.dataGridWasteReceived.Items.Refresh(); } } #endregion } }