using System;
using System.Data;
using System.Web;
using System.Web.UI;
using BoyunBase;
using SiteCore;

public partial class Part_ArticleContent : System.Web.UI.UserControl
{
    private PartAccess pAcc = null;
    private int aid = 0;

    protected void Page_Load( object sender, EventArgs e )
    {
        try {
            if( IsPostBack ) return;

            aid = Todo.GetInt( "aid", Request, -1 );
            if( aid < 0 ) return;

            pAcc = new PartAccess( this );
            if( pAcc.IsReady )
                PartShow();

        } catch( Exception ex ) {
            Todo.DebugOut( "加载 Part_ArticleContent 出现异常：" + ex.Message );
        }
    }

    private void PartShow()
    {
        // 读取 内容
        ContentAccess ca = new ContentAccess( this, "TableName" );
        DataTable dt = ca.Read( "[@ID=" + aid + "]", "name" );
        if( dt == null || dt.Rows.Count < 1 ) {
            lbHeading.InnerText = "没有找到该文章";
            return;
        }

        // 显示 文章的标题
        DataRow dr = dt.Rows[0];
        string heading = Todo.Get( "Heading", dr );
        lbHeading.InnerText = heading;
        if( this.Page.Title == "" )
            this.Page.Title = heading;
        else
            this.Page.Title = heading + " - " + this.Page.Title;

        // 显示内容
        ltrContent.Text = Todo.Get( "Content", dr );

        // 显示时间
        string issueTime = Todo.Get( "IssueTime", dr );
        string format = pAcc.GetSetting( "issueTimeFormat" );
        lbIssueTime.InnerText = Todo.TimeFormat( issueTime, format );

        // 显示 作者 来源 访问量 等
        lbAuthor.InnerText = Todo.Get( "Author", dr );
        lbSource.InnerText = Todo.Get( "Source", dr );
        lbVisited.InnerText = Todo.Get( "Visited", dr );
    }
}
