protected void ShowBlogPostInfo(BLOGDB db) { bool valid = true; string blogid = Request.QueryString["blogid"]; if (String.IsNullOrEmpty(blogid)) { valid = false; } if (valid) { BLOGPOST blogpost_record = db.FindBlogPost(Int32.Parse(blogid)); blogpost_title_head.InnerHtml = blogpost_record.GetBPTitle(); blogpost_title.InnerHtml = blogpost_record.GetBPTitle(); blogpost_body.InnerHtml = blogpost_record.GetBPBody(); } else { valid = false; } if (!valid) { blog.InnerHtml = "There was an error finding that blog post"; } }
protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { BLOGDB db = new BLOGDB(); ShowBlogInfo(db); } }
protected void ListBlogPostMenu(BLOGDB db) { string query = "select * from blog_post"; List <Dictionary <String, String> > rs = db.List_Query(query); foreach (Dictionary <String, String> row in rs) { string blogid = row["blogid"]; string blogtitle = row["blogtitle"]; bloglist_result.InnerHtml += "<a href=\"ShowBlogPost.aspx?blogid=" + blogid + "\">" + blogtitle + "</a>"; } }
protected void AddPost(object sender, EventArgs e) { BLOGDB db = new BLOGDB(); BLOGPOST new_post = new BLOGPOST(); new_post.SetBPTitle(blog_title.Text); new_post.SetBPBody(blog_body.Text); db.AddBlogPost(new_post); Response.Redirect("ListBlogPost.aspx"); }
protected void Delete_BlogPost(object sender, EventArgs e) { bool valid = true; string blogid = Request.QueryString["blogid"]; if (String.IsNullOrEmpty(blogid)) { valid = false; } BLOGDB db = new BLOGDB(); if (valid) { db.DeleteBlogPost(Int32.Parse(blogid)); Response.Redirect("ListBlogPost.aspx"); } }
protected void Page_Load(object sender, EventArgs e) { bloglist_result.InnerHtml = ""; string query = "select * from blog_post order by blogid desc"; var db = new BLOGDB(); List <Dictionary <String, String> > rs = db.List_Query(query); /*foreach (Dictionary<String, String> row in rs) * { * bloglist_result.InnerHtml += "<div class=\"listitem\">"; * * * string blogid = row["blogid"]; * * string blogtitle = row["blogtitle"]; * bloglist_result.InnerHtml += "<a href=\"ShowBlogPost.aspx?blogid=" + blogid + "\">" + blogtitle + "</a>"; * * string blogbody = row["blogbody"]; * // bloglist_result.InnerHtml += "<div class=\"col2last\">" + blogbody + "</div>"; * * bloglist_result.InnerHtml += "</div> "; * }*/ foreach (Dictionary <String, String> row in rs) { bloglist_result.InnerHtml += "<div class=\"main-post\">"; string blogid = row["blogid"]; string blogtitle = row["blogtitle"]; bloglist_result.InnerHtml += "<h2><a href=\"ShowBlogPost.aspx?blogid=" + blogid + "\">" + blogtitle + "</a></h2>"; string blogbody = row["blogbody"]; bloglist_result.InnerHtml += "<p>" + blogbody + "</p>"; bloglist_result.InnerHtml += "</div>"; } }
protected void Page_Load(object sender, EventArgs e) { blogpost_result.InnerHtml = ""; string searchkey = ""; if (Page.IsPostBack) { searchkey = blogpost_search.Text; } string query = "select * from blog_post"; if (searchkey != "") { query += "where blogtitle like '%" + searchkey + "%'"; query += "where blogbody like '%" + searchkey + "%'"; } var db = new BLOGDB(); List <Dictionary <String, String> > rs = db.List_Query(query); foreach (Dictionary <String, String> row in rs) { blogpost_result.InnerHtml += "<div class=\"listitem\">"; string blogid = row["blogid"]; string blogtitle = row["blogtitle"]; blogpost_result.InnerHtml += "<div class=\"col2\"><a href=\"ShowBlogPost.aspx?blogid=" + blogid + "\">" + blogtitle + "</a></div>"; string blogbody = row["blogbody"]; blogpost_result.InnerHtml += "<div class=\"col2last\">" + blogbody + "</div>"; blogpost_result.InnerHtml += "</div>"; } }
protected void Update_Blog(object sender, EventArgs e) { BLOGDB db = new BLOGDB(); bool valid = true; string blogid = Request.QueryString["blogid"]; if (String.IsNullOrEmpty(blogid)) { valid = false; } Debug.WriteLine("i am trying to update the blog with id=" + blogid); if (valid) { BLOGPOST new_blog = new BLOGPOST(); new_blog.SetBPTitle(blog_title.Text); new_blog.SetBPBody(blog_post.Text); Debug.WriteLine("the new blog title is " + blog_title.Text + " and the new blog body is " + blog_post.Text); try { db.UpdateBlogPost(Int32.Parse(blogid), new_blog); Response.Redirect("ShowBlogPost.aspx?blogid=" + blogid); } catch { Debug.WriteLine("now im in the catch, is it working?"); valid = false; } } if (!valid) { Debug.WriteLine("last chance, but we kinda already know we got here"); blog.InnerHtml = "There was an error updating your blog"; } }
protected void ShowBlogInfo(BLOGDB db) { bool valid = true; string blogid = Request.QueryString["blogid"]; if (String.IsNullOrEmpty(blogid)) { valid = false; } if (valid) { Debug.WriteLine("is this it?"); BLOGPOST blog_record = db.FindBlogPost(Int32.Parse(blogid)); update_title.InnerHtml = blog_record.GetBPTitle(); blog_title.Text = blog_record.GetBPTitle(); blog_post.Text = blog_record.GetBPBody(); } if (!valid) { blog.InnerHtml = "There was an error updating your blog"; } }
protected void Page_Load(object sender, EventArgs e) { BLOGDB db = new BLOGDB(); ShowBlogPostInfo(db); }
protected void Page_Load(object sender, EventArgs e) { BLOGDB db = new BLOGDB(); ListBlogPostMenu(db); }