All articles(网络文学目录) All Pictures(图片目录) All Softwares(软件目录)

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

Writer: 归海一刀 Article type: Programming skills(编程技巧) Time: 2014/1/30 0:53:38 Browse times: 391 Comment times: 0

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


Head photo

Go homepage
Upload pictures
Write articles

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

3.4. 人事子系统服务层(Service)
部门服务接口(IDeptService.cs)
using System;
using Guushuuse.SalaryPrj.HR.DomainModel;
using Guushuuse.SalaryPrj.HR.Dao;
using System.Collections;

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


/// 部门服务接口
///

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

部门服务类(DeptService.cs)
using System;
using System.Collections.Generic;
using System.Text;
using Guushuuse.SalaryPrj.HR.Dao;
using Guushuuse.SalaryPrj.HR.DomainModel;
using System.Collections;
using Spring.Transaction.Interceptor;

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


/// 部门服务类
///

public class DeptService : IDeptService
{
private IDeptDao _deptDao;

public IDeptDao DeptDao
{
get { return _deptDao; }
set { _deptDao = value; }
}

public DeptService()
{

}

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

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

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

public IList GetAllDepts()
{
return _deptDao.GetAllDepts();
}

public Dept GetDept(int deptID)
{
return _deptDao.GetDept(deptID);
}
}
}

员工服务接口(IEmployeeService.cs)
using System;
using Guushuuse.SalaryPrj.HR.DomainModel;
using Guushuuse.SalaryPrj.HR.Dao;
using System.Collections;

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


/// 员工服务接口
///

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

员工服务类(EmployeeService.cs)
using System;
using System.Collections.Generic;
using System.Text;
using Guushuuse.SalaryPrj.HR.Dao;
using Guushuuse.SalaryPrj.HR.DomainModel;
using System.Collections;
using Spring.Transaction.Interceptor;

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


/// 员工服务类
///

public class EmployeeService : IEmployeeService
{
private IEmployeeDao _employeeDao;

public IEmployeeDao EmployeeDao
{
get { return _employeeDao; }
set { _employeeDao = value; }
}

public EmployeeService()
{

}

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

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

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

public IList GetAllEmployees()
{
return _employeeDao.GetAllEmployees();
}

public Employee GetEmployee(int employeeID)
{
return _employeeDao.GetEmployee(employeeID);
}
}
}

服务定位类(ServiceLocator.cs)
using System;
using System.Collections.Generic;
using System.Text;
using Spring.Context;
using Spring.Context.Support;

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


/// 服务定位类
///

public class ServiceLocator
{
private static IApplicationContext _ctx;

static ServiceLocator()
{
_ctx = ContextRegistry.GetContext();
}

public static IDeptService DeptService
{
get
{
IDeptService deptService = _ctx["deptService"] as IDeptService;

return deptService;
}
}

public static IEmployeeService EmployeeService
{
get
{
IEmployeeService employeeService = _ctx["employeeService"] as IEmployeeService;

return employeeService;
}
}
}
}

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




3.5. 人事子系统帮助类(Helper)
帮助类(HRHelper.cs)
using System;
using System.Collections.Generic;
using System.Text;
using Guushuuse.SalaryPrj.HR.DomainModel;
using Guushuuse.SalaryPrj.HR.Service;
using System.Collections;

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


/// 帮助类
///

public class HRHelper
{
/**////
/// 新增部门
///

///
///
public static void CreateDept(string code, string name)
{
try
{
Dept dept = new Dept();
dept.Code = code;
dept.Name = name;

ServiceLocator.DeptService.CreateDept(dept);
}
catch (Exception ex)
{
throw ex;
}
}

/**////


/// 更新部门
///

///
///
///
public static void UpdateDept(int id, string code, string name)
{
try
{
Dept dept = ServiceLocator.DeptService.GetDept(id);
dept.Code = code;
dept.Name = name;

ServiceLocator.DeptService.CreateDept(dept);
}
catch (Exception ex)
{
throw ex;
}
}

/**////


/// 删除部门
///

///
///
///
public static void DeleteDept(int id, string code, string name)
{
try
{
Dept dept = ServiceLocator.DeptService.GetDept(id);

ServiceLocator.DeptService.DeleteDept(dept);
}
catch (Exception ex)
{
throw ex;
}
}

/**////


/// 取出所有部门
///

///
public static IList GetAllDepts()
{
IList depts;

try
{
depts = ServiceLocator.DeptService.GetAllDepts();
}
catch (Exception ex)
{
throw ex;
}

return depts;
}

/**////


/// 新增员工
///

///
///
///
public static void CreateEmployee(string code, string name, int deptID)
{
try
{
Employee employee = new Employee();
employee.Code = code;
employee.Name = name;
employee.Dept = ServiceLocator.DeptService.GetDept(deptID);

ServiceLocator.EmployeeService.CreateEmployee(employee);
}
catch (Exception ex)
{
throw ex;
}
}

/**////


/// 更新员工
///

///
///
///
///
public static void UpdateEmployee(int id, string code, string name, int deptID)
{
try
{
Employee employee = ServiceLocator.EmployeeService.GetEmployee(id);
employee.Code = code;
employee.Name = name;
employee.Dept = ServiceLocator.DeptService.GetDept(deptID);

ServiceLocator.EmployeeService.CreateEmployee(employee);
}
catch (Exception ex)
{
throw ex;
}
}

/**////


/// 删除员工
///

///
///
///
public static void DeleteEmployee(int id, string code, string name)
{
try
{
Employee employee = ServiceLocator.EmployeeService.GetEmployee(id);

ServiceLocator.EmployeeService.DeleteEmployee(employee);
}
catch (Exception ex)
{
throw ex;
}
}

/**////


/// 取出所有员工
///

///
public static IList GetAllEmployees()
{
IList employees;

try
{
employees = ServiceLocator.EmployeeService.GetAllEmployees();
}
catch (Exception ex)
{
throw ex;
}

return employees;
}
}
}





There are 0 records,
Comment:
Must be registered users to comment(必须是注册用户才能发表评论)

Disclaimer Privacy Policy About us Site Map
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.