void setContext(ITypeDescriptorContext context) { _metaConnection = context.Instance as MetaConnection; _metaEnum = context.Instance as MetaEnum; _metaTable = context.Instance as MetaTable; _metaColumn = context.Instance as MetaColumn; _metaJoin = context.Instance as MetaJoin; _reportView = context.Instance as ReportView; _reportOutput = context.Instance as ReportOutput; _reportSchedule = context.Instance as ReportSchedule; _parameter = context.Instance as Parameter; _security = context.Instance as SealSecurity; _emailDevice = context.Instance as OutputEmailDevice; }
private void changeTableColumnNames(MetaTable table, string oldValue, string newValue) { if (!string.IsNullOrEmpty(newValue) && newValue != oldValue) { //Change the table name in the columns foreach (var col in table.Columns) { col.Name = col.Name.Replace(oldValue + ".", newValue + "."); col.Name = col.Name.Replace(oldValue.ToLower() + ".", newValue + "."); } } }
public void AddColumnsFromCatalog(List<MetaColumn> columns, DbConnection connection, MetaTable table) { if (table.Name == null) throw new Exception("No table name has been defined..."); //handle if table name = dbname.owner.tablename string name = table.Name.Replace("[", "").Replace("]", ""); string[] names = name.Split('.'); DataTable schemaColumns = null; Helper.ExecutePrePostSQL(connection, table.PreSQL, table, table.IgnorePrePostError); if (names.Length == 3) schemaColumns = connection.GetSchema("Columns", names); else if (names.Length == 2) schemaColumns = connection.GetSchema("Columns", new string[] { null, names[0], names[1] }); else schemaColumns = connection.GetSchema("Columns", new string[] { null, null, name }); Helper.ExecutePrePostSQL(connection, table.PostSQL, table, table.IgnorePrePostError); foreach (DataRow row in schemaColumns.Rows) { try { string tableName = (!string.IsNullOrEmpty(table.AliasName) ? table.AliasName : Helper.DBNameToDisplayName(row["TABLE_NAME"].ToString().Trim())); MetaColumn column = MetaColumn.Create(tableName + "." + GetColumnName(row["COLUMN_NAME"].ToString())); column.DisplayName = table.KeepColumnNames ? row["COLUMN_NAME"].ToString().Trim() : Helper.DBNameToDisplayName(row["COLUMN_NAME"].ToString().Trim()); column.DisplayOrder = table.GetLastDisplayOrder(); MetaColumn col = table.Columns.FirstOrDefault(); if (col != null) column.Category = col.Category; else column.Category = !string.IsNullOrEmpty(table.AliasName) ? table.AliasName : Helper.DBNameToDisplayName(table.Name.Trim()); column.Source = this; string odbcType = ""; if (row.Table.Columns.Contains("TYPE_NAME")) odbcType = row["TYPE_NAME"].ToString(); column.Type = connection is OdbcConnection ? Helper.ODBCToNetTypeConverter(odbcType) : Helper.DatabaseToNetTypeConverter(row["DATA_TYPE"]); column.SetStandardFormat(); if (!columns.Exists(i => i.Name == column.Name)) columns.Add(column); } catch { } } }
public MetaColumn AddColumn(MetaTable table) { MetaColumn result = MetaColumn.Create("ColumnName"); result.Source = this; MetaColumn col = table.Columns.FirstOrDefault(); if (col != null) result.Category = col.Category; else result.Category = !string.IsNullOrEmpty(table.AliasName) ? table.AliasName : Helper.DBNameToDisplayName(table.Name.Trim()); result.DisplayOrder = table.GetLastDisplayOrder(); table.Columns.Add(result); return result; }
public void RemoveTable(MetaTable item) { //remove joins related MetaData.Joins.RemoveAll(i => i.LeftTableGUID == item.GUID || i.RightTableGUID == item.GUID); MetaData.Tables.Remove(item); }
public void AddColumnsFromCatalog(List <MetaColumn> columns, DbConnection connection, MetaTable table) { if (table.Name == null) { throw new Exception("No table name has been defined..."); } //handle if table name = dbname.owner.tablename string name = table.Name.Replace("[", "").Replace("]", ""); string[] names = name.Split('.'); DataTable schemaColumns = null; Helper.ExecutePrePostSQL(connection, table.PreSQL, table, table.IgnorePrePostError); if (names.Length == 3) { schemaColumns = connection.GetSchema("Columns", names); } else if (names.Length == 2) { schemaColumns = connection.GetSchema("Columns", new string[] { null, names[0], names[1] }); } else { schemaColumns = connection.GetSchema("Columns", new string[] { null, null, name }); } Helper.ExecutePrePostSQL(connection, table.PostSQL, table, table.IgnorePrePostError); foreach (DataRow row in schemaColumns.Rows) { try { string tableName = (!string.IsNullOrEmpty(table.AliasName) ? table.AliasName : Helper.DBNameToDisplayName(row["TABLE_NAME"].ToString().Trim())); MetaColumn column = MetaColumn.Create(tableName + "." + GetColumnName(row["COLUMN_NAME"].ToString())); column.DisplayName = table.KeepColumnNames ? row["COLUMN_NAME"].ToString().Trim() : Helper.DBNameToDisplayName(row["COLUMN_NAME"].ToString().Trim()); column.DisplayOrder = table.GetLastDisplayOrder(); MetaColumn col = table.Columns.FirstOrDefault(); if (col != null) { column.Category = col.Category; } else { column.Category = !string.IsNullOrEmpty(table.AliasName) ? table.AliasName : Helper.DBNameToDisplayName(table.Name.Trim()); } column.Source = this; string odbcType = ""; if (row.Table.Columns.Contains("TYPE_NAME")) { odbcType = row["TYPE_NAME"].ToString(); } column.Type = connection is OdbcConnection?Helper.ODBCToNetTypeConverter(odbcType) : Helper.DatabaseToNetTypeConverter(row["DATA_TYPE"]); column.SetStandardFormat(); if (!columns.Exists(i => i.Name == column.Name)) { columns.Add(column); } } catch { } } }