using System.Web;
using System.Web.Services;

namespace web.MyAJAX
{
    /// <summary>
    /// $codebehindclassname$ 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    public class HdCheckUser : IHttpHandler
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="context"></param>
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string type = "";// t ： 类型 n ：用户名
            if (HttpContext.Current.Request.QueryString["t"] != null)
            {
                type = HttpContext.Current.Request.QueryString["t"].ToString();
            }
            #region
            //添加 注册
            if (type == "Reg")
            {
                string _EnName = HttpContext.Current.Request.QueryString["n"].ToString();
                context.Response.Write(IsReg(_EnName));
                context.Response.End();
                return;
            }
            #endregion


        }
        #region
        /// <summary>
        /// 0 ：不可重复，ok：可以注册，：err：发生异常，no：其他
        /// </summary>
        /// <param name="EnName"></param>
        /// <returns></returns>
        private string IsReg(string EnName)
        {
            int count = Stat.BLL.Users.CheckUserName(EnName);

            if (count > 0)
                return "0"; //不能够注册（已经存在，）
            else if (count == 0)
                return "ok"; //可以注册（不存在 ，）
            else if (count == -1)
                return "err";
            else
                return "no";
        }
        #endregion











        /// <summary>
        /// 
        /// </summary>
        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}
