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

namespace JuSNS.Web.home.ram
{
    public partial class net : JuSNS.UI.Page.BasePage
    {
        protected string province = string.Empty;
        protected string cityarray = string.Empty;
        protected string Pr = null;
        protected void Page_Load(object sender, EventArgs e)
        {
            loadPro();
            string tPath = "~/template/site/net.html";
            string TempletContent = Public.GetTempleContent(tPath, false);
            TempletContent = GetReplaceContent(TempletContent);
            Response.Write(TempletContent);
            Response.End();
        }

        protected string GetReplaceContent(string sContent)
        {
            string listSTR = string.Empty;
            sContent = Public.ReplacePublic(sContent);
            sContent = sContent.Replace("{GetHtmlHead}", this.GetHtmlHead());
            sContent = sContent.Replace("{GetHtmlShort}", this.GetHtmlShort());
            sContent = sContent.Replace("{GetHtmlLeft}", this.GetHtmlLeft());
            sContent = sContent.Replace("{GetHtmlFoot}", this.GetHtmlFoot());
            sContent = sContent.Replace("{RecUser}", GetRecUser("Rec"));
            sContent = sContent.Replace("{HotUser}", GetRecUser("Hot"));
            sContent = sContent.Replace("{GGUser}", GetRecUser("GG"));
            sContent = sContent.Replace("{MMUser}", GetRecUser("MM"));
            sContent = sContent.Replace("{JFUser}", GetRecUser("JF"));
            sContent = sContent.Replace("{HYUser}", GetRecUser("HY"));
            sContent = sContent.Replace("{province}", province);
            sContent = sContent.Replace("{cityarray}", cityarray);
            sContent = sContent.Replace("{HotBlog}", GetHotBlog());
            sContent = sContent.Replace("{AlbumList}", AlbumList());
            sContent = sContent.Replace("{Mood}", Mood());
            sContent = sContent.Replace("{GroupList}", Groups());
            sContent = sContent.Replace("{HotNews}", HotNews());
            sContent = sContent.Replace("{DYNNews}", DynList());
            listSTR = sContent;
            return listSTR;
        }

        protected string GetRecUser(string flg)
        {
            string listSTR = string.Empty;
            int ReCount, PgCount;
            int PageIndex = 1;
            DataTable dt = null;
            switch (flg)
            {
                case "Rec":
                    dt = UtilPage.GetPage("Friend_Index_Rec_aspx", PageIndex, 7, out ReCount, out PgCount, null);
                    break;
                case "Hot":
                    dt = UtilPage.GetPage("Friend_Index_Hot_aspx", PageIndex, 14, out ReCount, out PgCount, null);
                    break;
                case "GG":
                    dt = UtilPage.GetPage("Friend_Index_GG_aspx", PageIndex, 14, out ReCount, out PgCount, null);
                    break;
                case "MM":
                    dt = UtilPage.GetPage("Friend_Index_MM_aspx", PageIndex, 14, out ReCount, out PgCount, null);
                    break;
                case "JF":
                    dt = UtilPage.GetPage("Friend_Index_JF_aspx", PageIndex, 14, out ReCount, out PgCount, null);
                    break;
                case "HY":
                    dt = UtilPage.GetPage("Friend_Index_HY_aspx", PageIndex, 14, out ReCount, out PgCount, null);
                    break;
            }
            Home.Album ab = new Home.Album();
            JuSNS.Home.User u = new JuSNS.Home.User();
            int gRowscount = dt.Rows.Count;
            for (int i = 0; i < gRowscount; i++)
            {
                listSTR += "<li><a href=\"" + rooDir + "/user/" + JuSNS.Common.Public.URLWrite(string.Empty, "r", dt.Rows[i]["UserID"].ToString()) + "\">\n";
                listSTR += "<img alt=\"" + dt.Rows[i]["UserName"] + "\" src=\"" + this.GetHeadImage(Convert.ToInt32(dt.Rows[i]["UserID"].ToString()), 1) + "\"  align=\"absmiddle\" style=\"width:48px;height:48px;\" />\n";
                listSTR += "<span>" + JuSNS.Common.Input.GetSubString(dt.Rows[i]["UserName"].ToString(), 8) + "</span></a>\n";
                listSTR += "</li>\n";
            }
            return listSTR;
        }

