using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;
using System.Text;

public partial class usercontrol_NewTopMsg : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        getMsg();
    }

    void getMsg()
    {
        OleDbDataReader dr = null;
        if (WebClass.GetCache("NewTop10") == null)
        {
            try
            {
                string sql = "SELECT TOP 10 * FROM MESSAGE WHERE uSTATUS = TRUE ORDER BY ID DESC";
                dr = SqlHelper.ExecuteReader(sql);
                StringBuilder sb = new StringBuilder();
                sb.Append("<span style='width:98%;font-weight:bold;margin-top:10px;'>最新留言</span>");
                while (dr.Read())
                {
                    //string url = dr["surl"].ToString().Replace("http://", "");
                    string ut = dr["utext"].ToString();
                    if (WebClass.GetBytesLength(ut) > 25)
                        ut = WebClass.CutString(ut, 25);
                    sb.AppendFormat("<li><a href=\"Message.aspx\">{0}</a></li>", Server.HtmlEncode(ut));
                }
                WebClass.SetCache("NewTop10",sb.ToString());
                this.dt10.InnerHtml = sb.ToString();
            }
            catch (Exception ex)
            {
                this.dt10.InnerHtml = "读取出错:" + ex.Message;
            }
            finally { if (!dr.IsClosed)dr.Close(); }
        }
        else
        {
            this.dt10.InnerHtml = WebClass.GetCache("NewTop10").ToString();
        }
    }
}
