From 64338adb2f660443e1b1d5d1e66ff2f4ebeff058 Mon Sep 17 00:00:00 2001 From: Andreas Date: Thu, 8 Dec 2022 13:51:09 +0100 Subject: [PATCH] Opdracht 3a --- .../classes/Game.cs | 43 +----------------- .../classes/Model.cs | 44 ++++++++++++++++++- .../classes/Publisher.cs | 5 +++ 3 files changed, 49 insertions(+), 43 deletions(-) diff --git a/OOP-Opdracht-CSharp-Alfa-2022/OOP-Opdracht-CSharp-Alfa-2022/classes/Game.cs b/OOP-Opdracht-CSharp-Alfa-2022/OOP-Opdracht-CSharp-Alfa-2022/classes/Game.cs index 98f0722..3f69271 100644 --- a/OOP-Opdracht-CSharp-Alfa-2022/OOP-Opdracht-CSharp-Alfa-2022/classes/Game.cs +++ b/OOP-Opdracht-CSharp-Alfa-2022/OOP-Opdracht-CSharp-Alfa-2022/classes/Game.cs @@ -7,52 +7,11 @@ namespace OOP_Opdracht_CSharp_Alfa_2022.classes { class Game : Model { - // Define class members - - private Dictionary table_data; - private KeyValuePair record; // Define methods - // Define Getters and Setters + - // Table data get/set methods - public Dictionary getTableData() - { - return this.table_data; - } - public void setTableData(Dictionary table_data) - { - this.table_data = table_data; - return; - } - // Record get/set methods - public void setRecord(int key, string value) - { - var record = new KeyValuePair(key, value); - return; - } - // Overload in case of previously instantiated KeyValuePair as parameter - public void setRecord(KeyValuePair keyValuePair) - { - this.setRecord(keyValuePair.Key, keyValuePair.Value); - return; - } - public KeyValuePair getRecord() - { - return this.record; - } - // Get KeyValuePair by id, returns [-1, "Invalid Record"] when out of bounds - public KeyValuePair find(int id = 1) - { - KeyValuePair record = new KeyValuePair(-1, "Invalid Record"); - if (this.table_data.ContainsKey(id)) - { - record = new KeyValuePair(id, this.table_data.GetValueOrDefault(id)); - } - this.record = record; - return record; - } // Game class constructor public Game() { diff --git a/OOP-Opdracht-CSharp-Alfa-2022/OOP-Opdracht-CSharp-Alfa-2022/classes/Model.cs b/OOP-Opdracht-CSharp-Alfa-2022/OOP-Opdracht-CSharp-Alfa-2022/classes/Model.cs index 201309d..73acea3 100644 --- a/OOP-Opdracht-CSharp-Alfa-2022/OOP-Opdracht-CSharp-Alfa-2022/classes/Model.cs +++ b/OOP-Opdracht-CSharp-Alfa-2022/OOP-Opdracht-CSharp-Alfa-2022/classes/Model.cs @@ -7,7 +7,49 @@ namespace OOP_Opdracht_CSharp_Alfa_2022.classes { abstract class Model { - private SqlConnection connection; + protected SqlConnection connection; + protected Dictionary table_data; + protected KeyValuePair record; + // Define Getters and Setters + + // Table data get/set methods + public Dictionary getTableData() + { + return this.table_data; + } + public void setTableData(Dictionary table_data) + { + this.table_data = table_data; + return; + } + // Record get/set methods + public void setRecord(int key, string value) + { + var record = new KeyValuePair(key, value); + return; + } + // Overload in case of previously instantiated KeyValuePair as parameter + public void setRecord(KeyValuePair keyValuePair) + { + this.setRecord(keyValuePair.Key, keyValuePair.Value); + return; + } + public KeyValuePair getRecord() + { + return this.record; + } + + // Get KeyValuePair by id, returns [-1, "Invalid Record"] when out of bounds + public KeyValuePair find(int id = 1) + { + KeyValuePair record = new KeyValuePair(-1, "Invalid Record"); + if (this.table_data.ContainsKey(id)) + { + record = new KeyValuePair(id, this.table_data.GetValueOrDefault(id)); + } + this.record = record; + return record; + } } } diff --git a/OOP-Opdracht-CSharp-Alfa-2022/OOP-Opdracht-CSharp-Alfa-2022/classes/Publisher.cs b/OOP-Opdracht-CSharp-Alfa-2022/OOP-Opdracht-CSharp-Alfa-2022/classes/Publisher.cs index 91cc5d8..eed5abb 100644 --- a/OOP-Opdracht-CSharp-Alfa-2022/OOP-Opdracht-CSharp-Alfa-2022/classes/Publisher.cs +++ b/OOP-Opdracht-CSharp-Alfa-2022/OOP-Opdracht-CSharp-Alfa-2022/classes/Publisher.cs @@ -6,5 +6,10 @@ namespace OOP_Opdracht_CSharp_Alfa_2022.classes { class Publisher : Model { + public Publisher() + { + if (table_data == null) table_data = new Dictionary(); + table_data.Add(1, "Electornic Arts"); + } } }