protected void Page_Load(object sender, EventArgs e) { catID = Int32.Parse(Request.QueryString["catID"]); displayPosts(DBconnection.getForumPosts(catID)); //HtmlGenericControl forumLink = new HtmlGenericControl("a"); //forumLink.Attributes.Add("href", "ForumCategories.aspx"); //forumLink.InnerText = "Forum > "; //forumPath.Controls.Add(forumLink); //HtmlGenericControl catLink = new HtmlGenericControl("a"); //forumLink.InnerText = Request.QueryString["catTitle"]; //forumPath.Controls.Add(forumLink); }
protected void btn_login_Click(object sender, EventArgs e) { string loginEmail = txt_email.Text; string loginPassword = txt_password.Text; string confirmPassword = DBconnection.getPassword(loginEmail); if (loginPassword.Equals(confirmPassword)) { Session["loginData"] = DBconnection.getUser(loginEmail); Response.Write("<script>alert('You are logged in')</script>"); Response.Redirect(Request.Url.ToString()); } else { Response.Write("<script>alert('Details do not match.')</script>"); } }
protected void btn_add_Click(object sender, EventArgs e) { //create a new Forum objet, then pass it as a parameter in order to add post title to the database Forum post = new Forum(catID, TextBox1.Text, DateTime.Now, user.Id); DBconnection.addForumNewPost(post); post.Text = TextBox2.Text; post.PostID = DBconnection.lastPK("ID", "ForumPosts"); //add the message assosiated with this post DBconnection.addForumMessage(post); HttpContext.Current.Response.Write("<script>alert('Your post has been added')</script>"); //redirect the user to his message Response.Redirect("ForumMessages.aspx?catID=" + post.CategoryID + "&postID=" + post.PostID); }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { //populate ddl_repeatForWks for (int i = 0; i <= 20; i++) { ddl_repeatWks.Items.Add(i.ToString()); } //populate ddl_timeH int h = 00; for (int i = 0; i < 24; i++) { ddl_timeH.Items.Add(h.ToString("D2")); h++; } //populate ddl_timeM int m = 00; for (int i = 0; i <= 59; i++) { ddl_timeM.Items.Add(m.ToString("D2")); m++; } //populate ddl_capacity for (int i = 6; i <= 20; i++) { ddl_capacity.Items.Add(i.ToString()); } //populate duration [session] for (int i = 60; i <= 90; i = i + 10) { ddl_duration.Items.Add(i.ToString()); } } //get list of instructors to be displayed in ddl_instructors instructors = DBconnection.getInstructorsList(); }
protected void Page_Load(object sender, EventArgs e) { if (Session["loginData"] != null) { userData = (User)Session["loginData"]; } else { Response.Redirect("Default.aspx"); } reservationsList = DBconnection.getClassReservations(userData.Id, "Class"); displayReservations(reservationsList); reservationsList = DBconnection.getClassReservations(userData.Id, "Workshop"); displayReservations(reservationsList); displayWaitingLists(DBconnection.viewUserQueues(userData.Id)); }
protected void btn_deleteRecord_Click(object sender, EventArgs e) { //check if a session has been selected before proceeding if (Session["selectedRow"] == null) { HttpContext.Current.Response.Write("<script>alert('Please select a session to be deleted first!')</script>"); } else { //delete a record from a database based on the session type (class, workshop") and sessionID DBconnection.deleteRecord(DropDownList1.SelectedValue, Int32.Parse(Session["selectedRow"].ToString()), "ID"); //remove all queues assosiated with this session DBconnection.removeQueue(Int32.Parse(Session["selectedRow"].ToString()), "SessionID"); //delete all reservations assosiated with this session DBconnection.deleteRecord("Reservation", Int32.Parse(Session["selectedRow"].ToString()), DropDownList1.SelectedValue + "ID"); GridView1.SelectedIndex = -1; //clear grid view selection Session["selectedRow"] = null; // clear selectedRow session's data refreshTable(); HttpContext.Current.Response.Write("<script>alert('Session has been deleted.')</script>"); //show javascript confirmation window } }
private void displayCategories(List <Forum> c) { for (int i = 0; i < c.Count; i++) { HtmlTableRow tr = new HtmlTableRow(); HtmlTableCell td_IMG = new HtmlTableCell(); HtmlGenericControl img = new HtmlGenericControl("img"); img.Attributes.Add("src", "images/forumCategories.png"); td_IMG.Controls.Add(img); HtmlTableCell td_title = new HtmlTableCell(); HtmlGenericControl a = new HtmlGenericControl("a"); a.Attributes.Add("href", "ForumPosts.aspx?catID=" + c[i].CategoryID + "&catTitle=" + c[i].Title); a.InnerHtml = c[i].Title + " <br />"; td_title.Controls.Add(a); HtmlGenericControl span = new HtmlGenericControl("span"); span.Attributes.Add("class", "desc"); span.InnerText = c[i].Text; td_title.Controls.Add(span); HtmlTableCell td_posts = new HtmlTableCell(); td_posts.InnerHtml = DBconnection.getNumberOfRecords("ForumPosts", "CategoryID_FK", c[i].CategoryID) + " Posts"; HtmlTableCell td_Messages = new HtmlTableCell(); td_Messages.InnerHtml = DBconnection.getNumberOfRecords("CategoryID_FK", c[i].CategoryID) + " Messages"; tr.Controls.Add(td_IMG); tr.Controls.Add(td_title); tr.Controls.Add(td_posts); tr.Controls.Add(td_Messages); ForumCategoriesTable.Controls.Add(tr); } }
//change session's status protected void btn_status_Click(object sender, EventArgs e) { //check if a session has been selected before proceeding if (Session["selectedRow"] == null) { HttpContext.Current.Response.Write("<script>alert('Please select a session to be modyfied first!')</script>"); //error message } else { //get the current status of a selected session from the database string currentStatus = DBconnection.getStatus(Session["selectedRow"].ToString(), DropDownList1.SelectedValue); string updatedStatus = "something went wrong"; //set status to the opposite [Active = Cancelled/Cancelled = Active] if (currentStatus.Equals("Active")) { updatedStatus = "Cancelled"; } else if (currentStatus.Equals("Cancelled")) { updatedStatus = "Active"; } else { return; } //update status in the database DBconnection.changeStatus(DropDownList1.SelectedValue, updatedStatus, Session["selectedRow"].ToString()); //clear gridview selection and reset data GridView1.SelectedIndex = -1; Session["selectedRow"] = null; refreshTable(); HttpContext.Current.Response.Write("<script>alert('Session has been set to " + updatedStatus + ".')</script>"); //conrimation message } }
private void displaySessions(List <Class> s) { Random random = new Random(); //if there are no classes in the database show error message if (s.Count == 0) { //create a generic html control (paragraph <p>) HtmlGenericControl error = new HtmlGenericControl("p"); //insert the content of a paragraph (<p>CONTENT</p>) error.InnerHtml = "<h2>Unfortunately, we do not have any sessions on selected day"; //add the html control to a div container with an ID of "extraThing" :) extraThing.Controls.Add(error); } else { for (int i = 0; i < s.Count; i++) { //create a HTML table row using HTML controlls and add it to //the table with ID of "sessionTable" HtmlTableRow tr = new HtmlTableRow(); sessionsTable.Controls.Add(tr); //create a table cell/column HtmlTableCell td1 = new HtmlTableCell(); //add this table cell to a table row tr.Controls.Add(td1); //create a generic <img> html tag HtmlGenericControl img = new HtmlGenericControl("img"); //give src attribute to the img tag and assign a path to it //this path contains a random number that randomly chooses image for each session img.Attributes.Add("src", "images/" + random.Next(1, 6) + ".jpg"); //add image to the table cell td1.Controls.Add(img); //tile & description column HtmlTableCell td2 = new HtmlTableCell(); tr.Controls.Add(td2); HtmlGenericControl title = new HtmlGenericControl("a"); title.InnerHtml = "<h2>" + s[i].Title + "</h2>"; //pass the session type and session ID to querry string //querry string with these information will be used on ReservationPage.aspx page title.Attributes.Add("href", "ReservationPage.aspx?id=" + s[i].Id + "&type2=Class"); td2.Controls.Add(title); HtmlGenericControl description = new HtmlGenericControl("p"); description.InnerText = s[i].Description; td2.Controls.Add(description); //Additional information column HtmlTableCell td3 = new HtmlTableCell(); tr.Controls.Add(td3); //create a html unordered list and populate it with list elements HtmlGenericControl ul = new HtmlGenericControl("ul"); td3.Controls.Add(ul); HtmlGenericControl li1 = new HtmlGenericControl("li"); //date and time ul.Controls.Add(li1); li1.InnerText = s[i].StartDate.ToShortDateString() + " at " + s[i].Time.ToString(@"hh\:mm"); HtmlGenericControl li2 = new HtmlGenericControl("li"); //level ul.Controls.Add(li2); li2.InnerText = s[i].Level; HtmlGenericControl li3 = new HtmlGenericControl("li"); //duration ul.Controls.Add(li3); li3.InnerText = "Duration: " + s[i].Duration.ToString() + " min"; HtmlGenericControl li4 = new HtmlGenericControl("li"); //available spaces ul.Controls.Add(li4); li4.InnerText = "Available: " + (s[i].Capacity - s[i].Reservations).ToString(); HtmlGenericControl li5 = new HtmlGenericControl("li"); //sessions status ul.Controls.Add(li5); li5.InnerText = s[i].Status; HtmlGenericControl li6 = new HtmlGenericControl("li"); ul.Controls.Add(li6); li6.InnerText = "With " + DBconnection.getUser(s[i].InstructorID).Name; //book column //contains a link to ReservationPage with parameters for querry string HtmlTableCell book = new HtmlTableCell(); tr.Controls.Add(book); HtmlGenericControl link = new HtmlGenericControl("a"); if (s[i].Status.Equals("Cancelled")) { book.Controls.Add(link); link.Attributes.Add("class", "bookLink"); link.Attributes.Add("href", "#"); link.InnerText = "Session cancelled"; } else { book.Controls.Add(link); link.Attributes.Add("class", "bookLink"); link.Attributes.Add("href", "ReservationPage.aspx?id=" + s[i].Id + "&type2=Class"); link.InnerText = "Book"; } } } }
protected void addSession(object sender, EventArgs e) { string type = ddl_type.SelectedValue; string title = txt_title.Text; string description = txt_description.Text; string style = ddl_style.SelectedValue; string level = rdb_level.SelectedValue; int capacity = Int32.Parse(ddl_capacity.SelectedValue); string room = txt_room.Text; DateTime date = myCalendar.SelectedDate; int repeatWks = Int32.Parse(ddl_repeatWks.SelectedValue); TimeSpan time = new TimeSpan(Int32.Parse(ddl_timeH.SelectedValue), Int32.Parse(ddl_timeM.SelectedValue), 00); int duration = Int32.Parse(ddl_duration.SelectedValue); int count = 0; int instructorID = 0; //Check if the choosen date is in the future int oldDateCheck = DateTime.Compare(date.Date.Add(time), DateTime.Now); if (oldDateCheck <= 0) { Response.Write("<script>alert('Choose a date in the future.')</script>"); } else { try { //find the instructor's ID number by looping through instructors name's. // while (!ddl_instructor.SelectedValue.Equals(instructors[count].Name)) { count++; } instructorID = instructors[count].Id; } catch (ArgumentOutOfRangeException ex) { lb_exceptionCatch.Text = "You need to choose default value for all drop down lists."; } if (ddl_type.SelectedValue.Equals("Class")) { Class session = new Class(date, time, style, level, instructorID, duration, capacity, title, description, room, 0, repeatWks); session.schedulesClass(); DBconnection.addClass(session); } else { Workshop session = new Workshop(date, time, style, level, instructorID, duration, capacity, title, description, room, 0); DBconnection.addWorkshop(session); } clearControls(); Response.Write("<script>alert('Your session has been added to the database.')</script>"); } }//end of add session
protected void Page_Load(object sender, EventArgs e) { postID = Int32.Parse(Request.QueryString["postID"]); catID = Int32.Parse(Request.QueryString["catID"]); displayMessages(DBconnection.getForumMessages(postID)); }
protected void btn_deleteCategory_Click(object sender, EventArgs e) { DBconnection.deleteForumCategory(Int32.Parse(ListBox1.SelectedValue)); refreshCategoriesList(); Response.Redirect(Request.RawUrl); }
protected void btn_addCategory_Click(object sender, EventArgs e) { DBconnection.addForumCategory(txt_categoryTitle.Text, txt_description.Text); Response.Redirect(Request.RawUrl); }