using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CareersOnlineLibrary;
using CareersOnlineLibrary.Entity;
using CareersOnlineLibrary.Controller;
namespace WebApplication1.Blogs
{
public partial class BlogList1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
// Put user code to initialize the page here
if (IsPostBack)
{
}
else
{
// initialize Blog and read it into a blog collection
CareersOnlineController controller = new CareersOnlineController();
BlogCollection blogs = new BlogCollection();
blogs = controller.GetTop10Blogs();
// Dynamically build the blog into a WebControls.Table
RebuildTableView(blogs);
blogs = null;
controller = null;
}
}
void RebuildTableView(BlogCollection blogs)
{
string previousUser = ""; // track previous
// loop through each row in the data set and create
// the row on the web page in a web table
foreach (Blog dr in blogs)
{
// add title (use a single column)
TableRow tr = new TableRow();
tr.Cells.Add(new TableCell());
// change title color slightly
tr.Cells[0].ForeColor = System.Drawing.Color.Navy;
tr.Cells[0].Width = 400;
// make the text title big and purple
tr.Cells[0].Text = "" + dr.Title + "";
this.BlogTable.Rows.Add(tr);
// add blog in a single column and span 2 columns
tr = new TableRow();
tr.Cells.Add(new TableCell());
tr.Cells[0].Width = 550;
tr.Cells[0].ColumnSpan = 2;
tr.Cells[0].Text = dr.BlogComment;
this.BlogTable.Rows.Add(tr);
// add user who posted and date (use two columns in the row)
tr = new TableRow();
tr.Height = 50;
tr.HorizontalAlign = HorizontalAlign.Left;
tr.VerticalAlign = VerticalAlign.Bottom;
tr.Cells.Add(new TableCell());
tr.Cells.Add(new TableCell());
tr.Cells[0].Text = "Posted by " + dr.Name;
DateTime postTime = DateTime.Parse(dr.Time.ToString());
tr.Cells[1].HorizontalAlign = HorizontalAlign.Right;
tr.Cells[1].Text = String.Format("{0}", postTime.ToString("MMM dd, yyyy @ hh:mm"));
this.BlogTable.Rows.Add(tr);
// add separtor graphic and span 2 columns
tr = new TableRow();
tr.Cells.Add(new TableCell());
tr.Cells.Add(new TableCell());
tr.Cells[0].ColumnSpan = 2;
this.BlogTable.Rows.Add(tr);
string imageFile = this.ResolveUrl(@"~\Images\separator.jpg");
System.Web.UI.WebControls.Image separator = new System.Web.UI.WebControls.Image();
separator.ImageUrl = imageFile;
separator.Width = 600;
separator.Height = 32;
separator.Visible = true;
tr.Cells[0].Controls.Add(separator);
tr.Cells[0].HorizontalAlign = HorizontalAlign.Center;
}
}
protected void btnOpenEntry_Click(object sender, EventArgs e)
{
Response.Redirect("~/Blogs/BlogEntry.aspx");
}
}
}