Compare commits
	
		
			No commits in common. "3ee4691a144223b26280cd14a71c5502c26bf082" and "8875d7e5132601502973d429f29d836820e4b56e" have entirely different histories.
		
	
	
		
			3ee4691a14
			...
			8875d7e513
		
	
		
							
								
								
									
										4
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										4
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							| @ -9,7 +9,6 @@ | |||||||
| *.user | *.user | ||||||
| *.userosscache | *.userosscache | ||||||
| *.sln.docstates | *.sln.docstates | ||||||
| **/*/.vscode/ |  | ||||||
| 
 | 
 | ||||||
| # User-specific files (MonoDevelop/Xamarin Studio) | # User-specific files (MonoDevelop/Xamarin Studio) | ||||||
| *.userprefs | *.userprefs | ||||||
| @ -397,6 +396,3 @@ FodyWeavers.xsd | |||||||
| 
 | 
 | ||||||
| # JetBrains Rider | # JetBrains Rider | ||||||
| *.sln.iml | *.sln.iml | ||||||
| 
 |  | ||||||
| # App config file |  | ||||||
| OOP-Opdracht-CSharp-Alfa-2022/OOP-Opdracht-CSharp-Alfa-2022/App.config |  | ||||||
|  | |||||||
| @ -8,7 +8,6 @@ | |||||||
| 
 | 
 | ||||||
|   <ItemGroup> |   <ItemGroup> | ||||||
|     <PackageReference Include="Microsoft.Data.SqlClient" Version="5.0.1" /> |     <PackageReference Include="Microsoft.Data.SqlClient" Version="5.0.1" /> | ||||||
|     <PackageReference Include="System.Configuration.ConfigurationManager" Version="7.0.0" /> |  | ||||||
|   </ItemGroup> |   </ItemGroup> | ||||||
| 
 | 
 | ||||||
| </Project> | </Project> | ||||||
|  | |||||||
| @ -10,72 +10,19 @@ namespace OOP_Opdracht_CSharp_Alfa_2022 | |||||||
|         { |         { | ||||||
|             Console.WriteLine("Hello World!"); |             Console.WriteLine("Hello World!"); | ||||||
|             Opdracht2(); |             Opdracht2(); | ||||||
|             Opdracht3(); |  | ||||||
|             Opdracht3c(); |  | ||||||
|             Opdracht4(); |  | ||||||
|         } |         } | ||||||
|         static void Opdracht2() |         static void Opdracht2() | ||||||
|         { |         { | ||||||
|             Game game = new classes.Game("game"); // Init publisher class instance |             Game game = new classes.Game(); | ||||||
|             var someRecord = game.find(1); // find specific record |             var someRecord = game.find(1); | ||||||
|             Console.WriteLine($"Record 1 is equal to {someRecord}"); |             Console.WriteLine($"Record 1 is equal to {someRecord}"); | ||||||
|             // Get the full dictionary and loop over each record |             var games = game.getTableData(); | ||||||
|             Dictionary<int, String> games = game.getTableData(); |  | ||||||
|             Console.WriteLine("Outputting Table Contents:"); |             Console.WriteLine("Outputting Table Contents:"); | ||||||
|             foreach (KeyValuePair<int, string> entry in games) |             foreach (KeyValuePair<int, string> entry in games) | ||||||
|             { |             { | ||||||
|                 Console.WriteLine($"Row with id {entry.Key} has value {entry.Value}"); // Output entry to Console |                 Console.WriteLine($"Row with id {entry.Key} has value {entry.Value}"); | ||||||
|             } |             } | ||||||
|             Console.WriteLine($"Trying to fetch KeyValue with invalid id 5 {game.find(7)}"); // Attempt to find invalid record and output to Console |             Console.WriteLine($"Trying to fetch KeyValue with invalid id 5 {game.find(5)}"); | ||||||
|         } |  | ||||||
|         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<int, string> 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 |  | ||||||
|         } |  | ||||||
| 
 |  | ||||||
|         static void Opdracht3c() |  | ||||||
|         { |  | ||||||
|             Publisher publisher = new Publisher("publisher"); // Init publisher class instance |  | ||||||
|             Dictionary<String, Model> tableDict = new Dictionary<string, Model>(); |  | ||||||
|              |  | ||||||
| 
 |  | ||||||
|             while(true){ |  | ||||||
|                 String input; |  | ||||||
|                 // Ask user if they want to request a specific entry |  | ||||||
|                 Console.WriteLine("Would you like to look up a record? [Y/n]"); |  | ||||||
|                 input  = Console.ReadLine(); |  | ||||||
|                 // Allow user to escape the loop |  | ||||||
|                 if(input == "n" || input == "N" || input == "no" || input == "NO" || input == "q"){ |  | ||||||
|                     break; |  | ||||||
|                 } |  | ||||||
|                 Console.WriteLine("Please enter the id of the publisher you wish to look up"); |  | ||||||
|                 input = Console.ReadLine(); |  | ||||||
|                 int id = -1; |  | ||||||
|                 try{ |  | ||||||
|                     id = int.Parse(input); |  | ||||||
|                 } |  | ||||||
|                 catch (FormatException) |  | ||||||
|                 { |  | ||||||
|                     Console.WriteLine("Invalid input for id. Please enter a positive Integer value (Whole number)"); |  | ||||||
|                 } |  | ||||||
|                 if(id >= 0){ |  | ||||||
|                     Console.WriteLine($"Record {id} is equal to {publisher.find(id)}"); |  | ||||||
|                 } |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|         public static void Opdracht4(){ |  | ||||||
|             Config config = Config.getInstance(); |  | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | |||||||
| @ -1,47 +0,0 @@ | |||||||
| using System.Collections.Generic; |  | ||||||
| using System.Collections; |  | ||||||
| using System.Linq; |  | ||||||
| using System.Configuration; |  | ||||||
| using System; |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| class Config{ |  | ||||||
| 
 |  | ||||||
|     private static Config instance = null; |  | ||||||
|     private Dictionary<string,string> contents; |  | ||||||
|     private Config(){ |  | ||||||
|         contents = GetSettings(); |  | ||||||
|     } |  | ||||||
|     public static Config getInstance(){ |  | ||||||
|         if ( instance == null ) instance = new Config(); |  | ||||||
|         return instance; |  | ||||||
|     } |  | ||||||
|     Dictionary <string,string> GetSettings()   |  | ||||||
|     {   |  | ||||||
|         Dictionary<string,string> settings = new Dictionary<string, string>(); |  | ||||||
|         try   |  | ||||||
|             {   |  | ||||||
|                 var appSettings = ConfigurationManager.AppSettings;   |  | ||||||
|                 if (appSettings.Count == 0)   |  | ||||||
|                 {   |  | ||||||
|                     Console.WriteLine("AppSettings is empty.");   |  | ||||||
|                 }   |  | ||||||
|                 else   |  | ||||||
|                 {   |  | ||||||
|                     var keys = appSettings.AllKeys;  |  | ||||||
|                     foreach(string key in keys){ |  | ||||||
|                         String value = appSettings.GetValues(key).GetValue(0).ToString(); |  | ||||||
|                         #if DEBUG |  | ||||||
|                         Console.WriteLine($"Debug: key {key} has value {value}"); |  | ||||||
|                         #endif |  | ||||||
|                         settings.Add(key,value); |  | ||||||
|                     } |  | ||||||
|                 } |  | ||||||
|             }   |  | ||||||
|             catch (ConfigurationErrorsException)   |  | ||||||
|             {   |  | ||||||
|                 Console.WriteLine("Error reading app settings");   |  | ||||||
|             }   |  | ||||||
|         return settings; |  | ||||||
|     }     |  | ||||||
| } |  | ||||||
| @ -13,14 +13,13 @@ namespace OOP_Opdracht_CSharp_Alfa_2022.classes | |||||||
|     |     | ||||||
| 
 | 
 | ||||||
|         // Game class constructor |         // Game class constructor | ||||||
|         public Game(String _tablename) : base(_tablename) |         public Game() | ||||||
|         { |         { | ||||||
|             // Set the table name |  | ||||||
|             if(this.table_data == null) table_data = new Dictionary<int, string>(); |             if(this.table_data == null) table_data = new Dictionary<int, string>(); | ||||||
|             String[] games = { "Battlefield 2042", "Counter-Strike: Global Offensive", "Quake III Arena", "Rust", "Starcraft II" }; |             this.table_data.Add(1, "Battlefield 2042"); | ||||||
|             for(int index = 1; index < games.Length+1; index++){ |             this.table_data.Add(2, "Counter-Strike: Global Offensive"); | ||||||
|                 this.table_data.Add(index, games[index-1]); |             this.table_data.Add(3, "Rust"); | ||||||
|             } | 
 | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|     } |     } | ||||||
|  | |||||||
| @ -10,12 +10,6 @@ namespace OOP_Opdracht_CSharp_Alfa_2022.classes | |||||||
|         protected SqlConnection connection; |         protected SqlConnection connection; | ||||||
|         protected Dictionary<int, string> table_data; |         protected Dictionary<int, string> table_data; | ||||||
|         protected KeyValuePair<int, string> record; |         protected KeyValuePair<int, string> record; | ||||||
|         protected String tablename; |  | ||||||
| 
 |  | ||||||
|         // Constructor |  | ||||||
|         public Model(String _tablename){ |  | ||||||
|             this.tablename = _tablename; |  | ||||||
|         } |  | ||||||
| 
 | 
 | ||||||
|         // Define Getters and Setters |         // Define Getters and Setters | ||||||
| 
 | 
 | ||||||
| @ -29,7 +23,6 @@ namespace OOP_Opdracht_CSharp_Alfa_2022.classes | |||||||
|             this.table_data = table_data; |             this.table_data = table_data; | ||||||
|             return; |             return; | ||||||
|         } |         } | ||||||
| 
 |  | ||||||
|         // Record get/set methods |         // Record get/set methods | ||||||
|         public void setRecord(int key, string value) |         public void setRecord(int key, string value) | ||||||
|         { |         { | ||||||
|  | |||||||
| @ -6,17 +6,10 @@ namespace OOP_Opdracht_CSharp_Alfa_2022.classes | |||||||
| { | { | ||||||
|     class Publisher : Model |     class Publisher : Model | ||||||
|     { |     { | ||||||
|         public Publisher(String _tablename) : base(_tablename) |         public Publisher() | ||||||
|         { |         { | ||||||
|             // Set the table name |             if (table_data == null) table_data = new Dictionary<int, string>(); | ||||||
|             this.tablename = "publisher"; |             table_data.Add(1, "Electronic Arts"); | ||||||
|             // Initialize dictionary |  | ||||||
|             if (this.table_data == null) this.table_data = new Dictionary<int, string>(); |  | ||||||
|             // 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]); |  | ||||||
|             } |  | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user