All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
asp.net2.0对Repeater数据控件进行绑定
程序开发:ASP.NET热点问题解答14个_.net资料_编程技术
用em指定字体尺寸的问题和解决办法_[Html教程]
Windows 下架设 PHP 服务器_[PHP教程]
URL重写实现IHttpHandler接口_[Asp.Net教程]
任意字符集下正常显示网页_[PHP教程]
ASP.NET的HTMLTable原样导出到Excel_[Asp.Net教程]
ASP.NET2.0,上传图片并为用户创建相应文件夹_.net资料_编程技术
用ASP.NET2.0如何随机读取Access记录?_.net资料_编程技术
在C#中取得指定长度的字符串_[Asp.Net教程]
Reading number is top 10 pictures
这年头,找个靠谱的妹子太难了
Born After 90 Beijing sports university campus flower photos1
Look for from human art net, is good--2
大四女生借债隆胸成功
10 powerless things in life
Men don't mature ten sign
俞敏洪在清华终于说了实话
The money of more than 100 countries and regions16
全球十大灵异酒店
Street street fighting
Download software ranking
matrix3
Unix video tutorial20
Unix video tutorial11
Such love down(擒爱记)
尖东毒玫瑰A
Popkart Cracked versions Mobile phone games
打鸟视频
塘西风月痕
美女写真2
matrix2
归海一刀 published in(发表于) 2014/1/30 0:53:44 Edit(编辑)
ASP.NET&Spring.NET&NHibernate最佳实践(四)——第3章人事子系统(1)_[Asp.Net教程]

ASP.NET&Spring.NET&NHibernate最佳实践(四)——第3章人事子系统(1)_[Asp.Net教程]

ASP.NET&Spring.NET&NHibernate最佳实践(四)——第3章人事子系统(1)_[Asp.Net教程]

人事子系统分层结构为:领域模型层(DomainModel)——数据访问层(Dao)——服务层(Sevice)——表示层(Web),在Web页面中采用了ObjectDataSource作为GridView的数据源,并为此增加了一个帮助类。
在数据访问层中充分体现了Spring.NET和NHibernate的无缝集成,只要继承HibernateDaoSupport就能很便捷的使用NHibernate,而不需要很深入了解NHibernate。


3.1. 人事子系统领域模型层(DomainModel)
部门(Dept.cs)
using System;
using System.Collections.Generic;
using System.Text;


namespace Guushuuse.SalaryPrj.HR.DomainModel
{
/**////


/// 部门
///

public class Dept
{
private int _id;
private string _code;
private string _name;


属性#region 属性


/**////


/// ID
///

public virtual int ID
{
get { return _id; }
set { _id = value; }
}


/**////


/// 部门代码
///

public virtual string Code
{
get { return _code; }
set { _code = value; }
}


/**////


/// 部门名称
///

public virtual string Name
{
get { return _name; }
set { _name = value; }
}


#endregion 属性


构造函数#region 构造函数


/**////


///
///

public Dept()
{
this._id = -1;
this._code = String.Empty;
this._name = String.Empty;
}


#endregion 构造函数
}
}


员工(Employee.cs)



using System;
using System.Collections.Generic;
using System.Text;


namespace Guushuuse.SalaryPrj.HR.DomainModel
{
/**////


/// 员工
///

public class Employee
{
private int _id;
private string _code;
private string _name;
private Dept _dept;


属性#region 属性


/**////


/// ID
///

public virtual int ID
{
get { return _id; }
set { _id = value; }
}


/**////


/// 工号
///

public virtual string Code
{
get { return _code; }
set { _code = value; }
}


/**////


/// 姓名
///

public virtual string Name
{
get { return _name; }
set { _name = value; }
}


/**////


/// 部门
///

public virtual Dept Dept
{
get { return _dept; }
set { _dept = value; }
}


/**////


/// 部门ID
///

public virtual int DeptID
{
get
{
if (_dept != null)
{
return _dept.ID;
}
else
{
return -1;
}
}
}


/**////


/// 部门名称
///

public virtual string DeptName
{
get
{
if (_dept != null)
{
return _dept.Name;
}
else
{
return String.Empty;
}
}
}


#endregion 属性


构造函数#region 构造函数


/**////


///
///

public Employee()
{
this._id = -1;
this._code = String.Empty;
this._name = String.Empty;
}


#endregion 构造函数
}
}


