protected void GetCourse()
        {
            //connect
            using (DefaultConnection db = new DefaultConnection())
            {
                //get the slected courseid from the url
                Int32 CourseID = Convert.ToInt32(Request.QueryString["CourseID"]);

                //query the db
                Course objC = (from c in db.Courses
                              where c.CourseID == CourseID
                              select c).FirstOrDefault();

                //populate the form
                txtTitle.Text = objC.Title;
                txtCredits.Text = objC.Credits.ToString();
                ddlDepartment.SelectedValue = objC.DepartmentID.ToString();

                //populate student enrollment grid
                var Enrollments = from en in db.Enrollments
                                  where en.CourseID == CourseID
                                  select en;

                //bind to grid
                grdEnrollments.DataSource = Enrollments.ToList();
                grdEnrollments.DataBind();

            }
        }
Ejemplo n.º 2
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 d in db.Students where d.StudentID == StudentID select d).FirstOrDefault();
                }

                stud.LastName = txtLName.Text;
                stud.FirstMidName = txtFName.Text;
                stud.EnrollmentDate = Convert.ToDateTime(txtEnrollmentDate.Text);

                if (String.IsNullOrEmpty(Request.QueryString["StudentID"]))
                {
                    db.Students.Add(stud);
                }
                db.Students.Add(stud);
                db.SaveChanges();

                Response.Redirect("students.aspx");
            }
        }
Ejemplo n.º 3
0
        protected void GetStudent()
        {
            //look up the selected student and fill the form
            using (DefaultConnection db = new DefaultConnection())
            {
                //store the id from url in a variable
                Int32 StudentID = Convert.ToInt32(Request.QueryString["StudentID"]);

                //look up student record based on id above
                Student stud = (from s in db.Students
                                where s.StudentID == StudentID
                                select s).FirstOrDefault();

                //pre populate form fields based on record info above
                txtLastName.Text = stud.LastName;
                txtFirstName.Text = stud.FirstMidName;
                txtDateEnrolled.Text = stud.EnrollmentDate.ToString();

                //populate enrollment grid
                var Enrollments = from en in db.Enrollments
                                  from c in db.Courses
                                  where en.StudentID == StudentID
                                  where c.CourseID == en.CourseID
                                  select en;

                //bind to grid
                grdCourses.DataSource = Enrollments.ToList();
                grdCourses.DataBind();

            }
        }
Ejemplo n.º 4
0
        protected void GetCourses()
        {
            using (DefaultConnection db = new DefaultConnection())
            {
                var courses = from c in db.Courses
                              select c;

                grdCourses.DataSource = courses.ToList();
                grdCourses.DataBind();
            }
        }
Ejemplo n.º 5
0
        protected void GetStudents()
        {
            using (DefaultConnection db = new DefaultConnection())
            {
                var studs = from d in db.Students
                           select d;

                grdStudents.DataSource = studs.ToList();
                grdStudents.DataBind();
            }
        }
Ejemplo n.º 6
0
        protected void GetCourses()
        {
            //use Entity Framework to connect and get the list of Departments
            using (DefaultConnection db = new DefaultConnection())
            {
                var crs = from c in db.Courses
                            select c;

                //bind the deps query result to our grid
                grdCourses.DataSource = crs.ToList();
                grdCourses.DataBind();
            }
        }
Ejemplo n.º 7
0
        protected void GetStudents()
        {
            //use Entity Framework to connect and get the list of Departments
            using (DefaultConnection db = new DefaultConnection())
            {
                var studs = from d in db.Students
                           select d;

                //bind the deps query result to our grid
                grdStudents.DataSource = studs.ToList();
                grdStudents.DataBind();
            }
        }
        protected void GetDepartment()
        {
            //look up the selected department and fill the form
            using (DefaultConnection db = new DefaultConnection())
            {
                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();

                //prepopulate the form fields
                txtName.Text = dep.Name;
                txtBudget.Text = dep.Budget.ToString();
            }
        }
