private void SavePB_Click(object sender, RoutedEventArgs e) { bool goodData = true; string errStr = "No Error"; WaveguideDB wgDB = new WaveguideDB(); bool success = wgDB.GetAllProjects(true); bool ProjectNameUnique = true; // if creating a new project, make sure project name isn't already used in database if (m_addingNew) { for (int i = 0; i < wgDB.m_projectList.Count(); i++) { if (wgDB.m_projectList[i].Description.Equals(ProjectVM.ProjectDescription, StringComparison.OrdinalIgnoreCase)) { ProjectNameUnique = false; break; } } } if (ProjectVM.ProjectDescription.Length < 1) { goodData = false; errStr = "Project must have a Name"; } else if (!ProjectNameUnique) { goodData = false; errStr = "Project Name: " + ProjectVM.ProjectDescription + " is already in use by another project (Includes Archived Projects)."; } if (goodData) { ProjectContainer pc = new ProjectContainer(); if (m_addingNew) // creating a new project { pc.Description = ProjectVM.ProjectDescription; pc.Archived = ProjectVM.Archived; pc.TimeStamp = ProjectVM.TimeStamp; success = wgDB.InsertProject(ref pc); } else // updating current project instead of creating a new one { pc.Description = ProjectVM.ProjectDescription; pc.ProjectID = ProjectVM.ProjectID; pc.Archived = ProjectVM.Archived; pc.TimeStamp = ProjectVM.TimeStamp; success = wgDB.UpdateProject(pc); } if (success) { ProjectVM.ProjectDescription = pc.Description; ProjectVM.ProjectID = pc.ProjectID; ProjectVM.Archived = pc.Archived; ProjectVM.TimeStamp = pc.TimeStamp; // delete all current UserProject records for this Project success = wgDB.RemoveProjectFromUserProjectTable(pc.ProjectID); if (success) { // add UserProject records as designed by ProjectVM.Users list for (int i = 0; i < ProjectVM.Users.Count(); i++) { if (ProjectVM.Users[i].AssignedToProject) { success = wgDB.AddUserToProject(ProjectVM.Users[i].UserID, ProjectVM.ProjectID); if (!success) { errStr = wgDB.GetLastErrorMsg(); MessageBox.Show(errStr, "Database Error", MessageBoxButton.OK, MessageBoxImage.Error); break; } } } } } if (success) { m_OK = true; Close(); } } if (!goodData) { MessageBox.Show(errStr, "Error in Project Data", MessageBoxButton.OK, MessageBoxImage.Error); } }