private void submitButton_Click(object sender, RoutedEventArgs e) { if ((string)durationTimeMenu.Tag == "true" && (string)startTimeMenu.Tag == "true") { db.Appointments.Load(); db.CurrentUsers.Load(); TutoringDB.Appointment tempAppointment = new TutoringDB.Appointment(); tempAppointment.Date = (DateTime)dateDatePicker.SelectedDate; tempAppointment.Time = timeSelected.TimeOfDay; tempAppointment.Id = db.Appointments.Count(); tempAppointment.Duration = timeSpan.TimeOfDay; db.Appointments.Add(tempAppointment); db.Tutors.Load(); db.TutorTuteeCourseAppointments.Load(); TutoringDB.TutorTuteeCourseAppointment joiner = new TutoringDB.TutorTuteeCourseAppointment(); joiner.AppointmentId = tempAppointment.Id; TutoringDB.Tutee tutee = db.Tutees.Where(i => i.Username == db.CurrentUsers.FirstOrDefault().UserName).First(); joiner.TuteeId = tutee.Id; joiner.Id = db.TutorTuteeCourseAppointments.Count(); joiner.Cours = courseComboBox.SelectedItem as TutoringDB.Cours; joiner.Tutor = tutorNameComboBox.SelectedItem as TutoringDB.Tutor; db.TutorTuteeCourseAppointments.Add(joiner); db.SaveChanges(); this.Close(); } else { MessageBox.Show("All Fields Must be Filled to Schedule Appointment"); } }
private void Apply_Click(object sender, RoutedEventArgs e) { db.CurrentUsers.Load(); db.TutorCourses.Load(); db.Tutees.Load(); db.Tutors.Load(); db.Courses.Load(); db.TutorConfirmationRequests.Load(); TutoringDB.Tutee temp = new TutoringDB.Tutee(); TutoringDB.Tutor temp2 = new TutoringDB.Tutor(); TutoringDB.Cours tempcs = new TutoringDB.Cours(); TutoringDB.TutorConfirmationRequest temptcs = new TutoringDB.TutorConfirmationRequest(); if (db.CurrentUsers.FirstOrDefault().Type == "tutee") { foreach (var tte in db.Tutees) { if (db.CurrentUsers.FirstOrDefault().UserName == tte.Username) { temp = tte; } } temp2.FirstName = temp.FirstName; temp2.LastName = temp.LastName; temp2.Password = temp.Password; temp2.UserName = temp.Username; temp2.Year = temp.Year; temp2.Email = temp.Email; //temp2.Id = db.Tutors.Count(); //K:LWEKFN:OINF:EWIOLFNSMDNF:OILEKNF:SOIDLKFNEOIL?JFEWFDSFS db.Tutors.Add(temp2); //db.Tutees.Remove(temp); //FKLJFEPLDKSFNPNEIKNELFPDIMOS:LDKFN:OEIJS db.SaveChanges(); } foreach (var tut in db.Tutors) { if (db.CurrentUsers.FirstOrDefault().UserName == tut.UserName) { temp2 = tut; } } foreach (var cs in db.Courses) { if (cs.CourseName == CourseList.SelectedItem.ToString()) { tempcs = cs; temptcs.Cours = tempcs; temptcs.Tutor = temp2; } } db.TutorConfirmationRequests.Add(temptcs); db.SaveChanges(); this.Close(); }
private void tuteeBindingNavigatorSaveItem_Click(object sender, EventArgs e) { Validate(); tuteeBindingSource.EndEdit(); try { dbcontext.SaveChanges(); } catch (DbEntityValidationException) { MessageBox.Show("All Fields must contain values", "Entity Validation Exception"); } }
private void submitButton_Click(object sender, RoutedEventArgs e) { if ((string)durationTimeMenu.Tag == "true" && (string)startTimeMenu.Tag == "true") { db.BusyTimes.Load(); db.CurrentUsers.Load(); TutoringDB.BusyTime tempBusyTime = new TutoringDB.BusyTime(); tempBusyTime.Date = (DateTime)dateDatePicker.SelectedDate; tempBusyTime.Time = timeSelected.TimeOfDay; tempBusyTime.Id = db.BusyTimes.Count(); tempBusyTime.Duration = timeSpan.TimeOfDay; db.BusyTimes.Add(tempBusyTime); if (db.CurrentUsers.First().Type == "tutee") { db.Tutees.Load(); db.TuteeBusyTimes.Load(); TutoringDB.TuteeBusyTime joiner = new TutoringDB.TuteeBusyTime(); joiner.BusyTimeId = tempBusyTime.Id; TutoringDB.Tutee tutee = db.Tutees.Where(i => i.Username == db.CurrentUsers.FirstOrDefault().UserName).First(); joiner.TuteeId = tutee.Id; joiner.Id = db.TuteeBusyTimes.Count(); db.TuteeBusyTimes.Add(joiner); } else { db.TutorBusyTimes.Load(); db.Tutors.Load(); TutoringDB.TutorBusyTime joiner = new TutoringDB.TutorBusyTime(); joiner.BusyTimesId = tempBusyTime.Id; TutoringDB.Tutor tutor = db.Tutors.Where(i => i.UserName == db.CurrentUsers.FirstOrDefault().UserName).First(); joiner.TutorId = tutor.Id; joiner.Id = db.TutorBusyTimes.Count(); db.TutorBusyTimes.Add(joiner); } db.SaveChanges(); this.Close(); } else { MessageBox.Show("All Fields Must be Filled to Add Busy Time"); } }
private void submitButton_Click(object sender, RoutedEventArgs e) { if (oldPasswordBox.Password == "" || newPasswordBox.Password == "") { info.WrongOldPassword = "******"; } else { TutoringDB.TutorDatabaseEntities userCreds = new TutoringDB.TutorDatabaseEntities(); bool correctOldPassword = (userCreds.Tutors.Any(userF => userF.UserName == user.UserName && userF.Password == oldPasswordBox.Password) || userCreds.Tutees.Any(userF => userF.Username == user.UserName && userF.Password == oldPasswordBox.Password) || userCreds.Faculties.Any(userF => userF.Username == user.UserName && userF.Password == oldPasswordBox.Password)); if (correctOldPassword) { info.WrongOldPassword = "******"; if (user.Type.ToLower().Contains("tutee")) { userCreds.Tutees.Where(userT => userT.Username == user.UserName) .FirstOrDefault().Password = newPasswordBox.Password; } else if (user.Type.ToLower().Contains("tutor")) { userCreds.Tutors.Where(userT => userT.UserName == user.UserName) .FirstOrDefault().Password = newPasswordBox.Password; } else { userCreds.Faculties.Where(userT => userT.Username == user.UserName) .FirstOrDefault().Password = newPasswordBox.Password; } userCreds.SaveChanges(); } else { info.WrongOldPassword = "******"; } } DataContext = info; }
private void onNotificationClicked(object obj) { Notification selection = obj as Notification; switch (selection.Type) { case "clear": Notifications.Clear(); Notifications.Add(new Notification("Nothing here!", "empty", -1)); var clearer = from i in readUser.TutorTuteeNotifications where i.Tutor.UserName == user.UserName || i.Tutee.Username == user.UserName select i; foreach (var element in clearer) { readUser.TutorTuteeNotifications.Remove(element); } readUser.SaveChanges(); refreshNotifications(); break; case "empty": break; case "TutorTuteeCourseAppointments": if (readUser.TutorTuteeCourseAppointments.Any(appointment => appointment.Id == selection.Id)) { var appt = readUser.TutorTuteeCourseAppointments.Where(appointment => appointment.Id == selection.Id).FirstOrDefault(); AppointmentInfo seeAppt = new AppointmentInfo(appt.Appointment.Date, appt.Appointment.Time); seeAppt.ShowDialog(); refreshCalendar(0); } else { MessageBox.Show("Appointment was cancelled"); } break; } ; refreshNotifications(); }
private void addButton_Click(object sender, RoutedEventArgs e) { TutoringDB.TutorDatabaseEntities db = new TutoringDB.TutorDatabaseEntities(); db.Tutees.Load(); db.Tutors.Load(); db.Faculties.Load(); int numTutees = db.Tutees.Count(); //Error Checking if (firstNameTextBox.Text != "" && lastNameTextBox.Text != "" && usernameTextBox.Text != "" && passwordTextBox.Text != "" && (yearTextBox.Text == "1" || yearTextBox.Text == "2" || yearTextBox.Text == "3" || yearTextBox.Text == "4") && emailTextBox.Text != "" ) { TutoringDB.Tutee temp = new TutoringDB.Tutee(); temp.FirstName = firstNameTextBox.Text; temp.LastName = lastNameTextBox.Text; temp.Username = usernameTextBox.Text; temp.Password = passwordTextBox.Text; temp.Year = Convert.ToInt32(yearTextBox.Text); temp.Email = emailTextBox.Text; db.Tutees.Add(temp); db.SaveChanges(); this.Close(); Label1.Text = ""; } else { Label1.Text = "Completely fill out form"; } }
private void updateButton_Click(object sender, EventArgs e) { if (endDateTimePicker.Value < startDateTimePicker.Value) { MessageBox.Show("End Date must be after Start Date."); } else { if (db.StartEnds.Count() > 0) { foreach (TutoringDB.StartEnd i in db.StartEnds) { db.StartEnds.Remove(i); } } TutoringDB.StartEnd tempStartEnd = new TutoringDB.StartEnd(); tempStartEnd.StartDate = startDateTimePicker.Value; tempStartEnd.EndDate = endDateTimePicker.Value; db.StartEnds.Add(tempStartEnd); MessageBox.Show("Database Updated."); db.SaveChanges(); this.Close(); } }
private void fillFacultyButton_Click(object sender, EventArgs e) { TutoringDB.TutorDatabaseEntities db = new TutoringDB.TutorDatabaseEntities(); db.Faculties.Load(); db.Courses.Load(); db.FacultyCourses.Load(); //Clear database first foreach (TutoringDB.FacultyCours f in db.FacultyCourses) { db.FacultyCourses.Remove(f); } foreach (TutoringDB.Cours fc in db.Courses) { db.Courses.Remove(fc); } foreach (TutoringDB.Faculty f in db.Faculties) { db.Faculties.Remove(f); } db.SaveChanges(); TutoringDB.Faculty tempFaculty = new TutoringDB.Faculty(); TutoringDB.Cours tempCourse = new TutoringDB.Cours(); TutoringDB.FacultyCours tempFacultyCourse = new TutoringDB.FacultyCours(); //Read file line-by-line and load into database foreach (string line in File.ReadLines(@"courses-fall16.txt")) { db.Faculties.Load(); //Fill Course Fields var pieces = line.Split('\t'); tempCourse.CourseNumber = pieces[0]; tempCourse.CourseName = pieces[1]; var code = pieces[0].Split(' '); tempCourse.Department = code[0]; db.Courses.Add(tempCourse); //Fill Faculty Fields tempFaculty.Username = tempFaculty.First_Name = pieces[2]; tempFaculty.Password = tempFaculty.LastName = pieces[3]; tempFaculty.Email = pieces[2] + pieces[3] + "@coe.edu"; var temps = db.Faculties.Where(i => i.First_Name == tempFaculty.First_Name && i.LastName == tempFaculty.LastName); if (temps.Count() == 0) { db.Faculties.Add(tempFaculty); tempFacultyCourse.Faculty = tempFaculty; tempFacultyCourse.Cours = tempCourse; db.FacultyCourses.Add(tempFacultyCourse); db.SaveChanges(); } else { var first = from i in db.Faculties where i.Email == tempFaculty.Email select i; tempFacultyCourse.FacultyId = first.FirstOrDefault().Id; tempFacultyCourse.Cours = tempCourse; db.FacultyCourses.Add(tempFacultyCourse); db.SaveChanges(); } } MessageBox.Show("Successfully Loaded."); }
private void clearButton_Click(object sender, EventArgs e) { TutoringDB.TutorDatabaseEntities db = new TutoringDB.TutorDatabaseEntities(); db.TutorTuteeCourseAppointments.Load(); foreach (var i in db.TutorTuteeCourseAppointments) { db.TutorTuteeCourseAppointments.Remove(i); } db.TutorTuteeNotifications.Load(); foreach (var i in db.TutorTuteeNotifications) { db.TutorTuteeNotifications.Remove(i); } db.TutorConfirmationRequests.Load(); foreach (var i in db.TutorConfirmationRequests) { db.TutorConfirmationRequests.Remove(i); } db.TutorCourses.Load(); foreach (var i in db.TutorCourses) { db.TutorCourses.Remove(i); } db.TutorBusyTimes.Load(); foreach (var i in db.TutorBusyTimes) { db.TutorBusyTimes.Remove(i); } db.FacultyCourses.Load(); foreach (var i in db.FacultyCourses) { db.FacultyCourses.Remove(i); } db.TuteeBusyTimes.Load(); foreach (var i in db.TuteeBusyTimes) { db.TuteeBusyTimes.Remove(i); } db.Appointments.Load(); foreach (var i in db.Appointments) { db.Appointments.Remove(i); } db.BaseSchedules.Load(); foreach (var i in db.BaseSchedules) { db.BaseSchedules.Remove(i); } db.BusyTimes.Load(); foreach (var i in db.BusyTimes) { db.BusyTimes.Remove(i); } db.Courses.Load(); foreach (var i in db.Courses) { db.Courses.Remove(i); } db.CurrentUsers.Load(); foreach (var i in db.CurrentUsers) { db.CurrentUsers.Remove(i); } db.Faculties.Load(); foreach (var i in db.Faculties) { db.Faculties.Remove(i); } db.StartEnds.Load(); foreach (var i in db.StartEnds) { db.StartEnds.Remove(i); } db.Tutees.Load(); foreach (var i in db.Tutees) { db.Tutees.Remove(i); } db.Tutors.Load(); foreach (var i in db.Tutors) { db.Tutors.Remove(i); } db.SaveChanges(); MessageBox.Show("Successfully Cleared."); }
private void fillTutorsTutees_Click(object sender, EventArgs e) { TutoringDB.TutorDatabaseEntities db = new TutoringDB.TutorDatabaseEntities(); db.Tutors.Load(); db.Tutees.Load(); db.TutorCourses.Load(); //Clear database first foreach (TutoringDB.Tutor t in db.Tutors) { db.Tutors.Remove(t); } foreach (TutoringDB.Tutee f in db.Tutees) { db.Tutees.Remove(f); } foreach (TutoringDB.TutorCourse tc in db.TutorCourses) { db.TutorCourses.Remove(tc); } db.SaveChanges(); TutoringDB.Tutor tempTutor = new TutoringDB.Tutor(); TutoringDB.Tutee tempTutee = new TutoringDB.Tutee(); //Fill Tutors foreach (string line in File.ReadLines(@"fakeTutors.csv")) { db.Tutors.Load(); db.Tutees.Load(); db.TutorCourses.Load(); var split = line.Split('|'); tempTutor.FirstName = split[0]; tempTutor.LastName = split[1]; tempTutor.UserName = split[2]; tempTutor.Password = split[3]; tempTutor.Email = split[4]; Random year = new Random(); tempTutor.Year = year.Next(1, 4); db.Tutors.Add(tempTutor); //Randomly matches tutors with courses Random rnd = new Random(); int limit = rnd.Next(4); db.SaveChanges(); db.Courses.Load(); //var courselist = db.Courses.Local; //for (int i = 0; i< limit; i++) //{ // int max = db.Courses.Count(); // tempTutorCourse.Cours = courselist[rnd.Next(0,max)]; // tempTutorCourse.TutorId = tempTutor.Id+1; // db.TutorCourses.Add(tempTutorCourse); //} //db.SaveChanges(); } //Fill Tutees foreach (string line in File.ReadLines(@"fakeTutees.csv")) { db.Tutors.Load(); db.Tutees.Load(); db.TutorCourses.Load(); var split = line.Split('|'); tempTutee.FirstName = split[0]; tempTutee.LastName = split[1]; tempTutee.Username = split[2]; tempTutee.Password = split[3]; tempTutee.Email = split[4]; Random year = new Random(); tempTutee.Year = year.Next(1, 4); db.Tutees.Add(tempTutee); db.SaveChanges(); } List <TutoringDB.TutorCourse> tcList = new List <TutoringDB.TutorCourse>(); db.Courses.Load(); db.Tutors.Load(); var tutorlist = db.Tutors.Local.ToList(); var courselist = db.Courses.Local.ToList(); int index = 0; foreach (TutoringDB.Cours c in courselist) { Random rnd = new Random(); int lim = rnd.Next(2, 5); for (int i = 0; i < lim; i++) { TutoringDB.TutorCourse tempTutorCourse = new TutoringDB.TutorCourse(); tempTutorCourse.Cours = c; tempTutorCourse.Tutor = tutorlist[index % tutorlist.Count()]; index++; tcList.Add(tempTutorCourse); } } for (int i = 0; i < tcList.Count; i++) { db.TutorCourses.Load(); db.TutorCourses.Add(tcList.ElementAt(i)); db.SaveChanges(); } db.SaveChanges(); MessageBox.Show("Successfully Loaded."); }