.NET中三层构架开发实例-用户注册系统
2024-07-10 13:11:50
供稿:网友
网站运营seo文章大全提供全面的站长运营经验及seo技术! 下面是用户注册系统开发的三层构架实例:数据库基类采用上面提供的代码。
1、用户注册模块数据层开发:
using system;
using system.data;
using system.data.sqlclient;
using haisky.htjob;
using system.xml;
namespace haisky.htjob.accounts.accountsdata
{
public class user : haisky.htjob.haiskydbobject
{
public user(string newconnectionstring) : base(newconnectionstring)
{//直接路由连接字符串}
public int create(string user_nm,string user_pwd)
{
int rowsaffected;
sqlparameter[] parameters = {new sqlparameter("@user_nm",sqldbtype.char,16),
new
sqlparameter("@user_pwd",sqldbtype.char,16)};
parameters[0].value = user_nm;
parameters[1].value = user_pwd;
parameters[2].direction = parameterdirection.output;
try
{
runprocedure("if_user_info",parameters,out rowsaffected);
}
catch
{ }
return (int)parameters[2].value;
}
}
}
2、用户注册商务层开发:
using system;
using system.configuration;
using haisky.htjob.accounts.accountsdata;
namespace haisky.htjob.accounts.accountbusiness
{
public class user : haisky.htjob.haiskybizobject
{
int userid;
string username;
string userpwd;
string strconn;
public user()
{
strconn = configurationsettings.appsettings["strconn"];
}
public int careate()
{
accountsdata.user datauser = new accountsdata.user(strconn);
userid = datauser.create(username,userpwd);
return userid;
}
public int userid
{
get
{
return userid;
}
set
{
userid = value;
}
}
public string username
{
get
{
return username;
}
set
{
username = value;
}
}
public string userpwd
{
get
{
return userpwd;
}
set
{
userpwd = value;
}
}
}
}
3、 用户注册表示层开发:
using system;
using system.collections;
using system.componentmodel;
using system.data;
using system.drawing;
using system.web;
using system.web.sessionstate;
using system.web.ui;
using system.web.ui.webcontrols;
using system.web.ui.htmlcontrols;
using haisky.htjob.accounts.accountbusiness;
namespace haisky.htjob.modules.accounts
{
public class register : system.web.ui.page
{
protected system.web.ui.webcontrols.textbox textbox1;
protected system.web.ui.webcontrols.textbox textbox2;
protected system.web.ui.webcontrols.table table1;
protected system.web.ui.webcontrols.button button1;
private void page_load(object sender, system.eventargs e)
{
table1.rows[0].cells[0].visible = false;
}
#region web form designer generated code
override protected void oninit(eventargs e)
{
initializecomponent();
base.oninit(e);
}
private void initializecomponent()
{
this.button1.click += new system.eventhandler(this.button1_click);
this.load += new system.eventhandler(this.page_load);
}
#endregion
private void button1_click(object sender, system.eventargs e)
{
int i;
htjob.accounts.accountbusiness.user businessuser = new htjob.accounts.accountbusiness.user();
businessuser.username = textbox1.text;
businessuser.userpwd = textbox2.text;
i = businessuser.careate();
response.write (i.tostring()); //这里输出返回值
}
}
}
4、该系统调用的存储过程:
create procedure if_user_info
(@user_nm char(16),@user_pwd char(16),@user_id int output)
as
insert user_info(user_nm,user_pwd) values(@user_nm,@user_pwd)
set @user_id = @@identity
if @@error > 0
begin
raiserror ('insert of article failed', 16, 1)