private void btnreg_Click(object sender, EventArgs e)
        {
            UserInfo userNew = new UserInfo();
            userNew.UserName = txtName.Text;

            userNew.UserPwd =Encryption(txtPsw.Text);
            userNew.UserPhone = txtPho.Text;
            userNew.Flag = 0;
            userNew.UserDelFlag = 0;
            //给UserAccount赋值 由于UserAccount不能设置为自动增长,随机数又的检测重复,所以我再次只获取用户的数量,根据用户数量给用户设置登录账号
            UserInfoBLL userBLL = new UserInfoBLL();
            int userCount = userBLL.GetUserCountByUserDelFlag(0);
            userNew.UserAccount = GetUserAccountByUserCount(userCount);
            int msg = userBLL.InsertUserInfo(userNew);//1成功   0失败
            //查看是否注册成功 成功:给用户返回登录账号,关闭注册窗体   失败:显示直接停留在注册窗体
            if (msg==1)
            {
                MessageBox.Show("注册成功,请牢记您的登录账号:" + userNew.UserAccount);
                this.Close();
            }
            else
            {
                MessageBox.Show("注册失败,请重新注册");
                txtName.Text = "";
                txtPho.Text = "";
                txtPsw.Text = "";
            }
        }
 /// <summary>
 /// 获取没有被删除的用户
 /// </summary>
 /// <param name="delFlag">删除标识</param>
 /// <returns>UserInfo集合</returns>
 public List<UserInfo> GetUserInfoByDelFlag(int delFlag)
 {
     string sql = "select UserId,UserName from UserInfo where  UserDelFlag=@UserDelFlag";
     OleDbDataReader odr = SqlHelper.ExecuteReader(sql, new OleDbParameter("@UserDelFlag", delFlag));
     List<UserInfo> list = new List<UserInfo>();
     if (odr.HasRows)
     {
         while (odr.Read())
         {
             UserInfo user = new UserInfo();
             user.UserId = Convert.ToInt32(odr["UserId"]);
             user.UserName = odr["UserName"].ToString();
             list.Add(user);
         }
     }
     return list;
 }
 //UserId,UserAccount,UserName,UserPwd,UserFlag,UserDelFlag,UserPhone
 /// <summary>
 /// 根据用户名跟用户标识从数据库中查询密码
 /// </summary>
 /// <param name="userName">用户名</param>
 /// <param name="flag">用户标识   0为普通用户    1管理员</param>
 /// <returns>UserInfo对象</returns>
 public UserInfo GetUserInfoByUserAccount(string UserAccount, int flag)
 {
     string sql = "select UserPwd,UserId,UserName from UserInfo where UserAccount=@UserAccount and UserFlag=@UserFlag and UserDelFlag=0";
     OleDbParameter[] param = {
                              new OleDbParameter("@UserAccount",UserAccount),
                              new OleDbParameter ("@UserFlag",flag)
                              };
     OleDbDataReader odr= SqlHelper.ExecuteReader(sql, param);
     UserInfo user = new UserInfo();
     if (odr.HasRows)
     {
         while (odr.Read())
         {
             user.UserId = Convert.ToInt32(odr["UserId"]);
             user.UserPwd = odr["UserPwd"].ToString();
             user.UserName = odr["UserName"].ToString();
         }
     }
     return user;
 }
 /// <summary>
 /// 注册用户事件
 /// </summary>
 /// <param name="user">要注册用户的信息</param>
 /// <returns>注册结果 1成功   0失败</returns>
 public int InsertUserInfo(UserInfo user)
 {
     return userDAL.InsertUserInfo(user);
 }
        /// <summary>
        /// 注册用户事件
        /// </summary>
        /// <param name="user">要注册用户的信息</param>
        /// <returns>受影响的行数</returns>
        public int InsertUserInfo(UserInfo user)
        {
            string sql = "insert into userinfo (UserAccount,UserName,UserPwd,UserFlag,UserDelFlag,UserPhone) values (@UserAccount,@UserName,@UserPwd,@UserFlag,@UserDelFlag,@UserPhone)";
            OleDbParameter[] param = {
                                     new OleDbParameter("@UserAccount",user.UserAccount),
                                     new OleDbParameter("@UserName",user.UserName),
                                     new OleDbParameter("@UserPwd",user.UserPwd),
                                     new OleDbParameter("@UserFlag",user.Flag),
                                     new OleDbParameter("@UserDelFlag",user.UserDelFlag),

                                     new OleDbParameter("@UserPhone",user.UserPhone)

                                     };
            return SqlHelper.ExecuteNonQuery(sql, param);
        }