예제 #1
0
        private void btnRequest_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(combCourseName.Text))                                                                         //check if anything necessary is null
            {
                MessageBox.Show("Please select a course for the session.");
            }
            else if (string.IsNullOrWhiteSpace(combHours.Text) || string.IsNullOrWhiteSpace(combMins.Text))
            {
                MessageBox.Show("Please input values for the hours and minutes dropdown boxes");
            }
            else if (((Convert.ToInt32(combHours.Text) * 4 + (Convert.ToInt32(combMins.Text) / 15)) == 0) ||                            //check that the appointment is between 15 minutes and 3 hours
                     ((Convert.ToInt32(combHours.Text) * 4 + (Convert.ToInt32(combMins.Text) / 15)) > 12))
            {
                MessageBox.Show("Please input values for the hours and minutes that are between a length of 15 minutes and 3 hours");
            }
            else
            {
                bool     weekly           = cbxWeekly.Checked;                                                                                 //get whether this is weekly
                DateTime start            = DateTime.Now;                                                                                      //set start to now
                TutorMasterDBEntities4 db = new TutorMasterDBEntities4();                                                                      //connect to database

                string classCode = (from row in db.Classes where combCourseName.Text == row.ClassName select row.ClassCode).First();           //get the class code

                var approvedTutorIds = (from row in db.StudentClasses.AsEnumerable() where classCode == row.ClassCode select row.ID).ToList(); //get all of the approved tutors
                if (approvedTutorIds.Count() == 0)
                {
                    MessageBox.Show("There are currently no tutors approved to tutor this course. Sorry.");
                }
                else
                {
                    List <Commitment> tuteeCommits = (from stucmt in db.StudentCommitments.AsEnumerable()                               //get the tutee commitments
                                                      where stucmt.ID == id
                                                      join cmt in db.Commitments.AsEnumerable() on stucmt.CmtID equals cmt.CmtID
                                                      select cmt).ToList();


                    int sessionLength = Convert.ToInt32(combHours.Text) * 4 + (Convert.ToInt32(combMins.Text) / 15);                   //get the number of 15 minute time blocks of the session

                    SortsAndSearches.QuickSort(ref tuteeCommits, tuteeCommits.Count());                                                //sort the tutee commit list

                    checkMax(ref tuteeCommits);                                                                                        //check if there are any 3 hour time blocks

                    removeNotOpens(ref tuteeCommits, start, weekly);                                                                   //remove the commitments that are not open

                    if (tuteeCommits.Count == 0)
                    {
                        MessageBox.Show("You currently have no available slots, please add some availability before attempting to schedule a session of this length");
                    }
                    else
                    {
                        List <string> tuteeValidSlots = getValidSlots(ref tuteeCommits, sessionLength);                                //get the tutee's valid time slots for the length of the session we're looking for

                        bool done = false;
                        for (int i = 0; i < approvedTutorIds.Count(); i++)                                                            //go through each tutor in the approved tutor list
                        {
                            if (approvedTutorIds[i] != id)                                                                            //don't let a tutor tutor him/herself
                            {
                                var tutorFirstName = (from row in db.Users.AsEnumerable() where row.ID == approvedTutorIds[i] select row.FirstName).First();
                                var tutorLastName  = (from row in db.Users.AsEnumerable() where row.ID == approvedTutorIds[i] select row.LastName).First();

                                List <TutorMaster.Commitment> tutorCommits = (from stucmt in db.StudentCommitments.AsEnumerable()     //get the tutor's commitments
                                                                              where stucmt.ID == approvedTutorIds[i]
                                                                              join cmt in db.Commitments.AsEnumerable() on stucmt.CmtID equals cmt.CmtID
                                                                              select cmt).ToList();

                                SortsAndSearches.QuickSort(ref tutorCommits, tutorCommits.Count());                                   //sort them

                                checkMax(ref tutorCommits);                                                                           //check for 3 tutoring blocks

                                removeNotOpens(ref tutorCommits, start, weekly);                                                      //remove the not opens

                                List <string> tutorValidSlots = getValidSlots(ref tutorCommits, sessionLength);                       //get the valid time slots for the tutors

                                for (int j = 0; j < tutorValidSlots.Count(); j++)                                                     //iterate through the valid tutor time slots
                                {
                                    if (SortsAndSearches.BinarySearch(tuteeValidSlots, tutorValidSlots[j]))                           //see if the tutorvalid slot is in the tutee list
                                    {                                                                                                 //if it is, ask the user if they'd this appointment
                                        DialogResult choice = MessageBox.Show("You have been matched with " + tutorFirstName + " " + tutorLastName +
                                                                              " for a time at: " + tutorValidSlots[j].Split(',')[0] + " - " + tutorValidSlots[j].Split(',')[1], "You've got a match!", MessageBoxButtons.YesNo);
                                        if (choice == DialogResult.Yes)                                                               //if they say yes, get their ids and add the commitments to their schedules
                                        {
                                            int tutorId = Convert.ToInt32(approvedTutorIds[i]);
                                            int tuteeId = Convert.ToInt32(id);
                                            addCommits(tutorValidSlots[j], tutorId, tuteeId, tutorCommits, tuteeCommits, classCode, db, weekly, sessionLength);
                                            done = true;
                                            break;
                                        }
                                        else if (choice == DialogResult.No)                                                           //if no, break out of this loop and repeat the same process with another approved tutor if there is one
                                        {
                                            break;
                                        }
                                    }
                                }
                                if (done)                                                                                             //if they picked this tutor and we're done, break out of this large for loop
                                {
                                    break;
                                }
                            }
                        }
                        if (!done)                                                                                                    //if we go through every tutor and do not pick one, put the message up
                        {
                            MessageBox.Show("There are no more tutors that meet your request requirements.");
                        }
                    }
                    StudentMain g = new StudentMain(id);                                                                              //return to student main
                    g.Show();
                    this.Dispose();
                }
            }
        }
