From 38bb3bd30db258ab5c26ecc2fe2f46b8492e5df0 Mon Sep 17 00:00:00 2001 From: HeshamTB Date: Sun, 12 Aug 2018 00:03:42 +0300 Subject: [PATCH 1/3] added JSON --- OWTrack/OWTrack.csproj | 4 ++++ OWTrack/Program.cs | 3 ++- OWTrack/Tracker.cs | 1 + OWTrack/packages.config | 4 ++++ 4 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 OWTrack/packages.config 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..35bff94 100644 --- a/OWTrack/Program.cs +++ b/OWTrack/Program.cs @@ -8,6 +8,7 @@ namespace OWTrack { static class Program { + public static string Version = "1.2.1"; /// /// 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..d4aa4c9 100644 --- a/OWTrack/Tracker.cs +++ b/OWTrack/Tracker.cs @@ -1,6 +1,7 @@ using System; using System.Diagnostics; using System.Linq; +using Newtonsoft.Json; namespace OWTrack 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 From bba991d3bff6e005bfcbb83cda2fd06324beb8d6 Mon Sep 17 00:00:00 2001 From: HeshamTB Date: Sun, 12 Aug 2018 02:21:12 +0300 Subject: [PATCH 2/3] save last record - JSON --- OWTrack/Form1.cs | 40 +++++++++++++++++++++++++++++++++------- OWTrack/Tracker.cs | 9 ++++----- 2 files changed, 37 insertions(+), 12 deletions(-) diff --git a/OWTrack/Form1.cs b/OWTrack/Form1.cs index 1bfd978..cae2868 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,33 @@ namespace OWTrack } } + private void loadSave() + { + if (saveExist()) + { + tr.wins = savedTracker().wins; + tr.losses = savedTracker().losses; + update(); + } + else MessageBox.Show("no save"); + } + + private bool saveExist() + { + if (File.Exists(Directory.GetCurrentDirectory() + "/data.json")) { return true; } + else return false; + } + + private Tracker savedTracker() + { + return JsonConvert.DeserializeObject(File.ReadAllText(Directory.GetCurrentDirectory() + "/data.json")); + } + + private void timer1_Tick(object sender, EventArgs e) + { + checkStatus(); + } + private void button1_Click(object sender, EventArgs e) { tr.addWin(); diff --git a/OWTrack/Tracker.cs b/OWTrack/Tracker.cs index d4aa4c9..bd2977b 100644 --- a/OWTrack/Tracker.cs +++ b/OWTrack/Tracker.cs @@ -1,20 +1,19 @@ using System; using System.Diagnostics; using System.Linq; -using Newtonsoft.Json; - +using System.IO; namespace OWTrack { class Tracker { - private int wins, losses = 0; + public int wins, losses = 0; public void Track() { - } - + } + public bool owRunning() { try From 3b1a3d80bb5f6af42f1cc36feba6a8002f79055c Mon Sep 17 00:00:00 2001 From: HeshamTB Date: Sun, 12 Aug 2018 02:33:26 +0300 Subject: [PATCH 3/3] final for 1.2.2 --- OWTrack/Form1.Designer.cs | 15 ++++++++++++++- OWTrack/Form1.cs | 29 +++++++++++++++++++++++++---- OWTrack/Program.cs | 2 +- OWTrack/Tracker.cs | 1 + 4 files changed, 41 insertions(+), 6 deletions(-) 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 cae2868..9f8fa9e 100644 --- a/OWTrack/Form1.cs +++ b/OWTrack/Form1.cs @@ -57,13 +57,29 @@ namespace OWTrack private bool saveExist() { - if (File.Exists(Directory.GetCurrentDirectory() + "/data.json")) { return true; } - else return false; + 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() { - return JsonConvert.DeserializeObject(File.ReadAllText(Directory.GetCurrentDirectory() + "/data.json")); + 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) @@ -100,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/Program.cs b/OWTrack/Program.cs index 35bff94..73159b4 100644 --- a/OWTrack/Program.cs +++ b/OWTrack/Program.cs @@ -8,7 +8,7 @@ namespace OWTrack { static class Program { - public static string Version = "1.2.1"; + public static string Version = "1.2.2"; /// /// The main entry point for the application. /// diff --git a/OWTrack/Tracker.cs b/OWTrack/Tracker.cs index bd2977b..18f84b9 100644 --- a/OWTrack/Tracker.cs +++ b/OWTrack/Tracker.cs @@ -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--; }