protected void getStudent()
        {
            //fill in form based upon selected student
            using (DefaultConnection db = new DefaultConnection())
            {
                Int32 StudentID = Convert.ToInt32(Request.QueryString["StudentID"]);

                //search departmet
                Student stdt = (from s in db.Students
                                where s.StudentID == StudentID
                                select s).FirstOrDefault();

                //populate fields
                txtLName.Text = stdt.LastName;
                txtFName.Text = stdt.FirstMidName;

                //populate courses grid
                var courses = from en in db.Enrollments
                              where en.StudentID == StudentID
                              orderby en.Course.Title
                              select en;

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

            }
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            //connect
            using (DefaultConnection db = new DefaultConnection())
            {
                //create new course and fill properties
                Course objc = new Course();
                objc.Title = txtTitle.Text;
                objc.Credits = Convert.ToInt32(txtCredits.Text);
                objc.DepartmentID = Convert.ToInt32(ddlDepartments.SelectedValue);

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

                //redirect back to courses page
                Response.Redirect("courses.aspx");

                //handle updating a record
                if (!string.IsNullOrEmpty(Request.QueryString["CourseID"]))
                {
                    Int32 CourseID = Convert.ToInt32(Request.QueryString["DepartmentID"]);

                }

            }
        }
        protected void getCourse()
        {
            //fill in form based upon selected course
            Int32 CourseID = Convert.ToInt32(Request.QueryString["CourseID"]);

            using (DefaultConnection db = new DefaultConnection())
            {
                //query database
                Course objc = (from c in db.Courses
                               where c.CourseID == CourseID
                               select c).FirstOrDefault();

                //populate the form
                txtTitle.Text = objc.Title;
                txtCredits.Text = Convert.ToString(objc.Credits);

                //assaign value for drop down menu
                ddlDepartments.SelectedValue = Convert.ToString(objc.DepartmentID);

                //populate enrollments grid
                var Enrollments = from en in db.Enrollments
                                  where en.CourseID == CourseID
                                  orderby en.Student.LastName, en.Student.FirstMidName
                                  select en;

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

            }
        }
Esempio n. 4
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"]);
            try
            {
                //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();

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

            }
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            //connect
            using (DefaultConnection db = new DefaultConnection())
            {
                //creating new student
                Student stu = new Student();
                Int32 StudentID = 0;
                //check for a url
                if (!String.IsNullOrEmpty(Request.QueryString["StudentID"]))
                {
                    //get the id
                     StudentID = Convert.ToInt32(Request.QueryString["StudentID"]);

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

                //properties for new students
                stu.LastName = txtLast.Text;
                stu.FirstMidName = txtFirst.Text;
                stu.EnrollmentDate = Convert.ToDateTime(txtEnroll.Text);
                if (StudentID == 0)
                {
                    db.Students.Add(stu);
                }

                //save new students
                db.SaveChanges();
                //send back to student page
                Response.Redirect("Students.aspx");
            }
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            //connect
            using (DefaultConnection db = new DefaultConnection())
            {
                //create new department in memory
                Department dep = new Department();

                //check url
                if(!String.IsNullOrEmpty(Request.QueryString["DepartmentID"]))
                {
                    Int32 DepartmentID = Convert.ToInt32(Request.QueryString["DepartmentID"]);

                    dep = (from d in db.Departments
                           where d.DepartmentID == DepartmentID
                           select d).FirstOrDefault();

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

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

                //redirect to department list page
                Response.Redirect("departments.aspx");
            }
        }
Esempio n. 7
0
        protected void GetDepartment()
        {
            try
            {
                //look up the selected department and fill the form
                using (DefaultConnection db = new DefaultConnection())
                {
                    //store the id from the url in a 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();

                    //pre-populate the form fields
                    txtName.Text = dep.Name;
                    txtBudget.Text = dep.Budget.ToString();
                }
            }
            catch (Exception ex)
            {
                Response.Redirect("error.aspx");

            }
        }
Esempio n. 8
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            using (DefaultConnection db = new DefaultConnection())
            {
                Student stu = new Student();

                Int32 StudentID = 0;

                if (!String.IsNullOrEmpty(Request.QueryString["StudentID"]))
                {
                    StudentID = Convert.ToInt32(Request.QueryString["StudentID"]);
                    stu = (from s in db.Students
                           where s.StudentID == StudentID
                           select s).FirstOrDefault();

                 }

                stu.LastName = txtLastName.Text;
                stu.FirstMidName = txtFirstName.Text;
                stu.EnrollmentDate = Convert.ToDateTime(txtDate.Text);

                if (StudentID == 0)
                {
                    db.Students.Add(stu);
                }
                db.SaveChanges();

                Response.Redirect("students.aspx");

            }
        }
