【毕业设计】注册功能完成

嘿嘿,今天的进度明显要比昨天快一些。一个上午已经将注册功能完成了。

具体步骤如下:

在Login.aspx页面的表格中添加一个注册按钮

image

新建注册页面Regist.aspx

image

 

在注册页面后台修改代码

  1. using System;
  2. using System.Collections;
  3. using System.Configuration;
  4. using System.Data;
  5. using System.Linq;
  6. using System.Web;
  7. using System.Web.Security;
  8. using System.Web.UI;
  9. using System.Web.UI.HtmlControls;
  10. using System.Web.UI.WebControls;
  11. using System.Web.UI.WebControls.WebParts;
  12. using System.Xml.Linq;
  13. using Layer.BlogDesignEntities;
  14. using Layer.BlogDesignLogic.UserBLL;
  15.  
  16. public partial class Regist : System.Web.UI.Page
  17. {
  18.     protected void Page_Load(object sender, EventArgs e)
  19.     {
  20.  
  21.     }
  22.     protected void ButtonCancel_Click(object sender, EventArgs e)
  23.     {
  24.         Response.Redirect("Default.aspx");
  25.     }
  26.     protected void ButtonSubmit_Click(object sender, EventArgs e)
  27.     {
  28.         IUserBLL user = new UserBLL();
  29.         UserInfo userInfo = new UserInfo();
  30.  
  31.         userInfo.UserName = TextBoxUserName.Text;
  32.         userInfo.PassWord = TextBoxPassWord.Text;
  33.         userInfo.UserMail = TextBoxEmail.Text;
  34.         userInfo.UserRight = 0;
  35.  
  36.         if (user.CreatUser(userInfo))
  37.         {
  38.             Response.Write("注册成功!");
  39.         }
  40.         else
  41.         {
  42.             Response.Write("注册失败!");
  43.         }
  44.     }
  45. }

在用户数据层中添加创建用户方法

接口

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Layer.BlogDesignEntities;
  6.  
  7. namespace Layer.BlogDesignDataAccess.UserDAL
  8. {
  9.     /// <summary>
  10.     /// 用户实体数据层接口
  11.     /// </summary>
  12.     public interface IUserDAL
  13.     {
  14.         /// <summary>
  15.         /// 获取用户信息
  16.         /// </summary>
  17.         /// <param name="uid">用户名称</param>
  18.         /// <returns>用户信息</returns>
  19.         UserInfo getUserInfo(string userName);
  20.  
  21.         /// <summary>
  22.         /// 添加用户
  23.         /// </summary>
  24.         /// <param name="userInfo">用户信息</param>
  25.         void creatUser(UserInfo useInfo);
  26.  
  27.         
  28.     }
  29. }

实现

  1.  
  2. void IUserDAL.creatUser(UserInfo userInfo)
  3. {
  4.     string strCmd = "insert into Users(PassWord,UserName,UserMail,UserRight) values(@PassWord,@UserName,@UserMail,@UserRight)";
  5.  
  6.     conn = new SqlConnection(strConn);
  7.  
  8.     conn.Open();
  9.     cmd = conn.CreateCommand();
  10.     cmd.CommandText=strCmd;
  11.  
  12.     SqlParameter p;
  13.     object val;
  14.  
  15.  
  16.     val = userInfo.PassWord;
  17.     p = new SqlParameter("@PassWord", SqlDbType.Char, 20);
  18.     p.Direction = ParameterDirection.Input;
  19.     p.Value = val;
  20.     cmd.Parameters.Add(p);
  21.  
  22.     val = userInfo.UserName;
  23.     p = new SqlParameter("@UserName", SqlDbType.Char, 20);
  24.     p.Direction = ParameterDirection.Input;
  25.     p.Value = val;
  26.     cmd.Parameters.Add(p);
  27.  
  28.     val = userInfo.UserMail;
  29.     p = new SqlParameter("@UserMail", SqlDbType.Char, 50);
  30.     p.Direction = ParameterDirection.Input;
  31.     p.Value = val;
  32.     cmd.Parameters.Add(p);
  33.  
  34.     val = userInfo.UserRight;
  35.     p = new SqlParameter("@UserRight", SqlDbType.Int);
  36.     p.Direction = ParameterDirection.Input;
  37.     p.Value = val;
  38.     cmd.Parameters.Add(p);
  39.  
  40.     cmd.Connection = conn;
  41.     cmd.ExecuteNonQuery();
  42. }

 

在用户逻辑层添加创建用户方法

接口

  1. /// <summary>
  2. /// 创建用户
  3. /// </summary>
  4. /// <param name="Use">欲用户信息</param>
  5. /// <returns>创建是否成功呢</returns>
  6. bool CreatUser(UserInfo Use);
  7.  
  8.  
  9. /// <summary>
  10. /// 检查注册信息是否重复
  11. /// </summary>
  12. /// <param name="Use">注册信息</param>
  13. /// <returns>是否重复</returns>
  14. bool creatUserCheck(UserInfo Use);

方法

  1. bool IUserBLL.CreatUser(UserInfo Use)
  2.       {
  3.  
  4.           IUserBLL UserB = new UserBLL();
  5.           IUserDAL User = new UserDAL();
  6.           if (Use.UserName.Trim().Equals(" "))
  7.           {
  8.               return false;
  9.           }
  10.           else
  11.           {
  12.               if (Use.PassWord.Trim().Equals(" "))
  13.               {
  14.                   return false;
  15.               }
  16.               else
  17.               {
  18.                   if (UserB.creatUserCheck(Use))
  19.                   {
  20.                       User.creatUser(Use);
  21.                       return true;
  22.                   }
  23.                   else
  24.                   {
  25.                       return false;
  26.                   }
  27.               }
  28.           }
  29.       }
  30.  
  31.       bool IUserBLL.creatUserCheck(UserInfo Use)
  32.       {
  33.  
  34.           IUserDAL User = new UserDAL();
  35.           UserInfo ue = new UserInfo();
  36.           ue = User.getUserInfo(Use.UserName);
  37.           if ((int)ue.UserId==0)
  38.           {
  39.               return true;
  40.           }
  41.           else
  42.           {
  43.               return false;
  44.           }
  45.       }

 

运行结果

image

image

posted @ 2010-04-13 12:33  Margin22  阅读(310)  评论(0编辑  收藏  举报