Example #1
0
 /// <summary>
 /// Sök Personer som börjar på ....
 /// </summary>
 private void ShowPeopleByLetter()
 {
     Console.Clear();
     Utilitys.LogoSearch();
     try
     {
         var db = new SQLDatabase();
         Console.Write("Enter a letter: ");
         var letter = Console.ReadLine();
         if (letter == "")
         {
             Utilitys.PrintRed("Next time enter a letter");
         }
         else
         {
             var sql = "Where firstName LIKE @letter +'%'";
             PrintAllPerson(db.ShowAllFrom(sql, ("@letter", letter)));
         }
     }
     catch
     {
         Console.WriteLine("Invalid input, try again");
     }
     Console.WriteLine("Press any key to go back!");
     Console.ReadLine();
 }
Example #2
0
        /// <summary>
        /// Visar föräldrar
        /// </summary>
        private void Parents()
        {
            Console.Clear();
            Utilitys.LogoSearch();
            var db = new SQLDatabase();

            Console.WriteLine("Enter name on person you wanna display: ");
            var name    = Console.ReadLine();
            var persons = db.GetPersons(name);

            if (persons.Count > 0)
            {
                var ctr = 1;
                foreach (var person in persons)
                {
                    var info = $"{ctr++}. {person.FirstName} {person.LastName} Born: {person.Born}";
                    Console.WriteLine(info);
                }
                Console.WriteLine("0. None of the above");
                var option = ChoosePerson(persons.Count);
                try
                {
                    var person = (persons[option - 1]);
                    var mother = db.GetPersons(person.Mother);
                    PrintPerson(person);
                    if (mother == null)
                    {
                        Console.WriteLine("No mother");
                    }
                    else
                    {
                        Console.WriteLine("Mother:");
                        PrintPerson(mother);
                    }
                    var father = db.GetPersons(person.Father);
                    if (father == null)
                    {
                        Console.WriteLine("No Father: ");
                    }
                    else
                    {
                        Console.WriteLine("Father: ");
                        PrintPerson(father);
                    }
                }
                catch
                {
                    Console.WriteLine("Somthing went wrong, try again");
                }
            }
            Console.WriteLine("Press any key to return: ");
            Console.ReadKey();
        }
Example #3
0
        /// <summary>
        /// Visar syskon
        /// </summary>
        private void ShowSiblings()
        {
            Console.Clear();
            Utilitys.LogoSearch();
            var db = new SQLDatabase();

            Console.WriteLine("Enter name on person you wanna display: ");
            var name    = Console.ReadLine();
            var persons = db.GetPersons(name);

            if (persons.Count > 0)
            {
                var ctr = 1;
                foreach (var person in persons)
                {
                    var info = $"{ctr++}. {person.FirstName} {person.LastName} Born: {person.Born}";
                    Console.WriteLine(info);
                }
                Console.WriteLine("0. None of the above");
                var option = ChoosePerson(persons.Count);
                if (option > 0)
                {
                    try
                    {
                        var siblings = db.GetSiblings(persons[option - 1]);
                        if (siblings.Count > 0)
                        {
                            Console.WriteLine($"{persons[option - 1].FirstName}\nSiblings: ");
                            PrintList(siblings);
                            Console.Write("Press any key to return: ");
                            Console.ReadKey();
                        }
                        else
                        {
                            Console.WriteLine("No Siblings found\n Press enter to return");
                            Console.ReadKey();
                        }
                    }
                    catch
                    {
                        Console.WriteLine("Wrong input!");
                    }
                }
            }
            else
            {
                Console.WriteLine("Person not found in DB");
            }
            Console.WriteLine("[Press any key to go back]");
            Console.Clear();
        }
Example #4
0
        private void ShowAllFromDatabase()
        {
            Console.Clear();
            Utilitys.LogoSearch();
            var db = new SQLDatabase();
            var dt = db.ShowAllFrom();

            foreach (DataRow row in dt.Rows)
            {
                Console.WriteLine($"ID: {row["Id"]} Name: {row["firstName"]} {row["lastName"]} " +
                                  $"Born: {row["born"]} Mother Id: {row["motherId"]} Father Id: {row["fatherId"]}");
            }
            Console.WriteLine("[Press any key to go back]");
            Console.ReadLine();
        }
Example #5
0
        /// <summary>
        /// Listar personer från databasen beroende på vad vi vill visa
        /// </summary>
        private void Search()
        {
            while (true)
            {
                Console.Clear();
                Utilitys.LogoSearch();
                var db = new SQLDatabase();
                Console.WriteLine("What do you wanna search for? ");
                Console.WriteLine("1. People starting with a certain letter");
                Console.WriteLine("2. People born a certain year");
                Console.WriteLine("3. People misssing data");
                Console.WriteLine("4. Show parents to a certain person");
                Console.WriteLine("5. Show siblings to a certain person");
                Console.WriteLine("6. Show all in DB");
                Console.WriteLine("7. Exit to main menu");
                var input = Console.ReadLine();
                switch (input)
                {
                case "1":
                    ShowPeopleByLetter();
                    break;

                case "2":
                    ShowWhenPeopleBorn();
                    break;

                case "3":
                    ShowPeopleMissingData();
                    break;

                case "4":
                    Parents();
                    break;

                case "5":
                    ShowSiblings();
                    break;

                case "6":
                    ShowAllFromDatabase();
                    break;

                case "7":
                    Menu();
                    break;
                }
            }
        }
Example #6
0
        /// <summary>
        /// Visar Personer som saknar data i databasen
        /// </summary>
        private void ShowPeopleMissingData()
        {
            while (true)
            {
                Console.Clear();
                Utilitys.LogoSearch();
                var db = new SQLDatabase();
                Console.WriteLine("Missing Infos Menu");
                Console.WriteLine("1. Show persons missing date of birth");
                Console.WriteLine("2. Show persons missing date of death");
                Console.WriteLine("3. Show persons missing MotherId");
                Console.WriteLine("4. Show persons missing FatherID");
                Console.WriteLine("5. Exit to main menu");
                var sql   = "";
                var input = Console.ReadLine();
                switch (input)
                {
                case "1":
                    sql = "Where born=0";
                    break;

                case "2":
                    sql = "Where died=0";
                    break;

                case "3":
                    sql = "Where motherId=0";
                    break;

                case "4":
                    sql = "Where fatherId=0";
                    break;

                case "5":
                    Menu();
                    break;
                }
                Console.Clear();
                PrintAllPerson(db.ShowAllFrom(sql));
                Console.WriteLine("Press any key to return: ");
                Console.ReadKey();
            }
        }
Example #7
0
        /// <summary>
        /// Listar personer efter år
        /// </summary>
        private void ShowWhenPeopleBorn()
        {
            Console.Clear();
            Utilitys.LogoSearch();
            try
            {
                var db = new SQLDatabase();
                Console.Write("Enter year: ");
                var year = Convert.ToInt32(Console.ReadLine());
                var sql  = "Where born = @born";

                PrintAllPerson(db.ShowAllFrom(sql, ("@born", $"{year}")));
            }
            catch
            {
                Console.WriteLine("Invalid Input, try again! ");
            }
            Console.WriteLine("Press any key to go back!");
            Console.ReadKey();
        }