using System;
using System.Text;
using System.Data;
using System.Collections.Generic;
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 JuSNS.Common;
using JuSNS.Home;
using JuSNS.Model;
using JuSNS.Config;
using JuSNS.UI.Control;

namespace JuSNS.Web.home.friend
{
    public partial class online : JuSNS.UI.Page.UserPage
    {
        Friend frd = new Friend();
        protected void Page_Load(object sender, EventArgs e)
        {
            LoadList();
        }

        /// <summary>
        /// 分页绑定数据
        /// </summary>
        protected void LoadList()
        {
            int ReCount, PgCount;
            int PageIndex = 1;
            if (Request.QueryString["Page"] != null)
            {
                PageIndex = Convert.ToInt32(Request.QueryString["Page"]);
            }
            DataTable dt = UtilPage.GetPage("OnlineFriend_aspx", PageIndex, 30, out ReCount, out PgCount, new SqlConditionInfo("@UserID", this.UserID, TypeCode.Int32));
            string PageUrl = "../friend/online.aspx";
            DataTable data = new DataTable();
            data.Columns.Add("d", typeof(string));
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                StringBuilder sb = new StringBuilder();
                DataRow dr = data.NewRow();
                string reshowStr = string.Empty;
                sb.Append("<li><div class=\"nl\">\n");
                sb.Append("<div class=\"w60 nl img\"><a href=\"../../user/" + JuSNS.Common.Public.URLWrite("", "r", dt.Rows[i]["UserID"].ToString()) + "\"><img style=\"width:48px;height:48px;\" src=\"" + GetHeadImage(Convert.ToInt32(dt.Rows[i]["UserID"].ToString()), 1) + "\" /> </a></div>\n");
                sb.Append("<div class=\"w120 nl\"><a href=\"../../user/" + JuSNS.Common.Public.URLWrite("", "r", dt.Rows[i]["UserID"].ToString()) + "\">" + dt.Rows[i]["UserName"].ToString() + "</a><div title=\"" + dt.Rows[i]["Mood"].ToString() + "\">" + ShowLastMiniBlog(dt.Rows[i]["Mood"].ToString()) + "</div><div class=\"tshow\">" + JuSNS.Common.Public.getTimeEXPINSpan(DateTime.Parse(dt.Rows[i]["LastTime"].ToString())) + "</div></div>\n");
                sb.Append("</div></li>\n");
                dr["d"] = sb.ToString();
                data.Rows.Add(dr);
            }
            this.MyNoteList.Visible = true;
            this.MyNoteList.DataSource = data;
            this.MyNoteList.DataBind();
            PageUrl += "";
            if (ReCount > 30)
            {
                this.DivPage.InnerHtml = PageNavigator.Pagination(PageIndex, PgCount, PageUrl);
            }
            else
            {
                this.DivPage.Visible = false;
            }
        }

        /// <summary>
        /// 取得心情日记信息
        /// </summary>
        /// <param name="userid"></param>
        /// <returns></returns>
        protected string ShowLastMiniBlog(string mood)
        {
            if (!string.IsNullOrEmpty(mood))
            {
                return Input.GetSubString(mood, 12);
            }
            else
            {
                return string.Empty;
            }
        }
    }
}
