Inheritance: INotifyPropertyChanging, INotifyPropertyChanged
        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 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();
                }
            }
        }
 private bool learningExperienceFieldsCheck(Learning_Experience expROW)
 {
     if (expROW == null)
     {
         //MessageBox.Show("You must first select a valid row before adding, saving, or deleting.",
         //                "Datagrid Row Selection Error", MessageBoxButton.OK,
         //                MessageBoxImage.Exclamation);
         return false;
     }
     else if (expROW.Semester != "Fall" && expROW.Semester != "Jan" && expROW.Semester != "Spring" && expROW.Semester != "")
     {
         MessageBox.Show("Entry in Semester column invalid. Valid entries are blank, 'Fall', 'Jan', or 'Spring'.",
                         "Datagrid Row Error", MessageBoxButton.OK,
                         MessageBoxImage.Exclamation);
         return false;
     }
     else if (expROW.Section.Equals(null))
     {
         MessageBox.Show("Must enter course section!", "Datagrid Row Error", MessageBoxButton.OK,
                         MessageBoxImage.Exclamation);
     }
     return true;
 }
        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;

                                //The bottom three object variables were missing in this else statemenet == Fixes the problem of the second entry not saving properly
                                exp.Section = expROW.Section;
                                exp.Professor = expROW.Professor;
                                exp.CourseName = expROW.CourseName;

                                db.Learning_Experiences.InsertOnSubmit(exp);
                                db.SubmitChanges();
                                LoadStudentLearningExperiences();

                            }
                        }
                    }
                }
        }
Beispiel #5
0
 partial void DeleteLearning_Experience(Learning_Experience instance);
Beispiel #6
0
 partial void UpdateLearning_Experience(Learning_Experience instance);
Beispiel #7
0
 partial void InsertLearning_Experience(Learning_Experience instance);
        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 bool learningExperienceFieldsCheck(Learning_Experience expROW)
 {
     if (expROW == null)
     {
         //MessageBox.Show("You must first select a valid row before adding, saving, or deleting.",
         //                "Datagrid Row Selection Error", MessageBoxButton.OK,
         //                MessageBoxImage.Exclamation);
         return false;
     }
     else if (expROW.Semester != "Fall" && expROW.Semester != "Jan" && expROW.Semester != "Spring" && expROW.Semester != "")
     {
         MessageBox.Show("Entry in Semester column invalid. Valid entries are blank, 'Fall', 'Jan', or 'Spring'.",
                         "Datagrid Row Error", MessageBoxButton.OK,
                         MessageBoxImage.Exclamation);
         return false;
     }
     else if (expROW.TypeofLearning != "Discipline-Based" && expROW.TypeofLearning != "Problem-Based" &&
              expROW.TypeofLearning != "Pure Service" && expROW.TypeofLearning != "Service Internship" &&
              expROW.TypeofLearning != "Community Based Research" && expROW.TypeofLearning != "Capstone Class"
         && expROW.TypeofLearning != "")
     {
         MessageBox.Show("Entry in Type of Learning column invalid.\n" +
             "Valid entries are blank, 'Discipline-Based', 'Problem-Based', 'Pure Service',\n" +
         "'Service Internship', 'Community Based Research', or 'Capstone Class'",
                         "Datagrid Row Error", MessageBoxButton.OK,
                         MessageBoxImage.Exclamation);
         return false;
     }
     else if (expROW.Section.Equals(null))
     {
         MessageBox.Show("Must enter course section!", "Datagrid Row Error", MessageBoxButton.OK,
                         MessageBoxImage.Exclamation);
     }
     return true;
 }