.NET中三層構(gòu)架開發(fā)實例-用戶注冊系統(tǒng)
2024-07-10 13:11:50
供稿:網(wǎng)友
網(wǎng)站運營seo文章大全提供全面的站長運營經(jīng)驗及seo技術(shù)! 下面是用戶注冊系統(tǒng)開發(fā)的三層構(gòu)架實例:數(shù)據(jù)庫基類采用上面提供的代碼。
1、用戶注冊模塊數(shù)據(jù)層開發(fā):
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、用戶注冊商務(wù)層開發(fā):
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、 用戶注冊表示層開發(fā):
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、該系統(tǒng)調(diào)用的存儲過程:
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)