OWtrack/OWTrack/Form1.cs

106 lines
2.7 KiB
C#
Raw Normal View History

2018-07-13 03:24:05 +02:00
using System;
using System.Drawing;
using System.Windows.Forms;
2018-08-12 01:21:12 +02:00
using Newtonsoft.Json;
using System.IO;
2018-07-13 03:24:05 +02:00
namespace OWTrack
{
public partial class Form1 : Form
{
2018-07-13 03:57:29 +02:00
Tracker tr = new Tracker();
private const string IS_RUNNING = "Running";
private const string NOT_RUNNING = " Not running";
2018-07-13 03:24:05 +02:00
public Form1()
{
InitializeComponent();
2018-08-12 01:21:12 +02:00
loadSave();
2018-07-13 03:57:29 +02:00
checkStatus();
2018-07-27 03:45:13 +02:00
label4.Text = Program.Version;
2018-08-12 01:21:12 +02:00
Text = "OWTrack " + Program.Version;
2018-07-13 03:57:29 +02:00
}
2018-08-12 01:21:12 +02:00
2018-07-13 03:57:29 +02:00
private void checkStatus()
{
2018-07-15 21:22:02 +02:00
try
{
2018-08-12 01:21:12 +02:00
File.WriteAllText(Directory.GetCurrentDirectory() + "/data.json", JsonConvert.SerializeObject(tr));
2018-07-15 21:22:02 +02:00
Time.Text = DateTime.Now.ToString("h:mm tt");
if (tr.owRunning())
{
status.Text = IS_RUNNING;
status.ForeColor = Color.FromArgb(128, 255, 128);
}
else
{
status.Text = NOT_RUNNING;
status.ForeColor = Color.Red;
}
}
catch (Exception e)
{
MessageBox.Show(e.Message);
}
2018-07-13 03:24:05 +02:00
}
2018-07-13 04:13:05 +02:00
2018-08-12 01:21:12 +02:00
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();
}
2018-07-13 04:13:05 +02:00
private void button1_Click(object sender, EventArgs e)
{
tr.addWin();
update();
}
2018-07-20 02:28:26 +02:00
2018-07-13 04:13:05 +02:00
private void button2_Click(object sender, EventArgs e)
{
tr.addLoss();
update();
}
2018-07-20 02:28:26 +02:00
2018-08-03 02:45:06 +02:00
private void reduceWinBut_Click(object sender, EventArgs e)
{
tr.reduceWin();
update();
}
private void reduceLossBut_Click(object sender, EventArgs e)
{
tr.rediceLoss();
update();
}
2018-07-13 04:13:05 +02:00
private void update()
{
Wins.Text = tr.GetWins().ToString();
Losses.Text = tr.GetLosses().ToString();
2018-08-03 02:45:06 +02:00
}
2018-07-13 03:24:05 +02:00
}
}