diff --git a/Online Gokkantoor/Data/Data.csproj b/Online Gokkantoor/Data/Data.csproj index 4ad7751..79dc07d 100644 --- a/Online Gokkantoor/Data/Data.csproj +++ b/Online Gokkantoor/Data/Data.csproj @@ -34,6 +34,7 @@ + diff --git a/Online Gokkantoor/Data/data.cs b/Online Gokkantoor/Data/data.cs index 27c796d..dc373f5 100644 --- a/Online Gokkantoor/Data/data.cs +++ b/Online Gokkantoor/Data/data.cs @@ -7,127 +7,38 @@ using Newtonsoft.Json; namespace Data { - public class dataLayer : IData + public class dataLayer { public dataLayer() { } - - - public List getBets() + public db getDb() { - List list = new List(); try { - using (StreamReader file = File.OpenText(@"../../Data/bets.json")) - { - - JsonSerializer serializer = new JsonSerializer(); - list = (List)serializer.Deserialize(file, typeof(List)); - - } - } catch (Exception e) - { - throw new Exception(e.Message); - } - - return list; - } - - public List getGames() - { - List list = new List(); - - try - { - using (StreamReader file = File.OpenText(@"../../Data/games.json")) + using (StreamReader file = File.OpenText(@"../../Data/db.json")) { JsonSerializer serializer = new JsonSerializer(); - list = (List)serializer.Deserialize(file, typeof(List)); - + return (db)serializer.Deserialize(file, typeof(db)); } - } catch (Exception e) + } catch (Exception ex) { - - throw new Exception(e.Message); + throw new Exception(ex.Message); } - return list; } - public List getPersons() + + public void saveDb(db d) { - - List list = new List(); - try { - using (StreamReader file = File.OpenText(@"../../Data/persons.json")) - { - JsonSerializer serializer = new JsonSerializer(); - list = (List)serializer.Deserialize(file, typeof(List)); - - } - } catch (Exception e) - { - throw new Exception(e.Message); - - } - return list; - } - - public List getPloegen() - { - List list = new List(); - try - { - using (StreamReader file = File.OpenText(@"../../Data/ploegen.json")) - { - JsonSerializer serializer = new JsonSerializer(); - list = (List)serializer.Deserialize(file, typeof(List)); - - } - } catch (Exception e) - { - throw new Exception(e.Message); - - } - return list; - } - - public void saveBets(List b) - { - using (StreamWriter file = File.CreateText(@"../../Data/bets.json")) + using (StreamWriter file = File.CreateText(@"../../Data/db.json")) { JsonSerializer serializer = new JsonSerializer(); - serializer.Serialize(file, b); + serializer.Serialize(file, d); } } - public void saveGames(List g) - { - using (StreamWriter file = File.CreateText(@"../../Data/games.json")) - { - JsonSerializer serializer = new JsonSerializer(); - serializer.Serialize(file, g); - } - } - public void savePersons(List p) - { - using (StreamWriter file = File.CreateText(@"../../Data/persons.json")) - { - JsonSerializer serializer = new JsonSerializer(); - serializer.Serialize(file, p); - } - } - - public void savePloegen(List p) - { - using (StreamWriter file = File.CreateText(@"../../Data/ploegen.json")) - { - JsonSerializer serializer = new JsonSerializer(); - serializer.Serialize(file, p); - } - } } } diff --git a/Online Gokkantoor/Data/db.cs b/Online Gokkantoor/Data/db.cs new file mode 100644 index 0000000..498c802 --- /dev/null +++ b/Online Gokkantoor/Data/db.cs @@ -0,0 +1,18 @@ +using Globals.classes; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Data +{ + public class db + { + public List persons { get; set; } + public List bets { get; set; } + public List ploegen { get; set; } + public List games { get; set; } + public List ploegInMatches { get; set; } + } +} diff --git a/Online Gokkantoor/GUI_Gokkantoor/Admin.Designer.cs b/Online Gokkantoor/GUI_Gokkantoor/Admin.Designer.cs index 2ce8540..5434eaa 100644 --- a/Online Gokkantoor/GUI_Gokkantoor/Admin.Designer.cs +++ b/Online Gokkantoor/GUI_Gokkantoor/Admin.Designer.cs @@ -83,6 +83,7 @@ this.listBox1.Name = "listBox1"; this.listBox1.Size = new System.Drawing.Size(120, 95); this.listBox1.TabIndex = 4; + this.listBox1.SelectedIndexChanged += new System.EventHandler(this.ListBox1_SelectedIndexChanged); // // label1 // @@ -106,6 +107,7 @@ this.Controls.Add(this.button1); this.Name = "Admin"; this.Text = "Admin"; + this.Load += new System.EventHandler(this.Admin_Load); this.ResumeLayout(false); this.PerformLayout(); diff --git a/Online Gokkantoor/GUI_Gokkantoor/Admin.cs b/Online Gokkantoor/GUI_Gokkantoor/Admin.cs index 5cfc992..fb3f7c9 100644 --- a/Online Gokkantoor/GUI_Gokkantoor/Admin.cs +++ b/Online Gokkantoor/GUI_Gokkantoor/Admin.cs @@ -16,7 +16,7 @@ namespace GUI_Gokkantoor public LogicLayer l; public Admin(LogicLayer l) { - l = new LogicLayer(); + this.l = l; InitializeComponent(); } @@ -55,5 +55,15 @@ namespace GUI_Gokkantoor a.FormClosed += adminClosed; a.Show(); } + + private void Admin_Load(object sender, EventArgs e) + { + listBox1.DataSource = l.GetGames(); + } + + private void ListBox1_SelectedIndexChanged(object sender, EventArgs e) + { + + } } } diff --git a/Online Gokkantoor/GUI_Gokkantoor/Data/bets.json b/Online Gokkantoor/GUI_Gokkantoor/Data/bets.json deleted file mode 100644 index e69de29..0000000 diff --git a/Online Gokkantoor/GUI_Gokkantoor/Data/db.json b/Online Gokkantoor/GUI_Gokkantoor/Data/db.json new file mode 100644 index 0000000..5fac7f8 --- /dev/null +++ b/Online Gokkantoor/GUI_Gokkantoor/Data/db.json @@ -0,0 +1 @@ +{"persons":[{"Id":0,"name":"John","lastname":"Smith","adress":"123","gsm":"456","balance":789.0}],"bets":[],"ploegen":[],"games":[],"ploegInMatches":[]} \ No newline at end of file diff --git a/Online Gokkantoor/GUI_Gokkantoor/Data/games.json b/Online Gokkantoor/GUI_Gokkantoor/Data/games.json deleted file mode 100644 index e69de29..0000000 diff --git a/Online Gokkantoor/GUI_Gokkantoor/Data/persons.json b/Online Gokkantoor/GUI_Gokkantoor/Data/persons.json deleted file mode 100644 index e69de29..0000000 diff --git a/Online Gokkantoor/GUI_Gokkantoor/Data/ploegen.json b/Online Gokkantoor/GUI_Gokkantoor/Data/ploegen.json deleted file mode 100644 index e69de29..0000000 diff --git a/Online Gokkantoor/GUI_Gokkantoor/GUI_Gokkantoor.csproj b/Online Gokkantoor/GUI_Gokkantoor/GUI_Gokkantoor.csproj index 404f87d..6948591 100644 --- a/Online Gokkantoor/GUI_Gokkantoor/GUI_Gokkantoor.csproj +++ b/Online Gokkantoor/GUI_Gokkantoor/GUI_Gokkantoor.csproj @@ -147,10 +147,7 @@ User.cs - - - - + SettingsSingleFileGenerator Settings.Designer.cs diff --git a/Online Gokkantoor/GUI_Gokkantoor/Gokspel.Designer.cs b/Online Gokkantoor/GUI_Gokkantoor/Gokspel.Designer.cs index ef8ca6f..8111760 100644 --- a/Online Gokkantoor/GUI_Gokkantoor/Gokspel.Designer.cs +++ b/Online Gokkantoor/GUI_Gokkantoor/Gokspel.Designer.cs @@ -47,6 +47,7 @@ this.ListMatch.Name = "ListMatch"; this.ListMatch.Size = new System.Drawing.Size(120, 95); this.ListMatch.TabIndex = 0; + this.ListMatch.SelectedIndexChanged += new System.EventHandler(this.ListMatch_SelectedIndexChanged); // // ListGokken // @@ -150,6 +151,7 @@ this.Controls.Add(this.ListMatch); this.Name = "Gokspel"; this.Text = "Gokspel"; + this.Load += new System.EventHandler(this.Gokspel_Load); this.ResumeLayout(false); this.PerformLayout(); diff --git a/Online Gokkantoor/GUI_Gokkantoor/Gokspel.cs b/Online Gokkantoor/GUI_Gokkantoor/Gokspel.cs index c75db01..7e0ea31 100644 --- a/Online Gokkantoor/GUI_Gokkantoor/Gokspel.cs +++ b/Online Gokkantoor/GUI_Gokkantoor/Gokspel.cs @@ -57,5 +57,15 @@ namespace GUI_Gokkantoor { } + + private void Gokspel_Load(object sender, EventArgs e) + { + + } + + private void ListMatch_SelectedIndexChanged(object sender, EventArgs e) + { + + } } } diff --git a/Online Gokkantoor/GUI_Gokkantoor/Login.cs b/Online Gokkantoor/GUI_Gokkantoor/Login.cs index 8b7375b..e43a915 100644 --- a/Online Gokkantoor/GUI_Gokkantoor/Login.cs +++ b/Online Gokkantoor/GUI_Gokkantoor/Login.cs @@ -19,8 +19,7 @@ namespace GUI_Gokkantoor { this.l = l; InitializeComponent(); - listBox1.DataSource = l.persons; - listBox1.DataSource = l.persons; + listBox1.DataSource = l.GetPeople(); } diff --git a/Online Gokkantoor/GUI_Gokkantoor/Team.Designer.cs b/Online Gokkantoor/GUI_Gokkantoor/Team.Designer.cs index 318a7de..189af6b 100644 --- a/Online Gokkantoor/GUI_Gokkantoor/Team.Designer.cs +++ b/Online Gokkantoor/GUI_Gokkantoor/Team.Designer.cs @@ -57,6 +57,7 @@ this.button1.TabIndex = 2; this.button1.Text = "Toevoegen"; this.button1.UseVisualStyleBackColor = true; + this.button1.Click += new System.EventHandler(this.Button1_Click); // // Team // diff --git a/Online Gokkantoor/GUI_Gokkantoor/Team.cs b/Online Gokkantoor/GUI_Gokkantoor/Team.cs index be14198..f246030 100644 --- a/Online Gokkantoor/GUI_Gokkantoor/Team.cs +++ b/Online Gokkantoor/GUI_Gokkantoor/Team.cs @@ -16,5 +16,10 @@ namespace GUI_Gokkantoor { InitializeComponent(); } + + private void Button1_Click(object sender, EventArgs e) + { + + } } } diff --git a/Online Gokkantoor/GUI_Gokkantoor/User.Designer.cs b/Online Gokkantoor/GUI_Gokkantoor/User.Designer.cs index f0532bd..b2b5ade 100644 --- a/Online Gokkantoor/GUI_Gokkantoor/User.Designer.cs +++ b/Online Gokkantoor/GUI_Gokkantoor/User.Designer.cs @@ -28,11 +28,11 @@ /// private void InitializeComponent() { - this.textBox1 = new System.Windows.Forms.TextBox(); - this.textBox2 = new System.Windows.Forms.TextBox(); - this.textBox3 = new System.Windows.Forms.TextBox(); - this.textBox4 = new System.Windows.Forms.TextBox(); - this.textBox5 = new System.Windows.Forms.TextBox(); + this.naam = new System.Windows.Forms.TextBox(); + this.achternaam = new System.Windows.Forms.TextBox(); + this.adres = new System.Windows.Forms.TextBox(); + this.gsm = new System.Windows.Forms.TextBox(); + this.balans = new System.Windows.Forms.TextBox(); this.label1 = new System.Windows.Forms.Label(); this.label2 = new System.Windows.Forms.Label(); this.label3 = new System.Windows.Forms.Label(); @@ -41,40 +41,40 @@ this.button1 = new System.Windows.Forms.Button(); this.SuspendLayout(); // - // textBox1 + // naam // - this.textBox1.Location = new System.Drawing.Point(281, 92); - this.textBox1.Name = "textBox1"; - this.textBox1.Size = new System.Drawing.Size(100, 20); - this.textBox1.TabIndex = 0; + this.naam.Location = new System.Drawing.Point(281, 92); + this.naam.Name = "naam"; + this.naam.Size = new System.Drawing.Size(100, 20); + this.naam.TabIndex = 0; // - // textBox2 + // achternaam // - this.textBox2.Location = new System.Drawing.Point(281, 118); - this.textBox2.Name = "textBox2"; - this.textBox2.Size = new System.Drawing.Size(100, 20); - this.textBox2.TabIndex = 1; + this.achternaam.Location = new System.Drawing.Point(281, 118); + this.achternaam.Name = "achternaam"; + this.achternaam.Size = new System.Drawing.Size(100, 20); + this.achternaam.TabIndex = 1; // - // textBox3 + // adres // - this.textBox3.Location = new System.Drawing.Point(281, 145); - this.textBox3.Name = "textBox3"; - this.textBox3.Size = new System.Drawing.Size(100, 20); - this.textBox3.TabIndex = 2; + this.adres.Location = new System.Drawing.Point(281, 145); + this.adres.Name = "adres"; + this.adres.Size = new System.Drawing.Size(100, 20); + this.adres.TabIndex = 2; // - // textBox4 + // gsm // - this.textBox4.Location = new System.Drawing.Point(281, 170); - this.textBox4.Name = "textBox4"; - this.textBox4.Size = new System.Drawing.Size(100, 20); - this.textBox4.TabIndex = 3; + this.gsm.Location = new System.Drawing.Point(281, 170); + this.gsm.Name = "gsm"; + this.gsm.Size = new System.Drawing.Size(100, 20); + this.gsm.TabIndex = 3; // - // textBox5 + // balans // - this.textBox5.Location = new System.Drawing.Point(281, 196); - this.textBox5.Name = "textBox5"; - this.textBox5.Size = new System.Drawing.Size(100, 20); - this.textBox5.TabIndex = 4; + this.balans.Location = new System.Drawing.Point(281, 196); + this.balans.Name = "balans"; + this.balans.Size = new System.Drawing.Size(100, 20); + this.balans.TabIndex = 4; // // label1 // @@ -130,6 +130,7 @@ this.button1.TabIndex = 10; this.button1.Text = "Toevoegen"; this.button1.UseVisualStyleBackColor = true; + this.button1.Click += new System.EventHandler(this.Button1_Click); // // User // @@ -142,11 +143,11 @@ this.Controls.Add(this.label3); this.Controls.Add(this.label2); this.Controls.Add(this.label1); - this.Controls.Add(this.textBox5); - this.Controls.Add(this.textBox4); - this.Controls.Add(this.textBox3); - this.Controls.Add(this.textBox2); - this.Controls.Add(this.textBox1); + this.Controls.Add(this.balans); + this.Controls.Add(this.gsm); + this.Controls.Add(this.adres); + this.Controls.Add(this.achternaam); + this.Controls.Add(this.naam); this.Name = "User"; this.Text = "User"; this.ResumeLayout(false); @@ -156,11 +157,11 @@ #endregion - private System.Windows.Forms.TextBox textBox1; - private System.Windows.Forms.TextBox textBox2; - private System.Windows.Forms.TextBox textBox3; - private System.Windows.Forms.TextBox textBox4; - private System.Windows.Forms.TextBox textBox5; + private System.Windows.Forms.TextBox naam; + private System.Windows.Forms.TextBox achternaam; + private System.Windows.Forms.TextBox adres; + private System.Windows.Forms.TextBox gsm; + private System.Windows.Forms.TextBox balans; private System.Windows.Forms.Label label1; private System.Windows.Forms.Label label2; private System.Windows.Forms.Label label3; diff --git a/Online Gokkantoor/GUI_Gokkantoor/User.cs b/Online Gokkantoor/GUI_Gokkantoor/User.cs index 8dfe38d..b2a9bd5 100644 --- a/Online Gokkantoor/GUI_Gokkantoor/User.cs +++ b/Online Gokkantoor/GUI_Gokkantoor/User.cs @@ -1,4 +1,5 @@ -using System; +using Logic; +using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; @@ -12,14 +13,29 @@ namespace GUI_Gokkantoor { public partial class User : Form { + LogicLayer l; public User(Logic.LogicLayer l) { InitializeComponent(); + this.l = l; } private void label4_Click(object sender, EventArgs e) { } + + private void Button1_Click(object sender, EventArgs e) + { + try + { + l.addPerson(new Globals.classes.Person(naam.Text, achternaam.Text, adres.Text, gsm.Text, double.Parse(balans.Text))); + l.save(); + + } catch (Exception ex) + { + // geen correcte double ingegeven wss. niet vergeten popup te schrijven. + } + } } } diff --git a/Online Gokkantoor/Globals/Classes/Game.cs b/Online Gokkantoor/Globals/Classes/Game.cs index f824c04..2f237cc 100644 --- a/Online Gokkantoor/Globals/Classes/Game.cs +++ b/Online Gokkantoor/Globals/Classes/Game.cs @@ -56,7 +56,7 @@ namespace Globals.classes this.home.scoreChanged += homeSet; this.away.scoreChanged += awaySet; } - public Game(int id, Ploeg home, Ploeg away, int scoreHome, int scoreAway) + public Game(int id, PloegInMatch home, PloegInMatch away, int scoreHome, int scoreAway) { homeSetBool = false; awaySetBool = false; diff --git a/Online Gokkantoor/Globals/Classes/Person.cs b/Online Gokkantoor/Globals/Classes/Person.cs index 3ac8b68..5562bc2 100644 --- a/Online Gokkantoor/Globals/Classes/Person.cs +++ b/Online Gokkantoor/Globals/Classes/Person.cs @@ -35,8 +35,15 @@ namespace Globals.classes public override bool Equals(object obj) { - Person p = (Person)obj; - return this.Id == p.Id; + try + { + + Person p = (Person)obj; + return this.Id == p.Id; + } catch (Exception e) + { + return false; + } } public override int GetHashCode() diff --git a/Online Gokkantoor/Globals/Classes/Ploeg.cs b/Online Gokkantoor/Globals/Classes/Ploeg.cs index 74e49d0..8cf0a40 100644 --- a/Online Gokkantoor/Globals/Classes/Ploeg.cs +++ b/Online Gokkantoor/Globals/Classes/Ploeg.cs @@ -6,23 +6,20 @@ namespace Globals.classes { public class Ploeg : IPloeg { - public Ploeg(int id, string naam) + public Ploeg(string naam) { - Id = id; this.naam = naam; } public Ploeg(Ploeg p) { - this.Id = p.Id; this.naam = p.naam; } - public int Id { get; set; } public string naam { get; set; } public override bool Equals(object obj) { - return base.Equals(obj); + return ((Ploeg)obj).naam == this.naam; } public override string ToString() diff --git a/Online Gokkantoor/Globals/Classes/ploegInMatch.cs b/Online Gokkantoor/Globals/Classes/ploegInMatch.cs index 4cff8bc..18f94c0 100644 --- a/Online Gokkantoor/Globals/Classes/ploegInMatch.cs +++ b/Online Gokkantoor/Globals/Classes/ploegInMatch.cs @@ -9,26 +9,29 @@ namespace Globals.classes { public class PloegInMatch : Ploeg { - public PloegInMatch(int id, string naam) : base(id, naam) + public int Id; + public PloegInMatch(int id, string naam) : base( naam) { + this.Id = id; } - public PloegInMatch(int id, string naam, int score) : base(id, naam) + public PloegInMatch(int id, string naam, int score) : base(naam) { + this.Id = id; setScore(score); } - public PloegInMatch(Ploeg p) : base(p) + public PloegInMatch(Ploeg p, int id) : base(p) { - this.Id = p.Id; + this.Id = id; this.naam = p.naam; } - public PloegInMatch(Ploeg p, int score) : base(p) + public PloegInMatch(Ploeg p, int score, int id) : base(p) { - this.Id = p.Id; + this.Id = id; this.naam = p.naam; setScore(score); @@ -46,6 +49,16 @@ namespace Globals.classes this.scoreSet = true; } + public override bool Equals(object obj) + { + return base.Equals(obj); + } + public override string ToString() + { + if (this.scoreSet) return this.naam + ": " +this.score; + else return this.naam + ": NaN"; + + } } } diff --git a/Online Gokkantoor/Globals/Globals.csproj b/Online Gokkantoor/Globals/Globals.csproj index 87ab05d..c30692f 100644 --- a/Online Gokkantoor/Globals/Globals.csproj +++ b/Online Gokkantoor/Globals/Globals.csproj @@ -35,21 +35,18 @@ - - - diff --git a/Online Gokkantoor/Globals/Interfaces/IData.cs b/Online Gokkantoor/Globals/Interfaces/IData.cs deleted file mode 100644 index 0df4ba5..0000000 --- a/Online Gokkantoor/Globals/Interfaces/IData.cs +++ /dev/null @@ -1,18 +0,0 @@ -using System; -using System.Collections.Generic; -using Globals.classes; - -namespace Globals.Interfaces -{ - public interface IData - { - List getPersons(); - List getGames(); - List getPloegen(); - List getBets(); - void saveBets(List b); - void saveGames(List g); - void savePloegen(List p); - void savePersons(List p); - } -} diff --git a/Online Gokkantoor/Globals/Interfaces/ILogic.cs b/Online Gokkantoor/Globals/Interfaces/ILogic.cs index fe0fda1..5cb0e1d 100644 --- a/Online Gokkantoor/Globals/Interfaces/ILogic.cs +++ b/Online Gokkantoor/Globals/Interfaces/ILogic.cs @@ -6,24 +6,22 @@ namespace Globals.Interfaces { public interface ILogic { - List persons { get; set; } - List bets { get; set; } - List ploegen { get; set; } - List games { get; set; } - Person getPerson(int id); - Bet getBet(int id); - Ploeg getPloeg(int id); - Game getGame(int id); - void addPloeg(Ploeg p); - void addGame(Game g); + void addBet(Bet b); + void addGame(Game g); void addPerson(Person p); + void addPloeg(Ploeg p); + void addPloegInMatch(PloegInMatch p); + Bet getBet(int id); + List GetBets(); + Game getGame(int id); + List GetGames(); + Person getPerson(int id); + List GetPeople(); + Ploeg getPloeg(string naam); + List GetPloegen(); + PloegInMatch GetPloegInMatch(int id); + List GetPloegInMatches(); void save(); - void updateGame(Game g); - void updatePerson(Person p); - Person getPersonByString(string s); - Ploeg getPloegByString(string s); - Game getGameByString(string s); - Bet getBetByString(string s); } } diff --git a/Online Gokkantoor/Globals/Interfaces/IPloeg.cs b/Online Gokkantoor/Globals/Interfaces/IPloeg.cs index 3791c4e..b1afa6b 100644 --- a/Online Gokkantoor/Globals/Interfaces/IPloeg.cs +++ b/Online Gokkantoor/Globals/Interfaces/IPloeg.cs @@ -3,7 +3,6 @@ namespace Globals.Interfaces { public interface IPloeg { - int Id { get; set; } string naam { get; set; } } } diff --git a/Online Gokkantoor/Logic/LogicLayer.cs b/Online Gokkantoor/Logic/LogicLayer.cs index 44f347b..fc89dd3 100644 --- a/Online Gokkantoor/Logic/LogicLayer.cs +++ b/Online Gokkantoor/Logic/LogicLayer.cs @@ -8,212 +8,118 @@ namespace Logic { public class LogicLayer : ILogic { - private dataLayer d; + private dataLayer data; + private db d; public LogicLayer() { - d = new dataLayer(); - persons = d.getPersons(); - bets = d.getBets(); - ploegen = d.getPloegen(); - games = d.getGames(); - if (games == null) games = new List(); - if (ploegen == null) ploegen = new List(); - if (persons == null) persons = new List(); - if (bets == null) bets = new List(); - } - - public LogicLayer(bool testMode) - { - d = new dataLayer(); - this.persons = new List(); - Person p = new Person("beppe", "vanrolleghem", "123straat", "04877777", 5); - fixIds(); - this.persons.Add(p); - } - - public List persons { get ; set; } - public List bets { get; set; } - public List ploegen { get; set; } - public List games { get; set; } - - private void fixIds() - { - int i = 0; - foreach(Person p in persons) - { - p.Id = i; - i++; - } - i = 0; - foreach(Bet b in bets) - { - b.Id = i; - i++; - } - i = 0; - foreach(Ploeg p in ploegen) - { - p.Id = i; - i++; - } - i = 0; - foreach(Game g in games) - { - g.Id = i; - i++; - } + data = new dataLayer(); + d = data.getDb(); + if (d.games == null) d.games = new List(); + if (d.ploegen == null) d.ploegen = new List(); + if (d.persons == null) d.persons = new List(); + if (d.bets == null) d.bets = new List(); + if (d.ploegInMatches == null) d.ploegInMatches = new List(); } public void addBet(Bet b) { - - bets.Add(b); - fixIds(); + + d.bets.Add(b); } public void addGame(Game g) { - games.Add(g); - fixIds(); + d.games.Add(g); } public void addPerson(Person p) { - persons.Add(p); - fixIds(); + d.persons.Add(p); } public void addPloeg(Ploeg p) { - ploegen.Add(p); - fixIds(); + d.ploegen.Add(p); + } + + public void addPloegInMatch(PloegInMatch p) + { + d.ploegInMatches.Add(p); } public Bet getBet(int id) { - foreach(Bet b in bets) + foreach(Bet b in d.bets) { if (b.Id == id) return b; } throw new Exception("No bets found with that id"); } + public List GetBets() + { + return d.bets; + } + public Game getGame(int id) { - foreach (Game b in games) + foreach (Game b in d.games) { if (b.Id == id) return b; } throw new Exception("No bets found with that id"); } + public List GetGames() + { + return d.games; + } + + public List GetPeople() + { + return d.persons; + } + public Person getPerson(int id) { - return persons.FindLast(x => id == x.Id); + return d.persons.FindLast(x => id == x.Id); //lambda } - public List filter(List p) + public Ploeg getPloeg(string naam) { - return filter(p); + foreach (Ploeg b in d.ploegen) + { + if (b.naam == naam) return b; + } + throw new Exception("No ploegen found with that naam"); } - public Ploeg getPloeg(int id) + public List GetPloegen() { - foreach (Ploeg b in ploegen) + return d.ploegen; + } + + public PloegInMatch GetPloegInMatch(int id) + { + + foreach (PloegInMatch b in d.ploegInMatches) { if (b.Id == id) return b; } - throw new Exception("No bets found with that id"); + throw new Exception("No ploegen found with that naam"); } + + public List GetPloegInMatches() + { + return d.ploegInMatches; + } + public void save() { - fixIds(); - d.savePersons(persons); - d.savePloegen(ploegen); - d.saveGames(games); - d.saveBets(bets); + data.saveDb(d); } - public void updateGame(Game g) - { - foreach (Game ga in games) - { - if (ga.Id == g.Id) - { - ga.home = g.home; - ga.away = g.away; - - } - } - updateBets(); - updateBalances(); - } - - private void updateBets() - { - foreach (Bet b in bets) - { - Game g = games.Find(e => b.game.Id == e.Id); - b.game = g; - if (g.away.scoreSet && g.home.scoreSet) { b.finished = true; } - } - - } - private void updateBalances() - { - foreach (Person p in persons) - { - foreach (Bet b in bets) - { - if (b.Equals(p) && b.finished) p.balance += b.getProfit(); - } - } - } - - public void updatePerson(Person p) - { - persons[persons.FindIndex(e => e.Id == p.Id)] = p; - } - - public Person getPersonByString(string s) - { - foreach (Person p in persons) - { - if (p.ToString() == s) - { - return p; - } - } - throw new Exception("No person by that personString found"); - } - - public Ploeg getPloegByString(string s) - { - foreach (Ploeg p in ploegen) - { - if (p.ToString() == s) return p; - } - throw new Exception("No ploeg by that ploegString was found"); - } - - public Game getGameByString(string s) - { - foreach (Game g in games) - { - if (g.ToString() == s) return g; - } - throw new Exception("No game by that gameString found"); - } - - public Bet getBetByString(string s) - { - foreach (Bet b in bets) - { - if (b.ToString() == s) return b; - } - throw new Exception("No bet by that betString was found"); - } } }