From 1fb0e5801b0605cf0267c544a5738ef65bcffb32 Mon Sep 17 00:00:00 2001 From: Beppe Date: Sat, 3 Aug 2019 21:29:23 +0200 Subject: [PATCH] Events added for ploegen.cs (reset json files for next boot) --- Online Gokkantoor/Data/data.cs | 16 +++---- Online Gokkantoor/Globals/Classes/Game.cs | 44 +++++++++++++++++-- Online Gokkantoor/Globals/Classes/Ploeg.cs | 18 ++++++-- Online Gokkantoor/Globals/Interfaces/IGame.cs | 1 + .../Globals/Interfaces/IPloeg.cs | 5 ++- 5 files changed, 68 insertions(+), 16 deletions(-) diff --git a/Online Gokkantoor/Data/data.cs b/Online Gokkantoor/Data/data.cs index a26f2a3..27c796d 100644 --- a/Online Gokkantoor/Data/data.cs +++ b/Online Gokkantoor/Data/data.cs @@ -21,7 +21,7 @@ namespace Data List list = new List(); try { - using (StreamReader file = File.OpenText(@"Data/bets.json")) + using (StreamReader file = File.OpenText(@"../../Data/bets.json")) { JsonSerializer serializer = new JsonSerializer(); @@ -42,7 +42,7 @@ namespace Data try { - using (StreamReader file = File.OpenText(@"Data/games.json")) + using (StreamReader file = File.OpenText(@"../../Data/games.json")) { JsonSerializer serializer = new JsonSerializer(); list = (List)serializer.Deserialize(file, typeof(List)); @@ -61,7 +61,7 @@ namespace Data List list = new List(); try { - using (StreamReader file = File.OpenText(@"Data/persons.json")) + using (StreamReader file = File.OpenText(@"../../Data/persons.json")) { JsonSerializer serializer = new JsonSerializer(); list = (List)serializer.Deserialize(file, typeof(List)); @@ -80,7 +80,7 @@ namespace Data List list = new List(); try { - using (StreamReader file = File.OpenText(@"Data/ploegen.json")) + using (StreamReader file = File.OpenText(@"../../Data/ploegen.json")) { JsonSerializer serializer = new JsonSerializer(); list = (List)serializer.Deserialize(file, typeof(List)); @@ -96,7 +96,7 @@ namespace Data public void saveBets(List b) { - using (StreamWriter file = File.CreateText(@"Data/bets.json")) + using (StreamWriter file = File.CreateText(@"../../Data/bets.json")) { JsonSerializer serializer = new JsonSerializer(); serializer.Serialize(file, b); @@ -105,7 +105,7 @@ namespace Data public void saveGames(List g) { - using (StreamWriter file = File.CreateText(@"Data/games.json")) + using (StreamWriter file = File.CreateText(@"../../Data/games.json")) { JsonSerializer serializer = new JsonSerializer(); serializer.Serialize(file, g); @@ -114,7 +114,7 @@ namespace Data public void savePersons(List p) { - using (StreamWriter file = File.CreateText(@"Data/persons.json")) + using (StreamWriter file = File.CreateText(@"../../Data/persons.json")) { JsonSerializer serializer = new JsonSerializer(); serializer.Serialize(file, p); @@ -123,7 +123,7 @@ namespace Data public void savePloegen(List p) { - using (StreamWriter file = File.CreateText(@"Data/ploegen.json")) + using (StreamWriter file = File.CreateText(@"../../Data/ploegen.json")) { JsonSerializer serializer = new JsonSerializer(); serializer.Serialize(file, p); diff --git a/Online Gokkantoor/Globals/Classes/Game.cs b/Online Gokkantoor/Globals/Classes/Game.cs index 421c7c1..42053ba 100644 --- a/Online Gokkantoor/Globals/Classes/Game.cs +++ b/Online Gokkantoor/Globals/Classes/Game.cs @@ -11,38 +11,62 @@ namespace Globals.classes [JsonConstructor] public Game(int Id, Ploeg home, Ploeg away, DateTime date) { + homeSetBool = false; + awaySetBool = false; + this.Id = Id; this.home = home; this.away = away; + this.home.scoreChanged += homeSet; + this.away.scoreChanged += awaySet; this.date = date; } public Game(Ploeg home, Ploeg away, DateTime d) { + homeSetBool = false; + awaySetBool = false; + this.home = home; this.away = away; + this.home.scoreChanged += homeSet; + this.away.scoreChanged += awaySet; + this.date = d; } public Game(Ploeg home, Ploeg away, DateTime d, int scoreHome, int scoreAway) { + homeSetBool = false; + awaySetBool = false; + this.home = home; this.away = away; - this.home.score = scoreHome; - this.away.score = scoreAway; + this.home.scoreChanged += homeSet; + this.away.scoreChanged += awaySet; + this.home.setScore(scoreHome); + this.away.setScore(scoreAway); this.date = d; } public Game(int id, Ploeg home, Ploeg away) { + homeSetBool = false; + awaySetBool = false; Id = id; this.home = home ?? throw new ArgumentNullException(nameof(home)); this.away = away ?? throw new ArgumentNullException(nameof(away)); + this.home.scoreChanged += homeSet; + this.away.scoreChanged += awaySet; } public Game(int id, Ploeg home, Ploeg away, int scoreHome, int scoreAway) { + homeSetBool = false; + awaySetBool = false; Id = id; this.home = home ?? throw new ArgumentNullException(nameof(home)); this.away = away ?? throw new ArgumentNullException(nameof(away)); - this.home.score = scoreHome; - this.away.score = scoreAway; + this.home.scoreChanged += homeSet; + this.away.scoreChanged += awaySet; + this.home.setScore(scoreHome); + this.away.setScore(scoreAway); } [JsonProperty("id")] public int Id { get; set; } @@ -53,6 +77,18 @@ namespace Globals.classes [JsonProperty("Date")] public DateTime date { get; set; } //y m d + private bool homeSetBool; + private bool awaySetBool; + private void homeSet (object s, EventArgs e) + { + homeSetBool = true; + + } + private void awaySet(object s, EventArgs e) + { + awaySetBool = true; + } + public state getWinner() { if (!this.home.scoreSet || !this.away.scoreSet) diff --git a/Online Gokkantoor/Globals/Classes/Ploeg.cs b/Online Gokkantoor/Globals/Classes/Ploeg.cs index b247d12..e43108c 100644 --- a/Online Gokkantoor/Globals/Classes/Ploeg.cs +++ b/Online Gokkantoor/Globals/Classes/Ploeg.cs @@ -34,9 +34,11 @@ namespace Globals.classes public int Id { get; set; } public string naam { get; set; } - public int score { get; set; } - public bool scoreSet { get => this.score != int.MinValue; } - + public int score { get; private set; } + public bool scoreSet { get; } + + public event EventHandler scoreChanged; + public override bool Equals(object obj) { try @@ -66,5 +68,15 @@ namespace Globals.classes return this.Id + ": " + this.naam + score; } + public void setScore(int i) + { + EventHandler h = scoreChanged; + if (null != h) h(this, EventArgs.Empty); + this.score = i; + } + public int getScore() + { + return this.score; + } } } diff --git a/Online Gokkantoor/Globals/Interfaces/IGame.cs b/Online Gokkantoor/Globals/Interfaces/IGame.cs index 7b887df..9bea3c4 100644 --- a/Online Gokkantoor/Globals/Interfaces/IGame.cs +++ b/Online Gokkantoor/Globals/Interfaces/IGame.cs @@ -11,5 +11,6 @@ namespace Globals.Interfaces Ploeg away { get; set; } DateTime date { get; set; } state getWinner(); + } } diff --git a/Online Gokkantoor/Globals/Interfaces/IPloeg.cs b/Online Gokkantoor/Globals/Interfaces/IPloeg.cs index 7ffc8be..59e574a 100644 --- a/Online Gokkantoor/Globals/Interfaces/IPloeg.cs +++ b/Online Gokkantoor/Globals/Interfaces/IPloeg.cs @@ -5,7 +5,10 @@ namespace Globals.Interfaces { int Id { get; set; } string naam { get; set; } - int score { get; set; } + int score { get; } bool scoreSet { get; } + event EventHandler scoreChanged; + void setScore(int i); + int getScore(); } }