// For changing courses. Needs a direct access to user database
 public void changeInstrutor(courseDatabase crsDB, string newInstructor, string oldInstructor, string crsID)
 {
     foreach (faculty fac in facLst)
     {
         bool newI = false;
         bool oldI = false;
         if (!newI)
         {
             if (fac.username.Trim() == newInstructor.Trim())
             {
                 course crs = crsDB.getCourse(crsID);
                 fac.nextSemesterCourses.Add(crs);
                 newI = true;
             }
         }
         if (!oldI)
         {
             if (fac.username.Trim() == oldInstructor.Trim())
             {
                 foreach (course crs in fac.nextSemesterCourses)
                 {
                     if (crs.crsID == crsID.Trim())
                     {
                         fac.nextSemesterCourses.Remove(crs);
                         oldI = true;
                         break;
                     }
                 }
             }
         }
         if (oldI && newI)
         {
             break;
         }
     }
 }
Exemple #2
0
        private void confirmClick(object sender, EventArgs e)
        {
            // Search for missing fields
            if (crsIDBox.Text == "" || titleBox.Text == "" || facDropDown.Text == "" ||
                creditBox.Text == "" || seatBox.Text == "")
            {
                MessageBox.Show("Required fields missing.",
                                "Invalid Input",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                return;
            }

            // Check if there is any time specified
            if (!MA.Checked && !MB.Checked && !TA.Checked && !TB.Checked && !WA.Checked && !WB.Checked &&
                !RA.Checked && !RB.Checked && !FA.Checked && !FB.Checked)
            {
                MessageBox.Show("Specify a time slot.",
                                "Invalid Input",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                return;
            }

            // Day duplicate over multiple time blocks
            if ((MA.Checked && MB.Checked) || (TA.Checked && TB.Checked) || (WA.Checked && WB.Checked) ||
                (RA.Checked && RB.Checked) || (FA.Checked && FB.Checked))
            {
                MessageBox.Show("Cannot have the same day over two slots",
                                "Invalid Input",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                return;
            }

            // Check the presence of starting and ending time.
            if (MA.Checked || TA.Checked || WA.Checked || RA.Checked || FA.Checked)
            {
                if (startingTimeA.Text == "" || endingTimeA.Text == "")
                {
                    MessageBox.Show("Specify the starting and ending time.",
                                    "Invalid input",
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                    return;
                }
            }


            string crsID = crsIDBox.Text;

            // Search for duplicate course ID
            foreach (course crs in crsDB.getCourseList())
            {
                if (crsID.Trim() == crs.crsID)
                {
                    MessageBox.Show("The course ID is already taken.",
                                    "Duplicate",
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                    return;
                }
            }

            string  title      = titleBox.Text.Trim();
            string  instructor = facDropDown.Text.Trim();
            faculty inst       = usrDB.getFacultyList()[0];

            foreach (faculty fac in usrDB.getFacultyList())
            {
                if (fac.fname + " " + fac.lname == instructor)
                {
                    inst = fac;
                    break;
                }
            }
            string credits = creditBox.Text;

            try
            {
                if (Convert.ToSingle(credits) == 0)
                {
                    MessageBox.Show("No credits given.",
                                    "Warning",
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Warning);
                }
            }
            catch
            {
                MessageBox.Show("Credits have to be a number.",
                                "Warning",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                return;
            }

            int seats = 0;

            try
            {
                seats = Convert.ToInt32(seatBox.Text);
            }
            catch
            {
                MessageBox.Show("Seats have to be a number.",
                                "Warning",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                return;
            }

            // Get the course time block
            int dd = 0;

            if (MA.Checked)
            {
                dd += 1;
            }
            if (TA.Checked)
            {
                dd += 2;
            }
            if (WA.Checked)
            {
                dd += 4;
            }
            if (RA.Checked)
            {
                dd += 8;
            }
            if (FA.Checked)
            {
                dd += 16;
            }

            string day = dd.ToString();

            if (day.Length < 2)
            {
                day = "0" + day;
            }

            string timeBlockA = day + UF.utilities.encodeTime(startingTimeA.Text, endingTimeA.Text);


            if (MB.Checked || TB.Checked || WB.Checked || RB.Checked || FB.Checked)
            {
                // Get the course time block
                dd = 0;
                if (MB.Checked)
                {
                    dd += 1;
                }
                if (TB.Checked)
                {
                    dd += 2;
                }
                if (WB.Checked)
                {
                    dd += 4;
                }
                if (RB.Checked)
                {
                    dd += 8;
                }
                if (FB.Checked)
                {
                    dd += 16;
                }

                day = dd.ToString();
                if (day.Length < 2)
                {
                    day = "0" + day;
                }

                string timeBlockB = day + UF.utilities.encodeTime(startingTimeB.Text, endingTimeB.Text);

                List <string> lst = new List <string>();
                lst.Add(timeBlockA);
                lst.Add(timeBlockB);
                crs = new course(crsID, title, inst.username, credits, seats, 2, lst);
            }
            else
            {
                List <string> lst = new List <string>();
                lst.Add(timeBlockA);
                crs = new course(crsID, title, inst.username, credits, seats, 1, lst);
            }
            string message;

            message  = "Course ID : " + crs.crsID + "\n";
            message += "Title : " + crs.title + "\n";
            message += "Instructor : " + crs.instructor + "\n";
            message += "Credits : " + crs.credit.ToString() + "\n";
            message += "Seats : " + crs.seats.ToString() + "\n";
            message += crs.getBlocks() + "\n";
            message += "Are you sure?";
            if (MessageBox.Show(message, "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.No)
            {
                MessageBox.Show("Canceled the creation.", "Cancel", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                this.DialogResult = DialogResult.OK;
                Close();
            }
        }
 public void addCrs(course crs, string filepath)
 {
     crsLst.Add(crs);
 }
Exemple #4
0
 public void dropCrsFromNext(course courseDeleted)
 {
     registeredCrs.Remove(courseDeleted);
 }
Exemple #5
0
 public void addClassToNext(course courseAdded)
 {
     registeredCrs.Add(courseAdded);
 }
Exemple #6
0
 public void removeCrsFromNext(course crs)
 {
     nextSemesterCourses.Remove(crs);
 }
Exemple #7
0
        public validity isValidAdd(course crsBngAdded)
        {
            bool   validAdd       = true;
            bool   warning        = false;
            string warningMessage = "";
            double nextSmstCrd    = 0.00;

            List <classTime> timeBlocksAdding = crsBngAdded.getClassTime();

            // Totals current semester credit & checks if course is already taken this semester
            foreach (course crs in registeredCrs)
            {
                nextSmstCrd += Convert.ToDouble(crs.credit);
                if (crsBngAdded.crsID.Trim().Substring(0, crsBngAdded.crsID.Trim().Length - 3) == crs.crsID.Trim().Substring(0, crs.crsID.Trim().Length - 3))
                {
                    validAdd       = false;
                    warningMessage = "You have already enrolled in this course this semester";
                }


                List <classTime> timeBlocksCurrent = crs.getClassTime();

                foreach (classTime eachCurrentBlock in timeBlocksCurrent)
                {
                    foreach (classTime eachAddingBlock in timeBlocksAdding)
                    {
                        if (eachCurrentBlock.getDays().Intersect(eachAddingBlock.getDays()).Count() != 0)
                        {
                            double startA = eachCurrentBlock.getStartTime();
                            double startB = eachAddingBlock.getStartTime();
                            double endA   = eachCurrentBlock.getEndTime();
                            double endB   = eachAddingBlock.getEndTime();

                            if (!(startA == endB || startB == endA))
                            {
                                if (startA >= startB)
                                {
                                    if (startA <= endB)
                                    {
                                        warning = true;
                                        if (validAdd)
                                        {
                                            warningMessage = "There is a time overlap";
                                        }
                                    }
                                }

                                if (startB >= startA)
                                {
                                    if (startB <= endA)
                                    {
                                        warning = true;
                                        if (validAdd)
                                        {
                                            warningMessage = "There is a time overlap";
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }



            // Checks if total credit for next semester is above 5.00
            if (nextSmstCrd + Convert.ToDouble(crsBngAdded.credit.Trim()) >= 5.00)
            {
                validAdd       = false;
                warningMessage = "You can not enroll in more than 5.00 credits worth of courses";
            }

            // Checks if course has been taken previously
            if (validAdd)
            {
                bool found = false;
                foreach (previousCourse prvCrs in pastCrs)
                {
                    if (prvCrs.crsID.Trim().Substring(0, prvCrs.crsID.Trim().Length - 3) == crsBngAdded.crsID.Trim().Substring(0, crsBngAdded.crsID.Trim().Length - 3))
                    {
                        warning = true;
                        found   = true;
                        if (validAdd)
                        {
                            warningMessage = "You have already taken this course previously";
                        }
                    }
                }
                if (!found)
                {
                    foreach (previousCourse pcrs in currentCrs)
                    {
                        if (pcrs.crsID.Trim().Substring(0, pcrs.crsID.Trim().Length - 3) == crsBngAdded.crsID.Trim().Substring(0, crsBngAdded.crsID.Trim().Length - 3))
                        {
                            warning = true;
                            if (validAdd)
                            {
                                warningMessage = "You are taking this course this semester.";
                            }
                        }
                    }
                }
            }

            //check number of seats avaialble
            if (crsBngAdded.seats == 0)
            {
                validAdd       = false;
                warningMessage = "There are no seats available for the class";
            }

            validity returningVal = new validity(validAdd, warning, warningMessage);

            return(returningVal);
        }
Exemple #8
0
        // Event handlers
        private void addCrsClick(object sender, EventArgs e)
        {
            int count = addCrsLst.Count;

            if (count == 0)
            {
                MessageBox.Show("Select classes",
                                "No class selected",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
            }
            else
            {
                foreach (string crsID in addCrsLst)
                {
                    Dictionary <string, float> gradeDict = new Dictionary <string, float>()
                    {
                        { "A", 4.0f },
                        { "A-", 3.7f },
                        { "B+", 3.3f },
                        { "B", 3.0f },
                        { "B-", 2.7f },
                        { "C+", 2.3f },
                        { "C", 2.0f },
                        { "C-", 1.7f },
                        { "D+", 1.3f },
                        { "D", 1.0f },
                        { "D-", 0.7f }
                    };
                    course        crs       = crsDB.getCourse(crsID);
                    bool          preReq    = true;
                    List <string> preReqLst = crs.preReqLst;
                    foreach (string courseID in preReqLst)
                    {
                        bool temp = false;
                        foreach (previousCourse pcrs in std.pastCrs)
                        {
                            if (courseID == pcrs.crsID.Substring(0, courseID.Length) && gradeDict.ContainsKey(pcrs.grade))
                            {
                                temp = true;
                                break;
                            }
                        }
                        if (!temp)
                        {
                            foreach (previousCourse pcrs in std.currentCrs)
                            {
                                if (courseID == pcrs.crsID.Substring(0, courseID.Length))
                                {
                                    temp = true;
                                    break;
                                }
                            }
                            if (!temp)
                            {
                                preReq = false;
                                break;
                            }
                        }
                    }
                    if (!preReq)
                    {
                        MessageBox.Show("You're missing prerequisites.", "Requirement", MessageBoxButtons.OK,
                                        MessageBoxIcon.Error);
                        return;
                    }
                    validity v = std.isValidAdd(crs);
                    if (v.valid)
                    {
                        if (v.warning)
                        {
                            MessageBox.Show(crsID + "\n" + v.message, "Warning",
                                            MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        }
                        // Add the course to the student
                        usrDB.addCrsToStd(crsID, "S15", ref crsDB, std);

                        // Update the course list and student schedule
                        foreach (DataGridViewRow row in crsLst.Rows)
                        {
                            if (row.Cells["Course ID"].Value.ToString().ToString() == crsID)
                            {
                                if (row.Visible)
                                {
                                    crs = crsDB.getCourse(crsID);
                                    row.Cells["Seats"].Value = crs.seats + " / " + crs.maxSeats;
                                    DataTable table = (DataTable)stdSch.DataSource;
                                    table.Rows.Add(crs.crsID, crs.title, crs.instructor, crs.credit, crs.getBlocks());
                                    break;
                                }
                            }
                        }
                    }
                    else
                    {
                        MessageBox.Show(crsID + "\n" + v.message + "\n" + "The course was not added.", "Invalid add",
                                        MessageBoxButtons.OK, MessageBoxIcon.Error);
                        continue;
                    }
                }

                crsLst.AutoSizeColumnsMode       = DataGridViewAutoSizeColumnsMode.None;
                crsLst.AutoSizeColumnsMode       = DataGridViewAutoSizeColumnsMode.AllCells;
                crsLst.DefaultCellStyle.WrapMode = DataGridViewTriState.True;
                int width = crsLst.Columns["Schedule"].GetPreferredWidth(DataGridViewAutoSizeColumnMode.AllCells, true);
                crsLst.Columns["Schedule"].AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
                crsLst.AutoSizeRowsMode          = DataGridViewAutoSizeRowsMode.DisplayedCells;
                crsLst.Columns["Schedule"].Width = width;

                crsLst.ClearSelection();
                for (int i = 0; i < crsLst.Rows.Count; i++)
                {
                    crsLst.Rows[i].Cells["Add"].Value = null;
                }
                addCrsLst.Clear();
                MessageBox.Show("The process completed.",
                                "Done",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Information);
            }
        }