static void Main(string[] args) { context = new ClubDbContext(); Console.SetCursorPosition(2, 2); Console.Write("Clear database? (Y/N): "); bool loop = true; while (loop) { char c = Console.ReadKey().KeyChar; if (c == 'Y' || c == 'y') { loop = false; context.Database.Delete(); Dictionary <Leden, string> teamKey = new Dictionary <Leden, string>(); ConsoleWriting.WriteCreatingDB(); leden = new List <string>(); boetes = new List <string>(); teams = new List <string>(); wedstrijden = new List <string>(); // Split text (file) to 2d String array. foreach (String dir in dirOne) { if (File.Exists(dir)) { gridOne = fileToGrid(File.ReadAllText(dir)); } } foreach (String dir in dirTwo) { if (File.Exists(dir)) { gridTwo = fileToGrid(File.ReadAllText(dir)); } } //gridOne = fileToGrid(File.ReadAllText(dirOne)); //gridTwo = fileToGrid(File.ReadAllText(dirTwo)); for (int i = 0; i < gridOne.GetLength(1) - 1; i++) { // Insert Memebers Leden lid = new Leden(); lid.adres = getColumn("adres")[i]; lid.gebjaar = Convert.ToInt32(getColumn("gebjaar")[i]); lid.naam = getColumn("naam")[i]; lid.jaarlid = Convert.ToInt32(getColumn("jaarlid")[i]); lid.s = getColumn("s")[i]; lid.snummer = Convert.ToInt32(getColumn("snummer")[i]); if (!teamKey.ContainsKey(lid) && getColumn("team")[i] != "") { teamKey.Add(lid, getColumn("team")[i]); } context.Leden.Add(lid); ConsoleWriting.UpdateProgress(1); // Insert Penalties Boetes boete = new Boetes(); boete.bedrag_boete = Convert.ToInt32(getColumn("bedrag_boete")[i] == "" ? "0" : getColumn("bedrag_boete")[i]); boete.speler = (lid); boete.toelichting = getColumn("toelichting")[i]; //boete.teamcode = context.Boetes.Add(boete); ConsoleWriting.UpdateProgress(1); } context.SaveChanges(); for (int i = 0; i < gridTwo.GetLength(1) - 1; i++) { Zalen zaal = new Zalen(); // Insert Gyms zaal.zaaladres = getColumn("zaaladres")[i]; zaal.trainzaal = getColumn("trainzaal")[i]; zaal.zaaltel = getColumn("zaaltel")[i]; if (!context.Zalen.Local.Any(b => b.trainzaal == zaal.trainzaal) && (zaal.trainzaal != "")) { context.Zalen.Add(zaal); ConsoleWriting.UpdateProgress(1); } try { context.SaveChanges(); ConsoleWriting.UpdateProgress(1); } catch (Exception e) { Console.WriteLine(e); } } for (int i = 0; i < gridTwo.GetLength(1) - 1; i++) { Training training = new Training(); Teams team = new Teams(); Wedstrijden wedstrijd = new Wedstrijden(); // Insert Teams team.teamcode = getColumn("teamcode")[i]; team.trainer = context.Leden.Local.Single(b => b.snummer == Convert.ToInt32(getColumn("trainer")[i])); team.leeftijdsklasse = getColumn("leeftijdsklasse")[i]; team.sexe = getColumn("sexe")[i]; foreach (Leden l in from b in teamKey where b.Value == team.teamcode select b.Key) { team.spelers.Add(l); } if (!context.Teams.Local.Any(b => b == team)) { context.Teams.Add(team); ConsoleWriting.UpdateProgress(1); } // Insert Game try { wedstrijd.wedstrijdnummer = Convert.ToInt32(getColumn("wedstrijdnummer")[i]); } catch (FormatException e) { wedstrijd.scheids = null; } try { wedstrijd.scheids = context.Leden.Local.Single(b => b.snummer == Convert.ToInt32(getColumn("scheids")[i])); } catch (FormatException e) { wedstrijd.scheids = null; } wedstrijd.wedstrijddatum = getColumn("wedstrijddatum")[i]; wedstrijd.tegenstander = getColumn("tegenstander")[i]; try { wedstrijd.wedstrijdzaal = context.Zalen.Local.Single(b => b.trainzaal == getColumn("wedstrijdzaal")[i]); } catch (Exception e) { Console.WriteLine(e.Message); } wedstrijd.teamcode = team; context.Wedstrijden.Add(wedstrijd); // Insert Trains if (!team.trainingen.Any(b => b.traindag == Convert.ToInt32(getColumn("traindag")[i]))) { try { training.traindag = Convert.ToInt32(getColumn("traindag")[i]); } catch (FormatException e) { training.traindag = 0; } try { training.trainlengte = Convert.ToInt32(getColumn("trainlengte")[i]); } catch (FormatException e) { training.trainlengte = 0; } try { training.trainzaal = context.Zalen.Local.Single(b => b.trainzaal == getColumn("trainzaal")[i]); } catch (Exception e) { Console.WriteLine(e.Message); } team.trainingen.Add(training); } } try { context.SaveChanges(); ConsoleWriting.UpdateProgress(1); } catch (Exception e) { Console.WriteLine(e); } } else if (c == 'N' || c == 'n') { loop = false; } } ConsoleWriting.listMembers(context.Leden.ToList <Leden>()); }
public static void addMember() { Leden lid = new Leden(); bool looping = true; String[] options = { "Cancel", "Name", "Member number", "Gender (m/v)", "Adress", "Year of birth", "Member since", "Done" }; String[] contents = { "", "", "", "", "", "", "", "" }; contents[2] = (Program.context.Leden.Max(x => x.snummer) + 1) + ""; contents[6] = DateTime.Now.Year + ""; Console.Clear(); String printMe = "- Main Menu -"; Console.SetCursorPosition(Console.WindowWidth / 2 - printMe.Length / 2, 2); Console.Write(printMe); int index = 0; while (looping) { bool jump = false; for (int i = 0; i < options.Length; i++) { Console.SetCursorPosition(4, 4 + i); Console.Write(i == index ? " >" : " "); Console.Write(options[i]); if (i != 0 && i != 7) { Console.Write(": " + contents[i]); for (int j = 0; j < Console.WindowWidth - Console.CursorLeft; j++) { Console.Write(" "); } } } if (index != 0 && index != 7) { Console.CursorVisible = true; try { Console.SetCursorPosition(options[index].Length + contents[index].Length + 8, index + 4); } catch (ArgumentOutOfRangeException e) { Console.SetCursorPosition(0, 0); Console.Write("Now you're just making stuff up."); } } else { Console.CursorVisible = false; } ConsoleKeyInfo k = Console.ReadKey(true); switch (k.Key) { case ConsoleKey.DownArrow: index++; index = index > options.Length - 1 ? options.Length - 1 : index; break; case ConsoleKey.UpArrow: index--; index = index < 0 ? 0 : index; break; case ConsoleKey.Enter: jump = true; break; case ConsoleKey.Backspace: if (contents[index] != "") { contents[index] = contents[index].Remove(contents[index].Length - 1); } break; default: if (Char.IsLetterOrDigit(k.KeyChar)) { contents[index] += k.KeyChar; } break; } if (jump) { switch (index) { case 0: looping = false; break; case 7: //String[] options = { "Cancel", "Name", "Member number", "Gender (m/v)", "Adress", "Year of birth", "Member since", "Done"}; bool error = false; lid.naam = contents[1]; try { lid.snummer = Convert.ToInt32(contents[2]); } catch (Exception e) { error = true; } if (Program.context.Leden.Any(b => b.snummer == lid.snummer)) { error = true; } lid.s = contents[3]; lid.adres = contents[4]; try { lid.gebjaar = Convert.ToInt32(contents[5]); } catch (Exception e) { error = true; } try { lid.jaarlid = Convert.ToInt32(contents[6]); } catch (Exception e) { error = true; } looping = error; if (!error) { Program.context.Leden.Add(lid); Program.context.SaveChanges(); } break; default: index++; break; } } } ConsoleWriting.MainMenu(); }