Esempio n. 1
0
        public void removeStd(string username, ref courseDatabase crsDB)
        {
            student std = getStudent(username);

            // Increment the number of seats available for each course the student has registered for
            List <course> registeredCrsLst = std.registeredCrs;

            foreach (course registeredCrs in registeredCrsLst)
            {
                foreach (course crs in crsDB.getCourseList())
                {
                    if (registeredCrs.crsID == crs.crsID)
                    {
                        crs.disenrollUser(std);
                        break;
                    }
                }
            }

            // Remove the student from the advisees list of his advisor
            faculty advisor = getFaculty(std.advisor);

            advisor.removeAdvisee(username);

            // Remove the student from the database
            stdLst.Remove(std);
        }
Esempio n. 2
0
        // Construct the database and update it
        public courseDatabase(ref userDatabase userDB)
        {
            this.crsLst = new List <course>();
            string line;

            System.IO.StreamReader input = new System.IO.StreamReader(@"..\..\courseDB.in");
            while ((line = input.ReadLine()) != null)
            {
                string        code            = line.Substring(0, 10).Trim();
                string        title           = line.Substring(11, 15).Trim();
                string        instructor      = line.Substring(27, 10).Trim().ToLower();
                string        credit          = line.Substring(38, 4).Trim();
                int           seats           = Convert.ToInt32(line.Substring(43, 3).Trim());
                int           num_time_blocks = int.Parse(line.Substring(47, 1).Trim());
                int           index           = 49;
                List <string> BlockLst        = new List <string>();
                for (int i = 0; i < num_time_blocks; i++)
                {
                    string time_block = line.Substring(index, 5);
                    BlockLst.Add(time_block);
                    index += 6;
                }
                course crs = new course(code, title, instructor, credit, seats, num_time_blocks, BlockLst);
                crsLst.Add(crs);
                faculty courseFac = userDB.getFaculty(instructor.Trim());
                courseFac.nextSemesterCourses.Add(crs);
            }
            input.Close();
        }
Esempio n. 3
0
        public void addUser(string username, string password, string fname, string mname, string lname, string status, string filepath)
        {
            string fileLine = username.PadRight(11) + password.PadRight(11) + fname.PadRight(16) + mname.PadRight(16) + lname.PadRight(16) + status.PadRight(10);

            if (status == "admin")
            {
                admin newAdm = new admin(fname, mname, lname, username, password);
                adminLst.Add(newAdm);
            }
            else if (status == "faculty")
            {
                faculty newFac = new faculty(fname, mname, lname, username, password);
                facLst.Add(newFac);
            }
            else if (status == "manager")
            {
                manager newMan = new manager(fname, mname, lname, username, password);
                manLst.Add(newMan);
            }
            else
            {
                student newStd = new student(fname, mname, lname, status, username, password);
                stdLst.Add(newStd);
                foreach (faculty fac in facLst)
                {
                    if (newStd.advisor.Trim() == fac.username.Trim())
                    {
                        fac.addAdvisee(newStd);
                    }
                }
            }
        }
Esempio n. 4
0
        public facMainpage(string username, userDatabase usrDB, courseDatabase crsDB)
        {
            InitializeComponent();
            this.usrDB = usrDB;
            this.crsDB = crsDB;
            fac        = usrDB.getFaculty(username);

            // Change texts
            welcome.Text += fac.fname + " " + fac.lname;

            // Create all the tables
            createCrsLst();
            createFacSch();
            createAdviseeLst();

            // Auto complete
            foreach (course crs in crsDB.getCourseList())
            {
                crsIDBox.AutoCompleteCustomSource.Add(crs.crsID);
            }

            // Clear selection of tables
            facSch.ClearSelection();
            adviseeLst.ClearSelection();
        }
