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.Common;
using JuSNS.Home;
using JuSNS.Model;
using JuSNS.Config;


namespace JuSNS.Web.user.Album
{
    public partial class HeadAlbum : JuSNS.UI.Page.UserPage
    {
        protected string[] r ={ "", "" };
        protected string errmsg = "";
        protected string AlbumContent;   //相册内容
        protected int PhotoCount = 0;  //相册中照片数量
        protected string Whos = "我";   //谁的相册
        protected string WhosHeadImage = "";
        protected AlbumInfo AbInf = new AlbumInfo();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(Request.QueryString["r[0]"]))
            {
                r[0] = Request.QueryString["r[0]"];
            }
            else
            {
                r[0] = this.UserID.ToString();
            }
            if (!string.IsNullOrEmpty(Request.QueryString["r[0]"]))
            {
                r[1] = Request.QueryString["r[1]"];
            }
            else
            {
                r[1] = Convert.ToString(0);
            }
            AbInf.AlbumID = 0;
            AbInf.Title = "头像相册";
            AbInf.UserID = Convert.ToInt32(r[0]);
            if (Convert.ToInt32(r[0]) == this.UserID)
            {
                this.toc.Visible = true;
            }
            else
            {
                this.toc.Visible = false;
            }
            this.SuccessMSG.Visible = false;
            if (Session["SuccessMSG"] != null)
            {
                this.SuccessMSG.InnerText = Session["SuccessMSG"].ToString();
                this.SuccessMSG.Visible = true;
                Session.Remove("SuccessMSG");
            }
            albumContent();
            setWhos();
        }

        /// <summary>
        /// 设置内容和照片数量
        /// </summary>
        /// <returns></returns>
        protected void albumContent()
        {
            Photo ph = new Photo();
            List<PhotoInfo> listinfo = ph.HeadInfoList(Convert.ToInt32(r[1]), Convert.ToInt32(r[0]));
            StringBuilder sb = new StringBuilder();
            sb.Append("<tr>\n");
            for (int i = 0; i < listinfo.Count; i++)
            {
                sb.Append("<td>\n");
                sb.Append("                <a class=\"photo\" href=\"PhotoView.aspx?r[0]=" + listinfo[i].PhotoID + "&r[1]=" + listinfo[i].AlbumID + "&r=" + listinfo[i].UploadUser + "\">\n");
                sb.Append("                    <img src=\"" + Public.GetSmallHeadPic(listinfo[i].FilePath, 2) + "\" alt=\"" + listinfo[i].Description + "\" /></a></td>\n");
                if ((i + 1) % 4 == 0)
                {

                    sb.Append("</td></tr>");

                    if (i < listinfo.Count - 1)
                    {
                        sb.Append("<tr>");
                    }
                }
            }
            PhotoCount = listinfo.Count;
            AlbumContent = sb.ToString();
        }

        /// <summary>
        /// 设置是谁的相册
        /// </summary>
        protected void setWhos()
        {
            if (r[0] == this.UserID.ToString())
            {
                Whos = "我";
            }
            else
            {
                User u = new User();
                UserInfo UI = u.GetUserInfo(Convert.ToInt32(r[0]));
                Photo ph = new Photo();
                Whos = UI.Username;
            }
        }
    }
}
