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 JuSNS.Model;
using JuSNS.UI.Control;
using JuSNS.Common;

namespace JuSNS.Web.home.mail
{
    public partial class index : JuSNS.UI.Page.UserPage
    {
        JuSNS.Home.User user = new JuSNS.Home.User();
        JuSNS.Model.UserInfo userinfo = new JuSNS.Model.UserInfo();
        JuSNS.Home.Photo photo = new JuSNS.Home.Photo();
        JuSNS.Model.PhotoInfo photoinfo = new JuSNS.Model.PhotoInfo();
        protected string SenderName = "";

        JuSNS.Home.Mail letter = new JuSNS.Home.Mail();
        protected void Page_Load(object sender, EventArgs e)
        {
            LoadList();
        }

        /// <summary>
        /// 加载分页
        /// </summary>
        /// <param name="PageIndex">当前页数</param>
        protected void LoadList()
        {
            DivPage.Visible = false;
            int r, p, PageIndex = 0;
            PageIndex = Convert.ToInt32(Request.QueryString["Page"]);
            SqlConditionInfo st = new SqlConditionInfo("@Receiver", UserID, TypeCode.Int32);

            DataTable dt = JuSNS.Home.UtilPage.GetPage("Inbox_aspx", PageIndex, PAGESZ, out r, out p, st);
            if (dt != null)
            {
                Rpt_Inbox.DataSource = dt;
                Rpt_Inbox.DataBind();
                dt.Clear();
                dt.Dispose();
            }
            //判断是否调用分页
            if (r > PAGESZ)
            {
                DivPage.Visible = true;
                DivPage.InnerHtml = PageNavigator.Pagination(PageIndex, p, "inbox.aspx");
            }
            span_Count.InnerHtml = r.ToString();
        }

        /// <summary>
        /// 取得Li样式
        /// </summary>
        /// <param name="isReplay">是否已回复</param>
        /// <param name="ID">私信编号</param>
        /// <returns></returns>
        protected string getClass(object isReplay, object ID)
        {
            string listTF = string.Empty;
            if (Convert.ToInt32(isReplay) == 1)
            {
                listTF = "<span class=\"blue bold\"><已回复></span> ";
            }
            int isread = letter.getNewReCNT(Convert.ToInt32(ID), UserID);
            if (isread == 0)
            {
                listTF = "<span class=\"reshow bold\"><未阅></span> ";
            }
            return listTF;
        }       

        /// <summary>
        /// 取得最新回复内容
        /// </summary>
        /// <param name="LetterID">私信编号</param>
        /// <returns></returns>
        protected string getContent(object LetterID)
        {
            JuSNS.Home.Mail letter = new JuSNS.Home.Mail();
            return JuSNS.Common.Public.CheckSma(Input.HtmlDecode(letter.getNewReContent(Convert.ToInt32(LetterID), false, 0)));
        }

        /// <summary>
        /// 取得时间
        /// </summary>
        /// <param name="time">时间</param>
        /// <returns></returns>
        protected string getTime(object time)
        {
            return JuSNS.Common.Public.getTimeSpan(Convert.ToDateTime(time));
        }

        /// <summary>
        /// 取得用户编号
        /// </summary>
        /// <param name="Sender">发送者</param>
        /// <param name="Receiver">接收者</param>
        /// <returns></returns>
        protected string getUserID(object Sender, object Receiver)
        {
            if (Sender.ToString() == UserID.ToString())
                return JuSNS.Common.Public.URLWrite("", "r", Receiver.ToString());
            else
                return JuSNS.Common.Public.URLWrite("", "r", Sender.ToString());
        }

        /// <summary>
        /// 取得用户名称
        /// </summary>
        /// <param name="UserName">用户名称</param>
        /// <param name="Sender">发送者</param>
        /// <param name="Receiver">接收者</param>
        /// <returns></returns>
        protected string getUserName(object UserName, object Sender, object Receiver)
        {
            if (Sender.ToString() == UserID.ToString())
                return SenderName;
            else
                return UserName.ToString();
        }

        /// <summary>
        /// 取得用户头像地址
        /// </summary>
        /// <param name="FilePath">照片编号</param>
        /// <param name="Sender">发送者</param>
        /// <param name="Receiver">接收者</param>
        /// <returns></returns>
        protected string getHead(object Sender, object Receiver)
        {
            if (Sender.ToString() != UserID.ToString())
            {
                return this.GetHeadImage(Sender, 1);
            }
            else
                return this.GetHeadImage(Receiver, 1);
        }

    }
}
