internal void Change() { // in yet in change mode if (_currentChangeMode == E_ChangeMode.no_change) { // check if changing is possible and switch controls _currentChangeMode = DoChange(); // switch label if changing possible if (_currentChangeMode != E_ChangeMode.no_change) { Window.Location_ChangeButton.Content = "Save"; } } else { // re-enable controls again ResetControlState(); // save the changes to the database SaveChangeChanges(); // ask maincontroler to reload data from database and refresh all controls // maincontroler needs to take care of this since it not only settings tab MainControler.ReloadAndRefreshControls(); // reset the modes _currentChangeMode = E_ChangeMode.no_change; } }
internal virtual void Edit() { // currently in "add" mode... if (_currentMode == E_Mode.add) { // check if editing is possible and switch controls CurrentEditMode = DoEdit(); // edit is possible if (CurrentEditMode != E_EditMode.no_edit) { // update button state / label UpdateButtons(); // switch to edit mode _currentMode = E_Mode.edit; } } else { // set control state ResetControlState(); // save the changes to the database SaveEditChanges(); // ask maincontroler to reload data from database and refresh all controls // maincontroler needs to take care of this since it not only settings tab MainControler.ReloadAndRefreshControls(); // reset the modes _currentMode = E_Mode.add; CurrentEditMode = E_EditMode.no_edit; } }
internal void Add() { // if the autocomplete textboxes are not left via TAB but by clicking directly on a button, // the display item is not udpated - so do this here as a workaround UpdateDisplayItem(); // db operations might take a while Mouse.OverrideCursor = System.Windows.Input.Cursors.Wait; // add country to database PersistenceManager.E_DBReturnCode success = DataAccessAdapter.SmartAddCountry(DisplayItem, out string errorMessage); // show success or error message EvaluateDatabaseMessages(success, errorMessage); // reload data from database and refresh controls MainControler.ReloadAndRefreshControls(); // reset cursor Mouse.OverrideCursor = null; Window.Settings_CountryControl.SetFocus(); }
internal void Delete() { SettingsDeleteWindow deletingWindow = new SettingsDeleteWindow(Window); if (deletingWindow.ShowDialog() == true) { switch (deletingWindow.DeleteTarget) { case SettingsDeleteWindow.EDeleteTarget.Country: var country = Window.Settings_CountryControl.GetCurrentObject() as Country; if (country != null) { if (DataAccessAdapter.DeleteCountryById(country.Id, out string errorMessage) == PersistenceManager.E_DBReturnCode.no_error) { MainControler.ReloadAndRefreshControls(); ShowMessage("Country sucessfully deleted.", E_MessageType.info); } else { ShowMessage("Error deleting the country." + errorMessage, E_MessageType.error); } } RefreshAllObjectsFromDB(); break; case SettingsDeleteWindow.EDeleteTarget.Area: var area = Window.Settings_AreaControl.GetCurrentObject() as Area; if (area != null) { if (DataAccessAdapter.DeleteAreaById(area.Id, out string errorMessage) == PersistenceManager.E_DBReturnCode.no_error) { MainControler.ReloadAndRefreshControls(); ShowMessage("Area sucessfully deleted.", E_MessageType.info); } else { ShowMessage("Error deleting the area." + errorMessage, E_MessageType.error); } } break; case SettingsDeleteWindow.EDeleteTarget.Subarea: var subArea = Window.Settings_SubAreaControl.GetCurrentObject() as SubArea; if (subArea != null) { if (DataAccessAdapter.DeleteSubAreaById(subArea.Id, out string errorMessage) == PersistenceManager.E_DBReturnCode.no_error) { MainControler.ReloadAndRefreshControls(); ShowMessage("Subarea sucessfully deleted.", E_MessageType.info); } else { ShowMessage("Error deleting the Subarea." + errorMessage, E_MessageType.error); } } break; case SettingsDeleteWindow.EDeleteTarget.None: // nothing to delete break; default: System.Diagnostics.Debug.Assert(false); throw new Exception("Unknonw enum value in SettingTabControler::Delete"); } } }