petshop3 三层 结构分析

上传人:小** 文档编号:89126509 上传时间:2019-05-19 格式:DOC 页数:11 大小:29KB
返回 下载 相关 举报
petshop3  三层 结构分析_第1页
第1页 / 共11页
petshop3  三层 结构分析_第2页
第2页 / 共11页
petshop3  三层 结构分析_第3页
第3页 / 共11页
petshop3  三层 结构分析_第4页
第4页 / 共11页
petshop3  三层 结构分析_第5页
第5页 / 共11页
点击查看更多>>
资源描述

《petshop3 三层 结构分析》由会员分享,可在线阅读,更多相关《petshop3 三层 结构分析(11页珍藏版)》请在金锄头文库上搜索。

1、PetShop3 三层结构分析这是一个信息管理项目,实际管理内容就不说了根据PetShop3.0的框架:Web层只依赖于BLL和Model,也就是说web层调用BLL层方法返回的Model层定义的数据;BLL层依赖于IDAL,Model,这一层实际是使用IDAL中的方法组合为业务,并处理IDAL层返回的Model;IDAL定义了所有底层方法,给DAL层留下接口;Model定义了对象实体,只有属性没有方法,基本上可以作为抽象类定义。DALFactory的作用是根据配置文件中的设置动态取出取出数据访问层(DataAccessLayer)对象的实例,这样做就把实际使用的DAL跟BLL层分离,如果需要

2、切换到其他DAL,只要修改此层就可以了。本项目使用NH(NHibernate)作为DAl,所以命名为NHDAL。NHDAL依赖于Model,继承Model中属性的定义,并添加了NH需要用到的属性器。同时NHDAL实现IDAL中定义的方法。下面是对登陆验证和储存日志的实例先看看IDAL和Model中的定义吧代码段一IDAL接口定义usingSystem;namespaceCManager.IDAL.Log/summary/ILoginLog的摘要说明。/summarypublicinterfaceISignLogvoidLogSignIn(stringuserid,stringsessionid

3、,stringclientip,DateTimelogindate);boolCheckPassword(stringuserid,stringpassword);代码段二Model对象定义usingSystem;namespaceCManager.Model.Log/summary/LoginInfo的摘要说明。/summarypublicclassSignLogInfopublicintSignLogIDgetreturn_SignLogID;publicstringUserIDgetreturn_UserID;publicstringSessionIDgetreturn_SessionI

4、D;publicstringClientIPgetreturn_ClientIP;publicDateTimeSignInDategetreturn_SignInDate;publicDateTimeSignOutDategetreturn_SignOutDate;protectedint_SignLogID;protectedstring_UserID;protectedstring_SessionID;protectedstring_ClientIP;protectedDateTime_SignInDate;protectedDateTime_SignOutDate;然后是BLL中调用。因

5、为BLL不依赖于任何DAL,所以通过中间层DALFactory创建DAL的实例,并通过IDAl定义的接口返回给BLL。代码段三BLL方法usingSystem;usingSystem.Collections;usingSystem.Web;usingCManager.Model.Log;usingCManager.Model.Collections;usingCManager.DALFactory.Log;usingCManager.IDAL.Log;namespaceCManager.BLL.LogpublicclassLog/未完成,应该返回Module.Log.Accountpublic

6、staticboolLogin(stringuserid,stringpassword,HttpContextcontext)ISignLoglog=LogFactory.CreateSignLog();if(log.CheckPassword(userid,password)log.LogSignIn(userid,context.Session.SessionID,context.Request.UserHostAddress,DateTime.Now);returntrue;elsereturnfalse;代码段四DALFactory方法usingSystem;usingCManager

7、.IDAL.Log;usingSystem.Reflection;namespaceCManager.DALFactory.LogpublicclassLogFactorypublicstaticISignLogCreateSignLog()/获取web.config里DAL的设置stringpath=System.Configuration.ConfigurationSettings.AppSettingsWebDAL;/组合出类名stringclassName=path+.Log.SignLog;/运行时创建类实例,需要类实现实例化return(ISignLog)Assembly.Load

8、(path).CreateInstance(className);代码段五web.config?xmlversion=1.0encoding=utf-8?configuration!-这段大家都熟悉了-configSectionssectionname=nhibernatetype=System.Configuration.NameValueSectionHandler,System,Version=1.0.5000.0,Culture=neutral,PublicKeyToken=b77a5c561934e089/configSectionsnhibernateaddkey=hibernat

9、e.connection.providervalue=NHibernate.Connection.DriverConnectionProvider/addkey=hibernate.connection.driver_classvalue=NHibernate.Driver.SqlClientDriver/addkey=hibernate.connection.connection_stringvalue=server=127.0.0.1;database=CManager;uid=sa;pwd=;/addkey=hibernate.connection.isolationvalue=Read

10、Committed/addkey=hibernate.dialectvalue=NHibernate.Dialect.MsSql2000Dialect/nhibernateappSettings!-默认显示每页显示记录数-addkey=DefaultRecordCountvalue=20/!-*数据库层所在命名空间*实际使用的DAL在这里设置-addkey=WebDALvalue=CManager.NHDAL/appSettingssystem.web!-这段按下,不占页面了-/system.web/configuration理论上Web层并不知道IDAL层定义的原子方法,只使用BLL层给出的

11、方法。这就是所谓的业务层与表现层分开。Web层只接受用户发出的请求,然后处理参数交给BLL层,并对BLL层返回的结果进行判断返回给结果。代码段六Web层调用usingSystem;usingSystem.Collections;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Web;usingSystem.Web.SessionState;usingSystem.Web.UI;usingSystem.Web.UI.WebControls;usingSystem.Web.UI.HtmlCont

12、rols;usingCManager.BLL.Log;usingCManager.Model.Log;namespaceBTTech.CManager.Web/summary/Login的摘要说明。/summarypublicclassLogin:PageBaseprotectedSystem.Web.UI.WebControls.TextBoxUserName;protectedSystem.Web.UI.WebControls.TextBoxPassword;protectedSystem.Web.UI.HtmlControls.HtmlInputImageImageButton1;pri

13、vatevoidPage_Load(objectsender,System.EventArgse)privatevoidImageButton1_ServerClick(objectsender,System.Web.UI.ImageClickEventArgse)if(Log.Login(UserName.Text,Password.Text,this.Context)Response.Redirect(,true);elseAlert(用户名或密码错误);最后是本文的主角NHDAL了,虽然最后出现,却是所有实际操作的最终执行者。代码段七实现IDALusingSystem;usingNHib

14、ernate.Cfg;usingNHibernate;namespaceCManager.NHDAL.Log/summary/SignLog的摘要说明。/summarypublicclassSignLog:NHObject,CManager.IDAL.Log.ISignLogpublicSignLog()publicvoidLogSignIn(stringuserid,stringsessionid,stringclientip,DateTimelogindate)ISessionsession=CreateSession();session.Save(newSignLogInfo(userid,sessionid,clientip,logindate);publicboolCheckPassword(stringuserid,stringpassword)/未完成returntrue;代码段八继承ModelusingSystem;usingCManager.Model;namespaceCManager.NHDAL.Log/summary/SignLog的摘要说明。/summarypublicclassSignLogInfo:CManager.Model.Log.SignLogInfoprivateintIdgetreturnthis._SignLogID;

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 商业/管理/HR > 管理学资料

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号