Esempio n. 9
0
 //Entity Framework to bring in students list
 protected void GetStudents()
 {
     using (DefaultConnection db = new DefaultConnection())
     {
         var stu = from s in db.Students select s;
         grdStudents.DataSource = stu.ToList();
         grdStudents.DataBind();
     }
 }
Esempio n. 10
0
 protected void GetStudents()
 {
     //use enity framework to connect to get list of students
     using (DefaultConnection db = new DefaultConnection())
     {
         var stud = from s in db.Students
                    select s;
         //bind stud query results to our grid
         grdStudents.DataSource = stud.ToList();
         grdStudents.DataBind();
     }
 }
Esempio n. 11
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. 12
0
        protected void GetStudents()
        {
            //use entity framework to connect and get list of Departments
            using (DefaultConnection db = new DefaultConnection())
            {
                var stud = from d in db.Students
                           select d;

                //bind the stud query result to grid
                grdStudents.DataSource = stud.ToList();
                grdStudents.DataBind();
            }
        }
        protected void getStudents()
        {
            //conect and use database student table
            using (DefaultConnection db = new DefaultConnection())
            {
                var stdt = from s in db.Students
                           select s;

                //bind query return to grid
                grdStudents.DataSource = stdt.ToList();
                grdStudents.DataBind();
            }
        }
        protected void GetStudents()
        {
            //Using the Entity Framework to connect and get the list of Students.
            using (DefaultConnection db = new DefaultConnection())
            {
                var students = from stu in db.Students
                               select stu;

                //Binding the Stu query results to the grid.
                grdStudents.DataSource = students.ToList();
                grdStudents.DataBind();
            }
        }
Esempio n. 15
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();
                txtLastName.Text = stu.LastName;
                txtFirstName.Text = stu.FirstMidName;
               txtDate.Text = stu.EnrollmentDate.ToString("yyyy-MM-dd");
            }
        }
        protected void GetStudents()
        {
            //look up the selected student
            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();

                txtLast.Text = stu.LastName;
                txtFirst.Text = stu.FirstMidName;
            }
        }
        protected void getDepartments()
        {
            using (DefaultConnection db = new DefaultConnection())
            {
                var dpmt = from d in db.Departments
                           orderby d.Name
                           select d;
                ddlDepartments.DataSource = dpmt.ToList();
                ddlDepartments.DataBind();

                //add default option to drop down list
                ListItem DefaultItem = new ListItem("-Select-", "0");
                ddlDepartments.Items.Insert(0, DefaultItem);
            }
        }
Esempio n. 18
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            try
            {

                //connect
                using (DefaultConnection db = new DefaultConnection())
                {
                    //create a new department in memory
                    Department dep = new Department();

                    Int32 DepartmentID = 0;

                    //check for a url
                    if (!String.IsNullOrEmpty(Request.QueryString["DepartmentID"]))
                    {
                        //get the id from the url
                        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
                    if (DepartmentID == 0)
                    {
                        db.Departments.Add(dep);
                    }

                    //save the new department
                    db.SaveChanges();

                    //redirect to the departments list page
                    Response.Redirect("departments.aspx");
                }
            }
            catch (Exception ex)
            {
                Response.Redirect("error.aspx");

            }
        }
