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: DAAB C# Business Entity 2.0
Download Count:
9101
View Count:
6052
Template Properties
Unique ID:
2d90f9de-f4af-4eee-beef-cb3531dbd64f
Title:
DAAB C# Business Entity 2.0
Namespace:
DAAB.C#
Output Language:
C#
Mode:
Markup
Start Tag:
<%
End Tag:
%>
Template Body
Engine:
Microsoft Script
Language:
VBScript
<% '------------------------------------------------------------------------------ ' New Version For Enterprise Library - January 2006 y Framework 2.0 ' Last Update : Ago/24/2006 ' Updated by : Jose Lopez '------------------------------------------------------------------------------ ' 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. '------------------------------------------------------------------------------ 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 IDbCommand Dim IDataParameter Dim ParameterPrefix Dim dialect If context.Objects.ContainsKey("DnpUtils") Then DnpUtils.SaveInputToCache(context) End if 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") 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_DAAB_BusinessEntity.vbgen ' ' ** IMPORTANT ** ' How to Generate your stored procedures: ' ' SQL = SQL_DAAB_Net2_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 : YourObjectBase ' { ' ' } ' '=============================================================================== */ // 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 System.Data.Common; namespace <%= TrimSpaces(namespace) %> { public abstract class <%= TrimSpaces(objTable.Alias) %>Base { #region < VARIABLES > <% output.tabLevel = 2 ' List all fields as member variables For Each objColumn In objTable.Columns name = GetName(objColumn) alias = GetAlias(objColumn) output.autoTabLn "private " & objColumn.LanguageType & " _" & alias & ";" Next %> private bool _isNew; #endregion #region < CONSTRUCTORES > protected <%= TrimSpaces(objTable.Alias) %>Base(<% output.write ")" & vbCrLf output.tabLevel = 2 output.autoTabLn "{" output.tabLevel = 3 For Each objColumn in objTable.PrimaryKeys alias = GetAlias(objColumn) output.autoTabLn "_" & alias & " = " & GetNullValueDefault(objColumn) & ";" Next For Each objColumn in objTable.Columns If objColumn.IsNullable Then alias = GetAlias(objColumn) output.autoTabLn "_" & alias & " = " & GetNullValueDefault(objColumn) & ";" End If Next output.tabLevel = 2 output.autoTabLn "}" %> protected <%= TrimSpaces(objTable.Alias) %>Base(<% 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 output.write ") : this()" & vbCrLf output.tabLevel = 2 output.autoTabLn "{" output.tabLevel = 3 For Each objColumn in objTable.PrimaryKeys alias = GetAlias(objColumn) output.autoTabLn "_" & alias & " = " & alias & ";" Next output.tabLevel = 2 output.autoTabLn "}" If bOtherColumns Then %> protected <%= TrimSpaces(objTable.Alias) %>Base(<% ' List all fields as parameters bFirst = true For Each objColumn in objTable.Columns If Not objColumn.IsComputed Then If Not bFirst Then output.write ", " End If alias = GetAlias(objColumn) output.write objColumn.LanguageType & " " & alias bFirst = False End If Next output.write ") : this()" & vbCrLf output.tabLevel = 2 output.autoTabLn "{" output.tabLevel = 3 For Each objColumn in objTable.Columns If Not objColumn.IsComputed Then alias = GetAlias(objColumn) output.autoTabLn "_" & alias & " = " & alias & ";" End If Next output.tabLevel = 2 output.autoTabLn "}" End If %> #endregion #region < Metodos para Obtención de Detalles > <% For Each objFK in objTable.ForeignKeys if objFK.ForeignTable = objTable.Name then %> public static DataTable GetBy<%=objFK.PrimaryTable %>(<% bFirst = true 'objFK.ForeignTable & "_" & poner ^ For Each objColumn in objFK.ForeignColumns If Not bFirst Then output.write ", " End If output.write objColumn.LanguageType & " " & GetAlias(objColumn) bFirst = false Next %>) { Database db = DatabaseFactory.CreateDatabase(); string sqlCommand = "Select * From <%=objFK.ForeignTable %> Where <% bFirst = true For Each objColumn in objFK.ForeignColumns name = GetName(objColumn) alias = GetAlias(objColumn) If Not bFirst Then output.write ", " End If output.write name & " = " & GetParameterPrefix & name bFirst = false Next %>"; DbCommand dbCommandWrapper = db.GetSqlStringCommand(sqlCommand); <% output.tabLevel = 3 For Each objColumn in objFK.ForeignColumns name = GetName(objColumn) alias = GetAlias(objColumn) output.autoTabLn "db.AddInParameter(dbCommandWrapper, """ & GetParameterPrefix & name & """, " & objColumn.DbTargetType & ", " & GetAlias(objColumn) & ");" next %> DataTable t = db.ExecuteDataSet(dbCommandWrapper).Tables[0]; <% For Each col in objFK.ForeignColumns output.autoTabLn "t.Columns[""" & GetName(col) & """].DefaultValue = " & GetAlias(col) & ";" next%> return t; } <% end if next %> #endregion #region < PROPIEDADES > <% For Each objColumn in objTable.Columns name = GetName(objColumn) alias = GetAlias(objColumn) %> public <%= objColumn.LanguageType %> <%= alias %> { get { return _<%= alias %>; } <% output.tabLevel = 3 If Not objColumn.IsComputed Then output.autoTabLn "set { _" & alias & " = value; }" End If %> } <% Next %> public bool IsNew { get { <% output.tabLevel = 4 bFirst = true For Each objColumn in objTable.PrimaryKeys If objColumn.IsAutoKey Then If Not bFirst Then output.write " && " Else output.autoTab "_isNew = (" End If output.write "_" & GetAlias(objColumn) & " == " & GetEmptyValue(objColumn) bFirst = false End If Next If Not bFirst Then output.writeLn ");" %> return _isNew; } set { _isNew = value; } } #endregion #region Utilerias public static bool Existe(<% 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 output.write ")" %> { Database db = DatabaseFactory.CreateDatabase(); string sqlCommand = "<%= CreateProcedureName(objTable, "E") %>"; DbCommand dbCommandWrapper = db.GetStoredProcCommand(sqlCommand); // Add in parameters <% If objTable.PrimaryKeys.Count > 0 Then output.tabLevel = 3 For Each objColumn in objTable.PrimaryKeys name = GetName(objColumn) alias = GetAlias(objColumn) output.autoTabLn "db.AddInParameter(dbCommandWrapper, """ & GetParameterPrefix & name & """, " & objColumn.DbTargetType & ", " & GetAlias(objColumn) & ");" Next End If %> // DataSet that will hold the returned results // Note: connection closed by ExecuteDataSet method call bool ret = false; int num = Convert.ToInt32(db.ExecuteScalar(dbCommandWrapper)); ret = num > 0; return ret; } public static DataTable GetAll<%= TrimSpaces(objTable.Name) %>() { Database db = DatabaseFactory.CreateDatabase(); string sqlCommand = "daab_GetAll<%=TrimSpaces(objTable.Name) %>"; DbCommand dbCommandWrapper = db.GetStoredProcCommand(sqlCommand); DataTable ret = db.ExecuteDataSet(dbCommandWrapper).Tables[0]; <% if objTable.PrimaryKeys.Count > 0 then %> ret.PrimaryKey = new DataColumn[] { <% bFirst = true For Each objColumn in objTable.PrimaryKeys If Not bFirst Then output.write ", " End If output.write "ret.Columns[""" & GetName(objColumn) & """]" bFirst = false Next %> }; <% end if %> return ret; } public static void SaveAll(DataTable tabla) { Database db = DatabaseFactory.CreateDatabase(); DbDataAdapter da = db.GetDataAdapter(); da.SelectCommand = db.GetStoredProcCommand("daab_GetAll<%=TrimSpaces(objTable.Name) %>"); da.InsertCommand = db.GetStoredProcCommand("daab_Add<%=TrimSpaces(objTable.Name) %>"); da.UpdateCommand = db.GetStoredProcCommand("daab_Update<%=TrimSpaces(objTable.Name) %>"); da.DeleteCommand = db.GetStoredProcCommand("daab_Delete<%=TrimSpaces(objTable.Name) %>"); #region Parametros de InsertCommand <% If objTable.PrimaryKeys.Count > 0 Then output.tabLevel = 3 For Each objColumn in objTable.Columns name = GetName(objColumn) alias = GetAlias(objColumn) If objColumn.IsComputed Or (objColumn.IsInPrimaryKey And objColumn.IsAutoKey) Then output.autoTabLn "db.AddOutParameter(da.InsertCommand, """ & GetParameterPrefix & name & """, " & objColumn.DbTargetType & ", " & GetParameterSize(objColumn) & ");" Else output.autoTabLn "db.AddInParameter(da.InsertCommand, """ & GetParameterPrefix & name & """, " & objColumn.DbTargetType & ", """ & name & """, DataRowVersion.Default);" End If Next End If %> #endregion #region Parametros de UpdateCommand <% output.tabLevel = 3 For Each objColumn in objTable.Columns name = GetName(objColumn) alias = GetAlias(objColumn) If objColumn.IsComputed Then output.autoTabLn "db.AddOutParameter(da.UpdateCommand, """ & GetParameterPrefix & name & """, " & objColumn.DbTargetType & ", " & GetParameterSize(objColumn) & ");" Else output.autoTabLn "db.AddInParameter(da.UpdateCommand, """ & GetParameterPrefix & name & """, " & objColumn.DbTargetType & ", """ & name & """, DataRowVersion.Default);" End If Next %> #endregion #region Parametros de DeleteCommand <% If objTable.PrimaryKeys.Count > 0 Then output.tabLevel = 3 For Each objColumn in objTable.PrimaryKeys name = GetName(objColumn) alias = GetAlias(objColumn) output.autoTabLn "db.AddInParameter(da.DeleteCommand, """ & GetParameterPrefix & name & """, " & objColumn.DbTargetType & ", """ & name & """, DataRowVersion.Default);" Next End If %> #endregion db.UpdateDataSet(tabla.DataSet, tabla.TableName, da.InsertCommand, da.UpdateCommand, da.DeleteCommand, UpdateBehavior.Standard); } #endregion /// <summary> /// Populates a dataset 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 DataSet containing the results of the query</returns> private DataSet 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 output.write ")" & vbCrLf %> { // Create the Database object, using the default database service. The // default database service is determined through configuration. Database db = DatabaseFactory.CreateDatabase(); string sqlCommand = "<%= CreateProcedureName(objTable, "K") %>"; DbCommand dbCommandWrapper = db.GetStoredProcCommand(sqlCommand); // Add in parameters <% If objTable.PrimaryKeys.Count > 0 Then output.tabLevel = 3 For Each objColumn in objTable.PrimaryKeys name = GetName(objColumn) alias = GetAlias(objColumn) output.autoTabLn "db.AddInParameter(dbCommandWrapper, """ & GetParameterPrefix & name & """, " & objColumn.DbTargetType & ", " & GetAlias(objColumn) & ");" Next End If %> // DataSet that will hold the returned results // Note: connection closed by ExecuteDataSet method call return db.ExecuteDataSet(dbCommandWrapper); } /// <summary> /// Populates current instance of the 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 %> public virtual void Load(<% 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 output.write ")" & vbCrLf %> { // DataSet that will hold the returned results DataSet ds = this.LoadByPrimaryKey(<% bFirst = true For Each objColumn in objTable.PrimaryKeys If Not bFirst Then output.write ", " End If output.write GetAlias(objColumn) bFirst = false Next %>); // Load member variables from datarow DataRow row = ds.Tables[0].Rows[0]; <% output.tabLevel = 3 For Each objColumn in objTable.Columns alias = GetAlias(objColumn) If objColumn.LanguageType = "Guid" Then If objColumn.IsNullable Then output.autoTabLn "_" & alias & " = row.IsNull(""" & alias & """) ? " & GetNullValueDefault(objColumn) & " : (" & objColumn.LanguageType & ")row[""" & alias & """];" Else output.autoTabLn "_" & alias & " = (" & objColumn.LanguageType & ")row[""" & alias & """];" End If ElseIf objColumn.LanguageType = "byte[]" Then If objColumn.IsNullable Then output.autoTabLn "_" & alias & " = row.IsNull(""" & alias & """) ? new byte[] {} : row[""" & alias & """] as byte[];" Else output.autoTabLn "_" & alias & " = row[""" & alias & """] as byte[];" End If ElseIf objColumn.LanguageType = "short" Then If objColumn.IsNullable Then output.autoTabLn "_" & alias & " = row.IsNull(""" & alias & """) ? (short)" & GetNullValueDefault(objColumn) & " : (" & objColumn.LanguageType & ")row[""" & alias & """];" Else output.autoTabLn "_" & alias & " = (" & objColumn.LanguageType & ")row[""" & alias & """];" End If Else If objColumn.IsNullable Then output.autoTabLn "_" & alias & " = row.IsNull(""" & alias & """) ? " & GetNullValueDefault(objColumn) & " : (" & objColumn.LanguageType & ")row[""" & alias & """];" Else output.autoTabLn "_" & alias & " = (" & objColumn.LanguageType & ")row[""" & alias & """];" End If End If Next %> } /// <summary> /// Adds or updates information in the database depending on the primary key stored in the object instance. /// </summary> /// <returns>Returns True if saved successfully, False otherwise.</returns> public bool Save() { if (this.IsNew) return Insert(); else return Update(); } /// <summary> /// Inserts the current instance data into the database. /// </summary> /// <returns>Returns True if saved successfully, False otherwise.</returns> private bool Insert() { // Create the Database object, using the default database service. The // default database service is determined through configuration. Database db = DatabaseFactory.CreateDatabase(); string sqlCommand = "<%= CreateProcedureName(objTable, "I") %>"; DbCommand dbCommandWrapper = db.GetStoredProcCommand(sqlCommand); // Add parameters <% If objTable.PrimaryKeys.Count > 0 Then output.tabLevel = 3 For Each objColumn in objTable.Columns name = GetName(objColumn) alias = GetAlias(objColumn) If objColumn.IsComputed Or (objColumn.IsInPrimaryKey And objColumn.IsAutoKey) Then output.autoTabLn "db.AddOutParameter(dbCommandWrapper, """ & GetParameterPrefix & name & """, " & objColumn.DbTargetType & ", " & GetParameterSize(objColumn) & ");" Else If objColumn.IsNullable Then If objColumn.LanguageType = "byte[]" Then output.autoTabLn "db.AddInParameter(dbCommandWrapper, """ & GetParameterPrefix & name & """, " & objColumn.DbTargetType & ", SetNullValue((_" & alias & ".Length == 0), _" & alias & "));" Else output.autoTabLn "db.AddInParameter(dbCommandWrapper, """ & GetParameterPrefix & name & """, " & objColumn.DbTargetType & ", SetNullValue((_" & alias & " == " & GetNullValueDefault(objColumn) & "), _" & alias & "));" End If Else output.autoTabLn "db.AddInParameter(dbCommandWrapper, """ & GetParameterPrefix & name & """, " & objColumn.DbTargetType & ", _" & alias & ");" End If End If Next End If %> db.ExecuteNonQuery(dbCommandWrapper); <% output.tabLevel = 3 bFirst = True For Each objColumn in objTable.Columns If (objColumn.IsInPrimaryKey And objColumn.IsAutoKey) Or objColumn.IsComputed Then If bFirst Then output.autoTabLn "" output.autoTabLn "// Save output parameter values" output.autoTabLn "object param;" bFirst = False End If name = GetName(objColumn) alias = GetAlias(objColumn) output.autoTabLn "param = db.GetParameterValue(dbCommandWrapper, """ & GetParameterPrefix & name & """);" output.autoTabLn "if (param == DBNull.Value) return false;" If objColumn.LanguageType = "Guid" Then output.autoTabLn "_" & alias & " = (" & objColumn.LanguageType & ")param;" ElseIf objColumn.LanguageType = "byte[]" Then output.autoTabLn "_" & alias & " = param as " & objColumn.LanguageType & ";" Else output.autoTabLn "_" & alias & " = (" & objColumn.LanguageType & ")param;" End If End If Next output.autoTabLn "" output.autoTabLn "return true;" %> } /// <summary> /// Updates the current instance data in the database. /// </summary> /// <returns>Returns True if saved successfully, False otherwise.</returns> public bool Update() { // Create the Database object, using the default database service. The // default database service is determined through configuration. Database db = DatabaseFactory.CreateDatabase(); string sqlCommand = "<%= CreateProcedureName(objTable, "U") %>"; DbCommand dbCommandWrapper = db.GetStoredProcCommand(sqlCommand); // Add parameters <% output.tabLevel = 3 For Each objColumn in objTable.Columns name = GetName(objColumn) alias = GetAlias(objColumn) If objColumn.IsComputed Then output.autoTabLn "db.AddOutParameter(dbCommandWrapper, """ & GetParameterPrefix & name & """, " & objColumn.DbTargetType & ", " & GetParameterSize(objColumn) & ");" Else If objColumn.IsNullable Then If objColumn.LanguageType = "byte[]" Then output.autoTabLn "db.AddInParameter(dbCommandWrapper, """ & GetParameterPrefix & name & """, " & objColumn.DbTargetType & ", SetNullValue((_" & alias & ".Length == 0), _" & alias & "));" Else output.autoTabLn "db.AddInParameter(dbCommandWrapper, """ & GetParameterPrefix & name & """, " & objColumn.DbTargetType & ", SetNullValue((_" & alias & " == " & GetNullValueDefault(objColumn) & "), _" & alias & "));" End If Else output.autoTabLn "db.AddInParameter(dbCommandWrapper, """ & GetParameterPrefix & name & """, " & objColumn.DbTargetType & ", _" & alias & ");" End If End If Next %> try { db.ExecuteNonQuery(dbCommandWrapper); <% output.tabLevel = 4 bFirst = True For Each objColumn in objTable.Columns If (objColumn.IsInPrimaryKey And objColumn.IsAutoKey) Or objColumn.IsComputed Then If bFirst Then output.autoTabLn "" output.autoTabLn "// Save output parameter values" output.autoTabLn "object param;" bFirst = False End If name = GetName(objColumn) alias = GetAlias(objColumn) output.autoTabLn "param = db.GetParameterValue(dbCommandWrapper, """ & GetParameterPrefix & name & """);" output.autoTabLn "if (param == DBNull.Value) return false;" If objColumn.LanguageType = "Guid" Then output.autoTabLn "_" & alias & " = (" & objColumn.LanguageType & ")param;" ElseIf objColumn.LanguageType = "byte[]" Then output.autoTabLn "_" & alias & " = param as " & objColumn.LanguageType & ";" Else output.autoTabLn "_" & alias & " = (" & objColumn.LanguageType & ")param;" End If End If Next output.autoTabLn "" output.autoTabLn "return true;" %> } catch { return false; } } /// <summary> /// Removes 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 %> public static void Remove(<% 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 output.write ")" & vbCrLf %> { // Create the Database object, using the default database service. The // default database service is determined through configuration. Database db = DatabaseFactory.CreateDatabase(); string sqlCommand = "<%= CreateProcedureName(objTable, "D") %>"; DbCommand dbCommandWrapper = db.GetStoredProcCommand(sqlCommand); // Add primary keys to command wrapper. <% If objTable.PrimaryKeys.Count > 0 Then output.tabLevel = 3 For Each objColumn in objTable.PrimaryKeys name = GetName(objColumn) alias = GetAlias(objColumn) output.autoTabLn "db.AddInParameter(dbCommandWrapper, """ & GetParameterPrefix & name & """, " & objColumn.DbTargetType & ", " & GetAlias(objColumn) & ");" Next End If %> db.ExecuteNonQuery(dbCommandWrapper); } /// <summary> /// Serializes the current instance data to an Xml string. /// </summary> /// <returns>A string containing the Xml representation of the object.</returns> virtual public string ToXml() { // DataSet that will hold the returned results DataSet ds = this.LoadByPrimaryKey(<% bFirst = true For Each objColumn in objTable.PrimaryKeys If Not bFirst Then output.write ", " End If output.write "_" & GetAlias(objColumn) bFirst = false Next %>); StringWriter writer = new StringWriter(); ds.WriteXml(writer); return writer.ToString(); } /// <summary> /// Utility function that returns a DBNull.Value if requested. The comparison is done inline /// in the Insert() and Update() functions. /// </summary> private object SetNullValue(bool isNullValue, object value) { if (isNullValue) return DBNull.Value; else return value; } } } <% ' 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) & "Base.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 alias alias = TrimSpaces(objColumn.Alias) GetAlias = UCase(Left(alias, 1)) & Right(alias, Len(alias) -1) End Function Function GetName(objColumn) Dim name name = objColumn.Name GetName = UCase(Left(name, 1)) & Right(name, Len(name) -1) 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 = "@" Case Else GetParameterPrefix = "@" End Select End Function Function CreateProcedureName(objTable, suffix) Dim bFirst Dim str bFirst = true Select Case suffix Case "L" str = "Get" Case "K" str = "Get" Case "U" str ="Update" Case "I" str = "Add" Case "D" str = "Delete" case "E" str = "Exists" End Select CreateProcedureName = "daab_" & str & TrimSpaces(objTable.Name) End Function Function GetFullType(objColumn) Select Case LCase(objColumn.LanguageType) Case "string" GetFullType = "String" Case "int" GetFullType = "Int32" Case "short" GetFullType = "Short" Case "decimal" GetFullType = "Decimal" Case "datetime" GetFullType = "DateTime" Case "byte[]" GetFullType = "Byte" Case "bool" GetFullType = "Boolean" Case Else GetFullType = objColumn.LanguageType End Select End Function Function GetEmptyValue(objColumn) Select Case objColumn.DbTargetType Case "DbType.Int16", "DbType.Int32", "DbType.Int64", "DbType.Decimal", "DbType.Double", "DbType.Currency", "DbType.Single" GetEmptyValue = "0" Case "DbType.Guid" GetEmptyValue = "Guid.Empty" Case "DbType.StringFixedLength", "DbType.AnsiStringFixedLength", "DbType.String", "DbType.AnsiString" GetEmptyValue = "string.Empty" Case Else GetEmptyValue = Replace(objColumn.DbTargetType, "DbType.", "") 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 GetNullValueDefault(objColumn) Select Case objColumn.DbTargetType Case "DbType.Int16", "DbType.Int32", "DbType.Int64", "DbType.Decimal", "DbType.Double", "DbType.Currency", "DbType.Single" GetNullValueDefault = "0" Case "DbType.Guid" GetNullValueDefault = "Guid.Empty" Case "DbType.StringFixedLength", "DbType.AnsiStringFixedLength", "DbType.String", "DbType.AnsiString" GetNullValueDefault = "string.Empty" Case "DbType.DateTime" GetNullValueDefault = "DateTime.Parse(""01/01/1900"")" Case "DbType.Boolean" GetNullValueDefault = "false" Case "DbType.Binary", "DbType.Byte" GetNullValueDefault = "new byte[] {}" Case "DbType.Object" GetNullValueDefault = "null" Case Else GetNullValueDefault = objColumn.DbTargetType '"string.Empty" End Select End Function %>
Dynamic Interface:
Engine:
Microsoft Script
Language:
VBScript
Dim cmbDatabases Dim lstTables Dim chk 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# dOOdad from a Table." ui.Width = 330 ui.Height = 440 ' 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 '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
Copyright © 2004 MyGeneration Software. All rights reserved.
Feedback:
feedback@mygenerationsoftware.com
Support:
support@mygenerationsoftware.com