【毕业设计】注册功能完成
嘿嘿,今天的进度明显要比昨天快一些。一个上午已经将注册功能完成了。
具体步骤如下:
在Login.aspx页面的表格中添加一个注册按钮
新建注册页面Regist.aspx
在注册页面后台修改代码
- using System;
- using System.Collections;
- using System.Configuration;
- using System.Data;
- using System.Linq;
- using System.Web;
- using System.Web.Security;
- using System.Web.UI;
- using System.Web.UI.HtmlControls;
- using System.Web.UI.WebControls;
- using System.Web.UI.WebControls.WebParts;
- using System.Xml.Linq;
- using Layer.BlogDesignEntities;
- using Layer.BlogDesignLogic.UserBLL;
- public partial class Regist : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- }
- protected void ButtonCancel_Click(object sender, EventArgs e)
- {
- Response.Redirect("Default.aspx");
- }
- protected void ButtonSubmit_Click(object sender, EventArgs e)
- {
- IUserBLL user = new UserBLL();
- UserInfo userInfo = new UserInfo();
- userInfo.UserName = TextBoxUserName.Text;
- userInfo.PassWord = TextBoxPassWord.Text;
- userInfo.UserMail = TextBoxEmail.Text;
- userInfo.UserRight = 0;
- if (user.CreatUser(userInfo))
- {
- Response.Write("注册成功!");
- }
- else
- {
- Response.Write("注册失败!");
- }
- }
- }
在用户数据层中添加创建用户方法
接口
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using Layer.BlogDesignEntities;
- namespace Layer.BlogDesignDataAccess.UserDAL
- {
- /// <summary>
- /// 用户实体数据层接口
- /// </summary>
- public interface IUserDAL
- {
- /// <summary>
- /// 获取用户信息
- /// </summary>
- /// <param name="uid">用户名称</param>
- /// <returns>用户信息</returns>
- UserInfo getUserInfo(string userName);
- /// <summary>
- /// 添加用户
- /// </summary>
- /// <param name="userInfo">用户信息</param>
- void creatUser(UserInfo useInfo);
- }
- }
实现
- void IUserDAL.creatUser(UserInfo userInfo)
- {
- string strCmd = "insert into Users(PassWord,UserName,UserMail,UserRight) values(@PassWord,@UserName,@UserMail,@UserRight)";
- conn = new SqlConnection(strConn);
- conn.Open();
- cmd = conn.CreateCommand();
- cmd.CommandText=strCmd;
- SqlParameter p;
- object val;
- val = userInfo.PassWord;
- p = new SqlParameter("@PassWord", SqlDbType.Char, 20);
- p.Direction = ParameterDirection.Input;
- p.Value = val;
- cmd.Parameters.Add(p);
- val = userInfo.UserName;
- p = new SqlParameter("@UserName", SqlDbType.Char, 20);
- p.Direction = ParameterDirection.Input;
- p.Value = val;
- cmd.Parameters.Add(p);
- val = userInfo.UserMail;
- p = new SqlParameter("@UserMail", SqlDbType.Char, 50);
- p.Direction = ParameterDirection.Input;
- p.Value = val;
- cmd.Parameters.Add(p);
- val = userInfo.UserRight;
- p = new SqlParameter("@UserRight", SqlDbType.Int);
- p.Direction = ParameterDirection.Input;
- p.Value = val;
- cmd.Parameters.Add(p);
- cmd.Connection = conn;
- cmd.ExecuteNonQuery();
- }
在用户逻辑层添加创建用户方法
接口
- /// <summary>
- /// 创建用户
- /// </summary>
- /// <param name="Use">欲用户信息</param>
- /// <returns>创建是否成功呢</returns>
- bool CreatUser(UserInfo Use);
- /// <summary>
- /// 检查注册信息是否重复
- /// </summary>
- /// <param name="Use">注册信息</param>
- /// <returns>是否重复</returns>
- bool creatUserCheck(UserInfo Use);
方法
- bool IUserBLL.CreatUser(UserInfo Use)
- {
- IUserBLL UserB = new UserBLL();
- IUserDAL User = new UserDAL();
- if (Use.UserName.Trim().Equals(" "))
- {
- return false;
- }
- else
- {
- if (Use.PassWord.Trim().Equals(" "))
- {
- return false;
- }
- else
- {
- if (UserB.creatUserCheck(Use))
- {
- User.creatUser(Use);
- return true;
- }
- else
- {
- return false;
- }
- }
- }
- }
- bool IUserBLL.creatUserCheck(UserInfo Use)
- {
- IUserDAL User = new UserDAL();
- UserInfo ue = new UserInfo();
- ue = User.getUserInfo(Use.UserName);
- if ((int)ue.UserId==0)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
运行结果
本文来自博客园,作者:Margin22,转载请注明原文链接:https://www.cnblogs.com/skyler/archive/2010/04/13/1710997.html
.Net Core QQ群:26555711