Beispiel #1
0
        public bool LoadSettingFromFile() //ref TestingForm oTestingForm)
        {
            bool   bRet  = false;
            string sFile = string.Empty;
            string sConnectionSettings = string.Empty;

            //TestSettingsData oTestSettingsData = null;
            this.ClearSettings();
            string sFileContents = string.Empty;

            if (UserIoHelper.PickLoadFromFile(FormDataFilePath, "*.xml", ref sFile, "XML files (*.xml)|*.xml"))
            {
                try
                {
                    sFileContents = System.IO.File.ReadAllText(sFile);
                    SettingsData  = SerialHelper.DeserializeObjectFromString <TestSettingsData>(sFileContents);
                    //SetFormFromData(ref oTestingForm);
                    bRet = true;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error Saving File");
                }
            }
            //oTestSettingsData = null;
            return(bRet);
        }
Beispiel #2
0
        /// <summary>
        /// this button handles displaying the File Open dialog and loading the settings from an existing xml file
        /// useriohelper is for displaying the dialog and serialhelper is for parsing out the xml for settings
        /// once the settings have been parsed from the xml file, setformfromconnectionsettings is called to populate the form
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void mnuFileLoadSettings_Click(object sender, EventArgs e)
        {
            string sFile               = string.Empty;
            string sFilter             = "XML files (*.xml)|*.xml|All files (*.*)|*.*";
            string sConnectionSettings = string.Empty;

            ConnectionSettings oConnectionSetting = null;
            string             sFileContents      = string.Empty;

            if (UserIoHelper.PickLoadFromFile(AppDomain.CurrentDomain.BaseDirectory, "*.xml", ref sFile, sFilter))
            {
                try
                {
                    sFileContents      = System.IO.File.ReadAllText(sFile);
                    oConnectionSetting = SerialHelper.DeserializeObjectFromString <ConnectionSettings>(sFileContents);
                    if (oConnectionSetting == null)
                    {
                        throw new Exception("Settings file cannot be deserialized.");
                    }
                    SetFormFromConnectionSettings(oConnectionSetting);
                }
                catch (Exception ex)
                {
                    txtBoxErrorLog.Clear();
                    txtBoxErrorLog.Text = ex.ToString() + "Error Loading File";
                }
            }
            oConnectionSetting = null;
        }