diff --git a/OWTrack/Form1.Designer.cs b/OWTrack/Form1.Designer.cs index e719c9d..56a4569 100644 --- a/OWTrack/Form1.Designer.cs +++ b/OWTrack/Form1.Designer.cs @@ -42,6 +42,7 @@ this.label4 = new System.Windows.Forms.Label(); this.reduceLossBut = new System.Windows.Forms.Button(); this.reduceWinBut = new System.Windows.Forms.Button(); + this.clearBut = new System.Windows.Forms.Button(); this.SuspendLayout(); // // label1 @@ -168,15 +169,26 @@ this.reduceWinBut.Name = "reduceWinBut"; this.reduceWinBut.Size = new System.Drawing.Size(20, 24); this.reduceWinBut.TabIndex = 9; - this.reduceWinBut.Text = "+"; + this.reduceWinBut.Text = "-"; this.reduceWinBut.UseVisualStyleBackColor = true; this.reduceWinBut.Click += new System.EventHandler(this.reduceWinBut_Click); // + // clearBut + // + this.clearBut.Location = new System.Drawing.Point(209, 132); + this.clearBut.Name = "clearBut"; + this.clearBut.Size = new System.Drawing.Size(49, 25); + this.clearBut.TabIndex = 10; + this.clearBut.Text = "clear"; + this.clearBut.UseVisualStyleBackColor = true; + this.clearBut.Click += new System.EventHandler(this.clearBut_Click); + // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(263, 170); + this.Controls.Add(this.clearBut); this.Controls.Add(this.reduceWinBut); this.Controls.Add(this.reduceLossBut); this.Controls.Add(this.label4); @@ -214,6 +226,7 @@ private System.Windows.Forms.Label label4; private System.Windows.Forms.Button reduceLossBut; private System.Windows.Forms.Button reduceWinBut; + private System.Windows.Forms.Button clearBut; } } diff --git a/OWTrack/Form1.cs b/OWTrack/Form1.cs index 1bfd978..9f8fa9e 100644 --- a/OWTrack/Form1.cs +++ b/OWTrack/Form1.cs @@ -1,6 +1,8 @@ using System; using System.Drawing; using System.Windows.Forms; +using Newtonsoft.Json; +using System.IO; namespace OWTrack { @@ -13,20 +15,17 @@ namespace OWTrack public Form1() { InitializeComponent(); + loadSave(); checkStatus(); label4.Text = Program.Version; - Text = "OWTrack " + Program.Version; + Text = "OWTrack " + Program.Version; } - - private void timer1_Tick(object sender, EventArgs e) - { - checkStatus(); - } - + private void checkStatus() { try { + File.WriteAllText(Directory.GetCurrentDirectory() + "/data.json", JsonConvert.SerializeObject(tr)); Time.Text = DateTime.Now.ToString("h:mm tt"); if (tr.owRunning()) { @@ -45,6 +44,49 @@ namespace OWTrack } } + private void loadSave() + { + if (saveExist()) + { + tr.wins = savedTracker().wins; + tr.losses = savedTracker().losses; + update(); + } + else MessageBox.Show("no save"); + } + + private bool saveExist() + { + try + { + if (File.Exists(Directory.GetCurrentDirectory() + "/data.json")) { return true; } + else return false; + } + catch (Exception e) + { + MessageBox.Show(e.Message); + return false; + } + } + + private Tracker savedTracker() + { + try + { + return JsonConvert.DeserializeObject(File.ReadAllText(Directory.GetCurrentDirectory() + "/data.json")); + } + catch (Exception e) + { + MessageBox.Show(e.Message); + return null; + } + } + + private void timer1_Tick(object sender, EventArgs e) + { + checkStatus(); + } + private void button1_Click(object sender, EventArgs e) { tr.addWin(); @@ -74,6 +116,11 @@ namespace OWTrack Wins.Text = tr.GetWins().ToString(); Losses.Text = tr.GetLosses().ToString(); } - + + private void clearBut_Click(object sender, EventArgs e) + { + tr.reset(); + update(); + } } } diff --git a/OWTrack/OWTrack.csproj b/OWTrack/OWTrack.csproj index a21b8d3..91f8bc3 100644 --- a/OWTrack/OWTrack.csproj +++ b/OWTrack/OWTrack.csproj @@ -68,6 +68,9 @@ true + + ..\packages\Newtonsoft.Json.11.0.2\lib\net45\Newtonsoft.Json.dll + @@ -102,6 +105,7 @@ True Resources.resx + SettingsSingleFileGenerator Settings.Designer.cs diff --git a/OWTrack/Program.cs b/OWTrack/Program.cs index d2adcf9..73159b4 100644 --- a/OWTrack/Program.cs +++ b/OWTrack/Program.cs @@ -8,6 +8,7 @@ namespace OWTrack { static class Program { + public static string Version = "1.2.2"; /// /// The main entry point for the application. /// @@ -18,6 +19,6 @@ namespace OWTrack Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Form1()); } - public static string Version = "1.2.1"; + } } diff --git a/OWTrack/Tracker.cs b/OWTrack/Tracker.cs index 8f22a14..18f84b9 100644 --- a/OWTrack/Tracker.cs +++ b/OWTrack/Tracker.cs @@ -1,19 +1,19 @@ using System; using System.Diagnostics; using System.Linq; - +using System.IO; namespace OWTrack { class Tracker { - private int wins, losses = 0; + public int wins, losses = 0; public void Track() { - } - + } + public bool owRunning() { try @@ -29,6 +29,7 @@ namespace OWTrack } } + public void reset() { wins = 0; losses = 0; } public void addWin() { wins++; } public void addLoss() { losses++; } public void reduceWin() { wins--; } diff --git a/OWTrack/packages.config b/OWTrack/packages.config new file mode 100644 index 0000000..5762754 --- /dev/null +++ b/OWTrack/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file