save last record - JSON
This commit is contained in:
parent
38bb3bd30d
commit
bba991d3bf
@ -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<Tracker>(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();
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user