private void learningExperienceSave() { Learning_Experience expROW = studentLearningExperiences_DataGrid.SelectedItem as Learning_Experience; if (learningExperienceFieldsCheck(expROW)) { if (dbMethods.CheckDatabaseConnection()) { using (PubsDataContext db = new PubsDataContext()) { //Learning_Experience exp = (from s in db.Learning_Experiences // where s.Student_ID == expROW.Student_ID // select s); var completionList = new List <Learning_Experience>(from s in db.Learning_Experiences where s.ID == expROW.ID select s); if (completionList.Count > 0) { var completion = completionList.First(); completion.Student_ID = student.Student_ID; completion.ConfirmedHours = expROW.ConfirmedHours; completion.CourseNumber = expROW.CourseNumber; completion.LiabilityWaiver = expROW.LiabilityWaiver; completion.ProjectAgreement = expROW.ProjectAgreement; completion.Semester = expROW.Semester; completion.Year = expROW.Year; completion.TimeLog = expROW.TimeLog; completion.TotalHours = expROW.TotalHours; completion.TypeofLearning = expROW.TypeofLearning; completion.Section = expROW.Section; completion.Professor = expROW.Professor; completion.CourseName = expROW.CourseName; db.SubmitChanges(); LoadStudentLearningExperiences(); } else { Learning_Experience exp = new Learning_Experience(); exp.Student_ID = student.Student_ID; exp.ConfirmedHours = expROW.ConfirmedHours; exp.CourseNumber = expROW.CourseNumber; exp.LiabilityWaiver = expROW.LiabilityWaiver; exp.ProjectAgreement = expROW.ProjectAgreement; exp.Semester = expROW.Semester; exp.Year = expROW.Year; exp.TimeLog = expROW.TimeLog; exp.TotalHours = expROW.TotalHours; exp.TypeofLearning = expROW.TypeofLearning; db.Learning_Experiences.InsertOnSubmit(exp); db.SubmitChanges(); LoadStudentLearningExperiences(); } } } } }
private void save_BTN_Click(object sender, RoutedEventArgs e) { if (dbMethods.CheckDatabaseConnection()) { using (PubsDataContext db = new PubsDataContext()) { if (studentID_TB.Text.Length > 0 && graduationYear_TB.Text.Length > 0) { var CheckExists = (from s in db.Students where s.Student_ID == Convert.ToInt32(studentID_TB.Text) select s); //if the user does not exists, application will create a new user if (CheckExists.Count() == 0) { student.Student_ID = Convert.ToInt32(studentID_TB.Text); student.FirstName = studentFirstName_TB.Text; student.LastName = studentLastName_TB.Text; student.GraduationYear = Convert.ToInt32(graduationYear_TB.Text); student.Email = studentemail_TB.Text; Learning_Experience exp = new Learning_Experience(); exp.Student_ID = Convert.ToInt32(studentID_TB.Text); db.Students.InsertOnSubmit(student); db.Learning_Experiences.InsertOnSubmit(exp); db.SubmitChanges(); LoadStudentLearningExperiences(); } else { //save student info Student stud = (from s in db.Students where s.Student_ID == student.Student_ID select s).Single(); stud.Student_ID = Convert.ToInt32(studentID_TB.Text); stud.FirstName = studentFirstName_TB.Text; stud.LastName = studentLastName_TB.Text; stud.GraduationYear = Convert.ToInt32(graduationYear_TB.Text); stud.Email = studentemail_TB.Text; //saves experience by calling the save experiences button event learningExperienceSave(); db.SubmitChanges(); } } else { MessageBox.Show( "SLApp apologizes for the inconvenience, but at this time all fields must contain data before saving.", "Save Error!", MessageBoxButton.OK, MessageBoxImage.Error); } //this.Close(); } } }
private void deleteUser_BTN_Click(object sender, RoutedEventArgs e) { if (dbMethods.CheckDatabaseConnection()) { if (MessageBox.Show("Are you sure you want to delete this user?", "Confirm Delete!", MessageBoxButton.YesNo) == MessageBoxResult.Yes) { using (PubsDataContext db = new PubsDataContext()) { Application_User expROW = users_DataGrid.SelectedItem as Application_User; var completionList = new List <Application_User>(from s in db.Application_Users where s.Username == expROW.Username select s); if (expROW != null && completionList.Any()) { var completion = completionList.First(); db.Application_Users.DeleteOnSubmit(completion); db.SubmitChanges(); LoadUsers(users_DataGrid); } else { LoadUsers(users_DataGrid); } } } } }
private void learningExperienceDelete() { if (dbMethods.CheckDatabaseConnection()) { if (MessageBox.Show("Are you sure you want to delete this learning experience?", "Confirm Delete!", MessageBoxButton.YesNo) == MessageBoxResult.Yes) { using (PubsDataContext db = new PubsDataContext()) { Learning_Experience expROW = studentLearningExperiences_DataGrid.SelectedItem as Learning_Experience; var completionList = new List <Learning_Experience>(from s in db.Learning_Experiences where s.ID == expROW.ID select s); if (expROW != null && completionList.Any()) { var completion = completionList.First(); db.Learning_Experiences.DeleteOnSubmit(completion); db.SubmitChanges(); LoadStudentLearningExperiences(); } else { LoadStudentLearningExperiences(); } } } } }
private void delete_BTN_Click(object sender, RoutedEventArgs e) { if (dbMethods.CheckDatabaseConnection()) { if (MessageBox.Show("Are you sure you want to delete this student?", "Confirm Delete!", MessageBoxButton.YesNo) == MessageBoxResult.Yes) { using (PubsDataContext db = new PubsDataContext()) { if (studentID_TB.Text.Length > 0 && graduationYear_TB.Text.Length > 0) { Student stud = (from s in db.Students where s.Student_ID == student.Student_ID select s).Single(); var completionList = new List <Learning_Experience>(from s in db.Learning_Experiences where s.Student_ID == student.Student_ID select s); db.Students.DeleteOnSubmit(stud); db.Learning_Experiences.DeleteAllOnSubmit(completionList); db.SubmitChanges(); this.Close(); } else { MessageBox.Show( "SLApp apologizes for the inconvenience, but you cannot delete an empty profile.", "Delete Error!", MessageBoxButton.OK, MessageBoxImage.Error); } } } } }
private void saveUser_BTN_Click(object sender, RoutedEventArgs e) { Application_User userROW = users_DataGrid.SelectedItem as Application_User; if (userROW != null) { if (dbMethods.CheckDatabaseConnection()) { using (PubsDataContext db = new PubsDataContext()) { var completionList = new List <Application_User>(from s in db.Application_Users where s.Username == userROW.Username select s); if (completionList.Count > 0) { var completion = completionList.First(); completion.Username = userROW.Username; completion.Password = userROW.Password; completion.LastName = userROW.LastName; completion.IsAdmin = userROW.IsAdmin; completion.FirstName = userROW.FirstName; completion.Birthdate = userROW.Birthdate; // Fixes the issue with saving birthdates db.SubmitChanges(); LoadUsers(users_DataGrid); } else { Application_User exp = new Application_User(); exp.Username = userROW.Username; exp.Password = userROW.Password; exp.LastName = userROW.LastName; exp.IsAdmin = userROW.IsAdmin; exp.FirstName = userROW.FirstName; exp.Birthdate = userROW.Birthdate; // Fixes the issue with saving birthdates db.Application_Users.InsertOnSubmit(exp); db.SubmitChanges(); LoadUsers(users_DataGrid); } } } } }
private void AgencyLongTermServiceSave_BTN_OnClick(object sender, RoutedEventArgs e) { Types_of_Service expROW = longTerm_DataGrid.SelectedItem as Types_of_Service; if (dbMethods.CheckDatabaseConnection()) { using (PubsDataContext db = new PubsDataContext()) { var completionList = new List <Types_of_Service>(from s in db.Types_of_Services where s.Agency == expROW.Agency select s); if (completionList.Count > 0) { var completion = completionList.First(); completion.Agency = expROW.Agency; completion.Body = expROW.Body; completion.CommunityBasedResearch = expROW.CommunityBasedResearch; completion.LongTerm = expROW.LongTerm; completion.ShortTerm = expROW.ShortTerm; completion.Title = expROW.Title; db.SubmitChanges(); LongTerm_Expander_OnExpanded(sender, e); } else { Types_of_Service exp = new Types_of_Service(); exp.Agency = agent.Name; exp.Body = expROW.Body; exp.CommunityBasedResearch = expROW.CommunityBasedResearch; exp.LongTerm = expROW.LongTerm; exp.ShortTerm = expROW.ShortTerm; exp.Title = expROW.Title; db.Types_of_Services.InsertOnSubmit(exp); db.SubmitChanges(); LongTerm_Expander_OnExpanded(sender, e); } } } }
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e) { if (dbMethods.CheckDatabaseConnection()) { using (PubsDataContext db = new PubsDataContext()) { var empty = (from exp in db.Learning_Experiences where exp.Student_ID == 0 select exp); db.Learning_Experiences.DeleteAllOnSubmit(empty); db.SubmitChanges(); } } }
private void agencyDelete_BTN_Click(object sender, RoutedEventArgs e) { if (dbMethods.CheckDatabaseConnection()) { if (MessageBox.Show("Are you sure you want to delete this agency?", "Confirm Delete!", MessageBoxButton.YesNo) == MessageBoxResult.Yes) { using (PubsDataContext db = new PubsDataContext()) { Agency stud = (from s in db.Agencies where s.Name == agent.Name select s).Single(); db.Agencies.DeleteOnSubmit(stud); db.SubmitChanges(); this.Close(); } } } }
private void LongTerm_Expander_OnExpanded(object sender, RoutedEventArgs e) { if (dbMethods.CheckDatabaseConnection()) { using (PubsDataContext db = new PubsDataContext()) { var completionList = new List <ServiceOpportunity>(from s in db.Types_of_Services where s.Agency == agent.Name select new ServiceOpportunity(s.Agency, "Long Term", s.Title, s.Body)); if (!completionList.Any()) { ServiceOpportunity exp = new ServiceOpportunity(); exp.Agency = agent.Name; db.Types_of_Services.InsertOnSubmit(new Types_of_Service()); db.SubmitChanges(); completionList.Add(exp); } longTerm_DataGrid.DataContext = completionList; } } }
private void Delete_agency_MenuItem_Click(object sender, RoutedEventArgs e) { if (dbMethods.CheckDatabaseConnection()) { if (MessageBox.Show("Are you sure you want to delete this agency?", "Confirm Delete!", MessageBoxButton.YesNo) == MessageBoxResult.Yes) { using (PubsDataContext db = new PubsDataContext()) { Agency agentRow = agencySearch_DataGrid.SelectedItem as Agency; Agency stud = (from a in db.Agencies where a.Name == agentRow.Name select a).Single(); db.Agencies.DeleteOnSubmit(stud); db.SubmitChanges(); } agencySearch_BTN_Click(sender, e); } } }
public void LoadStudentLearningExperiences() { if (dbMethods.CheckDatabaseConnection()) { using (PubsDataContext db = new PubsDataContext()) { var completionList = new List <Learning_Experience>(from s in db.Learning_Experiences where s.Student_ID == student.Student_ID select s); if (!completionList.Any()) { Learning_Experience exp = new Learning_Experience(); exp.Student_ID = student.Student_ID; db.Learning_Experiences.InsertOnSubmit(exp); db.SubmitChanges(); completionList.Add(exp); } studentLearningExperiences_DataGrid.DataContext = completionList; } } }
private void delete_BTN_Click(object sender, RoutedEventArgs e) { if (dbMethods.CheckDatabaseConnection()) { if (MessageBox.Show("Are you sure you want to delete this student?", "Confirm Delete!", MessageBoxButton.YesNo) == MessageBoxResult.Yes) { using (PubsDataContext db = new PubsDataContext()) { Student stud = (from s in db.Students where s.Student_ID == student.Student_ID select s).Single(); var completionList = new List <Learning_Experience>(from s in db.Learning_Experiences where s.Student_ID == student.Student_ID select s); db.Students.DeleteOnSubmit(stud); db.Learning_Experiences.DeleteAllOnSubmit(completionList); db.SubmitChanges(); this.Close(); } } } }
private void Delete_MenuItem_Click(object sender, RoutedEventArgs e) { if (dbMethods.CheckDatabaseConnection()) { if (MessageBox.Show("Are you sure you want to delete this student?", "Confirm Delete!", MessageBoxButton.YesNo) == MessageBoxResult.Yes) { using (PubsDataContext db = new PubsDataContext()) { Student studentRow = studentSearch_DataGrid.SelectedItem as Student; Student stud = (from s in db.Students where s.Student_ID == studentRow.Student_ID select s).Single(); Learning_Experience exp = (from ex in db.Learning_Experiences where ex.Student_ID == stud.Student_ID select ex).Single(); db.Students.DeleteOnSubmit(stud); db.Learning_Experiences.DeleteOnSubmit(exp); db.SubmitChanges(); } } } studentSearch_BTN_Click(sender, e); }
private void save_BTN_Click(object sender, RoutedEventArgs e) { if (dbMethods.CheckDatabaseConnection()) { using (PubsDataContext db = new PubsDataContext()) { var CheckExists = (from s in db.Agencies where s.Name == agencyName_TB.Text select s); //if the agency does not exists, application will create a new agency try { if (CheckExists.Count() == 0) { agent.Name = agencyName_TB.Text; agent.City = agencyAddressCity_TB.Text; agent.CoordinatorName = agencyCoordinatorName_TB.Text; agent.Description = description_TB.Text; agent.Email = agencyEmail_TB.Text; agent.FaxNumber = agencyFax_TB.Text; agent.Phone = agencyPhone_TB.Text; agent.Rating = Convert.ToInt32(agencyRating_TB.Text); agent.State = agencyAddressState_TB.Text; agent.StreetAddress = agencyAddressStreet_TB.Text; agent.WebsiteLink = agencyWebsite_TB.Text; agent.Zip = agencyAddressZipcode_TB.Text; agent.AlternateContact = agencyAlternateName_TB.Text; db.Agencies.InsertOnSubmit(agent); db.SubmitChanges(); } else { //save agency info && save as current agent Agency agency = agent = (from s in db.Agencies where s.Name == agent.Name select s).Single(); agency.Name = agencyName_TB.Text; agency.City = agencyAddressCity_TB.Text; agency.CoordinatorName = agencyCoordinatorName_TB.Text; agency.Description = description_TB.Text; agency.Email = agencyEmail_TB.Text; agency.FaxNumber = agencyFax_TB.Text; agency.Phone = agencyPhone_TB.Text; agency.Rating = Convert.ToInt32(agencyRating_TB.Text); agency.State = agencyAddressState_TB.Text; agency.StreetAddress = agencyAddressStreet_TB.Text; agency.WebsiteLink = agencyWebsite_TB.Text; agency.Zip = agencyAddressZipcode_TB.Text; agency.AlternateContact = agencyAlternateName_TB.Text; db.SubmitChanges(); } } catch (Exception) { MessageBox.Show("SLApp apologies for the inconvenience, but at this time Rating must contain contain data.", "Save Error!", MessageBoxButton.OK, MessageBoxImage.Error); } } } }
private void save_BTN_Click(object sender, RoutedEventArgs e) { if (dbMethods.CheckDatabaseConnection()) { using (PubsDataContext db = new PubsDataContext()) { if (studentID_TB.Text.Length > 0 && graduationYear_TB.Text.Length > 0) { // if there's a problem with the student ID, exit function if (!student_ID_IntCheck(studentID_TB.Text)) { return; } // if there's a problem with the student's grad year year, exit function if (!studentGradYearIntCheck(graduationYear_TB.Text)) { return; } var CheckExists = (from s in db.Students where s.Student_ID == Convert.ToInt32(studentID_TB.Text) select s); //if the user does not exist, application will create a new user if (CheckExists.Count() == 0) { student.Student_ID = Convert.ToInt32(studentID_TB.Text); student.FirstName = studentFirstName_TB.Text; student.LastName = studentLastName_TB.Text; student.GraduationYear = Convert.ToInt32(graduationYear_TB.Text); student.Email = studentemail_TB.Text; Learning_Experience exp = new Learning_Experience(); exp.Student_ID = Convert.ToInt32(studentID_TB.Text); db.Students.InsertOnSubmit(student); db.Learning_Experiences.InsertOnSubmit(exp); db.SubmitChanges(); LoadStudentLearningExperiences(); } else //if the student ID is found in the database { //save student info after checking that the user did not accidentally change information Student stud = (from s in db.Students where s.Student_ID == Convert.ToInt32(studentID_TB.Text) select s).Single(); //Create a shallow copy to see if indentification info changes Student studCopy = new Student(); studCopy.Student_ID = stud.Student_ID; studCopy.FirstName = stud.FirstName; studCopy.LastName = stud.LastName; studCopy.GraduationYear = stud.GraduationYear; studCopy.Email = stud.Email; //Update student information using input fields stud.Student_ID = Convert.ToInt32(studentID_TB.Text); stud.FirstName = studentFirstName_TB.Text; stud.LastName = studentLastName_TB.Text; stud.GraduationYear = Convert.ToInt32(graduationYear_TB.Text); stud.Email = studentemail_TB.Text; //If the user has changed the basic information in the student profile, make sure // that was intentional before updating. if (!(studCopy.Student_ID == stud.Student_ID && studCopy.FirstName == stud.FirstName && studCopy.LastName == stud.LastName && studCopy.GraduationYear == stud.GraduationYear && studCopy.Email == stud.Email)) { bool check = overwriteCheck(studCopy); if (!check) //If it was a mistake, don't save changes { return; } } student = stud; // fills in this window's student information //saves experience by calling the save experiences button event learningExperienceSave(); db.SubmitChanges(); LoadStudentLearningExperiences(); // reloads student information into the window } } else { MessageBox.Show( "SLApp apologizes for the inconvenience, but at this time all fields must contain data before saving.", "Save Error!", MessageBoxButton.OK, MessageBoxImage.Error); } //this.Close(); } } }