protected void ShowPageInfo(Pagedb db) { bool valid = true; string pageid = Request.QueryString["pageid"]; if (String.IsNullOrEmpty(pageid)) { valid = false; } show_pagetitle.InnerHtml = ""; show_pagebody.InnerHtml = ""; //We will attempt to get the record we need if (valid) { HTTP_Page page_record = db.FindPage(Int32.Parse(pageid)); show_pagetitle.InnerHtml = page_record.GetPagetitle(); show_pagebody.InnerHtml = page_record.GetPagebody(); edit_page.InnerHtml = "<div><a href =\"EditPage.aspx?pageid=" + pageid + "\">Edit</a></div>"; } else { valid = false; } if (!valid) { error_summary.InnerHtml = "There was an error finding that article."; } }
//Show the information of the article that needs editting protected void ShowPageInfo(Pagedb db) { bool valid = true; string pageid = Request.QueryString["pageid"]; if (String.IsNullOrEmpty(pageid)) { valid = false; } show_pagetitle.InnerHtml = ""; show_pagebody.InnerHtml = ""; if (valid) { HTTP_Page page_record = db.FindPage(Int32.Parse(pageid)); show_pagetitle.InnerHtml = page_record.GetPagetitle(); show_pagebody.InnerHtml = page_record.GetPagebody(); } else { valid = false; } //Problem //1. Edit page did not work //Reason: the query in Pagedb.cs is wrong //Solution/status: fixed //2. The pagebody did not update //Reason: Because of the "'" apostrope that make the wrong query //Solution/status + Future reference: Look into SQL parameterized query C# ASP.NET }
protected void ShowAuthorInfo(Pagedb db) { bool valid = true; string authorid = Request.QueryString["authorid"]; if (String.IsNullOrEmpty(authorid)) { valid = false; } show_authorfname.InnerHtml = ""; show_authorlname.InnerHtml = ""; if (valid) { Authors author_record = db.FindAuthor(Int32.Parse(authorid)); show_authorfname.InnerHtml = author_record.GetAuthorfname(); show_authorlname.InnerHtml = author_record.GetAuthorlname(); show_authorfullname.InnerHtml = show_authorfname.InnerHtml + " " + show_authorlname.InnerHtml; } else { valid = false; } }
protected void Update_Page(object sender, EventArgs e) { Pagedb db = new Pagedb(); bool valid = true; string pageid = Request.QueryString["pageid"]; if (String.IsNullOrEmpty(pageid)) { valid = false; } if (valid) { HTTP_Page new_page = new HTTP_Page(); //update the page new_page.SetPagetitle(edit_pagetitle.Text); new_page.SetPagebody(edit_pagebody.Text); //adding to the database try { db.Update_Page(Int32.Parse(pageid), new_page); Response.Redirect("~/ShowPage.aspx?pageid=" + pageid); } catch { valid = false; } } if (!valid) { editpage.InnerHtml = "There was an error updating that article."; } }
protected void Page_Load(object sender, EventArgs e) { Pagedb db = new Pagedb(); ShowAuthorInfo(db); ShowAuthorArticle(db); }
protected void Update_Author(object sender, EventArgs e) { Pagedb db = new Pagedb(); bool valid = true; string authorid = Request.QueryString["authorid"]; if (String.IsNullOrEmpty(authorid)) { valid = false; } if (valid) { Authors new_author = new Authors(); //update author new_author.SetAuthorfname(edit_authorfname.Text); new_author.SetAuthorlname(edit_authorlname.Text); //adding to the database try { db.Update_Author(Int32.Parse(authorid), new_author); Response.Redirect("~/ShowAuthor.aspx?authorid=" + authorid); } catch { valid = false; } } if (!valid) { editauthor.InnerHtml = "There was an error updating that author."; } }
protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { Pagedb db = new Pagedb(); ShowPageInfo(db); } }
protected void Page_Load(object sender, EventArgs e) { pages_result.InnerHtml = ""; quick_nav.InnerHtml = ""; string searchkey = ""; if (Page.IsPostBack) { searchkey = page_search.Text; } string query = "select pages.*, concat(authorfname, ' ', authorlname) as 'author full name' from pages left join authors on authors.authorid = pages.authorid"; if (searchkey != "") { query += " WHERE pagetitle like '%" + searchkey + "%' "; query += " or pagebody like '%" + searchkey + "%' "; query += " or authorfname like '%" + searchkey + "%' "; query += " or authorlname like '%" + searchkey + "%' "; //query += " or pagedate like '" + searchkey + "' "; } //sql_debugger.InnerHtml = query; var db = new Pagedb(); List <Dictionary <String, String> > rs = db.List_Query(query); foreach (Dictionary <String, String> row in rs) { pages_result.InnerHtml += "<div class=\"list item\">"; string pageid = row["pageid"]; string authorid = row["authorid"]; string authorname = row["author full name"]; string ListofArticles = "<a href =\"ShowPage.aspx?pageid=" + pageid + "\">" + row["pagetitle"] + "</a>" + "<div>" + row["pagebody"] + "</div>" + "<div>" + "Written by: " + "<a href =\"ShowAuthor.aspx?authorid=" + authorid + "\">" + authorname + "</a></div>" + "<a href =\"EditPage.aspx?pageid=" + pageid + "\">Edit</a>"; pages_result.InnerHtml += "<div class=\"col2\">" + ListofArticles + "</div>"; string QuickNavigation = "<a href =\"ShowPage.aspx?pageid=" + pageid + "\">" + row["pagetitle"] + "</a>"; quick_nav.InnerHtml += "<div>" + QuickNavigation + "</div>"; } if (pages_result.InnerHtml == "") { pages_result.InnerHtml += "<div class=\"col2\">" + "There is no article matches the search criteria" + "</div>"; } //Problem: //Can not display pagedate //Reason: the pagedate format is not right. //Status: unsolved, temporary solution: delete the date //Future development: //reset the name pages to articles to match the context. I tried reseting but it made the whole project collapsed so I just go with it. //the quick navigation should stay the same and will not be modified by the query. }
protected void ShowAuthorArticle(Pagedb db) { string authorid = Request.QueryString["authorid"]; string query = "select pages.* from pages inner join authors on pages.authorid = authors.authorid where authors.authorid=" + authorid; List <Dictionary <String, String> > rs = db.List_Query(query); foreach (Dictionary <String, String> row in rs) { string pagetitle = row["pagetitle"]; string pagebody = row["pagebody"]; show_author_article.InnerHtml += "<div id=\"MainContent_show_pagetitle\">" + pagetitle + "</div><div id=\"MainContent_show_pagebody\">" + pagebody + "</div>"; } }
protected void Delete_Page(object sender, EventArgs e) { bool valid = true; string pageid = Request.QueryString["pageid"]; if (String.IsNullOrEmpty(pageid)) { valid = false; } Pagedb db = new Pagedb(); //deleting the page from the database if (valid) { db.Delete_Page(Int32.Parse(pageid)); Response.Redirect("List_Pages.aspx"); } }
protected void Page_Load(object sender, EventArgs e) { authors_result.InnerHtml = ""; string searchkey = ""; if (Page.IsPostBack) { searchkey = author_search.Text; } string query = "select authors.* from authors"; if (searchkey != "") { query += " WHERE authorfname like '%" + searchkey + "%' "; query += " or authorlname like '%" + searchkey + "%' "; } sql_debugger.InnerHtml = query; var db = new Pagedb(); List <Dictionary <String, String> > rs = db.List_Query(query); foreach (Dictionary <String, String> row in rs) { authors_result.InnerHtml += "<div class=\"list item\">"; string authorid = row["authorid"]; string authorfname = row["authorfname"]; authors_result.InnerHtml += "<div class=\"col3\"><a href=\"ShowAuthor.aspx?authorid=" + authorid + "\">" + authorfname + "</a></div>"; string authorlname = row["authorlname"]; authors_result.InnerHtml += "<div class=\"col3\">" + authorlname + "</div>"; authors_result.InnerHtml += "<div class=\"col3last\">" + /*"<a href =\"EditAuthor.aspx?studentid=" + authorid + "\">" + "Edit" + "</a>" + " " + " " + " " + "<a href =\"DeleteAuthor.aspx?studentid=" + authorid + "\">" + "Delete" + "</a>" + " " + " " + " " +*/ "<a href=\"ShowAuthor.aspx?authorid=" + authorid + "\">" + "View" + "</a></div>"; } if (authors_result.InnerHtml == "") { authors_result.InnerHtml += "<div class=\"col2\">" + "There is no authors matches the search criteria" + "</div>"; } }
protected void Add_Page(object sender, EventArgs e) { //create connection Pagedb db = new Pagedb(); //create a new particular page HTTP_Page new_page = new HTTP_Page(); //detail about the page new_page.SetPagetitle(add_pagetitle.Text); new_page.SetPagebody(add_pagebody.Text); new_page.SetAuthorid(Int32.Parse(add_authorid.Text)); //add the page to the database db.Add_Page(new_page); Response.Redirect("List_Pages.aspx"); //Problem: When adding authorid in, the new page can not be added to the database, there is sth wrong in the List-Query method //Reason: 1. the authorid is added to the insert statement (solved) 2. the authorid is not convert from string into int //Status: solved }
protected void Page_Load(object sender, EventArgs e) { Pagedb db = new Pagedb(); ShowPageInfo(db); }