Example #1
0
        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, "");
            }
        }