Ejemplo n.º 1
0
 //Konstruktor
 public Calculator(CalcForm newForm)
 {
     this.Form = newForm;
 }
Ejemplo n.º 2
0
        public static void LoadFile(string fileName, CalcForm form, bool custom)
        {
            try
            {
                if (!File.Exists(fileName))
                {
                    Debug.WriteLine("The settings file '" + fileName + "' does not exist.");
                    return;
                }

                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.Load(fileName);

                LoadSettings(xmlDoc);
                Data.Load(xmlDoc, custom);
                Help.Load(xmlDoc);
                form.LoadSettings(xmlDoc, custom);
            }
            catch (Exception ex)
            {
                MessageBox.Show("An error occurred when trying to load the settings file '" + fileName + "':\n" + ex.Message + "\n\n" + ex.StackTrace, "Settings Not Loaded");
            }
        }
Ejemplo n.º 3
0
        public static void Save(CalcForm form)
        {
            try
            {
                string appDataPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + Path.DirectorySeparatorChar + Globals.k_appNameIdent;
                if (!Directory.Exists(appDataPath)) Directory.CreateDirectory(appDataPath);

                string fileName = appDataPath + Path.DirectorySeparatorChar + Globals.k_settingsFileName;

                XmlTextWriter xml = new XmlTextWriter(fileName, Encoding.UTF8);
                try
                {
                    xml.Formatting = Formatting.Indented;
                    xml.WriteStartDocument();
                    xml.WriteStartElement(Globals.k_appNameIdent);

                    SaveSettings(xml);
                    Data.Save(xml, true);
                    form.SaveSettings(xml);

                    xml.WriteEndElement();
                    xml.WriteEndDocument();
                }
                finally
                {
                    xml.Close();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("An error occurred when trying to save the settings:\n" + ex.Message + "\n\n" + ex.StackTrace, "Settings Not Saved");
            }
        }
Ejemplo n.º 4
0
        public static void Load(CalcForm form)
        {
            try
            {
                string defaultFile = Path.GetDirectoryName(Application.ExecutablePath) + Path.DirectorySeparatorChar + Globals.k_defaultSettingsFileName;
                string userFile = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + Path.DirectorySeparatorChar
                    + Globals.k_appNameIdent + Path.DirectorySeparatorChar + Globals.k_settingsFileName;

                Data.SetDefaults();
                LoadFile(defaultFile, form, false);
                LoadFile(userFile, form, true);
            }
            catch (Exception ex)
            {
                MessageBox.Show("An error occurred when trying to load the settings:\n" + ex.Message + "\n\n" + ex.StackTrace, "Settings Not Loaded");
            }
        }