//[FUNCTION - DeepCopySingleCourse]
 //Function is mainly the answer from the following post on how to copy a complex object
 //https://stackoverflow.com/questions/16696448/how-to-make-a-copy-of-an-object-in-c-sharp
 //Copies instance of a SingleCourse Object into an identical new object
 public static SingleCourse DeepCopySingleCourse(SingleCourse other)
 {
     using (MemoryStream ms = new MemoryStream())
     {
         BinaryFormatter formatter = new BinaryFormatter();
         formatter.Serialize(ms, other);
         ms.Position = 0;
         return((SingleCourse)formatter.Deserialize(ms));
     }
 }
示例#2
0
        //[FUNCTION - FindIfMatchingInstructs]
        //Returns false if course doesnt have a matching instructor
        bool FindIfMatchingInstructs(SingleCourse course)
        {
            foreach (var instructor in course.getInstructAvailable())
            {
                if (instructor == InstructorNameFilter.Text)
                {
                    return(false);
                }
            }

            return(true);
        }
示例#3
0
 //[FUNCTION - addButton_Click]
 //Adds selected course to user's courses when button is clicked
 private void addButton_Click(object sender, EventArgs e)
 {
     if (courseAccepted == true)
     {
         selectedRow = addCoursesDataTable.Rows[selectedTableIndex];
         SingleCourse selectedCourseClass = allCourses[allCourses.IndexOf(allCourses.Find(s => (s.courseName == (string)selectedRow.Cells[1].Value) &&
                                                                                          (s.abrvCourseName == (string)selectedRow.Cells[0].Value)))];
         MainCourseForm.selectedCourses.Add(selectedCourseClass);
         addCourseStateLabel.ForeColor = Color.Green;
         addCourseStateLabel.Text      = "Added " + (string)selectedRow.Cells[1].Value + " to course list!";
         MainCourseForm.RefreshTable();
         courseAccepted = false;
     }
 }
示例#4
0
 //[FUNCTION - AddSelectedCourse]
 //Adds the course that the user selected last
 private void AddSelectedCourse()
 {
     if (courseAccepted)
     {
         selectedRow = addCoursesDataTable.Rows[selectedTableIndex];
         SingleCourse selectedCourseClass = DeepCopySingleCourse(allCourses[allCourses.IndexOf(allCourses.Find(s => (s.getCourseName() == (string)selectedRow.Cells[1].Value) &&
                                                                                                               (s.getAbrvCourseName() == (string)selectedRow.Cells[0].Value)))]);
         MainCourseForm.selectedCourses.Add(selectedCourseClass);
         addCourseStateLabel.ForeColor = Color.Green;
         addCourseStateLabel.Text      = "Added " + (string)selectedRow.Cells[1].Value + " to course list!";
         MainCourseForm.RefreshTable();
         courseAccepted = false;
     }
     if (MainCourseForm.selectedCourses.Count() >= 10)
     {
         addCourseStateLabel.ForeColor = Color.Red;
         addCourseStateLabel.Text      = "Cannot have more that 10 courses!";
     }
 }