using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Cn_Controls_UserRegisterPost : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    /// <summary>
    /// 注册
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnPost_Click(object sender, EventArgs e)
    {
        string UserName = txtUserName.Text;
        string UserPwd = txtUserPwd.Text;
        string UserPwd2 = txtUserPwd2.Text;

        if (string.IsNullOrEmpty(UserName))
        {
            SnSee.Tool.MessageTool.MessageBox(this.Page, "Please enter your name to be registered members of!");
            return;
        }

        if (string.IsNullOrEmpty(UserPwd) || string.IsNullOrEmpty(UserPwd2))
        {
            SnSee.Tool.MessageTool.MessageBox(this.Page, "Please enter your Login password!");
            return;
        }

        if (UserPwd != UserPwd2)
        {
            SnSee.Tool.MessageTool.MessageBox(this.Page, "Two different password, please check!");
            return;
        } 
        SnSee.Bean.UserBaseBean _UserBaseBeanCheck = (SnSee.Bean.UserBaseBean)SnSee.Factory.Factory.UserBase.Select("UserName='" + UserName + "'");
        if (_UserBaseBeanCheck != null)
        {
            SnSee.Tool.MessageTool.MessageBox(this.Page, "Current Member name already exists, use the other Member name!");
            return;
        } SnSee.Bean.UserBaseBean _UserBaseBean = new SnSee.Bean.UserBaseBean();
        _UserBaseBean.UserName = UserName;
        _UserBaseBean.UserPwd = SnSee.Module.User.User.SetUserPassword(UserPwd);
        _UserBaseBean.FullName = SnSee.Tool.EncodeTool.HtmlEncode(txtFullName.Text);
        _UserBaseBean.Gender = SnSee.Tool.ConvertTool.GetInt32(rbtnGender.SelectedValue);
        _UserBaseBean.CompanyName = SnSee.Tool.EncodeTool.HtmlEncode(txtCompanyName.Text);
        _UserBaseBean.Address = SnSee.Tool.EncodeTool.HtmlEncode(txtAddress.Text);
        _UserBaseBean.Tel = SnSee.Tool.EncodeTool.HtmlEncode(txtTel.Text);
        _UserBaseBean.Fax = SnSee.Tool.EncodeTool.HtmlEncode(txtFax.Text);
        _UserBaseBean.Email = SnSee.Tool.EncodeTool.HtmlEncode(txtEmail.Text);
        _UserBaseBean.State = 1;

        if (SnSee.Factory.Factory.UserBase.Insert(_UserBaseBean))
        {
            if (SnSee.Module.User.User.UserLogin(UserName, UserPwd, 720))
            {
                SnSee.Tool.MessageTool.MessageBox(this.Page, "registered members are welcome to join you!", "UserCenter.aspx");
            }
        }
    }
}
