protected void btnSave_Click(object sender, EventArgs e)
        {
            //use EF to connect to SQL server
            using (comp2007Entities db = new comp2007Entities())
            {
                //use the Student model to save the new record
                Course c = new Course();
                int courseID = 0;

                if (Request.QueryString["CourseID"] != null)
                {
                    courseID = int.Parse(Request.QueryString["CourseID"]);

                    c = (from obj in db.Courses where obj.CourseID == courseID select obj).FirstOrDefault();
                }

                c.Title = txtTitle.Text;
                c.Credits = int.Parse(txtCredits.Text);
                c.DepartmentID = int.Parse(ddlDepartment.SelectedValue);

                if (courseID == 0)
                {
                    db.Courses.Add(c);
                }

                db.SaveChanges();

                //redirect to the updated students page
                Response.Redirect("courses.aspx");
            }
        }
        protected void GetStudent()
        {
            //populate form with existing student record
            Int32 StudentID = Convert.ToInt32(Request.QueryString["StudentID"]);

            //connect to db via EF
            using (comp2007Entities db = new comp2007Entities())
            {
                //populate a student instance with the StudentID from the URL parameter
                Student s = (from objS in db.Students
                             where objS.StudentID == StudentID
                             select objS).FirstOrDefault();

                //map the student properties to the form controls if we found a match
                if (s != null)
                {
                    txtLastName.Text = s.LastName;
                    txtFirstMidName.Text = s.FirstMidName;
                    txtEnrollmentDate.Text = s.EnrollmentDate.ToString("yyyy-MM-dd");
                }

                //enrollments - this code goes in the same method that populates the student form but below the existing code that's already in GetStudent()
                var objE = (from en in db.Enrollments
                            join c in db.Courses on en.CourseID equals c.CourseID
                            join d in db.Departments on c.DepartmentID equals d.DepartmentID
                            where en.StudentID == StudentID
                            select new { en.EnrollmentID, en.Grade, c.Title, d.Name });

                grdCourses.DataSource = objE.ToList();
                grdCourses.DataBind();

            }
        }
        protected void getCategoryDetail()
        {
            //populate form with existing student record
            Int32 CategoryID = Convert.ToInt32(Request.QueryString["CategoryID"]);

            //connect to db via EF
            using (comp2007Entities db = new comp2007Entities())
            {
                //populate a student instance with the student ID from the url parameter
                Category c = (from objS in db.Categories
                                where objS.CategoryID == CategoryID
                                select objS).FirstOrDefault();

                //map the student to the form controls when s found
                if (c != null)
                {
                    txtCtgname.Text = c.CategoryName;
                    if(c.isExpense){
                        ckbIsExpense.Checked = true;
                    }
                    if (c.isActive)
                    {
                        ckbActivated.Checked = true;
                    }

                }

            }
        }
