Пример #1
0
        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");
            }
        }
Пример #2
0
        protected void GetCourse()
        {
            //connect
            using (DefaultConnection db = new DefaultConnection())
            {
                //get selected 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 enrollments grid
                var Enrollments = from en in db.Enrollments
                                  where en.CourseID == CourseID
                                  orderby en.Student.LastName, en.Student.FirstMidName
                                  select en;

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

            }
        }
Пример #3
0
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            using (DefaultConnection db = new DefaultConnection())
            {
                Instructor objI = new Instructor();

                objI.FirstName = txtFirstName.Text;
                objI.LastName = txtLastName.Text;
                objI.Username = txtUsername.Text;
                objI.DepartmentID = Convert.ToInt32(ddlDepartment.SelectedValue);

                String password = txtPassword.Text;
                String salt = CreateSalt(8);
                String pass_and_salt = password + salt;

                // Create a new instance of the hash crypto service provider.
                HashAlgorithm hashAlg = new SHA256CryptoServiceProvider();
                // Convert the data to hash to an array of Bytes.
                byte[] bytValue = System.Text.Encoding.UTF8.GetBytes(pass_and_salt);
                // Compute the Hash. This returns an array of Bytes.
                byte[] bytHash = hashAlg.ComputeHash(bytValue);
                // Optionally, represent the hash value as a base64-encoded string,
                // For example, if you need to display the value or transmit it over a network.
                string base64 = Convert.ToBase64String(bytHash);

                objI.Password = base64;
                objI.Salt = salt;

                db.Instructors.Add(objI);
                db.SaveChanges();
            }
        }
Пример #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();

                txtLastName.Text = stu.LastName;
                txtFirstName.Text = stu.FirstMidName;
                txtDate.Text = stu.EnrollmentDate.ToString("yyyy-MM-dd");

                //populate student enrollments grid
                var Enrollments = from e in db.Enrollments
                                  where e.StudentID == StudentID
                                  select e;

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

                grdCourses.DataBind();

            }
        }
Пример #5
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");

            }
        }
Пример #6
0
        protected void GetStudent()
        {
            //populate form with existing student record
            Int32 StudentID = Convert.ToInt32(Request.QueryString["StudentID"]);

            //connect to db via EF
            using (DefaultConnection db = new DefaultConnection())
            {
                //populate a student instance with the StudentID from the URL parameter
                Student s = (from objS in db.Students
                             where objS.StudentID == StudentID
                             select objS).FirstOrDefault();

                //map the student properties to the form controls if we found a match
                if (s != null) {
                    txtLastName.Text = s.LastName;
                    txtFirstMidName.Text = s.FirstMidName;
                    txtEnrollmentDate.Text = s.EnrollmentDate.ToString("yyyy-MM-dd");
                }
                var Enrolled = from c in db.Enrollments
                              where c.StudentID == StudentID
                              select c;
                grdEnrolled.DataSource = Enrolled.ToList();
                grdEnrolled.DataBind();
            }
        }
Пример #7
0
 protected void GetCourses()
 {
     using (DefaultConnection db = new DefaultConnection())
     {
         var courses = from c in db.Courses
                       select c;
         grdCourses.DataSource = courses.ToList();
         grdCourses.DataBind();
     }
 }
Пример #8
0
        protected void GetCourses()
        {
            using (DefaultConnection db = new DefaultConnection())
            {
                var cours = from d in db.Courses
                             select d;

                //bind the cours query result to our grid
                grdCourses.DataSource = cours.ToList();
                grdCourses.DataBind();
            }
        }
Пример #9
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();
     }
 }
Пример #10
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();
            }
        }
Пример #11
0
        protected void GetStudents()
        {
            using (DefaultConnection db = new DefaultConnection())
            {
                var stu = from s in db.Students
                          select s;

                grdStudents.DataSource = stu.ToList();
                grdStudents.DataBind();


            }

        }
Пример #12
0
        protected void GetCourses()
        {
            //connect to EF
            using (DefaultConnection db = new DefaultConnection())
            {

                //query the courses table using EF and LINQ
                var Courses = from c in db.Courses1
                              select c;

                //bind the result to the gridview
                grdCourses.DataSource = Courses.ToList();
                grdCourses.DataBind();
            }
        }