Esempio n. 19
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 stu = (from s in db.Students
                               where s.StudentID == StudentID
                               select s).FirstOrDefault();

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

                GetStudents();

            }
        }
        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 department
                Department dep = (from d in db.Departments
                                  where d.DepartmentID == DepartmentID
                                  select d).FirstOrDefault();

                //pre-populate the form fields
                txtName.Text = dep.Name;
                txtBudget.Text = dep.Budget.ToString();
            }
        }
        protected void GetStudents()
        {
            using (DefaultConnection db = new DefaultConnection())
            {
                //Store the id from the URL in a variable
                Int32 StudentID = Convert.ToInt32(Request.QueryString["StudentID"]);

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

                //pre-populate the form fields
                txtLastName.Text = stu.LastName;
                txtFirstMidName.Text = stu.FirstMidName;
            }
        }
        protected void grdStudents_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            //identify student id to manipulate
            Int32 StudentID = Convert.ToInt32(grdStudents.DataKeys[e.RowIndex].Values["StudentID"]);

            //Select current id based upon selected row
            using (DefaultConnection db = new DefaultConnection())
            {
                Student stdt = (from s in db.Students
                                where s.StudentID == StudentID
                                select s).FirstOrDefault();
                db.Students.Remove(stdt);
                db.SaveChanges();

                //refresh grid
                getStudents();
            }
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            //connect to database
            using (DefaultConnection db = new DefaultConnection())
            {
                //create new student in memory
                Student stdt = new Student();
                Int32 StudentID = 0;

                DateTime EnDate = DateTime.Now;

                //handle updating a record
                if (!String.IsNullOrEmpty(Request.QueryString["StudentID"]))
                {
                    StudentID = Convert.ToInt32(Request.QueryString["StudentID"]);

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

                    //set enroll date to equal existing result
                    EnDate = stdt.EnrollmentDate;

                }

                //fill in student details
                stdt.FirstMidName = txtLName.Text;
                stdt.LastName = txtFName.Text;
                //add current date time as time of registering
                stdt.EnrollmentDate = EnDate;

                if (StudentID == 0)
                {
                    //create new row in database
                    db.Students.Add(stdt);
                }

                db.SaveChanges();

                //redirect back to students page
                Response.Redirect("students.aspx");

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

                //look up student
                Student stud = (from s in db.Students
                                where s.StudentID == StudentID
                                select s).FirstOrDefault();
                //populate form fields
                txtLast.Text = stud.LastName;
                txtFirst.Text = stud.FirstMidName;
                txtEnroll.Text = stud.EnrollmentDate.ToString();

            }
        }
        protected void grdDepartments_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            //identify department id to be deleted from the row the user selected
            Int32 DepartmentID = Convert.ToInt32(grdDepartments.DataKeys[e.RowIndex].Values["DepartmentID"]);

            //connect to database
            using (DefaultConnection db = new DefaultConnection())
            {
                //SElect current department based upon id
                Department dep = (from d in db.Departments
                                  where d.DepartmentID == DepartmentID
                                  select d).FirstOrDefault();
                db.Departments.Remove(dep);
                db.SaveChanges();

                //refresh the grid
                GetDepartments();

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

            //Connecting to the Database.
            using (DefaultConnection db = new DefaultConnection())
            {
                Student stu = (from s in db.Students
                                   where s.StudentID == StudentID
                                   select s).FirstOrDefault();

                //Deleting.
                db.Students.Remove(stu);
                db.SaveChanges();

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

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

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

                //refresh grid
                GetStudents();
            }
        }
Esempio n. 28
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            using (DefaultConnection db = new DefaultConnection())
            {
                //create a new student in memory
                Student stud = new Student();

                Int32 StudentID = 0;

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

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

                //fill the properties of the new student
                stud.LastName = txtLast.Text;
                stud.FirstMidName = txtFirst.Text;
                stud.EnrollmentDate = Convert.ToDateTime(txtEnroll.Text);

                //add if we have no id in the url
                if (StudentID == 0)
                {

                    db.Students.Add(stud);
                }

                //save the student
                db.SaveChanges();

                //redirect to student list page
                Response.Redirect("students.aspx");

            }
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            //connect
            using (DefaultConnection db = new DefaultConnection())
            {

                //create a new department in memory
                Department dep = new Department();

                // op2 :Int32 DepartmentID = 0;

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

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

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

                //op2: if(DepartmentID==0)

                // save the new department
                //excute the change commands
                db.SaveChanges();

                //redirect to the departments list page
                Response.Redirect("departments.aspx");

            }
        }
Esempio n. 30
0
        protected void grdStudents_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            //identify id of student to delete from the row the user has chosen
            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 grid
                Response.Redirect("students.aspx");

            }
        }