Example #4
0
        protected void grdStudents_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            //store which row was clicked
            Int32 selectedRow = e.RowIndex;

            //get the selected StudentID using the grid's Data Key collection
            Int32 StudentID = Convert.ToInt32(grdStudents.DataKeys[selectedRow].Values["StudentID"]);

            //use EF to remove the selected student from the db
            using (comp2007Entities db = new comp2007Entities())
            {

                try
                {
                    Student s = (from objS in db.Students
                                 where objS.StudentID == StudentID
                                 select objS).FirstOrDefault();

                    //do the delete
                    db.Students.Remove(s);
                    db.SaveChanges();
                }
                catch (Exception)
                {

                    Response.Redirect("error.aspx");
                }
            }

            //refresh the grid
            GetStudents();
        }
        protected void getAccountMod()
        {
            //
            Int32 AccountID = Convert.ToInt32(Request.QueryString["AccountID"]);

            //connect to db via EF
            using (comp2007Entities db = new comp2007Entities())
            {
                //
                Account a = (from objS in db.Accounts
                             where objS.AccountID == AccountID
                            select objS).FirstOrDefault();

                //map the student properties to the form controls if we found a match
                if (a != null)
                {

                    ddlCategory.SelectedIndex = a.CategoryID;
                    //ddlDepartment.SelectedValue=
                    txtAccountName.Text = a.AccountName;
                    if(a.isActive){
                        ckbIsActive.Checked=true;
                    }
                }
            }
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            //use EF to connect to SQL server
            using (comp2007Entities db = new comp2007Entities())
            {
                //use the Student model to save the new record
                Student s = new Student();
                int studentID = 0;

                if (Request.QueryString["StudentID"] != null)
                {
                    studentID = int.Parse(Request.QueryString["StudentID"]);

                    s = (from objS in db.Students where objS.StudentID == studentID select objS).FirstOrDefault();
                }

                s.LastName = txtLastName.Text;
                s.FirstMidName = txtFirstMidName.Text;
                s.EnrollmentDate = DateTime.Parse(txtEnrollmentDate.Text);

                if (studentID == 0)
                {
                    db.Students.Add(s);
                }

                db.SaveChanges();

                //redirect to the updated students page
                Response.Redirect("students.aspx");
            }
        }
        protected void GetCourses()
        {
            //
            Int32 CourseID = Convert.ToInt32(Request.QueryString["CourseID"]);

            //connect to db via EF
            using (comp2007Entities db = new comp2007Entities())
            {
                //
                Course c = (from objS in db.Courses
                            where objS.CourseID == CourseID
                            select objS).FirstOrDefault();

                //map the student properties to the form controls if we found a match
                if (c != null)
                {

                    ddlDepartment.SelectedIndex = c.DepartmentID;
                    //ddlDepartment.SelectedValue=
                    txtCourseTitle.Text = c.Title;
                    txtCredits.Text = c.Credits.ToString();
                }

                //enrollments - this code goes in the same method that populates the student form but below the existing code that's already in GetStudent()
                var objE = (from en in db.Enrollments
                            join s in db.Students on en.StudentID equals s.StudentID
                            where en.CourseID == CourseID
                            select new { en.EnrollmentID, s.LastName, s.FirstMidName, s.EnrollmentDate });

                grdStudents.DataSource = objE.ToList();
                grdStudents.DataBind();

            }
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            //use EF to connect to SQL server
            using (comp2007Entities db = new comp2007Entities())
            {
                //use the Student model to save the new record
                Department d = new Department();
                int departmentID = 0;

                if (Request.QueryString["DepartmentID"] != null)
                {
                    departmentID = int.Parse(Request.QueryString["DepartmentID"]);

                    d = (from obj in db.Departments where obj.DepartmentID == departmentID select obj).FirstOrDefault();
                }

                d.Name = txtName.Text;
                d.Budget = decimal.Parse(txtBudget.Text);

                if (departmentID == 0)
                {
                    db.Departments.Add(d);
                }

                db.SaveChanges();

                //redirect to the updated students page
                Response.Redirect("departments.aspx");
            }
        }
        protected void GetDepartments()
        {
            using (comp2007Entities db = new comp2007Entities())
            {
                var departments = from d in db.Departments
                                  select d;

                grdDepartments.DataSource = departments.ToList();
                grdDepartments.DataBind();
            }
        }
        protected void GetStudents()
        {
            using (comp2007Entities db = new comp2007Entities())
            {
                var Students = from s in db.Students
                               select s;

                grdStudents.DataSource = Students.ToList();
                grdStudents.DataBind();
            }
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            // use EF to connect to SQL
            using (comp2007Entities db = new comp2007Entities())
            {
                //use the student model to save the new model
                Category c = new Category();
                Int32 CategoryID = 0;

                //check save? or update??
                if (Request.QueryString["CategoryID"] != null)
                {
                    //get the id from the url
                    CategoryID = Convert.ToInt32(Request.QueryString["CategoryID"]);
                    //get the current student from EF
                    c = (from objS in db.Categories
                         where objS.CategoryID == CategoryID
                         select objS).FirstOrDefault();
                }

                c.CategoryName = txtCtgname.Text;

                if (ckbIsExpense.Checked)
                {
                    c.isExpense = true;
                }
                else
                {
                    c.isExpense = false;
                }

                if (ckbActivated.Checked)
                {
                    c.isActive = true;
                }
                else
                {
                    c.isActive = false;
                }

                if (CategoryID == 0)
                {
                    db.Categories.Add(c);
                }

                db.SaveChanges();

                //redirect to the updated list page
                Response.Redirect("category.aspx");

            }
        }
        protected void GetCourses()
        {
            using (comp2007Entities db = new comp2007Entities())
            {
                string SortString = Session["SortColumn"].ToString();

                var courses = from c in db.Courses
                              select c;

                grdCourses.DataSource = courses.AsQueryable().OrderBy(SortString).ToList();
                grdCourses.DataBind();
            }
        }
        protected void getDepartments()
        {
            using (comp2007Entities db = new comp2007Entities())
            {
                String SortString = Session["SortColumn"].ToString() + " " + Session["SortDirection"].ToString();

                var departments = from objS in db.Departments
                                  select objS;

                //bind the result to the gridview
                grdDepartments.DataSource = departments.AsQueryable().OrderBy(SortString).ToList();
                grdDepartments.DataBind();
            }
        }
        protected void getMonthly()
        {
            using (comp2007Entities db = new comp2007Entities())
            {
                String SortString = Session["SortColumn"].ToString() + " " + Session["SortDirection"].ToString();
                Int32 targetMonth = Convert.ToInt32(ddlMonth.SelectedValue);
                Int32 targetYear = Convert.ToInt32(ddlYear.SelectedValue);

                var objE = (from a in db.Accounts
                            select new { a.Category.CategoryName, a.AccountName });

                //bind the result to the gridview
                grdMonthly.DataSource = objE.AsQueryable().OrderBy(SortString).ToList();
                grdMonthly.DataBind();
            }
        }
        protected void grdCourses_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            int selectedRow = e.RowIndex;

            int courseID = (int)grdCourses.DataKeys[selectedRow].Values["CourseID"];

            using (comp2007Entities db = new comp2007Entities())
            {
                Course c = (from obj in db.Courses where obj.CourseID == courseID select obj).FirstOrDefault();

                db.Courses.Remove(c);
                db.SaveChanges();

                GetCourses();
            }
        }
        protected void grdCourseStudents_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            int enrollmentID = Convert.ToInt32(grdCourseStudents.DataKeys[e.RowIndex].Values["EnrollmentID"]);

            using (comp2007Entities db = new comp2007Entities())
            {
                var objE = (from en in db.Enrollments
                            where en.EnrollmentID == enrollmentID
                            select en).FirstOrDefault();

                db.Enrollments.Remove(objE);
                db.SaveChanges();

                GetCourse();
            }
        }
        protected void grdStudents_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            int selectedRow = e.RowIndex;

            int studentID = (int)grdStudents.DataKeys[selectedRow].Values["StudentID"];

            using (comp2007Entities db = new comp2007Entities())
            {
                Student s = (from objS in db.Students where objS.StudentID == studentID select objS).FirstOrDefault();

                db.Students.Remove(s);
                db.SaveChanges();

                GetStudents();
            }
        }
        protected void GetStudents()
        {
            //connect to EF
            using (comp2007Entities db = new comp2007Entities())
            {
                String SortString = Session["SortColumn"].ToString() + " " + Session["SortDirection"].ToString();

                //query the students table using EF and LINQ
                var Students = from s in db.Students
                               select s;

                //bind the result to the gridview
                grdStudents.DataSource = Students.AsQueryable().OrderBy(SortString).ToList();
                grdStudents.DataBind();

            }
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            //use EF to connect to SQL Server
            using (comp2007Entities db = new comp2007Entities())
            {

                //use the Student model to save the new record
                Account a = new Account();
                Int32 AccountID = 0;

                //check the querystring for an id so we can determine add / update
                if (Request.QueryString["AccountID"] != null)
                {
                    //get the id from the url
                    AccountID = Convert.ToInt32(Request.QueryString["AccountID"]);

                    //get the current student from EF
                    a = (from objS in db.Accounts
                         where objS.AccountID == AccountID
                         select objS).FirstOrDefault();
                }

                a.CategoryID = Convert.ToInt32(ddlCategory.SelectedIndex);
                a.AccountName = txtAccountName.Text;
                if (ckbIsActive.Checked)
                {
                    a.isActive = true;
                }
                else
                {
                    a.isActive = false;
                }

                //call add only if we have no student ID
                if (AccountID == 0)
                {
                    db.Accounts.Add(a);
                }

                //run the update or insert
                db.SaveChanges();

                //redirect to the updated students page
                Response.Redirect("account.aspx");
            }
        }
        protected void getAccounts()
        {
            //connect to EF
            using (comp2007Entities db = new comp2007Entities())
            {
                String SortString = Session["SortColumn"].ToString() + " " + Session["SortDirection"].ToString();

                //query the students table using EF and LINQ
                var Accounts = from n in db.Accounts
                               select new { n.AccountID, n.AccountName, n.Category.CategoryName,  n.isActive };

                //bind the result to the gridview

                grdAccounts.DataSource = Accounts.AsQueryable().OrderBy(SortString).ToList();
                grdAccounts.DataBind();

            }
        }
        protected void GetCourses()
        {
            //connect to EF
            using (comp2007Entities db = new comp2007Entities())
            {
                String SortString = Session["SortColumn"].ToString() + " " + Session["SortDirection"].ToString();

                //query the students table using EF and LINQ
                var Courses = from c in db.Courses
                              select new { c.CourseID, c.Title, c.Credits, c.Department.Name};

                //bind the result to the gridview

                grdCourses.DataSource = Courses.AsQueryable().OrderBy(SortString).ToList();
                grdCourses.DataBind();

            }
        }
        protected void GetDepartment()
        {
            int departmentID = int.Parse(Request.QueryString["DepartmentID"]);

            using (comp2007Entities db = new comp2007Entities())
            {
                Department department = (from obj in db.Departments where obj.DepartmentID == departmentID select obj).FirstOrDefault();

                txtName.Text = department.Name;
                txtBudget.Text = department.Budget.ToString();

                var objD = (from d in db.Departments
                            join c in db.Courses on d.DepartmentID equals c.DepartmentID
                            where d.DepartmentID == departmentID
                            select new { c.CourseID, c.Title, c.Credits });

                grdDepartmentCourses.DataSource = objD.ToList();
                grdDepartmentCourses.DataBind();
            }
        }