예제 #2
0
        //Match Function and it's helpers
        private void MatchTimes(ComboBox TutBox, ComboBox ClsBox)
        {
            TutorMasterDBEntities4 db = new TutorMasterDBEntities4();

            lvAvailableTimes.Items.Clear();
            lvAvailableTimes.Hide();

            //a. Name of Tutor, use it to find their ID
            int TutID = tutorIDs[TutBox.SelectedIndex];

            //b. Length of tutoring session in minutes
            int length = Convert.ToInt32(combStartHour.Text) * 4 + (Convert.ToInt32(combStartMinute.Text) / 15);

            //c. whether it is weekly
            bool weekly = cbxWeekly.Checked;

            //d. tutee ID (ACCID), use to match the availiblity
            int TuteeID = ACCID;


            DateTime start = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 0, 0, 0);

            string classCode = (from row in db.Classes where row.ClassName == ClsBox.Text select row.ClassCode).First();

            List <Commitment> tuteeCommits = (from stucmt in db.StudentCommitments.AsEnumerable()    // create a list of tutee's commitments
                                              where stucmt.ID == TuteeID
                                              join cmt in db.Commitments.AsEnumerable() on stucmt.CmtID equals cmt.CmtID
                                              select cmt).ToList();

            SortsAndSearches.QuickSort(ref tuteeCommits, tuteeCommits.Count()); //sort the tutee commits so that they are in chronological order

            checkMax(ref tuteeCommits);

            removeNotOpens(ref tuteeCommits, start, weekly); //remove all the things that are not open

            if (tuteeCommits.Count == 0)                     //If the tuttee doesn't have any compatible availibility then give a pop up box to let them know
            {
                MessageBox.Show("You currently have no available slots, please add some availability before attempting to schedule a session of this length");
            }
            else
            {
                List <string> tuteeValidSlots = getValidSlots(ref tuteeCommits, length);                          //this is returning 0 for some reason

                List <TutorMaster.Commitment> tutorCommits = (from stucmt in db.StudentCommitments.AsEnumerable() //This creates a list of all the tutor commitments.
                                                              where stucmt.ID == TutID
                                                              join cmt in db.Commitments.AsEnumerable() on stucmt.CmtID equals cmt.CmtID
                                                              select cmt).ToList();

                SortsAndSearches.QuickSort(ref tutorCommits, tutorCommits.Count());      //sort it so we can use it
                checkMax(ref tutorCommits);
                removeNotOpens(ref tutorCommits, start, weekly);                         //remove the occupied commitments

                List <string> tutorValidSlots = getValidSlots(ref tutorCommits, length); //create a list of all the valid tutor slots

                int numMatches = 0;
                lvAvailableTimes.Show();
                for (int j = 0; j < tutorValidSlots.Count(); j++) //iterate through all the available tutor slots
                {
                    if (SortsAndSearches.BinarySearch(tuteeValidSlots, tutorValidSlots[j]))
                    {
                        //add all the slots to the tutor availibility timeslot
                        ListViewItem item = new ListViewItem(new string[] { tutorValidSlots[j].Split(',')[0], tutorValidSlots[j].Split(',')[1] });
                        lvAvailableTimes.Items.Add(item);//adds the time slot to the combo box

                        numMatches++;
                    }
                }

                if (numMatches == 0)
                {
                    MessageBox.Show("This Tutor has no matching availibility.");
                }
                btnSendRequest.Click += (sender, e) => btnSendRequest_Click(sender, e, tutorValidSlots, TutID, TuteeID, tutorCommits, tuteeCommits, classCode, db, weekly, length);
            }
        }
