protected void CheckOut() { //get selected room number Int32 RoomID = Convert.ToInt32(Request.QueryString["RoomID"]); using (comp2007Entities db = new comp2007Entities()) { //get selected room Room objC = (from r in db.Rooms where r.RoomID == RoomID select r).FirstOrDefault(); //populate the room objC.Size = objC.Size; objC.CostPerDay = objC.CostPerDay; objC.Availability = objC.Availability; //set room to available if (objC.Availability == "n") { objC.Availability = "y"; if (String.IsNullOrEmpty(Request.QueryString["RoomID"])) { //add db.Rooms.Add(objC); //save and redirect db.SaveChanges(); } } else { //a customer is already checked into this room Response.Redirect("rooms.aspx"); } Booking objD = (from b in db.Bookings where b.RoomID == RoomID select b).FirstOrDefault(); //remove customer's entry from the bookings db db.Bookings.Remove(objD); db.SaveChanges(); //Redirect Response.Redirect("bookings.aspx"); } }
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 (comp2007Entities db = new comp2007Entities()) { try { Student s = (from objS in db.Students where objS.StudentID == StudentID select objS).FirstOrDefault(); //do the delete db.Students.Remove(s); db.SaveChanges(); } catch (Exception) { Response.Redirect("error.aspx"); } } //refresh the grid GetStudents(); }
protected void btnSave_Click(object sender, EventArgs e) { //do insert or update using (comp2007Entities db = new comp2007Entities()) { Room objC = new Room(); if (!String.IsNullOrEmpty(Request.QueryString["RoomID"])) { Int32 RoomID = Convert.ToInt32(Request.QueryString["RoomID"]); objC = (from r in db.Rooms where r.RoomID == RoomID select r).FirstOrDefault(); } //populate the room from the input form objC.Size = ddlRoomSize.Text; objC.CostPerDay = Convert.ToDecimal(txtCostPerDay.Text); objC.Availability = "y"; if (String.IsNullOrEmpty(Request.QueryString["RoomID"])) { //add db.Rooms.Add(objC); } //save and redirect db.SaveChanges(); Response.Redirect("rooms.aspx"); } }
protected void btnSave_Click(object sender, EventArgs e) { //do insert or update using (comp2007Entities db = new comp2007Entities()) { Room objC = new Room(); if (!String.IsNullOrEmpty(Request.QueryString["RoomID"])) { Int32 RoomID = Convert.ToInt32(Request.QueryString["RoomID"]); objC = (from r in db.Rooms where r.RoomID == RoomID select r).FirstOrDefault(); } Booking objD = new Booking(); //populate the booking entry from the input form and room info objD.RoomID = objC.RoomID; objD.LastName = txtLastName.Text; objD.FirstName = txtFirstName.Text; objD.DaysStaying = Convert.ToInt32(txtDaysStaying.Text); objD.BookDate = DateTime.Today; //Decimal TotalCost = objC.CostPerDay * objD.DaysStaying; //add db.Bookings.Add(objD); //save and redirect db.SaveChanges(); Response.Redirect("bookings.aspx"); } }
protected void btnSave_Click(object sender, EventArgs e) { //use EF to connect to SQL server using (comp2007Entities db = new comp2007Entities()) { //use the Student model to save the new record Department d = new Department(); int departmentID = 0; if (Request.QueryString["DepartmentID"] != null) { departmentID = int.Parse(Request.QueryString["DepartmentID"]); d = (from obj in db.Departments where obj.DepartmentID == departmentID select obj).FirstOrDefault(); } d.Name = txtName.Text; d.Budget = decimal.Parse(txtBudget.Text); if (departmentID == 0) { db.Departments.Add(d); } db.SaveChanges(); //redirect to the updated students page Response.Redirect("departments.aspx"); } }
protected void btnSave_Click(object sender, EventArgs e) { //use EF to connect to SQL server using (comp2007Entities db = new comp2007Entities()) { //use the Student model to save the new record Course c = new Course(); int courseID = 0; if (Request.QueryString["CourseID"] != null) { courseID = int.Parse(Request.QueryString["CourseID"]); c = (from obj in db.Courses where obj.CourseID == courseID select obj).FirstOrDefault(); } c.Title = txtTitle.Text; c.Credits = int.Parse(txtCredits.Text); c.DepartmentID = int.Parse(ddlDepartment.SelectedValue); if (courseID == 0) { db.Courses.Add(c); } db.SaveChanges(); //redirect to the updated students page Response.Redirect("courses.aspx"); } }
protected void btnSave_Click(object sender, EventArgs e) { //use EF to connect to SQL server using (comp2007Entities db = new comp2007Entities()) { //use the Student model to save the new record Student s = new Student(); int studentID = 0; if (Request.QueryString["StudentID"] != null) { studentID = int.Parse(Request.QueryString["StudentID"]); s = (from objS in db.Students where objS.StudentID == studentID select objS).FirstOrDefault(); } s.LastName = txtLastName.Text; s.FirstMidName = txtFirstMidName.Text; s.EnrollmentDate = DateTime.Parse(txtEnrollmentDate.Text); if (studentID == 0) { db.Students.Add(s); } db.SaveChanges(); //redirect to the updated students page Response.Redirect("students.aspx"); } }
protected void btnSave_Click(object sender, EventArgs e) { // use EF to connect to SQL using (comp2007Entities db = new comp2007Entities()) { //use the student model to save the new model Category c = new Category(); Int32 CategoryID = 0; //check save? or update?? if (Request.QueryString["CategoryID"] != null) { //get the id from the url CategoryID = Convert.ToInt32(Request.QueryString["CategoryID"]); //get the current student from EF c = (from objS in db.Categories where objS.CategoryID == CategoryID select objS).FirstOrDefault(); } c.CategoryName = txtCtgname.Text; if (ckbIsExpense.Checked) { c.isExpense = true; } else { c.isExpense = false; } if (ckbActivated.Checked) { c.isActive = true; } else { c.isActive = false; } if (CategoryID == 0) { db.Categories.Add(c); } db.SaveChanges(); //redirect to the updated list page Response.Redirect("category.aspx"); } }
protected void grdCourseStudents_RowDeleting(object sender, GridViewDeleteEventArgs e) { int enrollmentID = Convert.ToInt32(grdCourseStudents.DataKeys[e.RowIndex].Values["EnrollmentID"]); using (comp2007Entities db = new comp2007Entities()) { var objE = (from en in db.Enrollments where en.EnrollmentID == enrollmentID select en).FirstOrDefault(); db.Enrollments.Remove(objE); db.SaveChanges(); GetCourse(); } }
protected void btnSave_Click(object sender, EventArgs e) { //use EF to connect to SQL Server using (comp2007Entities db = new comp2007Entities()) { //use the Student model to save the new record Account a = new Account(); Int32 AccountID = 0; //check the querystring for an id so we can determine add / update if (Request.QueryString["AccountID"] != null) { //get the id from the url AccountID = Convert.ToInt32(Request.QueryString["AccountID"]); //get the current student from EF a = (from objS in db.Accounts where objS.AccountID == AccountID select objS).FirstOrDefault(); } a.CategoryID = Convert.ToInt32(ddlCategory.SelectedIndex); a.AccountName = txtAccountName.Text; if (ckbIsActive.Checked) { a.isActive = true; } else { a.isActive = false; } //call add only if we have no student ID if (AccountID == 0) { db.Accounts.Add(a); } //run the update or insert db.SaveChanges(); //redirect to the updated students page Response.Redirect("account.aspx"); } }
protected void CheckIn() { //populate the existing room for editing using (comp2007Entities db = new comp2007Entities()) { Room objC = new Room(); if (!String.IsNullOrEmpty(Request.QueryString["RoomID"])) { Int32 RoomID = Convert.ToInt32(Request.QueryString["RoomID"]); objC = (from r in db.Rooms where r.RoomID == RoomID select r).FirstOrDefault(); } //populate the room from the input form objC.Size = objC.Size; objC.CostPerDay = objC.CostPerDay; objC.Availability = objC.Availability; //set availability to no if (objC.Availability == "y") { objC.Availability = "n"; if (String.IsNullOrEmpty(Request.QueryString["RoomID"])) { //add db.Rooms.Add(objC); } //save db.SaveChanges(); } //room not currently available else { //redirect Response.Redirect("rooms.aspx"); } } }
protected void grdRooms_RowDeleting(object sender, GridViewDeleteEventArgs e) { //get selected room number Int32 RoomID = Convert.ToInt32(grdRooms.DataKeys[e.RowIndex].Values["RoomID"]); using (comp2007Entities db = new comp2007Entities()) { //get selected room Room objC = (from r in db.Rooms where r.RoomID == RoomID select r).FirstOrDefault(); //delete db.Rooms.Remove(objC); db.SaveChanges(); //refresh grid GetRooms(); } }
protected void grdCourses_RowDeleting(object sender, GridViewDeleteEventArgs e) { //get selected record id Int32 EnrollmentID = Convert.ToInt32(grdCourses.DataKeys[e.RowIndex].Values["EnrollmentID"]); using (comp2007Entities db = new comp2007Entities()) { //get selected record Enrollment objE = (from en in db.Enrollments where en.EnrollmentID == EnrollmentID select en).FirstOrDefault(); //delete db.Enrollments.Remove(objE); db.SaveChanges(); //refresh the data on the page GetStudent(); } }
protected void grdCourses_RowDeleting(object sender, GridViewDeleteEventArgs e) { //get selected course ID Int32 CourseID = Convert.ToInt32(grdCourses.DataKeys[e.RowIndex].Values["CourseID"]); using (comp2007Entities db = new comp2007Entities()) { //get selected course Course objC = (from c in db.Courses where c.CourseID == CourseID select c).FirstOrDefault(); //delete db.Courses.Remove(objC); db.SaveChanges(); //refresh grid GetCourses(); } }
protected void btnSave_Click(object sender, EventArgs e) { //use EF to connect to SQL Server using (comp2007Entities db = new comp2007Entities()) { //use the Student model to save the new record Course c = new Course(); Int32 CourseID = 0; //check the querystring for an id so we can determine add / update if (Request.QueryString["CourseID"] != null) { //get the id from the url CourseID = Convert.ToInt32(Request.QueryString["CourseID"]); //get the current student from EF c = (from objS in db.Courses where objS.CourseID == CourseID select objS).FirstOrDefault(); } c.DepartmentID = Convert.ToInt32(ddlDepartment.SelectedIndex); c.Title = txtCourseTitle.Text; c.Credits = Convert.ToInt32(txtCredits.Text); //call add only if we have no student ID if (CourseID == 0) { db.Courses.Add(c); } //run the update or insert db.SaveChanges(); //redirect to the updated students page Response.Redirect("courses.aspx"); } }
protected void btnSave_Click(object sender, EventArgs e) { //use EF to connect to SQL Server using (comp2007Entities db = new comp2007Entities()) { //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"); } }
protected void grdDepartmentCourses_RowDeleting(object sender, GridViewDeleteEventArgs e) { int courseID = Convert.ToInt32(grdDepartmentCourses.DataKeys[e.RowIndex].Values["CourseID"]); using (comp2007Entities db = new comp2007Entities()) { var objE = (from en in db.Enrollments where en.CourseID == courseID select en); db.Enrollments.RemoveRange(objE); var objC = (from c in db.Courses where c.CourseID == courseID select c).FirstOrDefault(); db.Courses.Remove(objC); db.SaveChanges(); GetDepartment(); } }
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 (comp2007Entities db = new comp2007Entities()) { 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(); }
protected void grdCourses_RowDeleting(object sender, GridViewDeleteEventArgs e) { int selectedRow = e.RowIndex; int courseID = (int)grdCourses.DataKeys[selectedRow].Values["CourseID"]; using (comp2007Entities db = new comp2007Entities()) { Course c = (from obj in db.Courses where obj.CourseID == courseID select obj).FirstOrDefault(); db.Courses.Remove(c); db.SaveChanges(); GetCourses(); } }
protected void grdDepartments_RowDeleting(object sender, GridViewDeleteEventArgs e) { //store which row was clicked Int32 selectedRow = e.RowIndex; //get the selected departmentID using the grid's data key collection Int32 departmentID = Convert.ToInt32(grdDepartments.DataKeys[selectedRow].Values["DepartmentID"]); //use EF to remove the selected student from the db using (comp2007Entities db = new comp2007Entities()) { Department d = (from objS in db.Departments where objS.DepartmentID == departmentID select objS).FirstOrDefault(); // do the deletion db.Departments.Remove(d); db.SaveChanges(); } //refresh the grid getDepartments(); }
protected void grdStudents_RowDeleting(object sender, GridViewDeleteEventArgs e) { Int32 EnrollmentID = Convert.ToInt32(grdStudents.DataKeys[e.RowIndex].Values["EnrollmentID"]); using (comp2007Entities db = new comp2007Entities()) { Enrollment en = (from objS in db.Enrollments where objS.EnrollmentID == EnrollmentID select objS).FirstOrDefault(); //do the delete db.Enrollments.Remove(en); db.SaveChanges(); GetCourses(); } }
protected void grdCourses_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 CourseID = Convert.ToInt32(grdCourses.DataKeys[selectedRow].Values["CourseID"]); //use EF to remove the selected student from the db using (comp2007Entities db = new comp2007Entities()) { Course c = (from objS in db.Courses where objS.CourseID == CourseID select objS).FirstOrDefault(); //do the delete db.Courses.Remove(c); db.SaveChanges(); } //refresh the grid GetCourses(); }
protected void grdDepartments_RowDeleting(object sender, GridViewDeleteEventArgs e) { int selectedRow = e.RowIndex; int departmentID = (int)grdDepartments.DataKeys[selectedRow].Values["DepartmentID"]; using (comp2007Entities db = new comp2007Entities()) { Department d = (from obj in db.Departments where obj.DepartmentID == departmentID select obj).FirstOrDefault(); db.Departments.Remove(d); db.SaveChanges(); GetDepartments(); } }
protected void grdStudents_RowDeleting(object sender, GridViewDeleteEventArgs e) { int selectedRow = e.RowIndex; int studentID = (int)grdStudents.DataKeys[selectedRow].Values["StudentID"]; using (comp2007Entities db = new comp2007Entities()) { Student s = (from objS in db.Students where objS.StudentID == studentID select objS).FirstOrDefault(); db.Students.Remove(s); db.SaveChanges(); GetStudents(); } }