diff --git a/OOP-Opdracht-CSharp-Alfa-2022/OOP-Opdracht-CSharp-Alfa-2022/Program.cs b/OOP-Opdracht-CSharp-Alfa-2022/OOP-Opdracht-CSharp-Alfa-2022/Program.cs index 65a24dd..aab57cf 100644 --- a/OOP-Opdracht-CSharp-Alfa-2022/OOP-Opdracht-CSharp-Alfa-2022/Program.cs +++ b/OOP-Opdracht-CSharp-Alfa-2022/OOP-Opdracht-CSharp-Alfa-2022/Program.cs @@ -10,19 +10,37 @@ namespace OOP_Opdracht_CSharp_Alfa_2022 { Console.WriteLine("Hello World!"); Opdracht2(); + Opdracht3(); } static void Opdracht2() { - Game game = new classes.Game(); - var someRecord = game.find(1); + Game game = new classes.Game("game"); // Init publisher class instance + var someRecord = game.find(1); // find specific record Console.WriteLine($"Record 1 is equal to {someRecord}"); + + // Get the full dictionary and loop over each record var games = game.getTableData(); Console.WriteLine("Outputting Table Contents:"); foreach (KeyValuePair entry in games) { - Console.WriteLine($"Row with id {entry.Key} has value {entry.Value}"); + Console.WriteLine($"Row with id {entry.Key} has value {entry.Value}"); // Output entry to Console } - Console.WriteLine($"Trying to fetch KeyValue with invalid id 5 {game.find(5)}"); + Console.WriteLine($"Trying to fetch KeyValue with invalid id 5 {game.find(7)}"); // Attempt to find invalid record and output to Console + } + static void Opdracht3() + { + Publisher publisher = new Publisher("publisher"); // Init publisher class instance + var someRecord = publisher.find(1); // find specific record + Console.WriteLine($"Record 1 is equal to {someRecord}"); + + // Get the full dictionary and loop over each record + var publishers = publisher.getTableData(); + Console.WriteLine("Outputting Table Contents:"); + foreach (KeyValuePair entry in publishers) + { + Console.WriteLine($"Row with id {entry.Key} has value {entry.Value}"); // Output entry to Console + } + Console.WriteLine($"Trying to fetch KeyValue with invalid id 5 {publisher.find(7)}"); // Attempt to find invalid record and output to Console } } } 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 3f69271..1d9bf28 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 @@ -13,13 +13,14 @@ namespace OOP_Opdracht_CSharp_Alfa_2022.classes // Game class constructor - public Game() + public Game(String _tablename) : base(_tablename) { + // Set the table name if(this.table_data == null) table_data = new Dictionary(); - this.table_data.Add(1, "Battlefield 2042"); - this.table_data.Add(2, "Counter-Strike: Global Offensive"); - this.table_data.Add(3, "Rust"); - + String[] games = { "Battlefield 2042", "Counter-Strike: Global Offensive", "Quake III Arena", "Rust", "Starcraft II" }; + for(int index = 1; index < games.Length+1; index++){ + this.table_data.Add(index, games[index-1]); + } } } 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 3cf5456..c7b1a3d 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 @@ -10,6 +10,12 @@ namespace OOP_Opdracht_CSharp_Alfa_2022.classes protected SqlConnection connection; protected Dictionary table_data; protected KeyValuePair record; + protected String tablename; + + // Constructor + public Model(String _tablename){ + this.tablename = _tablename; + } // Define Getters and Setters @@ -23,6 +29,7 @@ namespace OOP_Opdracht_CSharp_Alfa_2022.classes this.table_data = table_data; return; } + // Record get/set methods public void setRecord(int key, string value) { 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 bd2523f..6022997 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,10 +6,17 @@ namespace OOP_Opdracht_CSharp_Alfa_2022.classes { class Publisher : Model { - public Publisher() + public Publisher(String _tablename) : base(_tablename) { - if (table_data == null) table_data = new Dictionary(); - table_data.Add(1, "Electronic Arts"); + // Set the table name + this.tablename = "publisher"; + // Initialize dictionary + if (this.table_data == null) this.table_data = new Dictionary(); + // Add the publishers to the dictionary + String[] publishers = { "Electronic Arts", "Valve", "id Software", "Facepunch Studios", "Activision Blizzard" }; + for(int index = 1; index < publishers.Length+1; index++){ + this.table_data.Add(index, publishers[index-1]); + } } } }