运用SQL Artisan编写业务代码(1)
00004 namespace GentleIDC . Sysbase . Company
00005 {
00006 /// <summary>
00007 /// 功能 : 公司对象操作类
00008 /// 作者 : 樊健汉
00009 /// 编写日期: 2006-4-24
00010 /// 修改人 :
00011 /// 修改日期
00012 /// </summary>
00013 public class CompanyObj : Gentle . Business . BusinessAdapter
00014 {
00015 public const string Error_Exist ="相同名称的公司信息已经存在!" ;
00016 public const string Error_ItemIsNull ="缺少公司信息对象!" ;
00017 /// <summary>
00018 /// 构造添加公司信息对象
00019 /// </summary>
00020 public CompanyObj ()
00021 {
00022 }
00023 /// <summary>
00024 /// 构造公司信息对象
00025 /// 并指定操作的类型(添加|修改)
00026 /// </summary>
00027 /// <param name="isnew">bool</param>
00028 public CompanyObj ( bool isnew )
00029 {
00030 IsNew = isnew ;
00031 }
00032 /// <summary>
00033 /// 是否新增信息
00034 /// 默认是新增
00035 /// </summary>
00036 public bool IsNew
00037 {
00038 get
00039 {
00040 return mIsNew ;
00041 }
00042 set
00043 {
00044 mIsNew = value ;
00045 }
00046 }
00047 /// <summary>
00048 /// 公司信息列表
00049 /// </summary>
00050 public GentleIDC . Entitys . tCompany Item
00051 {
00052 get
00053 {
00054 return mItem ;
00055 }
00056 set
00057 {
00058 mItem = value ;
00059 }
00060 }
00061 private bool mIsNew = true ;
00062 private GentleIDC . Entitys . tCompany mItem ;
00063 protected override void OnExecute ()
00064 {
00065 if ( Item == null )
00066 throw ( new Gentle . Business . BusinessException ( Error_ItemIsNull
, null ));
00067 if ( IsNew )
00068 {
00069 System . Collections . IList lst = DataUnit . List ( typeof ( tCompany )
, tCompany . _CompanyName == Item . CompanyName );
00070 if ( lst . Count >0)
00071 {
00072 throw ( new Gentle . Business . BusinessException ( Error_Exist ,
null ));
00073 }
00074 Item . CompanyIndex = GetRecordIndex ( tCompany . TBL . Name );
00075 DataUnit . Save ( Item );
00076
00077 }
00078 else
00079 {
00080 DataUnit . Update ( Item );
00081 }
00082 base . OnExecute ();
00083 }
00084
00085
00086
00087 /// <summary>
00088 /// 获取相应索引的公司对象
00089 /// </summary>
00090 /// <param name="companyid">公司记录索引</param>
00091 /// <returns>tCompany</returns>
00092 public static tCompany GetByIndex ( int companyid )
00093 {
00094 using ( IDataSession sessaion = MappingContainer . ConfigContainer .
OpenSession ())
00095 {
00096 sessaion . Open ();
00097 return GetByIndex ( companyid , sessaion );
00098 }
00099 }
00100
00101 /// <summary>
00102 /// 在指定的数据容器中获取相应索引的公司信息
00103 /// </summary>
00104 /// <param name="companyid">公司索引值</param>
00105 /// <param name="session">数据容器</param>
00106 /// <returns>公司对象</returns>
00107 public static tCompany GetByIndex ( int companyid , IDataSession session
)
00108 {
00109 return ( tCompany ) session . Load ( typeof ( tCompany ), companyid );
00110 }
00111 /// <summary>
00112 /// 删除相应索引的公司记录
00113 /// </summary>
00114 /// <param name="companyid">公司索引</param>
00115 public static void DeleteByIndex ( int companyid )
00116 {
00117 using ( IDataSession session = MappingContainer . ConfigContainer .
OpenSession ())
00118 {
00119 session . Open ();
00120 DeleteByIndex ( companyid , session );
00121 }
00122 }
00123 /// <summary>
00124 /// 在指定数据容器中删除相应索引的公司记录
00125 /// </summary>
00126 /// <param name="companyid">公司索引</param>
00127 /// <param name="session">数据容器</param>
00128 public static void DeleteByIndex ( int companyid , IDataSession session )
00129 {
00130 IDelete delte = session . CreateDelete ( tCompany . TBL );
00131 delte . Expreesion = tCompany . _CompanyIndex == companyid ;
00132 delte . Execute ();
00133 }
00134
00135 }
00136 }
00004 namespace GentleIDC . Sysbase . Company
00005 {
00006 /// <summary>
00007 /// 功能 : 公司信息查询类
00008 /// 作者 : 樊健汉
00009 /// 编写日期: 2006-4-24
00010 /// 修改人 :
00011 /// 修改日期
00012 /// </summary>
00013 public class CompanyQuery : Gentle . Business . BusinessAdapter
00014 {
00015 /// <summary>
00016 /// 公司信息查询类
00017 /// </summary>
00018 [ System . Serializable ()]
00019 public class CompanySearch
00020 {
00021 /// <summary>
00022 /// 公司名称
00023 /// </summary>
00024 public string CompanyName
00025 {
00026 get
00027 {
00028 return mCompanyName ;
00029 }
00030 set
00031 {
00032 mCompanyName = value ;
00033 }
00034 }
00035 public HFSoft . Data . Expressions . Expression GetExpression ()
00036 {
00037 if ( CompanyName != null )
00038 return tCompany . _CompanyName . Match ( CompanyName );
00039 return null ;
00040 }
00041 private string mCompanyName ;
00042 }
00043 /// <summary>
00044 /// 设置查询对象
00045 /// </summary>
00046 public GentleIDC . Sysbase . Company . CompanyQuery . CompanySearch Filter
00047 {
00048 get
00049 {
00050 return mFilter ;
00051 }
00052 }
00053 /// <summary>
00054 /// 获取信息的查询信息
00055 /// </summary>
00056 public System . Data . DataSet Items
00057 {
00058 get
00059 {
00060 return mItem ;
00061 }
00062 }
00063 private System . Data . DataSet mItem ;
00064 private GentleIDC . Sysbase . Company . CompanyQuery . CompanySearch mFilter
= new CompanySearch ();
00065 protected override void OnExecute ()
00066 {
00067 IQuery query = DataUnit . CreateQuery ( tCompany . TBL );
00068 query . Expreesion = Filter . GetExpression ();
00069 mItem = query . ExecuteDataSet ();
00070 base . OnExecute ();
00071 }
00072
00073 }
00074 }