public static StringBuilder WriteDataBaseManager(XsdDataBase.TBL_ConnectionRow nConnection, string nCatalogClassName, string nNamespaceMap) { var SourceCode = new StringBuilder(); // Escribir el encabezado DataBaseClassWriter.Write(SourceCode, 0, "//------------------------------------------------------------------------------"); DataBaseClassWriter.Write(SourceCode, 0, "// <auto-generated>"); DataBaseClassWriter.Write(SourceCode, 0, "// Este código fue generado automaticamente por una herramienta de propiedad de CargoMaster"); DataBaseClassWriter.Write(SourceCode, 0, "// Versión del motor en tiempo de ejecución: " + Program.AssemblyVersion); DataBaseClassWriter.Write(SourceCode, 0, "// </auto-generated>"); DataBaseClassWriter.Write(SourceCode, 0, "//------------------------------------------------------------------------------"); DataBaseClassWriter.Write(SourceCode, 0, "// Conexion: " + nConnection.Connection_Name); DataBaseClassWriter.Write(SourceCode, 0, ""); // Escribir el namespace DataBaseClassWriter.Write(SourceCode, 0, "namespace " + nNamespaceMap + (nNamespaceMap == "" ? nCatalogClassName : "." + nCatalogClassName)); DataBaseClassWriter.Write(SourceCode, 0, "{"); // Escribir inicio de la clase DBManager DataBaseClassWriter.Write(SourceCode, 1, "public partial class " + nCatalogClassName + "DBManager"); DataBaseClassWriter.Write(SourceCode, 1, "{"); DataBaseClassWriter.Write(SourceCode, 1, "}"); DataBaseClassWriter.Write(SourceCode, 0, "}"); return SourceCode; }
public FormCatalogConfig(XsdDataBase nData) { InitializeComponent(); DataBaseDataSet = nData; CatalogDataGridView.DataSource = DataBaseDataSet; DataBaseDataSet.TBL_Catalog.AcceptChanges(); }
public static StringBuilder WriteDataBaseManagerDesigner(XsdDataBase.TBL_ConnectionRow nConnection, string nCatalogClassName, string nCatalog, string nNamespaceMap, XsdDataBase nDataBaseMap, bool IsMobile, bool UseFramework2) { var SourceCode = new StringBuilder(); var schemas = CMData.DataBase.DataBase.GetDistinctRows( nDataBaseMap.TBL_Object.Select("fk_Connection = " + nConnection.id_Connection + " AND Catalog_Name = '" + nCatalog + "' AND Selected = 1"), "Schema_Name"); //Encabezado del archivo WriteBeginSource(ref SourceCode, nConnection.Connection_Name, nNamespaceMap, nCatalogClassName); // Escribir la clase WriteDatabaseManagerClass(ref SourceCode, nDataBaseMap, nConnection.id_Connection, nCatalogClassName, schemas, nCatalog); // Escribir enumeración de esquemas DataBaseClassWriter.Write(SourceCode, 0, ""); DataBaseClassWriter.Write(SourceCode, 1, "#region Enumeraciones del DBManager"); DataBaseClassWriter.Write(SourceCode, 0, ""); WriteSchemaEnum(ref SourceCode, nDataBaseMap, nConnection.id_Connection, nCatalogClassName, nCatalog, schemas); DataBaseClassWriter.Write(SourceCode, 0, ""); DataBaseClassWriter.Write(SourceCode, 1, "#endregion"); DataBaseClassWriter.Write(SourceCode, 0, ""); // Escribir las clases de los esquemas WriteSchemaManager(ref SourceCode, nCatalog, schemas, nDataBaseMap, nConnection.id_Connection, IsMobile, UseFramework2); // Escribir los datasets WriteDatasets(ref SourceCode, schemas, nCatalog, nDataBaseMap, nConnection.id_Connection, IsMobile); // Final del archivo WriteEndSource(ref SourceCode); return SourceCode; }
public void CompareAndRestoreObjectStoredProcedure(XsdDataBase.TBL_ObjectRow originalObject, XsdDataBase.TBL_ObjectRow newObject, ref StringBuilder log) { var strLogObject = new StringBuilder(""); if (originalObject != null) { newObject.Catalog_Name = originalObject.Catalog_Name; newObject.Schema_Name = originalObject.Schema_Name; newObject.Object_Type = originalObject.Object_Type; newObject.Object_Name = originalObject.Object_Name; newObject.Selected = originalObject.Selected; newObject.Mapped = originalObject.Mapped; if (strLogObject.ToString() != "") { log.AppendLine("Se encontraron errores en el procedimiento almacenado [" + originalObject.Object_Name + "]"); log.AppendLine(strLogObject.ToString()); } } else { log.AppendLine("El procedimiento almacenado [" + newObject.Object_Name + "] ha sido agregado recientemente"); } }
private static void WriteDatasets(ref StringBuilder nSourceCode, DataTable schemas, string nCatalog, XsdDataBase nDataBaseMap, int nidConnection, bool IsMobile) { DataBaseClassWriter.Write(nSourceCode, 1, "#region Datasets"); DataBaseClassWriter.Write(nSourceCode, 0, ""); foreach (DataRow schema in schemas.Rows) { var SchemaConfig = nDataBaseMap.TBL_Schema.FindByfk_ConnectionSchema_Name(nidConnection, schema["Schema_Name"].ToString ()); var SchemaNameDataSet = SchemaConfig.Schema_Alias + "DataSet"; DataBaseClassWriter.Write(nSourceCode, 1, "[global::System.CodeDom.Compiler.GeneratedCodeAttribute(\"System.Data.Design.TypedDataSetGenerator\", \"2.0.0.0\")]"); DataBaseClassWriter.Write(nSourceCode, 1, "[global::System.Serializable()]"); DataBaseClassWriter.Write(nSourceCode, 1, "[global::System.ComponentModel.DesignerCategoryAttribute(\"code\")]"); if (!IsMobile) DataBaseClassWriter.Write(nSourceCode, 1, "[global::System.ComponentModel.ToolboxItem(true)]"); DataBaseClassWriter.Write(nSourceCode, 1, "[global::System.Xml.Serialization.XmlSchemaProviderAttribute(\"GetTypedDataSetSchema\")]"); DataBaseClassWriter.Write(nSourceCode, 1, "[global::System.Xml.Serialization.XmlRootAttribute(\"" + SchemaNameDataSet + "\")]"); if (!IsMobile) DataBaseClassWriter.Write(nSourceCode, 1, "[global::System.ComponentModel.Design.HelpKeywordAttribute(\"vs.data.DataSet\")]"); DataBaseClassWriter.Write(nSourceCode, 1, "public class " + SchemaNameDataSet + ": DataSet"); DataBaseClassWriter.Write(nSourceCode, 1, "{"); var sqlFilter = "(Generic_Type = 'Table' OR Generic_Type = 'View') AND Catalog_Name = '" + nCatalog + "' AND Schema_Name = '" + SchemaConfig.Schema_Name + "' AND Selected = 1"; var tablas = (XsdDataBase.TBL_ObjectRow[]) (nDataBaseMap.TBL_Object.Select(sqlFilter)); DataBaseClassWriter.Write(nSourceCode, 2, "#region Declaraciones"); DataBaseClassWriter.Write(nSourceCode, 0, ""); foreach (var tabla in tablas) { DataBaseClassWriter.Write(nSourceCode, 2, "private Schema" + SchemaConfig.Schema_Alias + "." + FormatCode.ToIdentifier(tabla.Object_Name) + "DataTable table" + FormatCode.ToIdentifier(tabla.Object_Name) + ";"); } DataBaseClassWriter.Write(nSourceCode, 0, ""); DataBaseClassWriter.Write(nSourceCode, 2, "#endregion"); DataBaseClassWriter.Write(nSourceCode, 0, ""); DataBaseClassWriter.Write(nSourceCode, 2, "#region Propiedades"); DataBaseClassWriter.Write(nSourceCode, 0, ""); foreach (var tabla in tablas) { DataBaseClassWriter.Write(nSourceCode, 2, "[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]"); if (!IsMobile) { DataBaseClassWriter.Write(nSourceCode, 2, "[global::System.ComponentModel.Browsable(false)]"); DataBaseClassWriter.Write(nSourceCode, 2, "[global::System.ComponentModel.DesignerSerializationVisibility(global::System.ComponentModel.DesignerSerializationVisibility.Content)]"); } DataBaseClassWriter.Write(nSourceCode, 2, "public Schema" + SchemaConfig.Schema_Alias + "." + FormatCode.ToIdentifier(tabla.Object_Name) + "DataTable " + FormatCode.ToIdentifier(tabla.Object_Name)); DataBaseClassWriter.Write(nSourceCode, 2, "{"); DataBaseClassWriter.Write(nSourceCode, 3, "get { return this.table" + FormatCode.ToIdentifier(tabla.Object_Name) + "; }"); DataBaseClassWriter.Write(nSourceCode, 2, "}"); DataBaseClassWriter.Write(nSourceCode, 0, ""); } DataBaseClassWriter.Write(nSourceCode, 0, ""); DataBaseClassWriter.Write(nSourceCode, 2, "#endregion"); DataBaseClassWriter.Write(nSourceCode, 0, ""); DataBaseClassWriter.Write(nSourceCode, 2, "#region Metodos"); DataBaseClassWriter.Write(nSourceCode, 0, ""); DataBaseClassWriter.Write(nSourceCode, 2, "public " + SchemaNameDataSet + "()"); DataBaseClassWriter.Write(nSourceCode, 3, ": base()"); DataBaseClassWriter.Write(nSourceCode, 2, "{"); foreach (var tabla in tablas) { DataBaseClassWriter.Write(nSourceCode, 3, "if((this.Tables[\"" + tabla.Object_Name + "\"]) == null)"); DataBaseClassWriter.Write(nSourceCode, 3, "{"); DataBaseClassWriter.Write(nSourceCode, 4, "this.table" + FormatCode.ToIdentifier(tabla.Object_Name) + " = new Schema" + SchemaConfig.Schema_Alias + "." + FormatCode.ToIdentifier(tabla.Object_Name) + "DataTable();"); DataBaseClassWriter.Write(nSourceCode, 4, "base.Tables.Add(this.table" + FormatCode.ToIdentifier(tabla.Object_Name) + ");"); DataBaseClassWriter.Write(nSourceCode, 3, "}"); } DataBaseClassWriter.Write(nSourceCode, 2, "}"); DataBaseClassWriter.Write(nSourceCode, 1, ""); DataBaseClassWriter.Write(nSourceCode, 2, "[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]"); DataBaseClassWriter.Write(nSourceCode, 2, "protected override bool ShouldSerializeTables()"); DataBaseClassWriter.Write(nSourceCode, 2, "{"); DataBaseClassWriter.Write(nSourceCode, 3, "return false;"); DataBaseClassWriter.Write(nSourceCode, 2, "}"); DataBaseClassWriter.Write(nSourceCode, 1, ""); DataBaseClassWriter.Write(nSourceCode, 2, "[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]"); DataBaseClassWriter.Write(nSourceCode, 2, "protected override bool ShouldSerializeRelations()"); DataBaseClassWriter.Write(nSourceCode, 2, "{"); DataBaseClassWriter.Write(nSourceCode, 3, "return false;"); DataBaseClassWriter.Write(nSourceCode, 2, "}"); DataBaseClassWriter.Write(nSourceCode, 1, ""); foreach (var tabla in tablas) { DataBaseClassWriter.Write(nSourceCode, 2, "[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]"); DataBaseClassWriter.Write(nSourceCode, 2, "private bool ShouldSerialize" + FormatCode.ToIdentifier(tabla.Object_Name) + "()"); DataBaseClassWriter.Write(nSourceCode, 2, "{"); DataBaseClassWriter.Write(nSourceCode, 3, "return false;"); DataBaseClassWriter.Write(nSourceCode, 2, "}"); DataBaseClassWriter.Write(nSourceCode, 1, ""); } DataBaseClassWriter.Write(nSourceCode, 2, "#endregion"); DataBaseClassWriter.Write(nSourceCode, 0, ""); DataBaseClassWriter.Write(nSourceCode, 1, "}"); DataBaseClassWriter.Write(nSourceCode, 0, ""); } // Fin de esquemas DataBaseClassWriter.Write(nSourceCode, 1, "#endregion"); }
private static void WriteStoreProcedures(ref StringBuilder nSourceCode, XsdDataBase nDataBaseMap, XsdDataBase.TBL_ObjectRow[] nObjetos) { foreach (var Objeto in nObjetos) { var ObjetNameFormated = FormatCode.ToIdentifier(Objeto.Object_Name); var ObjetNameFormatedType = ObjetNameFormated + "StoreProcedure"; DataBaseClassWriter.Write(nSourceCode, 2, "/// <summary>"); DataBaseClassWriter.Write(nSourceCode, 2, "/// Clase encargada de encapsular las funcionalidades de acceso al procedimiento almacenado " + Objeto.Object_Name); DataBaseClassWriter.Write(nSourceCode, 2, "/// </summary>"); DataBaseClassWriter.Write(nSourceCode, 2, "public class " + ObjetNameFormatedType + " : StoreProcedureManager"); 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, ""); var opetarionParams = ""; var returnRows = Objeto.GetTBL_SP_ReturnRows(); var retType = ReturnType.TablaGenerica; XsdDataBase.TBL_ObjectRow objectReturned = null; var dataTypeReturned = DbType.Object; if (returnRows.Length > 0) { retType = (ReturnType) (Enum.Parse(typeof (ReturnType), returnRows[0].Return_Type)); switch (retType) { case ReturnType.TablaTipada: DataRow[] Filas = nDataBaseMap.TBL_Object.Select("Schema_Name = '" + returnRows[0].Schema_Name_Returned + "' AND Object_Name = '" + returnRows[0].Object_Name_Returned + "'"); if (Filas.Length > 0) objectReturned = (XsdDataBase.TBL_ObjectRow) (Filas[0]); else throw new Exception("El procedimiento almacenado " + Objeto.Object_Name + ", retorna un objeto de tipo " + returnRows[0].Object_Name_Returned + " que no se encuentra definido"); //objectReturned = (XsdDataBase.TBL_ObjectRow)(nDataBaseMap.TBL_Object.Select("Schema_Name = '" + returnRows[0].Schema_Name_Returned + "' AND Object_Name = '" + returnRows[0].Object_Name_Returned + "'")[0]); break; case ReturnType.Escalar: dataTypeReturned = (DbType) (Enum.Parse(typeof (DbType), returnRows[0].Data_Type_Returned)); break; } } var nParameters = nDataBaseMap.GetParameters(Objeto); opetarionParams = ""; foreach (var par in nParameters) { if (opetarionParams != "") opetarionParams += ", "; opetarionParams = opetarionParams + DataBaseClassWriter.GetApplicationStringType(par.Type, LanguajeType.CSharp, true) + " n" + par.Name.TrimStart('@'); } DataBaseClassWriter.Write(nSourceCode, 3, "#region Metodos"); DataBaseClassWriter.Write(nSourceCode, 0, ""); if (retType == ReturnType.Nada) { DataBaseClassWriter.Write(nSourceCode, 3, "/// <summary>"); DataBaseClassWriter.Write(nSourceCode, 3, "///Permite la ejecución del procedimiento almacenado " + Objeto.Object_Name); DataBaseClassWriter.Write(nSourceCode, 3, "/// </summary>"); DataBaseClassWriter.Write(nSourceCode, 3, "[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]"); DataBaseClassWriter.Write(nSourceCode, 3, "public void DBExecute(" + opetarionParams + ")"); DataBaseClassWriter.Write(nSourceCode, 3, "{"); DataBaseClassWriter.Write(nSourceCode, 4, "List<Parameter> nParameters = new List<Parameter>();"); foreach (var par in nParameters) { DataBaseClassWriter.Write(nSourceCode, 4, "nParameters.Add(new Parameter(\"" + par.Name + "\", DbType." + par.Type.ToString() + ", \"" + par.SpecificType + "\", n" + par.Name.TrimStart('@') + ", " + DataBaseClassWriter.getBoolean(par.IsNullable, LanguajeType.CSharp) + ", " + par.MaxLength + ", " + par.Precision + ", " + par.Scale + ", ParameterDirection." + par.Direction.ToString() + "));"); } DataBaseClassWriter.Write(nSourceCode, 4, "base.DBExecuteSp(nParameters);"); DataBaseClassWriter.Write(nSourceCode, 3, "}"); DataBaseClassWriter.Write(nSourceCode, 0, ""); } else { var strReturnType = ""; switch (retType) { case ReturnType.Escalar: strReturnType = DataBaseClassWriter.GetApplicationStringType(dataTypeReturned.ToString(), LanguajeType.CSharp); break; case ReturnType.TablaTipada: if (objectReturned != null) strReturnType = "Schema" + FormatCode.ToIdentifier(objectReturned.Schema_Name) + "." + FormatCode.ToIdentifier(objectReturned.Object_Name) + "DataTable"; break; case ReturnType.TablaGenerica: strReturnType = "DataTable"; break; } DataBaseClassWriter.Write(nSourceCode, 3, "///<summary>"); DataBaseClassWriter.Write(nSourceCode, 3, "///Permite la ejecución del procedimiento almacenado " + Objeto.Object_Name + " y retorna los datos encontrados"); DataBaseClassWriter.Write(nSourceCode, 3, "///</summary>"); DataBaseClassWriter.Write(nSourceCode, 3, "[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]"); DataBaseClassWriter.Write(nSourceCode, 3, "public " + strReturnType + " DBExecute(" + opetarionParams + ")"); DataBaseClassWriter.Write(nSourceCode, 3, "{"); DataBaseClassWriter.Write(nSourceCode, 4, "List<Parameter> nParameters = new List<Parameter>();"); foreach (var par in nParameters) { DataBaseClassWriter.Write(nSourceCode, 4, "nParameters.Add(new Parameter(\"" + par.Name + "\", DbType." + par.Type.ToString() + ", \"" + par.SpecificType + "\", n" + par.Name.TrimStart('@') + ", " + DataBaseClassWriter.getBoolean(par.IsNullable, LanguajeType.CSharp) + ", " + par.MaxLength + ", " + par.Precision + ", " + par.Scale + ", ParameterDirection." + par.Direction.ToString() + "));"); } if (retType == ReturnType.Escalar) { DataBaseClassWriter.Write(nSourceCode, 4, "try"); DataBaseClassWriter.Write(nSourceCode, 4, "{"); DataBaseClassWriter.Write(nSourceCode, 5, strReturnType + " Value;"); DataBaseClassWriter.Write(nSourceCode, 5, "DataTable tableData = new DataTable();"); DataBaseClassWriter.Write(nSourceCode, 5, "base.DBExecuteSp(tableData, nParameters);"); DataBaseClassWriter.Write(nSourceCode, 5, "if(tableData.Rows.Count > 0)"); DataBaseClassWriter.Write(nSourceCode, 5, "{"); if (strReturnType.ToUpper() == "STRING") DataBaseClassWriter.Write(nSourceCode, 6, "Value = tableData.Rows[0][0].ToString();"); if (dataTypeReturned.ToString().ToUpper() == "BINARY") DataBaseClassWriter.Write(nSourceCode, 6, "Value = (byte[])tableData.Rows[0][0];"); else DataBaseClassWriter.Write(nSourceCode, 6, "Value = " + GetConvertFuncion(dataTypeReturned.ToString()) + "(tableData.Rows[0][0].ToString());"); DataBaseClassWriter.Write(nSourceCode, 6, "return Value;"); DataBaseClassWriter.Write(nSourceCode, 5, "}"); DataBaseClassWriter.Write(nSourceCode, 5, "else"); DataBaseClassWriter.Write(nSourceCode, 5, "{"); DataBaseClassWriter.Write(nSourceCode, 5, "throw new Exception(\"El procedimiento no retornó valor\");"); DataBaseClassWriter.Write(nSourceCode, 5, "}"); DataBaseClassWriter.Write(nSourceCode, 4, "}"); DataBaseClassWriter.Write(nSourceCode, 4, "catch( Exception ex)"); DataBaseClassWriter.Write(nSourceCode, 4, "{"); DataBaseClassWriter.Write(nSourceCode, 5, "throw new Exception(\"No fue posible ejecutar el procedimiento almacenado " + Objeto.Object_Name + ", \" + ex.Message, ex);"); DataBaseClassWriter.Write(nSourceCode, 4, "}"); } else { DataBaseClassWriter.Write(nSourceCode, 4, "DataTable tableData = new " + strReturnType + "();"); DataBaseClassWriter.Write(nSourceCode, 4, "try"); DataBaseClassWriter.Write(nSourceCode, 4, "{"); DataBaseClassWriter.Write(nSourceCode, 5, "base.DBExecuteSp(tableData, nParameters);"); DataBaseClassWriter.Write(nSourceCode, 4, "}"); DataBaseClassWriter.Write(nSourceCode, 4, "catch(Exception ex)"); DataBaseClassWriter.Write(nSourceCode, 4, "{"); DataBaseClassWriter.Write(nSourceCode, 5, "throw new Exception(\"No fue posible ejecutar el procedimiento almacenado " + Objeto.Object_Name + ", \" + ex.Message, ex);"); DataBaseClassWriter.Write(nSourceCode, 4, "}"); DataBaseClassWriter.Write(nSourceCode, 4, "return (" + strReturnType + ")tableData;"); } DataBaseClassWriter.Write(nSourceCode, 3, "}"); DataBaseClassWriter.Write(nSourceCode, 0, ""); } if (retType == ReturnType.TablaTipada || retType == ReturnType.TablaGenerica) { DataBaseClassWriter.Write(nSourceCode, 3, "///<summary>"); DataBaseClassWriter.Write(nSourceCode, 3, "///Permite la ejecución del procedimiento almacenado " + Objeto.Object_Name + " y retorna los datos encontrados"); DataBaseClassWriter.Write(nSourceCode, 3, "///</summary>"); DataBaseClassWriter.Write(nSourceCode, 3, "[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]"); DataBaseClassWriter.Write(nSourceCode, 3, "public void DBExecute(DataTable tableData" + (opetarionParams == "" ? "" : ", " + opetarionParams) + ")"); DataBaseClassWriter.Write(nSourceCode, 3, "{"); DataBaseClassWriter.Write(nSourceCode, 4, "List<Parameter> nParameters = new List<Parameter>();"); foreach (var par in nParameters) { DataBaseClassWriter.Write(nSourceCode, 4, "nParameters.Add(new Parameter(\"" + par.Name + "\", DbType." + par.Type.ToString() + ", \"" + par.SpecificType + "\", n" + par.Name.TrimStart('@') + ", " + DataBaseClassWriter.getBoolean(par.IsNullable, LanguajeType.CSharp) + ", " + par.MaxLength + ", " + par.Precision + ", " + par.Scale + ", ParameterDirection." + par.Direction.ToString() + "));"); } DataBaseClassWriter.Write(nSourceCode, 4, "try"); DataBaseClassWriter.Write(nSourceCode, 4, "{"); DataBaseClassWriter.Write(nSourceCode, 5, "base.DBExecuteSp(tableData, nParameters);"); DataBaseClassWriter.Write(nSourceCode, 4, "}"); DataBaseClassWriter.Write(nSourceCode, 4, "catch(Exception ex)"); DataBaseClassWriter.Write(nSourceCode, 4, "{"); DataBaseClassWriter.Write(nSourceCode, 5, "throw new Exception(\"No fue posible ejecutar el procedimiento almacenado " + Objeto.Object_Name + ", \" + ex.Message, ex);"); DataBaseClassWriter.Write(nSourceCode, 4, "}"); DataBaseClassWriter.Write(nSourceCode, 3, "}"); DataBaseClassWriter.Write(nSourceCode, 0, ""); } DataBaseClassWriter.Write(nSourceCode, 3, "#endregion"); DataBaseClassWriter.Write(nSourceCode, 2, "}"); // Fin de la clase DataBaseClassWriter.Write(nSourceCode, 0, ""); } }
public void RemoveObjects(XsdDataBase ds, int id_Connection, string objectType) { DataRow[] rows = ds.TBL_Object.Select("fk_Connection = " + id_Connection + " AND Generic_Type = '" + objectType + "'"); foreach (var row in rows) { row.Delete(); } }
private void ShowObjectConfig(XsdDataBase.TBL_ObjectRow obj) { if (obj.Generic_Type == "StoredProcedure") { var dlg = new FormConfigStoredProcedure(); dlg.SetDataSource(DataBaseDataSet, SelectedConnection, obj); dlg.ShowDialog(); } else { var dlg = new FormConfigTableFilter(); dlg.SetDataSource(DataBaseDataSet, obj.id_Object); dlg.ShowDialog(); } }
public void RemoveObjectsReturnedInStoredProcedures(XsdDataBase ds, int id_Connection) { var spRows = FindObjects(ds, id_Connection, "StoredProcedure"); foreach (var spRow in spRows) { var oldSPReturns = (XsdDataBase.TBL_SP_ReturnRow[])ds.TBL_SP_Return.Select("fk_Object = " + spRow.id_Object); if (oldSPReturns.Length > 0) { var Return_Type = (ReturnType)(Enum.Parse(typeof(ReturnType), oldSPReturns[0].Return_Type)); if (Return_Type == ReturnType.TablaTipada) { ds.TBL_SP_Return.RemoveTBL_SP_ReturnRow(oldSPReturns[0]); } } } }
public override void FillDataBaseViews(XsdDataBase.TBL_ObjectDataTable nObjectTable, XsdDataBase.TBL_ConnectionRow nConnection, List<string> nSchemaFilter) { try { var sql = new StringBuilder(); sql.AppendLine(@"SELECT c.table_catalog , c.table_schema, c.table_name, c.table_type FROM information_schema.tables c"); sql.AppendLine(@"WHERE c.table_type = 'VIEW' AND c.table_schema NOT IN('information_schema', 'pg_catalog')"); if (nSchemaFilter != null && nSchemaFilter.Count > 0) { string CadenaFiltro = ""; foreach (var Filtro in nSchemaFilter) { if (CadenaFiltro != "") CadenaFiltro += ", "; CadenaFiltro += "'" + Filtro + "'"; } sql.AppendLine(@"AND c.table_schema IN(" + CadenaFiltro + ")"); } sql.AppendLine(@"ORDER BY c.table_schema, c.table_name"); DataTable table = ExecuteQueryGet(sql.ToString()); for (int i = 0; i < table.Rows.Count; i++) { DataRow row = table.Rows[i]; var newObjectRow = nObjectTable.NewTBL_ObjectRow(); newObjectRow.fk_Connection = nConnection.id_Connection; newObjectRow.Catalog_Name = row["table_catalog"].ToString(); newObjectRow.Schema_Name = row["table_schema"].ToString(); newObjectRow.Object_Type = row["table_type"].ToString(); newObjectRow.Generic_Type = "View"; newObjectRow.Object_Name = row["table_name"].ToString(); newObjectRow.Selected = false; nObjectTable.AddTBL_ObjectRow(newObjectRow); } } catch (Exception ex) { throw new Exception("No fue posible obtener el listado de tablas " + base.Connection.DataSource + " , " + ex.Message, ex); } }
public override void FillDataBaseParameters(XsdDataBase.TBL_FieldDataTable nFieldTable, XsdDataBase.TBL_ObjectRow nTable) { try { string sql = @"SELECT p.parameter_name , 'NO' is_nullable , p.data_type , p.character_maximum_length, p.numeric_precision , p.numeric_scale , p.udt_name , p.ordinal_position , p.parameter_mode" + ControlChars.CrLf + "FROM information_schema.routines r INNER JOIN information_schema.parameters p ON p.specific_catalog = r.specific_catalog AND p.specific_schema = r.specific_schema AND p.specific_name = r.specific_name" + ControlChars.CrLf + "WHERE r.routine_type = 'FUNCTION' AND r.specific_schema NOT IN('information_schema', 'pg_catalog')" + ControlChars.CrLf + "AND r.routine_catalog = '" + nTable.Catalog_Name + "' AND r.routine_schema = '" + nTable.Schema_Name + "' AND r.routine_name = '" + nTable.Object_Name + "'" + ControlChars.CrLf + "ORDER BY p.ordinal_position"; DataTable table = ExecuteQueryGet(sql); for (int i = 0; i < table.Rows.Count; i++) { DataRow row = table.Rows[i]; nFieldTable.AddTBL_FieldRow(nTable, row["parameter_name"].ToString(), GetGenericParameterType(row["udt_name"].ToString()).ToString(), row["data_type"].ToString(), (row["is_nullable"].ToString().ToUpper() != "NO"), ConvertToInt(row["character_maximum_length"]), ConvertToByte(row["numeric_precision"]), ConvertToByte(row["numeric_scale"]), row["ordinal_position"].ToString(), GetGenericParameterDirection(row["parameter_mode"].ToString())); } } catch (Exception ex) { throw new Exception("No fue posible obtener el listado de columnas " + base.Connection.DataSource + " Tabla = " + nTable.Object_Name + ", " + ex.Message, ex); } }
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 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 WriteDBFindByOrderBy(ref StringBuilder nSourceCode, XsdDataBase nDataBaseMap, XsdDataBase.TBL_ObjectRow tabla, ref int idMetodo, XsdDataBase.TBL_FilterRow filtro, string ObjetNameFormated) { var nFilterParam = nDataBaseMap.GetFilterColumns(filtro, tabla.id_Object); var opetarionParams = ""; var strLine = ""; foreach (var par in nFilterParam) { if (opetarionParams != "") opetarionParams += ", "; opetarionParams = opetarionParams + DataBaseClassWriter.GetApplicationStringType(par.Type, LanguajeType.CSharp, true) + " n" + par.Name; strLine += " " + par.Name; } var FunctionName = strLine.Replace(" ", ""); if (FunctionName.Length > 500) { idMetodo++; FunctionName = FunctionName.Substring(0, 500) + idMetodo.ToString(); } DataBaseClassWriter.Write(nSourceCode, 3, "/// <summary>"); DataBaseClassWriter.Write(nSourceCode, 3, "/// Retorna registros de la tabla " + tabla.Object_Name + ", filtrando por" + strLine); DataBaseClassWriter.Write(nSourceCode, 3, "/// </summary>"); DataBaseClassWriter.Write(nSourceCode, 3, "[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]"); DataBaseClassWriter.Write(nSourceCode, 3, "public " + ObjetNameFormated + "DataTable DBFindBy" + FunctionName + "(" + opetarionParams + (opetarionParams == "" ? "" : ", ") + "int nMaxRows, " + ObjetNameFormated + "EnumList nOrderByParams)"); DataBaseClassWriter.Write(nSourceCode, 3, "{"); DataBaseClassWriter.Write(nSourceCode, 4, "List<Parameter> nFilters = new List<Parameter>();"); foreach (var par in nFilterParam) { DataBaseClassWriter.Write(nSourceCode, 4, "nFilters.Add(new Parameter(\"" + par.Name + "\", DbType." + par.Type.ToString() + ", \"" + par.SpecificType + "\", n" + par.Name + ", " + DataBaseClassWriter.getBoolean(par.IsNullable, LanguajeType.CSharp) + ", " + par.MaxLength + ", " + par.Precision + ", " + par.Scale + ", ParameterDirection." + par.Direction.ToString() + "));"); } DataBaseClassWriter.Write(nSourceCode, 4, FormatCode.ToIdentifier(tabla.Object_Name) + "DataTable nDataTable = new " + ObjetNameFormated + "DataTable();"); DataBaseClassWriter.Write(nSourceCode, 4, "base.DBFill(nDataTable, nFilters, nMaxRows, nOrderByParams);"); DataBaseClassWriter.Write(nSourceCode, 4, "return nDataTable;"); DataBaseClassWriter.Write(nSourceCode, 3, "}"); DataBaseClassWriter.Write(nSourceCode, 0, ""); }
private static void WriteDatabaseManagerClass(ref StringBuilder nSourceCode, XsdDataBase nDataBaseMap, int nidConnection, string nCatalogClassName, DataTable schemas, string nCatalog) { // Escribir inicio de la clase DBManager DataBaseClassWriter.Write(nSourceCode, 1, "/// <summary>"); DataBaseClassWriter.Write(nSourceCode, 1, "/// Clase encargada de encapsular todos los accesos a la base de datos " + nCatalog); DataBaseClassWriter.Write(nSourceCode, 1, "/// </summary>"); DataBaseClassWriter.Write(nSourceCode, 1, "public partial class " + nCatalogClassName + "DBManager : DBManager"); DataBaseClassWriter.Write(nSourceCode, 1, "{"); // Declaracion variables locales de los esquemas DataBaseClassWriter.Write(nSourceCode, 2, "#region Declaraciones"); DataBaseClassWriter.Write(nSourceCode, 0, ""); foreach (DataRow schema in schemas.Rows) { var SchemaConfig = nDataBaseMap.TBL_Schema.FindByfk_ConnectionSchema_Name(nidConnection, schema["Schema_Name"].ToString ()); DataBaseClassWriter.Write(nSourceCode, 2, "private " + SchemaConfig.Schema_Alias + "Schema" + " _Schema" + SchemaConfig.Schema_Alias + ";"); } DataBaseClassWriter.Write(nSourceCode, 0, ""); DataBaseClassWriter.Write(nSourceCode, 2, "#endregion"); DataBaseClassWriter.Write(nSourceCode, 0, ""); // Propiedades de acceso a los esquemas DataBaseClassWriter.Write(nSourceCode, 2, "#region Propiedades"); DataBaseClassWriter.Write(nSourceCode, 0, ""); foreach (DataRow schema in schemas.Rows) { var SchemaConfig = nDataBaseMap.TBL_Schema.FindByfk_ConnectionSchema_Name(nidConnection, schema["Schema_Name"].ToString ()); DataBaseClassWriter.Write(nSourceCode, 2, "public " + SchemaConfig.Schema_Alias + "Schema" + " Schema" + SchemaConfig.Schema_Alias); DataBaseClassWriter.Write(nSourceCode, 2, "{"); DataBaseClassWriter.Write(nSourceCode, 3, "get { return _Schema" + SchemaConfig.Schema_Alias + "; }"); DataBaseClassWriter.Write(nSourceCode, 2, "}"); } DataBaseClassWriter.Write(nSourceCode, 0, ""); DataBaseClassWriter.Write(nSourceCode, 2, "public override string ClassFileName"); DataBaseClassWriter.Write(nSourceCode, 2, "{"); DataBaseClassWriter.Write(nSourceCode, 3, "get { return this.GetType().Name; }"); DataBaseClassWriter.Write(nSourceCode, 2, "}"); DataBaseClassWriter.Write(nSourceCode, 0, ""); DataBaseClassWriter.Write(nSourceCode, 2, "#endregion"); DataBaseClassWriter.Write(nSourceCode, 0, ""); // Constructores de la clase DataBaseClassWriter.Write(nSourceCode, 2, "#region Constructores"); DataBaseClassWriter.Write(nSourceCode, 0, ""); DataBaseClassWriter.Write(nSourceCode, 2, "public " + nCatalogClassName + "DBManager(string nConnectionString)"); DataBaseClassWriter.Write(nSourceCode, 3, ": base(nConnectionString)"); DataBaseClassWriter.Write(nSourceCode, 2, "{"); DataBaseClassWriter.Write(nSourceCode, 3, "Initialize();"); DataBaseClassWriter.Write(nSourceCode, 2, "}"); DataBaseClassWriter.Write(nSourceCode, 0, ""); DataBaseClassWriter.Write(nSourceCode, 2, "private void Initialize()"); DataBaseClassWriter.Write(nSourceCode, 2, "{"); foreach (DataRow schema in schemas.Rows) { var SchemaConfig = nDataBaseMap.TBL_Schema.FindByfk_ConnectionSchema_Name(nidConnection, schema["Schema_Name"].ToString ()); DataBaseClassWriter.Write(nSourceCode, 3, "_Schema" + SchemaConfig.Schema_Alias + " = new " + SchemaConfig.Schema_Alias + "Schema(this);"); } DataBaseClassWriter.Write(nSourceCode, 0, ""); // Inicializar mapeo de esquemas DataBaseClassWriter.Write(nSourceCode, 3, "if(this.SchemaMaping.Schemas.Count == 0)"); DataBaseClassWriter.Write(nSourceCode, 3, "{"); foreach (DataRow schema in schemas.Rows) { var SchemaConfig = nDataBaseMap.TBL_Schema.FindByfk_ConnectionSchema_Name(nidConnection, schema["Schema_Name"].ToString ()); DataBaseClassWriter.Write(nSourceCode, 4, "this.SchemaMaping.Schemas.Add(\"" + SchemaConfig.Schema_Alias + "\", \"" + SchemaConfig.Schema_Name + "\");"); } DataBaseClassWriter.Write(nSourceCode, 3, "}"); DataBaseClassWriter.Write(nSourceCode, 2, "}"); DataBaseClassWriter.Write(nSourceCode, 0, ""); DataBaseClassWriter.Write(nSourceCode, 2, "#endregion"); DataBaseClassWriter.Write(nSourceCode, 1, "}"); }
public void CompareOriginalVsNewObjects(XsdDataBase originalDataBase, XsdDataBase newDataBase, ref StringBuilder log, XsdDataBase.TBL_ConnectionRow SelectedConnection) { var originalobjects = FindObjects(originalDataBase, SelectedConnection.id_Connection, "Table"); foreach (var originalObject in originalobjects) { var newObject = FindObjectRow(newDataBase, originalObject.Catalog_Name, originalObject.Schema_Name, originalObject.Object_Name); if (newObject == null) { log.AppendLine("La tabla [" + originalObject.Object_Name + "] ha sido eliminada de la base de datos "); } } originalobjects = FindObjects(originalDataBase, SelectedConnection.id_Connection, "View"); foreach (var originalObject in originalobjects) { var newObject = FindObjectRow(newDataBase, originalObject.Catalog_Name, originalObject.Schema_Name, originalObject.Object_Name); if (newObject == null) { log.AppendLine("La vista [" + originalObject.Object_Name + "] ha sido eliminada de la base de datos "); } } originalobjects = FindObjects(originalDataBase, SelectedConnection.id_Connection, "StoredProcedure"); foreach (var originalObject in originalobjects) { var newObject = FindObjectRow(newDataBase, originalObject.Catalog_Name, originalObject.Schema_Name, originalObject.Object_Name); if (newObject == null) { log.AppendLine("El procedimiento [" + originalObject.Object_Name + "] ha sido eliminado de la base de datos "); } } }
public void RestoreOriginalObjectStoredProcedure(XsdDataBase originalDataBase, XsdDataBase.TBL_ObjectRow oldObject, XsdDataBase.TBL_ObjectRow newObject, ref StringBuilder log, XsdDataBase dtsDataBase) { var strLogObject = new StringBuilder(""); if (oldObject != null) { newObject.Selected = oldObject.Selected; // Recuperar las columnas var oldColumns = (XsdDataBase.TBL_FieldRow[])(originalDataBase.TBL_Field.Select("fk_Object = " + oldObject.id_Object)); foreach (var oldColumn in oldColumns) { var newColumn = dtsDataBase.TBL_Field.NewTBL_FieldRow(); newColumn.fk_Object = newObject.id_Object; newColumn.Field_Name = oldColumn.Field_Name; newColumn.Field_Type = oldColumn.Field_Type; newColumn.Specific_Type = oldColumn.Specific_Type; newColumn.Is_Nullable = oldColumn.Is_Nullable; newColumn.Max_Length = oldColumn.Max_Length; newColumn.Precision = oldColumn.Precision; newColumn.Scale = oldColumn.Scale; newColumn.PrimaryKey_Order = oldColumn.PrimaryKey_Order; newColumn.Direction = oldColumn.Direction; dtsDataBase.TBL_Field.AddTBL_FieldRow(newColumn); } newObject.Mapped = true; if (strLogObject.ToString() != "") { log.AppendLine("Se encontraron errores en el procedimiento almacenado [" + oldObject.Object_Name + "]"); log.AppendLine(strLogObject.ToString()); newObject.Mapped = false; } } else { log.AppendLine("El procedimiento almacenado [" + newObject.Object_Name + "] ha sido agregado recientemente"); newObject.Mapped = false; } }
public void RestoreObjectsReturnedInStoredProceduresOld(XsdDataBase dsOriginal, XsdDataBase dsNew, int id_Connection, ref StringBuilder log) { var spOriginalObjects = FindObjects(dsOriginal, id_Connection, "StoredProcedure"); foreach (var spOriginalObject in spOriginalObjects) { var strLog = new StringBuilder(""); var originalReturn = (XsdDataBase.TBL_SP_ReturnRow[])(dsOriginal.TBL_SP_Return.Select("fk_Object = " + spOriginalObject.id_Object)); if (originalReturn.Length > 0) { var spNewObject = FindObjectRow(dsNew, spOriginalObject.Catalog_Name, spOriginalObject.Schema_Name, spOriginalObject.Object_Name); if (spNewObject != null) { var newReturn = dsNew.TBL_SP_Return.NewTBL_SP_ReturnRow(); newReturn.fk_Object = spNewObject.id_Object; newReturn.Return_Type = originalReturn[0].Return_Type; newReturn.Data_Type_Returned = originalReturn[0].Data_Type_Returned; dsNew.TBL_SP_Return.AddTBL_SP_ReturnRow(newReturn); var Return_Type = (ReturnType)(Enum.Parse(typeof(ReturnType), originalReturn[0].Return_Type)); if (Return_Type == ReturnType.TablaTipada) { newReturn.Schema_Name_Returned = originalReturn[0].Schema_Name_Returned; newReturn.Object_Name_Returned = originalReturn[0].Object_Name_Returned; } if (strLog.ToString() != "") { dsNew.TBL_SP_Return.RemoveTBL_SP_ReturnRow(newReturn); log.AppendLine("Se Eliminó el tipo de dato retornado del objeto [" + spNewObject.Object_Name + "] "); log.AppendLine(strLog.ToString()); } } else { log.AppendLine("El Objeto [" + spOriginalObject.Object_Name + "] no encontrado en la nueva base de datos"); } } } }
private static void WriteViews(ref StringBuilder nSourceCode, XsdDataBase nDataBaseMap, XsdDataBase.TBL_ObjectRow[] nObjetos) { foreach (var Objeto in nObjetos) { var ObjetNameFormated = FormatCode.ToIdentifier(Objeto.Object_Name); var ObjetNameFormatedType = ObjetNameFormated + "View"; DataBaseClassWriter.Write(nSourceCode, 2, "/// <summary>"); DataBaseClassWriter.Write(nSourceCode, 2, "/// Clase encargada de encapsular las funcionalidades de acceso a la vista " + Objeto.Object_Name); DataBaseClassWriter.Write(nSourceCode, 2, "/// </summary>"); DataBaseClassWriter.Write(nSourceCode, 2, "public class " + ObjetNameFormatedType + " : ViewManager"); 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, ""); // Columnas //var nViewColumns = nDataBaseMap.GetTableColumns(Objeto); // Implementacion de DBGet WriteDBGet(ref nSourceCode, new List<Parameter>(), ObjetNameFormated); WriteDBGetOrderBy(ref nSourceCode, new List<Parameter>(), ObjetNameFormated); // Implementacion de DBFill WriteDBFill(ref nSourceCode, new List<Parameter>()); WriteDBFillOrderBy(ref nSourceCode, new List<Parameter>(), ObjetNameFormated); WriteDBFillTyped(ref nSourceCode, new List<Parameter>(), ObjetNameFormated); WriteDBFillOrderByTyped(ref nSourceCode, new List<Parameter>(), 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 WriteDeclaracionesEsquema(ref StringBuilder nSourceCode, XsdDataBase.TBL_ObjectRow[] objetos, string SchemaNameFormated, string nTipo) { DataBaseClassWriter.Write(nSourceCode, 2, "//" + nTipo); foreach (var objeto in objetos) { var ObjetNameFormated = FormatCode.ToIdentifier(objeto.Object_Name); DataBaseClassWriter.Write(nSourceCode, 2, "private Schema" + SchemaNameFormated + "." + ObjetNameFormated + nTipo + " _" + ObjetNameFormated + ";"); } DataBaseClassWriter.Write(nSourceCode, 0, ""); }
private static void WriteInitializeEsquema(ref StringBuilder nSourceCode, XsdDataBase.TBL_ObjectRow[] objetos, string SchemaNameFormated, string nTipo) { DataBaseClassWriter.Write(nSourceCode, 3, "//" + nTipo); foreach (var objeto in objetos) { var ObjetNameFormated = FormatCode.ToIdentifier(objeto.Object_Name); DataBaseClassWriter.Write(nSourceCode, 3, " this._" + ObjetNameFormated + " = new Schema" + SchemaNameFormated + "." + ObjetNameFormated + nTipo + "(this);"); } DataBaseClassWriter.Write(nSourceCode, 0, ""); }
private static void WriteObjectEnum(ref StringBuilder nSourceCode, string SchemaName, string nCatalogClassName, XsdDataBase.TBL_ObjectRow[] nObjetos, string nTipo) { DataBaseClassWriter.Write(nSourceCode, 1, "///<summary>"); DataBaseClassWriter.Write(nSourceCode, 1, "///Enumeración de " + nTipo + " del esquema " + SchemaName); DataBaseClassWriter.Write(nSourceCode, 1, "///</summary>"); DataBaseClassWriter.Write(nSourceCode, 1, "public class " + nCatalogClassName + nTipo + "Enum : ObjectEnum"); DataBaseClassWriter.Write(nSourceCode, 1, "{"); foreach (var objeto in nObjetos) { DataBaseClassWriter.Write(nSourceCode, 2, "public static readonly " + nCatalogClassName + nTipo + "Enum " + FormatCode.ToIdentifier(objeto.Object_Name) + " = new " + nCatalogClassName + nTipo + "Enum(\"" + objeto.Object_Name + "\");"); } DataBaseClassWriter.Write(nSourceCode, 2, nCatalogClassName + nTipo + "Enum(string n" + nTipo + "Name) : base(n" + nTipo + "Name) { }"); DataBaseClassWriter.Write(nSourceCode, 1, "}"); DataBaseClassWriter.Write(nSourceCode, 0, ""); DataBaseClassWriter.Write(nSourceCode, 1, "///<summary>"); DataBaseClassWriter.Write(nSourceCode, 1, "///Colección de " + nTipo + " enumerados del esquema " + SchemaName); DataBaseClassWriter.Write(nSourceCode, 1, "///</summary>"); DataBaseClassWriter.Write(nSourceCode, 1, "public class " + nCatalogClassName + nTipo + "EnumList : ObjectEnumList"); DataBaseClassWriter.Write(nSourceCode, 1, "{"); DataBaseClassWriter.Write(nSourceCode, 2, "public " + nCatalogClassName + nTipo + "EnumList() {}"); DataBaseClassWriter.Write(nSourceCode, 2, "public " + nCatalogClassName + nTipo + "EnumList(" + nCatalogClassName + nTipo + "Enum n" + nTipo + ") { base.Add(n" + nTipo + "); }"); DataBaseClassWriter.Write(nSourceCode, 1, "}"); DataBaseClassWriter.Write(nSourceCode, 0, ""); }
public override void FillDataBaseStoredProcedures(XsdDataBase.TBL_ObjectDataTable nObjectTable, XsdDataBase.TBL_ConnectionRow nConnection, List<string> nSchemaFilter) { try { string sql = @"SELECT r.routine_catalog , r.routine_schema , r.routine_name , r.routine_type , 'StoredProcedure' AS generic_type" + ControlChars.CrLf + "FROM information_schema.routines r" + ControlChars.CrLf + "WHERE r.routine_type = 'FUNCTION' AND" + ControlChars.CrLf + "r.specific_schema NOT IN('information_schema', 'pg_catalog')" + ControlChars.CrLf + "ORDER BY r.routine_schema , r.routine_name"; DataTable table = ExecuteQueryGet(sql); for (int i = 0; i < table.Rows.Count; i++) { DataRow row = table.Rows[i]; var newObjectRow = nObjectTable.NewTBL_ObjectRow(); newObjectRow.fk_Connection = nConnection.id_Connection; newObjectRow.Catalog_Name = row["routine_catalog"].ToString(); newObjectRow.Schema_Name = row["routine_schema"].ToString(); newObjectRow.Object_Type = row["routine_type"].ToString(); newObjectRow.Generic_Type = "StoredProcedure"; newObjectRow.Object_Name = row["routine_name"].ToString(); newObjectRow.Selected = false; nObjectTable.AddTBL_ObjectRow(newObjectRow); } } catch (Exception ex) { throw new Exception("No fue posible obtener el listado de tablas " + base.Connection.DataSource + " , " + ex.Message, ex); } }
private static void WritePropiedadesEsquema(ref StringBuilder nSourceCode, XsdDataBase.TBL_ObjectRow[] objetos, string SchemaNameFormated, string nTipo) { DataBaseClassWriter.Write(nSourceCode, 2, "//" + nTipo); foreach (var objeto in objetos) { var ObjetNameFormated = FormatCode.ToIdentifier(objeto.Object_Name); DataBaseClassWriter.Write(nSourceCode, 2, "public Schema" + SchemaNameFormated + "." + ObjetNameFormated + nTipo + " " + ObjetNameFormated); DataBaseClassWriter.Write(nSourceCode, 2, "{"); DataBaseClassWriter.Write(nSourceCode, 3, "get { return this._" + ObjetNameFormated + "; }"); DataBaseClassWriter.Write(nSourceCode, 2, "}"); } DataBaseClassWriter.Write(nSourceCode, 0, ""); }
public override void FillDataTableColumns(XsdDataBase.TBL_FieldDataTable nFieldTable, XsdDataBase.TBL_RelationDataTable nRelationTable, XsdDataBase.TBL_ObjectRow nTable) { try { if (nTable.Generic_Type == "View") { string sql = @"select column_name , nullable is_nullable , data_type , data_length character_maximum_length , data_precision numeric_precision , data_scale numeric_scale , data_type udt_name , column_id ordinal_position " + ControlChars.CrLf + "from all_tab_columns av where owner = '" + nTable.Schema_Name + "' and table_name = '" + nTable.Object_Name + "'"; DataTable table = ExecuteQueryGet(sql); for (int i = 0; i < table.Rows.Count; i++) { DataRow row = table.Rows[i]; nFieldTable.AddTBL_FieldRow(nTable, row["column_name"].ToString(), GetGenericParameterType(row["udt_name"].ToString()).ToString(), row["data_type"].ToString(), (row["is_nullable"].ToString().ToUpper() != "NO"), ConvertToInt(row["character_maximum_length"]), ConvertToByte(row["numeric_precision"]), ConvertToByte(row["numeric_scale"]), row["ordinal_position"].ToString(), GetGenericParameterDirection("In")); } } else // Table { string sql = @"Select * From (" + ControlChars.CrLf + "SELECT col.column_name , col.is_nullable , col.data_type , col.character_maximum_length, col.numeric_precision , col.numeric_scale , col.ordinal_position , col.table_catalog , col.table_schema , col.table_name , k.ordinal_position pk_position , col.udt_name" + ControlChars.CrLf + "FROM information_schema.key_column_usage k INNER JOIN information_schema.table_constraints tc ON tc.constraint_type = 'PRIMARY KEY' AND tc.constraint_name = k.constraint_name" + ControlChars.CrLf + "RIGHT JOIN information_schema.columns col ON col.column_name = k.column_name AND tc.table_name = col.table_name" + ControlChars.CrLf + "WHERE col.table_catalog = '" + nTable.Catalog_Name + "' AND col.table_schema = '" + nTable.Schema_Name + "' AND col.table_name = '" + nTable.Object_Name + "'" + ControlChars.CrLf + ") Tab Left Join (" + ControlChars.CrLf + "SELECT FRG_TBL.CONSTRAINT_NAME AS FRG_CONSTRAINT_NAME , FRG_TBL.TABLE_CATALOG AS FRG_TABLE_CATALOG , FRG_TBL.TABLE_SCHEMA AS FRG_TABLE_SCHEMA" + ControlChars.CrLf + ", FRG_TBL.TABLE_NAME AS FRG_TABLE_NAME , FRG_TBL.COLUMN_NAME AS FRG_COLUMN_NAME , FRG_TBL.ORDINAL_POSITION AS FRG_ORDINAL_POSITION" + ControlChars.CrLf + ", PRI_TBL.CONSTRAINT_NAME AS PRI_CONSTRAINT_NAME , PRI_TBL.CONSTRAINT_CATALOG AS PRI_CONSTRAINT_CATALOG , PRI_TBL.CONSTRAINT_SCHEMA AS PRI_CONSTRAINT_SCHEMA" + ControlChars.CrLf + ", PRI_TBL.TABLE_NAME AS PRI_TABLE_NAME , PRI_TBL.COLUMN_NAME AS PRI_COLUMN_NAME , PRI_TBL.ORDINAL_POSITION AS PRI_ORDINAL_POSITION" + ControlChars.CrLf + "FROM INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS RC" + ControlChars.CrLf + "JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE FRG_TBL " + ControlChars.CrLf + "ON FRG_TBL.CONSTRAINT_CATALOG = RC.CONSTRAINT_CATALOG AND FRG_TBL.CONSTRAINT_SCHEMA = RC.CONSTRAINT_SCHEMA AND FRG_TBL.CONSTRAINT_NAME = RC.CONSTRAINT_NAME" + ControlChars.CrLf + "JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE PRI_TBL" + ControlChars.CrLf + "ON PRI_TBL.CONSTRAINT_CATALOG = RC.UNIQUE_CONSTRAINT_CATALOG " + ControlChars.CrLf + "AND PRI_TBL.CONSTRAINT_SCHEMA = RC.UNIQUE_CONSTRAINT_SCHEMA" + ControlChars.CrLf + "AND PRI_TBL.CONSTRAINT_NAME = RC.UNIQUE_CONSTRAINT_NAME" + ControlChars.CrLf + "AND PRI_TBL.ORDINAL_POSITION = FRG_TBL.ORDINAL_POSITION" + ControlChars.CrLf + "WHERE FRG_TBL.CONSTRAINT_CATALOG = '" + nTable.Catalog_Name + "' AND FRG_TBL.CONSTRAINT_SCHEMA = '" + nTable.Schema_Name + "' AND" + ControlChars.CrLf + "FRG_TBL.TABLE_NAME = '" + nTable.Object_Name + "' " + ControlChars.CrLf + ") Rel" + ControlChars.CrLf + "On Rel.FRG_COLUMN_NAME = Tab.column_name" + ControlChars.CrLf + "Order by table_catalog , table_schema , table_name , ordinal_position"; DataTable table = ExecuteQueryGet(sql); string col = ""; XsdDataBase.TBL_FieldRow field = null; for (int i = 0; i < table.Rows.Count; i++) { DataRow row = table.Rows[i]; if (col != row["column_name"].ToString()) { field = nFieldTable.AddTBL_FieldRow(nTable, row["column_name"].ToString(), GetGenericParameterType(row["udt_name"].ToString()).ToString(), row["data_type"].ToString(), (row["is_nullable"].ToString().ToUpper() != "NO"), ConvertToInt(row["character_maximum_length"]), ConvertToByte(row["numeric_precision"]), ConvertToByte(row["numeric_scale"]), row["pk_position"].ToString(), GetGenericParameterDirection("In")); col = row["column_name"].ToString(); } if (!row.IsNull("FRG_CONSTRAINT_NAME")) { nRelationTable.AddTBL_RelationRow(field, row["FRG_CONSTRAINT_NAME"].ToString(), row["PRI_TABLE_NAME"].ToString(), row["PRI_COLUMN_NAME"].ToString()); } } } } catch (Exception ex) { throw new Exception("No fue posible obtener el listado de columnas " + base.Connection.DataSource + " Tabla = " + nTable.Object_Name + ", " + ex.Message, ex); } }
private static void WriteSchemaEnum(ref StringBuilder nSourceCode, XsdDataBase nDataBaseMap, int nidConnection, string nCatalogClassName, string nCatalog, DataTable schemas) { DataBaseClassWriter.Write(nSourceCode, 1, "///<summary>"); DataBaseClassWriter.Write(nSourceCode, 1, "///Enumeración de los esquemas de la base de datos " + nCatalog); DataBaseClassWriter.Write(nSourceCode, 1, "///</summary>"); DataBaseClassWriter.Write(nSourceCode, 1, "public class " + nCatalogClassName + "SchemaEnum : SchemaEnum"); DataBaseClassWriter.Write(nSourceCode, 1, "{"); foreach (DataRow schema in schemas.Rows) { var SchemaConfig = nDataBaseMap.TBL_Schema.FindByfk_ConnectionSchema_Name(nidConnection, schema["Schema_Name"].ToString ()); DataBaseClassWriter.Write(nSourceCode, 2, "public static readonly " + nCatalogClassName + "SchemaEnum " + SchemaConfig.Schema_Alias + " = new " + nCatalogClassName + "SchemaEnum(\"" + SchemaConfig.Schema_Name + "\");"); } DataBaseClassWriter.Write(nSourceCode, 2, nCatalogClassName + "SchemaEnum(string nSchemaName) : base(nSchemaName) { }"); DataBaseClassWriter.Write(nSourceCode, 1, "}"); DataBaseClassWriter.Write(nSourceCode, 0, ""); DataBaseClassWriter.Write(nSourceCode, 1, "///<summary>"); DataBaseClassWriter.Write(nSourceCode, 1, "///Colección de esquemas enumerados de la base de datos" + nCatalog); DataBaseClassWriter.Write(nSourceCode, 1, "///</summary>"); DataBaseClassWriter.Write(nSourceCode, 1, "public class " + nCatalogClassName + "SchemaEnumList : SchemaEnumList"); DataBaseClassWriter.Write(nSourceCode, 1, "{"); DataBaseClassWriter.Write(nSourceCode, 2, "public " + nCatalogClassName + "SchemaEnumList() {}"); DataBaseClassWriter.Write(nSourceCode, 0, ""); DataBaseClassWriter.Write(nSourceCode, 2, "public " + nCatalogClassName + "SchemaEnumList(" + nCatalogClassName + "SchemaEnum nSchema) { base.Add(nSchema); }"); DataBaseClassWriter.Write(nSourceCode, 1, "}"); // Fin de la clase }
private void RefreshObject(XsdDataBase.TBL_ObjectRow originalObject) { try { var map = new DataBaseMapper(DataBaseDataSet, SelectedConnection); var log = new StringBuilder(); if (originalObject.Generic_Type == "StoredProcedure") map.RefreshStoredProcedure(ref originalObject); else map.RefreshObjectTable(ref originalObject); // No aplica para modo por demanda originalObject.Mapped = true; if (log.ToString() != "") { var dlg = new FormLog(); dlg.AppendText(log.ToString()); dlg.ShowDialog(); } } catch (Exception ex) { if (originalObject != null) originalObject.Mapped = false; MessageBox.Show(ex.Message, Program.AssemblyTitle, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private static void WriteSchemaManager(ref StringBuilder nSourceCode, string nCatalog, DataTable schemas, XsdDataBase nDataBaseMap, int nidConnection, bool IsMobile, bool UseFramework2) { // Recorrer los esquemas foreach (DataRow schema in schemas.Rows) { var SchemaConfig = nDataBaseMap.TBL_Schema.FindByfk_ConnectionSchema_Name(nidConnection, schema["Schema_Name"].ToString ()); // objetos del esquema var sqlFilter = "Generic_Type = 'Table' AND Catalog_Name = '" + nCatalog + "' AND Schema_Name = '" + SchemaConfig.Schema_Name + "' AND Selected = 1"; var tablas = (XsdDataBase.TBL_ObjectRow[]) (nDataBaseMap.TBL_Object.Select(sqlFilter)); sqlFilter = "Generic_Type = 'View' AND Catalog_Name = '" + nCatalog + "' AND Schema_Name = '" + SchemaConfig.Schema_Name + "' AND Selected = 1"; var vistas = (XsdDataBase.TBL_ObjectRow[]) (nDataBaseMap.TBL_Object.Select(sqlFilter)); sqlFilter = "Generic_Type = 'StoredProcedure' AND Catalog_Name = '" + nCatalog + "' AND Schema_Name = '" + SchemaConfig.Schema_Name + "' AND Selected = 1"; var procedimientos = (XsdDataBase.TBL_ObjectRow[]) (nDataBaseMap.TBL_Object.Select(sqlFilter)); // Escribir inicio de la clase DataBaseClassWriter.Write(nSourceCode, 1, "/// <summary>"); DataBaseClassWriter.Write(nSourceCode, 1, "/// Clase encargada de encapsular las funcionalidades de acceso al esquema " + SchemaConfig.Schema_Name); DataBaseClassWriter.Write(nSourceCode, 1, "/// </summary>"); DataBaseClassWriter.Write(nSourceCode, 1, "public class " + SchemaConfig.Schema_Alias + "Schema" + " : SchemaManager"); DataBaseClassWriter.Write(nSourceCode, 1, "{"); // Declaracion variables locales del esquema DataBaseClassWriter.Write(nSourceCode, 2, "#region Declaraciones"); DataBaseClassWriter.Write(nSourceCode, 0, ""); WriteDeclaracionesEsquema(ref nSourceCode, tablas, SchemaConfig.Schema_Alias, "Table"); WriteDeclaracionesEsquema(ref nSourceCode, vistas, SchemaConfig.Schema_Alias, "View"); WriteDeclaracionesEsquema(ref nSourceCode, procedimientos, SchemaConfig.Schema_Alias, "StoreProcedure"); DataBaseClassWriter.Write(nSourceCode, 2, "#endregion"); DataBaseClassWriter.Write(nSourceCode, 0, ""); // Declaracion propiedades del esquema DataBaseClassWriter.Write(nSourceCode, 2, "#region Propiedades"); DataBaseClassWriter.Write(nSourceCode, 0, ""); WritePropiedadesEsquema(ref nSourceCode, tablas, SchemaConfig.Schema_Alias, "Table"); WritePropiedadesEsquema(ref nSourceCode, vistas, SchemaConfig.Schema_Alias, "View"); WritePropiedadesEsquema(ref nSourceCode, procedimientos, SchemaConfig.Schema_Alias, "StoreProcedure"); DataBaseClassWriter.Write(nSourceCode, 2, "#endregion"); DataBaseClassWriter.Write(nSourceCode, 0, ""); // Constructores DataBaseClassWriter.Write(nSourceCode, 2, "#region Constructores"); DataBaseClassWriter.Write(nSourceCode, 0, ""); DataBaseClassWriter.Write(nSourceCode, 2, "internal " + SchemaConfig.Schema_Alias + "Schema" + "(DBManager nDbManager)"); DataBaseClassWriter.Write(nSourceCode, 3, ": base(nDbManager)"); DataBaseClassWriter.Write(nSourceCode, 2, "{"); DataBaseClassWriter.Write(nSourceCode, 3, "base.SchemaAlias = \"" + SchemaConfig.Schema_Alias + "\";"); DataBaseClassWriter.Write(nSourceCode, 3, "Initialize();"); DataBaseClassWriter.Write(nSourceCode, 2, "}"); DataBaseClassWriter.Write(nSourceCode, 0, ""); DataBaseClassWriter.Write(nSourceCode, 2, "private void Initialize()"); DataBaseClassWriter.Write(nSourceCode, 2, "{"); WriteInitializeEsquema(ref nSourceCode, tablas, SchemaConfig.Schema_Alias, "Table"); WriteInitializeEsquema(ref nSourceCode, vistas, SchemaConfig.Schema_Alias, "View"); WriteInitializeEsquema(ref nSourceCode, procedimientos, SchemaConfig.Schema_Alias, "StoreProcedure"); DataBaseClassWriter.Write(nSourceCode, 2, "}"); DataBaseClassWriter.Write(nSourceCode, 0, ""); DataBaseClassWriter.Write(nSourceCode, 2, "#endregion"); DataBaseClassWriter.Write(nSourceCode, 1, "}"); // Fin de la clase DataBaseClassWriter.Write(nSourceCode, 0, ""); // Enumeraciones DataBaseClassWriter.Write(nSourceCode, 1, "#region Enumeraciones del esquema " + SchemaConfig.Schema_Name); DataBaseClassWriter.Write(nSourceCode, 0, ""); WriteObjectEnum(ref nSourceCode, SchemaConfig.Schema_Name, SchemaConfig.Schema_Alias, tablas, "Table"); WriteObjectEnum(ref nSourceCode, SchemaConfig.Schema_Name, SchemaConfig.Schema_Alias, vistas, "View"); WriteObjectEnum(ref nSourceCode, SchemaConfig.Schema_Name, SchemaConfig.Schema_Alias, procedimientos, "StoredProcedure"); DataBaseClassWriter.Write(nSourceCode, 1, "#endregion"); DataBaseClassWriter.Write(nSourceCode, 0, ""); // Escribir el Namespace del esquema DataBaseClassWriter.Write(nSourceCode, 1, "namespace Schema" + SchemaConfig.Schema_Alias); DataBaseClassWriter.Write(nSourceCode, 1, "{"); // Escribir objetos DataBaseClassWriter.Write(nSourceCode, 2, "#region Objetos de acceso a datos"); DataBaseClassWriter.Write(nSourceCode, 0, ""); WriteTables(ref nSourceCode, nDataBaseMap, tablas); WriteViews(ref nSourceCode, nDataBaseMap, vistas); WriteStoreProcedures(ref nSourceCode, nDataBaseMap, procedimientos); DataBaseClassWriter.Write(nSourceCode, 2, "#endregion"); DataBaseClassWriter.Write(nSourceCode, 0, ""); // Escribir las tablas tipadas DataBaseClassWriter.Write(nSourceCode, 2, "#region Tablas tipadas"); DataBaseClassWriter.Write(nSourceCode, 0, ""); WriteDataTables(ref nSourceCode, nDataBaseMap, tablas, IsMobile, UseFramework2); WriteDataTables(ref nSourceCode, nDataBaseMap, vistas, IsMobile, UseFramework2); DataBaseClassWriter.Write(nSourceCode, 2, "#endregion"); DataBaseClassWriter.Write(nSourceCode, 1, "}"); DataBaseClassWriter.Write(nSourceCode, 0, ""); } //Fin de esquemas }
private void ShowObjectTest(XsdDataBase.TBL_ObjectRow obj) { var dlg = new FormTestObject(); dlg.SetDataSource(DataBaseDataSet, SelectedConnection, obj); dlg.ShowDialog(); }
public void RefreshStoredProcedure(ref XsdDataBase.TBL_ObjectRow nOriginalStoredProcedure) { // Consultar la nueva configuracion var newMapStoredProcedure = LoadAndRestoreStoredProcedure(nOriginalStoredProcedure, Log); //Restaurar informacion basica nOriginalStoredProcedure.Generic_Type = newMapStoredProcedure.Generic_Type; nOriginalStoredProcedure.Object_Type = newMapStoredProcedure.Object_Type; nOriginalStoredProcedure.Catalog_Name = newMapStoredProcedure.Catalog_Name; nOriginalStoredProcedure.Schema_Name = newMapStoredProcedure.Schema_Name; nOriginalStoredProcedure.Object_Name = newMapStoredProcedure.Object_Name; // Restaurar parametros var fields = nOriginalStoredProcedure.GetTBL_FieldRows(); foreach (var field in fields) { MapDataBase.TBL_Field.RemoveTBL_FieldRow(field); } try { fields = newMapStoredProcedure.GetTBL_FieldRows(); foreach (var parameter in fields) { MapDataBase.TBL_Field.AddTBL_FieldRow(nOriginalStoredProcedure, parameter.Field_Name, parameter.Field_Type, parameter.Specific_Type, parameter.Is_Nullable, parameter.Max_Length, parameter.Precision, parameter.Scale, parameter.PrimaryKey_Order, parameter.Direction); } } catch (Exception ex) { Log.AppendLine(ex.Message); } }