/// <summary>
        /// Saves any changed preferences to s_user_defaults
        /// </summary>
        /// <returns>void</returns>
        public DialogResult SaveGeneralTab()
        {
            // First, we need to show any dialogs that may result in Cancel
            if (chkSaveWindowProperties.Checked && !WasSaveWindowPropertiesInitiallyChecked)
            {
                // The user wants to start saving the window positions etc.
                // If we have some information about this that we stored previously, we can offer to use it again...
                string localAppDataPath = Path.Combine(
                    TAppSettingsManager.GetLocalAppDataPath(),
                    CommonFormsResourcestrings.StrFolderOrganisationName,
                    System.Diagnostics.FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).ProductName);
                string settingsFileName = String.Format(CommonFormsResourcestrings.StrScreenPositionsFileName, UserInfo.GUserInfo.UserID);
                string settingsPath     = Path.Combine(localAppDataPath, settingsFileName);

                if (File.Exists(settingsPath))
                {
                    string msg = String.Format("{0}{1}{2}{3}{4}",
                                               CommonFormsResourcestrings.StrReuseScreenPositionsMessage1,
                                               CommonFormsResourcestrings.StrReuseScreenPositionsMessage2,
                                               Environment.NewLine,
                                               Environment.NewLine,
                                               CommonFormsResourcestrings.StrReuseScreenPositionsMessage3);
                    DialogResult result = MessageBox.Show(msg,
                                                          CommonFormsResourcestrings.StrReuseScreenPositionsTitle,
                                                          MessageBoxButtons.YesNoCancel,
                                                          MessageBoxIcon.Question);

                    if (result == DialogResult.Cancel)
                    {
                        return(result);
                    }

                    if (result == DialogResult.No)
                    {
                        try
                        {
                            // Delete the old file
                            File.Delete(settingsPath);
                        }
                        catch (Exception ex)
                        {
                            TLogging.Log(String.Format("Exception occurred while deleting the window position file '{0}': {1}",
                                                       settingsPath,
                                                       ex.Message), TLoggingType.ToLogfile);
                        }
                    }

                    if (result == DialogResult.Yes)
                    {
                        // Load the information we have already
                        PetraUtilsObject.LoadWindowPositionsFromFile();
                    }
                }
            }

            if (LanguageChanged)
            {
                string LanguageCode = cmbLanguage.GetSelectedString();
                string CultureCode  = cmbCulture.GetSelectedString();

                // send to server
                TRemote.MSysMan.Maintenance.WebConnectors.SetLanguageAndCulture(LanguageCode, CultureCode);

                // set local settings for client
                Catalog.Init(LanguageCode, CultureCode);

                // TODO: can we reload the main window with the new language?
                MessageBox.Show(Catalog.GetString("Please restart the OpenPetra client to see the new language"),
                                Catalog.GetString("Restart the client"),
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Information);
            }

            TUserDefaults.SetDefault(MSysManConstants.USERDEFAULT_NUMBEROFRECENTPARTNERS, nudNumberOfPartners.Value);
            TUserDefaults.SetDefault(TUserDefaults.NamedDefaults.USERDEFAULT_ESC_CLOSES_SCREEN, chkEscClosesScreen.Checked);
            TUserDefaults.SetDefault(TUserDefaults.NamedDefaults.USERDEFAULT_SAVE_WINDOW_POS_AND_SIZE, chkSaveWindowProperties.Checked);

            return(DialogResult.OK);
        }
