protected void btnEdit_Click(object sender, EventArgs e) { EditMode = !EditMode; tbCourseCode.Visible = !tbCourseCode.Visible; calDate.Visible = !calDate.Visible; tbInstructor.Visible = !tbInstructor.Visible; tbLength.ReadOnly = !tbLength.ReadOnly; tbRoomName.Visible = !tbRoomName.Visible; btnDelete.Enabled = !btnDelete.Enabled; ddlCourseCode.Visible=!ddlCourseCode.Visible; ddlInstructor.Visible = !ddlInstructor.Visible; ddlRoomName.Visible = !ddlRoomName.Visible; //ddlSessions.Visible = !ddlSessions.Visible; if (EditMode) { btnEdit.Text = "Update"; ddlCourseCode.SelectedValue = session.CourseID.ToString(); ddlInstructor.SelectedValue = session.InstructorID.ToString(); ddlRoomName.SelectedValue = session.RoomID.ToString(); } else { btnEdit.Text = "Edit"; Classes.Session newSession = new Classes.Session(); newSession.CourseID = int.Parse(ddlCourseCode.SelectedValue); newSession.SessionDateTime = calDate.SelectedDate; newSession.InstructorID = int.Parse(ddlCourseCode.SelectedValue); newSession.SessionLength = int.Parse(tbLength.Text); newSession.RoomID = int.Parse(ddlRoomName.SelectedValue); newSession.SessionID = session.SessionID; Classes.Session.UpdateSession(newSession, session); Response.Redirect("~/Sessions.aspx?SessionID=" + session.SessionID); } }
protected void Page_Load(object sender, EventArgs e) { EditMode = false; ddlSessions.SelectedValue = Request.Params.Get("SessionID"); session = Classes.Session.GetSession(int.Parse(Request.Params.Get("SessionID"))).ElementAt(0); tbCourseCode.Text = Course.GetCourse(session.CourseID).ElementAt(0).CourseCode; tbInstructor.Text = Instructor.GetInstructor(session.InstructorID).ElementAt(0).InstructorFullName; tbRoomName.Text = Room.GetRoom(session.RoomID).ElementAt(0).RoomName; tbLength.Text = session.SessionLength.ToString(); tbDate.Text = session.SessionDateTime.ToShortDateString(); calDate.SelectedDate = session.SessionDateTime; }
protected void btnNewSession_Click(object sender, EventArgs e) { if(calNewSessionDate.SelectedDate != null && int.Parse(ddlNewSessionRooms.SelectedValue) > 0 && int.Parse(ddlNewSessionInstructors.SelectedValue) > 0 && int.Parse(tbNewSessionLength.Text) > 0) { Classes.Session newSession = new Session(); newSession.course = Course.GetCourse(int.Parse(ddlCourses.SelectedValue)).ElementAt(0); newSession.SessionDateTime = calNewSessionDate.SelectedDate; newSession.instructor = Instructor.GetInstructor(int.Parse(ddlNewSessionInstructors.SelectedValue)).ElementAt(0); newSession.SessionLength = int.Parse(tbNewSessionLength.Text); newSession.room = Room.GetRoom(int.Parse(ddlNewSessionRooms.SelectedValue)).ElementAt(0); Classes.Session.AddSession(newSession); Response.Redirect("Courses.aspx?CourseID="+ddlCourses.SelectedValue); } }
private static void AddParameters(Session session, SqlCommand comm) { comm.Parameters.AddWithValue("InstructorID", session.InstructorID); comm.Parameters.AddWithValue("CourseID", session.CourseID); comm.Parameters.AddWithValue("RoomID", session.RoomID); comm.Parameters.AddWithValue("DateTime", session.SessionDateTime); comm.Parameters.AddWithValue("Length", session.SessionLength); }
public static int UpdateSession(Session session, Session oldSession) { int rowsAffected = 0; // Setup Connection using (DatabaseConnection db = new DatabaseConnection("dbo.UpdateSession")) { // Set Parameters AddParameters(session, db.comm); AddOldParameters(oldSession, db.comm); // Open Connection db.conn.Open(); // Execute Command and Read Response rowsAffected = db.comm.ExecuteNonQuery(); } return rowsAffected; }
public static Session ReadSession(SqlDataReader reader) { Session session = new Session(); session.SessionID = (int)reader["SessionID"]; session.SessionDateTime = (DateTime)reader["SessionDateTime"]; session.SessionLength = (int)reader["SessionLength"]; session.SessionEnrolled = (int)reader["SessionEnrolled"]; session.SessionAvailableSeats = (int)reader["SessionAvailableSeats"]; session.course = Course.ReadCourse(reader); session.instructor = Instructor.ReadInstructor(reader); session.room = Room.ReadRoom(reader); return session; }
public static int AddSession(Session session) { int sessionID = -1; // Setup Connection using (DatabaseConnection db = new DatabaseConnection("dbo.AddSession")) { // Set Parameters AddParameters(session, db.comm); // Open Connection db.conn.Open(); // Execute Command and Read Response sessionID = Convert.ToInt32(db.comm.ExecuteScalar()); } return sessionID; }
public ClientSession() { client = new Client(); session = new Session(); status = new Status(); }