ui nog wa aanpasse en we zijn gucci

This commit is contained in:
Beppe Vanrolleghem
2019-08-12 18:15:17 +02:00
parent fb078ec1d8
commit 582c3f7244
27 changed files with 225 additions and 352 deletions

View File

@@ -34,6 +34,7 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="db.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="data.cs" />
</ItemGroup>

View File

@@ -7,127 +7,38 @@ using Newtonsoft.Json;
namespace Data
{
public class dataLayer : IData
public class dataLayer
{
public dataLayer()
{
}
public List<Bet> getBets()
public db getDb()
{
List<Bet> list = new List<Bet>();
try
{
using (StreamReader file = File.OpenText(@"../../Data/bets.json"))
{
JsonSerializer serializer = new JsonSerializer();
list = (List<Bet>)serializer.Deserialize(file, typeof(List<Bet>));
}
} catch (Exception e)
{
throw new Exception(e.Message);
}
return list;
}
public List<Game> getGames()
{
List<Game> list = new List<Game>();
try
{
using (StreamReader file = File.OpenText(@"../../Data/games.json"))
using (StreamReader file = File.OpenText(@"../../Data/db.json"))
{
JsonSerializer serializer = new JsonSerializer();
list = (List<Game>)serializer.Deserialize(file, typeof(List<Game>));
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<Person> getPersons()
public void saveDb(db d)
{
List<Person> list = new List<Person>();
try {
using (StreamReader file = File.OpenText(@"../../Data/persons.json"))
{
JsonSerializer serializer = new JsonSerializer();
list = (List<Person>)serializer.Deserialize(file, typeof(List<Person>));
}
} catch (Exception e)
{
throw new Exception(e.Message);
}
return list;
}
public List<Ploeg> getPloegen()
{
List<Ploeg> list = new List<Ploeg>();
try
{
using (StreamReader file = File.OpenText(@"../../Data/ploegen.json"))
{
JsonSerializer serializer = new JsonSerializer();
list = (List<Ploeg>)serializer.Deserialize(file, typeof(List<Ploeg>));
}
} catch (Exception e)
{
throw new Exception(e.Message);
}
return list;
}
public void saveBets(List<Bet> 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<Game> g)
{
using (StreamWriter file = File.CreateText(@"../../Data/games.json"))
{
JsonSerializer serializer = new JsonSerializer();
serializer.Serialize(file, g);
}
}
public void savePersons(List<Person> p)
{
using (StreamWriter file = File.CreateText(@"../../Data/persons.json"))
{
JsonSerializer serializer = new JsonSerializer();
serializer.Serialize(file, p);
}
}
public void savePloegen(List<Ploeg> p)
{
using (StreamWriter file = File.CreateText(@"../../Data/ploegen.json"))
{
JsonSerializer serializer = new JsonSerializer();
serializer.Serialize(file, p);
}
}
}
}

View File

@@ -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<Person> persons { get; set; }
public List<Bet> bets { get; set; }
public List<Ploeg> ploegen { get; set; }
public List<Game> games { get; set; }
public List<PloegInMatch> ploegInMatches { get; set; }
}
}

View File

@@ -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();

View File

@@ -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)
{
}
}
}

View File

@@ -0,0 +1 @@
{"persons":[{"Id":0,"name":"John","lastname":"Smith","adress":"123","gsm":"456","balance":789.0}],"bets":[],"ploegen":[],"games":[],"ploegInMatches":[]}

View File

@@ -147,10 +147,7 @@
<EmbeddedResource Include="User.resx">
<DependentUpon>User.cs</DependentUpon>
</EmbeddedResource>
<None Include="Data\bets.json" />
<None Include="Data\games.json" />
<None Include="Data\persons.json" />
<None Include="Data\ploegen.json" />
<None Include="Data\db.json" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>

View File

@@ -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();

View File

