コード例 #1
0
        private void   cmdGo_Click(object sender, EventArgs e)
        {
            try
            {
                string id      = GetString(txtCourseID);
                string name    = GetString(txtCourseName);
                byte   units   = 0;
                NList  prereqs = new NList();

                if (!Byte.TryParse(GetString(txtCourseUnits), out units))
                {
                    units = 0;
                }

                foreach (object course in lbxPrereqs.Items)
                {
                    prereqs.Append((Course)course);
                }

                Course cs = new Course(id,
                                       name,
                                       units,
                                       cbxFall.Checked,
                                       cbxWinter.Checked,
                                       cbxSpring.Checked,
                                       cbxSummer.Checked,
                                       prereqs,
                                       null);

                mainDB.Add(id, cs);
                mainDB.SaveDB();
                mainDB.PopulateListBox(lbxCList);
            }
            catch (Exception ex)
            {
                MessageBox.Show(String.Format("Error creating course. {0}", ex.Message));
            }
        }
コード例 #2
0
        private void AddCourse(Course course, CourseDB term, ListBox lbx)
        {
            NList        iter = course.Prereqs.Copy();
            AcademicYear ay;
            Course       cs;
            bool         found;

            // Check previous years for prereqs
            for (int i = 0; i < yearIndex; ++i)
            {
                ay = plan[i];

                for (iter.MoveFront(); iter.Index >= 0; iter.MoveNext())
                {
                    cs    = (Course)iter.Get();
                    found = ay.Fall.ContainsKey(cs.CourseID) || ay.Winter.ContainsKey(cs.CourseID) || ay.Spring.ContainsKey(cs.CourseID) || ay.Summer.ContainsKey(cs.CourseID);

                    if (found)
                    {
                        iter.Delete();
                    }
                }
            }

            ay = plan[yearIndex];

            // Check current year for prereqs
            for (iter.MoveFront(); iter.Index >= 0; iter.MoveNext())
            {
                cs = (Course)iter.Get();

                if (term == ay.Winter)
                {
                    found = ay.Fall.ContainsKey(cs.CourseID);
                }
                else if (term == ay.Spring)
                {
                    found = ay.Winter.ContainsKey(cs.CourseID) || ay.Fall.ContainsKey(cs.CourseID);
                }
                else if (term == ay.Summer)
                {
                    found = ay.Spring.ContainsKey(cs.CourseID) || ay.Winter.ContainsKey(cs.CourseID) || ay.Fall.ContainsKey(cs.CourseID);
                }
                else
                {
                    found = false;
                }

                if (found)
                {
                    iter.Delete();
                }
            }

            // Only add the course if it's prerequisites have been satisfied
            if (iter.Length < 1)
            {
                term.Add(course.CourseID, course);
                ay.SaveYear();
                term.PopulateListBox(lbx);
            }
        }