Ejemplo n.º 9
0
        protected void grdStudents_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            Int32 StudentID = Convert.ToInt32(grdStudents.DataKeys[e.RowIndex].Values["StudentID"]);

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

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

                GetStudents();
            }
        }
        protected void GetDepartments()
        {
            using (DefaultConnection db = new DefaultConnection())
            {
                //get department list
                var Departments = from d in db.Departments
                                  orderby d.Name
                                  select d;

                //bind to the dropdown list
                ddlDepartment.DataSource = Departments.ToList();
                ddlDepartment.DataBind();

                //add a default option to the dropdown after we fill it
                ListItem DefaultItem = new ListItem("-Select-", "0");
                ddlDepartment.Items.Insert(0, DefaultItem);
            }
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            //connect
            using (DefaultConnection db = new DefaultConnection())
            {
                //create a new course and fill the properties
                Course objC = new Course();
                objC.Title = txtTitle.Text;
                objC.Credits = Convert.ToInt32(txtCredits.Text);
                objC.DepartmentID = Convert.ToInt32(ddlDepartment.SelectedValue);

                //save
                db.Courses.Add(objC);
                db.SaveChanges();

                //redirect
                Response.Redirect("courses.aspx");
            }
        }
Ejemplo n.º 12
0
        protected void GetStudent()
        {
            //look up the selected student and fill the form
            using (DefaultConnection db = new DefaultConnection())
            {
                //store the id from url in a variable
                Int32 StudentID = Convert.ToInt32(Request.QueryString["StudentID"]);

                //look up student record based on id above
                Student stud = (from s in db.Students
                                where s.StudentID == StudentID
                                select s).FirstOrDefault();

                //pre populate form fields based on record info above
                txtLastName.Text = stud.LastName;
                txtFirstName.Text = stud.FirstMidName;
                txtDateEnrolled.Text = stud.EnrollmentDate.ToString();
            }
        }
Ejemplo n.º 13
0
        protected void grdStudents_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            //identify the student ID to be deleted from the row the user selected
            Int32 StudentID = Convert.ToInt32(grdStudents.DataKeys[e.RowIndex].Values["StudentID"]);

            //connect to db
            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 grid
                GetStudents();
            }
        }
Ejemplo n.º 14
0
        protected void grdDepartments_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            //identify the DepartmentID to be deleted from the row the user selected
            Int32 DepartmentID = Convert.ToInt32(grdDepartments.DataKeys[e.RowIndex].Values["DepartmentID"]);

            //connect
            using (DefaultConnection db = new DefaultConnection())
            {
                Department dep = (from d in db.Departments
                                  where d.DepartmentID == DepartmentID
                                  select d).FirstOrDefault();

                //delete
                db.Departments.Remove(dep);
                db.SaveChanges();

                //refresh grid
                GetDepartments();
            }
        }
Ejemplo n.º 15
0
        protected void GetStudent()
        {
            using (DefaultConnection db = new DefaultConnection())
            {
                Int32 StudentID = Convert.ToInt32(Request.QueryString["StudentID"]);

                Student stud = (from d in db.Students where d.StudentID == StudentID select d).FirstOrDefault();

                txtLName.Text = stud.LastName;
                txtFName.Text = stud.FirstMidName;
                txtEnrollmentDate.Text = stud.EnrollmentDate.ToString();

                //populate student enrollment grid
                var Enrollments = from en in db.Enrollments
                                  where en.StudentID == StudentID
                                  select en;

                //bind to grid
                grdCourseEnrollments.DataSource = Enrollments.ToList();
                grdCourseEnrollments.DataBind();
            }
        }
Ejemplo n.º 16
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            //connect
            using (DefaultConnection db = new DefaultConnection())
            {
                // create a new student in memory
                Student stud = new Student();

                //check for a url
                if (!String.IsNullOrEmpty(Request.QueryString["StudentID"]))
                {
                    //get id from url
                    Int32 StudentID = Convert.ToInt32(Request.QueryString["StudentID"]);

                    //look up the student
                    stud = (from s in db.Students
                            where s.StudentID == StudentID
                            select s).FirstOrDefault();
                }

                // fill properties of new student
                stud.LastName = txtLastName.Text;
                stud.FirstMidName = txtFirstName.Text;
                stud.EnrollmentDate = Convert.ToDateTime(txtDateEnrolled.Text);

                //add if we have no id in the url
                if (String.IsNullOrEmpty(Request.QueryString["StudentID"]))
                {
                    stud.EnrollmentDate = System.DateTime.Now;
                    db.Students.Add(stud);
                }
                db.SaveChanges();

                //redirect to students list page
                Response.Redirect("students.aspx");
            }
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            using(DefaultConnection db = new DefaultConnection())
            {
                //create a new department in memory
                Department dep = new Department();

                //check for a url
                if(!String.IsNullOrEmpty(Request.QueryString["DepartmentID"]))
                {
                    //get the id from url
                    Int32 DepartmentID = Convert.ToInt32(Request.QueryString["DepartmentID"]);

                    //look up the department
                    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 if we have no id in the url

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

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