Пример #1
0
    public bool isConflict(courseinfo course)
    {
        bool conflict = false;

        foreach (coursetime time in Times)             //Each time the course is offered
        {
            foreach (coursetime time2 in course.Times) //And each time of that class.
            {
                if (((time.start <= time2.start) && (time2.start <= time.end)) || ((time2.start <= time.start) && (time.start <= time2.end)))
                {     //Does this time overlap?
                    foreach (char day in time.daylist)
                    { //Is it on the same day?
                        if (time2.daylist.Contains(day))
                        {
                            conflict = true;
                            break;
                        }
                    }
                }
                if (conflict)
                {
                    break;
                }
            }
            if (conflict)
            {
                break;
            }
        }

        return(conflict);
    }
Пример #2
0
 public void Add(Student S, courseinfo C)
 {
     S.Next.Add(C.Coursename);
     S.EnrolledCredits += C.Credit;
     C.Students.Add(S.UserName);
     ++C.Enrolled;
 }
Пример #3
0
 public void Add(Student S, courseinfo C)
 {
     S.Next.Add(C.Coursename);
     S.EnrolledCredits += C.Credit;
     C.Students.Add(S.UserName);
     ++C.Enrolled;
 }
Пример #4
0
        private void RemoveCourse(courseinfo course)
        {
            foreach (Student stud in StudentList)
            {
                foreach (string course2 in stud.Next)
                {
                    if (course.Coursename == course2)
                    {
                        stud.Next.Remove(course2);
                    }
                }
            }

            foreach (Faculty prof in FacultyList)
            {
                foreach (string course2 in prof.Next)
                {
                    if (course.Coursename == course2)
                    {
                        prof.Next.Remove(course2);
                    }
                }
            }

            foreach (courseinfo course2 in NextCourses)
            {
                if (course.Coursename == course2.Coursename)
                {
                    NextCourses.Remove(course2);
                }
            }
        }
Пример #5
0
        private void ChangeInstructor(courseinfo course, Faculty prof)
        {
            foreach (Faculty oldProf in FacultyList)
                oldProf.Next.Remove(course.Coursename);

            course.Instructor = prof.UserName;
            prof.Next.Add(course.Coursename);
        }
Пример #6
0
 private void RemoveStudentfromCourse(Student S, courseinfo C)
 {
     S.Next.Remove(C.Coursename);
     S.EnrolledCredits -= C.Credit;
     C.Students.Remove(S.UserName);
     --C.Enrolled;
     MessageBox.Show("Student is no longer registered for " + C.Coursename + ".");
 }
Пример #7
0
 public void RemoveStudentfromCourse(Student S, courseinfo C)
 {
     S.Next.Remove(C.Coursename);
     S.EnrolledCredits -= C.Credit;
     C.Students.Remove(S.UserName);
     C.Enrolled--;
     MessageBox.Show("You are no longer registered for " + C.Coursename + ".");
 }
Пример #8
0
        private void ChangeInstructor(courseinfo course, Faculty prof)
        {
            foreach (Faculty oldProf in FacultyList)
            {
                oldProf.Next.Remove(course.Coursename);
            }

            course.Instructor = prof.UserName;
            prof.Next.Add(course.Coursename);
        }
Пример #9
0
    public errorReturn unenrollCourse(ref courseinfo course, ref VStudent student)
    {
        VStudent    dummy = new VStudent(this);
        errorReturn eN    = base.unenrollCourse(ref course, ref dummy);

        Next      = dummy.Next;
        Conflicts = dummy.Conflicts;

        return(eN);
    }
Пример #10
0
    //A student may only enroll itself.
    // super kludgy, but it should do the job.
    public List <errorReturn> enrollCourse(ref courseinfo course, ref VStudent student)
    {
        VStudent           dummy   = new VStudent(this);
        List <errorReturn> errlist = base.enrollCourse(ref course, ref dummy);

        Next      = dummy.Next;
        Conflicts = dummy.Conflicts;

        return(errlist);
    }
Пример #11
0
    public virtual errorReturn unenrollCourse(ref courseinfo course, ref VStudent student)
    {
        errorReturn er;

        //if (this.status == "faculty")
        //{
        //    //Depending on Future specs, we still might want to test for this.
        //}
        // shouldn't be needed
        //if ((this.status == "student") || (this.usertype == VType.student))
        //{
        //    //Is the user doing the edit the student being registered?
        //    if (this != student)
        //    {
        //        //We have a very clever student.
        //        er.wasError = true;
        //        er.errorWas = "diffStudent";
        //        return er; //This is one where we might want to kick them out.
        //    }
        //}


        if (!student.Next.Remove(course))
        {
            er.wasError = true;
            er.errorWas = "notenrolled";
            return(er);
            // throw "Unenroll encountered an error. Were you enrolled?" error
        }

        //recheck conflicts
        student.checkConflicts();

        er.wasError = false;
        er.errorWas = "notError";
        return(er);
    }
