Exemplo n.º 1
0
        //method to read students from csv file
        //@param:college1 object of College class where students are added to from csv file
        public static bool readStudent(College college1)
        {
            //find file named students
            string fldr = "\\stdtList.txt";
            fldr = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + fldr;

            //set up variables for line of text and parsed line
            string textLine = "";
            string[] row;

            bool complete = false;

            //open stream reader, read file line at a time parsing student information and add to dictionary
            try
            {
                using (System.IO.StreamReader objReader = new System.IO.StreamReader(fldr))
                {
                    while ((textLine = objReader.ReadLine()) != null)
                    {

                        row = textLine.Split(',');
                        string studentId = row[0];
                        char courseType = Convert.ToChar(row[1]);
                        int courseCode = Convert.ToInt16(row[2]);
                        if (courseCode < 100)
                        {
                            //double fee = Convert.ToDouble(row[3]);
                            AdultStudent adultStudent1 = new AdultStudent(studentId, courseType, courseCode);
                            adultStudent1.setFee(adultStudent1.CourseType);
                            college1.addStudent(adultStudent1);
                        }//end if
                        else
                        {
                            char studyMode = Convert.ToChar(row[3]);
                            HNStudent hnStudent1 = new HNStudent(studentId, courseType, courseCode, studyMode);
                            college1.addStudent(hnStudent1);
                        }//end else

                    }//end while
                    complete = true;
                }//end using
            }//end try
            catch
            {
                complete = false;
                return complete;
            }//endcatch

            return complete;
        }
Exemplo n.º 2
0
        //add student menu
        public void addStudentMenu()
        {
            string menuStudentId;
            string menuCourseType;
            string menuCourseCode;
            int coursecode;
            string studyMode;
            bool addSuccess;

            Console.WriteLine("Enter Student Id 	:> ");
            menuStudentId = Console.ReadLine();

            if (students.ContainsKey(menuStudentId))
            {
                Console.WriteLine("Unable to add student, student already exist!");
                Console.WriteLine("");
                Console.WriteLine("Pres any key to return to menu");
                Console.ReadLine();
                mainMenu();
            }

            Console.WriteLine("Enter Course Type	:> ");
            menuCourseType = Console.ReadLine();
            Console.WriteLine("Enter Course CCode	:> ");
            menuCourseCode = Console.ReadLine();

            coursecode = Convert.ToInt16(menuCourseCode);

            if (coursecode > 100)
            {
                Console.WriteLine("Enter StudyMode	:> ");
                studyMode = Console.ReadLine();
                HNStudent HNStudent1 = new HNStudent(menuStudentId, Convert.ToChar(menuCourseType), coursecode, Convert.ToChar(studyMode));
                addSuccess = addStudent(HNStudent1);

                if (addSuccess == true)
                {
                    Console.WriteLine("Student Added");
                }

            }
            else
            {
                AdultStudent adultStudent1 = new AdultStudent(menuStudentId, Convert.ToChar(menuCourseType), coursecode);
                adultStudent1.setFee(Convert.ToChar(menuCourseType));
                addSuccess = addStudent(adultStudent1);
                if (addSuccess == true)
                {
                    Console.WriteLine("Student Added");
                }

            }
            Console.WriteLine("");
            Console.WriteLine("Pres any key to return to menu");
            Console.ReadLine();
            mainMenu();
        }