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");
            }
        }
예제 #2
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())
            {
                //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");
            }
        }
예제 #4
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");

            }
        }
        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"]);

                }

            }
        }
예제 #6
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");

            }
        }
예제 #7
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 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");

            }
        }
예제 #10
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();
            }
        }
        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();
            }
        }
        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 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");

            }
        }
예제 #14
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");

            }
        }
예제 #15
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");

            }
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            //connecting to the database.
            using (DefaultConnection db = new DefaultConnection())
            {
                //create a new student in the memory.
                Student stu = new Student();

                Int32 StudentID = 0;

                //Check for a URL
                if (!String.IsNullOrEmpty(Request.QueryString["StudentID"]))
                {
                    //Get the ID from the URL.
                    StudentID = Convert.ToInt32(Request.QueryString["StudentID"]);

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

                //fill the properties of the new student.
                stu.LastName = txtLastName.Text;
                stu.FirstMidName = txtFirstMidName.Text;

                //Add if there is no ID in the URL.
                if (StudentID == 0)
                {
                    db.Students.Add(stu);
                }

                //Save the new student.
                db.SaveChanges();

                //Redirect the user to the Students list page.
                Response.Redirect("students.aspx");

            }
        }