private void btnAccept_Click(object sender, EventArgs e) { //This will need to change each student account selected and then remove the pending requests from the DB TutorMasterDBEntities4 db = new TutorMasterDBEntities4(); //side note, we should carefully control the life cycle of object contexts like these //open the db int reqNum = lvPendingRequests.CheckedItems.Count; //identify how many requests have been checked for (int i = 0; i < reqNum; i++) //iterate for how many requests have been clicked { string CC = lvPendingRequests.CheckedItems[i].SubItems[1].Text; //pull the classcode from the request in question string Id = lvPendingRequests.CheckedItems[i].SubItems[2].Text; int Id2 = Int32.Parse(Id); //Change the string into an int, this is really fragile if a bad id number is put in the system somehow. typechecking for those ids should prevent it StudentClass newClass = new StudentClass(); newClass.Key = getNextRequestKey(); newClass.ClassCode = CC; newClass.ID = Id2; db.StudentClasses.AddObject(newClass); Student tutor = (from row in db.Students where row.ID == Id2 select row).First(); tutor.Tutor = true; TutorRequest delU = (from row in db.TutorRequests where ((row.ClassCode == CC) && (row.ID == Id2)) select row).First(); //find the request that has the right ID and class code if (delU != null) { db.TutorRequests.DeleteObject(delU); //delete the object in the db db.SaveChanges(); //save the cahnges to the db } } db.SaveChanges(); MessageBox.Show("The selected tutor requests have been accepted and the tutors have been approved to tutor the selected courses"); lvPendingRequests.Clear(); //clean out the box SetupPendingRequests(id); //Set up the box again }
private void addStudentCommit(TutorMaster.StudentCommitment studentCommit) //add a student commitment { TutorMasterDBEntities4 db = new TutorMasterDBEntities4(); db.StudentCommitments.AddObject(studentCommit); db.SaveChanges(); }
private void setTuteeLocations() { TutorMasterDBEntities4 db = new TutorMasterDBEntities4(); //Connect to the database string loc = txtLoc.Text; //grab the text of the location the tutor typed in for (int i = 0; i < info.Count(); i++) //for every time chosen { DateTime startDate = DateTimeMethods.getStartTime(info[i]); //get the startTime DateTime endDate = DateTimeMethods.getEndTime(info[i]); //get the endTime int partnerID = Convert.ToInt32(info[i].Split(',')[2]); List <Commitment> tuteeCmtList = (from stucmt in db.StudentCommitments //get the tutee's commitments where stucmt.ID == partnerID join cmt in db.Commitments on stucmt.CmtID equals cmt.CmtID select cmt).ToList(); //if a commitment is in the time slot for (int m = 0; m < tuteeCmtList.Count(); m++) //go through the tutee commitments { if (DateTimeMethods.inTheTimeSlot(startDate, endDate, tuteeCmtList[m])) { tuteeCmtList[m].Class = tuteeCmtList[m].Class + "!"; //add an exclamation point to the tutee class so that the system knows this is a new commitment if (!admin) { tuteeCmtList[m].Location = loc + "?"; //change the location to the string the user typed in + a question mark } else { tuteeCmtList[m].Location = loc; } db.SaveChanges(); //save to database } } } }
private void setTutorLocations() { TutorMasterDBEntities4 db = new TutorMasterDBEntities4(); //Connect to the database string loc = txtLoc.Text; //grab the text of the location the tutor typed in List <Commitment> tutorCmtList = (from stucmt in db.StudentCommitments //get the tutor's commitments where stucmt.ID == id join cmt in db.Commitments on stucmt.CmtID equals cmt.CmtID select cmt).ToList(); for (int i = 0; i < info.Count(); i++) //for every time chosen { DateTime startDate = DateTimeMethods.getStartTime(info[i]); //get the startTime DateTime endDate = DateTimeMethods.getEndTime(info[i]); //get the endTime for (int c = 0; c < tutorCmtList.Count(); c++) //go through the tutor commitments { if (DateTimeMethods.inTheTimeSlot(startDate, endDate, tutorCmtList[c])) //if a commitment is in the time slot { if (!admin) { tutorCmtList[c].Location = loc + "?"; //change the location to the string the user typed in + a question mark } else { tutorCmtList[c].Location = loc; //change the location to the string the user typed in } db.SaveChanges(); //save to database } } } }
private void btnReject_Click(object sender, EventArgs e) //This Button now works fully! addition functionality would be eror checking for parse function and sending message to students and administrators once we set that up. { //This will need to remove all the requests from the DB and leave all acounts unchanged. Eventually, it will send a message to the admin account TutorMasterDBEntities4 db = new TutorMasterDBEntities4(); //side note, we should carefully control the life cycle of object contexts like these //open the db int reqNum = lvPendingRequests.CheckedItems.Count; //identify how many requests have been checked for (int i = 0; i < reqNum; i++) //iterate for how many requests have been clicked { string CC = lvPendingRequests.CheckedItems[i].SubItems[1].Text; //pull the classcode from the request in question string Id = lvPendingRequests.CheckedItems[i].SubItems[2].Text; int Id2 = Int32.Parse(Id); //Change the string into an int //This line creates text objects that look like 'FIRST LAST CLASS-123 ID' you may want to split the string to get the class code, but you also need the student ID TutorRequest delU = (from row in db.TutorRequests where ((row.ClassCode == CC) && (row.ID == Id2)) select row).First(); //find the request that has the right ID and class code if (delU != null) { db.TutorRequests.DeleteObject(delU); //delete the object in the db db.SaveChanges(); //save the cahnges to the db } } MessageBox.Show("The selected requests have been rejected and the selected tutors have not been approved for the requests courses."); lvPendingRequests.Clear(); //clean out the box SetupPendingRequests(id); //Set up the box again }
private void btnChangePassword_Click(object sender, EventArgs e) { TutorMasterDBEntities4 db = new TutorMasterDBEntities4(); //open the database User user = (from row in db.Users.AsEnumerable() where row.ID == id select row).First(); //get the user account string accountType = user.AccountType; //get the accountType of the user string oldPassword = user.Password; //get the password of the user string inputOld = txtOldPass.Text; //get the password they put in the old password textbox string inputNew = txtNewPass.Text; //get the new password they put in the new password textbox string inputConfirm = txtConfirm.Text; //get the confirmation of the password they put in the confirmation textbox if (string.IsNullOrWhiteSpace(oldPassword) || string.IsNullOrWhiteSpace(inputNew) || string.IsNullOrWhiteSpace(inputConfirm)) //check if they put something in each text box { MessageBox.Show("Please enter your old password, new password, and confirm your new password."); } else if (oldPassword != inputOld) //check if the old password matches what they put in { MessageBox.Show("Your old password and the password you put in as your old password do not match."); } else if (inputNew != inputConfirm) //check if the new password they put in and the confirmation as the same { MessageBox.Show("The new password you typed in and its confirmation do not match."); } else { user.Password = inputNew; //update the database db.SaveChanges(); backToMain(accountType); //go back to the right main form } }
private void addCommit(TutorMaster.Commitment commit) { TutorMasterDBEntities4 db = new TutorMasterDBEntities4(); //add a commitment db.Commitments.AddObject(commit); db.SaveChanges(); }
private void addRequest(TutorMaster.TutorRequest request) //add tutor request to the datbase { TutorMasterDBEntities4 db = new TutorMasterDBEntities4(); db.TutorRequests.AddObject(request); db.SaveChanges(); }
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 } } } }
private void saveClasses() { TutorMasterDBEntities4 db = new TutorMasterDBEntities4(); //var numReq = db.TutorRequests.Count(x => x.ID == accID); var requestClasses = (from stucla in db.TutorRequests where stucla.ID == accID join cla in db.Classes on stucla.ClassCode equals cla.ClassCode select cla).ToList(); var acceptedClasses = (from stucla in db.StudentClasses where stucla.ID == accID join cla in db.Classes on stucla.ClassCode equals cla.ClassCode select cla).ToList(); int numDepartments = tvClasses.Nodes.Count; for (int i = 0; i < numDepartments; i++) { int numNodes = tvClasses.Nodes[i].Nodes.Count; for (int j = 0; j < numNodes; j++) //loop through each class in each department and check whether the node is checked { TreeNode tn = tvClasses.Nodes[i].Nodes[j]; if (!tn.Checked) { //if already approved but not checked, delete from approved if (acceptedClasses.Exists(x => x.ClassName.Equals(tn.Text))) { string classCode = acceptedClasses.Find(x => x.ClassName.Equals(tn.Text)).ClassCode; db.StudentClasses.DeleteObject((from row in db.StudentClasses where row.ClassCode == classCode select row).First()); } //if requested and unchecked, delete from requests if (requestClasses.Exists(x => x.ClassName.Equals(tn.Text))) { string classCode = requestClasses.Find(x => x.ClassName.Equals(tn.Text)).ClassCode; db.TutorRequests.DeleteObject((from row in db.TutorRequests where row.ClassCode == classCode select row).First()); } } //if not approved or requested but checked, submit a request else { if (!(acceptedClasses.Exists(x => x.ClassName.Equals(tn.Text))) && !(requestClasses.Exists(x => x.ClassName.Equals(tn.Text)))) { TutorMaster.TutorRequest request = new TutorMaster.TutorRequest(); request.Key = getNextRequestKey(); request.ID = accID; string classCode = (from row in db.Classes where row.ClassName == tn.Text select row.ClassCode).First(); request.ClassCode = classCode; addRequest(request); } } } } db.SaveChanges(); }
private void saveNewTutorTutee(bool tutor, bool tutee, int id) { TutorMasterDBEntities4 db = new TutorMasterDBEntities4(); //connect to database Student newStudent = new Student(); //make new student object newStudent.Tutee = tutee; //load up the information newStudent.Tutor = tutor; newStudent.ID = id; db.Students.AddObject(newStudent); //add the tutor/tutee to the database db.SaveChanges(); //save the changes }
private void saveNewUser(string fname, string lname, string username, string password, string email, string phone, string accounttype, int id) { TutorMasterDBEntities4 db = new TutorMasterDBEntities4(); //connection to new database User newUser = new User(); //create a new user and load him up with the information newUser.ID = id; newUser.FirstName = fname; newUser.LastName = lname; newUser.Username = username; newUser.Password = password; newUser.Email = email; newUser.AccountType = accounttype; newUser.PhoneNumber = phone; db.Users.AddObject(newUser); //add them to the users table in the database db.SaveChanges(); //save the changes to the database }
private void removeAllClasses() //remove all a users tutor classes and tutor requests { TutorMasterDBEntities4 db = new TutorMasterDBEntities4(); var requests = (from row in db.TutorRequests where row.ID == accID select row).ToList(); var accepts = (from row in db.StudentClasses where row.ID == accID select row).ToList(); foreach (TutorRequest tr in requests) { db.DeleteObject(tr); } foreach (StudentClass sc in accepts) { db.DeleteObject(sc); } db.SaveChanges(); }
private void btnAdd_Click(object sender, EventArgs e) { string fname = txtFirstname.Text; //gets information from the form fields string lname = txtLastname.Text; string username = txtUsername.Text; string password = txtPassword.Text; string phone = txtPhoneNumber.Text; string email = txtEmail.Text; string accounttype = "Student"; bool tutor = cbxTutor.Checked; bool tutee = cbxTutee.Checked; TutorMasterDBEntities4 db = new TutorMasterDBEntities4(); if (goodToAdd(fname, lname, username, password, phone, email, tutor, tutee)) //checks if the form is filled out appropriately { if (action == EDIT) //if the user is editing a student { if (tutor) //save the classes if student is a tutor { saveClasses(); } else //if tutor status has been removed, remove all the classes they were approved for/had requested { if ((bool)(from row in db.Students where row.ID == accID select row.Tutor).First()) { removeAllClasses(); } } User updateUser = (from row in db.Users where row.ID == accID select row).Single(); //get the user object from the database updateUser.FirstName = fname; //update the object to admin input updateUser.LastName = lname; updateUser.Username = username; updateUser.Password = password; updateUser.PhoneNumber = phone; updateUser.Email = email; updateUser.AccountType = accounttype; Student updateStudent = (from row in db.Students where row.ID == accID select row).Single(); //get the Student object from the database updateStudent.Tutor = tutor; //update the object to admin input updateStudent.Tutee = tutee; db.SaveChanges(); //save changes AdminMain g = new AdminMain(); //return to admin main g.Show(); this.Dispose(); } else //user is in request or create mode { int ID = getNextID(); //gets ID for new user if (action == REQUEST) //if in request mode, adds the indicator to the end of the username { username += "?"; } saveNewUser(fname, lname, username, password, email, phone, accounttype, ID); //saves the user and student account to the database saveNewTutorTutee(tutor, tutee, ID); if (tutor) //if tutor, sends appropriate tutor requests { int numDepartments = tvClasses.Nodes.Count; for (int i = 0; i < numDepartments; i++) //loop through departments { int numNodes = tvClasses.Nodes[i].Nodes.Count; //for each class in a department for (int j = 0; j < numNodes; j++) { TreeNode tn = tvClasses.Nodes[i].Nodes[j]; if (tn.Checked) //check if the class is checked { TutorMaster.TutorRequest request = new TutorMaster.TutorRequest(); //create the request request.Key = getNextRequestKey(); request.ID = ID; string classCode = (from row in db.Classes where row.ClassName == tn.Text select row.ClassCode).First(); request.ClassCode = classCode; addRequest(request); //add request to database } } } } uncheckTree(); //reset the form txtFirstname.Text = ""; txtLastname.Text = ""; txtUsername.Text = ""; txtPassword.Text = ""; txtPhoneNumber.Text = ""; txtEmail.Text = ""; cbxTutor.Checked = false; cbxTutee.Checked = false; if (action == CREATE) //show user appropriate message { MessageBox.Show("Student has been added to the database."); } else { MessageBox.Show("Request has been sent to the administrator."); } } } }
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--; } } } }
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--; } } } }
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."); } }