All pastes #261403 Raw Edit

Kiryn

public text v1 · immutable
#261403 ·published 2006-11-29 05:45 UTC
rendered paste body
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using System.IO;

namespace Frost_Diary
{
    public partial class Settings : Form
    {
        public Settings()
        {
            InitializeComponent();
        }

        private void Settings_FormClosed(object sender, FormClosedEventArgs e)
        {
            CreateXMLConfigurationFile();
        }

        private void CreateXMLConfigurationFile()
        {
            try
            {
                string fileName = "frostconfiguration.xml";
                XmlDocument xmlDoc = new XmlDocument();
                try
                {
                    xmlDoc.Load(fileName);
                }
                catch (FileNotFoundException)
                {
                    XmlTextWriter writer = new XmlTextWriter(fileName, Encoding.UTF8);
                    writer.Formatting = Formatting.Indented;
                    writer.WriteProcessingInstruction("xml", "version=\"1.0\" encoding=\"utf-8\"");
                    writer.WriteStartElement("FrostDiary");
                    writer.Close();
                    xmlDoc.Load(fileName);
                }
                XmlNode root = xmlDoc.DocumentElement;
                XmlElement mainSettingsNode = xmlDoc.CreateElement("mainsettings");
                XmlText localtime = xmlDoc.CreateTextNode("localtime");
                if (rb12Hour.Checked)
                    localtime.Value = "12 hour";
                else if (rb24Hour.Checked)
                    localtime.Value = "24 hour";

                root.AppendChild(mainSettingsNode);
                mainSettingsNode.AppendChild(localtime);
                xmlDoc.Save(fileName);
            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }

        private void WriteError(string ErrorMessage)
        {
            MessageBox.Show(ErrorMessage.ToString());
        }
    }
}