Subversion Repositories Code-Repo

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
57 Kevin 1
using System;
2
using System.Collections.Generic;
3
using System.Linq;
4
using System.Text;
5
using System.Windows.Forms;
6
using System.IO;
7
using System.Xml.Linq;
8
 
9
namespace SWAT_Office_App
10
{
11
    class StatLogging
12
    {
13
        private static string logFileLocation = "StatLog.xml";
14
        public static int AccountsCreated { get; set; }
15
        public static int SharesCreated { get; set; }
16
 
17
        public static void ImportSettings()
18
        {
19
            try
20
            {
21
                if (File.Exists(logFileLocation))
22
                {
23
                    XElement Log = XElement.Load(logFileLocation);
24
                    AccountsCreated = int.Parse(Log.Element("AccountsCreated").Value);
25
                    SharesCreated = int.Parse(Log.Element("SharesCreated").Value);
26
                }
27
                else
28
                {
29
                    DebugText.appendText("No existing stat logging file detected.");
30
                    WriteDefaultConfigFile();
31
                }
32
            }
33
            catch (Exception e)
34
            {
35
                //MessageBox.Show(e.ToString(), "Error");
36
                DebugText.appendText(e.ToString());
37
                MessageBox.Show("An error has occured. Please notify a supervisor to debug.", "Error");
38
            }
39
        }
40
        public static void ExportSettings()
41
        {
42
            try
43
            {
44
                XElement Log = XElement.Load(logFileLocation);
45
                Log.SetElementValue("AccountsCreated", AccountsCreated);
46
                Log.SetElementValue("SharesCreated", SharesCreated);
47
                Log.Save(logFileLocation);
48
            }
49
            catch (Exception e)
50
            {
51
                //MessageBox.Show(e.ToString(), "Error");
52
                DebugText.appendText(e.ToString());
53
                MessageBox.Show("An error has occured. Please notify a supervisor to debug.", "Error");
54
            }
55
        }
56
        private static void WriteDefaultConfigFile()
57
        {
58
            try
59
            {
60
                XElement Log = new XElement("StatLog",
61
                    new XElement("AccountsCreated", 0),
62
                    new XElement("SharesCreated", 0)
63
                    );
64
                Log.Save(logFileLocation);
65
            }
66
            catch (Exception e)
67
            {
68
                //MessageBox.Show(e.ToString(), "Error");
69
                DebugText.appendText(e.ToString());
70
                MessageBox.Show("An error has occured. Please notify a supervisor to debug.", "Error");
71
            }
72
        }
73
    }
74
}