using System;
using System.Data;
using System.Text;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
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.Home;
using JuSNS.Model;

namespace JuSNS.Web.home.space
{
    public partial class dyn : JuSNS.UI.Page.UserPage
    {
        protected int uID = 0;
        JuSNS.Home.HomeIndex uHome = new JuSNS.Home.HomeIndex();
        protected void Page_Load(object sender, EventArgs e)
        {
            string r = Request.QueryString["r"];
            if (JuSNS.Common.Input.IsInteger(r))
            {
                uID = Convert.ToInt32(r);
            }
            else
            {
                uID = this.UserID;
            }
            DynList(50);
        }

        /// <summary>
        /// 读取动态
        /// </summary>
        protected void DynList(int Num)
        {
            string a = Request.QueryString["a"];
            if (string.IsNullOrEmpty(a))
            {
                a = string.Empty;
            }
            List<UserLogInfo> list = null;
            list = uHome.DynlistID(uID, Num, a);
            string UserDynStr = string.Empty;
            string rStr = string.Empty;
            if (list == null || list.Count < 1)
            {
                rStr = "<ul></ul>\r";
            }
            else
            {
                string gDateSTR = string.Empty;
                bool isZ = false;
                foreach (UserLogInfo info in list)
                {
                    string TmpUserLogStr = ParseUserLog.Parse(info, this.UserID);
                    if (TmpUserLogStr != string.Empty)
                    {
                        DateTime nday = DateTime.Now;
                        string ShowDateSTR = string.Empty;
                        if (gDateSTR != info.LogTime.ToString("MM-dd"))
                        {
                            if (info.LogTime.ToString("MM-dd") == nday.ToString("MM-dd")) { ShowDateSTR = "<li class=\"dyncli\"><span class=\"legend\">今天</span></li>"; }
                            else if (info.LogTime.ToString("MM-dd") == (nday.AddDays(-1)).ToString("MM-dd")) { ShowDateSTR = "<li class=\"dyncli\"><span class=\"legend\">昨天</span></li>"; }
                            else if (info.LogTime.ToString("MM-dd") == (nday.AddDays(-2)).ToString("MM-dd")) { ShowDateSTR = "<li class=\"dyncli\"><span class=\"legend\">前天</span></li>"; }
                            else
                            {
                                if (!isZ)
                                {
                                    ShowDateSTR = "<li class=\"dyncli\"><span class=\"legend\">更早</span></li>";
                                    isZ = true;
                                }
                            }
                        }
                        else
                        {
                            ShowDateSTR = string.Empty;
                        }
                        UserDynStr += ShowDateSTR;
                        UserDynStr += "<li class=\"ico-" + info.DynType + "\">" + TmpUserLogStr + "</li>\r";
                        if (UserDynStr.IndexOf("{UserHeadPic}") > -1)
                        {
                            UserDynStr = UserDynStr.Replace("{UserHeadPic}", "<a href=\"../user/" + JuSNS.Common.Public.URLWrite("", "r", info.infoarr) + "\"><img src=\"" + GetHeadImage(Convert.ToInt32(info.infoarr), 1) + "\" style=\"width:48px;\" /></a>");
                        }
                        UserDynStr = UserDynStr.Replace("{CloseDyn}", string.Empty);
                        gDateSTR = info.LogTime.ToString("MM-dd");
                    }
                }
                rStr = "<ul>" + UserDynStr + "</ul>\r";
                rStr = rStr.Replace("{Email}", "");
                rStr = rStr.Replace("{sUserID}", uID.ToString());
            }
            this.dnynews.InnerHtml=rStr;
        }
    }
}
