using System;
using System.Collections.Generic;
using System.Text;
using JoleYe.Model;
using JoleYe.Dal;
using JoleYe.Bll;
using System.Web;
using JoleYe.Conf;

namespace JoleYe.Web
{
    public class Register : Frontend
    {

        public Register()
        {
            WebConf conf = new WebConf();
            if (conf.getVal("userreg") == "1")
            {
                showMessage("×¢²á¹¦ÄÜÒÑ¾­¹Ø±Õ");
            }

            if (ISPOST)
            {
                MemberInfo info = new MemberInfo();
                info.username = pform("username");
                if (info.username == "")
                {
                    showMessage("ÓÃ»§Ãû²»ÄÜÎª¿Õ","javascript:history.back();");
                    return;
                }
                info.password = pform("pwd");
                if (info.password != pform("repwd"))
                {
                    showMessage("Á½´ÎÊäÈëµÄÃÜÂë²»Í¬", "javascript:history.back();");
                    return;
                }
                if (pform("sex") == "1")
                    info.sex = true;
                else
                    info.sex = false;

                info.truename = pform("truename");
                info.email = pform("email");
                if (info.email == "")
                {
                    showMessage("email²»ÄÜÎª¿Õ", "javascript:history.back();");
                    return;
                }
                info.telphone = pform("telphone");
                info.mobile = pform("mobile");
                info.qq = pform("qq");
                info.birth = pform("birth");
                info.ip = "ip";

                info.address = pform("address");
                PassportBll pb = new PassportBll();
                if (pb.register(info))
                {
                    string url = HttpContext.Current.Request.UrlReferrer.ToString();
                    die("<script type=\"text/javascript\">alert('×¢²á³É¹¦');location.href='" + url + "'</script>");
                }
                else
                    die("<script type=\"text/javascript\">alert('×¢²áÊ§°Ü');history.back();</script>");
            }
        }
    }
}
