<% @ Codetemplate Language = "C #" targetlanguage = "C #" Description = "generate a class for the specified table" %>
<% @ Property name = "sourcetable" type = "schemaexplorer. tableschema" Category = "context" Description = "A table" %>
<% @ Property name = "namespace" type = "string" Category = "context" default = "BLL" Description = "namespace" %>
<% @ Property name = "filepath" type = "string" Category = "context" Description = "the target path where file is saved" %>
<% @ Assembly name = "schemaexplorer" %>
<% @ Assembly name = "system. Data" %>
<% @ Import namespace = "schemaexplorer" %>
<% @ Import namespace = "system. Io" %>
<% @ Import namespace = "system. Data" %>
<% @ Import namespace = "system. Data. sqlclient" %>
Using system;
Using system. Collections. Generic;
Using system. collections;
Using system. text;
Using DLL. mapperdao;
Using DLL. interfaces;
Using entity;
Using ibatisnet. dataaccess;
Using ibatisnet. dataaccess. exceptions;
Using ibatisnet. dataaccess. configuration;
Using ibatisnet. Common. pagination;
Namespace <% = namespace %>
{
Public partial class <% = sourcetable. name %> Manage
{
# Region generate by codesmith
# Region private fields
Private Static <% = sourcetable. name %> Manage _ instance = new <% = sourcetable. name %> Manage ();
Private daomanager _ daomanager = NULL;
Private icommondao _ commondao = NULL;
Private string _ modelname = "<% = sourcetable. name %> ";
# Endregion
# Region Constructor
Private <% = sourcetable. name %> Manage ()
{
_ Daomanager = serviceconfig. getinstance (). daomanager;
_ Commondao = _ daomanager [typeof (icommondao)] as icommondao;
}
# Endregion
# Region Public Methods
Public static <% = sourcetable. name %> Manage getinstance ()
{
Return _ instance;
}
Public ilist get <% = sourcetable. name %> All ()
{
Return _ commondao. getall (_ modelname );
}
Public ilist get <% = sourcetable. name %> allbyhashtable (hashtable htwhere)
{
Return _ commondao. getallbyhashtable (_ modelname, htwhere );
}
Public ilist get <% = sourcetable. name %> allpaging (INT int_pagesize, int int_currentpageindex)
{
Return _ commondao. getallpaging (_ modelname, int_pagesize, int_currentpageindex );
}
Public ilist get <% = sourcetable. name %> allbyhashtablepaging (hashtable htwhere, int int_pagesize, int int_currentpageindex)
{
Return _ commondao. getallbyhashtablepaging (_ modelname, htwhere, int_pagesize, int_currentpageindex );
}
Public <% = sourcetable. name %> Get <% = sourcetable. name %> byid (int id)
{
Return (<% = sourcetable. name %>) _ commondao. getbyid (_ modelname, ID );
}
Public int insert <% = sourcetable. name %> (<% = sourcetable. name %> <% = sourcetable. name %>)
{
Object objid = NULL;
Bool flag = _ daomanager. isdaosessionstarted ();
If (! Flag) _ daomanager. begintransaction ();
Try
{
Objid = _ commondao. insert (_ modelname, <%= sourcetable. name %> );
If (! Flag) _ daomanager. committransaction ();
Return (INT) objid;
}
Catch (exception E)
{
If (! Flag) _ daomanager. rollbacktransaction ();
If (E is dataaccessexception)
{
Throw new exception ("Dao error! ", E );
}
Else
{
Throw new exception ("BLL error! ", E );
}
}
}
Public void update <% = sourcetable. name %> (<% = sourcetable. name %> <% = sourcetable. name %>)
{
Bool flag = _ daomanager. isdaosessionstarted ();
If (! Flag) _ daomanager. begintransaction ();
Try
{
_ Commondao. Update (_ modelname, <%= sourcetable. name %> );
If (! Flag) _ daomanager. committransaction ();
}
Catch (exception E)
{
If (! Flag) _ daomanager. rollbacktransaction ();
If (E is dataaccessexception)
{
Throw new exception ("Dao error! ", E );
}
Else
{
Throw new exception ("BLL error! ", E );
}
}
}
Public void Delete <% = sourcetable. name %> byid (int id)
{
Bool flag = _ daomanager. isdaosessionstarted ();
If (! Flag) _ daomanager. begintransaction ();
Try
{
_ Commondao. deletebyid (_ modelname, ID );
If (! Flag) _ daomanager. committransaction ();
}
Catch (exception E)
{
If (! Flag) _ daomanager. rollbacktransaction ();
If (E is dataaccessexception)
{
Throw new exception ("Dao error! ", E );
}
Else
{
Throw new exception ("BLL error! ", E );
}
}
}
<% IF (ishavefk () {%>
Public ilist get <% = sourcetable. name %> allfk ()
{
Return _ commondao. getallfk (_ modelname );
}
Public ilist get <% = sourcetable. name %> allbyhashtablefk (hashtable htwhere)
{
Return _ commondao. getallbyhashtablefk (_ modelname, htwhere );
}
Public ilist get <% = sourcetable. name %> allpagingfk (INT int_pagesize, int int_currentpageindex)
{
Return _ commondao. getallpagingfk (_ modelname, int_pagesize, int_currentpageindex );
}
Public ilist get <% = sourcetable. name %> allbyhashtablepagingfk (hashtable htwhere, int int_pagesize, int int_currentpageindex)
{
Return _ commondao. getallbyhashtablepagingfk (_ modelname, htwhere, int_pagesize, int_currentpageindex );
}
Public Re <% = sourcetable. name %> Get <% = sourcetable. name %> byidfk (int id)
{
Return (Re <% = sourcetable. name %>) _ commondao. getbyidfk (_ modelname, ID );
}
Public int insert <% = sourcetable. name %> FK (Re <% = sourcetable. name %> Re <% = sourcetable. name %>)
{
Object objid = NULL;
Bool flag = _ daomanager. isdaosessionstarted ();
If (! Flag) _ daomanager. begintransaction ();
Try
{
Objid = _ commondao. insertfk (_ modelname, Re <% = sourcetable. name %> );
If (! Flag) _ daomanager. committransaction ();
Return (INT) objid;
}
Catch (exception E)
{
If (! Flag) _ daomanager. rollbacktransaction ();
If (E is dataaccessexception)
{
Throw new exception ("Dao error! ", E );
}
Else
{
Throw new exception ("BLL error! ", E );
}
}
}
Public void update <% = sourcetable. name %> FK (Re <% = sourcetable. name %> Re <% = sourcetable. name %>)
{
Bool flag = _ daomanager. isdaosessionstarted ();
If (! Flag) _ daomanager. begintransaction ();
Try
{
_ Commondao. updatefk (_ modelname, Re <% = sourcetable. name %> );
If (! Flag) _ daomanager. committransaction ();
}
Catch (exception E)
{
If (! Flag) _ daomanager. rollbacktransaction ();
If (E is dataaccessexception)
{
Throw new exception ("Dao error! ", E );
}
Else
{
Throw new exception ("BLL error! ", E );
}
}
}
<% }%>
# Endregion
# Endregion
}
}
<SCRIPT runat = "template">
Public override void render (textwriter writer)
{
Streamwriter filewriter1 = new streamwriter (filepath + "/" + sourcetable. Name + "manage. cs", false );
This. response. addtextwriter (filewriter1 );
Base. Render (writer );
Filewriter1.close ();
}
Public bool ishavefk ()
{
For (INT I = 0; I <sourcetable. Columns. Count; I ++)
{
If (sourcetable. Columns [I]. isforeignkeymember)
Return true;
}
Return false;
}
</SCRIPT>