zoukankan
html css js c++ java
NHibernate 做个小项目来试一下吧 六
BLL层也完成了,现在来做 界面吧,在添加一个新建ASP.Net Web应用程序的新建工程
现搞个 注册的页吧,
(图片上传上就成这个样子了
)
using
System;
using
System.Collections;
using
System.ComponentModel;
using
System.Data;
using
System.Drawing;
using
System.Web;
using
System.Web.SessionState;
using
System.Web.UI;
using
System.Web.UI.WebControls;
using
System.Web.UI.HtmlControls;
using
guestbook.BLL;
using
guestbook.Dal;
using
guestbook.data;
namespace
guestbook.web
{
/**/
///
<summary>
///
Register 的摘要说明。
///
</summary>
public
class
Register : System.Web.UI.Page
{
protected
System.Web.UI.WebControls.TextBox txtUserName;
protected
System.Web.UI.WebControls.TextBox txtEmail;
protected
System.Web.UI.WebControls.Button Button1;
protected
System.Web.UI.WebControls.RegularExpressionValidator RegularExpressionValidator1;
protected
System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator2;
protected
System.Web.UI.WebControls.RequiredFieldValidator valUN;
protected
System.Web.UI.WebControls.TextBox txtPwd;
private
void
Page_Load(
object
sender, System.EventArgs e)
{
//
在此处放置用户代码以初始化页面
}
Web 窗体设计器生成的代码
#region
Web 窗体设计器生成的代码
override
protected
void
OnInit(EventArgs e)
{
//
//
CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base
.OnInit(e);
}
/**/
///
<summary>
///
设计器支持所需的方法 - 不要使用代码编辑器修改
///
此方法的内容。
///
</summary>
private
void
InitializeComponent()
{
this
.Button1.Click
+=
new
System.EventHandler(
this
.Button1_Click);
this
.Load
+=
new
System.EventHandler(
this
.Page_Load);
}
#endregion
private
void
Button1_Click(
object
sender, System.EventArgs e)
{
if
(Page.IsValid)
{
string
username
=
txtUserName.Text;
string
Email
=
txtEmail.Text;
string
pwd
=
txtPwd.Text;
users newUser
=
new
users();
newUser.Name
=
username;
newUser.email
=
Email;
newUser.password
=
pwd;
if
(
!
CreateAccount(newUser))
{
valUN.ErrorMessage
=
"
用户名已被注册,请另选!
"
;
valUN.IsValid
=
false
;
}
}
}
private
bool
CreateAccount(users user)
{
try
{
usersbll bll
=
new
usersbll();
bll.UserAdd(user);
HttpContext.Current.Session[
"
AccountInfo
"
]
=
user;
HttpContext.Current.Response.Redirect(
"
Default.aspx
"
,
true
);
}
catch
{
return
false
;
}
return
true
;
}
}
}
这个过程 总体来说比较顺利,但是在最后测试的时候 碰到了一点点问题 ,就是一开始,怎么也插入不了数据,后来才想起来,没有把NHibernate的配置复制到 web.config中去,晕啊,太粗心了我
还有一个要注意的就是,
<
configSections
>
<
section
name
="nhibernate"
type
= "System.Configuration.NameValueSectionHandler,System,Version=1.0.3300.0,Culture=neutral, PublicKeyToken=b77a5c561934e089"
/>
</
configSections
>
上面这一节 一定要 放在 <configSection>标签下在, 放到其它位置 就会报错。OK继续
本
作品
由
平波
创作,采用
知识共享署名 2.5 中国大陆许可协议
进行许可。
查看全文
相关阅读:
牛客练习赛19 D-托米去购物
牛客练习赛19 托米的简单表示法
Codeforces Round #492 (Div. 2) [Thanks, uDebug!]
Codeforces Round #393 (Div. 2) (8VC Venture Cup 2017
Codeforces Round #393 (Div. 2) (8VC Venture Cup 2017
Codeforces Round #491 (Div. 2) E
I00018 生成全1数
I00017 生成9开头的按位递减数
I00017 生成9开头的按位递减数
HDU1042 n!
原文地址:https://www.cnblogs.com/9527/p/53047.html
最新文章
试卷批分pascal程序
字符序列pascal程序
装载问题
工作分配问题pascal程序
组合的输出pascal程序
骑士旅行pascal解题程序
Python 爬虫-图片的爬取
Python 爬虫-Robots协议
Python 爬虫-Requests库入门
Python XML
热门文章
Python BeautifulSoup的使用
Python 网络编程和Socket
机器学习 Matplotlib库入门
Python 正则表达式
监督学*--k*邻算法
Python string常用函数
bzoj 1497 最小割
Educational Codeforces Round 46 (Rated for Div. 2)
Codeforces Round #361 (Div. 2) D
牛客练习赛19 C-托米航空公司
Copyright © 2011-2022 走看看