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 MySql.Data.MySqlClient;

public partial class Step2Class : Page
    {
		MysqlHelp mh = null;
		string createTableSQL = "";
			
		protected void Page_Load(object sender, EventArgs e)
        {
		
        }
		
		protected void btnAdd_Click(object sender, EventArgs e)
        {
			///获取用户输入的账号：
			string txtLoginNameValue = this.txtLoginName.Text.Replace("'", "");
			if(txtLoginNameValue.Length>20)txtLoginNameValue = this.txtLoginName.Text.Substring(0,20);
			///获取用户输入的保密码：
			string txtLoginPWDValue = this.txtLoginPWD.Text.Replace("'", "");
			if(txtLoginPWDValue.Length>8)txtLoginPWDValue = this.txtLoginPWD.Text.Substring(0,8);
			///获取用户输入的确认密码：
			string txtLoginPWDAgainValue = this.txtLoginPWDAgain.Text.Replace("'", "");
			if(txtLoginPWDAgainValue.Length>8)txtLoginPWDAgainValue = this.txtLoginPWDAgain.Text.Substring(0,8);
			
			if (txtLoginNameValue!="" && txtLoginPWDValue!=""){///判断用户输入的是否为空用户名和密码
				if ( txtLoginPWDValue== txtLoginPWDAgainValue)///如果用户输入的密码和确认密码相同
				{
					///创建数据连接对象：
					MysqlHelp mh = new MysqlHelp();
					///查询数据库，主要检测用户名是否已经存在
					DataTable dt=new DataTable();
					MySqlParameter[] quryParms  = {new MySqlParameter("?Name",MySqlDbType.VarChar,20)};
					quryParms[0].Value = ""+txtLoginNameValue;
					dt = mh.GetDatabysql("Select * From Users4DeepSoon Where Name=?Name",quryParms);
				
					///如果数据库查询到了记录，说明用户名已经存在了
					if (dt.Rows.Count>0){
						this.labelAddInfor.Text = "您输入的用户名已经存在!";
					}
					else {
						///利用MD5进行加密：
						string MD5PWD=System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(txtLoginPWDValue,"MD5");
						///添加新账户：
						MySqlParameter[] addParms ={new MySqlParameter("?Name",MySqlDbType.VarChar,20),new MySqlParameter("?PWD",MySqlDbType.VarChar,32)};
						addParms[0].Value = ""+txtLoginNameValue;
						addParms[1].Value = ""+MD5PWD;
						mh.Runsql("Insert Into Users4DeepSoon(Name,PWD) Values (?Name,?PWD)", addParms);
						///管理账户添加成功，跳转到下一步：
						Response.Redirect("step3.aspx");
					}
				
				}
				else
				{
					this.labelAddInfor.Text="你输入的前后密码不一致";
				}
			}//end 判断是否账户名和密码为空
			else
			{
				this.labelAddInfor.Text="账户名和密码不允许为空!";
			}	
		}///end btnAdd_Click()
		
    }