/// <summary>
 /// Append a CourseFaculty object to the CourseFaculty CSV file
 /// </summary>
 /// <param name="coursefaculty"></param>
 private void SaveCourseFacultyToFile(CourseFaculty coursefaculty)
 {
     using (System.IO.StreamWriter file = new System.IO.StreamWriter("CourseFaculty.csv", true))
     {
         file.WriteLine(coursefaculty.ToRecord());
         file.Close();
     }
     ExposeRelatedFaculty();
 }
Esempio n. 2
0
        /// <summary>
        /// Performs validation of and disk data update routine to allow Faculty to Unlinked from a Course as an Instructor
        /// </summary>
        /// <param name="StudentID">The unique ID of the Faculty to be unlinked</param>
        /// <param name="CourseID">The unique ID of the Course the Student is to be unregistered from</param>
        public static void DeleteCourseFaculty(Int16 CourseID, Int16 FacultyID)
        {
            //Verify that Course exists
            Course course = Globals.GetCourse(CourseID);

            if (course == null)
            {
                throw new Exception("ERROR: Invalid Course ID (" + CourseID.ToString() + ")");
                //return;
            }
            //Verify that Faculty exists
            Faculty faculty = Globals.GetFaculty(FacultyID);

            if (faculty == null)
            {
                throw new Exception("ERROR: Invalid Student ID (" + FacultyID.ToString() + ")");
                //return;
            }

            //Ask user to confirm the update
            if (MessageBox.Show("Are you sure you want to remove the faculty member named " + faculty.FirstName + " " + faculty.LastName + " as an instructor of course number " + course.CourseNumber + " ?", "Confirm Remove Instructor", MessageBoxButtons.YesNo, MessageBoxIcon.Question).Equals(DialogResult.No))
            {
                return;
            }

            ArrayList alOutput = new ArrayList();
            //Loop through the registry and output all CourseFaculty to an ArrayList except the Faculty to be UnLinked
            String CourseFacultyLine;

            System.IO.StreamReader CourseFacultyFile = new System.IO.StreamReader("CourseFaculty.csv");
            while ((CourseFacultyLine = CourseFacultyFile.ReadLine()) != null)
            {
                CourseFaculty coursefaculty = new CourseFaculty(CourseFacultyLine);
                if (coursefaculty != null)
                {
                    if ((coursefaculty.FacultyID.Equals(FacultyID)) && (coursefaculty.CourseID.Equals(CourseID)))
                    {
                    }
                    else
                    {
                        alOutput.Add(CourseFacultyLine);
                    }
                }
            }
            CourseFacultyFile.Close();

            //Write the ArrayList back to the CourseFaculty CSV file without Appending
            using (System.IO.StreamWriter file = new System.IO.StreamWriter("CourseFaculty.csv", false))
            {
                foreach (String s in alOutput)
                {
                    file.WriteLine(s);
                }
                file.Close();
            }
        }
        /// <summary>
        /// User clicked the Assign Faculty link, so popup the Faculty selection form and if "Select" is clicked on that form, save the CourseFaculty update to the CSV file
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void lnkAssignFaculty_Click(object sender, EventArgs e)
        {
            frmSelectFaculty fSelectFaculty = new frmSelectFaculty();

            if (fSelectFaculty.ShowDialog().Equals(DialogResult.OK))
            {
                CourseFaculty coursefaculty = new CourseFaculty();

                Course  course  = (Course)lstCourse.SelectedItem;
                Faculty faculty = (Faculty)fSelectFaculty.cboFaculty.SelectedItem;

                coursefaculty.CourseID  = course.ID;
                coursefaculty.FacultyID = faculty.ID;


                SaveCourseFacultyToFile(coursefaculty);
                splitContainer1.Panel2Collapsed = false;
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Validates that a Faculty teaches a Course as indicated in the CourseFaculty CSV file
        /// </summary>
        /// <param name="FacultyID">The unique ID of the Faculty to be verified</param>
        /// <returns>True if the Faculty teaches the Course</returns>
        public static bool FacultyTeachesCourse(Int16 CourseID, Int16 FacultyID)
        {
            bool bResult = false;

            String CourseFacultyLine;

            System.IO.StreamReader CourseFacultyFile = new System.IO.StreamReader("CourseFaculty.csv");
            while ((CourseFacultyLine = CourseFacultyFile.ReadLine()) != null)
            {
                CourseFaculty coursefaculty = new CourseFaculty(CourseFacultyLine);
                if ((coursefaculty.CourseID.Equals(CourseID)) && (coursefaculty.FacultyID.Equals(FacultyID)))
                {
                    bResult = true;
                    break;
                }
            }
            CourseFacultyFile.Close();

            return(bResult);
        }