コード例 #1
0
        private void setPreviousWeekliesToFalse()
        {
            TutorMasterDBEntities4 db = new TutorMasterDBEntities4();                                         //connect to the database

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

            List <DateTime> searchList = new List <DateTime>();                                                 //initialize search list

            SortsAndSearches.QuickSort(ref cmtList, cmtList.Count());

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

            for (int i = 0; i < cmtList.Count(); i++)                                                         //for each commitment in the commit list
            {
                if (DateTimeMethods.weeklyAndFound(cmtList[i], searchList))                                   //if the commitment is in the search list and weekly
                {
                    DateTime startSemes = new DateTime(2017, 1, 1, 0, 0, 0);
                    DateTime weekBack   = Convert.ToDateTime(cmtList[i].StartTime).AddDays(-7);               //go a week back in time
                    while (DateTime.Compare(startSemes, weekBack) <= 0)                                       //perform a binary search here
                    {
                        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], weekBack))                        //if you find the weekBack date time
                            {
                                if (cmtList[midpoint].Open == true)                                           //if the commitment is open
                                {
                                    cmtList[midpoint].Weekly = false;                                         //set its weekly to false
                                    db.SaveChanges();                                                         //save the changes to the database
                                }
                                found = true;
                            }
                            else
                            {
                                if (DateTimeMethods.weekBackEarlier(weekBack, cmtList[midpoint]))                                    //if weekback is earlier, search first half of list
                                {
                                    last = midpoint - 1;
                                }
                                else                                                                          //else, search the second half of the list
                                {
                                    first = midpoint + 1;
                                }
                            }
                        }
                        weekBack = weekBack.AddDays(-7);                                                      //go a week back in time
                    }
                }
            }
        }
コード例 #2
0
        private List <DateTime> getStartTimes()
        {//the purpose of this function is to get the starttimes from the checked items of the listviews
            List <DateTime> result = new List <DateTime>();

            for (int n = 0; n < lvTimeSlots.CheckedItems.Count; n++)                                          //go through each of the checked items
            {
                result.Add(DateTimeMethods.getDate(lvTimeSlots.CheckedItems[n].SubItems[0].Text.ToString())); //add the start time date to the list
            }

            return(result);                                                                       //return the desired list
        }
コード例 #3
0
        private int getNumSession(string info)
        {
            int      numSession = 0;
            string   startTime  = info.Split(',')[0];
            string   endTime    = info.Split(',')[1];
            string   timeSlot   = startTime + "," + endTime;              //load a timeslot string
            DateTime start      = DateTimeMethods.getStartTime(timeSlot); //get the datetime start time
            DateTime end        = DateTimeMethods.getEndTime(timeSlot);   //get the datetime end time

            while (DateTime.Compare(start, end) < 0)
            {
                numSession++;                                        //increment numsessions until you get to appropriate value
                start = start.AddMinutes(15);
            }
            return(numSession);
        }
コード例 #4
0
 private void loadListView(List <string> removeList)
 {//this function is made to load the listviews with times of prospective desired remove times
     for (int i = 0; i < removeList.Count(); i++)
     {
         DateTime startTime = DateTimeMethods.getDate(removeList[i].Split(',')[0]);                 //get the start time
         DateTime endTime   = DateTimeMethods.getDate(removeList[i].Split(',')[1]);                 //get the end time
         string   weekly    = "No";
         if (removeList[i].Split(',')[2] == "True" || removeList[i].Split(',')[2] == "Yes")
         {
             weekly = "Yes";
         }
         while (DateTimeMethods.startEarlierThanEnd(startTime, endTime))                            //if the start time is before the end time, add the strings to the listviews
         {
             lvTimeSlots.Items.Add(new ListViewItem(new string[] { startTime.ToString(), startTime.AddMinutes(15).ToString(), weekly }));
             startTime = startTime.AddMinutes(15);                                  //add the next 15 minute time block
         }
     }
 }