        protected string GetHotBlog()
        {
            string listSTR = string.Empty;
            int ReCount, PgCount;
            int PageIndex = 1;
            DataTable dt = UtilPage.GetPage("BlogList_Index_Hot_aspx", PageIndex, 10, out ReCount, out PgCount, null);
            Home.Album ab = new Home.Album();
            JuSNS.Home.User u = new JuSNS.Home.User();
            int gRowscount = dt.Rows.Count;
            for (int i = 0; i < gRowscount; i++)
            {
                listSTR += "<li><b><a href=\""+rooDir+"/blog/b" + dt.Rows[i]["ID"].ToString() + ".aspx\">" + JuSNS.Common.Input.GetSubString(dt.Rows[i]["Title"].ToString(), 82) + "</a></b>\n";
                listSTR += "<div><a href=\"" + rooDir + "/user/" + JuSNS.Common.Public.URLWrite(string.Empty, "r", dt.Rows[i]["UserID"].ToString()) + "\">" + dt.Rows[i]["UserName"].ToString() + "</a> <span class=\"time\">(" + JuSNS.Common.Public.getTimeEXPINSpan(DateTime.Parse(dt.Rows[i]["PostTime"].ToString())) + "，" + dt.Rows[i]["Comments"].ToString() + "人评论)</span> <a href=\"" + rooDir + "/blog/b" + dt.Rows[i]["ID"].ToString() + ".aspx#addcomment\">回复(" + dt.Rows[i]["comments"].ToString() + ")</a></div>\n";
                listSTR += "<div>" + JuSNS.Common.Input.GetSubString(JuSNS.Common.Input.ForTXT(JuSNS.Common.Input.LostHTML(dt.Rows[i]["Content"].ToString())), 150) + "</div>\n";
                listSTR += "</li>\n";
            }
            return listSTR;
        }

        protected string AlbumList()
        {
            string listSTR = string.Empty;
            int ReCount, PgCount;
            int PageIndex = 1;
            DataTable dt = UtilPage.GetPage("Friend_Album_List_All_Index", PageIndex, 6, out ReCount, out PgCount, null);
            Home.Album ab = new Home.Album();
            JuSNS.Home.User u = new JuSNS.Home.User();
            int gRowscount = dt.Rows.Count;
            for (int i = 0; i < gRowscount; i++)
            {
                listSTR += "<li><a href=\"" + rooDir + "/home/album/AlbumView.aspx?r[0]=" + dt.Rows[i]["UserID"] + "&r[1]=" + dt.Rows[i]["AlbumID"] + "\">\n";
                listSTR += "<img alt=\"" + dt.Rows[i]["Title"] + ",有" + dt.Rows[i]["ImagesCount"] + "张照片\" src=\"" + this.GetSmallPic(ab.CoverPath((int)dt.Rows[i]["AlbumID"]), 1) + "\" align=\"absmiddle\" /></a>\n";
                listSTR += "<div><a href=\"" + rooDir + "/home/albumAlbumview.aspx?r[0]=" + dt.Rows[i]["UserID"] + "&r[1]=" + dt.Rows[i]["AlbumID"] + "\">" + JuSNS.Common.Input.GetSubString(dt.Rows[i]["Title"].ToString(), 12) + "</a></div>\n";
                listSTR += "</li>\n";
            }
            return listSTR;
        }

        protected string Mood()
        {
            string listSTR = string.Empty;
            int ReCount, PgCount;
            int PageIndex = 1;

            DataTable dt = UtilPage.GetPage("mood_all_ram", PageIndex, 15, out ReCount, out PgCount, null);
            Home.Album ab = new Home.Album();
            JuSNS.Home.User u = new JuSNS.Home.User();
            int gRowscount = dt.Rows.Count;
            for (int i = 0; i < gRowscount; i++)
            {
                listSTR += "<li><a href=\"" + rooDir + "/user/" + JuSNS.Common.Public.URLWrite("", "r", dt.Rows[i]["UserID"].ToString()) + "\">" + dt.Rows[i]["UserName"].ToString() + "</a>说： \n";
                listSTR += "" + JuSNS.Common.Public.CheckSma(JuSNS.Common.Input.LostHTML(dt.Rows[i]["Content"].ToString())) + "<a href=\"" + rooDir + "/home/mood/?mid=" + dt.Rows[i]["ID"].ToString() + "#re_" + dt.Rows[i]["ID"].ToString() + "\">回复(" + dt.Rows[i]["cc"].ToString() + ")</a><span class=\"time\">(" + JuSNS.Common.Public.getTimeEXPINSpan(DateTime.Parse(dt.Rows[i]["PostTime"].ToString())) + ")</span>\n";
                listSTR += "</li>\n";
            }
            return listSTR;

        }

