日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程语言 > asp.net >内容正文

asp.net

步步为营 .NET三层架构解析 七、UI的设计(登陆页面、注册页页和添加部门页面)...

發(fā)布時(shí)間:2025/3/17 asp.net 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 步步为营 .NET三层架构解析 七、UI的设计(登陆页面、注册页页和添加部门页面)... 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

在我們?cè)O(shè)計(jì)好了三層架構(gòu)的SQLHelper、Model、DAL和BLL后,我們要開(kāi)始來(lái)調(diào)用它設(shè)計(jì)好的功能了。

首先我們來(lái)設(shè)計(jì)Login.aspx,先看界面的設(shè)計(jì):

<table><tr><td style="width: 100px; text-align: right">帳戶名:</td><td style="width: 100px"><asp:TextBox ID="txtUserName" runat="server"></asp:TextBox></td></tr><tr><td style="width: 100px; text-align: right">密碼:</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="登陸" /></td></tr></table>

再來(lái)看Login.aspx.cs的設(shè)計(jì):

記得加上這個(gè):

using BLL; using Model;

而后才是:

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()){// 密碼是經(jīng)過(guò)MD5加密后保存到數(shù)據(jù)庫(kù)的 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('密碼錯(cuò)誤');location.href='Login.aspx';</script>");}}else{Response.Write("<script>alert('帳戶名不存在');location.href='Login.aspx';</script>");}}private void SetSession(department Department,string DepartID){if (Department == null || string.IsNullOrEmpty(DepartID)){Response.Write("<script>alert('網(wǎng)站運(yùn)行錯(cuò)誤或你沒(méi)設(shè)置部門信息,請(qǐng)聯(lián)系管理員.');location.href='Login.aspx';</script>");return;}Session["Ename"] = txtUserName.Text.Trim().ToString();Session["Departid"] = DepartID;Session["Operater"] = "";if (Department.departname == "控制中心"){Response.Write("<script>alert('登錄成功');location.href='Default.aspx';</script>");}else{Response.Write("<script>alert('登錄成功');location.href='Default2.aspx';</script>");}}

接下來(lái)我們要在App_Code文件下新建PageBase.cs

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.departname != "控制中心"){Response.Redirect("/Web/Login.aspx");Response.End();return false;}}else{Response.Redirect("/Web/Login.aspx");Response.End();return false;}return true;}

加入下面之個(gè)方法:

再來(lái)看下ADDdepart.aspx的設(shè)計(jì):

<table><tr><td style="width: 100px">部門名稱:</td><td style="width: 100px"><asp:TextBox ID="txtDepartmentName" runat="server"></asp:TextBox></td></tr><tr><td style="width: 100px">描述:</td><td style="width: 100px"><asp:TextBox ID="txtDescription" runat="server"></asp:TextBox></td></tr><tr><td style="width: 100px"></td><td style="width: 100px"><asp:Button ID="btnAdd" runat="server" OnClick="btnAdd_Click" Text="增加" /></td></tr></table>

ADDdepart.aspx.cs的設(shè)計(jì):

//繼承PageBase類 public partial class ADDdepart : PageBase {protected void Page_Load(object sender, EventArgs e){if (!Page.IsPostBack){IsAdmin();}}protected void btnAdd_Click(object sender, EventArgs e){department Department = new department();department Departmenter = new department();departmentSystem DepartmentSystem = new departmentSystem();Department.departname = txtDepartmentName.Text.Trim();Department.description = txtDescription.Text.Trim();Departmenter = DepartmentSystem.Getdepartmenter(txtDepartmentName.Text.Trim());if (Departmenter.id <= 0){if (DepartmentSystem.Adddepartment(Department) >= 1){ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script>alert('恭喜您,部門添加成功!');</script>");}}else{ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script>alert('您填的部門己存在,請(qǐng)更改!');</script>");}} }

再來(lái)看下注冊(cè)頁(yè)面Register.aspx的設(shè)計(jì):

<table><tr><td style="width: 100px; text-align: right">帳戶名:</td><td style="width: 100px"><asp:TextBox ID="txtUserName" runat="server"></asp:TextBox></td><td style="width: 100px"></td></tr><tr><td style="width: 100px; text-align: right;">姓名:</td><td style="width: 100px"><asp:TextBox ID="txtName" runat="server"></asp:TextBox></td><td style="width: 100px"></td></tr><tr><td style="width: 100px; text-align: right;">年齡:</td><td style="width: 100px"><asp:TextBox ID="txtAge" runat="server"></asp:TextBox></td><td style="width: 100px"></td></tr><tr><td style="width: 100px; text-align: right;">密碼:</td><td style="width: 100px"><asp:TextBox ID="txtPassWord" runat="server" TextMode="Password"></asp:TextBox></td><td style="width: 100px"><asp:CompareValidator ID="CompareValidator1" runat="server" ControlToCompare="TextBox4"ControlToValidate="TextBox5" ErrorMessage="密碼不一樣"></asp:CompareValidator></td></tr><tr><td style="width: 100px; text-align: right;">重復(fù)密碼:</td><td style="width: 100px"><asp:TextBox ID="txtConfirmPassWord" runat="server" TextMode="Password"></asp:TextBox></td><td style="width: 100px"></td></tr><tr><td style="width: 100px; text-align: right;">部門:</td><td style="width: 100px"><asp:DropDownList ID="ddlDepartment" runat="server"></asp:DropDownList></td><td style="width: 100px"></td></tr><tr><td style="width: 100px"></td><td style="width: 100px"><asp:Button ID="btnLogin" runat="server" OnClick="btnLogin_Click" Text="注冊(cè)" /></td><td style="width: 100px"></td></tr></table>

下面是Register.aspx.cs的設(shè)計(jì):

protected void Page_Load(object sender, EventArgs e){if (!IsPostBack){ BinData();}}public void BinData(){List<department> Departmentlist = new List<department>();departmentSystem DepartmentSystem = new departmentSystem();Departmentlist = DepartmentSystem.GetDepartment();ddlDepartment.DataSource = Departmentlist;ddlDepartment.DataTextField = "departname";ddlDepartment.DataValueField = "id";ddlDepartment.DataBind();}protected void btnLogin_Click(object sender, EventArgs e){custom Custom = new custom();customSystem CustomSystem = new customSystem();custom Customn = new custom();Customn = CustomSystem.GetSinglename(txtUserName.Text.Trim());if (Customn.id <= 0){Custom.ename = txtUserName.Text.Trim();Custom.cname = txtName.Text.Trim();Custom.age = Convert.ToInt32(txtAge.Text.Trim());Custom.password = FormsAuthentication.HashPasswordForStoringInConfigFile(txtPassWord.Text.Trim(), "MD5");Custom.departID = int.Parse(ddlDepartment.SelectedValue);if (CustomSystem.customADD(Custom) >= 1){ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script>alert('恭喜您,帳號(hào)添加成功!');</script>");}}else{ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script>alert('你輸入的帳戶名己存在,請(qǐng)更改!');</script>");}}

以上只是UI簡(jiǎn)單的調(diào)用BLL的功能,下次再講解下GridView調(diào)用BLL和GridView的分頁(yè),可能我設(shè)計(jì)的只是較簡(jiǎn)單,歡迎大家提出你們寶貴的意見(jiàn).來(lái)共同提高.歡迎拍磚.

轉(zhuǎn)載于:https://www.cnblogs.com/springyangwc/archive/2011/03/27/1997314.html

總結(jié)

以上是生活随笔為你收集整理的步步为营 .NET三层架构解析 七、UI的设计(登陆页面、注册页页和添加部门页面)...的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。