Пример #13
0
        protected void GetDepartment()
        {
            using (DefaultConnection db = new DefaultConnection())
            {
                var deps = from d in db.Departments
                           orderby d.Name
                           select d;

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

                ListItem default_item = new ListItem("select", "0");
                ddlDepartment.Items.Insert(0, default_item);

            }
        }
Пример #14
0
        protected void GetStudents()
        {
            //connect to EF
            using (DefaultConnection db = new DefaultConnection())
            {

                //query the students table using EF and LINQ
                var Students = from s in db.Students
                               select s;

                //bind the result to the gridview
                grdStudents.DataSource = Students.ToList();
                grdStudents.DataBind();

            }
        }
Пример #15
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();

            }
        }
Пример #16
0
        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();
            }
        }
Пример #17
0
        protected void GetDepartments()
        {
            using (DefaultConnection db = new DefaultConnection())
            {
                var Departments = from d in db.Departments
                                  orderby d.Name
                                  select d;

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

                //add a default option
                ListItem DefaultItem = new ListItem("Select", "0");
                ddlDepartment.Items.Insert(0, DefaultItem);
            }
        }
        protected void GetDepartments()
        {
            //connect
            using (DefaultConnection db = new DefaultConnection())
            {
                // get the 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 default option the to the dropdown after we fill it
                ListItem DefaultItem = new ListItem("-Select-", "0");
                ddlDepartment.Items.Insert(0, DefaultItem);
            }
        }
Пример #19
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();
            }
        }
Пример #20
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();

                // 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");

            }
        }
Пример #21
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();
            }
        }
Пример #22
0
        protected void grdCourses_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            Int32 StudentID = Convert.ToInt32(grdCourses.DataKeys[e.RowIndex].Values["StudentID"]);

            //use EF to remove the selected student from the db
            using (DefaultConnection db = new DefaultConnection())
            {

                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
            GetStudent();
        }
Пример #23
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            //connect
            using (DefaultConnection db = new DefaultConnection())
            {
                //create new course and fills 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");
            }
        }
Пример #24
0
        protected void GetDepartments()
        {
            //use entity framework to connect and get the list of departments
            using (DefaultConnection db = new DefaultConnection())
            {
                //old query that show all department
                //var deps = from d in db.Departments
                 //          select d;
                //new query filtered for logged in user only
                Int32 DepartmentID = Convert.ToInt32(Session["DepartmentID"]);

                var deps = from d in db.Departments
                           where d.DepartmentID == DepartmentID
                           select d;

                //bind the deps query result to our grid
                grdDepartments.DataSource = deps.ToList();
                grdDepartments.DataBind();
            }
        }
Пример #25
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            //connect db
            using (DefaultConnection db = new DefaultConnection())
            {
                //create a new department in memory
                Student stud = new Student();

                Int32 StudentID = 0;

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

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

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

                //add if we have no id in the url
                if (StudentID == 0)
                {
                    db.Students.Add(stud);
                }

                //save new student
                db.SaveChanges();

                //redirect to student list page
                Response.Redirect("students.aspx");
            }
        }
Пример #26
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            //use EF to connect to SQL Server
            using (DefaultConnection db = new DefaultConnection())
            {

                //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");
            }
        }
Пример #27
0
        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 (DefaultConnection db = new DefaultConnection()) {

                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();
        }
Пример #28
0
        protected void GetStudent()
        {
            //store id from the url in a variable
            Int32 StudentID = Convert.ToInt32(Request.QueryString["StudentID"]);

            //look up selected student and fill the form
            using (DefaultConnection db = new DefaultConnection())
            {

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

                if(stud != null)
                {
                    //pre-populate the form fields
                    txtFirstName.Text = stud.FirstMidName;
                    txtLastName.Text = stud.LastName;
                    txtEnrollDate.Text = stud.EnrollmentDate.ToString("yyyy-mm-dd");
                }

                //populate enrollments
                var enroll = (from e in db.Enrollments
                              join c in db.Courses on e.CourseID equals c.CourseID
                              join d in db.Departments on c.DepartmentID equals d.DepartmentID
                              where e.StudentID == StudentID
                              select new { e.EnrollmentID, e.Grade, c.Title, d.Name });

                grdCourses.DataSource = enroll.ToList();
                grdCourses.DataBind();

                //show course panel
                pnlCourses.Visible = true;
            }
        }