HOME
User:
Anonymous
search for
in
Template Archives
Templates
Articles
Users
Login
Username:
Password:
Navigation
Registered User Functions:
Register New Account
Anonymous Functions:
Home
Users
Archives
Templates
Articles
MyGeneration Website
MyGeneration Forums
Categories
Application Type
Command Line
Graphical User Interface
Library
Sample
Web Application
Architecture Type
Client-Server
Distributed Computing
Multi-Tier
Peer-to-peer
Operating System
Linux
Win32
Programming Language
ASP
ASP.Net
C#
C++
Firebird SQL
J#
Java
Jet SQL
JScript
JSP
MySQL
Perl
PHP
PL/SQL
PostgreSQL
SQL
Transact-SQL
VB.Net
VBScript
XSLT
Template: EasyObject C# Business Entity
Download Count:
11358
View Count:
5410
Template Properties
Unique ID:
af0da2bf-9e7d-4069-9d24-c01d219a8f78
Title:
EasyObject C# Business Entity
Namespace:
EasyObject.C#
Output Language:
C#
Mode:
Markup
Start Tag:
<%
End Tag:
%>
Template Body
Engine:
Microsoft Script
Language:
VBScript
<% '------------------------------------------------------------------------------ ' Copyright 2005 by Noonan Consulting Inc. ' All Rights Reserved ' ' Permission to use, copy, modify, and distribute this software and its ' documentation for any purpose and without fee is hereby granted, ' provided that the above copyright notice appear in all copies and that ' both that copyright notice and this permission notice appear in ' supporting documentation. ' ' NCI DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS ' SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY ' AND FITNESS, IN NO EVENT SHALL NCI BE LIABLE FOR ANY ' SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES ' WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, ' WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER ' TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE ' OR PERFORMANCE OF THIS SOFTWARE. '------------------------------------------------------------------------------ ' CSharp_EasyObject_BusinessEntity.vbgen ' Last Update : 10/20/2006 '------------------------------------------------------------------------------ If context.Objects.ContainsKey("DnpUtils") Then DnpUtils.SaveInputToCache(context) End if Dim bFirst Dim name Dim alias Dim objTable Dim objColumn Dim tableNames Dim language Dim databaseName Dim database Dim namespace Dim props Dim bOtherColumns Dim sPrefix Dim sFormat Dim sStyle Dim IDbCommand Dim IDataParameter Dim ParameterPrefix Dim dialect dialect = 1 If input.Item("ckDialect3") Then dialect = 3 End If prefix = input.Item("prefix") ' Grab the namespace namespace = input.Item("txtNamespace") ' Set the Language for our column data types ' Grab the choices the user made in our UI Script (see Interface Code tab) Set tableNames = input.Item("lstTables") sPrefix = input.Item("txtPrefix") sFormat = input.Item("txtFormat") sStyle = input.Item("cmbFormat") databaseName = input.Item("cmbDatabase") Set database = MyMeta.Databases(databaseName) ' Loop through the tables the user selected and generate the business entities For intLp = 0 To tableNames.Count - 1 Set objTable = database.Tables(tablenames.item(intLp)) Set props = objTable.Properties bOtherColumns = (objTable.Columns.Count > objTable.PrimaryKeys.Count) '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ' Now we have the table that we desire to build a Business Object From, let us begin. '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ %>/* '=============================================================================== ' Generated From - CSharp_EasyObject_BusinessEntity.vbgen ' ' ** IMPORTANT ** ' How to Generate your stored procedures: ' ' SQL = SQL_DAAB_StoredProcs.vbgen ' ' This object is 'abstract' which means you need to inherit from it to be able ' to instantiate it. This is very easily done. You can override properties and ' methods in your derived class, this allows you to regenerate this class at any ' time and not worry about overwriting custom code. ' ' NEVER EDIT THIS FILE. ' ' public class YourObject : _YourObject ' { ' ' } ' '=============================================================================== */ // Generated by MyGeneration Version # (<%= input.Item("__version") %>) using System; using System.Data; using System.Configuration; using System.Collections; using System.Collections.Specialized; using System.Xml; using System.IO; using Microsoft.Practices.EnterpriseLibrary.Data; using NCI.EasyObjects; namespace <%= TrimSpaces(namespace) %> { #region Schema public class <%= TrimSpaces(objTable.Alias) %>Schema : NCI.EasyObjects.Schema { private static ArrayList _entries; <% output.tabLevel = 2 ' List all fields as member variables For Each objColumn In objTable.Columns name = GetActualName(objColumn) alias = GetAlias(objColumn) isAutoKey = objColumn.IsAutoKey If props.ContainsKey("SEQ:I:" & objColumn.Name) Then isAutoKey = True End if Select Case LCase(objColumn.LanguageType) Case "string" 'output.autoTabLn "public static SchemaItem " & alias & " = new SchemaItem(""" & name & """, " & objColumn.DbTargetType & ", SchemaItemJustify.None, " & objColumn.CharacterMaxLength & ");" output.autoTabLn "public static SchemaItem " & alias & " = new SchemaItem(""" & name & """, " & objColumn.DbTargetType & ", SchemaItemJustify.None, " & objColumn.CharacterMaxLength & ", " & ConvertToBoolean(objColumn.IsNullable) & ", " & ConvertToBoolean(objColumn.IsInPrimaryKey) & ", " & ConvertToBoolean(objColumn.IsInForeignKey) & ", " & ConvertToBoolean(objColumn.HasDefault) & ");" Case Else 'output.autoTab "public static SchemaItem " & alias & " = new SchemaItem(""" & name & """, " & objColumn.DbTargetType output.autoTabLn "public static SchemaItem " & alias & " = new SchemaItem(""" & name & """, " & objColumn.DbTargetType & ", " & ConvertToBoolean(isAutoKey) & ", " & ConvertToBoolean(objColumn.IsNullable) & ", " & ConvertToBoolean(objColumn.IsComputed) & ", " & ConvertToBoolean(objColumn.IsInPrimaryKey) & ", " & ConvertToBoolean(objColumn.IsInForeignKey) & ", " & ConvertToBoolean(objColumn.HasDefault) & ");" End Select Next %> public override ArrayList SchemaEntries { get { if (_entries == null ) { _entries = new ArrayList(); <% output.tabLevel = 5 ' Load all fields into the ArrayList For Each objColumn In objTable.Columns alias = GetAlias(objColumn) output.autoTabLn "_entries.Add(" & TrimSpaces(objTable.Alias) & "Schema." & alias & ");" If objColumn.IsComputed Then output.autoTabLn TrimSpaces(objTable.Alias) & "Schema." & alias & ".IsComputed = true;" End If propName = "SEQ:I:" & objColumn.Name If props.ContainsKey(propName) Then output.autoTabLn TrimSpaces(objTable.Alias) & "Schema." & alias & ".Properties.Add(""SEQ:I"", """ & props(propName).Value& """);" End if propName = "SEQ:U:" & objColumn.Name If props.ContainsKey(propName) Then output.autoTabLn TrimSpaces(objTable.Alias) & "Schema." & alias & ".Properties.Add(""SEQ:U"", """ & props(propName).Value& """);" output.autoTabLn TrimSpaces(objTable.Alias) & "Schema." & alias & ".IsRowID = true;" End if Next %> } return _entries; } } } #endregion public abstract class <%= "_" & TrimSpaces(objTable.Alias) %> : EasyObject { public <%= "_" & TrimSpaces(objTable.Alias) %>() { <%= TrimSpaces(objTable.Alias) %>Schema _schema = new <%= TrimSpaces(objTable.Alias) %>Schema(); this.SchemaEntries = _schema.SchemaEntries; <% output.write "this.SchemaGlobal = """ + objTable.Schema + """;" %> } public override void FlushData() { this._whereClause = null; this._aggregateClause = null; base.FlushData(); } /// <summary> /// Loads the business object with info from the database, based on the requested primary key. /// </summary> <% output.tabLevel = 2 For Each objColumn in objTable.PrimaryKeys output.autoTabLn "/// <param name=""" & GetAlias(objColumn) & """>" & objColumn.Description & "</param>" Next %> /// <returns>A Boolean indicating success or failure of the query</returns> public bool LoadByPrimaryKey(<% bFirst = true For Each objColumn in objTable.PrimaryKeys If Not bFirst Then output.write ", " End If output.write objColumn.LanguageType & " " & GetAlias(objColumn) bFirst = false Next %>) { switch(this.DefaultCommandType) { case CommandType.StoredProcedure: ListDictionary parameters = new ListDictionary(); // Add in parameters <% output.tabLevel = 5 For Each objColumn in objTable.PrimaryKeys name = GetName(objColumn) alias = GetAlias(objColumn) output.autoTabLn "parameters.Add(" & TrimSpaces(objTable.Alias) & "Schema." & alias & ".FieldName, " & alias & ");" Next %> return base.LoadFromSql(this.SchemaStoredProcedureWithSeparator + "<%= CreateProcedureName(objTable, "K") %>", parameters, CommandType.StoredProcedure); case CommandType.Text: this.Query.ClearAll(); this.Where.WhereClauseReset(); <% output.tabLevel = 5 For Each objColumn in objTable.PrimaryKeys name = GetName(objColumn) alias = GetAlias(objColumn) output.autoTabLn "this.Where." & alias & ".Value = " & alias & ";" Next %> return this.Query.Load(); default: throw new ArgumentException("Invalid CommandType", "commandType"); } } /// <summary> /// Loads all records from the table. /// </summary> /// <returns>A Boolean indicating success or failure of the query</returns> public bool LoadAll() { switch(this.DefaultCommandType) { case CommandType.StoredProcedure: return base.LoadFromSql(this.SchemaStoredProcedureWithSeparator + "<%= CreateProcedureName(objTable, "L") %>", null, CommandType.StoredProcedure); case CommandType.Text: this.Query.ClearAll(); this.Where.WhereClauseReset(); return this.Query.Load(); default: throw new ArgumentException("Invalid CommandType", "commandType"); } } /// <summary> /// Adds a new record to the internal table. /// </summary> public override void AddNew() { base.AddNew(); <% output.tabLevel = 3 For Each objColumn in objTable.Columns If objColumn.Default = "newid()" Or objColumn.Default = "GenGUID()" Then output.autoTabLn "this." + GetAlias(objColumn) +" = Guid.NewGuid();" End If Next %> } protected override DBCommandWrapper GetInsertCommand(CommandType commandType) { DBCommandWrapper dbCommandWrapper; // Create the Database object, using the default database service. The // default database service is determined through configuration. Database db = GetDatabase(); switch(commandType) { case CommandType.StoredProcedure: string sqlCommand = this.SchemaStoredProcedureWithSeparator + "<%= CreateProcedureName(objTable, "I") %>"; dbCommandWrapper = db.GetStoredProcCommandWrapper(sqlCommand); <% output.tabLevel = 5 For Each objColumn in objTable.PrimaryKeys isAutoKey = objColumn.IsAutoKey If props.ContainsKey("SEQ:I:" & objColumn.Name) Then isAutoKey = True End if If isAutoKey Then name = GetActualName(objColumn) alias = GetAlias(objColumn) output.autoTabLn "dbCommandWrapper.AddParameter(""" & name & """, " & objColumn.DbTargetType & ", " & objColumn.CharacterMaxLength & ", ParameterDirection.Output, true, 0, 0, """ & name & """, DataRowVersion.Default, Convert.DBNull);" End If Next %> CreateParameters(dbCommandWrapper); return dbCommandWrapper; case CommandType.Text: this.Query.ClearAll(); this.Where.WhereClauseReset(); foreach(SchemaItem item in this.SchemaEntries) { if (!item.IsComputed) { if ((item.IsAutoKey && this.IdentityInsert) || !item.IsAutoKey) { this.Query.AddInsertColumn(item); } } } dbCommandWrapper = this.Query.GetInsertCommandWrapper(); dbCommandWrapper.Command.Parameters.Clear(); if (this.IdentityInsert) { <% output.tabLevel = 6 For Each objColumn in objTable.PrimaryKeys isAutoKey = objColumn.IsAutoKey If props.ContainsKey("SEQ:I:" & objColumn.Name) Then isAutoKey = True End if If isAutoKey Then name = objColumn.Name alias = GetAlias(objColumn) output.autoTabLn "dbCommandWrapper.AddInParameter(""" & alias & """, " & objColumn.DbTargetType & ", """ & name & """, DataRowVersion.Default);" End If Next %> } else { <% output.tabLevel = 6 For Each objColumn in objTable.PrimaryKeys isAutoKey = objColumn.IsAutoKey inputOutput = "Output" If props.ContainsKey("SEQ:I:" & objColumn.Name) Then isAutoKey = True inputOutput = "InputOutput" End if If isAutoKey Then name = GetActualName(objColumn) alias = GetAlias(objColumn) output.autoTabLn "dbCommandWrapper.AddParameter(""" & name & """, " & objColumn.DbTargetType & ", " & objColumn.CharacterMaxLength & ", ParameterDirection." & inputOutput & ", true, 0, 0, """ & name & """, DataRowVersion.Default, Convert.DBNull);" End If Next %> } CreateParameters(dbCommandWrapper); return dbCommandWrapper; default: throw new ArgumentException("Invalid CommandType", "commandType"); } } protected override DBCommandWrapper GetUpdateCommand(CommandType commandType) { DBCommandWrapper dbCommandWrapper; // Create the Database object, using the default database service. The // default database service is determined through configuration. Database db = GetDatabase(); switch(commandType) { case CommandType.StoredProcedure: string sqlCommand = this.SchemaStoredProcedureWithSeparator + "<%= CreateProcedureName(objTable, "U") %>"; dbCommandWrapper = db.GetStoredProcCommandWrapper(sqlCommand); <% output.tabLevel = 5 For Each objColumn in objTable.PrimaryKeys name = GetActualName(objColumn) alias = GetAlias(objColumn) isAutoKey = objColumn.IsAutoKey If props.ContainsKey("SEQ:I:" & objColumn.Name) Then isAutoKey = True End if If isAutoKey Then output.autoTabLn "dbCommandWrapper.AddInParameter(""" & name & """, " & objColumn.DbTargetType & ", """ & name & """, DataRowVersion.Current);" End If Next %> CreateParameters(dbCommandWrapper); return dbCommandWrapper; case CommandType.Text: this.Query.ClearAll(); foreach(SchemaItem item in this.SchemaEntries) { if (!(item.IsAutoKey || item.IsComputed)) { this.Query.AddUpdateColumn(item); } } this.Where.WhereClauseReset(); <% output.tabLevel = 5 For Each objColumn in objTable.Columns name = GetActualName(objColumn) alias = GetAlias(objColumn) isRowID = False If props.ContainsKey("SEQ:U:" & objColumn.Name) Then isRowID = True End if If objColumn.IsInPrimaryKey Or objColumn.DataTypeName = "timestamp" Or isRowID Then output.autoTabLn "this.Where." & alias & ".Operator = WhereParameter.Operand.Equal;" End If Next %> dbCommandWrapper = this.Query.GetUpdateCommandWrapper(); dbCommandWrapper.Command.Parameters.Clear(); CreateParameters(dbCommandWrapper); <% output.tabLevel = 5 For Each objColumn in objTable.PrimaryKeys name = GetActualName(objColumn) alias = GetAlias(objColumn) isAutoKey = objColumn.IsAutoKey If props.ContainsKey("SEQ:I:" & objColumn.Name) Then isAutoKey = True End if If isAutoKey Then output.autoTabLn "dbCommandWrapper.AddInParameter(""" & name & """, " & objColumn.DbTargetType & ", """ & name & """, DataRowVersion.Current);" End If Next %> return dbCommandWrapper; default: throw new ArgumentException("Invalid CommandType", "commandType"); } } protected override DBCommandWrapper GetDeleteCommand(CommandType commandType) { DBCommandWrapper dbCommandWrapper; // Create the Database object, using the default database service. The // default database service is determined through configuration. Database db = GetDatabase(); switch(commandType) { case CommandType.StoredProcedure: string sqlCommand = this.SchemaStoredProcedureWithSeparator + "<%= CreateProcedureName(objTable, "D") %>"; dbCommandWrapper = db.GetStoredProcCommandWrapper(sqlCommand); <% output.tabLevel = 5 For Each objColumn in objTable.PrimaryKeys name = GetActualName(objColumn) alias = GetAlias(objColumn) output.autoTabLn "dbCommandWrapper.AddInParameter(""" & name & """, " & objColumn.DbTargetType & ", """ & name & """, DataRowVersion.Current);" Next %> return dbCommandWrapper; case CommandType.Text: this.Query.ClearAll(); this.Where.WhereClauseReset(); <% output.tabLevel = 5 For Each objColumn in objTable.PrimaryKeys name = GetActualName(objColumn) alias = GetAlias(objColumn) output.autoTabLn "this.Where." & alias & ".Operator = WhereParameter.Operand.Equal;" Next %> dbCommandWrapper = this.Query.GetDeleteCommandWrapper(); dbCommandWrapper.Command.Parameters.Clear(); <% output.tabLevel = 5 For Each objColumn in objTable.PrimaryKeys name = GetActualName(objColumn) alias = GetAlias(objColumn) output.autoTabLn "dbCommandWrapper.AddInParameter(""" & name & """, " & objColumn.DbTargetType & ", """ & name & """, DataRowVersion.Current);" Next %> return dbCommandWrapper; default: throw new ArgumentException("Invalid CommandType", "commandType"); } } private void CreateParameters(DBCommandWrapper dbCommandWrapper) { <% output.tabLevel = 3 For Each objColumn in objTable.Columns name = GetActualName(objColumn) alias = GetAlias(objColumn) isAutoKey = objColumn.IsAutoKey If props.ContainsKey("SEQ:I:" & objColumn.Name) Then isAutoKey = True End if isRowID = False If props.ContainsKey("SEQ:U:" & objColumn.Name) Then isRowID = True End if If objColumn.IsComputed Then If objColumn.DataTypeName = "timestamp" Then output.autoTabLn "dbCommandWrapper.AddParameter(""" & name & """, DbType.Binary, 8, ParameterDirection.InputOutput, false, 0, 0, """ & name & """, DataRowVersion.Current, null);" ElseIf objColumn.LanguageType = "string" Then output.autoTabLn "dbCommandWrapper.AddParameter(""" & name & """, " & objColumn.DbTargetType & ", " & objColumn.CharacterMaxLength & ", ParameterDirection.Output, true, 0, 0, """ & name & """, DataRowVersion.Current, null);" Else output.autoTabLn "dbCommandWrapper.AddParameter(""" & name & """, " & objColumn.DbTargetType & ", ParameterDirection.Output, """ & name & """, DataRowVersion.Current, null);" End If ElseIf isAutoKey Then ' Skip auto keys ElseIf isRowID Then output.autoTabLn "dbCommandWrapper.AddParameter(""" & name & """, " & objColumn.DbTargetType & ", ParameterDirection.InputOutput, """ & name & """, DataRowVersion.Current, null);" Else output.autoTabLn "dbCommandWrapper.AddInParameter(""" & name & """, " & objColumn.DbTargetType & ", """ & name & """, DataRowVersion.Current);" End If Next %> } #region Properties <% output.tabLevel = 4 ' List all fields as member variables For Each objColumn In objTable.Columns name = GetName(objColumn) alias = GetAlias(objColumn) langType = GetFullType(objColumn) %> public virtual <%= objColumn.LanguageType %> <%= alias %> { get { <% If objColumn.LanguageType = "byte[]" Then output.autoTabLn "return this.GetByteArray(" & TrimSpaces(objTable.Alias) & "Schema." & alias & ".FieldName);" Else output.autoTabLn "return this.Get" & langType & "(" & TrimSpaces(objTable.Alias) & "Schema." & alias & ".FieldName);" End If %> } set { <% If objColumn.LanguageType = "byte[]" Then output.autoTabLn "this.SetByteArray(" & TrimSpaces(objTable.Alias) & "Schema." & alias & ".FieldName, value);" Else output.autoTabLn "this.Set" & langType & "(" & TrimSpaces(objTable.Alias) & "Schema." & alias & ".FieldName, value);" End If %> } } <% Next %> public override string TableName { get { return "<%= objTable.Name %>"; } } #endregion #region String Properties <% output.writeLn "" For Each objColumn in objTable.Columns langType = objColumn.LanguageType If Not InStr(1, langType, "[]") > 0 Then If Not langType = "object" And Not langType = "byte[]" Then pname = GetName(objColumn) name = GetAlias(objColumn) langType = GetFullType(objColumn) output.write " public virtual string s_" & name & vbCrLf output.write " {" & vbCrLf output.write " get" & vbCrLf output.write " {" & vbCrLf output.write " return this.IsColumnNull(" & TrimSpaces(objTable.Alias) & "Schema." & name & ".FieldName) ? string.Empty : base.Get" & langType & "AsString(" & TrimSpaces(objTable.Alias) & "Schema." & name & ".FieldName);" & vbCrLf output.write " }" & vbCrLf If (Not objColumn.DataTypeName = "timestamp" And Not objColumn.IsComputed) Then output.write " set" & vbCrLf output.write " {" & vbCrLf output.write " if(string.Empty == value)" & vbCrLf output.write " this.SetColumnNull(" & TrimSpaces(objTable.Alias) & "Schema." & name & ".FieldName);" & vbCrLf output.write " else" & vbCrLf output.write " this." & name & " = base.Set" & langType & "AsString(" & TrimSpaces(objTable.Alias) & "Schema." & name & ".FieldName, value);" & vbCrLf output.write " }" & vbCrLf End If output.write " }" & vbCrLf & vbCrLf End If End If Next %> #endregion #region Where Clause public class WhereClause { public WhereClause(EasyObject entity) { this._entity = entity; } public TearOffWhereParameter TearOff { get { if(_tearOff == null) { _tearOff = new TearOffWhereParameter(this); } return _tearOff; } } #region TearOff's public class TearOffWhereParameter { public TearOffWhereParameter(WhereClause clause) { this._clause = clause; } <% output.writeLn "" For Each objColumn in objTable.Columns alias = GetAlias(objColumn) output.write " public WhereParameter " & alias & vbCrLf output.write " {" & vbCrLf output.write " get" & vbCrLf output.write " {" & vbCrLf output.write " WhereParameter wp = new WhereParameter(" + TrimSpaces(objTable.Alias) + "Schema." + alias + ");" & vbCrLf output.write " this._clause._entity.Query.AddWhereParameter(wp);" & vbCrLf output.write " return wp;" & vbCrLf output.write " }" & vbCrLf output.write " }" & vbCrLf & vbCrLf Next %> private WhereClause _clause; } #endregion <% output.writeLn "" Dim fldName For Each objColumn in objTable.Columns name = GetAlias(objColumn) fldName = "_" & name & "_W" output.write " public WhereParameter " & name & vbCrLf output.write " {" & vbCrLf output.write " get" & vbCrLf output.write " {" & vbCrLf output.write " if(" & fldName & " == null)" & vbCrLf output.write " {" & vbCrLf output.write " " & fldName & " = TearOff." & name & ";" & vbCrLf output.write " }" & vbCrLf output.write " return " & fldName & ";" & vbCrLf output.write " }" & vbCrLf output.write " }" & vbCrLf & vbCrLf Next For Each objColumn in objTable.Columns name = "_" & GetAlias(objColumn) & "_W" output.write " private WhereParameter " & name & " = null;" & vbCrLf Next output.write vbCrLf output.write " public void WhereClauseReset()" & vbCrLf output.write " {" & vbCrLf For Each objColumn in objTable.Columns name = "_" & GetAlias(objColumn) & "_W" output.write " " & name & " = null;" & vbCrLf Next output.write vbCrLf output.write" this._entity.Query.FlushWhereParameters();" & vbCrLf & vbCrLf output.write" }" & vbCrLf %> private EasyObject _entity; private TearOffWhereParameter _tearOff; } public WhereClause Where { get { if(_whereClause == null) { _whereClause = new WhereClause(this); } return _whereClause; } } private WhereClause _whereClause = null; #endregion #region Aggregate Clause public class AggregateClause { public AggregateClause(EasyObject entity) { this._entity = entity; } public TearOffAggregateParameter TearOff { get { if(_tearOff == null) { _tearOff = new TearOffAggregateParameter(this); } return _tearOff; } } #region TearOff's public class TearOffAggregateParameter { public TearOffAggregateParameter(AggregateClause clause) { this._clause = clause; } <% output.writeLn "" For Each objColumn in objTable.Columns alias = GetAlias(objColumn) output.write " public AggregateParameter " & alias & vbCrLf output.write " {" & vbCrLf output.write " get" & vbCrLf output.write " {" & vbCrLf output.write " AggregateParameter ap = new AggregateParameter(" + TrimSpaces(objTable.Alias) + "Schema." + alias + ");" & vbCrLf output.write " this._clause._entity.Query.AddAggregateParameter(ap);" & vbCrLf output.write " return ap;" & vbCrLf output.write " }" & vbCrLf output.write " }" & vbCrLf & vbCrLf Next %> private AggregateClause _clause; } #endregion <% output.writeLn "" For Each objColumn in objTable.Columns name = GetAlias(objColumn) fldName = "_" & name & "_W" output.write " public AggregateParameter " & name & vbCrLf output.write " {" & vbCrLf output.write " get" & vbCrLf output.write " {" & vbCrLf output.write " if(" & fldName & " == null)" & vbCrLf output.write " {" & vbCrLf output.write " " & fldName & " = TearOff." & name & ";" & vbCrLf output.write " }" & vbCrLf output.write " return " & fldName & ";" & vbCrLf output.write " }" & vbCrLf output.write " }" & vbCrLf & vbCrLf Next For Each objColumn in objTable.Columns name = "_" & GetAlias(objColumn) & "_W" output.write " private AggregateParameter " & name & " = null;" & vbCrLf Next output.write vbCrLf output.write " public void AggregateClauseReset()" & vbCrLf output.write " {" & vbCrLf For Each objColumn in objTable.Columns name = "_" & GetAlias(objColumn) & "_W" output.write " " & name & " = null;" & vbCrLf Next output.write vbCrLf output.write" this._entity.Query.FlushAggregateParameters();" & vbCrLf & vbCrLf output.write" }" & vbCrLf %> private EasyObject _entity; private TearOffAggregateParameter _tearOff; } public AggregateClause Aggregate { get { if(_aggregateClause == null) { _aggregateClause = new AggregateClause(this); } return _aggregateClause; } } private AggregateClause _aggregateClause = null; #endregion } } <% ' Save the output file for this Table Dim filename filename = input.item("txtPath") Dim length Dim pos lenth = Len(filename) pos = InStrRev(filename, "\") If Not pos = lenth Then filename = filename & "\" End If If prefix = True Then filename = filename & "_" & TrimSpaces(objTable.Alias) & ".cs" Else filename = filename & TrimSpaces(objTable.Alias) & ".cs" End If output.save filename, false buffer = buffer & output.text output.clear Next ' tableName output.write buffer %> <% '=========================================================================== ' These are support routines called by the above scirpt '=========================================================================== Function GetAlias(objColumn) Dim name name = TrimSpaces(objColumn.Alias) GetAlias = UCase(Left(name, 1)) & Right(name, Len(name) -1) End Function Function GetName(objColumn) Dim name name = GetActualName(objColumn) GetName = UCase(Left(name, 1)) & Right(name, Len(name) -1) End Function Function GetActualName(objColumn) Dim name GetActualName = objColumn.Name End Function Function TrimSpaces(str) Dim tname Dim name Dim char Dim l name = "" tname = str l = Len(tname) For j = 1 To l char = Mid(tname, j, 1) If Not char = " " Then name = name & char End If Next TrimSpaces = name End Function Function GetParameterPrefix Select Case MyMeta.DbTarget Case "OleDb" GetParameterPrefix = "@" Case "SqlClient" GetParameterPrefix = "@" Case "OracleClient" GetParameterPrefix = "p_" Case "FirebirdSql" GetParameterPrefix = "@" End Select End Function Function CreateProcedureName(objTable, suffix) Dim bFirst Dim str bFirst = true Select Case suffix Case "L" str = "GetAll" Case "K" str = "Get" Case "U" str = "Update" Case "I" str = "Add" Case "D" str = "Delete" End Select CreateProcedureName = BuildProcedureName(BuildVerb(str, sStyle), objTable.Name, objTable.Alias) End Function Function BuildProcedureName(sVerb, sTableName, sTableAlias) Dim sName sName = Replace(sFormat, "{verb}", sVerb) sName = Replace(sName, "{table}", TrimSpaces(sTableName)) sName = Replace(sName, "{alias}", TrimSpaces(sTableAlias)) sName = Replace(sName, "{prefix}", sPrefix) BuildProcedureName = sName End Function Function BuildVerb(sVerb, sStyle) Select Case sStyle Case "doodads" Select Case sVerb Case "Get" sVerb = "LoadByPrimaryKey" Case "GetAll" sVerb = "LoadAll" Case "Add" sVerb = "Insert" End Select Case "daab" End Select BuildVerb = sVerb End Function Function GetFullType(objColumn) Select Case LCase(objColumn.LanguageType) Case "string" GetFullType = "String" Case "int" GetFullType = "Integer" Case "short" GetFullType = "Short" Case "decimal" GetFullType = "Decimal" Case "double" GetFullType = "Double" Case "datetime" GetFullType = "DateTime" Case "byte[]" GetFullType = "Byte" Case "byte" GetFullType = "Byte" Case "bool" GetFullType = "Boolean" Case "float" GetFullType = "Float" Case "long" GetFullType = "Long" Case Else GetFullType = objColumn.LanguageType End Select End Function Function GetParameterSize(objColumn) Select Case objColumn.DbTargetType Case "DbType.Int32" GetParameterSize = "4" Case "DbType.Binary" GetParameterSize = "8" Case "DbType.Guid" GetParameterSize = "16" Case "DbType.StringFixedLength", "DbType.AnsiStringFixedLength", "DbType.String", "DbType.AnsiString" GetParameterSize = objColumn.CharacterMaxLength Case Else GetParameterSize = "0" End Select End Function Function ConvertToBoolean(test) If test Then ConvertToBoolean = "true" Else ConvertToBoolean = "false" End If End Function %>
Dynamic Interface:
Engine:
Microsoft Script
Language:
VBScript
Dim cmbDatabases Dim lstTables Dim chk Dim cmbFormat Dim txtFormat Dim txtPrefix Sub setup() If context.Objects.ContainsKey("DnpUtils") Then DnpUtils.ReadInputFromCache(context) End if If Not input.Contains("lstTables") Or Not input.Contains("txtPath") Then ui.Title = "Generate C# EasyObject from a Table." ui.Width = 330 ui.Height = 640 ' Grab default output path Dim sOutputPath sOutputPath = "" If input.Contains("defaultOutputPath") Then sOutputPath = input.Item("defaultOutputPath") End If ui.AddLabel "lblPath", "Output file path: ", "Select the output path." ui.AddTextBox "txtPath", sOutputPath, "Select the Output Path." ui.AddFilePicker "btnPath", "Select Path", "Select the Output Path.", "txtPath", true ui.AddLabel "lblNamespace", "Namespace: ", "Provide your objects namespace." ui.AddTextBox "txtNamespace", "Your.Namespace", "Provide your objects namespace." ' List Databases in a ComboBox ui.AddLabel "lblDatabases", "Select a database:", "Select a database in the dropdown below." Set cmbDatabases = ui.AddComboBox("cmbDatabase", "Select a database.") ' List Tables in a listbox ui.AddLabel "lblTables", "Select tables:", "Select tables from the listbox below." Set lstTables = ui.AddListBox ("lstTables", "Select tables:") 'lstTables.IsMultiSelect = false lstTables.Height = 120 ' Prefix ui.AddLabel "lblPrefix", "Procedure prefix:", "Enter a procedure prefix." Set txtPrefix = ui.AddTextBox("txtPrefix", "", "Enter the procedure prefix") ' List proc formats ui.AddLabel "lblFormat", "Select procedure format:", "Select a procedure format from the listbox below." Set cmbFormat = ui.AddComboBox("cmbFormat", "Select a procedure format.") cmbFormat.AttachEvent "onchange", "cmbFormat_onchange" Set txtFormat = ui.AddTextBox("txtFormat", "", "Enter the procedure format") txtFormat.Enabled = false setupFormatDropdown cmbFormat Set prefix = ui.AddCheckBox("prefix", "Prefix class with underscore?", true, "If checked, the file on disk will begin with an underscore") If MyMeta.DriverString = "FIREBIRD" Then Set chk = ui.AddCheckBox("ckDialect3", "DIALECT 3", false, "If checked, the stored procedure will use dialect 3 syntax") chk.forecolor = "red" End If ' Attach the onchange event to the cmbDatabases control. setupDatabaseDropdown cmbDatabases ui.ShowGUI = true Else ui.ShowGUI = false End if End Sub Sub setupDatabaseDropdown(cmbDatabases) cmbDatabases.BindData MyMeta.Databases If Not MyMeta.DefaultDatabase Is Nothing Then cmbDatabases.SelectedValue = MyMeta.DefaultDatabase.Name bindTables cmbDatabases.SelectedValue End If cmbDatabases.AttachEvent "onchange", "cmbDatabases_onchange" End Sub Sub bindTables(sDatabase) Set db = MyMeta.Databases(sDatabase) lstTables.BindData(db.Tables) End Sub ' Event Handler Sub cmbDatabases_onchange(control) Set cmbDatabases = ui.item("cmbDatabase") bindTables cmbDatabases.SelectedText End Sub Sub setupFormatDropdown(cmbFormat) cmbFormat.Add "daab", "ASP.NET Starter Kits" cmbFormat.Add "doodads", "dOOdads" cmbFormat.Add "custom", "Custom" cmbFormat.SelectedValue = "daab" cmbFormat_onchange(cmbFormat) End Sub Sub cmbFormat_onchange(control) txtFormat.Enabled = False Select Case cmbFormat.SelectedValue Case "daab" txtFormat.Text = "{prefix}{verb}{table}" txtPrefix.Text = "daab_" Case "doodads" txtFormat.Text = "{prefix}{table}{verb}" txtPrefix.Text = "proc_" Case "custom" txtFormat.Enabled = True End Select End Sub
Copyright © 2004 MyGeneration Software. All rights reserved.
Feedback:
feedback@mygenerationsoftware.com
Support:
support@mygenerationsoftware.com