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 窗体设计器生成的代码

            
    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继续
  • 相关阅读:
    LR实战之Discuz开源论坛——安装及简介
    LR如何利用siteScope监控MySQL性能
    初学SSH(其一)
    使用JUnit单元测试入门
    理解java中【同步】和【死锁】
    LR性能测试应用
    (28)ElasticSearch分布式架构特点
    (27)ElasticSearch 复合查询
    (06)Gitlab设置开启自启动、关闭开机自启动
    (05)安装GitLab
  • 原文地址:https://www.cnblogs.com/9527/p/53047.html
Copyright © 2011-2022 走看看