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 { if (File.Exists(fileName)) { File.Delete(fileName); xmlDoc.Load(fileName); } else 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"); XmlElement localtime = xmlDoc.CreateElement("localtime"); XmlText localtimeText = xmlDoc.CreateTextNode("localtime"); if (rb12Hour.Checked) localtimeText.Value = "12 hour"; else if (rb24Hour.Checked) localtimeText.Value = "24 hour"; root.AppendChild(mainSettingsNode); mainSettingsNode.AppendChild(localtime); localtime.AppendChild(localtimeText); xmlDoc.Save(fileName); } catch(Exception ex) { MessageBox.Show(ex.ToString()); } } private void WriteError(string ErrorMessage) { MessageBox.Show(ErrorMessage.ToString()); } } }