After we have designed SQLHelper, Model, DAL, and BLL for the three-tier architecture, we have to call the functions it has designed.
First, let's design Login. aspx. First, let's look at the interface design:
View sourceprint? <Table>
<Tr>
<Td style = "width: 100px; text-align: right">
Account name: </td>
<Td style = "width: 100px">
<Asp: TextBox ID = "txtUserName" runat = "server"> </asp: TextBox> </td>
</Tr>
<Tr>
<Td style = "width: 100px; text-align: right">
Password: </td>
<Td style = "width: 100px">
<Asp: TextBox ID = "txtPassWord" runat = "server" TextMode = "Password"> </asp: TextBox> </td>
</Tr>
<Tr>
<Td style = "width: 100px">
</Td>
<Td style = "width: 100px">
<Asp: Button ID = "btnLogin" runat = "server" OnClick = "btnLogin_Click1" Text = "login"/> </td>
</Tr>
</Table>
Let's take a look at the design of Login. aspx. cs:
Remember to add this:
View sourceprint? Using BLL;
Using Model;
Then:
View sourceprint? Protected void Page_Load (object sender, EventArgs e)
{
}
Protected void btnLogin_Click1 (object sender, EventArgs e)
{
Custom Custom = new custom ();
CustomSystem CustomSystem = new customSystem ();
Custom = CustomSystem. GetSinglename (txtUserName. Text. Trim (). ToString ());
If (Custom. ename = txtUserName. Text. Trim (). ToString ())
{
// The password is saved to the database after MD5 Encryption
View sourceprint? If (Custom. password = FormsAuthentication. HashPasswordForStoringInConfigFile (txtPassWord. Text. Trim (). ToString (), "MD5 "))
{
Department Department = new department ();
DepartmentSystem DepartmentSystem = new departmentSystem ();
Department = DepartmentSystem. Getsingledepartment (Custom. departID );
SetSession (Department, Custom. departID. ToString ());
}
Else
{
Response. Write ("<script> alert (incorrect password); location. href = Login. aspx; </script> ");
}
}
Else
{
Response. Write ("<script> alert (account name does not exist); location. href = Login. aspx; </script> ");
}
}
Private void SetSession (department Department, string DepartID)
{
If (Department = null | string. IsNullOrEmpty (DepartID ))
{
Response. Write ("<script> alert (website operation error or you have not set the department information, please contact the Administrator.); location. href = Login. aspx; </script> ");
Return;
}
Session ["Ename"] = txtUserName. Text. Trim (). ToString ();
Session ["Departid"] = DepartID;
Session ["Operater"] = "";
If (Department. role name = "Control Center ")
{
Response. Write ("<script> alert (logon successful); location. href = Default. aspx; </script> ");
}
Else
{
Response. Write ("<script> alert (logon successful); location. href = Default2.aspx; </script> ");
}
}
Next, we will create PageBase. cs in the App_Code file.
View sourceprint? Public bool IsAdmin ()
{
If (Session ["Departid"]! = Null)
{
Department Department = new department ();
DepartmentSystem DepartmentSystem = new departmentSystem ();
Department = DepartmentSystem. Getsingledepartment (int. Parse (Session ["Departid"]. ToString ()));
If (Department. Partition name! = "Control Center ")
{
Response. Redirect ("/Web/Login. aspx ");
Response. End ();
Return false;
}
}
Else
{
Response. Redirect ("/Web/Login. aspx ");
Response. End ();
Return false;
}
Return true;
}
Add the following method:
Let's take a look at the design of ADDdepart. aspx:
View sourceprint? <Table>
<Tr>
<Td style = "width: 100px">
Department name: </td>
<Td style = "width: 100px">
<Asp: TextBox ID = "txtDepartmentName" runat = "server"> </asp: TextBox> </td>