Esempio n. 1
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                using (comp2007Entities db = new comp2007Entities())
                {

                    Course c = new Course();

                    Int32 CourseID = 0;

                    if (Request.QueryString["CourseID"] != null)
                    {
                        CourseID = Convert.ToInt32(Request.QueryString["CourseID"]);

                        c = (from objD in db.Courses where objD.CourseID == CourseID select objD).FirstOrDefault();
                    }
                    c.Title = txtTitle.Text;
                    c.Credits = Convert.ToInt32(txtCredits.Text);
                    c.DepartmentID = Convert.ToInt32(ddlCourses.SelectedValue);

                    if (CourseID == 0)
                    {
                        db.Courses.Add(c);
                    }
                    db.SaveChanges();
                    Response.Redirect("courses.aspx");
                }
            }
            catch (Exception ex)
            {
                Response.Redirect("/error.aspx");
            }
        }
Esempio n. 2
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                using (comp2007Entities db = new comp2007Entities())
                {
                    Student s = new Student();
                    Int32 StudentID = 0;

                    if (Request.QueryString["StudentID"] != null)
                    {
                        StudentID = Convert.ToInt32(Request.QueryString["StudentID"]);

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

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

                    Enrollment en = new Enrollment();
                    en.CourseID = Convert.ToInt32(ddlCourses.SelectedValue);
                    en.StudentID = s.StudentID;

                    if (StudentID == 0)
                    {
                        db.Students.Add(s);
                        db.Enrollments.Add(en);
                    }
                    db.SaveChanges();
                    Response.Redirect("students.aspx");
                }
            }
            catch (Exception ex)
            {
                Response.Redirect("/error.aspx");
            }
        }
        protected void grdDepartments_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            try {
            Int32 selectedRow = e.RowIndex;

            Int32 DepartmentID = Convert.ToInt32(grdDepartments.DataKeys[selectedRow].Values["DepartmentID"]);

            using (comp2007Entities db = new comp2007Entities())
            {
                Department d = (from objD in db.Departments where objD.DepartmentID == DepartmentID select objD).FirstOrDefault();
                db.Departments.Remove(d);
                db.SaveChanges();
            }
            GetDepartments();
            }
            catch (Exception ex)
            {
                Response.Redirect("/error.aspx");
            }
        }
Esempio n. 4
0
        protected void grdStudents_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            try {
            Int32 StudentID = Convert.ToInt32(grdStudents.DataKeys[e.RowIndex].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();
            }
            GetCourse();
            }
            catch (Exception ex)
            {
                Response.Redirect("/error.aspx");
            }
        }
Esempio n. 5
0
        protected void grdCourses_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            try {
            Int32 selectedRow = e.RowIndex;

            Int32 CourseID = Convert.ToInt32(grdCourses.DataKeys[selectedRow].Values["CourseID"]);

            using (comp2007Entities db = new comp2007Entities())
            {
                Course c = (from objC in db.Courses where objC.CourseID == CourseID select objC).FirstOrDefault();
                db.Courses.Remove(c);
                db.SaveChanges();
            }
            GetCourses();
            }
            catch (Exception ex)
            {
                Response.Redirect("/error.aspx");
            }
        }
Esempio n. 6
0
        protected void grdEnrollment_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            try
            {
                Int32 EnrollmentID = Convert.ToInt32(grdEnrollment.DataKeys[e.RowIndex].Values["EnrollmentID"]);

                using (comp2007Entities db = new comp2007Entities())
                {
                    Enrollment en = (from objE in db.Enrollments where objE.EnrollmentID == EnrollmentID select objE).FirstOrDefault();
                    db.Enrollments.Remove(en);
                    db.SaveChanges();
                }
                GetStudent();

            }
            catch (Exception ex)
            {
                Response.Redirect("/error.aspx");
            }
        }