Пример #12
0
 public bool Equals(courseinfo course)
 {
     return this.Coursename.Substring(0, Coursename.Length - 3) == course.Coursename.Substring(0, course.Coursename.Length - 3);
 }
Пример #13
0
 public bool Equals(courseinfo course)
 {
     return(this.Coursename.Substring(0, Coursename.Length - 3) == course.Coursename.Substring(0, course.Coursename.Length - 3));
 }
Пример #14
0
 public override errorReturn unenrollCourse(ref courseinfo course, ref VStudent student)
 {
     return base.unenrollCourse(ref course,ref student);
 }
Пример #15
0
    public bool isConflict(courseinfo course)
    {
        bool conflict = false;

        foreach (coursetime time in Times)   //Each time the course is offered
        {
            foreach (coursetime time2 in course.Times)     //And each time of that class.
            {
                if (((time.start <= time2.start) && (time2.start <= time.end)) || ((time2.start <= time.start) && (time.start <= time2.end)))
                {   //Does this time overlap?
                    foreach (char day in time.daylist)
                    {   //Is it on the same day?
                        if (time2.daylist.Contains(day))
                        {
                            conflict = true;
                            break;
                        }
                    }
                }
                if (conflict)
                    break;
            }
            if (conflict)
                break;
        }

        return conflict;
    }
Пример #16
0
        public void AddStudenttoCourse(Student S, courseinfo C)
        {
            bool enroll = true;
            List<string> messages = new List<string>();

            foreach (string course in S.Current)
            {
                if (course.Substring(0, course.Length - 3) == C.SecLessName)
                {
                    messages.Add("You've Already Registered for this Course!");
                    enroll = false;
                    break;
                }
            }

            if (C.Enrolled >= C.Seats)
            {
                messages.Add("Class is Full!");
                enroll = false;
            }

            if (S.EnrolledCredits <= 5.0 - C.Credit)
            {
                messages.Add("Trying to Enroll for 5 Credits or More!");
                enroll = false;
            }

            foreach (string req in C.Prereqs)
            {
                bool taken = false;
                foreach (courserecord pastcourse in S.History)
                {
                    if (pastcourse.SecLessName == req)
                    {
                        taken = true;
                        break;
                    }
                }
                foreach (string curcourse in S.Current)
                {
                    if (curcourse.Substring(0, curcourse.Length - 3) == req)
                    {
                        taken = true;
                        break;
                    }
                }
                if (!taken)
                {
                    messages.Add("You Don't Meet the Prerequisites!");
                    enroll = false;
                    break;
                }
            }

            bool retake = false;
            foreach (string course in S.Current)
            {
                if (C.SecLessName == course.Substring(0, course.Length - 3))
                {
                    retake = true;
                    break;
                }
            }
            //foreach (courserecord course in S.Current) CHANGED HERE
            foreach (courserecord course in S.History)
            {
                if (course.Term == "S13")
                    if (C.SecLessName == course.SecLessName)
                    {
                        retake = true;
                        break;
                    }
            }
            if (retake)
                messages.Add("You're Retaking this Class!");

            foreach (courseinfo Course in coursesNextYear)    //Compare to each already added class
            {
                bool iscnflct = false;
                if (S.Next.Contains(Course.Coursename))
                {
                    foreach (coursetime time in C.Times)   //Each time the course is offered
                    {
                        foreach (coursetime time2 in Course.Times)     //And each time of that class.
                        {
                            if (((time.start <= time2.start) && (time2.start <= time.end)) || ((time2.start <= time.start) && (time.start <= time2.end)))
                            {   //Does this time overlap?
                                foreach (char day in time.daylist)
                                {   //Is it on the same day?
                                    if (time2.daylist.Contains(day))
                                    {   //Throw warning message.
                                        messages.Add("Conflicts with Another Class!");
                                        iscnflct = true;
                                        break;
                                    }
                                }
                                if (iscnflct)
                                    break;
                            }
                        }
                        if (iscnflct)
                            break;
                    }
                    if (iscnflct)
                        break;
                }
            }

            if (enroll)
            {
                Add(S, C);
                messages.Add("Successfully Enrolled in Class.");
            }
            else messages.Add("Can't Enroll in Class.");

            string text = "";
            foreach (string str in messages)
                text += str + '\n';
            MessageBox.Show(text);
        }
Пример #17
0
 //An admin may add any student to any class.
 public override List<errorReturn> enrollCourse(ref courseinfo course, ref VStudent student)
 {
     return base.enrollCourse(ref course,ref student);
 }
