From 20f1abe7c1067da10ada84e5e7769a2c0d73caf0 Mon Sep 17 00:00:00 2001 From: Daniel Schick Date: Thu, 20 Jan 2022 08:39:41 +0100 Subject: [PATCH] =?UTF-8?q?WasteReceived=20hinzugef=C3=BCgt,=20neue=20Wast?= =?UTF-8?q?e=20Codes,..?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ENI2/Controls/ENIDataGrid.cs | 20 ++-- .../WasteDetailControl.xaml | 4 +- .../WasteDetailControl.xaml.cs | 105 +++++++++++++++++- ENI2/ENI2.csproj | 7 ++ ENI2/EditControls/EditWasteDialog.xaml | 2 +- .../EditControls/EditWasteReceivedDialog.xaml | 32 ++++++ .../EditWasteReceivedDialog.xaml.cs | 62 +++++++++++ ENI2/Properties/Resources.Designer.cs | 18 +++ ENI2/Properties/Resources.resx | 6 + bsmd.database/WAS.cs | 41 +++++++ 10 files changed, 278 insertions(+), 19 deletions(-) create mode 100644 ENI2/EditControls/EditWasteReceivedDialog.xaml create mode 100644 ENI2/EditControls/EditWasteReceivedDialog.xaml.cs diff --git a/ENI2/Controls/ENIDataGrid.cs b/ENI2/Controls/ENIDataGrid.cs index 5e0300bc..feeab8c1 100644 --- a/ENI2/Controls/ENIDataGrid.cs +++ b/ENI2/Controls/ENIDataGrid.cs @@ -203,8 +203,7 @@ namespace ENI2.Controls { if((this.SelectedItems != null) && (this.SelectedItems.Count == 1) && !this.IsReadOnly) { - DatabaseEntity selectedEntity = this.SelectedItems[0] as DatabaseEntity; - if (selectedEntity != null) + if (this.SelectedItems[0] is DatabaseEntity selectedEntity) this.EditRequested?.Invoke(selectedEntity); } } @@ -213,8 +212,7 @@ namespace ENI2.Controls { if ((this.SelectedItems != null) && (this.SelectedItems.Count == 1) ) { - DatabaseEntity selectedEntity = this.SelectedItems[0] as DatabaseEntity; - if (selectedEntity != null) + if (this.SelectedItems[0] is DatabaseEntity selectedEntity) this.PrintRequested?.Invoke(selectedEntity); } } @@ -223,8 +221,7 @@ namespace ENI2.Controls { if ((this.SelectedItems != null) && (this.SelectedItems.Count == 1)) { - DatabaseEntity selectedEntity = this.SelectedItems[0] as DatabaseEntity; - if (selectedEntity != null) + if (this.SelectedItems[0] is DatabaseEntity selectedEntity) this.ExportRequested?.Invoke(selectedEntity); } } @@ -233,8 +230,7 @@ namespace ENI2.Controls { if ((this.SelectedItems != null) && (this.SelectedItems.Count == 1)) { - DatabaseEntity selectedEntity = this.SelectedItems[0] as DatabaseEntity; - if (selectedEntity != null) + if (this.SelectedItems[0] is DatabaseEntity selectedEntity) this.ShowTextRequested?.Invoke(selectedEntity); } } @@ -247,12 +243,10 @@ namespace ENI2.Controls { if (sender != null) { - DataGrid grid = sender as DataGrid; - if ((grid != null) && (grid.SelectedItems != null) && (grid.SelectedItems.Count == 1) && !this.IsReadOnly) + if ((sender is DataGrid grid) && (grid.SelectedItems != null) && (grid.SelectedItems.Count == 1) && !this.IsReadOnly) { DataGridRow dgr = grid.ItemContainerGenerator.ContainerFromItem(grid.SelectedItem) as DataGridRow; - DatabaseEntity selectedEntity = grid.SelectedItem as DatabaseEntity; - if (selectedEntity != null) + if (grid.SelectedItem is DatabaseEntity selectedEntity) this.EditRequested?.Invoke(selectedEntity); } } @@ -264,7 +258,7 @@ namespace ENI2.Controls private static T GetVisualChild(Visual parent) where T : Visual { - T child = default(T); + T child = default; int numVisuals = VisualTreeHelper.GetChildrenCount(parent); for (int i = 0; i < numVisuals; i++) { diff --git a/ENI2/DetailViewControls/WasteDetailControl.xaml b/ENI2/DetailViewControls/WasteDetailControl.xaml index 33ea8a1a..08d06950 100644 --- a/ENI2/DetailViewControls/WasteDetailControl.xaml +++ b/ENI2/DetailViewControls/WasteDetailControl.xaml @@ -148,8 +148,8 @@ - + diff --git a/ENI2/DetailViewControls/WasteDetailControl.xaml.cs b/ENI2/DetailViewControls/WasteDetailControl.xaml.cs index dccc78c1..42c366df 100644 --- a/ENI2/DetailViewControls/WasteDetailControl.xaml.cs +++ b/ENI2/DetailViewControls/WasteDetailControl.xaml.cs @@ -23,7 +23,8 @@ namespace ENI2.DetailViewControls private Message _wasMessage; private WAS _was; - private Message _wasRcptMessage; + private Message _wasRcptMessage; + private WAS_RCPT _selectedWAS_RCPT; private static readonly string[] _wasteDeliveryList = { @@ -144,9 +145,15 @@ namespace ENI2.DetailViewControls 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; + #endregion - } + } #region Waste receipt grid event handler @@ -175,6 +182,8 @@ namespace ENI2.DetailViewControls _wasRcptMessage.Elements.Add(epd.WAS_RCPT); this.dataGridWasteReceipt.Items.Refresh(); this.SublistElementChanged(Message.NotificationClass.WAS_RCPT); + this.dataGridWasteReceived.ItemsSource = null; + this._selectedWAS_RCPT = null; } } @@ -188,6 +197,8 @@ namespace ENI2.DetailViewControls DatabaseEntity.ResetIdentifiers(new List(_wasRcptMessage.Elements)); this.SublistElementChanged(Message.NotificationClass.WAS_RCPT); this.dataGridWasteReceipt.Items.Refresh(); + this.dataGridWasteReceived.ItemsSource = null; + this._selectedWAS_RCPT = null; } } @@ -222,6 +233,94 @@ namespace ENI2.DetailViewControls 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(_wasRcptMessage.Elements)); + this.SublistElementChanged(Message.NotificationClass.WAS_RCPT); + this.dataGridWasteReceived.Items.Refresh(); + } + } + + private void DataGridWasteReceived_CreateRequested() + { + 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 (!this._selectedWAS_RCPT.WasteReceived.Contains(ewrd.WasteReceived)) + 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 (!this._selectedWAS_RCPT.WasteReceived.Contains(ewrd.WasteReceived)) + 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 (!this._selectedWAS_RCPT.WasteReceived.Contains(ewrd.WasteReceived)) + _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 (!_selectedWAS_RCPT.WasteReceived.Contains(ewrd.WasteReceived)) + _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 @@ -427,6 +526,6 @@ namespace ENI2.DetailViewControls } #endregion - + } } diff --git a/ENI2/ENI2.csproj b/ENI2/ENI2.csproj index 8cf758cf..a9588845 100644 --- a/ENI2/ENI2.csproj +++ b/ENI2/ENI2.csproj @@ -233,6 +233,9 @@ EditWasteReceiptDialog.xaml + + EditWasteReceivedDialog.xaml + @@ -625,6 +628,10 @@ Designer MSBuild:Compile + + Designer + MSBuild:Compile + Designer MSBuild:Compile diff --git a/ENI2/EditControls/EditWasteDialog.xaml b/ENI2/EditControls/EditWasteDialog.xaml index fcb180c0..84a84dbd 100644 --- a/ENI2/EditControls/EditWasteDialog.xaml +++ b/ENI2/EditControls/EditWasteDialog.xaml @@ -36,7 +36,7 @@