@@ -57,5 +57,15 @@ namespace GUI_Gokkantoor
{
}
private void Gokspel_Load(object sender, EventArgs e)
{
}
private void ListMatch_SelectedIndexChanged(object sender, EventArgs e)
{
}
}
}

View File

@@ -19,8 +19,7 @@ namespace GUI_Gokkantoor
{
this.l = l;
InitializeComponent();
listBox1.DataSource = l.persons;
listBox1.DataSource = l.persons;
listBox1.DataSource = l.GetPeople();
}

View File

@@ -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
//

View File

@@ -16,5 +16,10 @@ namespace GUI_Gokkantoor
{
InitializeComponent();
}
private void Button1_Click(object sender, EventArgs e)
{
}
}
}

View File

@@ -28,11 +28,11 @@
/// </summary>
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;

View File

@@ -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.
}
}
}
}

View File

@@ -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;

View File

@@ -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()

View File

@@ -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()

View File

@@ -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";
}
}
}

View File

@@ -35,21 +35,18 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Classes\PloegInMatch.cs" />
<Compile Include="MyClass.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Classes\Bet.cs" />
<Compile Include="Classes\Game.cs" />
<Compile Include="Classes\Person.cs" />
<Compile Include="Classes\Ploeg.cs" />
<Compile Include="Interfaces\IBet.cs" />
<Compile Include="Interfaces\IData.cs" />
<Compile Include="Interfaces\IGame.cs" />
<Compile Include="Interfaces\ILogic.cs" />
<Compile Include="Interfaces\IPerson.cs" />
<Compile Include="Interfaces\IPloeg.cs" />
<Compile Include="main.cs" />
</ItemGroup>
<ItemGroup />
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>

View File

@@ -1,18 +0,0 @@
using System;
using System.Collections.Generic;
using Globals.classes;
namespace Globals.Interfaces
{
public interface IData
{
List<Person> getPersons();
List<Game> getGames();
List<Ploeg> getPloegen();
List<Bet> getBets();
void saveBets(List<Bet> b);
void saveGames(List<Game> g);
void savePloegen(List<Ploeg> p);
void savePersons(List<Person> p);
}
}

View File

@@ -6,24 +6,22 @@ namespace Globals.Interfaces
{
public interface ILogic
{
List<Person> persons { get; set; }
List<Bet> bets { get; set; }
List<Ploeg> ploegen { get; set; }
List<Game> 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<Bet> GetBets();
Game getGame(int id);
List<Game> GetGames();
Person getPerson(int id);
List<Person> GetPeople();
Ploeg getPloeg(string naam);
List<Ploeg> GetPloegen();
PloegInMatch GetPloegInMatch(int id);
List<PloegInMatch> 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);
}
}

View File

@@ -3,7 +3,6 @@ namespace Globals.Interfaces
{
public interface IPloeg
{
int Id { get; set; }
string naam { get; set; }
}
}

View File

@@ -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<Game>();
if (ploegen == null) ploegen = new List<Ploeg>();
if (persons == null) persons = new List<Person>();
if (bets == null) bets = new List<Bet>();
}
public LogicLayer(bool testMode)
{
d = new dataLayer();
this.persons = new List<Person>();
Person p = new Person("beppe", "vanrolleghem", "123straat", "04877777", 5);
fixIds();
this.persons.Add(p);
}
public List<Person> persons { get ; set; }
public List<Bet> bets { get; set; }
public List<Ploeg> ploegen { get; set; }
public List<Game> 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<Game>();
if (d.ploegen == null) d.ploegen = new List<Ploeg>();
if (d.persons == null) d.persons = new List<Person>();
if (d.bets == null) d.bets = new List<Bet>();
if (d.ploegInMatches == null) d.ploegInMatches = new List<PloegInMatch>();
}
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<Bet> 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<Game> GetGames()
{
return d.games;
}
public List<Person> 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<Person> filter(List<Person> 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<Ploeg> 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<PloegInMatch> 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");
}
}
}