Esempio n. 5
0
        // Construct the database and update it
        public userDatabase(string filepath)
        {
            stdLst   = new List <student>();
            facLst   = new List <faculty>();
            adminLst = new List <admin>();
            manLst   = new List <manager>();

            string line;

            System.IO.StreamReader input = new System.IO.StreamReader(filepath);
            while ((line = input.ReadLine()) != null)
            {
                string username   = line.Substring(0, 10).Trim().ToLower();
                string password   = line.Substring(11, 10).Trim();
                string firstName  = line.Substring(22, 10).Trim();
                string middleName = line.Substring(38, 15).Trim();
                string lastName   = line.Substring(54, 15).Trim();
                string status     = line.Substring(70).Trim().ToLower();

                if (status == "faculty")
                {
                    faculty fac = new faculty(firstName, middleName, lastName, username, password);
                    facLst.Add(fac);
                }
                else if (status == "admin")
                {
                    admin adm = new admin(firstName, middleName, lastName, username, password);
                    adminLst.Add(adm);
                }
                else if (status == "manager")
                {
                    manager man = new manager(firstName, middleName, lastName, username, password);
                    manLst.Add(man);
                }
                else
                {
                    student std = new student(firstName, middleName, lastName, status, username, password);
                    stdLst.Add(std);
                }
            }

            foreach (student std in stdLst)
            {
                for (int i = 0; i < facLst.Count(); i++)
                {
                    if (std.advisor == facLst[i].username)
                    {
                        facLst[i].addAdvisee(std);
                        break;
                    }
                }
            }
            input.Close();
        }
Esempio n. 6
0
        public void removeFac(string username)
        {
            //Loops through their advisees and changes the students' advisor to "Staff"
            faculty fac = getFaculty(username);

            foreach (student std in fac.adviseesLst)
            {
                std.setAdvisor("Staff");
            }

            // Remove the faculty
            facLst.Remove(fac);
        }
Esempio n. 7
0
        public faculty getFaculty(string username)
        {
            faculty fac = facLst[0]; // Default value

            foreach (faculty f in facLst)
            {
                if (f.username.Trim() == username.ToLower())
                {
                    return(f);
                }
            }
            return(fac);
        }
Esempio n. 8
0
        public void changeAdvisor(string stdName, string facName)
        {
            // Change the student's advisor
            student std        = getStudent(stdName);
            string  curAdvisor = std.advisor;

            std.setAdvisor(facName);

            // Add the student to the new faulty's advisee list
            faculty fac = getFaculty(facName);

            fac.addAdvisee(std);

            // Remove the student from the previous faculty's advisee list
            fac = getFaculty(curAdvisor);
            fac.removeAdvisee(stdName);
        }
Esempio n. 9
0
        // Change the database
        public void removeCrs(string crsID, string filepath, ref userDatabase usrDB)
        {
            // Remove the course from the offering
            course removedCrs = getCourse(crsID);

            crsLst.Remove(removedCrs);

            // Remove the course from students' schedule
            List <student> enrolledStdLst = removedCrs.getStudents();

            foreach (student std in enrolledStdLst)
            {
                std.dropCrsFromNext(removedCrs);
            }

            // Remove the course from faculties' schedule
            faculty fac = usrDB.getFaculty(removedCrs.instructor);

            fac.removeCrsFromNext(removedCrs);

            ////Updates the coursedb.in file to remove the removed course from it
            //string[] courseLines = File.ReadAllLines(filepath);
            //string[] newCourseLinesArr;
            //List<string> newCourseLines = new List<string>();
            //foreach (string courseString in courseLines)
            //{
            //    string courseID = courseString.Substring(0, 10).Trim();
            //    //string courseID = courseString.Substring(4, 10);
            //    if (courseID == removedCrs.crsID.Trim())
            //        continue;   // Skip the iteration if the course is being deleted
            //    else
            //        newCourseLines.Add(courseString);

            //    newCourseLinesArr = newCourseLines.ToArray();
            //    File.WriteAllLines(filepath, newCourseLinesArr);
            //}
        }