예제 #3
0
 public static bool weeklyAndFound(Commitment commit, List <DateTime> searchList)
 {//this function checks if a commitment is weekly and found in the commitment list
     return(commit.Weekly == true && SortsAndSearches.BinarySearch(searchList, Convert.ToDateTime(commit.StartTime)));
 }
        private void loadMatchingTimeSlots()
        {
            TutorMasterDBEntities4 db = new TutorMasterDBEntities4();
            bool weekly = cbWeekly.Checked;

            if (rememberStudIDs.Count == 0)                                                                                     //if there are no valid students, print this message
            {
                MessageBox.Show("There are currently no students available for this course");
            }
            else
            {
                DateTime start         = DateTime.Now;
                string   classCode     = (from row in db.Classes where cbxClasses.Text == row.ClassName select row.ClassCode).First(); //get the classcode
                int      sessionLength = Convert.ToInt32(cbxHour.Text) * 4 + (Convert.ToInt32(cbxMinutes.Text) / 15);                  //calculate session length from the hour and minute dropdowns

                if (sessionLength > 12 || sessionLength == 0)                                                                          //make sure the length is of the appropriate size
                {
                    MessageBox.Show("Please pick a session legnth between 15 minutes and 3 hours.");
                }
                else
                {
                    List <TutorMaster.Commitment> studentCommits = (from stucmt in db.StudentCommitments.AsEnumerable()
                                                                    where stucmt.ID == id
                                                                    join cmt in db.Commitments.AsEnumerable() on stucmt.CmtID equals cmt.CmtID
                                                                    select cmt).ToList();                                      //get all of the signed in student's commitments

                    SortsAndSearches.QuickSort(ref studentCommits, studentCommits.Count);                                      //sort them

                    removeNotOpens(ref studentCommits, start, weekly);                                                         //remove the not opens

                    if (studentCommits.Count == 0)                                                                             //if the student we are signed in on has no open slots, print this message
                    {
                        MessageBox.Show("The student you are trying to create an appointment for currently has no open time slots with which to make an appointment.");
                    }
                    else
                    {
                        List <string> studentValidSlots = getValidSlots(ref studentCommits, sessionLength);                    //get all the slots of the appropriate length
                        int           partnerId         = rememberStudIDs[cbxStudents.SelectedIndex];                          //get the chosen partner id

                        List <TutorMaster.Commitment> partnerCommits = (from stucmt in db.StudentCommitments.AsEnumerable()
                                                                        where stucmt.ID == partnerId
                                                                        join cmt in db.Commitments.AsEnumerable() on stucmt.CmtID equals cmt.CmtID
                                                                        select cmt).ToList();

                        SortsAndSearches.QuickSort(ref partnerCommits, partnerCommits.Count);                                 //sort the partner's commitments

                        removeNotOpens(ref partnerCommits, start, weekly);                                                    //remove the not opens

                        if (partnerCommits.Count == 0)                                                                        //make sure they have some open available time
                        {
                            MessageBox.Show("The chosen partner currently has no open time slots with which to make an appointment.");
                        }
                        else
                        {
                            List <string> tuteeValidSlots = getValidSlots(ref partnerCommits, sessionLength);                  //get every possible valid slot

                            for (int c = 0; c < studentValidSlots.Count(); c++)
                            {
                                if (SortsAndSearches.BinarySearch(tuteeValidSlots, studentValidSlots[c]))                    //look for overlaps and then add them to the listview
                                {
                                    lvTimeMatches.Items.Add(new ListViewItem(new string[] { studentValidSlots[c].Split(',')[0], studentValidSlots[c].Split(',')[1] }));
                                }
                            }
                        }
                    }
                }
            }
        }
