遇见爱情遇见你 援交:步步为营 .NET三层架构解析 七、UI的设计(登陆页面、注册页页和添加部门页面)
来源:百度文库 编辑:九乡新闻网 时间:2024/10/06 02:02:02
步步为营 .NET三层架构解析 七、UI的设计(登陆页面、注册页页和添加部门页面)
2011-03-27 23:29byspring yang,2305visits,网摘,收藏,编辑在我们设计好了三层架构的SQLHelper、Model、DAL和BLL后,我们要开始来调用它设计好的功能了。
首先我们来设计Login.aspx,先看界面的设计:
"width: 100px; text-align: right"
>
帐户名:
"width: 100px"
>
"txtUserName"
runat=
"server"
>
"width: 100px; text-align: right"
>
密码:
"width: 100px"
>
"txtPassWord"
runat=
"server"
TextMode=
"Password"
>
"width: 100px"
>
"width: 100px"
>
"btnLogin"
runat=
"server"
OnClick=
"btnLogin_Click1"
Text=
"登陆"
/>
再来看Login.aspx.cs的设计:
记得加上这个:
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())
{
// 密码是经过MD5加密后保存到数据库的
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(
""
);
}
}
else
{
Response.Write(
""
);
}
}
private
void
SetSession(department Department,
string
DepartID)
{
if
(Department ==
null
||
string
.IsNullOrEmpty(DepartID))
{
Response.Write(
""
);
return
;
}
Session[
"Ename"
] = txtUserName.Text.Trim().ToString();
Session[
"Departid"
] = DepartID;
Session[
"Operater"
] =
""
;
if
(Department.departname ==
"控制中心"
)
{
Response.Write(
""
);
}
else
{
Response.Write(
""
);
}
}
接下来我们要在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
;
}
加入下面之个方法:
再来看下ADDdepart.aspx的设计:
"width: 100px"
>
部门名称:
"width: 100px"
>
"txtDepartmentName"
runat=
"server"
>
"width: 100px"
>
描述:
"width: 100px"
>
"txtDescription"
runat=
"server"
>
"width: 100px"
>
"width: 100px"
>
"btnAdd"
runat=
"server"
OnClick=
"btnAdd_Click"
Text=
"增加"
/>
ADDdepart.aspx.cs的设计:
//继承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(),
""
,
""
);
}
}
else
{
ClientScript.RegisterClientScriptBlock(
this
.GetType(),
""
,
""
);
}
}
}
再来看下注册页面Register.aspx的设计:
"width: 100px; text-align: right"
>
帐户名:
"width: 100px"
>
"txtUserName"
runat=
"server"
>
"width: 100px"
>
"width: 100px; text-align: right;"
>
姓名:
"width: 100px"
>
"txtName"
runat=
"server"
>
"width: 100px"
>
"width: 100px; text-align: right;"
>
年龄:
"width: 100px"
>
"txtAge"
runat=
"server"
>
"width: 100px"
>
"width: 100px; text-align: right;"
>
密码:
"width: 100px"
>
"txtPassWord"
runat=
"server"
TextMode=
"Password"
>
"width: 100px"
>
"CompareValidator1"
runat=
"server"
ControlToCompare=
"TextBox4"
ControlToValidate=
"TextBox5"
ErrorMessage=
"密码不一样"
>
"width: 100px; text-align: right;"
>
重复密码:
"width: 100px"
>
"txtConfirmPassWord"
runat=
"server"
TextMode=
"Password"
>
"width: 100px"
>
"width: 100px; text-align: right;"
>
部门:
"width: 100px"
>
"ddlDepartment"
runat=
"server"
>
"width: 100px"
>
"width: 100px"
>
"width: 100px"
>
"btnLogin"
runat=
"server"
OnClick=
"btnLogin_Click"
Text=
"注册"
/>
"width: 100px"
>
下面是Register.aspx.cs的设计:
protected
void
Page_Load(
object
sender, EventArgs e)
{
if
(!IsPostBack)
{
BinData();
}
}
public
void
BinData()
{
List Departmentlist =
new
List();
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(),
""
,
""
);
}
}
else
{
ClientScript.RegisterClientScriptBlock(
this
.GetType(),
""
,
""
);
}
}
以上只是UI简单的调用BLL的功能,下次再讲解下GridView调用BLL和GridView的分页,可能我设计的只是较简单,欢迎大家提出你们宝贵的意见.来共同提高.欢迎拍砖.
步步为营 .NET三层架构解析 七、UI的设计(登陆页面、注册页页和添加部门页面)
步步为营 .NET三层架构解析 一、什么是三层架构
如何自定义UCHome注册登陆退出的跳转页面
页面的架构
.NET三层架构解析一:什么是三层架构
添加页面
asp.net 的页面执行顺序 页面事件执行详解
asp.net页面指令和事件
30个登录/注册页面设计欣赏-设计之家
ASP.NET页面支持的指令
ASp.net?剖析三层架构
ASP.NET的页面——ASP.NET页面的生命周期
如何理解.Net的三层架构--51编程网
浅谈网络课程的页面设计
给z-blog文章页面模板single.html添加关键字和描述的
新浪微博注册页面的用户体验分析报告
网站架构(页面静态化,图片服务器分离,负载均衡)方案全解析
ASP.NET 定制简单的错误处理页面实现代码
ASP.NET教程之实现页面无刷新的方法
ASP.NET 2.0的页面缓存功能介绍
文档排版、页面设置和页面打印
word 页面设置和节的使用
网站页面的布局方式 首页设计的要点
30个极其迷人的flash载入页面的设计