コード例 #5
0
        private void addCommits(string timeSlot, int tutorId, int tuteeId, List <TutorMaster.Commitment> tutorCommits, List <TutorMaster.Commitment> tuteeCommits, string classCode, TutorMasterDBEntities4 db, bool weekly, int numSessions)
        {
            DateTime startTime = DateTimeMethods.getStartTime(timeSlot);               //get the start time of the time slot
            DateTime endTime   = DateTimeMethods.getEndTime(timeSlot);                 //get the end time of the time slot
            DateTime saveFirst = startTime;                                            //make copies of them
            DateTime saveEnd   = endTime;


            if (!weekly)                                                               //if the request is not weekly
            {
                for (int j = 0; j < tuteeCommits.Count(); j++)
                {
                    if (DateTime.Compare(startTime, Convert.ToDateTime(tuteeCommits[j].StartTime)) <= 0 && DateTime.Compare(endTime, Convert.ToDateTime(tuteeCommits[j].StartTime)) > 0)
                    {                                                                  //if the commitment's start time is between the end time and start time, update it to a new appointment
                        tuteeCommits[j].Open     = false;
                        tuteeCommits[j].Tutoring = false;
                        tuteeCommits[j].ID       = tutorId;
                        tuteeCommits[j].Class    = classCode + "!";
                        tuteeCommits[j].Weekly   = false;
                        db.SaveChanges();
                    }
                    else if (DateTime.Compare(endTime, Convert.ToDateTime(tuteeCommits[j].StartTime)) <= 0)
                    {                                                                  //else, break out of this for loop
                        break;
                    }
                }

                for (int i = 0; i < tutorCommits.Count(); i++)
                {
                    if (DateTime.Compare(startTime, Convert.ToDateTime(tutorCommits[i].StartTime)) <= 0 && DateTime.Compare(endTime, Convert.ToDateTime(tutorCommits[i].StartTime)) > 0)
                    {                                                                 //if the commitment's start time is between the end time and start time, update it to a new appointment
                        tutorCommits[i].Open     = false;
                        tutorCommits[i].Tutoring = true;
                        tutorCommits[i].ID       = tuteeId;
                        tutorCommits[i].Class    = classCode + "!";
                        tutorCommits[i].Weekly   = false;
                        db.SaveChanges();
                    }
                    else if (DateTime.Compare(endTime, Convert.ToDateTime(tutorCommits[i].StartTime)) <= 0)
                    {                                                                   //else, break out of this for loop
                        break;
                    }
                }
            }
            else
            {
                for (int j = 0; j < tuteeCommits.Count(); j++)
                {
                    if (DateTime.Compare(startTime, Convert.ToDateTime(tuteeCommits[j].StartTime)) <= 0 && DateTime.Compare(endTime, Convert.ToDateTime(tuteeCommits[j].StartTime)) > 0)
                    {
                        if (!tuteeCommits[j].Class.ToString().Contains('!'))
                        {                                                               //if the commitment is between the start and end times, put it as an appointment
                            tuteeCommits[j].Open     = false;
                            tuteeCommits[j].Tutoring = false;
                            tuteeCommits[j].ID       = tutorId;
                            tuteeCommits[j].Class    = classCode + "!";
                            db.SaveChanges();
                        }
                    }
                    else if (DateTime.Compare(endTime, Convert.ToDateTime(tuteeCommits[j].StartTime)) <= 0)
                    {                                                                  //if it is after end time, move our range forward a week
                        startTime = startTime.AddDays(7);
                        endTime   = endTime.AddDays(7);
                        j--;
                    }
                }
                startTime = saveFirst;
                endTime   = saveEnd;
                for (int i = 0; i < tutorCommits.Count(); i++)
                {
                    if (DateTime.Compare(startTime, Convert.ToDateTime(tutorCommits[i].StartTime)) <= 0 && DateTime.Compare(endTime, Convert.ToDateTime(tutorCommits[i].StartTime)) > 0)
                    {
                        if (!tutorCommits[i].Class.ToString().Contains('!'))
                        {                                                              //if tutor commits is in the range, change it to a new appointment
                            tutorCommits[i].Open     = false;
                            tutorCommits[i].Tutoring = true;
                            tutorCommits[i].ID       = tuteeId;
                            tutorCommits[i].Class    = classCode + "!";
                            db.SaveChanges();
                        }
                    }
                    else if (DateTime.Compare(endTime, Convert.ToDateTime(tutorCommits[i].StartTime)) <= 0)
                    {                                                                  //if it is after end time, move our range forward a week
                        startTime = startTime.AddDays(7);
                        endTime   = endTime.AddDays(7);
                        i--;
                    }
                }
            }
        }
