Inheritance: System.Data.Linq.DataContext
Example #1
0
        private void login_BTN_Click(object sender, RoutedEventArgs e)
        {
            if (dbMethods.CheckDatabaseConnection())
                        {
                                using(PubsDataContext db = new PubsDataContext())
                                {
                                    var users = (from u in db.Application_Users
                                                 where u.Username == username_TB.Text
                                                 select u).Distinct();

                                    if (users.Count() > 0)
                                    {
                                        var user = users.First();
                                        if (pwMethods.verifyPassword(user.Password, password_TB.Password))
                                        {
                                            isAdmin = user.IsAdmin;
                                            MainWindow main = new MainWindow(isAdmin);
                                            main.Show();
                                            Close();
                                        }
                                    }
                                    //else if (loginAttempts >= 5)
                                    //{
                                    //        ; // TODO: feature- lockout user after 5 loginAttempts
                                    //}
                                    else
                                    {
                                            MessageBox.Show("Invalid Login Credentials", "Login Error", MessageBoxButton.OK, MessageBoxImage.Stop);
                                            loginAttempts++;
                                    }

                                }
                        }
        }
        private void save_BTN_Click(object sender, RoutedEventArgs e)
        {
            if (dbMethods.CheckDatabaseConnection())
            {
                using(PubsDataContext db = new PubsDataContext())
                    {

                    }
            }
        }
        public StudentProfile(bool isAdmin)
        {
            InitializeComponent();

            if (isAdmin == false) studentNotes_DataGrid.IsEnabled = false;

            LoadStudentLearningExperiences();

            using (PubsDataContext db = new PubsDataContext())
            {
                servicelearningtype = (from type in db.Service_Learning_Types
                                       select type.Name).AsEnumerable().ToArray();
            }
        }
        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();
                    }
                }
            }
        }
Example #5
0
        private void agencySearch_BTN_Click(object sender, RoutedEventArgs e)
        {
            using (PubsDataContext db = new PubsDataContext())

            {
                var allAgency = (from agency in db.Agencies
                                 where (agencyName_TB.Text.Length == 0 || agency.Name.Contains(agencyName_TB.Text)) &&
                                 (agencyPhone_TB.Text.Length == 0 || agency.Phone.Contains(agencyPhone_TB.Text)) &&
                                 (agencyFax_TB.Text.Length == 0 || agency.FaxNumber.Contains(agencyFax_TB.Text)) &&
                                 (agencyRating_TB.Text.Length == 0||agency.Rating.ToString().Contains(agencyRating_TB.Text)) &&
                                 (agencyWebsite_TB.Text.Length == 0 || agency.WebsiteLink.Contains(agencyWebsite_TB.Text)) &&
                                 (agencyCoordinatorName_TB.Text.Length == 0 || agency.CoordinatorName.Contains(agencyCoordinatorName_TB.Text)) &&
                                 (agencyAddressStreet_TB.Text.Length == 0 || agency.StreetAddress.Contains(agencyAddressStreet_TB.Text)) &&
                                 (agencyAddressCity_TB.Text.Length == 0 || agency.City.Contains(agencyAddressCity_TB.Text)) &&
                                 (agencyAddressState_TB.Text.Length == 0 || agency.State.Contains(agencyAddressState_TB.Text)) &&
                                 (agencyAddressZipcode_TB.Text.Length == 0 || agency.Zip.Contains(agencyAddressZipcode_TB.Text))

                                 select agency);
                agencySearch_DataGrid.DataContext = allAgency;
            }
        }