Example #2
0
        /// <summary>
        /// Saves any changed preferences to s_user_defaults
        /// </summary>
        /// <returns>void</returns>
        public DialogResult SaveGeneralTab()
        {
            // First, we need to show any dialogs that may result in Cancel
            if (chkSaveWindowProperties.Checked && !WasSaveWindowPropertiesInitiallyChecked)
            {
                // The user wants to start saving the window positions etc.
                // If we have some information about this that we stored previously, we can offer to use it again...
                string localAppDataPath = Path.Combine(
                    TAppSettingsManager.GetLocalAppDataPath(),
                    CommonFormsResourcestrings.StrFolderOrganisationName,
                    System.Diagnostics.FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).ProductName);
                string settingsFileName = String.Format(CommonFormsResourcestrings.StrScreenPositionsFileName, UserInfo.GUserInfo.UserID);
                string settingsPath     = Path.Combine(localAppDataPath, settingsFileName);

                if (File.Exists(settingsPath))
                {
                    string msg = String.Format("{0}{1}{1}{2}",
                                               CommonFormsResourcestrings.StrReuseScreenPositionsMessage1,
                                               Environment.NewLine,
                                               CommonFormsResourcestrings.StrReuseScreenPositionsMessage2);

                    bool DoNotShowMessageBoxEverytime = false;

                    TFrmExtendedMessageBox extendedMessageBox = new TFrmExtendedMessageBox(FPetraUtilsObject.GetForm());

                    // customise button text
                    extendedMessageBox.YesButtonText = Catalog.GetString("Keep");
                    extendedMessageBox.NoButtonText  = Catalog.GetString("Discard");

                    extendedMessageBox.ShowDialog(msg,
                                                  CommonFormsResourcestrings.StrReuseScreenPositionsTitle,
                                                  string.Empty,
                                                  TFrmExtendedMessageBox.TButtons.embbYesNoCancel, TFrmExtendedMessageBox.TIcon.embiQuestion);
                    TFrmExtendedMessageBox.TResult result = extendedMessageBox.GetResult(out DoNotShowMessageBoxEverytime);

                    if (result == TFrmExtendedMessageBox.TResult.embrCancel)
                    {
                        return(DialogResult.Cancel);
                    }
                    else if (result == TFrmExtendedMessageBox.TResult.embrNo)
                    {
                        try
                        {
                            // Delete the old file
                            File.Delete(settingsPath);
                        }
                        catch (Exception ex)
                        {
                            TLogging.Log(String.Format("Exception occurred while deleting the window position file '{0}': {1}",
                                                       settingsPath,
                                                       ex.Message), TLoggingType.ToLogfile);
                        }
                    }
                    else if (result == TFrmExtendedMessageBox.TResult.embrYes)
                    {
                        // Load the information we have already
                        PetraUtilsObject.LoadWindowPositionsFromFile();
                    }
                }
            }

            if (LanguageChanged)
            {
                string LanguageCode = cmbLanguage.GetSelectedString();
                string CultureCode  = cmbCulture.GetSelectedString();

                // send to server
                TRemote.MSysMan.Maintenance.WebConnectors.SetLanguageAndCulture(LanguageCode, CultureCode);

                // set local settings for client
                Catalog.Init(LanguageCode, CultureCode);

                // TODO: can we reload the main window with the new language?
                MessageBox.Show(Catalog.GetString("Please restart the OpenPetra client to see the new language"),
                                Catalog.GetString("Restart the client"),
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Information);
            }

            TUserDefaults.SetDefault(TTextFileEncoding.ALLOW_MBCS_TEXT_ENCODING, chkImportAsianANSI.Checked);
            TUserDefaults.SetDefault(MSysManConstants.USERDEFAULT_NUMBEROFRECENTPARTNERS, nudNumberOfPartners.Value);
            TUserDefaults.SetDefault(TUserDefaults.NamedDefaults.USERDEFAULT_ESC_CLOSES_SCREEN, chkEscClosesScreen.Checked);
            TUserDefaults.SetDefault(TUserDefaults.NamedDefaults.USERDEFAULT_SAVE_WINDOW_POS_AND_SIZE, chkSaveWindowProperties.Checked);
            TUserDefaults.SetDefault(TUserDefaults.NamedDefaults.MODULE_TO_OPEN_AT_STARTUP, cmbInitialSelectedModule.GetSelectedString());

            return(DialogResult.OK);
        }