Esempio n. 10
0
        private void confirmClick(object sender, EventArgs e)
        {
            // Search for missing fields
            if (crsIDBox.Text == "" || titleBox.Text == "" || facDropDown.Text == "" ||
                creditBox.Text == "" || seatBox.Text == "")
            {
                MessageBox.Show("Required fields missing.",
                                "Invalid Input",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                return;
            }

            // Check if there is any time specified
            if (!MA.Checked && !MB.Checked && !TA.Checked && !TB.Checked && !WA.Checked && !WB.Checked &&
                !RA.Checked && !RB.Checked && !FA.Checked && !FB.Checked)
            {
                MessageBox.Show("Specify a time slot.",
                                "Invalid Input",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                return;
            }

            // Day duplicate over multiple time blocks
            if ((MA.Checked && MB.Checked) || (TA.Checked && TB.Checked) || (WA.Checked && WB.Checked) ||
                (RA.Checked && RB.Checked) || (FA.Checked && FB.Checked))
            {
                MessageBox.Show("Cannot have the same day over two slots",
                                "Invalid Input",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                return;
            }

            // Check the presence of starting and ending time.
            if (MA.Checked || TA.Checked || WA.Checked || RA.Checked || FA.Checked)
            {
                if (startingTimeA.Text == "" || endingTimeA.Text == "")
                {
                    MessageBox.Show("Specify the starting and ending time.",
                                    "Invalid input",
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                    return;
                }
            }


            string crsID = crsIDBox.Text;

            // Search for duplicate course ID
            foreach (course crs in crsDB.getCourseList())
            {
                if (crsID.Trim() == crs.crsID)
                {
                    MessageBox.Show("The course ID is already taken.",
                                    "Duplicate",
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                    return;
                }
            }

            string  title      = titleBox.Text.Trim();
            string  instructor = facDropDown.Text.Trim();
            faculty inst       = usrDB.getFacultyList()[0];

            foreach (faculty fac in usrDB.getFacultyList())
            {
                if (fac.fname + " " + fac.lname == instructor)
                {
                    inst = fac;
                    break;
                }
            }
            string credits = creditBox.Text;

            try
            {
                if (Convert.ToSingle(credits) == 0)
                {
                    MessageBox.Show("No credits given.",
                                    "Warning",
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Warning);
                }
            }
            catch
            {
                MessageBox.Show("Credits have to be a number.",
                                "Warning",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                return;
            }

            int seats = 0;

            try
            {
                seats = Convert.ToInt32(seatBox.Text);
            }
            catch
            {
                MessageBox.Show("Seats have to be a number.",
                                "Warning",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                return;
            }

            // Get the course time block
            int dd = 0;

            if (MA.Checked)
            {
                dd += 1;
            }
            if (TA.Checked)
            {
                dd += 2;
            }
            if (WA.Checked)
            {
                dd += 4;
            }
            if (RA.Checked)
            {
                dd += 8;
            }
            if (FA.Checked)
            {
                dd += 16;
            }

            string day = dd.ToString();

            if (day.Length < 2)
            {
                day = "0" + day;
            }

            string timeBlockA = day + UF.utilities.encodeTime(startingTimeA.Text, endingTimeA.Text);


            if (MB.Checked || TB.Checked || WB.Checked || RB.Checked || FB.Checked)
            {
                // Get the course time block
                dd = 0;
                if (MB.Checked)
                {
                    dd += 1;
                }
                if (TB.Checked)
                {
                    dd += 2;
                }
                if (WB.Checked)
                {
                    dd += 4;
                }
                if (RB.Checked)
                {
                    dd += 8;
                }
                if (FB.Checked)
                {
                    dd += 16;
                }

                day = dd.ToString();
                if (day.Length < 2)
                {
                    day = "0" + day;
                }

                string timeBlockB = day + UF.utilities.encodeTime(startingTimeB.Text, endingTimeB.Text);

                List <string> lst = new List <string>();
                lst.Add(timeBlockA);
                lst.Add(timeBlockB);
                crs = new course(crsID, title, inst.username, credits, seats, 2, lst);
            }
            else
            {
                List <string> lst = new List <string>();
                lst.Add(timeBlockA);
                crs = new course(crsID, title, inst.username, credits, seats, 1, lst);
            }
            string message;

            message  = "Course ID : " + crs.crsID + "\n";
            message += "Title : " + crs.title + "\n";
            message += "Instructor : " + crs.instructor + "\n";
            message += "Credits : " + crs.credit.ToString() + "\n";
            message += "Seats : " + crs.seats.ToString() + "\n";
            message += crs.getBlocks() + "\n";
            message += "Are you sure?";
            if (MessageBox.Show(message, "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.No)
            {
                MessageBox.Show("Canceled the creation.", "Cancel", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                this.DialogResult = DialogResult.OK;
                Close();
            }
        }