示例#1
0
        public void GenerateSchemaXML(XsdDataBase.TBL_ConnectionRow nConnection, XsdDataBase nDataBaseMap, string nPath)
        {
            var catalogos = CMData.DataBase.DataBase.GetDistinctRows(_DataBaseDataSet.TBL_Object.Select("fk_Connection = " + nConnection.id_Connection), "Catalog_Name");

            foreach (DataRow catalogo in catalogos.Rows)
            {
                try
                {
                    var CatalogConfig = _DataBaseDataSet.TBL_Catalog.FindByfk_ConnectionCatalog_Name(nConnection.id_Connection, catalogo["Catalog_Name"].ToString());

                    var fileName = nPath.TrimEnd('\\') + "\\" + CatalogConfig.Class_Name + "DBManager.map";

                    var schemas = CMData.DataBase.DataBase.GetDistinctRows(nDataBaseMap.TBL_Object.Select("fk_Connection = " + nConnection.id_Connection + " AND Catalog_Name = '" + catalogo["Catalog_Name"] + "' AND Selected = 1"), "Schema_Name");
                    var Maping  = new SchemaMapingManager();

                    foreach (DataRow schema in schemas.Rows)
                    {
                        var SchemaConfig = nDataBaseMap.TBL_Schema.FindByfk_ConnectionSchema_Name(nConnection.id_Connection, schema["Schema_Name"].ToString());

                        Maping.Schemas.Add(SchemaConfig.Schema_Alias, SchemaConfig.Schema_Name);
                    }

                    SchemaMapingManager.Serialize(Maping, fileName);
                }
                catch (Exception ex)
                {
                    _Log.AppendLine(ex.Message);
                }
            }
        }
示例#2
0
        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 ");
                }
            }
        }
示例#3
0
        //public DataBaseMapper(XsdDataBase.TBL_ConnectionRow nConnection)
        //{
        //    _MapDataBase = new XsdDataBase();
        //    _Connection = nConnection;
        //}

        public DataBaseMapper(XsdDataBase nMapDataBase, XsdDataBase.TBL_ConnectionRow nConnection)
        {
            Log         = new StringBuilder();
            MapDataBase = nMapDataBase;
            Connection  = nConnection;
        }
示例#4
0
        public void GenerateClassCode(XsdDataBase.TBL_ConnectionRow nConnection, string nPath, string nNamespaceMap, LanguajeType Languaje, bool IsMobile, bool UseFramework2)
        {
            //Crear el Database Manager
            var catalogos = CMData.DataBase.DataBase.GetDistinctRows(_DataBaseDataSet.TBL_Object.Select("fk_Connection = " + nConnection.id_Connection), "Catalog_Name");

            foreach (DataRow catalogo in catalogos.Rows)
            {
                try
                {
                    var CatalogConfig = _DataBaseDataSet.TBL_Catalog.FindByfk_ConnectionCatalog_Name(nConnection.id_Connection, catalogo["Catalog_Name"].ToString());

                    var fileName         = nPath.TrimEnd('\\') + "\\" + CatalogConfig.Class_File_Name + "DBManager";
                    var fileNameDesigner = nPath.TrimEnd('\\') + "\\" + CatalogConfig.Class_File_Name + "DBManager.Designer";

                    switch (Languaje)
                    {
                    case LanguajeType.VB:
                        fileName         += ".vb";
                        fileNameDesigner += ".vb";
                        break;

                    case LanguajeType.CSharp:
                        fileName         += ".cs";
                        fileNameDesigner += ".cs";
                        break;
                    }

                    var importsCode        = getImports(Languaje);
                    var SourceCode         = new StringBuilder();
                    var SourceCodeDesigner = new StringBuilder();

                    switch (Languaje)
                    {
                    case LanguajeType.VB:
                        SourceCode         = VisualBasicWriter.WriteDataBaseManager(nConnection, CatalogConfig.Class_Name, nNamespaceMap);
                        SourceCodeDesigner = VisualBasicWriter.WriteDataBaseManagerDesigner(nConnection, CatalogConfig.Class_Name, CatalogConfig.Catalog_Name, nNamespaceMap, _DataBaseDataSet, IsMobile, UseFramework2);
                        break;

                    case LanguajeType.CSharp:
                        SourceCode         = CSharpWriter.WriteDataBaseManager(nConnection, CatalogConfig.Class_Name, nNamespaceMap);
                        SourceCodeDesigner = CSharpWriter.WriteDataBaseManagerDesigner(nConnection, CatalogConfig.Class_Name, CatalogConfig.Catalog_Name, nNamespaceMap, _DataBaseDataSet, IsMobile, UseFramework2);
                        break;
                    }

                    StreamWriter sw = null;

                    // Diseñador
                    sw = new System.IO.StreamWriter(fileNameDesigner);

                    foreach (var imp in importsCode)
                    {
                        sw.WriteLine(imp);
                    }

                    sw.WriteLine();

                    sw.Write(SourceCodeDesigner.ToString());
                    sw.Flush();
                    sw.Close();

                    // Codigo usuario
                    if (!File.Exists(fileName))
                    {
                        sw = new System.IO.StreamWriter(fileName);

                        foreach (var imp in importsCode)
                        {
                            sw.Write(imp + ControlChars.CrLf);
                        }

                        sw.Write(SourceCode.ToString());
                        sw.Flush();
                        sw.Close();
                    }
                }
                catch (Exception ex)
                {
                    _Log.AppendLine(ex.Message);
                }
            }
        }
示例#5
0
        public override void FillDataBaseTables(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 = 'BASE TABLE' AND c.table_schema NOT IN('information_schema', 'pg_catalog')");
                sql.AppendLine(@"AND  EXISTS (SELECT cu.table_name FROM information_schema.key_column_usage cu WHERE cu.table_schema = c.table_schema AND cu.table_name = c.table_name)");

                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  = "Table";
                    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);
            }
        }
示例#6
0
        public override void FillDataBaseStoredProcedures(XsdDataBase.TBL_ObjectDataTable nObjectTable, XsdDataBase.TBL_ConnectionRow nConnection, List <string> nSchemaFilter)
        {
            try
            {
                var sql = new StringBuilder();
                sql.AppendLine(@"SELECT r.routine_catalog , r.routine_schema , r.routine_name , r.routine_type , 'StoredProcedure' AS generic_type");
                sql.AppendLine(@"FROM information_schema.routines r");
                sql.AppendLine(@"WHERE r.routine_type = 'PROCEDURE' AND");
                sql.AppendLine(@"r.specific_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 r.routine_schema IN(" + CadenaFiltro + ")");
                }

                sql.AppendLine(@"ORDER BY r.routine_schema , r.routine_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["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);
            }
        }
示例#7
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);
            }
        }