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;
using Fm.Bussiness;

public partial class member_register : System.Web.UI.Page
{
   
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.Form["username"] != null)
        {
            Response.ContentType = "text/html";
            Response.Write(GetUser(Request.Form["username"].ToString()));
            Response.Flush();
            Response.Close();
        }
        if (Request.Form["mail"] != null)
        {
            Response.ContentType = "text/html";
            Response.Write(GetMail(Request.Form["mail"].ToString()));
            Response.Flush();
            Response.Close();
        }
        if (Request.Form["u_name"] != null && Request.Form["u_pass"] != null)
        {
            Response.ContentType = "text/html";
          
         
           
                //将获取的密码进行加密
                string pass = FormsAuthentication.HashPasswordForStoringInConfigFile(Request.Form["u_pass"].ToString().Trim(), "MD5");
                //获取实体类
                Fm.EntityClass.User user = new Fm.EntityClass.User();
                user.u_name = Request.Form["u_name"].ToString().Trim();
                user.u_pass = pass;
                user.u_nc = Request.Form["nicheng"].ToString();
                user.u_mail = Request.Form["u_mail"].ToString().Trim();
                //实例化数据添加类
                sys_user_user sys = new sys_user_user();
                user.u_id = sys.sys_user_add(user);
                if (user.u_id > 0)
                {
                    //会员所属角色添加
                    Fm.EntityClass.Urcenter ur = new Fm.EntityClass.Urcenter();
                    ur.r_id = 2;
                    ur.u_id = user.u_id;
                    sys.sys_ur_add(ur);
                    Response.Write("1");
                }
                else
                {
                    Response.Write("-2");
                }

            //释放资源
            Response.Flush();
            Response.Close();
        }
    }
    string GetMail(string mail)
    {
        public_select ps = new public_select();
        DataView dv = ps.Getps("Fm_user", "u_mail", "u_mail='" + mail + "'");
        if (dv.Count > 0)
        {
            return "false";
        }
        else
        {
            return "true";
        }
    }
    //获取用户名
    string GetUser(string username)
    {
        public_select ps = new public_select();
        string str = "";
        DataView dv = ps.Getps("Fm_user","u_name","u_name='" + username + "'");
        if (dv.Count > 0)
        {
            str = "false";
        }
        else
        {
            str = "true";
        }
        return str;
    }
    //添加新会员
    void UserAdd()
    {
        Response.Write("asdfasd");
        //if (Session["CheckCode"].ToString() == authcode.Value)
        //{
        //    
        //    public_select ps = new public_select();
        //    //将获取的密码进行加密
        //    string pass = FormsAuthentication.HashPasswordForStoringInConfigFile(password.Value.Trim(), "MD5");
        //    //会员信息实体类
        //    //获取实体类
        //    Fm.Entity.User user = new Fm.Entity.User();
        //    user.u_name = username.Value.Trim();
        //    user.u_pass = pass;
        //    user.u_nc = nicheng.Value;
        //    user.u_mail = mail.Value.Trim();
        //    user.u_id = sys.sys_user_add(user);
        //    if (user.u_id > 0)
        //    {
        //        //会员所属角色添加
        //        Fm.Entity.Urcenter ur = new Fm.Entity.Urcenter();
        //        ur.r_id = 2;
        //        ur.u_id = user.u_id;
        //        if (sys.sys_ur_add(ur))
        //        {
        //            Response.Redirect("../Erro.aspx?eid=恭喜您,您已经注册成功!&url=login.aspx", false);
        //        }
        //    }
        //}
        //else
        //{
        //    Response.Write("<script>alert('请输入正确的验证码!');</script>");
        //}
    }
    protected void Button1_ServerClick(object sender, EventArgs e)
    {
       
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
       
    }
}
