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 addfriend : JuSNS.UI.Page.UserPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            int n = 0;
            JuSNS.Home.Friend frd = new JuSNS.Home.Friend();
            JuSNS.Home.User us = new JuSNS.Home.User();
            string uid = Request.QueryString["uid"];
            if (uid == UserID.ToString())
            {
                Response.Write("<span class=\"reshow\">不能自己加自己为好友！</span>");
                Response.End();
            }
            if (JuSNS.Common.Input.IsInteger(uid))
            {
                if (!us.CheckUser(Convert.ToInt32(uid)))
                {
                    n = -4;
                }
                else
                {
                    n = frd.Request(UserID, Convert.ToInt32(uid));
                }
            }
            else if (uid.IndexOf("@") > -1)
            { 
                //根据电子邮件取得ID
                int gUID = frd.GetUserIDFromEmail(uid);
                if (gUID > 0)
                {
                    if (gUID == UserID)
                    {
                        Response.Write("<span class=\"reshow\">不能自己加自己为好友！</span>");
                        Response.End();
                    }
                    n = frd.Request(UserID, Convert.ToInt32(gUID));
                }
                else
                {
                    n = -4;
                }
            }
            else 
            {
                n = -3;
            }

            if (n == -1)
            {
                Response.Write("<span class=\"reshow\">您们已经是好友了！</span>");
                Response.End();
            }
            else if (n == -2)
            {
                Response.Write("您的请求已经发送过，等待对方验证！");
                Response.End();
            }
            else if (n == -3)
            {
                Response.Write("<span class=\"reshow\">请正确填写！</span>");
                Response.End();
            }
            else if (n == -4)
            {
                Response.Write("<span class=\"reshow\">用户不存在或者用户没有激活帐号！</span>");
                Response.End();
            }
            else
            {
                Response.Write("加好友成功，等待对方验证！");
                Response.End();
            }

        }
    }
}
