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 _out : 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 = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            LoadList();
            IsAddSuc();
        }

        /// <summary>
        /// 检查是否添加成功
        /// </summary>
        protected void IsAddSuc()
        {
            try
            {
                if (Request.Cookies["LetterIsScu"].Value == "true")
                    ShowSuc("发送成功!", this.div_Suc);
                Response.Cookies["LetterIsScu"].Value = "";
            }
            catch (Exception e) { }
        }


        /// <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("@Sender", UserID, TypeCode.Int32);

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

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

        /// <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), true, UserID)));
        }

        /// <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 (Receiver.ToString() == UserID.ToString())
                return JuSNS.Common.Public.URLWrite("", "r", Sender.ToString());
            else
                return JuSNS.Common.Public.URLWrite("", "r", Receiver.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 (Receiver.ToString() == UserID.ToString())
                return SenderName;
            else
                return UserName.ToString();
        }

    }
}
