private void OnTreeViewItemSelected(object sender, AllSamplingEntitiesEventHandler e) { TreeViewEntity = e.TreeViewEntity; ProjectSetting = e.ProjectSetting; LandingSite = e.LandingSite; Gear = e.Gear; MonthSampled = e.MonthSampled; switch (TreeViewEntity) { case "tv_ProjectSettingViewModel": break; case "tv_LandingSiteViewModel": break; case "tv_GearViewModel": break; case "tv_MonthFishingViewModel": _samplingRadioButtonWasClicked = false; rbSampling.IsChecked = true; OnEntityButtonClick(rbSampling, null); lblContentTitle.Content = $"{ProjectSetting.ProjectName} samplings in {LandingSite.ToString()}, caught using {Gear.GearName} on {((DateTime)MonthSampled).ToString("MMM-yyyy")}"; break; } }
private void OnButton_Click(object sender, RoutedEventArgs e) { string buttonName = ((Button)sender).Name; switch (buttonName) { case "buttonSubGrid1": switch (_entityType) { case "LandingSite": case "Gear": case "Fisher": SamplingHistoryWindow shw = new SamplingHistoryWindow(_entityType); shw.Owner = this; shw.ShowDialog(); break; case "GPS": GPSStatusWindow gsw = new GPSStatusWindow("gps_history"); gsw.Owner = this; gsw.Show(); break; } break; case "buttonSubGrid": switch (_entityType) { case "Fisher": FisherAndGPS fg = (FisherAndGPS)gridData.SelectedItem; FisherGPSWindow fgw = new FisherGPSWindow(fisher: fg.Fisher, readOnly: false, parentWindow: this); //FisherGPSWindow fgw = new FisherGPSWindow((Fisher)gridData.SelectedItem); fgw.ShowDialog(); if (!fgw.Cancelled && RefreshDataGridNeeded) { refreshDataGrid(); } break; case "GPS": GPSStatusWindow gsw = new GPSStatusWindow("assignment"); gsw.Owner = this; gsw.Show(); break; } //buttonSubGrid.IsEnabled = false; break; case "buttonAdd": AddEditWindow aew = new AddEditWindow(_entityType, true); aew.ShowDialog(); if (!aew.Cancelled) { refreshDataGrid(); } break; case "buttonEdit": aew = new AddEditWindow(_entityType, false, _entityID); aew.ShowDialog(); if (!aew.Cancelled) { refreshDataGrid(); } break; case "buttonDelete": string msgCannotDelete = ""; bool deleteSuccess = false; switch (_entityType) { case "Gear": if (BSCEntities.GearViewModel.CanDeleteEntity(Gear)) { BSCEntities.GearViewModel.DeleteRecordFromRepo(Gear.GearName); deleteSuccess = true; } else { msgCannotDelete = $"Cannot delete the gear '{Gear.GearName}' because it is already used by the database"; } break; case "Fisher": if (Entities.BSCEntities.FisherViewModel.CanDeleteEntity(Fisher)) { Entities.BSCEntities.FisherViewModel.DeleteRecordFromRepo(_entityID); deleteSuccess = true; } else { msgCannotDelete = $"Cannot delete the fisher '{Fisher.FisherName}' because it is already used by the database"; } break; case "LandingSite": if (BSCEntities.LandingSiteViewModel.CanDeleteEntity(LandingSite)) { Entities.BSCEntities.LandingSiteViewModel.DeleteRecordFromRepo(LandingSite.LandingSiteID); } else { msgCannotDelete = $"Cannot delete the GPS '{LandingSite.ToString()}' because it is already used by the database"; } break; case "GPS": if (Entities.BSCEntities.GPSViewModel.CanDeleteEntity(GPS)) { Entities.BSCEntities.GPSViewModel.DeleteRecordFromRepo(_entityID); deleteSuccess = true; } else { msgCannotDelete = $"Cannot delete the GPS '{GPS.ToString()}' because it is already used by the database"; } break; case "ProjectSetting": if (Entities.BSCEntities.ProjectSettingViewModel.CanDeleteEntity(ProjectSetting)) { Entities.BSCEntities.ProjectSettingViewModel.DeleteRecordFromRepo(ProjectSetting.ProjectID); deleteSuccess = true; } else { msgCannotDelete = $"Cannot delete the project '{ProjectSetting.ProjectName}' because it is already used by the database"; } break; } if (deleteSuccess) { //gridData.Items.Refresh(); refreshDataGrid(); } else { if (msgCannotDelete.Length > 0) { MessageBox.Show(msgCannotDelete, "Validation error", MessageBoxButton.OK, MessageBoxImage.Information); } } break; } }