//
        private void lToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog1 = new OpenFileDialog();

            openFileDialog1.InitialDirectory = "c:\\";
            openFileDialog1.Filter           = "txt files (*.gps)|*gps|All files (*.*)|*.*";
            openFileDialog1.FilterIndex      = 2;
            openFileDialog1.RestoreDirectory = true;

            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                Degree degree = XMLSerializer.DeserializeXMLToDegree(openFileDialog1.FileName);

                mCoursesTaken = degree.TakenCourses;
                mDegree       = degree;
                uiClassList.SetTakenClass(mCoursesTaken);
                // RegisterClicks();
                //add the degree control to the tab

                while (mDegree.Semesters.Count < mDegree.MaxSemesters)
                {
                    mDegree.Semesters.Add(new Semester());
                }

                DegreeControl page = new DegreeControl(mDegree, mCoursesTaken, this, "Default");
                mTabs.Items.Clear();
                mTabs.Items.Add(page);

                //this.RegCourses(degree);
            }
        }
        //populat teh required, taken, elective, and replacement classes
        private void PopulateLists()
        {
            List <Course>   required  = new List <Course>();
            List <Elective> electives = new List <Elective>();

            if (mTabs.SelectedIndex > -1)
            {
                DegreeControl control = (DegreeControl)mTabs.Items[mTabs.SelectedIndex];
                Degree        clone   = mDegree.Clone();
                clone.Semesters = control.Semesters;

                foreach (Course course in clone.RequiredCourses)
                {
                    //check all semesters and the Taken list
                    if (clone.SemesterCourseTaken(course.UID).Count == 0 && !CourseIsTaken(course.Name))
                    {
                        required.Add(course);
                    }
                }

                uiClassList.SetRequirements(required);

                foreach (Elective elective in clone.ElectiveCourses)
                {
                    elective.RemainingHours = clone.ElectiveBeingTaken(elective);
                    if (clone.ElectiveBeingTaken(elective) > (Int64)0)
                    {
                        electives.Add(elective);
                    }
                }
                uiClassList.SetElectives(electives);
            }
        }
