コード例 #1
0
ファイル: VUser.cs プロジェクト: TheBuckmaster/Db_Repo
    //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;
    }
コード例 #2
0
ファイル: VUser.cs プロジェクト: TheBuckmaster/Db_Repo
    //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);
        }
    }