Step by step. NET three-tier Architecture Analysis 7. UI design (login page, registration page, and add Department page)

Source: Internet
Author: User

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>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.