Example #6
0
        public StudentProfile(Student stud, bool isAdmin, bool IsEdit)
        {
            InitializeComponent();
            using (PubsDataContext db = new PubsDataContext())
            {
                servicelearningtype = (from type in db.Service_Learning_Types
                                       select type.Name).AsEnumerable().ToArray();
            }
            if (isAdmin == false)studentNotes_DataGrid.IsEnabled = false;
            #if Demo
            studentID_TB.Visibility = Visibility.Hidden;
            #endif

            student = stud;

            this.studentFirstName_TB.Text = stud.FirstName;
            this.studentLastName_TB.Text = stud.LastName;
            this.studentID_TB.Text = stud.Student_ID.ToString();
            this.studentemail_TB.Text = stud.Email;
            this.graduationYear_TB.Text = stud.GraduationYear.ToString();

            LoadStudentLearningExperiences();
        }
        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;

                }
            }
        }
Example #8
0
        private void LoadUsers(DataGrid dg)
        {
            if (dbMethods.CheckDatabaseConnection())
            {
                using (PubsDataContext db = new PubsDataContext())
                {
            #if Demo
                    var Allusers = new List<Application_User>(from users in db.Application_Users
                                                              where users.Username != "bwatts"
                                                              select users);
            #else
                    var Allusers = new List<Application_User>(from users in db.Application_Users
                                                              select users);
            #endif

                    dg.DataContext = Allusers;
                }
            }
        }
Example #9
0
        private void CourseCount()
        {
            if (dbMethods.CheckDatabaseConnection())
            {
                using (PubsDataContext db = new PubsDataContext())
                {
                    var allcourses = new List<Learning_Experience>(from e in db.Learning_Experiences
                                                                   where
                                                                   (queryYear_TB.Text.Length == 0 || e.Year.ToString() == queryYear_TB.Text) &&
                                                                   (querySemester_ComboBox.Text.Length == 0 || e.Semester == querySemester_ComboBox.Text) &&
                                                                   (queryPrefix_TB.Text.Length == 0 || e.CourseNumber.ToString() == queryPrefix_TB.Text)
                                                                   select e).GroupBy(x => String.Format("{0}-{1}", x.CourseNumber, x.Section)).Distinct();

                    courseCount_TB.Text = allcourses.Count().ToString();
                }
            }
        }
Example #10
0
 private void AvgHoursPerStudent()
 {
     if (dbMethods.CheckDatabaseConnection())
     {
         using (PubsDataContext db = new PubsDataContext())
         {
             var totalhours = new List<Learning_Experience>(from e in db.Learning_Experiences
                                                            where
                                                            (queryYear_TB.Text.Length == 0 || e.Year.ToString() == queryYear_TB.Text) &&
                                                            (querySemester_ComboBox.Text.Length == 0 || e.Semester == querySemester_ComboBox.Text) &&
                                                            (queryPrefix_TB.Text.Length == 0 || e.CourseNumber.ToString() == queryPrefix_TB.Text)
                                                            select e);
             var totalstudents = new List<Student>(from s in db.Students
                                                   from e in db.Learning_Experiences
                                                   where e.Student_ID == s.Student_ID &&
                                                   (queryYear_TB.Text.Length == 0 || e.Year.ToString() == queryYear_TB.Text) &&
                                                   (querySemester_ComboBox.Text.Length == 0 || e.Semester == querySemester_ComboBox.Text) &&
                                                            (queryPrefix_TB.Text.Length == 0 || e.CourseNumber.ToString() == queryPrefix_TB.Text)
                                                   select s);
             double avg_hours;
             avg_hours = (Convert.ToDouble(totalhours.Sum(i => i.TotalHours.GetValueOrDefault(0))) / Convert.ToDouble(totalstudents.Count()));
             avgHoursStudent_TB.Text = (Math.Round(avg_hours, 3)).ToString();
         }
     }
 }
