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

                Student stud = new Student();

                if (!String.IsNullOrEmpty(Request.QueryString["StudentID"]))
                {

                    Int32 StudentID = Convert.ToInt32(Request.QueryString["StudentID"]);
                     stud = (from s in db.Students
                                   where s.StudentID == StudentID
                                   select s).FirstOrDefault();
                }

                stud.LastName = txtName.Text;
                stud.FirstMidName = txtFirstName.Text;
                stud.EnrollmentDate = Convert.ToDateTime(txtEnrollmentDate.Text);

                // add the new department if no url
                if (String.IsNullOrEmpty(Request.QueryString["StudentID"]))
                {
                    db.Students.Add(stud);
                    db.SaveChanges();
                }

                // save new department
                db.SaveChanges();

                //redirect
                Response.Redirect("students.aspx");
            }
        }
Esempio n. 2
0
        protected void GetDepartments()
        {
            // use entity framework to connect and get the list of departments
            using (DefaultConnection db = new DefaultConnection())
            {
                var deps = from d in db.Departments
                           select d;

                // bind the deps query result to our grid
                grdDepartments.DataSource = deps.ToList();
                grdDepartments.DataBind();
            }
        }
Esempio n. 3
0
        protected void GetStudents()
        {
            // use entity framework to connect and get the list of departments
            using (DefaultConnection db = new DefaultConnection())
            {
                var stud = from s in db.Students
                           select s;

                //append the current direction to the Sort Column
                String Sort = Session["SortColumn"].ToString() + " " + Session["SortDirection"].ToString();

                grdStudents.DataSource = stud.AsQueryable().OrderBy(Sort).ToList();

                grdStudents.DataBind();

            }
        }
Esempio n. 4
0
        protected void GetStudent()
        {
            using (DefaultConnection db = new DefaultConnection())
            {

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

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

                txtFirstName.Text = stu.LastName;
                txtName.Text = stu.FirstMidName;
                txtEnrollmentDate.Text = Convert.ToString(stu.EnrollmentDate);

            }
        }
Esempio n. 5
0
        protected void grdStudents_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            // identify the department id to be deleted from the row the user selected
            Int32 StudentID = Convert.ToInt32(grdStudents.DataKeys[e.RowIndex].Values["StudentID"]);

            //connect
            using (DefaultConnection db = new DefaultConnection())
            {
                Student stud = (from s in db.Students
                                where s.StudentID == StudentID
                                select s).FirstOrDefault();

                // delete
                db.Students.Remove(stud);
                db.SaveChanges();

                //refresh the grid
                GetStudents();

            }
        }