private static void WriteTables(ref StringBuilder nSourceCode, XsdDataBase nDataBaseMap, XsdDataBase.TBL_ObjectRow[] nObjetos) { foreach (var Objeto in nObjetos) { var ObjetNameFormated = FormatCode.ToIdentifier(Objeto.Object_Name); var ObjetNameFormatedType = ObjetNameFormated + "Table"; DataBaseClassWriter.Write(nSourceCode, 2, "/// <summary>"); DataBaseClassWriter.Write(nSourceCode, 2, "/// Clase encargada de encapsular las funcionalidades de acceso a la tabla " + Objeto.Object_Name); DataBaseClassWriter.Write(nSourceCode, 2, "/// </summary>"); DataBaseClassWriter.Write(nSourceCode, 2, "public class " + ObjetNameFormatedType + " : TableManager"); DataBaseClassWriter.Write(nSourceCode, 2, "{"); // Constructores DataBaseClassWriter.Write(nSourceCode, 3, "#region Constructores"); DataBaseClassWriter.Write(nSourceCode, 0, ""); DataBaseClassWriter.Write(nSourceCode, 3, "internal " + ObjetNameFormatedType + "(SchemaManager nSchemaManager)"); DataBaseClassWriter.Write(nSourceCode, 4, ": base(nSchemaManager)"); DataBaseClassWriter.Write(nSourceCode, 3, "{"); DataBaseClassWriter.Write(nSourceCode, 4, "base._ObjectName = \"" + Objeto.Object_Name + "\";"); DataBaseClassWriter.Write(nSourceCode, 3, "}"); DataBaseClassWriter.Write(nSourceCode, 0, ""); DataBaseClassWriter.Write(nSourceCode, 3, "#endregion"); DataBaseClassWriter.Write(nSourceCode, 0, ""); DataBaseClassWriter.Write(nSourceCode, 3, "#region Metodos"); DataBaseClassWriter.Write(nSourceCode, 0, ""); // Llaves primarias var PrimaryKeys = nDataBaseMap.GetPrimaryKeys(Objeto); // Columnas var TableColumns = nDataBaseMap.GetTableColumns(Objeto); // Identificador unico de la tabla ( Puede hacer parte de una llave compuesta ) var KeyParam = nDataBaseMap.GetIdOnPrimaryKey(Objeto); // LLaves foraneas que se encuentran en la llave primaria //var nPrimaryForeingKeys = nDataBaseMap.GetForeignsOnPrimaryKeys(Objeto); // Implementacion de DBInsert WriteDBInsert(ref nSourceCode, TableColumns); WriteDBInsertTyped(ref nSourceCode, TableColumns, Objeto.Object_Name); WriteDBInsertRow(ref nSourceCode, TableColumns, Objeto.Object_Name); foreach (var Key in KeyParam) { // Implementacion de DBNextId WriteDBNextId(ref nSourceCode, PrimaryKeys, Key, KeyParam.Count > 1); // Implementacion de DBSaveTableAutoNextId WriteDBSaveTableAutoNextId(ref nSourceCode, TableColumns, PrimaryKeys, Key, KeyParam.Count > 1); WriteDBSaveTableAutoNextIdTyped(ref nSourceCode, TableColumns, PrimaryKeys, Key, ObjetNameFormated, KeyParam.Count > 1); } // Implementacion de DBUpdate WriteDBUpdate(ref nSourceCode, TableColumns, PrimaryKeys); WriteDBUpdateTyped(ref nSourceCode, TableColumns, PrimaryKeys, Objeto.Object_Name); // Implementacion de DBSaveTable WriteDBSaveTable(ref nSourceCode, TableColumns, PrimaryKeys); WriteDBSaveTableTyped(ref nSourceCode, TableColumns, PrimaryKeys, ObjetNameFormated); // Implementacion de DBDelete WriteDBDelete(ref nSourceCode, PrimaryKeys); // Implementacion de DBGet WriteDBGet(ref nSourceCode, PrimaryKeys, ObjetNameFormated); WriteDBGetOrderBy(ref nSourceCode, PrimaryKeys, ObjetNameFormated); // Implementacion de DBFill WriteDBFill(ref nSourceCode, PrimaryKeys); WriteDBFillOrderBy(ref nSourceCode, PrimaryKeys, ObjetNameFormated); WriteDBFillTyped(ref nSourceCode, PrimaryKeys, ObjetNameFormated); WriteDBFillOrderByTyped(ref nSourceCode, PrimaryKeys, ObjetNameFormated); // Filtros var filtros = (XsdDataBase.TBL_FilterRow[]) (nDataBaseMap.TBL_Filter.Select("fk_Object = " + Objeto.id_Object)); foreach (var filtro in filtros) { int idMetodo = 0; // Implementacion de DBFind WriteDBFindBy(ref nSourceCode, nDataBaseMap, Objeto, ref idMetodo, filtro, ObjetNameFormated); WriteDBFindByOrderBy(ref nSourceCode, nDataBaseMap, Objeto, ref idMetodo, filtro, ObjetNameFormated); // Implementacion de DBFillBy WriteDBFillBy(ref nSourceCode, nDataBaseMap, Objeto, ref idMetodo, filtro); WriteDBFillByOrderBy(ref nSourceCode, nDataBaseMap, Objeto, ref idMetodo, filtro, ObjetNameFormated); } DataBaseClassWriter.Write(nSourceCode, 3, "#endregion"); DataBaseClassWriter.Write(nSourceCode, 2, "}"); // Fin de la clase DataBaseClassWriter.Write(nSourceCode, 0, ""); } }
private static void WriteDataTables(ref StringBuilder nSourceCode, XsdDataBase nDataBaseMap, XsdDataBase.TBL_ObjectRow[] tablas, bool IsMobile, bool UseFramework2) { var idMetodo = 0; foreach (var table in tablas) { DataBaseClassWriter.Write(nSourceCode, 2, "#region " + table.Object_Name); DataBaseClassWriter.Write(nSourceCode, 0, ""); var nPrimaryKeys = nDataBaseMap.GetPrimaryKeys(table); var ObjetNameFormated = FormatCode.ToIdentifier(table.Object_Name); var nInColumns = nDataBaseMap.GetTableColumns(table); DataBaseClassWriter.Write(nSourceCode, 1, "///<summary>"); DataBaseClassWriter.Write(nSourceCode, 1, "///Enumeración de las columnas de la tabla " + table.Object_Name); DataBaseClassWriter.Write(nSourceCode, 1, "///</summary>"); DataBaseClassWriter.Write(nSourceCode, 1, "public class " + ObjetNameFormated + "Enum : ColumnEnum"); DataBaseClassWriter.Write(nSourceCode, 1, "{"); foreach (var par in nInColumns) { DataBaseClassWriter.Write(nSourceCode, 2, "public static readonly " + ObjetNameFormated + "Enum " + FormatCode.ToIdentifier(par.Name) + " = new " + ObjetNameFormated + "Enum(\"" + par.Name + "\");"); } DataBaseClassWriter.Write(nSourceCode, 2, ObjetNameFormated + "Enum(string nColumnName) : base(nColumnName) { }"); DataBaseClassWriter.Write(nSourceCode, 1, "}"); DataBaseClassWriter.Write(nSourceCode, 1, "///<summary>"); DataBaseClassWriter.Write(nSourceCode, 1, "///Colección columnas enumeradas de la tabla " + table.Object_Name); DataBaseClassWriter.Write(nSourceCode, 1, "///</summary>"); DataBaseClassWriter.Write(nSourceCode, 1, "public class " + ObjetNameFormated + "EnumList : ColumnEnumList"); DataBaseClassWriter.Write(nSourceCode, 1, "{"); DataBaseClassWriter.Write(nSourceCode, 2, "public " + ObjetNameFormated + "EnumList() {}"); DataBaseClassWriter.Write(nSourceCode, 2, "public " + ObjetNameFormated + "EnumList(" + ObjetNameFormated + "Enum nColumn, bool nAscendente) { base.Add(nColumn, nAscendente); }"); DataBaseClassWriter.Write(nSourceCode, 1, "}"); DataBaseClassWriter.Write(nSourceCode, 1, "///<summary>"); DataBaseClassWriter.Write(nSourceCode, 1, "///Representa un DataTable tipado de la tabla " + table.Object_Name); DataBaseClassWriter.Write(nSourceCode, 1, "///</summary>"); DataBaseClassWriter.Write(nSourceCode, 1, "[Serializable()]"); if (UseFramework2) DataBaseClassWriter.Write(nSourceCode, 1, "public partial class " + ObjetNameFormated + "DataTable : CMData.Utils.TypedTable<" + ObjetNameFormated + "Row>"); else DataBaseClassWriter.Write(nSourceCode, 1, "public partial class " + ObjetNameFormated + "DataTable : System.Data.TypedTableBase<" + ObjetNameFormated + "Row>"); DataBaseClassWriter.Write(nSourceCode, 1, "{"); DataBaseClassWriter.Write(nSourceCode, 0, "#region Declaraciones"); foreach (var par in nInColumns) { DataBaseClassWriter.Write(nSourceCode, 2, "private global::System.Data.DataColumn column" + FormatCode.ToIdentifier(par.Name) + ";"); } DataBaseClassWriter.Write(nSourceCode, 0, "#endregion"); DataBaseClassWriter.Write(nSourceCode, 0, ""); DataBaseClassWriter.Write(nSourceCode, 0, "#region Propiedades"); foreach (var par in nInColumns) { DataBaseClassWriter.Write(nSourceCode, 2, "[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]"); DataBaseClassWriter.Write(nSourceCode, 2, "public global::System.Data.DataColumn " + FormatCode.ToIdentifier(par.Name) + "Column"); DataBaseClassWriter.Write(nSourceCode, 2, "{"); DataBaseClassWriter.Write(nSourceCode, 3, "get { return this.column" + FormatCode.ToIdentifier(par.Name) + "; }"); DataBaseClassWriter.Write(nSourceCode, 2, "}"); } DataBaseClassWriter.Write(nSourceCode, 0, ""); DataBaseClassWriter.Write(nSourceCode, 2, "[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]"); if (!IsMobile) DataBaseClassWriter.Write(nSourceCode, 2, "[global::System.ComponentModel.Browsable(false)]"); DataBaseClassWriter.Write(nSourceCode, 2, "public int Count"); DataBaseClassWriter.Write(nSourceCode, 2, "{"); DataBaseClassWriter.Write(nSourceCode, 3, "get { return this.Rows.Count; }"); DataBaseClassWriter.Write(nSourceCode, 2, "}"); DataBaseClassWriter.Write(nSourceCode, 2, "[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]"); DataBaseClassWriter.Write(nSourceCode, 2, "public " + ObjetNameFormated + "Row this[int index]"); DataBaseClassWriter.Write(nSourceCode, 2, "{"); DataBaseClassWriter.Write(nSourceCode, 3, "get { return (" + ObjetNameFormated + "Row)this.Rows[index]; }"); DataBaseClassWriter.Write(nSourceCode, 2, "}"); DataBaseClassWriter.Write(nSourceCode, 0, "#endregion"); DataBaseClassWriter.Write(nSourceCode, 0, ""); DataBaseClassWriter.Write(nSourceCode, 0, "#region Constructores"); DataBaseClassWriter.Write(nSourceCode, 2, "[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]"); DataBaseClassWriter.Write(nSourceCode, 2, "public " + ObjetNameFormated + "DataTable()"); DataBaseClassWriter.Write(nSourceCode, 3, ": base()"); DataBaseClassWriter.Write(nSourceCode, 2, "{"); DataBaseClassWriter.Write(nSourceCode, 3, "this.TableName = \"" + table.Object_Name + "\";"); DataBaseClassWriter.Write(nSourceCode, 3, "this.BeginInit();"); DataBaseClassWriter.Write(nSourceCode, 3, "this.InitClass();"); DataBaseClassWriter.Write(nSourceCode, 3, "this.EndInit();"); DataBaseClassWriter.Write(nSourceCode, 2, "}"); DataBaseClassWriter.Write(nSourceCode, 2, "[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]"); DataBaseClassWriter.Write(nSourceCode, 2, "internal " + ObjetNameFormated + "DataTable(global::System.Data.DataTable table)"); DataBaseClassWriter.Write(nSourceCode, 3, ": base()"); DataBaseClassWriter.Write(nSourceCode, 2, "{"); DataBaseClassWriter.Write(nSourceCode, 3, "this.TableName = table.TableName;"); DataBaseClassWriter.Write(nSourceCode, 3, "if(table.CaseSensitive != table.DataSet.CaseSensitive)"); DataBaseClassWriter.Write(nSourceCode, 3, "{"); DataBaseClassWriter.Write(nSourceCode, 4, "this.CaseSensitive = table.CaseSensitive;"); DataBaseClassWriter.Write(nSourceCode, 3, "}"); DataBaseClassWriter.Write(nSourceCode, 3, "if(table.Locale.ToString() != table.DataSet.Locale.ToString())"); DataBaseClassWriter.Write(nSourceCode, 4, "this.Locale = table.Locale;"); DataBaseClassWriter.Write(nSourceCode, 0, ""); DataBaseClassWriter.Write(nSourceCode, 3, "if(table.Namespace != table.DataSet.Namespace)"); DataBaseClassWriter.Write(nSourceCode, 4, "this.Namespace = table.Namespace;"); DataBaseClassWriter.Write(nSourceCode, 0, ""); DataBaseClassWriter.Write(nSourceCode, 3, "this.Prefix = table.Prefix;"); DataBaseClassWriter.Write(nSourceCode, 3, "this.MinimumCapacity = table.MinimumCapacity;"); DataBaseClassWriter.Write(nSourceCode, 2, "}"); if (!IsMobile) { DataBaseClassWriter.Write(nSourceCode, 2, "[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]"); DataBaseClassWriter.Write(nSourceCode, 2, "public " + ObjetNameFormated + "DataTable(global::System.Runtime.Serialization.SerializationInfo info, global::System.Runtime.Serialization.StreamingContext context)"); DataBaseClassWriter.Write(nSourceCode, 3, ":base(info, context)"); DataBaseClassWriter.Write(nSourceCode, 2, "{"); DataBaseClassWriter.Write(nSourceCode, 3, "this.InitVars();"); DataBaseClassWriter.Write(nSourceCode, 2, "}"); } DataBaseClassWriter.Write(nSourceCode, 2, ""); DataBaseClassWriter.Write(nSourceCode, 0, "#endregion"); DataBaseClassWriter.Write(nSourceCode, 0, ""); DataBaseClassWriter.Write(nSourceCode, 0, "#region Metodos"); DataBaseClassWriter.Write(nSourceCode, 2, "[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]"); DataBaseClassWriter.Write(nSourceCode, 2, "public void Remove" + ObjetNameFormated + "Row( " + ObjetNameFormated + "Row row)"); DataBaseClassWriter.Write(nSourceCode, 2, "{"); DataBaseClassWriter.Write(nSourceCode, 3, "this.Rows.Remove(row);"); DataBaseClassWriter.Write(nSourceCode, 2, "}"); DataBaseClassWriter.Write(nSourceCode, 2, "[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]"); DataBaseClassWriter.Write(nSourceCode, 2, "public void Add" + ObjetNameFormated + "Row(" + ObjetNameFormated + "Row row)"); DataBaseClassWriter.Write(nSourceCode, 2, "{"); DataBaseClassWriter.Write(nSourceCode, 3, "this.Rows.Add(row);"); DataBaseClassWriter.Write(nSourceCode, 2, "}"); DataBaseClassWriter.Write(nSourceCode, 2, "[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]"); DataBaseClassWriter.Write(nSourceCode, 2, "internal void InitVars()"); DataBaseClassWriter.Write(nSourceCode, 2, "{"); foreach (var par in nInColumns) { DataBaseClassWriter.Write(nSourceCode, 3, "this.column" + FormatCode.ToIdentifier(par.Name) + " = base.Columns[\"" + par.Name + "\"];"); } DataBaseClassWriter.Write(nSourceCode, 2, "}"); DataBaseClassWriter.Write(nSourceCode, 2, "[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]"); DataBaseClassWriter.Write(nSourceCode, 2, "private void InitClass()"); DataBaseClassWriter.Write(nSourceCode, 2, "{"); foreach (var par in nInColumns) { DataBaseClassWriter.Write(nSourceCode, 3, "this.column" + FormatCode.ToIdentifier(par.Name) + " = new global::System.Data.DataColumn(\"" + par.Name + "\", typeof(" + DataBaseClassWriter.GetApplicationStringType(par.Type, LanguajeType.CSharp, false) + "), null, global::System.Data.MappingType.Element);"); if (par.MaxLength > 0 && CMData.DataBase.DataBase.IsStringType(par) && table.Generic_Type != "View") DataBaseClassWriter.Write(nSourceCode, 3, "this.column" + FormatCode.ToIdentifier(par.Name) + ".MaxLength = " + par.MaxLength + ";"); DataBaseClassWriter.Write(nSourceCode, 3, "base.Columns.Add(this.column" + FormatCode.ToIdentifier(par.Name) + ");"); } var strLine = ""; if (table.Generic_Type != "View") { if (nPrimaryKeys.Count > 0) { strLine = ""; foreach (var par in nPrimaryKeys) { if (strLine != "") strLine += ", "; strLine += "this.column" + par.Name; } DataBaseClassWriter.Write(nSourceCode, 3, "this.Constraints.Add(new global::System.Data.UniqueConstraint(\"" + table.Object_Name + "Key1\", new global::System.Data.DataColumn[] { " + strLine + "}, true));"); } foreach (var par in nInColumns) { if (!par.IsNullable) DataBaseClassWriter.Write(nSourceCode, 3, "this.column" + FormatCode.ToIdentifier(par.Name) + ".AllowDBNull = false;"); } } DataBaseClassWriter.Write(nSourceCode, 2, "}"); DataBaseClassWriter.Write(nSourceCode, 0, ""); DataBaseClassWriter.Write(nSourceCode, 0, "#endregion"); DataBaseClassWriter.Write(nSourceCode, 0, ""); DataBaseClassWriter.Write(nSourceCode, 0, "#region Funciones"); var strLine2 = ""; if (nPrimaryKeys.Count > 0 && table.Generic_Type != "View") { strLine = ""; foreach (var par in nPrimaryKeys) { strLine += par.Name; } var strFunctionName = strLine; if (strFunctionName.Length > 500) { idMetodo++; strFunctionName = strFunctionName.Substring(0, 500) + idMetodo.ToString(); } strLine2 = ""; foreach (var par in nPrimaryKeys) { if (strLine2 != "") strLine2 += ", "; strLine2 += DataBaseClassWriter.GetApplicationStringType(par.Type, LanguajeType.CSharp, false) + " n" + par.Name; } DataBaseClassWriter.Write(nSourceCode, 2, "[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]"); DataBaseClassWriter.Write(nSourceCode, 2, "public " + ObjetNameFormated + "Row FindBy" + strFunctionName + "(" + strLine2 + ")"); DataBaseClassWriter.Write(nSourceCode, 2, "{"); strLine = ""; foreach (var par in nPrimaryKeys) { if (strLine != "") strLine += ", "; strLine += "n" + par.Name; } DataBaseClassWriter.Write(nSourceCode, 3, "return (" + ObjetNameFormated + "Row)this.Rows.Find(new object[] {" + strLine + "});"); DataBaseClassWriter.Write(nSourceCode, 2, "}"); } DataBaseClassWriter.Write(nSourceCode, 2, "[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]"); DataBaseClassWriter.Write(nSourceCode, 2, "public " + ObjetNameFormated + "Row New" + ObjetNameFormated + "Row()"); DataBaseClassWriter.Write(nSourceCode, 2, "{"); DataBaseClassWriter.Write(nSourceCode, 3, "return (" + ObjetNameFormated + "Row)this.NewRow();"); DataBaseClassWriter.Write(nSourceCode, 2, "}"); DataBaseClassWriter.Write(nSourceCode, 2, "[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]"); strLine = ""; strLine2 = ""; foreach (var par in nInColumns) { if (strLine != "") strLine += ", "; if (strLine2 != "") strLine2 += ", "; strLine += DataBaseClassWriter.GetApplicationStringType(par.Type, LanguajeType.CSharp, par.IsNullable) + " n" + par.Name; strLine2 += "DBNulls.GetPrimitiveObjectValue(n" + par.Name + ")"; } DataBaseClassWriter.Write(nSourceCode, 2, "public " + ObjetNameFormated + "Row Add" + ObjetNameFormated + "Row(" + strLine + ")"); DataBaseClassWriter.Write(nSourceCode, 2, "{"); DataBaseClassWriter.Write(nSourceCode, 3, FormatCode.ToIdentifier(table.Object_Name) + "Row row" + ObjetNameFormated + "Row = (" + ObjetNameFormated + "Row)this.NewRow();"); DataBaseClassWriter.Write(nSourceCode, 3, "object[] columnValuesArray = new object[] {" + strLine2 + "};"); DataBaseClassWriter.Write(nSourceCode, 3, "row" + ObjetNameFormated + "Row.ItemArray = columnValuesArray;"); DataBaseClassWriter.Write(nSourceCode, 3, "this.Rows.Add(row" + ObjetNameFormated + "Row);"); DataBaseClassWriter.Write(nSourceCode, 3, "return row" + ObjetNameFormated + "Row;"); DataBaseClassWriter.Write(nSourceCode, 2, "}"); DataBaseClassWriter.Write(nSourceCode, 2, "[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]"); DataBaseClassWriter.Write(nSourceCode, 2, "public override global::System.Data.DataTable Clone()"); DataBaseClassWriter.Write(nSourceCode, 2, "{"); DataBaseClassWriter.Write(nSourceCode, 3, FormatCode.ToIdentifier(table.Object_Name) + "DataTable cln = (" + ObjetNameFormated + "DataTable)base.Clone();"); DataBaseClassWriter.Write(nSourceCode, 3, "cln.InitVars();"); DataBaseClassWriter.Write(nSourceCode, 3, "return cln;"); DataBaseClassWriter.Write(nSourceCode, 2, "}"); DataBaseClassWriter.Write(nSourceCode, 2, "[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]"); DataBaseClassWriter.Write(nSourceCode, 2, "protected override global::System.Data.DataRow NewRowFromBuilder(global::System.Data.DataRowBuilder builder)"); DataBaseClassWriter.Write(nSourceCode, 2, "{"); DataBaseClassWriter.Write(nSourceCode, 3, "return new " + ObjetNameFormated + "Row(builder);"); DataBaseClassWriter.Write(nSourceCode, 2, "}"); DataBaseClassWriter.Write(nSourceCode, 2, "[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]"); DataBaseClassWriter.Write(nSourceCode, 2, "protected override global::System.Type GetRowType()"); DataBaseClassWriter.Write(nSourceCode, 2, "{"); DataBaseClassWriter.Write(nSourceCode, 3, "return typeof(" + ObjetNameFormated + "Row);"); DataBaseClassWriter.Write(nSourceCode, 2, "}"); DataBaseClassWriter.Write(nSourceCode, 2, "[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]"); DataBaseClassWriter.Write(nSourceCode, 2, "protected override global::System.Data.DataTable CreateInstance()"); DataBaseClassWriter.Write(nSourceCode, 2, "{"); DataBaseClassWriter.Write(nSourceCode, 3, "return new " + ObjetNameFormated + "DataTable();"); DataBaseClassWriter.Write(nSourceCode, 2, "}"); // Objeto complejo var objectName = FormatCode.ToIdentifier(table.Object_Name); var objectXmlName = objectName + "Type"; DataBaseClassWriter.Write(nSourceCode, 2, "/// <summary>"); DataBaseClassWriter.Write(nSourceCode, 2, "/// Retorna una lista de filas de tipo " + table.Object_Name + " tipados para serializacion en XML"); DataBaseClassWriter.Write(nSourceCode, 2, "/// </summary>"); DataBaseClassWriter.Write(nSourceCode, 2, "/// <returns></returns>"); DataBaseClassWriter.Write(nSourceCode, 2, "public List<" + objectXmlName + "> ToXmlList()"); DataBaseClassWriter.Write(nSourceCode, 2, "{"); DataBaseClassWriter.Write(nSourceCode, 3, "return XmlList<" + objectXmlName + ">.ConvertToXmlList(this);"); DataBaseClassWriter.Write(nSourceCode, 2, "}"); // Objeto simple objectName = FormatCode.ToIdentifier(table.Object_Name); objectXmlName = objectName + "SimpleType"; DataBaseClassWriter.Write(nSourceCode, 2, "/// <summary>"); DataBaseClassWriter.Write(nSourceCode, 2, "/// Retorna una lista de filas de tipo " + table.Object_Name + " tipados para serializacion en XML"); DataBaseClassWriter.Write(nSourceCode, 2, "/// </summary>"); DataBaseClassWriter.Write(nSourceCode, 2, "/// <returns></returns>"); DataBaseClassWriter.Write(nSourceCode, 2, "public List<" + objectXmlName + "> ToSimpleXmlList()"); DataBaseClassWriter.Write(nSourceCode, 2, "{"); DataBaseClassWriter.Write(nSourceCode, 3, "return XmlList<" + objectXmlName + ">.ConvertToXmlList(this);"); DataBaseClassWriter.Write(nSourceCode, 2, "}"); DataBaseClassWriter.Write(nSourceCode, 0, ""); DataBaseClassWriter.Write(nSourceCode, 0, "#endregion"); DataBaseClassWriter.Write(nSourceCode, 1, "}"); DataBaseClassWriter.Write(nSourceCode, 1, "///<summary>"); DataBaseClassWriter.Write(nSourceCode, 1, "///Representa un DataRow tipado de la tabla " + table.Object_Name); DataBaseClassWriter.Write(nSourceCode, 1, "///</summary>"); DataBaseClassWriter.Write(nSourceCode, 1, "[Serializable()]"); DataBaseClassWriter.Write(nSourceCode, 1, "public partial class " + ObjetNameFormated + "Row : global::System.Data.DataRow"); DataBaseClassWriter.Write(nSourceCode, 1, "{"); DataBaseClassWriter.Write(nSourceCode, 0, "#region Declaraciones"); DataBaseClassWriter.Write(nSourceCode, 0, ""); DataBaseClassWriter.Write(nSourceCode, 2, "private " + ObjetNameFormated + "DataTable table" + ObjetNameFormated + ";"); DataBaseClassWriter.Write(nSourceCode, 0, ""); DataBaseClassWriter.Write(nSourceCode, 0, "#endregion"); DataBaseClassWriter.Write(nSourceCode, 0, ""); DataBaseClassWriter.Write(nSourceCode, 0, "#region Propiedades"); DataBaseClassWriter.Write(nSourceCode, 0, ""); foreach (var par in nInColumns) { DataBaseClassWriter.Write(nSourceCode, 2, "[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]"); DataBaseClassWriter.Write(nSourceCode, 2, "public " + DataBaseClassWriter.GetApplicationStringType(par.Type, LanguajeType.CSharp, false) + " " + par.Name); DataBaseClassWriter.Write(nSourceCode, 2, "{"); DataBaseClassWriter.Write(nSourceCode, 3, "get"); DataBaseClassWriter.Write(nSourceCode, 3, "{"); DataBaseClassWriter.Write(nSourceCode, 4, "try"); DataBaseClassWriter.Write(nSourceCode, 4, "{"); DataBaseClassWriter.Write(nSourceCode, 5, "return (" + DataBaseClassWriter.GetApplicationStringType(par.Type, LanguajeType.CSharp, false) + " )this[this.table" + ObjetNameFormated + "." + par.Name + "Column];"); DataBaseClassWriter.Write(nSourceCode, 4, "}"); DataBaseClassWriter.Write(nSourceCode, 4, "catch(global::System.InvalidCastException e)"); DataBaseClassWriter.Write(nSourceCode, 4, "{"); DataBaseClassWriter.Write(nSourceCode, 5, "throw new global::System.Data.StrongTypingException(\"El valor de la columna '" + par.Name + "' de la tabla '" + ObjetNameFormated + "' es DBNull.\", e);"); DataBaseClassWriter.Write(nSourceCode, 4, "}"); DataBaseClassWriter.Write(nSourceCode, 3, "}"); DataBaseClassWriter.Write(nSourceCode, 3, "set"); DataBaseClassWriter.Write(nSourceCode, 3, "{"); DataBaseClassWriter.Write(nSourceCode, 4, "this[this.table" + ObjetNameFormated + "." + par.Name + "Column] = value;"); DataBaseClassWriter.Write(nSourceCode, 3, "}"); DataBaseClassWriter.Write(nSourceCode, 2, "}"); } DataBaseClassWriter.Write(nSourceCode, 0, ""); DataBaseClassWriter.Write(nSourceCode, 0, "#endregion"); DataBaseClassWriter.Write(nSourceCode, 0, ""); DataBaseClassWriter.Write(nSourceCode, 0, "#region Constructores"); DataBaseClassWriter.Write(nSourceCode, 0, ""); DataBaseClassWriter.Write(nSourceCode, 2, "[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]"); DataBaseClassWriter.Write(nSourceCode, 2, "internal " + ObjetNameFormated + "Row(global::System.Data.DataRowBuilder rb)"); DataBaseClassWriter.Write(nSourceCode, 3, ": base(rb)"); DataBaseClassWriter.Write(nSourceCode, 2, "{"); DataBaseClassWriter.Write(nSourceCode, 3, "this.table" + ObjetNameFormated + " = (" + ObjetNameFormated + "DataTable)this.Table;"); DataBaseClassWriter.Write(nSourceCode, 2, "}"); DataBaseClassWriter.Write(nSourceCode, 0, ""); DataBaseClassWriter.Write(nSourceCode, 0, "#endregion"); DataBaseClassWriter.Write(nSourceCode, 0, ""); DataBaseClassWriter.Write(nSourceCode, 0, "#region Metodos"); DataBaseClassWriter.Write(nSourceCode, 0, ""); foreach (var par in nInColumns) { if (par.IsNullable) { DataBaseClassWriter.Write(nSourceCode, 2, "[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]"); DataBaseClassWriter.Write(nSourceCode, 2, "public void Set" + par.Name + "Null()"); DataBaseClassWriter.Write(nSourceCode, 2, "{"); DataBaseClassWriter.Write(nSourceCode, 3, "this[this.table" + ObjetNameFormated + "." + par.Name + "Column] = global::System.Convert.DBNull;"); DataBaseClassWriter.Write(nSourceCode, 2, "}"); } } DataBaseClassWriter.Write(nSourceCode, 0, ""); DataBaseClassWriter.Write(nSourceCode, 0, "#endregion"); DataBaseClassWriter.Write(nSourceCode, 0, ""); DataBaseClassWriter.Write(nSourceCode, 0, "#region Funciones"); DataBaseClassWriter.Write(nSourceCode, 0, ""); foreach (var par in nInColumns) { if (par.IsNullable) { DataBaseClassWriter.Write(nSourceCode, 2, "[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]"); DataBaseClassWriter.Write(nSourceCode, 2, "public bool Is" + par.Name + "Null()"); DataBaseClassWriter.Write(nSourceCode, 2, "{"); DataBaseClassWriter.Write(nSourceCode, 3, "return this.IsNull(this.table" + ObjetNameFormated + "." + par.Name + "Column);"); DataBaseClassWriter.Write(nSourceCode, 2, "}"); } } // Tipo complejo objectName = FormatCode.ToIdentifier(table.Object_Name); objectXmlName = objectName + "Type"; DataBaseClassWriter.Write(nSourceCode, 0, ""); DataBaseClassWriter.Write(nSourceCode, 2, "[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]"); DataBaseClassWriter.Write(nSourceCode, 2, "public " + objectXmlName + " To" + objectXmlName + "()"); DataBaseClassWriter.Write(nSourceCode, 2, "{"); DataBaseClassWriter.Write(nSourceCode, 3, "return XmlList<" + objectXmlName + ">.ConvertToXmlBasicType(this);"); DataBaseClassWriter.Write(nSourceCode, 2, "}"); DataBaseClassWriter.Write(nSourceCode, 0, ""); // Tipo simple objectXmlName = objectName + "SimpleType"; DataBaseClassWriter.Write(nSourceCode, 0, ""); DataBaseClassWriter.Write(nSourceCode, 2, "[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]"); DataBaseClassWriter.Write(nSourceCode, 2, "public " + objectXmlName + " To" + objectXmlName + "()"); DataBaseClassWriter.Write(nSourceCode, 2, "{"); DataBaseClassWriter.Write(nSourceCode, 3, "return XmlList<" + objectXmlName + ">.ConvertToXmlBasicType(this);"); DataBaseClassWriter.Write(nSourceCode, 2, "}"); DataBaseClassWriter.Write(nSourceCode, 0, ""); DataBaseClassWriter.Write(nSourceCode, 0, "#endregion"); DataBaseClassWriter.Write(nSourceCode, 1, "}"); DataBaseClassWriter.Write(nSourceCode, 0, ""); // Entidad que representa un Row para XML // Tipo Complejo objectXmlName = objectName + "Type"; DataBaseClassWriter.Write(nSourceCode, 1, "[Serializable]"); DataBaseClassWriter.Write(nSourceCode, 1, "public class " + objectXmlName + " : XmlBase"); DataBaseClassWriter.Write(nSourceCode, 1, "{"); DataBaseClassWriter.Write(nSourceCode, 1, " public " + objectXmlName + "() {}"); nInColumns = nDataBaseMap.GetTableColumns(table); foreach (var par in nInColumns) { DataBaseClassWriter.Write(nSourceCode, 2, "public " + DataBaseClassWriter.GetApplicationStringType(par.Type, LanguajeType.CSharp, true) + " " + par.Name + ";"); } DataBaseClassWriter.Write(nSourceCode, 1, "}"); DataBaseClassWriter.Write(nSourceCode, 0, ""); // Tipo simple objectXmlName = objectName + "SimpleType"; DataBaseClassWriter.Write(nSourceCode, 1, "[Serializable]"); DataBaseClassWriter.Write(nSourceCode, 1, "public class " + objectXmlName + " : XmlBase"); DataBaseClassWriter.Write(nSourceCode, 1, "{"); DataBaseClassWriter.Write(nSourceCode, 1, " public " + objectXmlName + "() {}"); nInColumns = nDataBaseMap.GetTableColumns(table); foreach (var par in nInColumns) { DataBaseClassWriter.Write(nSourceCode, 2, "public " + DataBaseClassWriter.getLanguajeStringType(par.Type, LanguajeType.CSharp) + " " + par.Name + ";"); } DataBaseClassWriter.Write(nSourceCode, 1, "}"); DataBaseClassWriter.Write(nSourceCode, 2, "#endregion"); //Region Tablas DataBaseClassWriter.Write(nSourceCode, 0, ""); } }
private static void WriteDataTables(ref StringBuilder nSourceCode, XsdDataBase nDataBaseMap, XsdDataBase.TBL_ObjectRow[] tablas, bool IsMobile, bool UseFramework2) { int idMetodo = 0; foreach (var table in tablas) { DataBaseClassWriter.Write(nSourceCode, 2, "#Region \" " + table.Object_Name + "\""); DataBaseClassWriter.Write(nSourceCode, 0, ""); var nPrimaryKeys = nDataBaseMap.GetPrimaryKeys(table); var ObjetNameFormated = FormatCode.ToIdentifier(table.Object_Name); var nInColumns = nDataBaseMap.GetTableColumns(table); DataBaseClassWriter.Write(nSourceCode, 1, "'''<summary>"); DataBaseClassWriter.Write(nSourceCode, 1, "'''Enumeración de las columnas de la tabla " + table.Object_Name); DataBaseClassWriter.Write(nSourceCode, 1, "'''</summary>"); DataBaseClassWriter.Write(nSourceCode, 1, "Public Class " + ObjetNameFormated + "Enum"); DataBaseClassWriter.Write(nSourceCode, 2, "Inherits ColumnEnum"); foreach (var par in nInColumns) { DataBaseClassWriter.Write(nSourceCode, 2, "Public Shared ReadOnly " + FormatCode.ToIdentifier(par.Name) + " As New " + ObjetNameFormated + "Enum(\"" + par.Name + "\")"); } DataBaseClassWriter.Write(nSourceCode, 2, "Sub New(ByVal nColumnName As String)"); DataBaseClassWriter.Write(nSourceCode, 3, "MyBase.New(nColumnName)"); DataBaseClassWriter.Write(nSourceCode, 2, "End Sub"); DataBaseClassWriter.Write(nSourceCode, 1, "End Class"); DataBaseClassWriter.Write(nSourceCode, 1, "'''<summary>"); DataBaseClassWriter.Write(nSourceCode, 1, "'''Colección columnas enumeradas de la tabla " + table.Object_Name); DataBaseClassWriter.Write(nSourceCode, 1, "'''</summary>"); DataBaseClassWriter.Write(nSourceCode, 1, "Public Class " + ObjetNameFormated + "EnumList"); DataBaseClassWriter.Write(nSourceCode, 2, "Inherits ColumnEnumList"); DataBaseClassWriter.Write(nSourceCode, 2, "Public Sub New()"); DataBaseClassWriter.Write(nSourceCode, 2, "End Sub"); DataBaseClassWriter.Write(nSourceCode, 2, "Public Sub New(ByVal nColumn As " + ObjetNameFormated + "Enum, ByVal nAscendente As Boolean)"); DataBaseClassWriter.Write(nSourceCode, 3, "MyBase.Add(nColumn, nAscendente)"); DataBaseClassWriter.Write(nSourceCode, 2, "End Sub"); DataBaseClassWriter.Write(nSourceCode, 1, "End Class"); DataBaseClassWriter.Write(nSourceCode, 1, "'''<summary>"); DataBaseClassWriter.Write(nSourceCode, 1, "'''Representa un DataTable tipado de la tabla " + table.Object_Name); DataBaseClassWriter.Write(nSourceCode, 1, "'''</summary>"); DataBaseClassWriter.Write(nSourceCode, 1, "<Serializable()> _"); DataBaseClassWriter.Write(nSourceCode, 1, "Partial Public Class " + ObjetNameFormated + "DataTable"); if (UseFramework2) DataBaseClassWriter.Write(nSourceCode, 2, "Inherits CMData.Utils.TypedTable(Of " + ObjetNameFormated + "Row)"); else DataBaseClassWriter.Write(nSourceCode, 2, "Inherits System.Data.TypedTableBase(Of " + ObjetNameFormated + "Row)"); DataBaseClassWriter.Write(nSourceCode, 0, ""); DataBaseClassWriter.Write(nSourceCode, 0, "#Region \" Declaraciones \""); foreach (var par in nInColumns) { DataBaseClassWriter.Write(nSourceCode, 2, "Private column" + FormatCode.ToIdentifier(par.Name) + " As Global.System.Data.DataColumn"); } DataBaseClassWriter.Write(nSourceCode, 0, "#End Region"); DataBaseClassWriter.Write(nSourceCode, 0, ""); DataBaseClassWriter.Write(nSourceCode, 0, "#Region \" Propiedades \""); foreach (var par in nInColumns) { DataBaseClassWriter.Write(nSourceCode, 2, "<Global.System.Diagnostics.DebuggerNonUserCodeAttribute()> _"); DataBaseClassWriter.Write(nSourceCode, 2, "Public ReadOnly Property " + par.Name + "Column() As Global.System.Data.DataColumn"); DataBaseClassWriter.Write(nSourceCode, 3, "Get"); DataBaseClassWriter.Write(nSourceCode, 4, "Return Me.column" + par.Name); DataBaseClassWriter.Write(nSourceCode, 3, "End Get"); DataBaseClassWriter.Write(nSourceCode, 2, "End Property"); } DataBaseClassWriter.Write(nSourceCode, 0, ""); if (!IsMobile) { DataBaseClassWriter.Write(nSourceCode, 2, "<Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), _"); DataBaseClassWriter.Write(nSourceCode, 2, "Global.System.ComponentModel.Browsable(False)> _"); } else { DataBaseClassWriter.Write(nSourceCode, 2, "<Global.System.Diagnostics.DebuggerNonUserCodeAttribute()> _"); } DataBaseClassWriter.Write(nSourceCode, 2, "Public ReadOnly Property Count() As Integer"); DataBaseClassWriter.Write(nSourceCode, 3, "Get"); DataBaseClassWriter.Write(nSourceCode, 4, "Return Me.Rows.Count"); DataBaseClassWriter.Write(nSourceCode, 3, "End Get"); DataBaseClassWriter.Write(nSourceCode, 2, "End Property"); DataBaseClassWriter.Write(nSourceCode, 2, "<Global.System.Diagnostics.DebuggerNonUserCodeAttribute()> _"); DataBaseClassWriter.Write(nSourceCode, 2, "Default Public ReadOnly Property Item(ByVal index As Integer) As " + ObjetNameFormated + "Row"); DataBaseClassWriter.Write(nSourceCode, 3, "Get"); DataBaseClassWriter.Write(nSourceCode, 4, "Return CType(Me.Rows(index), " + ObjetNameFormated + "Row)"); DataBaseClassWriter.Write(nSourceCode, 3, "End Get"); DataBaseClassWriter.Write(nSourceCode, 2, "End Property"); DataBaseClassWriter.Write(nSourceCode, 0, "#End Region"); DataBaseClassWriter.Write(nSourceCode, 0, ""); DataBaseClassWriter.Write(nSourceCode, 0, "#Region \" Constructores \""); DataBaseClassWriter.Write(nSourceCode, 2, "<Global.System.Diagnostics.DebuggerNonUserCodeAttribute()> _"); DataBaseClassWriter.Write(nSourceCode, 2, "Public Sub New()"); DataBaseClassWriter.Write(nSourceCode, 3, "MyBase.New()"); DataBaseClassWriter.Write(nSourceCode, 3, "Me.TableName = \"" + table.Object_Name + "\""); DataBaseClassWriter.Write(nSourceCode, 3, "Me.BeginInit()"); DataBaseClassWriter.Write(nSourceCode, 3, "Me.InitClass()"); DataBaseClassWriter.Write(nSourceCode, 3, "Me.EndInit()"); DataBaseClassWriter.Write(nSourceCode, 2, "End Sub"); DataBaseClassWriter.Write(nSourceCode, 2, "<Global.System.Diagnostics.DebuggerNonUserCodeAttribute()> _"); DataBaseClassWriter.Write(nSourceCode, 2, "Friend Sub New(ByVal table As Global.System.Data.DataTable)"); DataBaseClassWriter.Write(nSourceCode, 3, "MyBase.New()"); DataBaseClassWriter.Write(nSourceCode, 3, "Me.TableName = table.TableName"); DataBaseClassWriter.Write(nSourceCode, 3, "If (table.CaseSensitive <> table.DataSet.CaseSensitive) Then"); DataBaseClassWriter.Write(nSourceCode, 4, "Me.CaseSensitive = table.CaseSensitive"); DataBaseClassWriter.Write(nSourceCode, 3, "End If"); DataBaseClassWriter.Write(nSourceCode, 3, "If (table.Locale.ToString() <> table.DataSet.Locale.ToString()) Then"); DataBaseClassWriter.Write(nSourceCode, 4, "Me.Locale = table.Locale"); DataBaseClassWriter.Write(nSourceCode, 3, "End If"); DataBaseClassWriter.Write(nSourceCode, 3, "If (table.Namespace <> table.DataSet.Namespace) Then"); DataBaseClassWriter.Write(nSourceCode, 4, "Me.Namespace = table.Namespace"); DataBaseClassWriter.Write(nSourceCode, 3, "End If"); DataBaseClassWriter.Write(nSourceCode, 3, "Me.Prefix = table.Prefix"); DataBaseClassWriter.Write(nSourceCode, 3, "Me.MinimumCapacity = table.MinimumCapacity"); DataBaseClassWriter.Write(nSourceCode, 2, "End Sub"); if (!IsMobile) { DataBaseClassWriter.Write(nSourceCode, 2, "<Global.System.Diagnostics.DebuggerNonUserCodeAttribute()> _"); DataBaseClassWriter.Write(nSourceCode, 2, "Protected Sub New(ByVal info As Global.System.Runtime.Serialization.SerializationInfo, ByVal context As Global.System.Runtime.Serialization.StreamingContext)"); DataBaseClassWriter.Write(nSourceCode, 3, "MyBase.New(info, context)"); DataBaseClassWriter.Write(nSourceCode, 3, "Me.InitVars()"); DataBaseClassWriter.Write(nSourceCode, 2, "End Sub"); } DataBaseClassWriter.Write(nSourceCode, 2, ""); DataBaseClassWriter.Write(nSourceCode, 0, "#End Region"); DataBaseClassWriter.Write(nSourceCode, 0, ""); DataBaseClassWriter.Write(nSourceCode, 0, "#Region \" Metodos \""); DataBaseClassWriter.Write(nSourceCode, 2, "<Global.System.Diagnostics.DebuggerNonUserCodeAttribute()> _"); DataBaseClassWriter.Write(nSourceCode, 2, "Public Sub Remove" + ObjetNameFormated + "Row(ByVal row As " + ObjetNameFormated + "Row)"); DataBaseClassWriter.Write(nSourceCode, 3, "Me.Rows.Remove(row)"); DataBaseClassWriter.Write(nSourceCode, 2, "End Sub"); DataBaseClassWriter.Write(nSourceCode, 2, "<Global.System.Diagnostics.DebuggerNonUserCodeAttribute()> _"); DataBaseClassWriter.Write(nSourceCode, 2, "Public Overloads Sub Add" + ObjetNameFormated + "Row(ByVal row As " + ObjetNameFormated + "Row)"); DataBaseClassWriter.Write(nSourceCode, 3, "Me.Rows.Add(row)"); DataBaseClassWriter.Write(nSourceCode, 2, "End Sub"); DataBaseClassWriter.Write(nSourceCode, 2, "<Global.System.Diagnostics.DebuggerNonUserCodeAttribute()> _"); DataBaseClassWriter.Write(nSourceCode, 2, "Friend Sub InitVars()"); foreach (var par in nInColumns) { DataBaseClassWriter.Write(nSourceCode, 3, "Me.column" + FormatCode.ToIdentifier(par.Name) + " = MyBase.Columns(\"" + par.Name + "\")"); } DataBaseClassWriter.Write(nSourceCode, 2, "End Sub"); DataBaseClassWriter.Write(nSourceCode, 2, "<Global.System.Diagnostics.DebuggerNonUserCodeAttribute()> _"); DataBaseClassWriter.Write(nSourceCode, 2, "Private Sub InitClass()"); foreach (var par in nInColumns) { DataBaseClassWriter.Write(nSourceCode, 3, "Me.column" + FormatCode.ToIdentifier(par.Name) + " = New Global.System.Data.DataColumn(\"" + par.Name + "\", GetType(" + DataBaseClassWriter.GetApplicationStringType(par.Type, LanguajeType.VB, false) + "), Nothing, Global.System.Data.MappingType.Element)"); if (par.MaxLength > 0 && CMData.DataBase.DataBase.IsStringType(par) && table.Generic_Type != "View") DataBaseClassWriter.Write(nSourceCode, 3, "Me.column" + FormatCode.ToIdentifier(par.Name) + ".MaxLength = " + par.MaxLength); DataBaseClassWriter.Write(nSourceCode, 3, "MyBase.Columns.Add(Me.column" + FormatCode.ToIdentifier(par.Name) + ")"); } var strLine = ""; if (table.Generic_Type != "View") { if (nPrimaryKeys.Count > 0) { strLine = ""; foreach (var par in nPrimaryKeys) { if (strLine != "") strLine += ", "; strLine += "Me.column" + par.Name; } DataBaseClassWriter.Write(nSourceCode, 3, "Me.Constraints.Add(New Global.System.Data.UniqueConstraint(\"" + table.Object_Name + "Key1\", New Global.System.Data.DataColumn() { " + strLine + "}, True))"); } foreach (var par in nInColumns) { if (!par.IsNullable) DataBaseClassWriter.Write(nSourceCode, 3, "Me.column" + FormatCode.ToIdentifier(par.Name) + ".AllowDBNull = False"); } } DataBaseClassWriter.Write(nSourceCode, 2, "End Sub"); DataBaseClassWriter.Write(nSourceCode, 0, ""); DataBaseClassWriter.Write(nSourceCode, 0, "#End Region"); DataBaseClassWriter.Write(nSourceCode, 0, ""); DataBaseClassWriter.Write(nSourceCode, 0, "#Region \" Funciones \""); var strLine2 = ""; if (nPrimaryKeys.Count > 0 && table.Generic_Type != "View") { strLine = ""; foreach (var par in nPrimaryKeys) { strLine += par.Name; } var strFunctionName = strLine; if (strFunctionName.Length > 500) { idMetodo++; strFunctionName = strFunctionName.Substring(0, 500) + idMetodo.ToString(); } strLine2 = ""; foreach (var par in nPrimaryKeys) { if (strLine2 != "") strLine2 += ", "; strLine2 += "ByVal n" + par.Name + " As " + DataBaseClassWriter.GetApplicationStringType(par.Type, LanguajeType.VB, false); } DataBaseClassWriter.Write(nSourceCode, 2, "<Global.System.Diagnostics.DebuggerNonUserCodeAttribute()> _"); DataBaseClassWriter.Write(nSourceCode, 2, "Public Function FindBy" + strFunctionName + "(" + strLine2 + ") As " + ObjetNameFormated + "Row"); strLine = ""; foreach (var par in nPrimaryKeys) { if (strLine != "") strLine += ", "; strLine += "n" + par.Name; } DataBaseClassWriter.Write(nSourceCode, 3, "Return CType(Me.Rows.Find(New Object() {" + strLine + "}), " + ObjetNameFormated + "Row)"); DataBaseClassWriter.Write(nSourceCode, 2, "End Function"); } DataBaseClassWriter.Write(nSourceCode, 2, "<Global.System.Diagnostics.DebuggerNonUserCodeAttribute()> _"); DataBaseClassWriter.Write(nSourceCode, 2, "Public Function New" + ObjetNameFormated + "Row() As " + ObjetNameFormated + "Row"); DataBaseClassWriter.Write(nSourceCode, 3, "Return CType(Me.NewRow, " + ObjetNameFormated + "Row)"); DataBaseClassWriter.Write(nSourceCode, 2, "End Function"); DataBaseClassWriter.Write(nSourceCode, 2, "<Global.System.Diagnostics.DebuggerNonUserCodeAttribute()> _"); strLine = ""; strLine2 = ""; foreach (var par in nInColumns) { if (strLine != "") strLine += ", "; if (strLine2 != "") strLine2 += ", "; strLine += "ByVal n" + par.Name + " As " + DataBaseClassWriter.GetApplicationStringType(par.Type, LanguajeType.VB, par.IsNullable); strLine2 += "n" + par.Name; } DataBaseClassWriter.Write(nSourceCode, 2, "Public Overloads Function Add" + ObjetNameFormated + "Row(" + strLine + ") As " + ObjetNameFormated + "Row"); DataBaseClassWriter.Write(nSourceCode, 3, "Dim row" + ObjetNameFormated + "Row As " + ObjetNameFormated + "Row = CType(Me.NewRow, " + ObjetNameFormated + "Row)"); DataBaseClassWriter.Write(nSourceCode, 3, "Dim columnValuesArray() As Object = New Object() {" + strLine2 + "}"); DataBaseClassWriter.Write(nSourceCode, 3, "row" + ObjetNameFormated + "Row.ItemArray = columnValuesArray"); DataBaseClassWriter.Write(nSourceCode, 3, "Me.Rows.Add(row" + ObjetNameFormated + "Row)"); DataBaseClassWriter.Write(nSourceCode, 3, "Return row" + ObjetNameFormated + "Row"); DataBaseClassWriter.Write(nSourceCode, 2, "End Function"); DataBaseClassWriter.Write(nSourceCode, 2, "<Global.System.Diagnostics.DebuggerNonUserCodeAttribute()> _"); DataBaseClassWriter.Write(nSourceCode, 2, "Public Overrides Function Clone() As Global.System.Data.DataTable"); DataBaseClassWriter.Write(nSourceCode, 3, "Dim cln As " + ObjetNameFormated + "DataTable = CType(MyBase.Clone, " + ObjetNameFormated + "DataTable)"); DataBaseClassWriter.Write(nSourceCode, 3, "cln.InitVars()"); DataBaseClassWriter.Write(nSourceCode, 3, "Return cln"); DataBaseClassWriter.Write(nSourceCode, 2, "End Function"); DataBaseClassWriter.Write(nSourceCode, 2, "<Global.System.Diagnostics.DebuggerNonUserCodeAttribute()> _"); DataBaseClassWriter.Write(nSourceCode, 2, "Protected Overrides Function NewRowFromBuilder(ByVal builder As Global.System.Data.DataRowBuilder) As Global.System.Data.DataRow"); DataBaseClassWriter.Write(nSourceCode, 3, "Return New " + ObjetNameFormated + "Row(builder)"); DataBaseClassWriter.Write(nSourceCode, 2, "End Function"); DataBaseClassWriter.Write(nSourceCode, 2, "<Global.System.Diagnostics.DebuggerNonUserCodeAttribute()> _"); DataBaseClassWriter.Write(nSourceCode, 2, "Protected Overrides Function GetRowType() As Global.System.Type"); DataBaseClassWriter.Write(nSourceCode, 3, "Return GetType(" + ObjetNameFormated + "Row)"); DataBaseClassWriter.Write(nSourceCode, 2, "End Function"); DataBaseClassWriter.Write(nSourceCode, 2, "<Global.System.Diagnostics.DebuggerNonUserCodeAttribute()> _"); DataBaseClassWriter.Write(nSourceCode, 2, "Protected Overrides Function CreateInstance() As Global.System.Data.DataTable"); DataBaseClassWriter.Write(nSourceCode, 3, "Return New " + ObjetNameFormated + "DataTable"); DataBaseClassWriter.Write(nSourceCode, 2, "End Function"); // Objeto complejo var objectName = FormatCode.ToIdentifier(table.Object_Name); var objectXmlName = objectName + "Type"; DataBaseClassWriter.Write(nSourceCode, 2, "''' <summary>"); DataBaseClassWriter.Write(nSourceCode, 2, "''' Retorna una lista de filas de tipo " + table.Object_Name + " tipados para serializacion en XML"); DataBaseClassWriter.Write(nSourceCode, 2, "''' </summary>"); DataBaseClassWriter.Write(nSourceCode, 2, "''' <returns></returns>"); DataBaseClassWriter.Write(nSourceCode, 2, "Public Function ToXmlList() As List(Of " + objectXmlName + ")"); DataBaseClassWriter.Write(nSourceCode, 3, "Return XmlList(Of " + objectXmlName + ").ConvertToXmlList(Me)"); DataBaseClassWriter.Write(nSourceCode, 2, "End Function"); // Objeto simple objectXmlName = objectName + "SimpleType"; DataBaseClassWriter.Write(nSourceCode, 2, "''' <summary>"); DataBaseClassWriter.Write(nSourceCode, 2, "''' Retorna una lista de filas de tipo " + table.Object_Name + " tipados para serializacion en XML"); DataBaseClassWriter.Write(nSourceCode, 2, "''' </summary>"); DataBaseClassWriter.Write(nSourceCode, 2, "''' <returns></returns>"); DataBaseClassWriter.Write(nSourceCode, 2, "Public Function ToSimpleXmlList() As List(Of " + objectXmlName + ")"); DataBaseClassWriter.Write(nSourceCode, 3, "Return XmlList(Of " + objectXmlName + ").ConvertToXmlList(Me)"); DataBaseClassWriter.Write(nSourceCode, 2, "End Function"); DataBaseClassWriter.Write(nSourceCode, 0, ""); DataBaseClassWriter.Write(nSourceCode, 0, "#End Region"); DataBaseClassWriter.Write(nSourceCode, 0, ""); DataBaseClassWriter.Write(nSourceCode, 1, "End Class"); DataBaseClassWriter.Write(nSourceCode, 1, "'''<summary>"); DataBaseClassWriter.Write(nSourceCode, 1, "'''Representa un DataRow tipado de la tabla " + table.Object_Name); DataBaseClassWriter.Write(nSourceCode, 1, "'''</summary>"); DataBaseClassWriter.Write(nSourceCode, 1, "<Serializable()> _"); DataBaseClassWriter.Write(nSourceCode, 1, "Partial Public Class " + ObjetNameFormated + "Row"); DataBaseClassWriter.Write(nSourceCode, 2, "Inherits Global.System.Data.DataRow"); DataBaseClassWriter.Write(nSourceCode, 0, ""); DataBaseClassWriter.Write(nSourceCode, 0, "#Region \" Declaraciones \""); DataBaseClassWriter.Write(nSourceCode, 0, ""); DataBaseClassWriter.Write(nSourceCode, 2, "Private table" + ObjetNameFormated + " As " + ObjetNameFormated + "DataTable"); DataBaseClassWriter.Write(nSourceCode, 0, ""); DataBaseClassWriter.Write(nSourceCode, 0, "#End Region"); DataBaseClassWriter.Write(nSourceCode, 0, ""); DataBaseClassWriter.Write(nSourceCode, 0, "#Region \" Propiedades \""); DataBaseClassWriter.Write(nSourceCode, 0, ""); foreach (var par in nInColumns) { DataBaseClassWriter.Write(nSourceCode, 2, "<Global.System.Diagnostics.DebuggerNonUserCodeAttribute()> _"); DataBaseClassWriter.Write(nSourceCode, 2, "Public Property [" + par.Name + "]() As " + DataBaseClassWriter.GetApplicationStringType(par.Type, LanguajeType.VB, false)); DataBaseClassWriter.Write(nSourceCode, 3, "Get"); DataBaseClassWriter.Write(nSourceCode, 4, "Try"); DataBaseClassWriter.Write(nSourceCode, 5, "Return CType(Me(Me.table" + ObjetNameFormated + "." + par.Name + "Column), " + DataBaseClassWriter.GetApplicationStringType(par.Type, LanguajeType.VB, false) + " )"); DataBaseClassWriter.Write(nSourceCode, 4, "Catch e As Global.System.InvalidCastException"); DataBaseClassWriter.Write(nSourceCode, 5, "Throw New Global.System.Data.StrongTypingException(\"El valor de la columna '" + par.Name + "' de la tabla '" + ObjetNameFormated + "' es DBNull.\", e)"); DataBaseClassWriter.Write(nSourceCode, 4, "End Try"); DataBaseClassWriter.Write(nSourceCode, 3, "End Get"); DataBaseClassWriter.Write(nSourceCode, 3, "Set(ByVal value As " + DataBaseClassWriter.GetApplicationStringType(par.Type, LanguajeType.VB, false) + ")"); DataBaseClassWriter.Write(nSourceCode, 4, "Me(Me.table" + ObjetNameFormated + "." + par.Name + "Column) = value"); DataBaseClassWriter.Write(nSourceCode, 3, "End Set"); DataBaseClassWriter.Write(nSourceCode, 2, "End Property"); } DataBaseClassWriter.Write(nSourceCode, 0, ""); DataBaseClassWriter.Write(nSourceCode, 0, "#End Region"); DataBaseClassWriter.Write(nSourceCode, 0, ""); DataBaseClassWriter.Write(nSourceCode, 0, "#Region \" Constructores \""); DataBaseClassWriter.Write(nSourceCode, 0, ""); DataBaseClassWriter.Write(nSourceCode, 2, "<Global.System.Diagnostics.DebuggerNonUserCodeAttribute()> _"); DataBaseClassWriter.Write(nSourceCode, 2, "Friend Sub New(ByVal rb As Global.System.Data.DataRowBuilder)"); DataBaseClassWriter.Write(nSourceCode, 3, "MyBase.New(rb)"); DataBaseClassWriter.Write(nSourceCode, 3, "Me.table" + ObjetNameFormated + " = CType(Me.Table, " + ObjetNameFormated + "DataTable)"); DataBaseClassWriter.Write(nSourceCode, 2, "End Sub"); DataBaseClassWriter.Write(nSourceCode, 0, ""); DataBaseClassWriter.Write(nSourceCode, 0, "#End Region"); DataBaseClassWriter.Write(nSourceCode, 0, ""); DataBaseClassWriter.Write(nSourceCode, 0, "#Region \" Metodos \""); DataBaseClassWriter.Write(nSourceCode, 0, ""); foreach (var par in nInColumns) { if (par.IsNullable) { DataBaseClassWriter.Write(nSourceCode, 2, "<Global.System.Diagnostics.DebuggerNonUserCodeAttribute()> _"); DataBaseClassWriter.Write(nSourceCode, 2, "Public Sub Set" + par.Name + "Null()"); DataBaseClassWriter.Write(nSourceCode, 3, "Me(Me.table" + ObjetNameFormated + "." + par.Name + "Column) = Global.System.Convert.DBNull"); DataBaseClassWriter.Write(nSourceCode, 2, "End Sub"); } } DataBaseClassWriter.Write(nSourceCode, 0, ""); DataBaseClassWriter.Write(nSourceCode, 0, "#End Region"); DataBaseClassWriter.Write(nSourceCode, 0, ""); DataBaseClassWriter.Write(nSourceCode, 0, "#Region \" Funciones \""); DataBaseClassWriter.Write(nSourceCode, 0, ""); foreach (var par in nInColumns) { if (par.IsNullable) { DataBaseClassWriter.Write(nSourceCode, 2, "<Global.System.Diagnostics.DebuggerNonUserCodeAttribute()> _"); DataBaseClassWriter.Write(nSourceCode, 2, "Public Function Is" + par.Name + "Null() As Boolean"); DataBaseClassWriter.Write(nSourceCode, 3, "Return Me.IsNull(Me.table" + ObjetNameFormated + "." + par.Name + "Column)"); DataBaseClassWriter.Write(nSourceCode, 2, "End Function"); } } // Tipo complejo objectName = FormatCode.ToIdentifier(table.Object_Name); objectXmlName = objectName + "Type"; DataBaseClassWriter.Write(nSourceCode, 0, ""); DataBaseClassWriter.Write(nSourceCode, 2, "<Global.System.Diagnostics.DebuggerNonUserCodeAttribute()> _"); DataBaseClassWriter.Write(nSourceCode, 2, "Public Function To" + objectXmlName + "() As " + objectXmlName + ""); DataBaseClassWriter.Write(nSourceCode, 3, "Return XmlList(Of " + objectXmlName + ").ConvertToXmlBasicType(Me)"); DataBaseClassWriter.Write(nSourceCode, 2, "End Function"); DataBaseClassWriter.Write(nSourceCode, 0, ""); // Tipo simple objectName = FormatCode.ToIdentifier(table.Object_Name); objectXmlName = objectName + "SimpleType"; DataBaseClassWriter.Write(nSourceCode, 0, ""); DataBaseClassWriter.Write(nSourceCode, 2, "<Global.System.Diagnostics.DebuggerNonUserCodeAttribute()> _"); DataBaseClassWriter.Write(nSourceCode, 2, "Public Function To" + objectXmlName + "() As " + objectXmlName + ""); DataBaseClassWriter.Write(nSourceCode, 3, "Return XmlList(Of " + objectXmlName + ").ConvertToXmlBasicType(Me)"); DataBaseClassWriter.Write(nSourceCode, 2, "End Function"); DataBaseClassWriter.Write(nSourceCode, 0, ""); DataBaseClassWriter.Write(nSourceCode, 0, "#End Region"); DataBaseClassWriter.Write(nSourceCode, 0, ""); DataBaseClassWriter.Write(nSourceCode, 1, "End Class"); DataBaseClassWriter.Write(nSourceCode, 0, ""); // Entidad que representa un Row para XML // Tipo Complejo objectXmlName = objectName + "Type"; nInColumns = nDataBaseMap.GetTableColumns(table); DataBaseClassWriter.Write(nSourceCode, 1, "<Serializable> _ "); DataBaseClassWriter.Write(nSourceCode, 1, "Public Class " + objectXmlName); DataBaseClassWriter.Write(nSourceCode, 2, "Inherits XmlBase"); DataBaseClassWriter.Write(nSourceCode, 2, ""); DataBaseClassWriter.Write(nSourceCode, 2, " Public Sub New()"); DataBaseClassWriter.Write(nSourceCode, 2, " End Sub"); DataBaseClassWriter.Write(nSourceCode, 2, ""); foreach (var par in nInColumns) { DataBaseClassWriter.Write(nSourceCode, 2, "Public " + par.Name + " As " + DataBaseClassWriter.GetApplicationStringType(par.Type, LanguajeType.VB, true)); } DataBaseClassWriter.Write(nSourceCode, 2, ""); DataBaseClassWriter.Write(nSourceCode, 1, "End Class"); DataBaseClassWriter.Write(nSourceCode, 0, ""); // Tipo simple objectXmlName = objectName + "SimpleType"; nInColumns = nDataBaseMap.GetTableColumns(table); DataBaseClassWriter.Write(nSourceCode, 1, "<Serializable> _ "); DataBaseClassWriter.Write(nSourceCode, 1, "Public Class " + objectXmlName); DataBaseClassWriter.Write(nSourceCode, 2, "Inherits XmlBase"); DataBaseClassWriter.Write(nSourceCode, 2, ""); DataBaseClassWriter.Write(nSourceCode, 2, " Public Sub New()"); DataBaseClassWriter.Write(nSourceCode, 2, " End Sub"); DataBaseClassWriter.Write(nSourceCode, 2, ""); foreach (var par in nInColumns) { DataBaseClassWriter.Write(nSourceCode, 2, "Public " + par.Name + " As " + DataBaseClassWriter.getLanguajeStringType(par.Type, LanguajeType.VB)); } DataBaseClassWriter.Write(nSourceCode, 2, ""); DataBaseClassWriter.Write(nSourceCode, 1, "End Class"); DataBaseClassWriter.Write(nSourceCode, 2, "#End Region"); DataBaseClassWriter.Write(nSourceCode, 0, ""); } }