Example #23
0
        protected void GetCourses()
        {
            using (comp2007Entities db = new comp2007Entities())
            {
                try
                {
                    String SortString = Session["SortColumn"].ToString() + " " + Session["SortDirection"].ToString();

                    var Courses = from c in db.Courses
                                  select new { c.CourseID, c.Title, c.Credits, c.Department.Name };
                    grdCourses.DataSource = Courses.AsQueryable().OrderBy(SortString).ToList();
                    grdCourses.DataBind();
                }
                catch (Exception e)
                {
                    Response.Redirect("error.aspx");
                }

            }
        }
        protected void GetCourse()
        {
            int courseID = int.Parse(Request.QueryString["CourseID"]);

            using (comp2007Entities db = new comp2007Entities())
            {
                Course course = (from obj in db.Courses where obj.CourseID == courseID select obj).FirstOrDefault();

                txtTitle.Text = course.Title;
                txtCredits.Text = course.Credits.ToString();

                var objS = (from s in db.Students
                            join e in db.Enrollments on s.StudentID equals e.StudentID
                            join c in db.Courses on e.CourseID equals c.CourseID
                            where c.CourseID == courseID
                            select new { s.StudentID, s.LastName, s.FirstMidName, s.EnrollmentDate, e.EnrollmentID });

                grdCourseStudents.DataSource = objS.ToList();
                grdCourseStudents.DataBind();
            }
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            //use EF to connect to SQL Server
            using (comp2007Entities db = new comp2007Entities())
            {

                //use the Student model to save the new record
                Course c = new Course();
                Int32 CourseID = 0;

                //check the querystring for an id so we can determine add / update
                if (Request.QueryString["CourseID"] != null)
                {
                    //get the id from the url
                    CourseID = Convert.ToInt32(Request.QueryString["CourseID"]);

                    //get the current student from EF
                    c = (from objS in db.Courses
                         where objS.CourseID == CourseID
                         select objS).FirstOrDefault();
                }

                c.DepartmentID = Convert.ToInt32(ddlDepartment.SelectedIndex);

                c.Title = txtCourseTitle.Text;
                c.Credits = Convert.ToInt32(txtCredits.Text);

                //call add only if we have no student ID
                if (CourseID == 0)
                {
                    db.Courses.Add(c);
                }

                //run the update or insert
                db.SaveChanges();

                //redirect to the updated students page
                Response.Redirect("courses.aspx");
            }
        }
        protected void grdDepartmentCourses_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            int courseID = Convert.ToInt32(grdDepartmentCourses.DataKeys[e.RowIndex].Values["CourseID"]);

            using (comp2007Entities db = new comp2007Entities())
            {
                var objE = (from en in db.Enrollments
                            where en.CourseID == courseID
                            select en);

                db.Enrollments.RemoveRange(objE);

                var objC = (from c in db.Courses
                            where c.CourseID == courseID
                            select c).FirstOrDefault();

                db.Courses.Remove(objC);
                db.SaveChanges();

                GetDepartment();
            }
        }
