コード例 #1
0
ファイル: course.aspx.cs プロジェクト: KrunalSParmar/Lab3
        protected void btnSave_Click(object sender, EventArgs e)
        {
            //do insert or update
            using (comp2007Entities db = new comp2007Entities())
            {
                Course objC = new Course();

                if (!String.IsNullOrEmpty(Request.QueryString["CourseID"]))
                {
                    Int32 CourseID = Convert.ToInt32(Request.QueryString["CourseID"]);
                    objC = (from c in db.Courses
                            where c.CourseID == CourseID
                            select c).FirstOrDefault();
                }

                //populate the course from the input form
                objC.Title = txtTitle.Text;
                objC.Credits = Convert.ToInt32(txtCredits.Text);
                objC.DepartmentID = Convert.ToInt32(ddlDepartment.SelectedValue);

                if (String.IsNullOrEmpty(Request.QueryString["CourseID"]))
                {
                    //add
                    db.Courses.Add(objC);
                }

                //save and redirect
                db.SaveChanges();
                Response.Redirect("courses.aspx");
            }
        }
コード例 #2
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            using (comp2007Entities db = new comp2007Entities())
            {
                //use the student model to save record
                Student s = new Student();
                Enrollment en = new Enrollment();
                Int32 StudentID = 0;
                //check query string for an id so we can determine add or update
                if (Request.QueryString["StudentID"] != null)
                {
                    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 = txtFirstName.Text;
                s.EnrollmentDate = Convert.ToDateTime(txtEnrollmentDate.Text);

                //add only if student has no ID
                if (StudentID == 0)
                {
                    //redirect to updated table of students
                    db.Students.Add(s);

                }
                db.SaveChanges();
                Response.Redirect("students.aspx");
            }
        }
コード例 #3
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            using (comp2007Entities db = new comp2007Entities())
            {
                //use the student model to save record
                Department d = new Department();

                Int32 DepartmentID = 0;

                //check query string for an id so we can determine add or update
                if (Request.QueryString["DepartmentID"] != null)
                {
                    DepartmentID = Convert.ToInt32(Request.QueryString["DepartmentID"]);

                    //get the current student from EF
                    d = (from objD in db.Departments where objD.DepartmentID == DepartmentID select objD).FirstOrDefault();
                }
                d.Name = txtName.Text;
                d.Budget = Convert.ToDecimal(txtBudget.Text);

                //redirect to updated table of students
                if (DepartmentID == 0)
                {
                    db.Departments.Add(d);
                }
                db.SaveChanges();
                Response.Redirect("departments.aspx");
            }
        }
コード例 #4
0
        protected void grdCourse_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            Int32 CourseID = Convert.ToInt32(grdCourse.DataKeys[e.RowIndex].Values["CourseID"]);

            using (comp2007Entities db = new comp2007Entities())
            {
                Course objE = (from en in db.Courses
                                   where en.CourseID == CourseID
                                   select en).FirstOrDefault();
                db.Courses.Remove(objE);
                db.SaveChanges();

                GetDepartment();
            }
        }
コード例 #5
0
ファイル: student.aspx.cs プロジェクト: KrunalSParmar/Lab3
        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");
            }
        }
コード例 #6
0
        protected void grdDepartments_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            //store the row clicked
            Int32 selectedRow = e.RowIndex;

            //get the selected StudentID
            Int32 DepartmentID = Convert.ToInt32(grdDepartments.DataKeys[selectedRow].Values["DepartmentID"]);

            //using EF to remove selected student
            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();
            }
            //refresh grid
            GetDepartments();
        }
コード例 #7
0
        protected void grdCourses_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            //store the row clicked
            Int32 selectedRow = e.RowIndex;

            //get the selected StudentID
            Int32 CourseID = Convert.ToInt32(grdCourses.DataKeys[selectedRow].Values["CourseID"]);

            //using EF to remove selected student
            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();
            }
            //refresh grid
            GetCourses();
        }
コード例 #8
0
        protected void grdStudent_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            Int32 EnrollmentID = Convert.ToInt32(grdStudent.DataKeys[e.RowIndex].Values["EnrollmentID"]);

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

                GetStudent();
            }
        }
コード例 #9
0
ファイル: students.aspx.cs プロジェクト: KrunalSParmar/Lab3
        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())
            {

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

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

            //refresh the grid
            GetStudents();
        }
コード例 #10
0
ファイル: course.aspx.cs プロジェクト: KrunalSParmar/Lab3
        protected void grdStudents_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            Int32 StudentID = Convert.ToInt32(grdStudents.DataKeys[e.RowIndex].Values["StudentID"]);

            using (comp2007Entities db = new comp2007Entities())
            {
                //get selected record
                Student objE = (from s in db.Students
                                   where s.StudentID == StudentID
                                   select s).FirstOrDefault();

                //Delete
                db.Students.Remove(objE);
                db.SaveChanges();

                //Refresh the data on the page
                GetCourse();
            }
        }