// Copyright (c) 2017 schick Informatik // Description: MDH Meldung Bearbeitungsseite // using bsmd.database; using ClosedXML.Excel; using ENI2.EditControls; using ENI2.Util; using Microsoft.Win32; using System; using System.Collections.Generic; using System.IO; using System.Windows; using System.Windows.Controls; namespace ENI2.DetailViewControls { /// /// Interaction logic for MaritimeHealthDeclarationDetailControl.xaml /// public partial class MaritimeHealthDeclarationDetailControl : DetailBaseControl { private Message _mdhMessage; private Message _secMessage; private MDH _mdh; private SEC _sec; public MaritimeHealthDeclarationDetailControl() { InitializeComponent(); Loaded += MaritimeHealthDeclarationDetailControl_Loaded; } public override void Initialize() { base.Initialize(); foreach (Message aMessage in this.Messages) { if (aMessage.MessageNotificationClass == Message.NotificationClass.MDH) { this._mdhMessage = aMessage; this.ControlMessages.Add(aMessage); } if (aMessage.MessageNotificationClass == Message.NotificationClass.SEC) { this._secMessage = aMessage; if (this._secMessage.Elements.Count > 0) this._sec = this._secMessage.Elements[0] as SEC; } } #region init MDH if (this._mdhMessage == null) { this._mdhMessage = this.Core.CreateMessage(Message.NotificationClass.MDH); this.Messages.Add(this._mdhMessage); } MDH mdh = null; if (this._mdhMessage.Elements.Count > 0) mdh = this._mdhMessage.Elements[0] as MDH; if (mdh == null) { mdh = new MDH(); mdh.MessageCore = this.Core; mdh.MessageHeader = this._mdhMessage; _mdhMessage.Elements.Add(mdh); } #region Checkbox enable / disable controls this.checkBoxHasShipVisited.Checked += CheckBoxHasShipVisited_Checked; this.checkBoxHasShipVisited.Unchecked += CheckBoxHasShipVisited_Checked; this.CheckBoxHasShipVisited_Checked(null, null); this.checkBoxHavePersonsDied.Checked += CheckBoxHavePersonsDied_Checked; this.checkBoxHavePersonsDied.Unchecked += CheckBoxHavePersonsDied_Checked; this.CheckBoxHavePersonsDied_Checked(null, null); this.checkBoxTotalNumberSickHigherThan.Checked += CheckBoxTotalNumberSickHigherThan_Checked; this.checkBoxTotalNumberSickHigherThan.Unchecked += CheckBoxTotalNumberSickHigherThan_Checked; this.CheckBoxTotalNumberSickHigherThan_Checked(null, null); this.checkBoxStowawaysOnBoard.Checked += CheckBoxStowawaysOnBoard_Checked; this.checkBoxStowawaysOnBoard.Unchecked += CheckBoxStowawaysOnBoard_Checked; this.CheckBoxStowawaysOnBoard_Checked(null, null); this.checkBoxSanitaryControlExemption.Checked += CheckBoxSanitaryControlExemption_Checked; this.checkBoxSanitaryControlExemption.Unchecked += CheckBoxSanitaryControlExemption_Checked; this.CheckBoxSanitaryControlExemption_Checked(null, null); #endregion this.mainFrame.DataContext = mdh; this._mdh = mdh; this.dataGridPortOfCallLast30Days.Initialize(); this.dataGridPortOfCallLast30Days.ItemsSource = mdh.PortOfCallLast30Days; this.dataGridPortOfCallLast30Days.AddingNewItem += DataGridPortOfCallLast30Days_AddingNewItem; this.dataGridPortOfCallLast30Days.EditRequested += DataGridPortOfCallLast30Days_EditRequested; this.dataGridPortOfCallLast30Days.DeleteRequested += DataGridPortOfCallLast30Days_DeleteRequested; this.dataGridPortOfCallLast30Days.CreateRequested += DataGridPortOfCallLast30Days_CreateRequested; this.dataGridInfectedAreas.Initialize(); this.dataGridInfectedAreas.IsReadOnly = !(mdh.InfectedAreaVisited ?? false); this.dataGridInfectedAreas.ItemsSource = mdh.InfectedAreas; this.dataGridInfectedAreas.AddingNewItem += DataGridInfectedAreas_AddingNewItem; this.dataGridInfectedAreas.EditRequested += DataGridInfectedAreas_EditRequested; this.dataGridInfectedAreas.DeleteRequested += DataGridInfectedAreas_DeleteRequested; this.dataGridInfectedAreas.CreateRequested += DataGridInfectedAreas_CreateRequested; this.dataGridSanitaryMeasures.Initialize(); this.dataGridSanitaryMeasures.IsReadOnly = !(mdh.SanitaryMeasuresApplied ?? false); this.checkBoxHasShipVisited.DataContext = mdh; this.checkBoxSanitaryMeasuresApplied.DataContext = mdh; this.checkBoxSanitaryMeasuresApplied.Checked += CheckBoxSanitaryMeasuresApplied_Checked; this.checkBoxSanitaryMeasuresApplied.Unchecked += CheckBoxSanitaryMeasuresApplied_Checked; this.dataGridSanitaryMeasures.ItemsSource = mdh.SanitaryMeasuresDetails; this.dataGridSanitaryMeasures.AddingNewItem += DataGridSanitaryMeasures_AddingNewItem; this.dataGridSanitaryMeasures.EditRequested += DataGridSanitaryMeasures_EditRequested; this.dataGridSanitaryMeasures.DeleteRequested += DataGridSanitaryMeasures_DeleteRequested; this.dataGridSanitaryMeasures.CreateRequested += DataGridSanitaryMeasures_CreateRequested; this.checkSimplification.Checked += CheckSimplification_Checked; this.checkSimplification.Unchecked += CheckSimplification_Checked; #endregion } public override int SelectedTabIndex { get { return this.mainFrame.SelectedIndex; } set { this.mainFrame.SelectedIndex = value; } } #region SetEnabled public override void SetEnabled(bool enabled) { this.mdhGroupBox.IsEnabled = enabled; this.dataGridPortOfCallLast30Days.IsEnabled = enabled; this.buttonImportFromSEC.IsEnabled = enabled; this.checkBoxHasShipVisited.IsEnabled = enabled; this.dataGridInfectedAreas.IsEnabled = enabled; this.checkBoxSanitaryMeasuresApplied.IsEnabled = enabled; this.dataGridSanitaryMeasures.IsEnabled = enabled; } #endregion #region Enable Controls based on Checkbox (fixed) private void CheckBoxSanitaryControlExemption_Checked(object sender, RoutedEventArgs e) { this.textBoxPlaceOfIssue.IsEnabled = this.checkBoxSanitaryControlExemption.IsChecked ?? false; this.textBoxPlaceOfIssue.IsReadOnly = !(this.checkBoxSanitaryControlExemption.IsChecked ?? false); this.datePickerDateOfIssue.IsEnabled = this.checkBoxSanitaryControlExemption.IsChecked ?? false; } private void CheckBoxStowawaysOnBoard_Checked(object sender, RoutedEventArgs e) { this.textBoxStowawaysJoiningLocation.IsEnabled = this.checkBoxStowawaysOnBoard.IsChecked ?? false; this.textBoxStowawaysJoiningLocation.IsReadOnly = !(this.checkBoxStowawaysOnBoard.IsChecked ?? false); } private void CheckBoxTotalNumberSickHigherThan_Checked(object sender, RoutedEventArgs e) { this.integerUpDownNumberOfIllPersons.IsEnabled = this.checkBoxTotalNumberSickHigherThan.IsChecked ?? false; this.integerUpDownNumberOfDeaths.IsReadOnly = !(this.checkBoxTotalNumberSickHigherThan.IsChecked ?? false); } private void CheckBoxHavePersonsDied_Checked(object sender, RoutedEventArgs e) { this.integerUpDownNumberOfDeaths.IsEnabled = this.checkBoxHavePersonsDied.IsChecked ?? false; this.integerUpDownNumberOfDeaths.IsReadOnly = !(this.checkBoxHavePersonsDied.IsChecked ?? false); } private void CheckSimplification_Checked(object sender, RoutedEventArgs e) { bool simplified = this.checkSimplification.IsChecked ?? false; this.locodePortWhereHealthDeclarationWasGiven.IsEnabled = simplified; this.checkBoxAwareOfConditions.IsEnabled = !simplified; this.checkBoxHasShipVisited.IsEnabled = !simplified; this.checkBoxHavePersonsDied.IsEnabled = !simplified; this.checkBoxIsSuspectedInfectious.IsEnabled = !simplified; this.checkBoxReinspectionSanitary.IsEnabled = !simplified; this.checkBoxSanitaryControlExemption.IsEnabled = !simplified; this.checkBoxSanitaryMeasuresApplied.IsEnabled = !simplified; this.checkBoxSickAnimalsOrPets.IsEnabled = !simplified; this.checkBoxSickPersonsOnBoard.IsEnabled = !simplified; this.checkBoxStowawaysOnBoard.IsEnabled = !simplified; this.checkBoxTotalNumberSickHigherThan.IsEnabled = !simplified; this.checkBoxWasMedicalConsulted.IsEnabled = !simplified; this.dataGridInfectedAreas.IsEnabled = !simplified; this.dataGridPortOfCallLast30Days.IsEnabled = !simplified; this.dataGridSanitaryMeasures.IsEnabled = !simplified; this.datePickerDateOfIssue.IsEnabled = !simplified; this.textBoxPlaceOfIssue.IsEnabled = !simplified; this.textBoxStowawaysJoiningLocation.IsEnabled = !simplified; this.integerUpDownNumberOfDeaths.IsEnabled = !simplified; this.integerUpDownNumberOfDeaths.IsReadOnly = simplified; this.integerUpDownNumberOfIllPersons.IsEnabled = !simplified; this.integerUpDownNumberOfIllPersons.IsReadOnly = simplified; } private void CheckBoxHasShipVisited_Checked(object sender, RoutedEventArgs e) { this.dataGridInfectedAreas.IsReadOnly = !(this.checkBoxHasShipVisited.IsChecked ?? false); } private void CheckBoxSanitaryMeasuresApplied_Checked(object sender, RoutedEventArgs e) { this.dataGridSanitaryMeasures.IsReadOnly = !(this.checkBoxSanitaryMeasuresApplied.IsChecked ?? false); } #endregion #region load/button event handler private void MaritimeHealthDeclarationDetailControl_Loaded(object sender, RoutedEventArgs e) { this.RegisterCheckboxChange(this.checkBoxAwareOfConditions, Message.NotificationClass.MDH); this.RegisterCheckboxChange(this.checkBoxHasShipVisited, Message.NotificationClass.MDH); this.RegisterCheckboxChange(this.checkBoxHavePersonsDied, Message.NotificationClass.MDH); this.RegisterCheckboxChange(this.checkBoxIsSuspectedInfectious, Message.NotificationClass.MDH); this.RegisterCheckboxChange(this.checkBoxReinspectionSanitary, Message.NotificationClass.MDH); this.RegisterCheckboxChange(this.checkBoxSanitaryControlExemption, Message.NotificationClass.MDH); this.RegisterCheckboxChange(this.checkBoxSanitaryMeasuresApplied, Message.NotificationClass.MDH); this.RegisterCheckboxChange(this.checkBoxSickAnimalsOrPets, Message.NotificationClass.MDH); this.RegisterCheckboxChange(this.checkBoxSickPersonsOnBoard, Message.NotificationClass.MDH); this.RegisterCheckboxChange(this.checkBoxStowawaysOnBoard, Message.NotificationClass.MDH); this.RegisterCheckboxChange(this.checkBoxTotalNumberSickHigherThan, Message.NotificationClass.MDH); this.RegisterCheckboxChange(this.checkBoxWasMedicalConsulted, Message.NotificationClass.MDH); this.RegisterCheckboxChange(this.checkSimplification, Message.NotificationClass.MDH); this.RegisterLocodeChange(this.locodePortWhereHealthDeclarationWasGiven, Message.NotificationClass.MDH); this.RegisterIntegerUpDownChange(this.integerUpDownNumberOfDeaths, Message.NotificationClass.MDH); this.RegisterIntegerUpDownChange(this.integerUpDownNumberOfIllPersons, Message.NotificationClass.MDH); this.RegisterTextboxChange(this.textBoxPlaceOfIssue, Message.NotificationClass.MDH); this.RegisterTextboxChange(this.textBoxStowawaysJoiningLocation, Message.NotificationClass.MDH); this.RegisterDatePickerChange(this.datePickerDateOfIssue, Message.NotificationClass.MDH); } private void buttonImportFromSEC_Click(object sender, RoutedEventArgs e) { if(this._mdh.PortOfCallLast30Days.Count > 0) { MessageBox.Show(Properties.Resources.textOnlyIfGridIsEmpty, Properties.Resources.textCaptionError, MessageBoxButton.OK, MessageBoxImage.Warning); } else { if(this._sec != null) { foreach(LastTenPortFacilitiesCalled l10fc in _sec.LastTenPortFacilitesCalled) { if(l10fc.PortFacilityDateOfDeparture.HasValue && ((DateTime.Now - l10fc.PortFacilityDateOfDeparture.Value).TotalDays < 31)) { PortOfCallLast30Days poc30 = new PortOfCallLast30Days(); poc30.Identifier = PortOfCallLast30Days.GetNewIdentifier(this._mdh.PortOfCallLast30Days); poc30.PortOfCallLast30DaysCrewMembersJoined = false; poc30.PortOfCallLast30DaysDateOfDeparture = l10fc.PortFacilityDateOfDeparture; poc30.PortOfCallLast30DaysLocode = l10fc.PortFacilityPortLoCode; poc30.MDH = this._mdh; this._mdh.PortOfCallLast30Days.Add(poc30); } } if (this._mdh.PortOfCallLast30Days.Count > 0) { this.dataGridPortOfCallLast30Days.Items.Refresh(); this.SublistElementChanged(Message.NotificationClass.MDH); } } } } private void ButtonImportFromExcel_Click(object sender, RoutedEventArgs e) { OpenFileDialog ofd = new OpenFileDialog { Filter = "Excel Files|*.xls;*.xlsx" }; if (ofd.ShowDialog() ?? false) { try { using (var workbook = new XLWorkbook(ofd.FileName)) { var worksheet = workbook.Worksheet(1); // Get first worksheet var rows = worksheet.RangeUsed().RowsUsed(); // Get all rows with data List importPoC30 = new List(); foreach (var row in rows) { if (row.RowNumber() > worksheet.RangeUsed().RowCount()) break; if (worksheet.RangeUsed().ColumnCount() < 3) { throw new InvalidDataException("Sheet must have at least 3 Columns of data"); } PortOfCallLast30Days poc30 = new PortOfCallLast30Days(); if (row.Cell(1).IsEmpty() && row.Cell(2).IsEmpty()) continue; if (!row.Cell(1).IsEmpty()) poc30.PortOfCallLast30DaysLocode = row.Cell(1).GetString(); if (!row.Cell(2).IsEmpty()) poc30.PortOfCallLast30DaysDateOfDeparture = row.Cell(2).GetDateTime(); string boolString = ""; if (!row.Cell(3).IsEmpty()) boolString = row.Cell(3).GetString(); poc30.PortOfCallLast30DaysCrewMembersJoined = (boolString.Equals("y", StringComparison.OrdinalIgnoreCase) || (boolString.Equals("yes", StringComparison.OrdinalIgnoreCase)) || (boolString.Equals("j", StringComparison.OrdinalIgnoreCase))); if (worksheet.RangeUsed().ColumnCount() > 3) { string allNewCrew = row.Cell(4).IsEmpty() ? null : row.Cell(4).GetString()?.Trim(); if (!allNewCrew.IsNullOrEmpty()) { string[] crewNames = allNewCrew.Split(',', ';'); for (int i = 0; i < crewNames.Length; i++) { string crewName = crewNames[i].Trim(); if (crewName.IsNullOrEmpty()) continue; PortOfCallLast30DaysCrewJoinedShip poc30Crew = new PortOfCallLast30DaysCrewJoinedShip(); poc30Crew.PortOfCallLast30DaysCrewJoinedShipName = crewName; poc30Crew.PortOfCallLast30Days = poc30; poc30.CrewJoinedShip.Add(poc30Crew); } } } poc30.MDH = this._mdh; this._mdh.PortOfCallLast30Days.Add(poc30); importPoC30.Add(poc30); } if (importPoC30.Count > 0) { this.dataGridPortOfCallLast30Days.Items.Refresh(); this.SublistElementChanged(Message.NotificationClass.MDH); MessageBox.Show(String.Format(Properties.Resources.textPoC30Imported, importPoC30.Count), Properties.Resources.textCaptionInformation, MessageBoxButton.OK, MessageBoxImage.Information); } } } catch (Exception ex) { MessageBox.Show("Error reading Excel: " + ex.Message, Properties.Resources.textCaptionError, MessageBoxButton.OK, MessageBoxImage.Error); } } } #endregion #region SanitaryMeasures Grid private void DataGridSanitaryMeasures_CreateRequested() { EditSanitaryMeasureDialog epd = new EditSanitaryMeasureDialog(); epd.SanitaryMeasureDetail = new SanitaryMeasuresDetail(); epd.SanitaryMeasureDetail.Identifier = SanitaryMeasuresDetail.GetNewIdentifier(_mdh.SanitaryMeasuresDetails); epd.SanitaryMeasureDetail.MDH = this._mdh; epd.AddClicked += () => { epd.CopyValuesToEntity(); if(!this._mdh.SanitaryMeasuresDetails.Contains(epd.SanitaryMeasureDetail)) this._mdh.SanitaryMeasuresDetails.Add(epd.SanitaryMeasureDetail); this.dataGridSanitaryMeasures.Items.Refresh(); epd.SanitaryMeasureDetail = new SanitaryMeasuresDetail(); epd.SanitaryMeasureDetail.Identifier = SanitaryMeasuresDetail.GetNewIdentifier(_mdh.SanitaryMeasuresDetails); epd.SanitaryMeasureDetail.MDH = this._mdh; this.SublistElementChanged(Message.NotificationClass.MDH); }; if (epd.ShowDialog() ?? false) { if(!_mdh.SanitaryMeasuresDetails.Contains(epd.SanitaryMeasureDetail)) _mdh.SanitaryMeasuresDetails.Add(epd.SanitaryMeasureDetail); this.dataGridSanitaryMeasures.Items.Refresh(); this.SublistElementChanged(Message.NotificationClass.MDH); } } private void DataGridSanitaryMeasures_DeleteRequested(DatabaseEntity obj) { if (obj is SanitaryMeasuresDetail smd) { // are you sure dialog is in base class _mdh.SanitaryMeasuresDetails.Remove(smd); DBManager.GetSingleCon(Properties.Settings.Default.ConnectionString).Delete(smd); DatabaseEntity.ResetIdentifiers(new List(_mdh.SanitaryMeasuresDetails)); this.SublistElementChanged(Message.NotificationClass.MDH); this.dataGridSanitaryMeasures.Items.Refresh(); } } private void DataGridSanitaryMeasures_EditRequested(DatabaseEntity obj) { EditSanitaryMeasureDialog ecpd = new EditSanitaryMeasureDialog(); ecpd.SanitaryMeasureDetail = obj as SanitaryMeasuresDetail; ecpd.AddClicked += () => { ecpd.CopyValuesToEntity(); if (!_mdh.SanitaryMeasuresDetails.Contains(ecpd.SanitaryMeasureDetail)) _mdh.SanitaryMeasuresDetails.Add(ecpd.SanitaryMeasureDetail); this.dataGridSanitaryMeasures.Items.Refresh(); ecpd.SanitaryMeasureDetail = new SanitaryMeasuresDetail(); ecpd.SanitaryMeasureDetail.Identifier = SanitaryMeasuresDetail.GetNewIdentifier(_mdh.SanitaryMeasuresDetails); ecpd.SanitaryMeasureDetail.MDH = this._mdh; this.SublistElementChanged(Message.NotificationClass.MDH); }; if (ecpd.ShowDialog() ?? false) { if (!_mdh.SanitaryMeasuresDetails.Contains(ecpd.SanitaryMeasureDetail)) _mdh.SanitaryMeasuresDetails.Add(ecpd.SanitaryMeasureDetail); this.dataGridSanitaryMeasures.Items.Refresh(); this.SublistElementChanged(Message.NotificationClass.MDH); } } private void DataGridSanitaryMeasures_AddingNewItem(object sender, AddingNewItemEventArgs e) { this.DataGridSanitaryMeasures_CreateRequested(); } #endregion #region InfectedAreas Grid private void DataGridInfectedAreas_CreateRequested() { EditInfectedAreaDialog epd = new EditInfectedAreaDialog(); epd.InfectedArea = new InfectedArea(); epd.InfectedArea.Identifier = InfectedArea.GetNewIdentifier(_mdh.InfectedAreas); epd.InfectedArea.MDH = this._mdh; epd.AddClicked += () => { epd.CopyValuesToEntity(); if(!this._mdh.InfectedAreas.Contains(epd.InfectedArea)) this._mdh.InfectedAreas.Add(epd.InfectedArea); this.dataGridInfectedAreas.Items.Refresh(); epd.InfectedArea = new InfectedArea(); epd.InfectedArea.MDH = this._mdh; epd.InfectedArea.Identifier = InfectedArea.GetNewIdentifier(_mdh.InfectedAreas); this.SublistElementChanged(Message.NotificationClass.MDH); }; if (epd.ShowDialog() ?? false) { if(!this._mdh.InfectedAreas.Contains(epd.InfectedArea)) _mdh.InfectedAreas.Add(epd.InfectedArea); this.dataGridInfectedAreas.Items.Refresh(); this.SublistElementChanged(Message.NotificationClass.MDH); } } private void DataGridInfectedAreas_DeleteRequested(DatabaseEntity obj) { if (obj is InfectedArea ia) { // are you sure dialog is in base class _mdh.InfectedAreas.Remove(ia); DBManager.GetSingleCon(Properties.Settings.Default.ConnectionString).Delete(ia); DatabaseEntity.ResetIdentifiers(new List(_mdh.InfectedAreas)); this.SublistElementChanged(Message.NotificationClass.MDH); this.dataGridInfectedAreas.Items.Refresh(); } } private void DataGridInfectedAreas_EditRequested(DatabaseEntity obj) { EditInfectedAreaDialog ecpd = new EditInfectedAreaDialog(); ecpd.InfectedArea = obj as InfectedArea; ecpd.AddClicked += () => { ecpd.CopyValuesToEntity(); if (!_mdh.InfectedAreas.Contains(ecpd.InfectedArea)) _mdh.InfectedAreas.Add(ecpd.InfectedArea); this.dataGridInfectedAreas.Items.Refresh(); ecpd.InfectedArea= new InfectedArea(); ecpd.InfectedArea.MDH = this._mdh; ecpd.InfectedArea.Identifier = InfectedArea.GetNewIdentifier(_mdh.InfectedAreas); this.SublistElementChanged(Message.NotificationClass.MDH); }; if (ecpd.ShowDialog() ?? false) { if (!_mdh.InfectedAreas.Contains(ecpd.InfectedArea)) _mdh.InfectedAreas.Add(ecpd.InfectedArea); this.dataGridInfectedAreas.Items.Refresh(); this.SublistElementChanged(Message.NotificationClass.MDH); } } private void DataGridInfectedAreas_AddingNewItem(object sender, AddingNewItemEventArgs e) { this.DataGridInfectedAreas_CreateRequested(); } #endregion #region PortOfCallLast30Days grid private void DataGridPortOfCallLast30Days_CreateRequested() { EditPortOfCallLast30DaysDialog epd = new EditPortOfCallLast30DaysDialog(); epd.PocLast30Days = new PortOfCallLast30Days(); epd.PocLast30Days.Identifier = PortOfCallLast30Days.GetNewIdentifier(_mdh.PortOfCallLast30Days); epd.PocLast30Days.MDH = this._mdh; epd.AddClicked += () => { epd.CopyValuesToEntity(); if(!this._mdh.PortOfCallLast30Days.Contains(epd.PocLast30Days)) this._mdh.PortOfCallLast30Days.Add(epd.PocLast30Days); this.dataGridPortOfCallLast30Days.Items.Refresh(); epd.PocLast30Days = new PortOfCallLast30Days(); epd.PocLast30Days.MDH = this._mdh; epd.PocLast30Days.Identifier = PortOfCallLast30Days.GetNewIdentifier(_mdh.PortOfCallLast30Days); this.SublistElementChanged(Message.NotificationClass.MDH); }; if (epd.ShowDialog() ?? false) { if(!_mdh.PortOfCallLast30Days.Contains(epd.PocLast30Days)) _mdh.PortOfCallLast30Days.Add(epd.PocLast30Days); this.dataGridPortOfCallLast30Days.Items.Refresh(); this.SublistElementChanged(Message.NotificationClass.MDH); } } private void DataGridPortOfCallLast30Days_DeleteRequested(DatabaseEntity obj) { if (obj is PortOfCallLast30Days poc30d) { // are you sure dialog is in base class _mdh.PortOfCallLast30Days.Remove(poc30d); poc30d.DeleteElements(); DBManager.GetSingleCon(Properties.Settings.Default.ConnectionString).Delete(poc30d); DatabaseEntity.ResetIdentifiers(new List(_mdh.PortOfCallLast30Days)); this.SublistElementChanged(Message.NotificationClass.MDH); this.dataGridPortOfCallLast30Days.Items.Refresh(); } } private void DataGridPortOfCallLast30Days_EditRequested(DatabaseEntity obj) { EditPortOfCallLast30DaysDialog ecpd = new EditPortOfCallLast30DaysDialog(); ecpd.PocLast30Days = obj as PortOfCallLast30Days; ecpd.AddClicked += () => { ecpd.CopyValuesToEntity(); if (!_mdh.PortOfCallLast30Days.Contains(ecpd.PocLast30Days)) _mdh.PortOfCallLast30Days.Add(ecpd.PocLast30Days); this.dataGridPortOfCallLast30Days.Items.Refresh(); ecpd.PocLast30Days = new PortOfCallLast30Days(); ecpd.PocLast30Days.MDH = this._mdh; ecpd.PocLast30Days.Identifier = PortOfCallLast30Days.GetNewIdentifier(_mdh.PortOfCallLast30Days); this.SublistElementChanged(Message.NotificationClass.MDH); }; if (ecpd.ShowDialog() ?? false) { if (!_mdh.PortOfCallLast30Days.Contains(ecpd.PocLast30Days)) _mdh.PortOfCallLast30Days.Add(ecpd.PocLast30Days); this.dataGridPortOfCallLast30Days.Items.Refresh(); this.SublistElementChanged(Message.NotificationClass.MDH); } } private void DataGridPortOfCallLast30Days_AddingNewItem(object sender, AddingNewItemEventArgs e) { this.DataGridPortOfCallLast30Days_CreateRequested(); } #endregion #region Highlighting public override void HighlightErrorMessageContainer() { if (this._mdhMessage.HasErrors) { HighlightService.HighlightControl(this.mdhGroupBox, HighlightService.HighlightStyle.ERROR, this._mdhMessage); } } public override void HighlightViolationMessageContainer() { if (this._mdhMessage.HasViolations) HighlightService.HighlightControl(this.mdhGroupBox, HighlightService.HighlightStyle.VIOLATION, this._mdhMessage); } #endregion } }