コード例 #1
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);
        }
コード例 #2
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);
            }
        }