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 GetCourses()
        {
            // use entity framework to connect and get the list of departments
            using (DefaultConnection db = new DefaultConnection())
            {
                var cours = from c in db.Courses
                            select c;

                // bind the deps query result to our grid
                grdCourses.DataSource = cours.ToList();
                grdCourses.DataBind();
            }
        }
Esempio n. 4
0
        protected void GetEnrolledCourses()
        {
            using (DefaultConnection db = new DefaultConnection())
            {
                Int32 StudentID = Convert.ToInt32(Request.QueryString["StudentID"]);
                //Courses objc = (from s in db.Students
                //                where s.StudentID == StudentID
                //                select s).FirstOrDefault();
                //txtTitle.Text = objc.Title;
                //txtCredits.Text = objc.Credits.ToString();
                //ddlDepartments.SelectedValue = objc.DepartmentID.ToString();

            }
        }
Esempio n. 5
0
        protected void GetDepartments()
        {
            using (DefaultConnection db = new DefaultConnection())
            {
                var deps = from d in db.Departments
                           orderby d.Name
                           select d;

                ddlDepartments.DataSource = deps.ToList();
                ddlDepartments.DataBind();

                ListItem DefaultItem = new ListItem("-Select-", "0");
                ddlDepartments.Items.Insert(0, DefaultItem);
            }
        }
Esempio n. 6
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            using (DefaultConnection db = new DefaultConnection())
            {
                Course objc = new Course();
                objc.Title = txtTitle.Text;
                objc.Credits = Convert.ToInt32(txtCredits.Text);
                objc.DepartmentID = Convert.ToInt32(ddlDepartments.SelectedValue);

                db.Courses.Add(objc);
                db.SaveChanges();

                Response.Redirect("courses.aspx");

            }
        }
Esempio n. 7
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. 8
0
        protected void GetDepartment()
        {
            // look up the selected department and fill the form
            using (DefaultConnection db = new DefaultConnection())
            {
                // store the id from url in variable
                Int32 DepartmentID = Convert.ToInt32(Request.QueryString["DepartmentID"]);

                // look up the department
                Department dep = (from d in db.Departments
                                  where d.DepartmentID == DepartmentID
                                  select d).FirstOrDefault();

                // prepoulate form fields
                txtName.Text = dep.Name;
                txtBudget.Text = Convert.ToString(dep.Budget);
            }
        }
Esempio n. 9
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();

            }
        }
Esempio n. 10
0
        protected void GetCourse()
        {
            using (DefaultConnection db = new DefaultConnection())
            {
                Int32 CourseID = Convert.ToInt32(Request.QueryString["CourseID"]);
                Course objc = (from c in db.Courses
                               where c.CourseID == CourseID
                               select c).FirstOrDefault();
                txtTitle.Text = objc.Title;
                txtCredits.Text = objc.Credits.ToString();
                ddlDepartments.SelectedValue = objc.DepartmentID.ToString();

                //populate student enrollments grid
                var Enrollments = from en in db.Enrollments
                                  where en.CourseID == CourseID
                                  orderby en.Student.LastName
                                  select en;
                grdEnrollments.DataSource = Enrollments.ToList();
                grdEnrollments.DataBind();

            }
        }
Esempio n. 11
0
        protected void GetStudent()
        {
            Int32 StudentID = Convert.ToInt32(Request.QueryString["StudentID"]);
            using (DefaultConnection db = new DefaultConnection())
            {

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

                if (stu != null)
                {
                    txtName.Text = stu.LastName;
                    txtFirstName.Text = stu.FirstMidName;
                    txtEnrollmentDate.Text = stu.EnrollmentDate.ToString("yyyy-MM-dd");
                }

                var Courses = from c in db.Enrollments
                              where c.StudentID == StudentID
                              select c;
                grdCoursesEnrolled.DataSource = Courses.ToList();
                grdCoursesEnrolled.DataBind();
            }
        }
Esempio n. 12
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            // connect
            using (DefaultConnection db = new DefaultConnection())
            {
                // create a new department in memory
                Department dep = new Department();

                //check for url
                if (!String.IsNullOrEmpty(Request.QueryString["DepartmentID"]))
                {
                    // get ud from url
                    Int32 DepartmentID = Convert.ToInt32(Request.QueryString["DepartmentID"]);
                    dep = (from d in db.Departments
                           where d.DepartmentID == DepartmentID
                           select d).FirstOrDefault();
                }

                // fill the properties of the new department
                dep.Name = txtName.Text;
                dep.Budget = Convert.ToDecimal(txtBudget.Text);

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

                // save new department
                db.SaveChanges();

                //redirect
                Response.Redirect("departments.aspx");
            }
        }