First, set up the shelf, as shown in figure
650) this. width = 650; "border =" 0 "alt =" "src =" http://www.bkjia.com/uploads/allimg/131228/1644595061-0.jpg "/>
Next, write the data at a layer. First, write the data at the model layer. For example:
Public class User
{
Private string userId;
Public string UserId
{
Get {return userId ;}
Set {userId = value ;}
}
Private string userPwd;
Public string UserPwd
{
Get {return userPwd ;}
Set {userPwd = value ;}
}
Private string userName;
Public string UserName
{
Get {return userName ;}
Set {userName = value ;}
}
Private string userSex;
Public string UserSex
{
Get {return userSex ;}
Set {userSex = value ;}
}
Private string userTel;
Public string UserTel
{
Get {return userTel ;}
Set {userTel = value ;}
}
Private string userAddress;
Public string UserAddress
{
Get {return userAddress ;}
Set {userAddress = value ;}
}
Private string userEmail;
Public string UserEmail
{
Get {return userEmail ;}
Set {userEmail = value ;}
}
Private string userImg;
Public string UserImg
{
Get {return userImg ;}
Set {userImg = value ;}
}
}
Then there is the data link layer, for example:
Public class User_DAL
{Public object CheckLogin (User user, string right)
{
String sqlText;
If (right = "Administrator ")
{
SqlText = "select userPwd from user_tb where userId = @ userId ";
}
Else if (right = "department manager ")
{
SqlText = "select empPwd from Employee_tb where empId = @ userId and empType = 'department manager '";
}
Else if (right = "CR employee ")
{
SqlText = "select empPwd from Employee_tb where empId = @ userId and empType = 'cr employees '";
}
Else if (right = "driver ")
{
SqlText = "select empPwd from Employee_tb where empId = @ userId and empType = 'drivers '";
}
Else if (right = "Operation employee ")
{
SqlText = "select empPwd from Employee_tb where empId = @ userId and empType = 'employee operation '";
}
Else
{
SqlText = "select cusPwd from Customer_tb where cusId = @ userId ";
}
SqlParameter [] paras = new SqlParameter [1]
{
New SqlParameter ("userId", user. UserId)
};
Object obj = SqlLink. GetScaler (sqlText, paras );
Return obj;
}
}
Then there is the business logic layer; for example:
Public class User_BLL
{
User_DAL userdal = new User_DAL ();
Public int CheckLogin (User user, string right)
{
Object obj = userdal. CheckLogin (user, right );
Int result =-1;
If (obj = null)
{
Result = 0; // the user does not exist.
}
Else if (obj. ToString (). Trim () = user. UserPwd)
{
Result = 1; // correct
}
Else if (obj. ToString (). Trim ()! = User. UserPwd)
{
Result = 2; // incorrect password
}
Else
{
Result = 3; // System Error
}
Return result;
}
}
The presentation layer. For example:
Protected void BtnLogin_Click (object sender, EventArgs e)
{
Try
{
// Verify Logon
If (txtUserId. Text = "" | txtUserPwd. Text = "")
{
Response. Write ("<script> alert ('user name or password cannot be blank ') </script> ");
Return;
}
String userId = txtUserId. Text. Trim ();
String userPwd = txtUserPwd. Text. Trim ();
String right = cobRight. Text. Trim ();
User. UserId = userId. Trim ();
User. UserPwd = userPwd. Trim ();
Int I = userbll. CheckLogin (user, right );
If (I = 0)
{
Response. Write ("<script> alert ('user name does not exist') </script> ");
}
Else if (I = 1)
{
Session ["userId"] = txtUserId. Text;
Session ["userPwd"] = txtUserPwd. Text;
Server. Transfer ("Index. aspx ");
}
Else if (I = 2)
{
Response. Write ("<script> alert ('wrong password') </script> ");
}
Else if (I = 3)
{
Response. Write ("<script> alert ('System error') </script> ");
}
}
Catch (Exception ex)
{
Response. Write (ex. Message );
}
The presentation layer only writes the method, because you need to change the name as needed. If necessary, please leave a message.
This article from the "Love-JS" blog, please be sure to keep this source http://leileiaijishu.blog.51cto.com/6286126/1090948