Пример #1
0
        public static void listMembersBoetes(List <Leden> members)
        {
            String printMe = "";

            Console.Clear();
            Console.SetCursorPosition(2, 0);
            printMe = (String.Format(" {0,-15}   {1,4}   {2,1}   {3,20}   {4,4}   {5,4} ", "Naam", "Num", "S", "Boete", "Geb", "Lid"));
            Console.SetCursorPosition(Console.WindowWidth / 2 - printMe.Length / 2, Console.CursorTop);
            Console.Write(printMe);
            Console.CursorTop += 2;
            foreach (Leden member in members)
            {
                printMe = (String.Format(" {0,-15} | {1,4} | {2,1} | {3,20} | {4,4} | {5,4} ", member.naam, member.snummer, member.s, Program.context.Boetes.Single(b => b.speler.ledenID == member.ledenID).bedrag_boete, member.gebjaar, member.jaarlid));
                Console.SetCursorPosition(Console.WindowWidth / 2 - printMe.Length / 2, Console.CursorTop);
                Console.Write(printMe);
                Console.CursorTop++;
            }

            printMe = " -- Press any key to continue -- ";
            Console.SetCursorPosition(Console.WindowWidth / 2 - printMe.Length / 2, Console.WindowHeight - 2);
            Console.Write(printMe);

            Console.ReadKey(true);

            ConsoleWriting.MainMenu();
        }
Пример #2
0
        public static void deleteMember()
        {
            Console.Clear();
            Console.SetCursorPosition(2, 2);
            int index;

            try
            {
                index = Convert.ToInt32(Console.ReadLine());
            }
            catch (Exception e)
            {
                ConsoleWriting.MainMenu();
                return;
            }
            Program.context.Leden.Remove(Program.context.Leden.Where(r => r.snummer == index).ToArray()[0]);
            Program.context.SaveChanges();
            ConsoleWriting.MainMenu();
        }
Пример #3
0
        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>());
        }
Пример #4
0
        public static void MainMenu()
        {
            bool looping = true;

            String[] options = { "List members", "Add member", "NHL wedstrijden", "Ouwe gasten", "Exit", "Max boete C", "Edit member", "Remove member" };
            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((i + 1) + " ");
                    Console.Write(options[i]);
                }
                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;

                default:
                    if (Char.IsDigit(k.KeyChar))
                    {
                        int d = Convert.ToInt32(k.KeyChar.ToString()) - 1;
                        if (d < options.Length)
                        {
                            jump  = true;
                            index = d;
                        }
                    }
                    break;
                }
                if (jump)
                {
                    switch (index)
                    {
                    case 0:
                        listMembers(Program.context.Leden.ToList <Leden>());
                        looping = false;
                        break;

                    case 1:
                        addMember();
                        looping = false;
                        break;

                    case 2:
                        listMembers(Queries.scheidsrechtersBijZaal(Program.context.Zalen.ToArray()[2]));
                        looping = false;
                        break;

                    case 3:
                        Console.Clear();
                        Console.SetCursorPosition(2, 2);
                        Console.Write("Leeftijd: ");
                        int i = Convert.ToInt32(Console.ReadLine());
                        listMembers(Queries.ouderDanToenLid(i));
                        looping = false;
                        break;

                    case 4:
                        looping = false;
                        ConsoleWriting.GoodBye();
                        break;

                    case 5:
                        List <Leden> l = new List <Leden>();
                        l.Add(Queries.maxBoetes());
                        ConsoleWriting.listMembersBoetes(l);
                        looping = false;
                        break;

                    case 6:
                        editMember();
                        looping = false;
                        break;

                    case 7:
                        deleteMember();
                        looping = false;
                        break;

                    default:
                        break;
                    }
                }
            }
        }
Пример #5
0
        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();
        }