Example #11
0
 private void CoursesByType()
 {
     if (dbMethods.CheckDatabaseConnection())
     {
         using (PubsDataContext db = new PubsDataContext())
         {
             var courses = (from e in db.Learning_Experiences
                            where (queryYear_TB.Text.Length == 0 || e.Year.ToString() == queryYear_TB.Text) &&
                                  (querySemester_ComboBox.Text.Length == 0 || e.Semester == querySemester_ComboBox.Text) &&
                                  (queryPrefix_TB.Text.Length == 0 || e.CourseNumber.ToString() == queryPrefix_TB.Text)
                            group e by e.TypeofLearning into grp
                            select new {Type = grp.Key, Students = grp.Select(x => x.Student_ID).Distinct().Count(), Classes = grp.Select(x => x.CourseNumber).Distinct().Count()} );
             coursesByType_Datagrid.DataContext = courses;
         }
     }
 }
Example #12
0
        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;

                }
            }
        }
Example #13
0
        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 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();

                            }
                        }
                    }
                }
        }
Example #15
0
        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);
                }
            }
        }
Example #16
0
        private void Edit_MenuItem_Click(object sender, RoutedEventArgs e)
        {
            if (dbMethods.CheckDatabaseConnection())
            {
                using (PubsDataContext datab = new PubsDataContext())
                {
                    Student studentRow = studentSearch_DataGrid.SelectedItem as Student;
                    Student stud = (from s in datab.Students
                                    where s.Student_ID == studentRow.Student_ID
                                    select s).Single();

                    StudentProfile studentForm = new StudentProfile(stud, IsAdmin, true);
                    studentForm.Show();
                }
            }
        }
Example #17
0
        private void Edit_agency_MenuItem_Click(object sender, RoutedEventArgs e)
        {
            if (dbMethods.CheckDatabaseConnection())
            {
                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();

                    AgencyProfile agentForm = new AgencyProfile(stud, IsAdmin, true);
                    agentForm.Show();
                }
            }
        }
Example #18
0
        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 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();
                        }
                    }
                }
            }
        }
Example #20
0
        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 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();
                }
            }
        }
Example #22
0
        private void studentSearch_BTN_Click(object sender, RoutedEventArgs e)
        {
            /// <summary>
            ///Data grid based off of which fields have data entered into them,
            ///if a box has no txt entered then it is not included in the query generation
            ///
            /// Fields are: studentID_TB, studentLastName_TB, studentMiddleName_TB, graduatinoYear_TB
            /// </summary>
            ///
            if(dbMethods.CheckDatabaseConnection())
            {
                using (PubsDataContext db = new PubsDataContext())
                {
                    var allStudents = (from stud in db.Students
                                       from experience in db.Learning_Experiences.Where(a => a.Student_ID == stud.Student_ID).DefaultIfEmpty()

                                       where
                                           //student search section
                                           //ABLE TO SEARCH FOR PARTIALS
                                           (studentFirstName_TB.Text.Length == 0 || stud.FirstName.Contains(studentFirstName_TB.Text)) &&
                                           (studentLastName_TB.Text.Length == 0 || stud.LastName.Contains(studentLastName_TB.Text)) &&
                                           (studentID_TB.Text.Length == 0 || stud.Student_ID.ToString().Contains(studentID_TB.Text)) &&
                                           (graduationYear_TB.Text.Length == 0 || stud.GraduationYear.ToString().Contains(graduationYear_TB.Text)) &&

                                           //course search section
                                           (course_TB.Text.Length == 0 || experience.CourseNumber.Contains(course_TB.Text)) &&
                                           (professor_TB.Text.Length == 0 || experience.Professor.Contains(professor_TB.Text)) &&
                                           (CourseName_TB.Text.Length == 0 || experience.CourseName.Contains(CourseName_TB.Text)) &&
                                           (Section_TB.Text.Length == 0 || experience.Section.ToString().Contains(Section_TB.Text)) &&

                                           //service and hours section
                                           (serviceType_CBX.Text.Length == 0 || experience.TypeofLearning.Contains(serviceType_CBX.Text)) &&
                                           (semester_CBX.Text.Length == 0 || experience.Semester.Contains(semester_CBX.Text)) &&
                                           (year_TB.Text.Length == 0 || experience.Year.ToString().Contains(year_TB.Text))

                                       select stud).Distinct();
                    studentSearch_DataGrid.DataContext = allStudents;
                }
            }
        }
 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();
         }
     }
 }
