Exemplo n.º 1
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            //connect
            using (DefaultConnection conn = new DefaultConnection())
            {
                //instantiate a new student object in memory
                Course c = new Course();

                //decide if updating or adding, then save
                if (!String.IsNullOrEmpty(Request.QueryString["CourseID"]))
                {
                    Int32 CourseID = Convert.ToInt32(Request.QueryString["CourseID"]);

                    c = (from crs in conn.Courses
                         where crs.CourseID == CourseID
                         select crs).FirstOrDefault();
                }

                //fill the properties of our object from the form inputs
                c.Title = txtTitle.Text;
                c.Credits = Convert.ToInt32(txtCredits.Text);
                c.DepartmentID = Convert.ToInt32(ddlDepartment.SelectedValue);

                if (Request.QueryString.Count == 0)
                {
                    conn.Courses.Add(c);
                }
                conn.SaveChanges();

                //redirect to updated departments page
                Response.Redirect("Courses.aspx");
            }
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            //connect
            using (DefaultConnection conn = new DefaultConnection())
            {
                //instantiate a new deparment object in memory
                Department d = new Department();

                //decide if updating or adding, then save
                if (Request.QueryString.Count > 0)
                {
                    Int32 DepartmentID = Convert.ToInt32(Request.QueryString["DepartmentID"]);

                    d = (from dep in conn.Departments
                         where dep.DepartmentID == DepartmentID
                         select dep).FirstOrDefault();
                }

                //fill the properties of our object from the form inputs
                d.Name = txtName.Text;
                d.Budget = Convert.ToDecimal(txtBudget.Text);

                if (Request.QueryString.Count == 0)
                {
                    conn.Departments.Add(d);
                }
                conn.SaveChanges();

                //redirect to updated departments page
                Response.Redirect("departments.aspx");
            }
        }
Exemplo n.º 3
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            //connect
            using (DefaultConnection conn = new DefaultConnection())
            {
                //instantiate a new student object in memory
                Student s = new Student();

                //decide if updating or adding, then save
                if (Request.QueryString.Count > 0)
                {
                    Int32 StudentID = Convert.ToInt32(Request.QueryString["StudentID"]);

                    s = (from stu in conn.Students
                         where stu.StudentID == StudentID
                         select stu).FirstOrDefault();
                }

                //fill the properties of our object from the form inputs
                s.FirstMidName = txtFirstName.Text;
                s.LastName = txtLastName.Text;
                s.EnrollmentDate = Convert.ToDateTime(txtEnrollDate.Text);

                if (Request.QueryString.Count == 0)
                {
                    conn.Students.Add(s);
                }
                conn.SaveChanges();

                //redirect to updated departments page
                Response.Redirect("students.aspx");
            }
        }
Exemplo n.º 4
0
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            using (DefaultConnection conn = new DefaultConnection())
            {

                Int32 StudentID = Convert.ToInt32(ddlStudent.SelectedValue);
                Int32 CourseID = Convert.ToInt32(Request.QueryString["CourseID"]);

                Enrollment objE = new Enrollment();

                objE.StudentID = StudentID;
                objE.CourseID = CourseID;

                conn.Enrollments.Add(objE);
                conn.SaveChanges();

                //refresh
                GetStudents();

            }
        }
        protected void grdDepCourses_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            //get the selected Course id
            Int32 CourseID = Convert.ToInt32(grdDepCourses.DataKeys[e.RowIndex].Values["CourseID"]);

            using (DefaultConnection conn = new DefaultConnection())
            {

                Course objC = (from c in conn.Courses
                                   where c.CourseID == CourseID
                                   select c).FirstOrDefault();

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

                GetDepartment();

            }
        }
        protected void grdDepartments_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            //connect
            using (DefaultConnection conn = new DefaultConnection())
            {
                //get the selected department id
                Int32 DepartmentID = Convert.ToInt32(grdDepartments.DataKeys[e.RowIndex].Values["DepartmentID"]);

                var d = (from dep in conn.Departments
                         where dep.DepartmentID == DepartmentID
                         select dep).FirstOrDefault();

                //delete
                conn.Departments.Remove(d);
                conn.SaveChanges();

                //update the grid
                GetDepartments();

            }
        }
Exemplo n.º 7
0
        protected void grdStudents_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            //connect
            using (DefaultConnection conn = new DefaultConnection())
            {
                //get the selected department id
                Int32 StudentID = Convert.ToInt32(grdStudents.DataKeys[e.RowIndex].Values["StudentID"]);

                var s = (from stu in conn.Students
                         where stu.StudentID == StudentID
                         select stu).FirstOrDefault();

                //delete
                conn.Students.Remove(s);
                conn.SaveChanges();

                //update the grid
                GetStudents();

            }
        }
Exemplo n.º 8
0
        protected void grdStudents_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            //get the selected enrollment id
            Int32 EnrollmentID = Convert.ToInt32(grdStudents.DataKeys[e.RowIndex].Values["EnrollmentID"]);

            using (DefaultConnection conn = new DefaultConnection())
            {

                Enrollment objE = (from en in conn.Enrollments
                                   where en.EnrollmentID == EnrollmentID
                                   select en).FirstOrDefault();

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

                GetStudents();

            }
        }