Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            //Create User Input Variable
            int userInput = -1; //used to keep track of user input

            //Create a new business layer
            IBusinessLayer businessLayerInst = new BusinessLayer();
            int            desiredStandardID = -1;
            string         desiredStandardName, desiredStandardDescription, updateStandardName,
                           updateStandardDescription;
            Standard newStandard, standardInst, updateStandard, deleteStandard;

            int     desiredStudentID = -1, revisedStandardID;
            Student newStudent, updateStudent, deleteStudent;
            string  updateStudentName, updateStandardID, desiredStudentName;

            while (userInput != 14)
            {
                try {
                    //void RemoveStudent(Student removeStudentItem);
                    //display commands and prompt user to enter a valid command
                    Console.WriteLine("\n\nUser Menu: \n 1.  Display all Standards\n 2.  Get Standard by "
                                      + "Standard ID\n 3.  Get Standard by Standard Name\n 4.  Add new Standard\n 5.  "
                                      + "Udate Standard\n 6.  Remove Standard\n 7.  Display all Students\n 8.  Get "
                                      + "Student By Student ID\n 9.  Get Student by Student Name\n 10. Get all Students "
                                      + "that have the same Standard ID\n 11. Add new Student\n 12. Update Student\n "
                                      + "13. Remove Student\n 14. Exit Program");
                    Console.WriteLine("\nPlease enter the number of the command you wish to "
                                      + "execute:\n(1 <= command number =< 14): ");
                    //attempt to convert the user input into an integer
                    userInput = Convert.ToInt32(Console.ReadLine());
                    //if the conversion was correct but the number is not within the valid
                    //range of 1 <= input =< 14, then re-prompt the user to enter a valid value
                    if (userInput > 14 || userInput < 1)
                    {
                        Console.WriteLine("The number provided was not within the appropriate"
                                          + " range of permissible \nvalues. Please enter an integer value "
                                          + "between 1 and 14...");
                    }
                    else
                    {
                        switch (userInput)
                        {
                        case 1:
                            //Display all of the standard data
                            Console.WriteLine("Retrieve all of the Standards using the "
                                              + "getAllStandards() method:");
                            DisplayStandards(businessLayerInst.getAllStandards());
                            break;

                        case 2:
                            //Display standard data using getID method
                            Console.WriteLine("\n\nGet a Standard using the GetStandardByID(int id) "
                                              + "method:");
                            //get valid standard id
                            desiredStandardID = ValidateStandardID(businessLayerInst);
                            ViewStandard(businessLayerInst.GetStandardByID(desiredStandardID));
                            break;

                        case 3:
                            //Display standard data using GetByStandardName method
                            Console.WriteLine("\n\nGet a Standard using the GetByStandardName(string "
                                              + "standardName) method:");
                            //get valid standard id
                            desiredStandardName = ValidateStandardName(businessLayerInst);
                            ViewStandard(businessLayerInst.GetStandardByName(desiredStandardName));
                            break;

                        case 4:
                            //Add a new standard to the table
                            Console.WriteLine("\n\nAdd Standard using the addStandard(Standard "
                                              + "addStandardItem) method. ");
                            //inform user of auto-increment standard id table column definition
                            Console.WriteLine("The Standard ID will automatically be created for "
                                              + "you via the sql table definition.");
                            //get standard name from user
                            Console.WriteLine("Please Enter the Desired Standard Name:");
                            desiredStandardName = Console.ReadLine();
                            //get standard description from user
                            Console.WriteLine("Please Enter the Desired Standard Description:");
                            desiredStandardDescription = Console.ReadLine();

                            //create new standard using user information
                            newStandard = new Standard();
                            newStandard.StandardName = desiredStandardName;
                            newStandard.Description  = desiredStandardDescription;
                            businessLayerInst.addStandard(newStandard);

                            //Display the newly created standard
                            Console.WriteLine("\nNew Standard created successfully. Here is the "
                                              + "newly created standard:");
                            ViewStandard(newStandard);
                            break;

                        case 5:
                            //update Standard
                            Console.WriteLine("Udate Standard using the updateStandard(Standard "
                                              + "updateStandardItem) method:");
                            //get valid standard id
                            desiredStandardID = ValidateStandardID(businessLayerInst);
                            //get standard to update
                            updateStandard = businessLayerInst.GetStandardByID(desiredStandardID);
                            Console.WriteLine("\n\nStandard Data Retrieved.");

                            //check to see if user wants to update standard name
                            updateStandardName = UpdateDataValidation("Standard Name");
                            //update Standard Name
                            if (!String.IsNullOrEmpty(updateStandardName))
                            {
                                updateStandard.StandardName = updateStandardName;
                            }

                            //check to see if user wants to update standard description
                            updateStandardDescription = UpdateDataValidation("Standard Description");
                            //update Standard Description
                            if (!String.IsNullOrEmpty(updateStandardDescription))
                            {
                                updateStandard.Description = updateStandardDescription;
                            }

                            //update standard
                            businessLayerInst.updateStandard(updateStandard);
                            //show user updated data
                            if (String.IsNullOrEmpty(updateStandardDescription) &&
                                String.IsNullOrEmpty(updateStandardName))
                            {
                                Console.WriteLine("Standard will remain unchanged.");
                            }
                            else
                            {
                                Console.WriteLine("Standard Updated Successfully.");
                            }
                            //show updated standard data
                            Console.WriteLine("\nHere is the Updated Standard data:");
                            ViewStandard(businessLayerInst.GetStandardByID(desiredStandardID));
                            break;

                        case 6:
                            //remove standard data
                            Console.WriteLine("Remove Standard using the removeStandard(Standard "
                                              + "removeStandardItem) method.");
                            desiredStandardID = ValidateStandardID(businessLayerInst);
                            deleteStandard    = businessLayerInst.GetStandardByID(desiredStandardID);

                            //Delete reference to all students who have the StandardID that is
                            //going to be deleted.

                            //get student to update
                            Console.WriteLine("Deleting reference to all Students who are connected "
                                              + "to the Standard that is going to be deleted....");
                            standardInst = businessLayerInst.GetStudentsByStandardID(
                                desiredStandardID);
                            foreach (Student studentItem in standardInst.Students)
                            {
                                //get student to update
                                updateStudent = businessLayerInst.GetStudentByID(
                                    studentItem.StudentID);
                                updateStudent.StandardId = null;
                                businessLayerInst.UpdateStudent(updateStudent);
                            }//close foreach

                            //Delete Standard
                            businessLayerInst.removeStandard(deleteStandard);
                            //Display remaining standard data
                            Console.WriteLine("Standard successfully removed! Here is all of the "
                                              + "remaining Standard data:");
                            DisplayStandards(businessLayerInst.getAllStandards());
                            break;

                        case 7:
                            //Display all of the student data
                            Console.WriteLine("Retrieve all of the Students using the "
                                              + "getAllStudents() method:");
                            DisplayStudents(businessLayerInst.getAllStudents());
                            break;

                        case 8:
                            //Display student data using getID method
                            Console.WriteLine("\n\nGet a Student using the GetStudentID(int id) "
                                              + "method:");
                            //get valid standard id
                            desiredStudentID = ValidateStudentID(businessLayerInst);
                            ViewStudent(businessLayerInst.GetStudentByID(desiredStudentID));
                            break;

                        case 9:
                            //Display Student using GetStudentByName(string studentName) method
                            Console.WriteLine("\n\nGet a Student using the GetStudentByName(string "
                                              + "studentName) method:");
                            //get valid standard id
                            desiredStudentName = ValidateStudentName(businessLayerInst);
                            ViewStudent(businessLayerInst.GetStudentByName(desiredStudentName));
                            break;

                        case 10:
                            //Get all students that have the same Standard ID

                            Console.WriteLine("\n\nGet all Students that have the same Standard ID:");
                            //get valid standard id
                            desiredStandardID = ValidateStandardID(businessLayerInst);
                            standardInst      = businessLayerInst.GetStudentsByStandardID(
                                desiredStandardID);
                            if (!standardInst.Students.Any())
                            {
                                Console.WriteLine("No Students have the associated Standard ID!");
                            }
                            else
                            {
                                DisplayStudents(standardInst.Students.ToList <Student>());
                            }
                            break;

                        case 11:
                            //create new student
                            Console.WriteLine("\n\nAdd Student using addStudent(Student "
                                              + "addStudentItem) method. ");
                            //inform user of auto-increment standard id table column definition
                            Console.WriteLine("The Student ID will automatically be created for you "
                                              + "via the sql table definition.");
                            //get standard name from user
                            Console.WriteLine("Please Enter the Desired Student Name:");
                            desiredStudentName = Console.ReadLine();
                            //get standard description from user
                            Console.WriteLine("Please Enter the Desired Standard Associated with the "
                                              + "student (StandardId must be a valid StandardId in the Standards "
                                              + "table:");
                            //get valid standard id
                            desiredStandardID = ValidateStandardID(businessLayerInst);

                            //Add a new student to the table
                            newStudent             = new Student();
                            newStudent.StudentName = desiredStudentName;
                            newStudent.StandardId  = desiredStandardID;
                            businessLayerInst.addStudent(newStudent);

                            //Display the newly created student
                            Console.WriteLine("\nNew Student created successfully. Here is the newly "
                                              + "created student:");
                            ViewStudent(newStudent);
                            break;

                        case 12:
                            //update student
                            Console.WriteLine("Udate Student using the UpdateStudent(Student "
                                              + "updateStudentItem) method:");
                            //get valid student id
                            desiredStudentID = ValidateStudentID(businessLayerInst);
                            //get student to update
                            updateStudent = businessLayerInst.GetStudentByID(desiredStudentID);
                            Console.WriteLine("\n\nStudent Data Retrieved.");

                            //check to see if user wants to update student name
                            updateStudentName = UpdateDataValidation("Student Name");
                            //update student name
                            if (!String.IsNullOrEmpty(updateStudentName))
                            {
                                updateStudent.StudentName = updateStudentName;
                            }

                            //check to see if user wants to update standard id
                            updateStandardID = "initialize";
                            while (!updateStandardID.ToUpper().Equals("Y") &&
                                   !updateStandardID.ToUpper().Equals("N"))
                            {
                                Console.WriteLine("Do you wish to update the Standard ID? y/n");
                                updateStandardID = Console.ReadLine();
                            }//end while

                            //prompt user to enter updated standard ID
                            if (updateStandardID.ToUpper().Equals("Y"))
                            {
                                //validate standard ID
                                revisedStandardID = ValidateStandardID(businessLayerInst);
                                //update standard ID
                                updateStudent.StandardId = revisedStandardID;
                            }//end if

                            //update standard
                            businessLayerInst.UpdateStudent(updateStudent);
                            //show user updated data
                            if (String.IsNullOrEmpty(updateStudentName) &&
                                !updateStandardID.ToUpper().Equals("Y"))
                            {
                                Console.WriteLine("Student will remain unchanged.");
                            }
                            else
                            {
                                Console.WriteLine("Student Updated Successfully.");
                            }
                            //show updated standard data
                            Console.WriteLine("\nHere is the updated Student data:");
                            ViewStudent(businessLayerInst.GetStudentByID(desiredStudentID));
                            break;

                        case 13:
                            //remove student data
                            Console.WriteLine("Remove Student using the RemoveStudent(Student "
                                              + "removeStudentItem) method.");
                            desiredStudentID = ValidateStudentID(businessLayerInst);
                            deleteStudent    = businessLayerInst.GetStudentByID(desiredStudentID);
                            businessLayerInst.RemoveStudent(deleteStudent);

                            //Display remaining standard data
                            Console.WriteLine("Student Successfully Removed. Here is all of the "
                                              + "remaining Student data:");
                            DisplayStudents(businessLayerInst.getAllStudents());
                            break;

                        case 14:
                            Console.WriteLine("You chose command #14:\nYou will now exit the "
                                              + "program...");
                            break;

                        default:
                            Console.WriteLine("You have reached the default case...");
                            break;
                        } //end case
                    }     //end else
                }         //end try
                catch (FormatException) {
                    //inform the user that they did not enter an integer value and re-prompt
                    //the command value input.
                    Console.WriteLine("Invalid user input. Please enter an INTEGER value "
                                      + "between 1 and 14...");
                } //end catch
            }     //end while loop

            Console.WriteLine("Your session has been terminated. Thank you for using this "
                              + "program.\nClick any key to close this window..");
            Console.ReadKey();
        } //close Main(...)
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            bool   programEnd = false;
            string studentName, standardName;
            int    standardId, studentId;

            IBusinessLayer   businessLayer = new BusinessLayer();
            IList <Standard> standardTable;
            IList <Student>  studentTable;
            Student          student;
            Standard         standard;
            string           option;

            while (!programEnd)
            {
                Console.WriteLine("1. Table Standard");
                Console.WriteLine("2. Table Student");
                Console.WriteLine("3. Exit Program");
                Console.Write("Please select from the above: ");
                int intTemp = Convert.ToInt32(Console.ReadLine());

                if (intTemp == 1)
                {
                    bool standardEnd = false;

                    while (!standardEnd)
                    {
                        Console.WriteLine("Standard Table Options:");
                        Console.WriteLine("1. Create Standard");
                        Console.WriteLine("2. Update Standard");
                        Console.WriteLine("3. Delete Standard");
                        Console.WriteLine("4. Display students under a standard ID");
                        Console.WriteLine("5. Display all standards");
                        Console.WriteLine("6. Exit menu.");
                        Console.Write("Selection: ");
                        int intInput = Convert.ToInt32(Console.ReadLine());
                        Console.WriteLine();

                        if (intInput == 1)
                        {
                            Console.WriteLine("Please enter the standard you wish to enter:");
                            Console.Write("Standard Name: ");
                            standardName = Console.ReadLine();

                            Standard stand = new Standard()
                            {
                                StandardName = standardName
                            };

                            businessLayer.addStandard(stand);
                        }
                        else if (intInput == 2)
                        {
                            Console.WriteLine("Enter the standard name you wish to update: ");
                            Console.Write("Standard Name: ");
                            standardName = Console.ReadLine();
                            Console.WriteLine();

                            standard = businessLayer.GetStandardByName(standardName);
                            Console.Write("Enter the updated standard name: ");
                            standard.StandardName = Console.ReadLine();
                            businessLayer.updateStandard(standard);
                        }
                        else if (intInput == 3)
                        {
                            Console.Write("Enter the standard name you wish to delete: ");
                            standardId = Convert.ToInt16(Console.ReadLine());
                            standard   = businessLayer.GetStandardByID(standardId);
                            businessLayer.removeStandard(standard);
                        }
                        else if (intInput == 4)
                        {
                            Console.Write("Enter the standard ID you wish to access: ");
                            standardId = Convert.ToInt16(Console.ReadLine());
                            standard   = businessLayer.GetStandardByID(standardId);
                            Console.WriteLine();
                            Console.WriteLine("Students in " + standard.StandardName + ": ");
                            Console.WriteLine();
                            Console.WriteLine("Students: " + "\t\t" + "ID:");
                            foreach (Student s in standard.Students)
                            {
                                Console.WriteLine(s.StudentName + "\t\t\t" + s.StudentID);
                            }
                            Console.WriteLine();
                        }
                        else if (intInput == 5)
                        {
                            standardTable = businessLayer.getAllStandards();
                            Console.WriteLine();
                            foreach (Standard newStandard in standardTable)
                            {
                                Console.WriteLine(newStandard.StandardId + " " + newStandard.StandardName);
                            }
                            Console.WriteLine();
                        }
                        else if (intInput == 6)
                        {
                            standardEnd = true;
                        }
                        else
                        {
                            Console.WriteLine("Invalid input. Please enter a valid option.");
                        }
                    }
                }
                else if (intTemp == 2)
                {
                    bool studentEnd = false;

                    while (!studentEnd)
                    {
                        Console.WriteLine("Student Table Options:");
                        Console.WriteLine("1. Create Student");
                        Console.WriteLine("2. Update Student");
                        Console.WriteLine("3. Delete Student");
                        Console.WriteLine("4. Display all Students");
                        Console.WriteLine("5. Exit menu.");
                        Console.Write("Selection: ");
                        int input = Convert.ToInt32(Console.ReadLine());

                        if (input == 1)
                        {
                            Console.WriteLine("Please enter the student name and id.");
                            Console.Write("Name: ");
                            studentName = Console.ReadLine();

                            Console.Write("New student's standard ID: ");
                            standardId = Convert.ToInt16(Console.ReadLine());

                            student = new Student
                            {
                                StudentName = studentName,
                                StandardId  = standardId
                            };

                            standard = businessLayer.GetStandardByID(standardId);
                            standard.Students.Add(student);
                            businessLayer.addStudent(student);
                        }
                        else if (input == 2)
                        {
                            Console.Write("Would you like to update by student name or student id?: ");
                            option = Console.ReadLine();
                            Console.WriteLine();
                            if (option.Equals("name"))
                            {
                                Console.Write("Enter the student name you are searching for: ");
                                studentName = Console.ReadLine();
                                student     = businessLayer.getStudentByName(studentName);
                                Console.WriteLine();
                                Console.Write("Enter the updated student name: ");
                                student.StudentName = Console.ReadLine();
                                businessLayer.updateStudent(student);
                            }
                            else if (option.Equals("id"))
                            {
                                Console.Write("Enter the student ID you are searching for: ");
                                studentId = Convert.ToInt16(Console.ReadLine());
                                student   = businessLayer.getStudentByID(studentId);
                                Console.WriteLine();
                                Console.Write("Enter the updated student name: ");
                                student.StudentName = Console.ReadLine();
                                businessLayer.updateStudent(student);
                            }
                        }
                        else if (input == 3)
                        {
                            Console.Write("Enter the student ID you want to delete: ");
                            studentId = Convert.ToInt16(Console.ReadLine());
                            student   = businessLayer.getStudentByID(studentId);
                            businessLayer.removeStudent(student);
                        }
                        else if (input == 4)
                        {
                            studentTable = businessLayer.getAllStudents();
                            Console.WriteLine();
                            foreach (Student studentLoop in studentTable)
                            {
                                Console.WriteLine(studentLoop.StudentName + " " + studentLoop.StudentID);
                            }
                            Console.WriteLine();
                        }
                        else if (input == 5)
                        {
                            studentEnd = true;
                        }
                    }
                }
                else
                {
                    Console.WriteLine("Thank you for using this program!");
                    programEnd = true;
                }
            }
        }