Esempio n. 1
0
        public XsdDataBase.TBL_ObjectRow LoadAndRestoreStoredProcedure(XsdDataBase.TBL_ObjectRow nOriginalStoredProcedure, StringBuilder nLog)
        {
            CMData.Manager.DBManager DBM = null;

            try
            {
                if (Connection != null)
                {
                    if (Connection.IsConnection_TypeNull())
                    {
                        DBM = new CMData.Manager.DBManager(Connection.Connection_String);
                    }
                    else
                    {
                        var dbType = (CMData.DataBase.DataBaseType)(Enum.Parse(typeof(CMData.DataBase.DataBaseType), Connection.Connection_Type));
                        DBM = new CMData.Manager.DBManager(dbType, Connection.Connection_String);
                    }

                    DBM.Connection_Open();

                    var newDataBase = new XsdDataBase();
                    var newObject   = newDataBase.TBL_Object.NewTBL_ObjectRow();

                    newObject.Generic_Type = nOriginalStoredProcedure.Generic_Type;
                    newObject.Object_Type  = nOriginalStoredProcedure.Object_Type;
                    newObject.Catalog_Name = nOriginalStoredProcedure.Catalog_Name;
                    newObject.Schema_Name  = nOriginalStoredProcedure.Schema_Name;
                    newObject.Object_Name  = nOriginalStoredProcedure.Object_Name;

                    newDataBase.TBL_Object.AddTBL_ObjectRow(newObject);

                    DBM.DataBase.FillDataBaseParameters(newDataBase.TBL_Field, newObject);

                    try { newObject.Selected = nOriginalStoredProcedure.Selected; }
                    catch { }
                    newObject.Mapped = true;

                    try
                    {
                        var originalSpReturn = nOriginalStoredProcedure.GetTBL_SP_ReturnRows()[0];
                        var newSpReturn      = newDataBase.TBL_SP_Return.NewTBL_SP_ReturnRow();

                        newSpReturn.fk_Object            = newObject.id_Object;
                        newSpReturn.Return_Type          = originalSpReturn.Return_Type;
                        newSpReturn.Data_Type_Returned   = originalSpReturn.Data_Type_Returned;
                        newSpReturn.Schema_Name_Returned = originalSpReturn.Schema_Name_Returned;
                        newSpReturn.Object_Name_Returned = originalSpReturn.Object_Name_Returned;

                        newDataBase.TBL_SP_Return.AddTBL_SP_ReturnRow(newSpReturn);
                    }
                    catch { }

                    DBM.Connection_Close();

                    return(newObject);
                }

                throw new Exception("Se debe seleccionar una conexión");
            }
            catch (Exception ex)
            {
                if (DBM != null)
                {
                    DBM.Connection_Close();
                }
                throw new Exception(ex.Message);
            }
        }
Esempio n. 2
0
        public XsdDataBase.TBL_ObjectRow LoadAndRestoreObjectTable(XsdDataBase.TBL_ObjectRow nOriginalTable, StringBuilder nLog)
        {
            CMData.Manager.DBManager DBM = null;

            try
            {
                if (Connection != null)
                {
                    if (Connection.IsConnection_TypeNull())
                    {
                        DBM = new CMData.Manager.DBManager(Connection.Connection_String);
                    }
                    else
                    {
                        var dbType = (CMData.DataBase.DataBaseType)(Enum.Parse(typeof(CMData.DataBase.DataBaseType), Connection.Connection_Type));
                        DBM = new CMData.Manager.DBManager(dbType, Connection.Connection_String);
                    }

                    DBM.Connection_Open();

                    var newDataBase = new XsdDataBase();
                    var newObject   = newDataBase.TBL_Object.NewTBL_ObjectRow();

                    newObject.Generic_Type = nOriginalTable.Generic_Type;
                    newObject.Object_Type  = nOriginalTable.Object_Type;
                    newObject.Catalog_Name = nOriginalTable.Catalog_Name;
                    newObject.Schema_Name  = nOriginalTable.Schema_Name;
                    newObject.Object_Name  = nOriginalTable.Object_Name;

                    newDataBase.TBL_Object.AddTBL_ObjectRow(newObject);

                    DBM.DataBase.FillDataTableColumns(newDataBase.TBL_Field, newDataBase.TBL_Relation, newObject);
                    DBM.Connection_Close();

                    try { newObject.Selected = nOriginalTable.Selected; }
                    catch { }
                    newObject.Mapped = true;

                    //Restaurar filtros
                    try
                    {
                        var filters = nOriginalTable.GetTBL_FilterRows();

                        foreach (var originalFilter in filters)
                        {
                            var newFilter = newDataBase.TBL_Filter.NewTBL_FilterRow();

                            newFilter.fk_Object = newObject.id_Object;
                            newFilter.Name      = originalFilter.Name;
                            newDataBase.TBL_Filter.AddTBL_FilterRow(newFilter);

                            var  filterFields = originalFilter.GetTBL_Filter_FieldRows();
                            bool isNewFilterFieldsComplete = true;

                            foreach (var originalFilterField in filterFields)
                            {
                                var fieldRows = newDataBase.TBL_Field.Select("Field_Name = '" + originalFilterField.Field_Name + "'");

                                if (fieldRows.Length > 0)
                                {
                                    var newFilterField = newDataBase.TBL_Filter_Field.NewTBL_Filter_FieldRow();

                                    newFilterField.fk_Filter    = newFilter.id_Filter;
                                    newFilterField.Field_Name   = originalFilterField.Field_Name;
                                    newFilterField.Filter_Order = originalFilterField.Filter_Order;

                                    newDataBase.TBL_Filter_Field.AddTBL_Filter_FieldRow(newFilterField);
                                }
                                else
                                {
                                    nLog.AppendLine(ControlChars.Tab + "El campo con nombre [" + originalFilterField.Field_Name + "] no fue encontrado en la base de datos");
                                    isNewFilterFieldsComplete = false;
                                }
                            }

                            if (!isNewFilterFieldsComplete)
                            {
                                nLog.AppendLine(ControlChars.Tab + "El filtro con nombre [" + originalFilter.Name + "] no fue agregado debido a que no coinciden sus campos de filtrado");
                                newFilter.Delete();
                            }
                        }
                    }
                    catch { }

                    return(newObject);
                }

                throw new Exception("Se debe seleccionar una conexión");
            }
            catch (Exception ex)
            {
                if (DBM != null)
                {
                    DBM.Connection_Close();
                }
                throw new Exception(ex.Message, ex);
            }
        }