コード例 #6
0
        private void addCommits(string timeSlot, int tutorId, int tuteeId, List <TutorMaster.Commitment> tutorCommits, List <TutorMaster.Commitment> tuteeCommits, string classCode, TutorMasterDBEntities4 db, bool weekly, int numSessions)
        {
            DateTime startTime = DateTimeMethods.getStartTime(timeSlot); //get the start time of the time block
            DateTime endTime   = DateTimeMethods.getEndTime(timeSlot);   //get the end time of the time block
            DateTime saveFirst = startTime;                              //save copies of them
            DateTime saveEnd   = endTime;


            if (!weekly)                                                //if this is not weekly
            {
                for (int j = 0; j < tuteeCommits.Count(); j++)
                {
                    if (DateTime.Compare(startTime, Convert.ToDateTime(tuteeCommits[j].StartTime)) <= 0 && DateTime.Compare(endTime, Convert.ToDateTime(tuteeCommits[j].StartTime)) > 0)
                    {//if the tutee commit's start time is between our interval, then update the commitment to a finalized state
                        tuteeCommits[j].Location = tbxLocation.Text.ToString();
                        tuteeCommits[j].Open     = false;
                        tuteeCommits[j].Tutoring = false;
                        tuteeCommits[j].ID       = tutorId;
                        tuteeCommits[j].Class    = classCode + "!";
                        tuteeCommits[j].Weekly   = false;
                        db.SaveChanges();
                    }
                    else if (DateTime.Compare(endTime, Convert.ToDateTime(tuteeCommits[j].StartTime)) <= 0)
                    {//if its not, then break out the loop
                        break;
                    }
                }

                for (int i = 0; i < tutorCommits.Count(); i++)
                {
                    if (DateTime.Compare(startTime, Convert.ToDateTime(tutorCommits[i].StartTime)) <= 0 && DateTime.Compare(endTime, Convert.ToDateTime(tutorCommits[i].StartTime)) > 0)
                    {//if the tutor commit's start time is between our interval, then update the commitment to a finalized state
                        tutorCommits[i].Location = tbxLocation.Text.ToString();
                        tutorCommits[i].Open     = false;
                        tutorCommits[i].Tutoring = true;
                        tutorCommits[i].ID       = tuteeId;
                        tutorCommits[i].Class    = classCode + "!";
                        tutorCommits[i].Weekly   = false;
                        db.SaveChanges();
                    }
                    else if (DateTime.Compare(endTime, Convert.ToDateTime(tutorCommits[i].StartTime)) <= 0)
                    {//if its not, break out of the loop
                        break;
                    }
                }
            }
            else   //if the admin chooses to have this be a weekly appointment
            {
                for (int j = 0; j < tuteeCommits.Count(); j++)
                {
                    if (DateTime.Compare(startTime, Convert.ToDateTime(tuteeCommits[j].StartTime)) <= 0 && DateTime.Compare(endTime, Convert.ToDateTime(tuteeCommits[j].StartTime)) > 0)
                    {//if the tutee commitment is between the time slot, put it to a finalized state
                        if (!tuteeCommits[j].Class.ToString().Contains('!'))
                        {
                            tuteeCommits[j].Location = tbxLocation.Text.ToString();
                            tuteeCommits[j].Open     = false;
                            tuteeCommits[j].Tutoring = false;
                            tuteeCommits[j].ID       = tutorId;
                            tuteeCommits[j].Class    = classCode + "!";
                        }
                        db.SaveChanges();
                    }
                    else if (DateTime.Compare(endTime, Convert.ToDateTime(tuteeCommits[j].StartTime)) <= 0)
                    {//if its above our current endTime, then move startTime and endTime up a week
                        startTime = startTime.AddDays(7);
                        endTime   = endTime.AddDays(7);
                        j--;
                    }
                }
                startTime = saveFirst;//reset the start and end times
                endTime   = saveEnd;
                for (int i = 0; i < tutorCommits.Count(); i++)
                {
                    if (DateTime.Compare(startTime, Convert.ToDateTime(tutorCommits[i].StartTime)) <= 0 && DateTime.Compare(endTime, Convert.ToDateTime(tutorCommits[i].StartTime)) > 0)
                    {//if the tutor commitment is between the time slot, put it to a finalized state
                        if (!tutorCommits[i].Class.ToString().Contains('!'))
                        {
                            tutorCommits[i].Location = tbxLocation.Text.ToString();
                            tutorCommits[i].Open     = false;
                            tutorCommits[i].Tutoring = true;
                            tutorCommits[i].ID       = tuteeId;
                            tutorCommits[i].Class    = classCode + "!";
                        }
                        db.SaveChanges();
                    }
                    else if (DateTime.Compare(endTime, Convert.ToDateTime(tutorCommits[i].StartTime)) <= 0)
                    {//if its above our current endTime, then move startTime and endTime up a week
                        startTime = startTime.AddDays(7);
                        endTime   = endTime.AddDays(7);
                        i--;
                    }
                }
            }
        }
コード例 #7
0
        //this binary search is to find a commitment in a list of commitments by start times. if the commit's start time is in the list, then this returns true. otherwise, it returns false
        public static bool BinarySearch(List <string> cmtList, string commit)
        {
            bool found = false;
            int  first = 0;
            int  last  = cmtList.Count() - 1;

            while (first <= last && !found)
            {
                int midpoint = (first + last) / 2;
                if (DateTime.Compare(DateTimeMethods.getStartTime(cmtList[midpoint]), DateTimeMethods.getStartTime(commit)) == 0)
                {
                    found = true;
                    return(found);
                }
                else
                {
                    if (DateTime.Compare(DateTimeMethods.getStartTime(commit), DateTimeMethods.getStartTime(cmtList[midpoint])) < 0)
                    {
                        last = midpoint - 1;
                    }
                    else
                    {
                        first = midpoint + 1;
                    }
                }
            }
            return(found);
        }
コード例 #8
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.");
            }
        }