private void addCommit(TutorMaster.Commitment commit) { TutorMasterDBEntities4 db = new TutorMasterDBEntities4(); //add a commitment db.Commitments.AddObject(commit); db.SaveChanges(); }
public static bool sameCategory(TutorMaster.Commitment commitFirst, TutorMaster.Commitment commitSecond) //ask if the 15 minute time block of the first has the same values as the second { string class1; string class2; if (commitFirst.Class == "@") //if there is an @ sign, treat it as if it is - so the cancelled time can go with its adjacent open times { class1 = "-"; } else { class1 = commitFirst.Class; } if (commitSecond.Class == "@") //do the same for the second commitment passed in here { class2 = "-"; } else { class2 = commitSecond.Class; } return(class1 == class2 && commitFirst.Location == commitSecond.Location && //check all of the information except for the dateTimes of both commitments commitFirst.Open == commitSecond.Open && commitFirst.Weekly == commitSecond.Weekly && //all of the information must be the same in order for them to be in the same category commitFirst.ID == commitSecond.ID); }
private void add15Block(DateTime begin, bool weekly) { int lastCR = getNextCmtId(); //last commit row int lastSCR = getNextStdCmtKey(); //last student commit row //add the first student committment and comittment in case the commitment is not weekly TutorMaster.Commitment newCommit = new TutorMaster.Commitment(); newCommit.CmtID = lastCR; newCommit.Class = "-"; newCommit.Location = "-"; newCommit.Tutoring = false; newCommit.StartTime = begin; newCommit.Open = true; newCommit.Weekly = weekly; newCommit.ID = -1; addCommit(newCommit); TutorMaster.StudentCommitment newStudentCommit = new TutorMaster.StudentCommitment(); newStudentCommit.CmtID = lastCR; newStudentCommit.ID = id; newStudentCommit.Key = lastSCR; addStudentCommit(newStudentCommit); DateTime endOfSemester = new DateTime(2017, 6, 1, 0, 0, 0); //if it is weekly, keep going 7 days into future and if it is before end of semster, add the new commitment if (weekly) { while (begin.AddDays(7).CompareTo(endOfSemester) < 0) { begin = begin.AddDays(7); lastSCR += 1; lastCR += 1; //add the commitment first and then add the student commitment TutorMaster.Commitment newCommitW = new TutorMaster.Commitment(); newCommitW.CmtID = lastCR; newCommitW.Class = "-"; newCommitW.Location = "-"; newCommitW.Tutoring = false; newCommitW.StartTime = begin; newCommitW.Open = true; newCommitW.Weekly = weekly; newCommitW.ID = -1; addCommit(newCommitW); //add the student commitment weekly TutorMaster.StudentCommitment newStudentCommitW = new TutorMaster.StudentCommitment(); newStudentCommitW.CmtID = lastCR; newStudentCommitW.ID = id; newStudentCommitW.Key = lastSCR; addStudentCommit(newStudentCommitW); } } }
private List <string> getValidSlots(ref List <TutorMaster.Commitment> cmtList, int sessionLength) { int consecutiveCommits = 0; List <string> validSlots = new List <string>(); TutorMaster.Commitment initialCommit = cmtList[0]; DateTime startDate = Convert.ToDateTime(cmtList[0].StartTime); DateTime endDate = Convert.ToDateTime(cmtList[0].StartTime).AddMinutes(15); consecutiveCommits++; if (sessionLength == 1) { for (int i = 0; i < cmtList.Count(); i++) { DateTime start = Convert.ToDateTime(cmtList[i].StartTime); DateTime end = Convert.ToDateTime(cmtList[i].StartTime).AddMinutes(15); validSlots.Add(start.ToString() + "," + end.ToString()); } } else { for (int i = 0; i < cmtList.Count() - 1; i++) { DateTime currentCommitDate = Convert.ToDateTime(cmtList[i].StartTime); //get datetime of commitment we are on in loop DateTime nextCommitDate = Convert.ToDateTime(cmtList[i + 1].StartTime); //get datetime of commitment ahead of it if (DateTime.Compare(nextCommitDate, currentCommitDate.AddMinutes(15)) == 0 && consecutiveCommits < sessionLength) //if our next commit is 15 minutes later of our current and we are below threshold { consecutiveCommits++; //increment the consec counter endDate = Convert.ToDateTime(cmtList[i].StartTime).AddMinutes(15); //move end date up 15 minutes } else if (DateTime.Compare(nextCommitDate, currentCommitDate.AddMinutes(15)) == 0 && consecutiveCommits >= sessionLength) //if we are above the threshold and next commit is adjacent { endDate = Convert.ToDateTime(cmtList[i].StartTime).AddMinutes(15); //move up the end date validSlots.Add(startDate.ToString() + "," + endDate.ToString()); //add the valid slot startDate = startDate.AddMinutes(15); //move up the start date } else if (DateTime.Compare(nextCommitDate, currentCommitDate.AddMinutes(15)) != 0 && consecutiveCommits >= sessionLength) //if not adajacent but above threshold { endDate = Convert.ToDateTime(cmtList[i].StartTime).AddMinutes(15); //move up the enddate validSlots.Add(startDate.ToString() + "," + endDate.ToString()); //add the validslots //update our carries consecutiveCommits = 1; startDate = Convert.ToDateTime(cmtList[i + 1].StartTime); endDate = Convert.ToDateTime(cmtList[i + 1].StartTime).AddMinutes(15); initialCommit = cmtList[i + 1]; } else if (DateTime.Compare(nextCommitDate, currentCommitDate.AddMinutes(15)) != 0 && consecutiveCommits < sessionLength) //if not adjacent and not above the threshold { //update carries and set consec counter to 1 consecutiveCommits = 1; startDate = Convert.ToDateTime(cmtList[i + 1].StartTime); endDate = Convert.ToDateTime(cmtList[i + 1].StartTime).AddMinutes(15); initialCommit = cmtList[i + 1]; } } //handle the last commitment if (consecutiveCommits >= sessionLength && DateTime.Compare(Convert.ToDateTime(cmtList[cmtList.Count() - 2].StartTime).AddMinutes(15), Convert.ToDateTime(cmtList[cmtList.Count() - 1].StartTime)) == 0) { endDate = endDate.AddMinutes(15); //move the end date up by 15 minutes validSlots.Add(startDate.ToString() + "," + endDate.ToString()); //add the valid slots } else if (consecutiveCommits == sessionLength && DateTime.Compare(Convert.ToDateTime(cmtList[cmtList.Count() - 2].StartTime).AddMinutes(15), Convert.ToDateTime(cmtList[cmtList.Count() - 1].StartTime)) == 0) { endDate = endDate.AddMinutes(15); validSlots.Add(startDate.ToString() + "," + endDate.ToString()); } } return(validSlots); }
private bool sameCategory(TutorMaster.Commitment commitFirst, TutorMaster.Commitment commitSecond) //ask if the 15 minute time block of the first has the same values as the second { return(commitFirst.Class == commitSecond.Class && commitFirst.Location == commitSecond.Location && commitFirst.Open == commitSecond.Open && commitFirst.Weekly == commitSecond.Weekly && commitFirst.ID == commitSecond.ID); }
//QuickSort functions //this QuickSort sorts a commitment list by datetimes private static void Split(ref List <TutorMaster.Commitment> values, int first, int last, ref int splitPoint) { int center = (first + last) / 2; int median = 0; DateTime valueF = Convert.ToDateTime(values[first].StartTime); DateTime valueC = Convert.ToDateTime(values[center].StartTime); DateTime valueL = Convert.ToDateTime(values[last].StartTime); if ((DateTime.Compare(valueF, valueC) >= 0 && DateTime.Compare(valueF, valueL) <= 0) || (DateTime.Compare(valueF, valueL) >= 0 && DateTime.Compare(valueF, valueL) <= 0)) { median = first; } else if (DateTime.Compare(valueC, valueF) >= 0 && (DateTime.Compare(valueC, valueL) <= 0) || (DateTime.Compare(valueC, valueF)) >= 0 && (DateTime.Compare(valueC, valueL) <= 0)) { median = center; } else { median = last; } //Swap the median and first committments in the list TutorMaster.Commitment temp = values[first]; values[first] = values[median]; values[median] = temp; valueF = Convert.ToDateTime(values[first].StartTime); //get current first datetime valueC = Convert.ToDateTime(values[center].StartTime); //get current center datetime; valueL = Convert.ToDateTime(values[last].StartTime); TutorMaster.Commitment splitVal = values[first]; DateTime splitDate = Convert.ToDateTime(values[first].StartTime); int saveFirst = first; bool onCorrectSide = true; first++; valueF = Convert.ToDateTime(values[first].StartTime); do { onCorrectSide = true; while (onCorrectSide) { if (DateTime.Compare(valueF, splitDate) > 0) { onCorrectSide = false; } else { first++; valueF = Convert.ToDateTime(values[first].StartTime); onCorrectSide = (first <= last); } } onCorrectSide = (first <= last); while (onCorrectSide) { if (DateTime.Compare(valueL, splitDate) <= 0) { onCorrectSide = false; } else { last--; valueL = Convert.ToDateTime(values[last].StartTime); onCorrectSide = (first <= last); } } if (first < last) { TutorMaster.Commitment temp2 = values[first]; values[first] = values[last]; values[last] = temp2; first++; last--; valueF = Convert.ToDateTime(values[first].StartTime); valueL = Convert.ToDateTime(values[last].StartTime); } } while (first <= last); splitPoint = last; TutorMaster.Commitment temp3 = values[saveFirst]; values[saveFirst] = values[splitPoint]; values[splitPoint] = temp3; }
public static string getCommitTime(TutorMaster.Commitment commit) //get the c# datetime object of the commit's start time and cast it to a string { return(Convert.ToDateTime(commit.StartTime).ToString().Split(' ')[1] + " " + Convert.ToDateTime(commit.StartTime).ToString().Split(' ')[2]); }
public static bool isAccepted(TutorMaster.Commitment commit) //criteria for a commitment to be in the accepted state { return(commit.Class != "-" && !commit.Location.Contains('?') && commit.Location != "-" && commit.Open == false && commit.ID != -1); }
public static bool waitingForTutee(TutorMaster.Commitment commit) //criteria for a commitment to be waiting for a tutee { return(commit.Class != "-" && commit.Location.Contains('?') && commit.Open == false && commit.Tutoring == true && commit.ID != -1); }
public static bool waitingForLocation(TutorMaster.Commitment commit) //criteria for a commitment to be waiting for a location { return(commit.Class != "-" && commit.Location == "-" && commit.Open == false && commit.Tutoring == true && commit.ID != -1); }
public static bool isOpen(TutorMaster.Commitment commit) //criteria for a commitment to be open { return(commit.Class == "-" && commit.Location == "-" && commit.Open == true && commit.Tutoring == false && commit.ID == -1); }
public static string getCommitTime15(TutorMaster.Commitment commit15) //get the c# datetime object of the commit's start time 15 minutes in the future and cast it to a string { return(Convert.ToDateTime(commit15.StartTime).AddMinutes(15).ToString().Split(' ')[1] + " " + Convert.ToDateTime(commit15.StartTime).ToString().Split(' ')[2]); }