Пример #18
0
    public errorReturn unenrollCourse(ref courseinfo course, ref VStudent student)
    {
        VStudent dummy = new VStudent(this);
        errorReturn eN = base.unenrollCourse(ref course, ref dummy);

        Next = dummy.Next;
        Conflicts = dummy.Conflicts;

        return eN;
    }
Пример #19
0
 //An admin may add any student to any class.
 public override List <errorReturn> enrollCourse(ref courseinfo course, ref VStudent student)
 {
     return(base.enrollCourse(ref course, ref student));
 }
Пример #20
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            // our "databases"
            List <Admin>      AdminList   = new List <Admin>();
            List <Faculty>    FacultyList = new List <Faculty>();
            List <Student>    StudentList = new List <Student>();
            List <courseinfo> NextCourses = new List <courseinfo>();
            List <courseinfo> PrevCourses = new List <courseinfo>();

            string line    = "Yes";
            string nxtterm = "S13";

            while (line != null)
            {
                try
                {
                    string username;
                    string firstname;
                    string lastname;
                    string middlename;
                    string status;
                    string password;


                    StreamReader freader = new StreamReader("UserInput.txt");

                    line = freader.ReadLine();
                    if (line != null)
                    {
                        username   = line.Substring(0, 10).Trim();
                        password   = line.Substring(10, 10).Trim();
                        firstname  = line.Substring(20, 15).Trim();
                        middlename = line.Substring(35, 15).Trim();
                        lastname   = line.Substring(50, 15).Trim();
                        status     = line.Substring(65).Trim();
                        if (status == "Admin")
                        {
                            Admin A = new Admin(username, password,
                                                firstname, middlename, lastname, status);
                            AdminList.Add(A);
                        }
                        else if (status == "Faculty")
                        {
                            Faculty F = new Faculty(username, password,
                                                    firstname, middlename, lastname, status);
                            FacultyList.Add(F);
                        }
                        else
                        {
                            Student S = new Student(username, password, firstname,
                                                    middlename, lastname, status);
                            StudentList.Add(S);
                        }
                    }
                    else
                    {
                        freader.Close();
                        //button1.Visible = false;
                        //MessageBox.Show("File is now complete.");
                    }
                }

                catch (EndOfStreamException)
                { }
            }


            line = "Yes";
            while (line != null)
            {
                try
                {
                    string            coursename;
                    string            coursetitle;
                    string            instructor;
                    double            credit;
                    int               seats;
                    int               timeblocks;
                    List <coursetime> times = new List <coursetime>();

                    StreamReader sr = new StreamReader("ClassInput.txt");
                    {
                        while (line != null)
                        {
                            coursename  = line.Substring(0, 11).Trim();
                            coursetitle = line.Substring(11, 16).Trim();
                            instructor  = line.Substring(27, 11).Trim();
                            credit      = double.Parse(line.Substring(38, 5).Trim());
                            seats       = int.Parse(line.Substring(43, 4).Trim());
                            timeblocks  = int.Parse(line.Substring(47, 2).Trim());
                            string timeline = line.Substring(49).Trim();
                            int    numTimes = timeblocks;

                            for (int i = 0; i < numTimes; i++)
                            {
                                int        begin = (0 + (i * 5));
                                coursetime c     = new coursetime(timeline.Substring(begin, 5));
                                times.Add(c);
                            }

                            courseinfo myCourse = new courseinfo(coursename, coursetitle, instructor,
                                                                 credit, seats, times);
                            NextCourses.Add(myCourse);

                            //MessageBox.Show("There are " + Courses.Count + " Courses.");



                            line = sr.ReadLine();
                        }
                        sr.Close();
                        //MessageBox.Show("File is now complete.");
                    }
                }
                catch
                {
                    MessageBox.Show("There was an Error");
                }
            }
            //add advisees/schedule to faculty
            foreach (Faculty prof in FacultyList)
            {
                foreach (Student stud in StudentList)
                {
                    if (prof.UserName == stud.Status)
                    {
                        prof.Advisees.Add(stud.UserName);
                    }
                }
                foreach (courseinfo course in NextCourses)
                {
                    if (prof.UserName == course.Instructor)
                    {
                        prof.Next.Add(course.Coursename);
                    }
                }
            }

            line = "Yes";

            try
            {
                string username;
                int    numcourses;
                string coursename;
                string term;
                double credit;
                string grade;

                StreamReader sr = new StreamReader("HistoryInput.txt");
                while (!sr.EndOfStream)
                {
                    line     = sr.ReadLine();
                    username = line.Substring(0, 10);
                    line.Remove(0, 10);
                    line       = line.TrimStart();
                    numcourses = int.Parse(line.Substring(0, 2));
                    line.Remove(0, 2);
                    line = line.TrimStart();

                    // find index of student
                    int undx = 0;
                    foreach (Student stud in StudentList)
                    {
                        if (stud.UserName == username)
                        {
                            break;
                        }
                        ++undx;
                    }

                    for (int i = 0; i < numcourses; ++i)
                    {
                        coursename = line.Substring(0, 10);
                        line.Remove(0, 10);
                        line = line.TrimStart();
                        term = line.Substring(0, 3);
                        line.Remove(0, 3);
                        line   = line.TrimStart();
                        credit = double.Parse(line.Substring(0, 4));
                        line.Remove(0, 4);
                        line  = line.TrimStart();
                        grade = line.Substring(0, 3);
                        line.Remove(0, 3);
                        line = line.TrimStart();


                        // fixed maybe?
                        if (grade.Contains("N"))
                        {
                            if (term == nxtterm)
                            {
                                StudentList[undx].Current.Add(coursename);
                            }
                            // Users[undx].Add(new courserecord(coursename, term, credit, grade);
                            else
                            {
                                StudentList[undx].Next.Add(coursename);
                            }
                        }
                        else
                        {
                            StudentList[undx].History.Add(new courserecord(coursename, term, credit, grade));
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Invalid History Input File");
                Console.WriteLine(e.Message);
            }

            foreach (courseinfo course in NextCourses)
            {
                foreach (Student stud in StudentList)
                {
                    if (stud.Next.Contains(course.Coursename))
                    {
                        stud.EnrolledCredits += course.Credit;
                        course.Students.Add(stud.UserName);
                        ++course.Enrolled;
                    }
                }
            }


            // read course prereq database
            line = "Yes";
            try
            {
                string coursename;
                int    numprereq;
                string prereq;

                StreamReader sr = new StreamReader("PrereqInput.txt");
                while (!sr.EndOfStream)
                {
                    line = sr.ReadLine();

                    coursename = line.Substring(0, 7);
                    line.Remove(0, 7);
                    line      = line.TrimStart();
                    numprereq = int.Parse(line.Substring(0, 2));
                    line.Remove(0, 2);
                    line = line.TrimStart();

                    int cndx = 0;
                    foreach (courseinfo course in NextCourses)
                    {
                        if (course.SecLessName == coursename)
                        {
                            break;
                        }
                        ++cndx;
                    }

                    for (int i = 0; i < numprereq; ++i)
                    {
                        prereq = line.Substring(0, 7);
                        line.Remove(0, 7);
                        line = line.TrimStart();

                        NextCourses[cndx].Prereqs.Add(prereq);
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Invalid Prereq Input File");
                Console.WriteLine(e.Message);
            }

            //LAUNCH FORMS AND THINGS HERE
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new LoginForm(AdminList, FacultyList, StudentList, NextCourses, PrevCourses));
        }
Пример #21
0
    //A student may only enroll itself.
    // super kludgy, but it should do the job.
    public List<errorReturn> enrollCourse(ref courseinfo course, ref VStudent student)
    {
        VStudent dummy = new VStudent(this);
        List<errorReturn> errlist = base.enrollCourse(ref course, ref dummy);

        Next = dummy.Next;
        Conflicts = dummy.Conflicts;

        return errlist;
    }
Пример #22
0
    //Returns a list of errorReturns. Warnings are errorList objects with wasError = false;
    //Returns an empty list if there were neither errors nor warnings.
    //Test for success by List<errorReturn> i = enrollCourse(c,s); ((i.Count == 0) || (i[0].wasError == false));
    public virtual List <errorReturn> enrollCourse(ref courseinfo course, ref VStudent student)
    {
        List <errorReturn> errlist  = new List <errorReturn>();
        List <errorReturn> warnlist = new List <errorReturn>();
        errorReturn        eN;             // Always use this to add errors and warnings.

        if (student.Next.Contains(course)) //Is the student already registered for this course? Return an error.
        {
            if (course.Students.Contains(student))
            {
                eN.wasError = true;
                eN.errorWas = "AlreadyHere";
                errlist.Add(eN);
                return(errlist);
            }
            else
            {
                student.Next.Remove(course);    //if out of sync, course has priority
            }
        }

        //Generate list of Errors.
        if (course.isFull()) //Is the course full? Return an error.
        {
            eN.wasError = true;
            eN.errorWas = "CourseIsFull";
            errlist.Add(eN);
        }

        if ((student.enrolledCredits() + course.Credit) > 5.0) //Would this put the student over 5.0 credits?
        {
            eN.errorWas = ">5.0";
            if (status == "admin")                   //If Admin, warn, but allow.
            {
                eN.wasError = false;
                warnlist.Add(eN);
            }
            else                                                //If not Admin, return error.
            {
                eN.wasError = true;
                errlist.Add(eN);
            }
        }

        if (errlist.Count == 0)
        {                                                       //Generate list of Warnings.
            //Warnings for class conflict
            foreach (courseinfo course2 in student.Next)        //Compare to each already added class
            {
                foreach (coursetime time in course.Times)       //Each time the course is offered
                {
                    foreach (coursetime time2 in course2.Times) //And each time of that class.
                    {
                        bool iscnflct = false;
                        if (((time.start <= time2.start) && (time2.start <= time.end)) || ((time2.start <= time.start) && (time.start <= time2.end)))
                        {         //Does this time overlap?
                            foreach (char day in time.days)
                            {     //Is it on the same day?
                                if (time2.days.Contains(day))
                                { //Throw warning message.
                                    eN.wasError = false;
                                    eN.errorWas = "!" + course2.Coursetitle;
                                    warnlist.Add(eN);
                                    if (!student.Conflicts.Contains(course.Coursetitle))
                                    {
                                        student.Conflicts.Add(course.Coursetitle);
                                    }
                                    if (!student.Conflicts.Contains(course2.Coursetitle))
                                    {
                                        student.Conflicts.Add(course2.Coursetitle);
                                    }
                                    iscnflct = true;
                                    break;
                                }
                            }
                            if (iscnflct)
                            {
                                break;
                            }
                        }
                    }
                }
            }

            // Hopefully interface handles this now?
            bool repeat = false;
            // are they currently taking it?
            foreach (var course2 in student.Current)
            {
                if (course.Equals(course2))
                {
                    repeat = true;
                    break;
                }
            }
            // have they taken it before?
            if (!repeat)
            {
                foreach (var course2 in student.History)
                {
                    if (course.Equals(course2))
                    {
                        repeat = true;
                        break;
                    }
                }
            }
            // warn if they have taken it
            if (repeat)
            {
                eN.wasError = false;
                eN.errorWas = "?" + course.Coursetitle;
                warnlist.Add(eN);
            }

            //Beyond here, no new errors and no new warnings.
            student.Next.Add(course);          //The student has a course.
            course.enrollStudent(ref student); //The course has a student.
            //Otherwise, we'll return the list of warnings. The only way to have returned an empty list is
            //If there are no warnings.
            return(warnlist);
        }
        else
        {
            return(errlist);
        }
    }
Пример #23
0
        private void RemoveCourse(courseinfo course)
        {
            foreach (Student stud in StudentList)
            {
                foreach (string course2 in stud.Next)
                {
                    if (course.Coursename == course2)
                        stud.Next.Remove(course2);
                }
            }

            foreach (Faculty prof in FacultyList)
            {
                foreach (string course2 in prof.Next)
                {
                    if (course.Coursename == course2)
                        prof.Next.Remove(course2);
                }
            }

            foreach (courseinfo course2 in NextCourses)
            {
                if (course.Coursename == course2.Coursename)
                    NextCourses.Remove(course2);
            }
        }
Пример #24
0
 private void RemoveStudentfromCourse(Student S, courseinfo C)
 {
     S.Next.Remove(C.Coursename);
     S.EnrolledCredits -= C.Credit;
     C.Students.Remove(S.UserName);
     --C.Enrolled;
     MessageBox.Show("Student is no longer registered for " + C.Coursename + ".");
 }
Пример #25
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            // our "databases"
            List<Admin> AdminList = new List<Admin>();
            List<Faculty> FacultyList = new List<Faculty>();
            List<Student> StudentList = new List<Student>();
            List<courseinfo> NextCourses = new List<courseinfo>();
            List<courseinfo> PrevCourses = new List<courseinfo>();

            string line = "Yes";
            string nxtterm = "S13";

            while (line != null)
            {
            try
            {
                string username;
                string firstname;
                string lastname;
                string middlename;
                string status;
                string password;

                StreamReader freader = new StreamReader("UserInput.txt");

                line = freader.ReadLine();
                if (line != null)
                {
                    username = line.Substring(0, 10).Trim();
                    password = line.Substring(10, 10).Trim();
                    firstname = line.Substring(20, 15).Trim();
                    middlename = line.Substring(35, 15).Trim();
                    lastname = line.Substring(50, 15).Trim();
                    status = line.Substring(65).Trim();
                    if (status == "Admin")
                    {
                        Admin A = new Admin(username, password,
                            firstname, middlename, lastname, status);
                        AdminList.Add(A);
                    }
                    else if (status == "Faculty")
                    {
                        Faculty F = new Faculty(username, password,
                            firstname, middlename, lastname, status);
                        FacultyList.Add(F);
                    }
                    else
                    {
                        Student S = new Student(username, password, firstname,
                            middlename, lastname, status);
                        StudentList.Add(S);
                    }
                }
                else
                {
                    freader.Close();
                    //button1.Visible = false;
                    //MessageBox.Show("File is now complete.");
                }

            }

            catch (EndOfStreamException)
            { }

            }

            line = "Yes";
                    while (line != null)
                    {

                        try
                        {
                            string coursename;
                            string coursetitle;
                            string instructor;
                            double credit;
                            int seats;
                            int timeblocks;
                            List<coursetime> times = new List<coursetime>();

                            StreamReader sr = new StreamReader("ClassInput.txt");
                            {
                                while (line != null)
                                {
                                    coursename = line.Substring(0, 11).Trim();
                                    coursetitle = line.Substring(11, 16).Trim();
                                    instructor = line.Substring(27, 11).Trim();
                                    credit = double.Parse(line.Substring(38, 5).Trim());
                                    seats = int.Parse(line.Substring(43, 4).Trim());
                                    timeblocks = int.Parse(line.Substring(47, 2).Trim());
                                    string timeline = line.Substring(49).Trim();
                                    int numTimes = timeblocks;

                                    for (int i = 0; i < numTimes; i++)
                                    {
                                        int begin = (0 + (i * 5));
                                        coursetime c = new coursetime(timeline.Substring(begin, 5));
                                        times.Add(c);
                                    }

                                    courseinfo myCourse = new courseinfo(coursename, coursetitle, instructor,
                                        credit, seats, times);
                                    NextCourses.Add(myCourse);

                                    //MessageBox.Show("There are " + Courses.Count + " Courses.");

                                    line = sr.ReadLine();
                                }
                                sr.Close();
                                //MessageBox.Show("File is now complete.");

                            }
                        }
                        catch
                        {
                            MessageBox.Show("There was an Error");
                        }
                    }
                    //add advisees/schedule to faculty
                    foreach (Faculty prof in FacultyList)
                    {
                        foreach (Student stud in StudentList)
                        {
                            if (prof.UserName == stud.Status)
                                prof.Advisees.Add(stud.UserName);
                        }
                        foreach (courseinfo course in NextCourses)
                        {
                            if (prof.UserName == course.Instructor)
                                prof.Next.Add(course.Coursename);
                        }
                    }

                    line = "Yes";

                    try
                    {
                        string username;
                        int numcourses;
                        string coursename;
                        string term;
                        double credit;
                        string grade;

                        StreamReader sr = new StreamReader("HistoryInput.txt");
                            while (!sr.EndOfStream)
                            {
                                line = sr.ReadLine();
                                username = line.Substring(0, 10);
                                line.Remove(0, 10);
                                line = line.TrimStart();
                                numcourses = int.Parse(line.Substring(0, 2));
                                line.Remove(0, 2);
                                line = line.TrimStart();

                                // find index of student
                                int undx = 0;
                                foreach (Student stud in StudentList)
                                {
                                    if (stud.UserName == username)
                                        break;
                                    ++undx;
                                }

                                for (int i = 0; i < numcourses; ++i)
                                {
                                    coursename = line.Substring(0, 10);
                                    line.Remove(0, 10);
                                    line = line.TrimStart();
                                    term = line.Substring(0, 3);
                                    line.Remove(0, 3);
                                    line = line.TrimStart();
                                    credit = double.Parse(line.Substring(0, 4));
                                    line.Remove(0, 4);
                                    line = line.TrimStart();
                                    grade = line.Substring(0, 3);
                                    line.Remove(0, 3);
                                    line = line.TrimStart();

                                    // fixed maybe?
                                    if (grade.Contains("N"))
                                    {
                                        if (term == nxtterm)
                                            StudentList[undx].Current.Add(coursename);
                                        // Users[undx].Add(new courserecord(coursename, term, credit, grade);
                                        else StudentList[undx].Next.Add(coursename);
                                    }
                                    else StudentList[undx].History.Add(new courserecord(coursename, term, credit, grade));
                                }
                            }
                        }
                    catch (Exception e)
                    {
                        Console.WriteLine("Invalid History Input File");
                        Console.WriteLine(e.Message);
                    }

                    foreach (courseinfo course in NextCourses)
                    {
                        foreach (Student stud in StudentList)
                        {
                            if (stud.Next.Contains(course.Coursename))
                            {
                                stud.EnrolledCredits += course.Credit;
                                course.Students.Add(stud.UserName);
                                ++course.Enrolled;
                            }
                        }
                    }

                    // read course prereq database
                    line = "Yes";
                    try
                    {
                        string coursename;
                        int numprereq;
                        string prereq;

                        StreamReader sr = new StreamReader("PrereqInput.txt");
                            while (!sr.EndOfStream)
                            {
                                line = sr.ReadLine();

                                coursename = line.Substring(0, 7);
                                line.Remove(0, 7);
                                line = line.TrimStart();
                                numprereq = int.Parse(line.Substring(0, 2));
                                line.Remove(0, 2);
                                line = line.TrimStart();

                                int cndx = 0;
                                foreach (courseinfo course in NextCourses)
                                {
                                    if (course.SecLessName == coursename)
                                        break;
                                    ++cndx;
                                }

                                for (int i = 0; i < numprereq; ++i)
                                {
                                    prereq = line.Substring(0, 7);
                                    line.Remove(0, 7);
                                    line = line.TrimStart();

                                    NextCourses[cndx].Prereqs.Add(prereq);
                                }
                            }
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("Invalid Prereq Input File");
                        Console.WriteLine(e.Message);
                    }

                    //LAUNCH FORMS AND THINGS HERE
                    Application.EnableVisualStyles();
                    Application.SetCompatibleTextRenderingDefault(false);
                    Application.Run(new LoginForm(AdminList, FacultyList, StudentList, NextCourses, PrevCourses));
        }
Пример #26
0
    //Returns a list of errorReturns. Warnings are errorList objects with wasError = false;
    //Returns an empty list if there were neither errors nor warnings.
    //Test for success by List<errorReturn> i = enrollCourse(c,s); ((i.Count == 0) || (i[0].wasError == false));
    public virtual List<errorReturn> enrollCourse(ref courseinfo course, ref VStudent student)
    {
        List<errorReturn> errlist = new List<errorReturn>();
        List<errorReturn> warnlist = new List<errorReturn>();
        errorReturn eN; // Always use this to add errors and warnings.

        if (student.Next.Contains(course)) //Is the student already registered for this course? Return an error.
        {
            if (course.Students.Contains(student))
            {
                eN.wasError = true;
                eN.errorWas = "AlreadyHere";
                errlist.Add(eN);
                return errlist;
            }
            else student.Next.Remove(course);   //if out of sync, course has priority
        }

        //Generate list of Errors.
        if (course.isFull()) //Is the course full? Return an error.
        {
            eN.wasError = true;
            eN.errorWas = "CourseIsFull";
            errlist.Add(eN);
        }

        if ((student.enrolledCredits() + course.Credit) > 5.0) //Would this put the student over 5.0 credits?
        {
            eN.errorWas = ">5.0";
            if (status == "admin")                   //If Admin, warn, but allow.
            {
                eN.wasError = false;
                warnlist.Add(eN);
            }
            else                                                //If not Admin, return error.
            {
                eN.wasError = true;
                errlist.Add(eN);
            }
        }

        if (errlist.Count == 0)
        {   //Generate list of Warnings.

            //Warnings for class conflict
            foreach (courseinfo course2 in student.Next)    //Compare to each already added class
            {
                foreach (coursetime time in course.Times)   //Each time the course is offered
                {
                    foreach (coursetime time2 in course2.Times)     //And each time of that class.
                    {
                        bool iscnflct = false;
                        if (((time.start <= time2.start) && (time2.start <= time.end)) || ((time2.start <= time.start) && (time.start <= time2.end)))
                        {   //Does this time overlap?
                            foreach (char day in time.days)
                            {   //Is it on the same day?
                                if (time2.days.Contains(day))
                                {   //Throw warning message.
                                    eN.wasError = false;
                                    eN.errorWas = "!" + course2.Coursetitle;
                                    warnlist.Add(eN);
                                    if (!student.Conflicts.Contains(course.Coursetitle))
                                        student.Conflicts.Add(course.Coursetitle);
                                    if (!student.Conflicts.Contains(course2.Coursetitle))
                                        student.Conflicts.Add(course2.Coursetitle);
                                    iscnflct = true;
                                    break;
                                }
                            }
                            if (iscnflct)
                                break;
                        }
                    }
                }
            }

            // Hopefully interface handles this now?
            bool repeat = false;
            // are they currently taking it?
            foreach(var course2 in student.Current)
            {
                if(course.Equals(course2))
                {
                    repeat = true;
                    break;
                }
            }
            // have they taken it before?
            if (!repeat)
            {
                foreach (var course2 in student.History)
                {
                    if (course.Equals(course2))
                    {
                        repeat = true;
                        break;
                    }
                }
            }
            // warn if they have taken it
            if (repeat)
            {
                eN.wasError = false;
                eN.errorWas = "?" + course.Coursetitle;
                warnlist.Add(eN);
            }

            //Beyond here, no new errors and no new warnings.
            student.Next.Add(course);       //The student has a course.
            course.enrollStudent(ref student);   //The course has a student.
            //Otherwise, we'll return the list of warnings. The only way to have returned an empty list is
            //If there are no warnings.
            return warnlist;
        }
        else return errlist;
    }
Пример #27
0
 public override errorReturn unenrollCourse(ref courseinfo course, ref VStudent student)
 {
     return(base.unenrollCourse(ref course, ref student));
 }
Пример #28
0
    public virtual errorReturn unenrollCourse(ref courseinfo course, ref VStudent student)
    {
        errorReturn er;
        //if (this.status == "faculty")
        //{
        //    //Depending on Future specs, we still might want to test for this.
        //}
        // shouldn't be needed
        //if ((this.status == "student") || (this.usertype == VType.student))
        //{
        //    //Is the user doing the edit the student being registered?
        //    if (this != student)
        //    {
        //        //We have a very clever student.
        //        er.wasError = true;
        //        er.errorWas = "diffStudent";
        //        return er; //This is one where we might want to kick them out.
        //    }
        //}

        if (!student.Next.Remove(course))
        {
            er.wasError = true;
            er.errorWas = "notenrolled";
            return er;
            // throw "Unenroll encountered an error. Were you enrolled?" error
        }

        //recheck conflicts
        student.checkConflicts();

        er.wasError = false;
        er.errorWas = "notError";
        return er;
    }
Пример #29
0
        public void AddStudenttoCourse(Student S, courseinfo C)
        {
            bool          enroll   = true;
            List <string> messages = new List <string>();

            foreach (string course in S.Current)
            {
                if (course.Substring(0, course.Length - 3) == C.SecLessName)
                {
                    messages.Add("You've Already Registered for this Course!");
                    enroll = false;
                    break;
                }
            }

            if (C.Enrolled >= C.Seats)
            {
                messages.Add("Class is Full!");
                enroll = false;
            }

            if (S.EnrolledCredits <= 5.0 - C.Credit)
            {
                messages.Add("Trying to Enroll for 5 Credits or More!");
                enroll = false;
            }

            foreach (string req in C.Prereqs)
            {
                bool taken = false;
                foreach (courserecord pastcourse in S.History)
                {
                    if (pastcourse.SecLessName == req)
                    {
                        taken = true;
                        break;
                    }
                }
                foreach (string curcourse in S.Current)
                {
                    if (curcourse.Substring(0, curcourse.Length - 3) == req)
                    {
                        taken = true;
                        break;
                    }
                }
                if (!taken)
                {
                    messages.Add("You Don't Meet the Prerequisites!");
                    enroll = false;
                    break;
                }
            }

            bool retake = false;

            foreach (string course in S.Current)
            {
                if (C.SecLessName == course.Substring(0, course.Length - 3))
                {
                    retake = true;
                    break;
                }
            }
            //foreach (courserecord course in S.Current) CHANGED HERE
            foreach (courserecord course in S.History)
            {
                if (course.Term == "S13")
                {
                    if (C.SecLessName == course.SecLessName)
                    {
                        retake = true;
                        break;
                    }
                }
            }
            if (retake)
            {
                messages.Add("You're Retaking this Class!");
            }

            foreach (courseinfo Course in coursesNextYear)    //Compare to each already added class
            {
                bool iscnflct = false;
                if (S.Next.Contains(Course.Coursename))
                {
                    foreach (coursetime time in C.Times)           //Each time the course is offered
                    {
                        foreach (coursetime time2 in Course.Times) //And each time of that class.
                        {
                            if (((time.start <= time2.start) && (time2.start <= time.end)) || ((time2.start <= time.start) && (time.start <= time2.end)))
                            {         //Does this time overlap?
                                foreach (char day in time.daylist)
                                {     //Is it on the same day?
                                    if (time2.daylist.Contains(day))
                                    { //Throw warning message.
                                        messages.Add("Conflicts with Another Class!");
                                        iscnflct = true;
                                        break;
                                    }
                                }
                                if (iscnflct)
                                {
                                    break;
                                }
                            }
                        }
                        if (iscnflct)
                        {
                            break;
                        }
                    }
                    if (iscnflct)
                    {
                        break;
                    }
                }
            }

            if (enroll)
            {
                Add(S, C);
                messages.Add("Successfully Enrolled in Class.");
            }
            else
            {
                messages.Add("Can't Enroll in Class.");
            }

            string text = "";

            foreach (string str in messages)
            {
                text += str + '\n';
            }
            MessageBox.Show(text);
        }
Пример #30
0
 public void RemoveStudentfromCourse(Student S, courseinfo C)
 {
     S.Next.Remove(C.Coursename);
     S.EnrolledCredits -= C.Credit;
     C.Students.Remove(S.UserName);
     C.Enrolled--;
     MessageBox.Show("You are no longer registered for " + C.Coursename + ".");
 }