private bool GetScreenFilePath(out string APath) { string localAppDataPath = Path.Combine( TAppSettingsManager.GetLocalAppDataPath(), "OpenPetraOrg", System.Diagnostics.FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).ProductName); string settingsFileName = String.Format("{0}CSVSeparatorDialog.cfg", FUserID == null ? "" : FUserID + "."); try { if (!Directory.Exists(localAppDataPath)) { Directory.CreateDirectory(localAppDataPath); } APath = Path.Combine(localAppDataPath, settingsFileName); } catch (Exception ex) { TLogging.Log(String.Format("Exception occurred while creating the folder for a window position file '{0}': {1}", localAppDataPath, ex.Message), TLoggingType.ToLogfile); APath = string.Empty; return(false); } return(true); }
/// <summary> /// Gets the full path to the location for a temporary copy of a Templater template downloaded from the database. /// The location will be beneath the user's Local Application Data area /// </summary> /// <param name="AUniqueTemplateName">A unique filename made up of FormCode/FormName and FormLanguage</param> /// <param name="ATemplateFileExtension">A file extension with or without an initial dot</param> /// <returns>Full path to the file for the specified code, name and langauge</returns> public static String GetDefaultTemporaryTemplatePath(string AUniqueTemplateName, string ATemplateFileExtension) { string s = Path.Combine(TAppSettingsManager.GetLocalAppDataPath(), "OpenPetraOrg", "Templates", "Client", AUniqueTemplateName); if (ATemplateFileExtension.Length > 0) { if (!ATemplateFileExtension.StartsWith(".")) { s += "."; } s += ATemplateFileExtension; } return(s); }
/// <summary> /// Loads our window positions file for the current user /// </summary> public void LoadWindowPositionsFromFile() { FWindowPositions.Clear(); 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); try { if (File.Exists(settingsPath)) { using (StreamReader sr = new StreamReader(settingsPath)) { while (!sr.EndOfStream) { string oneLine = sr.ReadLine(); if (oneLine.Contains("=")) { string[] items = oneLine.Split('='); FWindowPositions.Add(items[0], items[1]); } } sr.Close(); } } } catch (Exception ex) { TLogging.Log(String.Format("Exception occurred while loading the window position file '{0}': {1}", settingsPath, ex.Message), TLoggingType.ToLogfile); } FWindowPositionsLoaded = true; }
/// <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); }
/// <summary> /// Called by TFrmPetraUtils during the TFrmPetra_Closing event /// </summary> public void TForm_Closing() { // Deal with the window positions which are stored on the local file system 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 (TUserDefaults.GetBooleanDefault(TUserDefaults.NamedDefaults.USERDEFAULT_SAVE_WINDOW_POS_AND_SIZE, true)) { // This is where we 'remember' the window position information if (FWinForm.Name == "TFrmMainWindowNew") { // we are closing the main window // Get our own window position properties GetWindowPositionProperties(); // Now save all the properties for all windows we know about try { if (!Directory.Exists(localAppDataPath)) { Directory.CreateDirectory(localAppDataPath); } using (StreamWriter sw = new StreamWriter(settingsPath)) { foreach (string key in FWindowPositions.Keys) { sw.WriteLine("{0}={1}", key, FWindowPositions[key]); } sw.Close(); } } catch (Exception ex) { TLogging.Log(String.Format("Exception occurred while saving the window position file '{0}': {1}", settingsPath, ex.Message), TLoggingType.ToLogfile); } } else if ((FWinForm.Name == "TFrmPartnerEdit") || (FWinForm.Name == "TFrmGiftBatch") || (FWinForm.Name == "TFrmGLBatch") || (FWinForm.Name == "TPartnerFindScreen")) { // We always save the settings for these forms - they can be launched from the main window or from Partner/Find or several other ways GetWindowPositionProperties(); } else if ((FCallerForm != null) && (FCallerForm.Name == "TFrmMainWindowNew") && !FWinForm.Modal) { // we were opened by the main window GetWindowPositionProperties(); } } else { // We are closing a screen and not saving window positions (or no longer saving them) FWindowPositions.Clear(); FWindowPositionsLoaded = false; } }
/// <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); }