FastSpring学习笔记四(BLL层类创建和DAL层类创建)
一、在DZ_Portal.App项目中的BLL文件夹下创建一个类:AnnouncementDAL.cs,代码如下:
using System;
using System.Collections.Generic;
using System.Text;
using FastSpring.Base;
using DZ_Portal.App.DAL;
using DZ_Portal.App.Model;
using Spring.Transaction.Interceptor;
using FastSpring.Exceptions;
namespace DZ_Portal.App.BLL
...{
Interface IAnnouncementManager#region Interface IAnnouncementManager
/**//// <summary>
/// Interface IUserManager 的摘要说明。
/// </summary>
public interface IAnnouncementManager : IBaseManager, IManyToOneEntityManager
...{
[Transaction]
bool TestTransActionDeleteObject(int ID); //ID小于10不能删除
}
#endregion
Class AnnouncementManager#region Class AnnouncementManager
public class AnnouncementManager : BaseManager, IAnnouncementManager
...{
public AnnouncementManager()
...{
//
// TODO: 在此处添加构造函数逻辑
//
}
protected override IBaseDAO GetBaseDAO()
...{
return _m_AnnouncementDao;
}
AnnouncementManager.AnnouncementDAO#region AnnouncementManager.AnnouncementDAO
private AnnouncementDAO _m_AnnouncementDao;
public AnnouncementDAO AnnouncementDAO
...{
get
...{
return _m_AnnouncementDao;
}
set
...{
_m_AnnouncementDao = value;
}
}
#endregion
IAnnouncementManager 成员#region IAnnouncementManager 成员
/**//// <summary>
/// ID小于10不能删除
/// </summary>
/// <param name="ID"></param>
/// <returns></returns>
public bool TestTransActionDeleteObject(int ID)
...{
Announcement dp = this._m_AnnouncementDao.Load(ID) as Announcement;
if (dp != null)
...{
this._m_AnnouncementDao.DeleteObject(dp);
}
if (ID < 10)
...{
throw new TransActionException("ID<10不能被删除!");
}
return true;
}
#endregion
}
#endregion
}
using System.Collections.Generic;
using System.Text;
using FastSpring.Base;
using DZ_Portal.App.DAL;
using DZ_Portal.App.Model;
using Spring.Transaction.Interceptor;
using FastSpring.Exceptions;
namespace DZ_Portal.App.BLL
...{
Interface IAnnouncementManager#region Interface IAnnouncementManager
/**//// <summary>
/// Interface IUserManager 的摘要说明。
/// </summary>
public interface IAnnouncementManager : IBaseManager, IManyToOneEntityManager
...{
[Transaction]
bool TestTransActionDeleteObject(int ID); //ID小于10不能删除
}
#endregion
Class AnnouncementManager#region Class AnnouncementManager
public class AnnouncementManager : BaseManager, IAnnouncementManager
...{
public AnnouncementManager()
...{
//
// TODO: 在此处添加构造函数逻辑
//
}
protected override IBaseDAO GetBaseDAO()
...{
return _m_AnnouncementDao;
}
AnnouncementManager.AnnouncementDAO#region AnnouncementManager.AnnouncementDAO
private AnnouncementDAO _m_AnnouncementDao;
public AnnouncementDAO AnnouncementDAO
...{
get
...{
return _m_AnnouncementDao;
}
set
...{
_m_AnnouncementDao = value;
}
}
#endregion
IAnnouncementManager 成员#region IAnnouncementManager 成员
/**//// <summary>
/// ID小于10不能删除
/// </summary>
/// <param name="ID"></param>
/// <returns></returns>
public bool TestTransActionDeleteObject(int ID)
...{
Announcement dp = this._m_AnnouncementDao.Load(ID) as Announcement;
if (dp != null)
...{
this._m_AnnouncementDao.DeleteObject(dp);
}
if (ID < 10)
...{
throw new TransActionException("ID<10不能被删除!");
}
return true;
}
#endregion
}
#endregion
}
二、在文件夹DAL下创建类:AnnouncementDAL.cs,代码如下:
using System;
using System.Collections.Generic;
using System.Text;
using FastSpring.Base;
using DZ_Portal.App.Model;
namespace DZ_Portal.App.DAL
...{
Interface IAnnouncementDAO#region Interface IAnnouncementDAO
/**//// <summary>
/// Interface IAnnouncementDAO 的摘要说明。
/// </summary>
public interface IAnnouncementDAO : IBaseDAO, IManyToOneEntityDAO
...{
}
#endregion
Class AnnouncementDAO#region Class AnnouncementDAO
/**//// <summary>
/// AnnouncementDAO 的摘要说明。
/// </summary>
public class AnnouncementDAO : BaseDAO, IAnnouncementDAO
...{
public AnnouncementDAO()
...{
//
// TODO: 在此处添加构造函数逻辑
//
}
public override Type GetEntityType()
...{
return typeof(Announcement);
}
}
#endregion
}
using System.Collections.Generic;
using System.Text;
using FastSpring.Base;
using DZ_Portal.App.Model;
namespace DZ_Portal.App.DAL
...{
Interface IAnnouncementDAO#region Interface IAnnouncementDAO
/**//// <summary>
/// Interface IAnnouncementDAO 的摘要说明。
/// </summary>
public interface IAnnouncementDAO : IBaseDAO, IManyToOneEntityDAO
...{
}
#endregion
Class AnnouncementDAO#region Class AnnouncementDAO
/**//// <summary>
/// AnnouncementDAO 的摘要说明。
/// </summary>
public class AnnouncementDAO : BaseDAO, IAnnouncementDAO
...{
public AnnouncementDAO()
...{
//
// TODO: 在此处添加构造函数逻辑
//
}
public override Type GetEntityType()
...{
return typeof(Announcement);
}
}
#endregion
}
到目前为止,我们已经把DZ_Portal.App项目所需要的类都创建好了,日后的所有有关类库的代码都是如此创建出不同的类,它们都是提供给网站应用程序所使用的基础,以后将不在陈述相关的东西,因为这部分的内容基本上都可以用工具自动生成代码的。编译这些代码需要引用下面的一些文件:FastSpring.Net、FastSpring.Net.Common、FastSpring.Net.Core、Spring.Core、Spring.Data、Spring.Data.NHibernate12
原创作品出自努力偷懒,转载请说明文章出处:http://blog.csdn.net/kfarvid或 http://www.cnblogs.com/kfarvid/