예제 #5
0
        private void deleteAvail(bool week)
        {
            TutorMasterDBEntities4 db = new TutorMasterDBEntities4();                                        //connect to the database

            List <Commitment> cmtList = (from stucmt in db.StudentCommitments                                //get the student's commitments
                                         where stucmt.ID == id
                                         join cmt in db.Commitments on stucmt.CmtID equals cmt.CmtID
                                         select cmt).ToList();

            SortsAndSearches.QuickSort(ref cmtList, cmtList.Count());                                                         //sort the list by DateTime

            List <DateTime> searchList = new List <DateTime>();

            searchList = getStartTimes();                                                                    //get the starttimes from the listview

            if (week)
            {
                for (int i = 0; i < cmtList.Count(); i++)
                {
                    if (SortsAndSearches.BinarySearch(searchList, Convert.ToDateTime(cmtList[i].StartTime)))
                    {
                        if (cmtList[i].Weekly == true)
                        {                                                                               //ask the user if they want to delete the weekly commitment through the end of the semester
                            DateTime endSemes    = new DateTime(2017, 5, 1, 0, 0, 0);                   //get end of semester
                            DateTime weekForward = Convert.ToDateTime(cmtList[i].StartTime).AddDays(7); //go a week forward
                            while (DateTimeMethods.endOfSemesIsLater(endSemes, weekForward))            //if the end of the semester is later than our commitment start Time
                            {                                                                           //run a binary search
                                bool found = false;
                                int  first = 0;
                                int  last  = cmtList.Count() - 1;
                                while (first <= last && !found)
                                {
                                    int midpoint = (first + last) / 2;
                                    if (DateTimeMethods.sameTime(cmtList[midpoint], weekForward))             //if commitment time and weekforward time are the same
                                    {
                                        if (cmtList[midpoint].Open == true)                                   //and if the midpoint commitment is open
                                        {
                                            db.Commitments.DeleteObject(cmtList[midpoint]);                   //delete the commitment from the database
                                            cmtList.Remove(cmtList[midpoint]);                                //remove it from the commit list as well
                                            db.SaveChanges();
                                        }
                                        found = true;                                                         //say we found what we were looking for
                                        break;                                                                //break out of the search
                                    }
                                    else
                                    {
                                        if (DateTimeMethods.forwardEarlierThanStart(weekForward, cmtList[midpoint]))
                                        {
                                            last = midpoint - 1;
                                        }
                                        else
                                        {
                                            first = midpoint + 1;
                                        }
                                    }
                                }
                                weekForward = weekForward.AddDays(7);
                            }
                        }

                        searchList.Remove(Convert.ToDateTime(cmtList[i].StartTime));
                        db.Commitments.DeleteObject(cmtList[i]);
                        i--;
                        db.SaveChanges();
                    }
                }
                MessageBox.Show("The checked 15 minute time blocks have been removed from your availability until the end of the semster.");
            }
            else
            {
                for (int i = 0; i < cmtList.Count(); i++)
                {
                    if (SortsAndSearches.BinarySearch(searchList, Convert.ToDateTime(cmtList[i].StartTime)))
                    {
                        searchList.Remove(Convert.ToDateTime(cmtList[i].StartTime));
                        db.Commitments.DeleteObject(cmtList[i]);
                        i--;
                        db.SaveChanges();
                    }
                }
                MessageBox.Show("Only the checked 15 minute time blocks have been removed from your availability.");
            }
        }