Esempio n. 3
0
        public void LoadAndRefreshAllObjects(bool recursiveSelectedObjects, bool AddNewsOnly)
        {
            CMData.Manager.DBManager DBM = null;
            bool Cancel = false;

            try
            {
                if (Connection != null)
                {
                    Log = new StringBuilder();

                    if (Connection.IsConnection_TypeNull())
                    {
                        DBM = new CMData.Manager.DBManager(Connection.Connection_String);
                    }
                    else
                    {
                        var dbType = (CMData.DataBase.DataBaseType)(Enum.Parse(typeof(CMData.DataBase.DataBaseType), Connection.Connection_Type));
                        DBM = new CMData.Manager.DBManager(dbType, Connection.Connection_String);
                    }

                    DBM.Connection_Open();

                    // Guardar antigua configuracion actual para ser actualizada en los casos en los que sea posible
                    var newMapDataBase = new XsdDataBase();

                    if (ProgressProcessChanged != null)
                    {
                        ProgressProcessChanged("Descargando", 3, 0);
                    }

                    // Cargar lista de objetos
                    var Filtros = new List <string>();
                    foreach (CMData.Schemas.XsdDataBase.TBL_SchemaRow SchemaRow in MapDataBase.TBL_Schema)
                    {
                        if (SchemaRow.Maping_Schema)
                        {
                            Filtros.Add(SchemaRow.Schema_Name);
                        }
                    }

                    DBM.DataBase.FillDataBaseTables(newMapDataBase.TBL_Object, Connection, Filtros);
                    DBM.DataBase.FillDataBaseViews(newMapDataBase.TBL_Object, Connection, Filtros);
                    DBM.DataBase.FillDataBaseStoredProcedures(newMapDataBase.TBL_Object, Connection, Filtros);

                    //Eliminar objetos no utilizados
                    var deleteObjects = new List <XsdDataBase.TBL_ObjectRow>();

                    foreach (XsdDataBase.TBL_ObjectRow originalObject in MapDataBase.TBL_Object.Rows)
                    {
                        var existsObj = FindObjectRow(newMapDataBase, originalObject.Catalog_Name, originalObject.Schema_Name, originalObject.Object_Name);

                        if (existsObj == null)
                        {
                            if (originalObject.Generic_Type == "Table")
                            {
                                Log.AppendLine("La tabla " + originalObject.Object_Name + " no fue encontrada en la base de datos");
                            }
                            else if (originalObject.Generic_Type == "View")
                            {
                                Log.AppendLine("La vista " + originalObject.Object_Name + " no fue encontrada en la base de datos");
                            }
                            else
                            {
                                Log.AppendLine("El procedimiento almacenado " + originalObject.Object_Name + " no fue encontrado en la base de datos");
                            }

                            deleteObjects.Add(originalObject);
                        }
                    }

                    foreach (var deleteObject in deleteObjects)
                    {
                        deleteObject.Delete();
                    }

                    //Agregar nuevos objetos
                    foreach (XsdDataBase.TBL_ObjectRow newObject in newMapDataBase.TBL_Object.Rows)
                    {
                        var existsObj = FindObjectRow(MapDataBase, newObject.Catalog_Name, newObject.Schema_Name, newObject.Object_Name);

                        if (existsObj == null)
                        {
                            bool mapped = false;

                            try { mapped = newObject.Mapped; }
                            catch { }

                            MapDataBase.TBL_Object.AddTBL_ObjectRow(Connection.id_Connection, newObject.Generic_Type, newObject.Catalog_Name, newObject.Schema_Name, newObject.Object_Type, newObject.Object_Name, newObject.Selected, mapped);

                            if (newObject.Generic_Type == "Table")
                            {
                                Log.AppendLine("La tabla " + newObject.Object_Name + " ha sido agregado recientemente");
                            }
                            else if (newObject.Generic_Type == "View")
                            {
                                Log.AppendLine("La vista " + newObject.Object_Name + " ha sido agregado recientemente");
                            }
                            else
                            {
                                Log.AppendLine("El procedimiento almacenado " + newObject.Object_Name + " ha sido agregado recientemente");
                            }
                        }
                    }

                    // Se sale si solo se requiere cargar los nuevos
                    if (AddNewsOnly)
                    {
                        return;
                    }

                    if (ProgressActionChanged != null)
                    {
                        ProgressActionChanged("Leyendo estructura de tablas", MapDataBase.TBL_Object.Rows.Count, 0);
                    }

                    var newObjectRows = FindObjects(MapDataBase, Connection.id_Connection, "Table");

                    foreach (var newObject in newObjectRows)
                    {
                        //Restaurar la configuracion temporalmente guardada
                        if (newObject.Selected)
                        {
                            if (recursiveSelectedObjects)
                            {
                                var TempObject = newObject;
                                RefreshObjectTable(ref TempObject);
                                newObject.Mapped = true;
                            }
                            else
                            {
                                newObject.Mapped = false;
                            }
                        }

                        if (ProgressIncrementAction != null)
                        {
                            ProgressIncrementAction(ref Cancel);
                        }
                        if (Cancel)
                        {
                            throw new Exception("Cancelada por el usuario");
                        }
                    }

                    if (ProgressIncrementProcess != null)
                    {
                        ProgressIncrementProcess(ref Cancel);
                    }
                    if (Cancel)
                    {
                        throw new Exception("Cancelada por el usuario");
                    }

                    // Actualizar las vistas
                    newObjectRows = FindObjects(MapDataBase, Connection.id_Connection, "View");

                    if (ProgressActionChanged != null)
                    {
                        ProgressActionChanged("Leyendo Vistas", newObjectRows.Length, 0);
                    }

                    foreach (var newObject in newObjectRows)
                    {
                        //Restaurar la configuracion temporalmente guardada
                        if (newObject.Selected)
                        {
                            if (recursiveSelectedObjects)
                            {
                                var TempObject = newObject;
                                RefreshObjectTable(ref TempObject);
                                newObject.Mapped = true;
                            }
                            else
                            {
                                newObject.Mapped = false;
                            }
                        }

                        if (ProgressIncrementAction != null)
                        {
                            ProgressIncrementAction(ref Cancel);
                        }
                        if (Cancel)
                        {
                            throw new Exception("Cancelada por el usuario");
                        }
                    }

                    if (ProgressIncrementProcess != null)
                    {
                        ProgressIncrementProcess(ref Cancel);
                    }
                    if (Cancel)
                    {
                        throw new Exception("Cancelada por el usuario");
                    }

                    // Actualizar los procedimientos almacenados
                    var newSpRows = FindObjects(MapDataBase, Connection.id_Connection, "StoredProcedure");

                    if (ProgressActionChanged != null)
                    {
                        ProgressActionChanged("Leyendo Procedimientos", newSpRows.Length, 0);
                    }

                    foreach (var newObject in newSpRows)
                    {
                        if (newObject.Selected)
                        {
                            if (recursiveSelectedObjects)
                            {
                                var TempObject = newObject;
                                RefreshStoredProcedure(ref TempObject);
                                newObject.Mapped = true;
                            }
                            else
                            {
                                newObject.Mapped = false;
                            }
                        }

                        if (ProgressIncrementAction != null)
                        {
                            ProgressIncrementAction(ref Cancel);
                        }
                        if (Cancel)
                        {
                            throw new Exception("Cancelada por el usuario");
                        }
                    }

                    if (ProgressIncrementProcess != null)
                    {
                        ProgressIncrementProcess(ref Cancel);
                    }
                    if (Cancel)
                    {
                        throw new Exception("Cancelada por el usuario");
                    }

                    DBM.Connection_Close();
                }
                else
                {
                    throw new Exception("Debe seleccionar una conexión");
                }
            }
            catch (Exception ex)
            {
                if (DBM != null)
                {
                    DBM.Connection_Close();
                }

                throw new Exception(ex.Message, ex);
            }
        }