Beispiel #3
0
        public PlanPage(Degree plan, List <Course> taken, GenerateSchedulesForm parent)
        {
            InitializeComponent();
            this.AutoScroll = true;

            Control = new DegreeControl(plan, taken, parent, "sdf");
            this.elementHost2.Child = Control;
        }
        private bool CourseIsBeingTaken(string courseName, DegreeControl plan)
        {
            foreach (OneYearViews year in plan.YearViews)
            {
                foreach (SemesterControl control in year.Semesters)
                {
                    if (control.ContainsCourseNotFail(courseName))
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
        //contructor
        public GenerateSchedulesForm(String degreeType, Degree degree, DBClass db)
        {
            InitializeComponent();
            //setup the class list
            uiClassList             = new ClassListUI(this);
            this.elementHost3.Child = uiClassList;
            mDb = db;
            //setup the degree and taken list
            mDegree = degree;
            // removes classes taken from the default schedule

            mCoursesTaken = degree.TakenCourses;
            uiClassList.SetTakenClass(mCoursesTaken);
            // RegisterClicks();
            //add the degree control to the tab

            while (mDegree.Semesters.Count < mDegree.MaxSemesters)
            {
                mDegree.Semesters.Add(new Semester());
            }

            DegreeControl page = new DegreeControl(mDegree, mCoursesTaken, this, "Default");

            mTabs = new System.Windows.Controls.TabControl();
            mTabs.Items.Add(page);
            elementHost1.Child      = mTabs;
            mTabs.SelectionChanged += new WPF.SelectionChangedEventHandler(mTabs_SelectionChanged);
            uiClassList.lstElectives.SelectionChanged += new WPF.SelectionChangedEventHandler(lstElectives_SelectionChanged);
            //UpdateCourseList(mDegree, control);
            //mDegreeControls.Add(control);

            List <string> codes = db.GetDegreeCodes();

            this.cmboDegreeSwitch.Items.Clear();
            foreach (string code in codes)
            {
                cmboDegreeSwitch.Items.Add(code);
            }
        }
        //save the degree out
        private void saveToolStripMenuItem_Click(object sender, EventArgs e)
        {
            SaveFileDialog openFileDialog1 = new SaveFileDialog();

            openFileDialog1.InitialDirectory = "c:\\";
            openFileDialog1.Filter           = "txt files (*.gps)|GPS";
            openFileDialog1.AddExtension     = true;
            openFileDialog1.FilterIndex      = 2;
            openFileDialog1.CheckFileExists  = false;
            openFileDialog1.RestoreDirectory = true;

            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                Degree degree = mDegree.Clone();
                degree.Semesters.Clear();
                DegreeControl control = (DegreeControl)mTabs.Items[mTabs.SelectedIndex];
                degree.Semesters    = control.Semesters;
                degree.TakenCourses = uiClassList.GetTakenList();


                XMLSerializer.SerializeDegreeToXML(degree, openFileDialog1.FileName + ".gps");
            }
        }
        //generate the schedules
        private void btnGenerateSchedules_Click(object sender, EventArgs e)
        {
            int schedulesToGen = 0;

            try
            {
                schedulesToGen = Convert.ToInt32(txtGenSchedules.Text);
            }
            catch
            {
                System.Windows.Forms.MessageBox.Show("Unable to parse request.  Please designate a number of schedules " +
                                                     "between 1 and 10.");
            }
            if (schedulesToGen > 0 && schedulesToGen <= 10)
            {
                Degree copy = mDegree.Clone();
                {
                    copy.Semesters.Clear();
                    // PlanPage selected = (PlanPage)tabControl1.SelectedTab;
                    //TODO
                    DegreeControl control = (DegreeControl)mTabs.Items[mTabs.SelectedIndex];
                    control.Title = "Model";
                    mTabs.Items.Clear();
                    mTabs.Items.Add(control);
                    copy.Semesters = control.Semesters;
                }


                DegreePlanner planner = new DegreePlanner();

                copy.TakenCourses = uiClassList.GetTakenList();

                List <Degree> generated = planner.GenerateSchedules(copy, schedulesToGen);

                int success = 0;
                for (int i = 0; i < generated.Count; i++)
                {
                    bool grad = true;
                    generated[i].Name = ((i + 1).ToString());     //nk

                    DegreeControl control = new DegreeControl(generated[i], mCoursesTaken, this, (i + 1).ToString());
                    control.Verify();
                    mTabs.Items.Add(control);
                    //tabControl1.TabPages.Add(new PlanPage(temp, mCoursesTaken, this)); //nk
                    //tabControl1.TabPages[i + 1].Text = (i + 1).ToString(); //nk

                    Degree checkGrad = generated[i].Clone();
                    checkGrad.Semesters = generated[i].Semesters;

                    //Check for graduation on requirements
                    foreach (Course course in checkGrad.RequiredCourses)
                    {
                        //check all semesters and the Taken list
                        if (checkGrad.SemesterCourseTaken(course.UID).Count == 0 && !CourseIsTaken(course.Name))
                        {
                            grad = false;
                        }
                    }

                    //Check for graduation of electives
                    foreach (Elective elective in checkGrad.ElectiveCourses)
                    {
                        elective.RemainingHours = checkGrad.ElectiveBeingTaken(elective);
                        if (checkGrad.ElectiveBeingTaken(elective) > (Int64)0)
                        {
                            grad = false;
                        }
                    }

                    if (grad)
                    {
                        success++;
                    }
                }

                System.Windows.Forms.MessageBox.Show(schedulesToGen.ToString() + " schedules were successfully generated." + Environment.NewLine + Environment.NewLine +
                                                     success.ToString() + " schedules resulted in graduation! "
                                                     );
                //  tabControl1.TabPages.Add(new PlanPage());
            }
            else
            {
            }
        }