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;

namespace JuSNS.Web.home.mail
{
    public partial class to : JuSNS.UI.Page.UserPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Response.CacheControl = "no-cache";
            GetIsNotEmail();
            if (!Page.IsPostBack)
            {
                getUserName();
            }
        }

        /// <summary>
        /// 检查是否传递了会员编号
        /// </summary>
        protected void getUserName()
        {
            string s_UID = Request.QueryString["UserID"];
            if (s_UID != null && s_UID != "")
            {
                JuSNS.Home.User user = new JuSNS.Home.User();
                JuSNS.Model.UserInfo userinfo = new JuSNS.Model.UserInfo();
                userinfo = user.GetUserInfo(Convert.ToInt32(s_UID));
                span_Receiver.InnerHtml = "<a href=\"../../user/?r=" + userinfo.UserID.ToString() + "\">" + userinfo.Username + "</a>";
                Hid_UserID.Value = userinfo.UserID.ToString();
                statesautocomplete.Visible = false;
            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            if (Page.IsPostBack)
            {
                bool tf = true;
                if (Hid_UserID.Value.Trim() == "")
                {
                    tf = false;
                    ShowErr("请输入用户名", div_Error);
                    return;
                }
                if (Txt_Title.Value.Trim() == "" || Txt_Content.Text.Trim() == "")
                {
                    tf = false;
                    ShowErr("请填写私信的标题或内容", div_Error);
                    return;
                }
                int i_FID = Convert.ToInt32(Request.Form["Hid_UserID"]);
                if (tf)
                {
                    JuSNS.Home.Mail Mail = new JuSNS.Home.Mail();
                    JuSNS.Model.Mailinfo Mailinfo = new JuSNS.Model.Mailinfo();
                    Mailinfo.ID = 0;
                    Mailinfo.Sender = UserID;
                    Mailinfo.Receiver = i_FID;
                    Mailinfo.Title = Txt_Title.Value;
                    Mailinfo.Content = Txt_Content.Text;
                    Mailinfo.PostTime = DateTime.Now;
                    Mailinfo.PostIP = JuSNS.Common.Public.GetClientIP();
                    Mailinfo.TopicID = 0;
                    Mailinfo.IsReply = false;
                    Mailinfo.LtType = 0;
                    Mailinfo.RelativeID = 0;
                    Mailinfo.IsRead = 0;

                    if (Mail.Add(Mailinfo) == 1)
                    {
                        Response.Cookies["LetterIsScu"].Value = "true";
                    }
                    Response.Redirect("out.aspx");
                }
            }
        }
    }
}