Example #27
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            //use EF to connect to SQL Server
            using (comp2007Entities db = new comp2007Entities())
            {

                //use the Student model to save the new record
                Student s = new Student();
                Int32 StudentID = 0;

                //check the querystring for an id so we can determine add / update
                if (Request.QueryString["StudentID"] != null)
                {
                    //get the id from the url
                    StudentID = Convert.ToInt32(Request.QueryString["StudentID"]);

                    //get the current student from EF
                    s = (from objS in db.Students
                         where objS.StudentID == StudentID
                         select objS).FirstOrDefault();
                }

                s.LastName = txtLastName.Text;
                s.FirstMidName = txtFirstMidName.Text;
                s.EnrollmentDate = Convert.ToDateTime(txtEnrollmentDate.Text);

                //call add only if we have no student ID
                if (StudentID == 0)
                {
                    db.Students.Add(s);
                }

                //run the update or insert
                db.SaveChanges();

                //redirect to the updated students page
                Response.Redirect("students.aspx");
            }
        }
        protected void GetStudent()
        {
            int studentID = int.Parse(Request.QueryString["StudentID"]);

            using (comp2007Entities db = new comp2007Entities())
            {
                Student s = (from objS in db.Students where objS.StudentID == studentID select objS).FirstOrDefault();

                txtLastName.Text = s.LastName;
                txtFirstMidName.Text = s.FirstMidName;

                txtEnrollmentDate.Text = s.EnrollmentDate.ToString("yyyy-mm-dd");

                var objE = (from en in db.Enrollments
                            join c in db.Courses on en.CourseID equals c.CourseID
                            join d in db.Departments on c.DepartmentID equals d.DepartmentID
                            where en.StudentID == studentID
                            select new { en.EnrollmentID, en.Grade, c.Title, d.Name });

                grdStudentCourses.DataSource = objE.ToList();
                grdStudentCourses.DataBind();
            }
        }
Example #29
0
        protected void GetStudents()
        {
            //connect to EF
            using (comp2007Entities db = new comp2007Entities())
            {

                try
                {
                    //query the students table using EF and LINQ
                    var Students = from s in db.Students
                                   select s;

                    //bind the result to the gridview
                    grdStudents.DataSource = Students.ToList();
                    grdStudents.DataBind();
                }
                catch (Exception)
                {

                    Response.Redirect("error.aspx");
                }

            }
        }
        protected void grdDepartments_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            //store which row was clicked
            Int32 selectedRow = e.RowIndex;

            //get the selected departmentID using the grid's data key collection
            Int32 departmentID = Convert.ToInt32(grdDepartments.DataKeys[selectedRow].Values["DepartmentID"]);

            //use EF to remove the selected student from the db
            using (comp2007Entities db = new comp2007Entities())
            {
                Department d = (from objS in db.Departments
                                where objS.DepartmentID == departmentID
                                select objS).FirstOrDefault();

                // do the deletion
                db.Departments.Remove(d);
                db.SaveChanges();
            }

            //refresh the grid
            getDepartments();
        }