Help With XML and timer

Guys,

I am attempting to write a reminder program storing the reminder date, time and detail in an XML file. I was advised that this is probably the best thing to do. I have started reading through XML last night and I have a basic jist of it but I am struggling with a few minor things. Below the code I have wrtten within the tick event of the timer.

[CODE]
private void timer1_Tick(object sender, EventArgs e)
{
//Retrieve file and convert to Stream
System.IO.StreamReader sr = new System.IO.StreamReader(@XMLFile1.xml);
//Xml Text Reader
System.Xml.XmlTextReader xr = new System.Xml.XmlTextReader(sr);
//Put it all into a Document
System.Xml.XmlDocument calendar = new System.Xml.XmlDocument();
//Load the Document into memory
calendar.Load(xr);
//Set datetime to current datetime
DateTime dtCurrentTime = DateTime.Now;
//Display current date time in label3
label3.Text = dtCurrentTime.ToShortTimeString();
//Read xml document
System.Xml.XmlNodeList appointdetail = calendar.SelectNodes("Calendar/Appointment");
System.Xml.XmlNode timedet = appointdetail.Item(0).SelectSingleNode("AppointmentTime");
//Output time from XML document to label2
label2.Text = timedet.InnerText;
if (label3.Text == label2.Text)
{
MessageBox.Show("AppointmentDetails");
}
}
[/CODE]

Now, for testing this I am extracting the time from the XML doc to label2 in order that I can eventualy check if the time is the same as the system time and then pop up a message box with the details. The time I have stored in the ML doc is 07:27AM. However, when the details is pulled into label2 it comes out as 19:00. Does anybody know why it is doing this or if there is a much easier way of doing this then I would appreciate the help. Still a newby to C# and now XML

Comments

  • Hi
    here is how i cheat i do not have to learn how to use xml
    1)Create a structure and class
    2)put my data in the structure
    3)Serialize the structure into an xml
    when i need the dat

    1)create an instance of the structure
    2)deseriaize the xml file that contains that strucure
    for more info search about XmlSerializer Class

    Here is some sample for a project of mine

    the structure that i need :
    public struct ServerConfig
    {
    public String IP_Addres;
    public String Potr_number;
    public String MySqlHost;
    public String DatabaseName;
    public String MySqlUser_Name;
    public String MySqlPassword;

    }
    the functions for saving and retriving the data

    void SaveSettings()
    {
    ServerConfig settings;
    settings.IP_Addres = this.IPaddress;
    settings.Potr_number = this.portNumber;
    settings.MySqlHost = this.server;
    settings.DatabaseName = this.DB;
    settings.MySqlUser_Name = this.userid;
    settings.MySqlPassword = this.password;//DataBaseLib.HandleDataBase.EncryptPassword(this.password);
    System.Xml.Serialization.XmlSerializer xs = new System.Xml.Serialization.XmlSerializer(typeof(ServerConfig));
    System.IO.StreamWriter sw = new System.IO.StreamWriter("serverConfig.cfg");
    xs.Serialize(sw, settings);

    }

    void LoadSettings()
    {
    System.Xml.Serialization.XmlSerializer xs = new System.Xml.Serialization.XmlSerializer(typeof(ServerConfig));
    System.IO.StreamReader sr = new System.IO.StreamReader("serverConfig.cfg");
    ServerConfig settings = (ServerConfig)xs.Deserialize(sr);
    this.IPaddress= settings.IP_Addres ;
    this.portNumber =settings.Potr_number ;
    this.server= settings.MySqlHost ;
    this.DB= settings.DatabaseName ;
    this.userid= settings.MySqlUser_Name ;
    this.password = settings.MySqlPassword;// DataBaseLib.HandleDataBase.DecriptPassword(settings.MySqlPassword);
    }

    in my example i do not encrypt my password, my project is not ready, but when it be ready i will encrypt the password and then put it to the file


    simion314
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion