using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.IO; using System.Text; using System.Threading; using System.Windows.Forms; using System.Xml; namespace FrostDiary { public partial class Form1 : Form { public Form1() { InitializeComponent(); txtEntryDate.Text = ""; txtEntryName.Text = ""; txtEntryNumber.Text = ""; txtEntryTime.Text = ""; rtbEntry.Text = ""; entryToolStripMenuItem.Enabled = false; } private void entryToolStripMenuItem_Click(object sender, EventArgs e) { ssProgressBar.Visible = true; ssProgressBar.Minimum = 1; ssProgressBar.Maximum = 2; ssProgressBar.Value = 1; ssProgressBar.Step = 1; txtEntryDate.Text = DateTime.Now.ToLongDateString(); txtEntryName.Text = string.Empty; txtEntryNumber.Text = txtEntryTime.Text.Length != 0 ? (Convert.ToInt32(txtEntryNumber.Text) + 1).ToString() : "0"; txtEntryTime.Text = DateTime.Now.ToLongTimeString(); ssProgressBar.PerformStep(); Thread.Sleep(1000); ssProgressBar.Visible = false; ssStatusLabel.Text = ""; } private void openDiaryToolStripMenuItem_Click(object sender, EventArgs e) { FileToOpen(); entryToolStripMenuItem.Enabled = true; } public void FileToOpen() { OpenFileDialog ofd = new OpenFileDialog(); ofd.InitialDirectory = "C:\\Program Files\\FrostDiary\\User\\"; ofd.Filter = "FrostDiary DiaryEntries (.fdd)|*.fdd"; ofd.FilterIndex = 2; ofd.RestoreDirectory = true; ssProgressBar.Visible = true; ssProgressBar.Minimum = 1; ssProgressBar.Maximum = 10; ssProgressBar.Value = 1; ssProgressBar.Step = 1; if (ofd.ShowDialog() == DialogResult.OK) { XmlTextReader xtr = new XmlTextReader(ofd.FileName); XmlReaderSettings s = new XmlReaderSettings(); s.IgnoreWhitespace = true; try { while (xtr.Read()) { ssProgressBar.PerformStep(); if (xtr.NodeType == XmlNodeType.Element) { if (xtr.LocalName.Equals("EntryNumber")) { txtEntryNumber.Text = xtr.ReadString(); } if (xtr.LocalName.Equals("Title")) { txtEntryName.Text = xtr.ReadString(); } if (xtr.LocalName.Equals("Date")) { txtEntryDate.Text = xtr.ReadString(); } if (xtr.LocalName.Equals("Time")) { txtEntryTime.Text = xtr.ReadString(); } if (xtr.LocalName.Equals("UserEntry")) { rtbEntry.Text = xtr.ReadString(); } } } Thread.Sleep(1000); ssProgressBar.Visible = false; ssStatusLabel.Text = "File successfully opened."; } catch (XmlException ex) { MessageBox.Show(ex.Message); } finally { xtr.Close(); } } } } }