The following is a three-tier architecture instance developed by the user registration system: the database base class uses the Code provided above.
1. Data Layer Development of the user registration module:
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)
{// Direct route connection string}
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. User Registration business layer development:
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. configurettings ["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. User Registration presentation layer development:
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. button#click );
This. Load + = new System. EventHandler (this. Page_Load );
}
# Endregion
Private void button#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 (); // the return value is output here.
}
}
}
4. stored procedure called by the system:
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)
This article from the CSDN blog, reproduced please indicate the source: http://blog.csdn.net/daban1/archive/2006/10/19/1341520.aspx