Esempio n. 1
0
        //Deleting a student from the student tracker or returns to main menu
        public static void DeleteStudent()
        {
            Console.WriteLine("Enter the first name of the student you wish to delete:");
            string deleteInput = Console.ReadLine();

            Console.WriteLine("You are deleting all instances of" + deleteInput + ". Is this correct? [Y]es or [N]o");
            char answerInput = Console.ReadKey().KeyChar;

            if (answerInput == 'Y')
            {
                foreach (StudentData deleteResult in StudentDataList.Where(s => s.FName.Contains(deleteInput)))
                {
                    StudentDataList.Remove(deleteResult);
                }

                Console.WriteLine("You have succesfully deleted a student.");
            }
            else if (answerInput == 'N')
            {
                StudentDataFunc.DisplayMenu();
            }
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            char   choice;
            string name;
            bool   isDone = false;

            // The following declaration will build a string of your current directory with the CSV filename
            string filePath = Path.Combine(Environment.CurrentDirectory, "StudentDataCSVFile.csv");

            try
            {
                // Loads data from csv file and readies if for processing
                LoadData(filePath);

                // While user does not QUIT, continually show the menu of options available
                while (!isDone)
                {
                    // Displays Menu for user
                    choice = StudentDataFunc.DisplayMenu();

                    if (choice == 'F') // Option: FIND
                    {
                        // Search List of Students
                        Console.WriteLine(" ");
                        Console.WriteLine("Please Enter \r\n [F] to search by student's first name, \r\n [L] to search by student's last or \r\n [T] to search teacher name:");
                        name = Console.ReadLine().ToUpper();

                        if (name == "F")
                        {
                            searchByFirstName();
                            break;
                        }

                        else if (name == "L")
                        {
                            searchByLastName();
                            break;
                        }

                        else if (name == "T")
                        {
                            searchByTeacherName();
                            break;
                        }

                        else
                        {
                            Console.WriteLine("No matching records found.");
                        }
                        Console.WriteLine(" ");
                    }
                    else if (choice == 'A') // Option: ADD
                    {
                        // Get data from the user to add to the student list
                        Console.WriteLine(" ");
                        Console.WriteLine("Enter first name of student to be added:");
                        string FNameInput = Console.ReadLine();

                        Console.WriteLine("Enter last name of student to be added:");
                        string LNameInput = Console.ReadLine();

                        Console.WriteLine("Enter the last name of the student's teacher:");
                        string TeacherNameInput = Console.ReadLine();

                        Console.WriteLine("Enter Quiz 1 score:");
                        int Quiz1Input = Convert.ToInt32(Console.ReadLine());

                        Console.WriteLine("Enter Quiz 2 score:");
                        int Quiz2Input = Convert.ToInt32(Console.ReadLine());

                        Console.WriteLine("Enter Quiz 3 score:");
                        int Quiz3Input = Convert.ToInt32(Console.ReadLine());

                        Console.WriteLine("Enter Quiz 4 score:");
                        int Quiz4Input = Convert.ToInt32(Console.ReadLine());

                        StudentDataList.Add(new StudentData(FNameInput, LNameInput, TeacherNameInput, Quiz1Input.ToString(),
                                                            Quiz2Input.ToString(), Quiz3Input.ToString(), Quiz4Input.ToString()));

                        Console.WriteLine(" ");
                        Console.WriteLine("Your data has been added.");
                        Console.WriteLine(" ");
                    }

                    else if (choice == 'D') // Option: DELETE
                    {
                        DeleteStudent();
                        Console.WriteLine(" ");
                    }

                    else if (choice == 'P') // Option: PRINT
                    {
                        // Print the student data to the screen
                        Console.WriteLine();
                        Console.WriteLine();
                        Console.WriteLine("Student     \tTeacher\tQz 1\tQz 2\tQz 3\tQz 4");
                        Console.WriteLine("--------    \t-------\t----\t----\t----\t----");
                        foreach (StudentData item in StudentDataList)
                        {
                            Console.WriteLine(item.LName + ", " +
                                              item.FName + "\t" +
                                              item.TeacherName + "\t" +
                                              item.Quiz1 + "\t" +
                                              item.Quiz2 + "\t" +
                                              item.Quiz3 + "\t" +
                                              item.Quiz4);
                        }
                        Console.WriteLine();
                    }

                    else if (choice == 'Q') // Option: QUIT
                    {
                        isDone = true;
                    }
                }

                // Save the student data and then set the done flag to exit the while loop
                SaveData(filePath);
            }
            catch (Exception ex)
            {
                throw new Exception("Your input is invalid.", innerException: ex);
            }
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            char   choice;
            var    p        = new Program();
            string filePath = @"C:\\Users\\jmrig\\source\\repos\\StudentTracker\\StudentTracker\\StudentDataCSVFile.csv";


            bool isDone = false;

//try
            //{
            while (!isDone)
            {
                //Loads data from csv file
                p.LoadData();

                //Displays Menu for user
                choice = StudentDataFunc.DisplayMenu();

                if (choice == 'F')
                {
                    //Search List of Students
                    Console.WriteLine(" ");
                    Console.WriteLine("Please Enter \r\n [F] to search by student's first name, \r\n [L] to search by student's last or \r\n [T] to search teacher name:");
                    string name = Console.ReadLine().ToUpper();
                    if (name == "F")
                    {
                        searchByFirstName();
                        break;
                    }

                    else if (name == "L")
                    {
                        searchByLastName();
                        break;
                    }

                    else if (name == "T")
                    {
                        searchByTeacherName();
                        break;
                    }

                    else
                    {
                        Console.WriteLine("No matching records found.");
                    }
                    Console.WriteLine(" ");
                    StudentDataFunc.DisplayMenu();
                }

                else if (choice == 'A')
                {
                    //Add Students to File
                    using (FileStream fs = new FileStream(@filePath, FileMode.Append))
                        using (StreamWriter sw = new StreamWriter(fs))
                        {
                            Console.WriteLine(" ");
                            Console.WriteLine("Enter first name of student to be added:");
                            string FNameInput = Console.ReadLine();

                            Console.WriteLine("Enter last name of student to be added:");
                            string LNameInput = Console.ReadLine();

                            Console.WriteLine("Enter the last name of the student's teacher:");
                            string TeacherNameInput = Console.ReadLine();

                            Console.WriteLine("Enter Quiz 1 score:");
                            int Quiz1Input = Convert.ToInt32(Console.ReadLine());

                            Console.WriteLine("Enter Quiz 2 score:");
                            int Quiz2Input = Convert.ToInt32(Console.ReadLine());

                            Console.WriteLine("Enter Quiz 3 score:");
                            int Quiz3Input = Convert.ToInt32(Console.ReadLine());

                            Console.WriteLine("Enter Quiz 4 score:");
                            int Quiz4Input = Convert.ToInt32(Console.ReadLine());

                            string textAdd = (FNameInput + "," + LNameInput + "," + TeacherNameInput + "," + Quiz1Input + "," + Quiz2Input + "," + Quiz3Input + "," + Quiz4Input);
                            sw.WriteLine(filePath, textAdd + Environment.NewLine);
                            Console.ReadLine();

                            StudentDataList.Add(new StudentData(FNameInput, LNameInput, TeacherNameInput, Quiz1Input.ToString(),
                                                                Quiz2Input.ToString(), Quiz3Input.ToString(), Quiz4Input.ToString()));
                            //SaveData(ToData());
                        }



                    Console.WriteLine("Your data has been added.");
                    Console.WriteLine(" ");
                    StudentDataFunc.DisplayMenu();
                }

                else if (choice == 'D')
                {
                    DeleteStudent();
                    Console.WriteLine(" ");
                    StudentDataFunc.DisplayMenu();
                }

                else if (choice == 'P')
                {
                    foreach (StudentData item in StudentDataList)
                    {
                        FileRead(item);
                    }
                    StudentDataFunc.DisplayMenu();
                }

                else if (choice == 'Q')
                {
                    isDone = true;
                }
            }
            //}
            //catch (Exception ex)
            //{
            //    throw new Exception("Your input is invalid.", innerException: ex);
            //}
        }