public void RefreshObjectTable(ref XsdDataBase.TBL_ObjectRow nOriginalTable) { // Consultar la nueva configuracion var newMapTable = LoadAndRestoreObjectTable(nOriginalTable, Log); // Restaurar informacion basica nOriginalTable.Generic_Type = newMapTable.Generic_Type; nOriginalTable.Object_Type = newMapTable.Object_Type; nOriginalTable.Catalog_Name = newMapTable.Catalog_Name; nOriginalTable.Schema_Name = newMapTable.Schema_Name; nOriginalTable.Object_Name = newMapTable.Object_Name; nOriginalTable.Selected = newMapTable.Selected; nOriginalTable.Mapped = newMapTable.Mapped; // Restaurar columnas var fields = nOriginalTable.GetTBL_FieldRows(); foreach (var field in fields) { field.Delete(); } try { fields = newMapTable.GetTBL_FieldRows(); foreach (var newMapField in fields) { var field = MapDataBase.TBL_Field.AddTBL_FieldRow(nOriginalTable, newMapField.Field_Name, newMapField.Field_Type, newMapField.Specific_Type, newMapField.Is_Nullable, newMapField.Max_Length, newMapField.Precision, newMapField.Scale, newMapField.PrimaryKey_Order, newMapField.Direction); try { var relations = newMapField.GetTBL_RelationRows(); foreach (var newMapRelation in relations) { MapDataBase.TBL_Relation.AddTBL_RelationRow(field, newMapRelation.Relation_Name, newMapRelation.Table_Name, newMapRelation.Column_Name); } } catch (Exception ex) { Log.AppendLine(ex.Message); } } } catch (Exception ex) { Log.AppendLine(ex.Message); } // Restaurar filtros var filters = nOriginalTable.GetTBL_FilterRows(); foreach (var nFilter in filters) { nFilter.Delete(); } try { filters = newMapTable.GetTBL_FilterRows(); foreach (var newMapFilter in filters) { var nFilter = MapDataBase.TBL_Filter.AddTBL_FilterRow(nOriginalTable, newMapFilter.Name); try { var filterFields = newMapFilter.GetTBL_Filter_FieldRows(); foreach (var newFilterField in filterFields) { MapDataBase.TBL_Filter_Field.AddTBL_Filter_FieldRow(nFilter, newFilterField.Filter_Order, newFilterField.Field_Name); } } catch (Exception ex) { Log.AppendLine(ex.Message); } } } catch (Exception ex) { Log.AppendLine(ex.Message); } }
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); } }