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.inc.Ajax.friend
{
    public partial class mailto : JuSNS.UI.Page.UserPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string a = Request.QueryString["a"];
            if (a == "save")
            {
                SendMail();
            }
            else
            {
                string uid = Request.QueryString["uid"];
                if (JuSNS.Common.Input.IsInteger(uid))
                {
                    JuSNS.Home.User us = new JuSNS.Home.User();
                    JuSNS.Model.UserInfo mdl = new JuSNS.Model.UserInfo();
                    mdl = us.GetUserInfo(Convert.ToInt32(uid));
                    this.UserNames.Value = mdl.Username;
                    this.uID.Value = uid;
                    this.m_title.Value = Request.QueryString["c"];
                }
            }
        }

        protected void SendMail()
        {
             JuSNS.Home.User us = new JuSNS.Home.User();
             string RecID = Request.QueryString["recID"];
             string Title = Request.QueryString["title"];
             string cont = Request.QueryString["content"];
             if (string.IsNullOrEmpty(Title))
             {
                 Response.Write("信件标题不能为空！");
                 Response.End();
             }
             if (string.IsNullOrEmpty(cont))
             {
                 Response.Write("信件内容不能为空！");
                 Response.End();
             }

             JuSNS.Home.Mail Mail = new JuSNS.Home.Mail();
            JuSNS.Model.Mailinfo Mailinfo = new JuSNS.Model.Mailinfo();
            Mailinfo.ID = 0;
            Mailinfo.Sender = UserID;
            Mailinfo.Receiver = Convert.ToInt32(RecID);
            Mailinfo.Title = Title;
            Mailinfo.Content = cont;
            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.Write("succ");
                Response.End();
            }
            else
            {
                Response.Write("意外错误！");
                Response.End();
            }
        }
    }
}