3.2. 人事子系统映射文件(HBM)
Dept.hbm.xml










Employee.hbm.xml











3.3. 人事子系统数据访问层(Dao)
部门数据访问接口(IDeptDao.cs)
using System;
using Guushuuse.SalaryPrj.HR.DomainModel;
using System.Collections;


namespace Guushuuse.SalaryPrj.HR.Dao
{
/**////


/// 部门数据访问接口
///

public interface IDeptDao
{
void CreateDept(Dept dept);
void DeleteDept(Dept dept);
IList GetAllDepts();
Dept GetDept(int deptID);
void UpdateDept(Dept dept);
}
}


部门数据访问类(DeptDao.cs)
using System;
using System.Collections.Generic;
using System.Text;
using Spring.Data.NHibernate.Support;
using Spring.Transaction.Interceptor;
using Guushuuse.SalaryPrj.HR.DomainModel;
using System.Collections;


namespace Guushuuse.SalaryPrj.HR.Dao
{
/**////


/// 部门数据访问类
///

public class DeptDao : HibernateDaoSupport, IDeptDao
{
public DeptDao()
{


}


[Transaction(ReadOnly = false)]
public void CreateDept(Dept dept)
{
HibernateTemplate.Save(dept);
}


[Transaction(ReadOnly = false)]
public void UpdateDept(Dept dept)
{
HibernateTemplate.Update(dept);
}


[Transaction(ReadOnly = false)]
public void DeleteDept(Dept dept)
{
HibernateTemplate.Delete(dept);
}


public IList GetAllDepts()
{
return HibernateTemplate.LoadAll(typeof(Dept));
}


public Dept GetDept(int deptID)
{
return (Dept)HibernateTemplate.Get(typeof(Dept), deptID);
}
}
}


员工数据访问接口(IEmployeeDao.cs)
using System;
using Guushuuse.SalaryPrj.HR.DomainModel;
using System.Collections;


namespace Guushuuse.SalaryPrj.HR.Dao
{
/**////


/// 员工数据访问接口
///

public interface IEmployeeDao
{
void CreateEmployee(Employee employee);
void DeleteEmployee(Employee employee);
IList GetAllEmployees();
Employee GetEmployee(int employeeID);
void UpdateEmployee(Employee employee);
}
}


员工数据访问类(EmployeeDao.cs)
using System;
using System.Collections.Generic;
using System.Text;
using Spring.Data.NHibernate.Support;
using Spring.Transaction.Interceptor;
using Guushuuse.SalaryPrj.HR.DomainModel;
using System.Collections;


namespace Guushuuse.SalaryPrj.HR.Dao
{
/**////


/// 员工数据访问类
///

public class EmployeeDao : HibernateDaoSupport, IEmployeeDao
{
public EmployeeDao()
{


}



[Transaction(ReadOnly = false)]
public void CreateEmployee(Employee employee)
{
HibernateTemplate.Save(employee);
}


[Transaction(ReadOnly = false)]
public void UpdateEmployee(Employee employee)
{
HibernateTemplate.Update(employee);
}


[Transaction(ReadOnly = false)]
public void DeleteEmployee(Employee employee)
{
HibernateTemplate.Delete(employee);
}


public IList GetAllEmployees()
{
return HibernateTemplate.LoadAll(typeof(Employee));
}


public Employee GetEmployee(int employeeID)
{
return (Employee)HibernateTemplate.Get(typeof(Employee), employeeID);
}
}
}


修改Config/Guushuuse.SalaryPrj.HR.config文件,新增object












添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.