Ejemplo n.º 1
0
        /// <summary>
        /// Ascii art logo för sök
        /// </summary>
        public static void LogoSearch()
        {
            Utilitys.PrintYellow(@"
   _____                      __
  / ___/___  ____ ___________/ /_
  \__ \/ _ \/ __ `/ ___/ ___/ __ \
 ___/ /  __/ /_/ / /  / /__/ / / /
/____/\___/\__,_/_/   \___/_/ /_/
");
        }
Ejemplo n.º 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();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Ascii art logo för Addperson
        /// </summary>
        public static void LogoAddPerson()
        {
            Utilitys.PrintGreen(@"
    ___       __    __
   /   | ____/ /___/ /  ____  ___  ______________  ____
  / /| |/ __  / __  /  / __ \/ _ \/ ___/ ___/ __ \/ __ \
 / ___ / /_/ / /_/ /  / /_/ /  __/ /  (__  ) /_/ / / / /
/_/  |_\__,_/\__,_/  / .___/\___/_/  /____/\____/_/ /_/
                    /_/

");
        }
Ejemplo n.º 4
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();
        }
Ejemplo n.º 5
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();
        }
Ejemplo n.º 6
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;
                }
            }
        }
Ejemplo n.º 7
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();
            }
        }
Ejemplo n.º 8
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();
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Lägger till Personer till Databasen
        /// </summary>
        private void AddPerson()
        {
            Console.Clear();
            Utilitys.LogoAddPerson();
            var db     = new SQLDatabase();
            var person = new Person();

            try
            {
                Console.Write("[Required]\nEnter first name: ");
                person.FirstName = Console.ReadLine();
                Console.Write("[Required]\nEnter last name: ");
                person.LastName = Console.ReadLine();
                Console.Write("[Optional]\nEnter year of birth-(yyyy): ");
                person.Born = int.Parse(Console.ReadLine());
            }
            catch
            {
                Debug.Write("Wrong input");
            }

            if (person.FirstName?.Length == 0 || person.LastName?.Length == 0)
            {
                Utilitys.PrintRed("Worng input, try again? (y/n)");
                var choice = Console.ReadLine();
                if (string.Equals(choice, "y", StringComparison.OrdinalIgnoreCase))
                {
                    AddPerson();
                }
            }
            else
            {
                person = db.CreatePerson(person);
                Utilitys.PrintGreen($"{person.FirstName} was added");
            }
            Console.WriteLine("Press any key to go back!");
            Console.ReadKey();
        }
Ejemplo n.º 10
0
        /// <summary>
        /// StartMeny
        /// </summary>
        private void Menu()
        {
            while (true)
            {
                Console.Clear();
                Utilitys.LogoMenu();
                Console.WriteLine("1. Add Person");
                Console.WriteLine("2. Show people");
                Console.WriteLine("3. Update person");
                Console.WriteLine("4. Delete person");
                Console.WriteLine("5. Exit application");
                var input = Console.ReadLine();
                switch (input)
                {
                case "1":
                    AddPerson();
                    break;

                case "2":
                    Search();
                    break;

                case "3":
                    UpdatePerson();
                    break;

                case "4":
                    DeletePerson();
                    break;

                case "5":
                    Environment.Exit(0);
                    break;
                }
            }
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Hämtar personer och uppdaterar dess data
        /// </summary>
        private void UpdatePerson()
        {
            Console.Clear();
            Utilitys.LogoUpdate();
            var db = new SQLDatabase();

            Console.Write("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]);
                    bool isRunning = true;
                    while (isRunning)
                    {
                        Console.Clear();
                        Utilitys.LogoUpdate();
                        PrintPerson(person);
                        Console.WriteLine("What do you wanna change?");
                        Console.WriteLine("1. First name: ");
                        Console.WriteLine("2. Last Name ");
                        Console.WriteLine("3. Date of birth ");
                        Console.WriteLine("4. Date of death ");
                        Console.WriteLine("5. Mother");
                        Console.WriteLine("6. Father");
                        Console.WriteLine("7. Exit to main Menu");

                        var input = Console.ReadLine();
                        if (int.TryParse(input, out int choice))
                        {
                            switch (choice)
                            {
                            case 1:
                                Console.Write("Enter first name: ");
                                person.FirstName = Console.ReadLine();
                                break;

                            case 2:
                                Console.Write("Enter first name: ");
                                person.LastName = Console.ReadLine();
                                break;

                            case 3:
                                Console.Write("Enter Date of birth: ");
                                person.Born = Convert.ToInt32(Console.ReadLine());
                                break;

                            case 4:
                                Console.Write("Enter Date of birth: ");
                                person.Died = Convert.ToInt32(Console.ReadLine());
                                break;

                            case 5:
                                var mother = GetParent("mother");
                                if (mother != null)
                                {
                                    person.Mother = mother.Id;
                                }
                                break;

                            case 6:
                                var father = GetParent("father");
                                if (father != null)
                                {
                                    person.Father = father.Id;
                                }
                                break;

                            case 7:
                                isRunning = false;
                                break;
                            }
                            db.Update(person);
                        }
                    }
                    Console.WriteLine("Wrong input!");
                }
                catch
                {
                    Console.WriteLine("Wrong input!");
                }
            }
            else
            {
                Console.WriteLine("Person not found in DB");
            }
        }