// We create the edit page so that we can edit data, through the Edit Page method we can set the new values the user updates. protected void Edit_Page(object sender, EventArgs e) { PagesDB db = new PagesDB(); bool valid = true; string pageid = Request.QueryString["pageid"]; if (String.IsNullOrEmpty(pageid)) { valid = false; } if (valid) { HTTP_Page new_page = new HTTP_Page(); new_page.SetPagetitle(page_title.Text); new_page.SetPagebody(page_body.Text); new_page.SetPageauthor(page_author.Text); try { db.EditPage(Int32.Parse(pageid), new_page); Response.Redirect("ShowPage.aspx?pageid=" + pageid); } catch { valid = false; } } if (!valid) { page_content.InnerHtml = "There was an error updating that page."; } }
//We also need to show the the page content to be able to update the changes we make. protected void ShowPageContent(PagesDB db) { bool valid = true; string pageid = Request.QueryString["pageid"]; if (String.IsNullOrEmpty(pageid)) { valid = false; } if (valid) { HTTP_Page page_record = db.FindPage(Int32.Parse(pageid)); page_title.Text = page_record.GetPagetitle(); page_body.Text = page_record.GetPagebody(); page_author.Text = page_record.GetPageauthor(); page_date.InnerHtml = page_record.GetTimeStamp().ToString("yyyy-MM-dd"); } else { valid = false; } if (!valid) { page_content.InnerHtml = "There was an error finding that Page."; } }
protected void Page_Load(object sender, EventArgs e) { PagesDB db = new PagesDB(); ShowPageContent(db); // when the page is loading we show the content created by the author }
protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { PagesDB db = new PagesDB(); ShowPageContent(db); } }
protected void ListFeatPages(PagesDB db) { // To get the pages to show on the header and footer as they are created we run a query in the method //with a foreach so that everytime a page is added to the databas it also shows on the header. string query = "select * from pagesmgmt"; List <Dictionary <String, String> > rs = db.List_Query(query); foreach (Dictionary <String, String> row in rs) { list_pages.InnerHtml += "<a id=\"navdes\" href=\"ShowPage.aspx?pageid=" + row["pageid"] + "\" >" + "Page " + row["pageid"] + "</a>"; } }
protected void Page_Load(object sender, EventArgs e) { page_result.InnerHtml = ""; string searchkey = ""; if (Page.IsPostBack) { searchkey = page_search.Text; } // We create the "search method" so that if the user wants to look for a specific page they can, // either trough author name or page title string query = "select * from pagesmgmt"; if (searchkey != "") { query += " WHERE pagetitle like '%" + searchkey + "%' "; query += " or pageauthor like '%" + searchkey + "%' "; } //We create the list query so that the pages where every new page is inserted into the list, // showing the title, author, date published and a way to edit it. var db = new PagesDB(); List <Dictionary <String, String> > rs = db.List_Query(query); foreach (Dictionary <String, String> row in rs) { page_result.InnerHtml += "<div class=\"listitem\">"; string pageid = row["pageid"]; string pagetitle = row["pagetitle"]; page_result.InnerHtml += "<div class=\"col4\"><a href=\"ShowPage.aspx?pageid=" + pageid + "\">" + pagetitle + "</a></div>"; string pageauthor = row["pageauthor"]; page_result.InnerHtml += "<div class=\"col4\">" + pageauthor + "</div>"; string publisheddate = row["timestamp"]; page_result.InnerHtml += "<div class=\"col4\">" + publisheddate + "</div>"; page_result.InnerHtml += "<div class=\"col4last\"><a href=\"EditPage.aspx?pageid=" + pageid + "\">" + "Edit" + "</a>" + "</div>"; page_result.InnerHtml += "</div>"; } }
//We haave to set up a method so that when the user clicks submit, the information goes into the database and into the "Manage Pages" page. //We set up connection to the PagesDB and SET the information into the values. protected void Add_Page(object sender, EventArgs e) { PagesDB db = new PagesDB(); HTTP_Page new_page = new HTTP_Page(); new_page.SetPagetitle(newpage_title.Text); new_page.SetPagebody(newpage_body.Text); new_page.SetPageauthor(newpage_author.Text); new_page.SetTimeStamp(DateTime.Now); db.AddPage(new_page); Response.Redirect("ManagePages.aspx"); }
// The user has to be able to delete the page, we make a method so that it deletes it from the database. protected void Delete_Page(object sender, EventArgs e) { bool valid = true; string pageid = Request.QueryString["pageid"]; if (String.IsNullOrEmpty(pageid)) { valid = false; } PagesDB db = new PagesDB(); if (valid) { db.DeletePage(Int32.Parse(pageid)); Response.Redirect("ManagePages.aspx"); } }
protected void Page_Load(object sender, EventArgs e) { PagesDB db = new PagesDB(); ListFeatPages(db); }