Ejemplo n.º 1
0
        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");
                }
            }
        }
Ejemplo n.º 2
0
 public SettingsDeleteWindowControler(SettingsDeleteWindow deleteWindow, MainWindow window) : base(window)
 {
     _deleteWindow = deleteWindow;
 }