Example #24
0
        private void StudentSearch_DataGrid_OnMouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            using (PubsDataContext datab = new PubsDataContext())
            {
                Student studentRow = studentSearch_DataGrid.SelectedItem as Student;
                if (studentRow != null)
                {
                    Student stud = (from s in datab.Students
                                    where s.Student_ID == studentRow.Student_ID
                                    select s).Single();

                    StudentProfile studentForm = new StudentProfile(stud, IsAdmin, true);
                    studentForm.Closed += new EventHandler((s0, e0) => studentSearch_BTN_Click(s0, null));
                    studentForm.Show();
                }
            }
        }
 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);
                 }
             }
         }
     }
 }
Example #26
0
 private void StudentsPerClass()
 {
     if (dbMethods.CheckDatabaseConnection())
     {
         using (PubsDataContext db = new PubsDataContext())
         {
             var grps = from s in db.Students
                         from e in db.Learning_Experiences
                         where s.Student_ID == e.Student_ID &&
                         e.TotalHours > 0 &&
                               (queryYear_TB.Text.Length == 0 || e.Year.ToString() == queryYear_TB.Text) &&
                               (querySemester_ComboBox.Text.Length == 0 || e.Semester == querySemester_ComboBox.Text) &&
                               (queryPrefix_TB.Text.Length == 0 || e.CourseNumber.ToString() == queryPrefix_TB.Text)
                         group e by new {e.CourseNumber, e.Section} into grp select new { Class = grp.Key.CourseNumber, Section = grp.Key.Section, Count = grp.Select(x => x.Student_ID).Distinct().Count() };
             dataGrid2.DataContext = grps;
         }
     }
 }
Example #27
0
        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
                            Agency agency = (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);
                    }
                }
            }
        }
Example #28
0
        private void UnduplicatedHours()
        {
            if (dbMethods.CheckDatabaseConnection())
            {
                using (PubsDataContext db = new PubsDataContext())
                {
                    var totalhours = new List<Learning_Experience>(from e in db.Learning_Experiences
                                                                   from s in db.Students
                                                                   where s.Student_ID == e.Student_ID &&
                                                                   (queryYear_TB.Text.Length == 0 || e.Year.ToString() == queryYear_TB.Text) &&
                                                                   (querySemester_ComboBox.Text.Length == 0 || e.Semester == querySemester_ComboBox.Text) &&
                                                                   (queryPrefix_TB.Text.Length == 0 || e.CourseNumber.ToString() == queryPrefix_TB.Text)
                                                                   select e).GroupBy(s => s.Student_ID).Select(e => e.MaxBy(x => x.TotalHours));

                        unduplicatedHours_TB.Text = totalhours.Sum(i => i.TotalHours.GetValueOrDefault(0)).ToString();
                }
            }
        }
Example #29
0
        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);
                        }
                    }
                }
        }
Example #30
0
 private void UnduplicatedStudents()
 {
     if (dbMethods.CheckDatabaseConnection())
     {
         using (PubsDataContext db = new PubsDataContext())
         {
             var totalstudents = new List<Student>(from s in db.Students
                                                   from e in db.Learning_Experiences
                                                   where e.Student_ID == s.Student_ID &&
                                                   (queryYear_TB.Text.Length == 0 || e.Year.ToString() == queryYear_TB.Text) &&
                                                   (querySemester_ComboBox.Text.Length == 0 || e.Semester == querySemester_ComboBox.Text) &&
                                                   (queryPrefix_TB.Text.Length == 0 || e.CourseNumber.ToString() == queryPrefix_TB.Text)
                                                   select s).Distinct();
             unduplicatedStudents_TB.Text = totalstudents.Count().ToString();
         }
     }
 }