        protected string Groups()
        {
            string listSTR = string.Empty;
            int ReCount, PgCount;
            int PageIndex = 1;
            DataTable dt = UtilPage.GetPage("Group_Index_Rec_aspx", PageIndex, 6, out ReCount, out PgCount, null);
            int gRowscount = dt.Rows.Count;
            for (int i = 0; i < gRowscount; i++)
            {
                listSTR += "<li><a href=\"" + rooDir + "/home/group/group.aspx?GroupID=" + dt.Rows[i]["GroupID"].ToString() + "\"  target=\"_blank\">\n";
                listSTR += "<img alt=\"" + dt.Rows[i]["GroupName"] + "\" src=\"" + this.GetGroupHead(dt.Rows[i]["Portrait"].ToString()) + "\"  align=\"absmiddle\" style=\"width:60px;height:60px;\" /></a>\n";
                listSTR += "<div><a href=\"" + rooDir + "/home/group/group.aspx?GroupID=" + dt.Rows[i]["GroupID"].ToString() + "\">" + JuSNS.Common.Input.GetSubString(dt.Rows[i]["GroupName"].ToString(), 12) + "</a></div>\n";
                listSTR += "</li>\n";
            }
            return listSTR;
        }

        protected string HotNews()
        {
            string listSTR = string.Empty;
            int ReCount, PgCount;
            int PageIndex = 1;
            DataTable dt = UtilPage.GetPage("News_ALL_aspx", PageIndex, 5, out ReCount, out PgCount, null);
            Home.Album ab = new Home.Album();
            JuSNS.Home.User u = new JuSNS.Home.User();
            int gRowscount = dt.Rows.Count;
            for (int i = 0; i < gRowscount; i++)
            {
                listSTR += "<li><div class=\"nl s99\"><a href=\"" + rooDir + "/News/n" + dt.Rows[i]["ID"].ToString() + ".aspx\">" + JuSNS.Common.Input.GetSubString(dt.Rows[i]["Title"].ToString(), 82) + "</a></div>\n";
                string PicSTR = string.Empty;
                if (!string.IsNullOrEmpty(dt.Rows[i]["Pic"].ToString()))
                {
                    PicSTR = "<div class=\"nl image\" style=\"margin-right:8px\"><a href=\"" + rooDir + "/News/n" + dt.Rows[i]["ID"].ToString() + ".aspx\"><img src=\"" + rooDir + "/" + dt.Rows[i]["Pic"].ToString() + "\" style=\"width:60px;\" align=\"absmiddle\" style=\"border:0;\" /></a></div>";
                }
                if (dt.Rows[i]["Content"].ToString().Length > 50)
                {
                    listSTR += "<div class=\"nl s99\"><div style=\"line-height:22px;\">" + PicSTR + "<div class=\"nl\">" + JuSNS.Common.Input.GetSubString(JuSNS.Common.Input.ForTXT(JuSNS.Common.Input.FilterHTML(dt.Rows[i]["Content"].ToString())), 200) + "</div></div><div class=\"spline\"></div>\n";
                }
                listSTR += "</li>\n";
            }
            return listSTR;
        }

        protected string DynList()
        {
            HomeIndex uHome = new HomeIndex();
            List<UserLogInfo> list = null;
            list = uHome.DynList(0);
            string UserDynStr = string.Empty;
            string rStr = string.Empty;
            if (list != null || list.Count > 0)
            {
                string gDateSTR = string.Empty;
                foreach (UserLogInfo info in list)
                {
                    string TmpUserLogStr = ParseUserLog.Parse(info, 0);
                    if (TmpUserLogStr != string.Empty)
                    {
                        UserDynStr += "<li>" + TmpUserLogStr + "</li>\r";
                        if (UserDynStr.IndexOf("{UserHeadPic}") > -1) { UserDynStr = UserDynStr.Replace("{UserHeadPic}", string.Empty); }
                        if (UserDynStr.IndexOf("{CloseDyn}") > -1) { UserDynStr = UserDynStr.Replace("{CloseDyn}", string.Empty); }
                        gDateSTR = info.LogTime.ToString("MM-dd");
                    }
                }
                rStr = UserDynStr;
                rStr = rStr.Replace("{Email}", string.Empty);
                rStr = rStr.Replace("{sUserID}", string.Empty);
            }
            return rStr;
        }

        protected void loadPro()
        {
            Dict dict = new Dict();
            IList<DictAreaInfo> list = dict.GetArea();
            foreach (DictAreaInfo info in list)
            {
                if (info.ParentID.Equals(0))
                {
                    province += "<option value=\"" + info.ID + "\">" + info.Name + "</option>";
                }
                else
                {
                    if (!cityarray.Equals(string.Empty))
                        cityarray += ",";
                    cityarray += "new Array('" + info.ParentID + "','" + info.ID + "','" + info.Name + "')";
                }
            } DataBind();
        }
    }
}
