本文整理汇总了C#中IHost.RefreshProjectTree方法的典型用法代码示例。如果您正苦于以下问题:C# IHost.RefreshProjectTree方法的具体用法?C# IHost.RefreshProjectTree怎么用?C# IHost.RefreshProjectTree使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IHost
的用法示例。
在下文中一共展示了IHost.RefreshProjectTree方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SyncFromDataSourceToTableModel
public void SyncFromDataSourceToTableModel(IHost host)
{
using (IDbConnection connection = GetConnection())
{
try
{
connection.Open();
DataTable schema = GetSchema(connection);
DataTable tables = GetSchema(connection, "tables");
DataTable columns = GetSchema(connection, "columns");
var tableElements = new Dictionary<string, TableElement>();
foreach (TableElement child in AllChildren)
{
string key = child.GetDisplayName();
tableElements.Add(key, child);
}
ClearChildren();
Engine.MuteNotify();
foreach (DataRow row in tables.Rows)
{
string tableName = row["table_name"].ToString();
TableElement table = null;
if (!tableElements.ContainsKey(tableName))
{
table = new TableElement();
table.Name = tableName;
tableElements.Add(tableName, table);
}
table = tableElements[tableName];
AddChild(table);
IDbCommand command = connection.CreateCommand();
command.CommandText = string.Format("select * from [{0}]", tableName);
IDataReader reader = command.ExecuteReader();
DataTable tableSchema = reader.GetSchemaTable();
reader.Close();
table.Columns.ClearChildren();
foreach (DataRow columnRow in tableSchema.Rows)
{
var column = new ColumnElement();
column.Name = (string) columnRow["ColumnName"];
column.IsNullable = (bool) columnRow["AllowDBNull"];
column.IsAutoIncrement = (bool) columnRow["IsAutoIncrement"];
column.IsIdentity = (bool) columnRow["IsIdentity"];
column.DefaultValue = "";
column.NativeType = (Type) columnRow["DataType"];
column.IsUnique = (bool) columnRow["IsUnique"];
column.Ordinal = (int) columnRow["ColumnOrdinal"];
column.DbType = (string) columnRow["DataTypeName"];
column.MaxLength = (int) columnRow["ColumnSize"];
table.Columns.AddChild(column);
}
}
//foreach (DataRow row in columns.Rows)
//{
// string tableName = row["table_name"].ToString();
// string columnName = row["column_name"].ToString();
// TableElement table = tableElements[tableName];
// ColumnElement column = new ColumnElement();
// column.Name = columnName;
// column.IsNullable = false;
// column.IsPK = false;
// column.DefaultValue = "";
// table.AddChild(column);
//}
Engine.EnableNotify();
}
catch
{
MessageBox.Show("Connection failed");
}
host.RefreshProjectTree();
}
}
示例2: SyncFromDataSourceToTableModel
public void SyncFromDataSourceToTableModel(IHost host)
{
var myMeta = new dbRoot();
myMeta.Connect(dbDriver.SQL, ConnectionString);
try
{
Engine.MuteNotify();
var tablesTrans = Tables.BeginTransaction();
foreach (ITable metaTable in myMeta.DefaultDatabase.Tables)
{
var table = tablesTrans.GetNamedChild<TableElement>(metaTable.Name);
Tables.AddChild(table);
var columnsTrans = table.Columns.BeginTransaction();
foreach (IColumn metaColumn in metaTable.Columns)
{
var column = columnsTrans.GetNamedChild<ColumnElement>(metaColumn.Name);
column.Name = metaColumn.Name;
column.IsNullable = metaColumn.IsNullable;
column.IsAutoKey = metaColumn.IsAutoKey;
column.IsInPrimaryKey = metaColumn.IsInPrimaryKey;
column.Default = metaColumn.Default;
column.Ordinal = metaColumn.Ordinal;
column.DbType = metaColumn.DataTypeName;
column.MaxLength = metaColumn.NumericPrecision;
column.AutoKeySeed = metaColumn.AutoKeySeed;
column.AutoKeyIncrement = metaColumn.AutoKeyIncrement;
table.Columns.AddChild(column);
}
}
//update foreign keys
//must be done in a 2nd step since all columns are not available in the first loop
foreach (ITable metaTable in myMeta.DefaultDatabase.Tables)
{
var table = tablesTrans.GetNamedChild<TableElement>(metaTable.Name);
var foreignKeysTrans = table.ForeignKeys.BeginTransaction();
foreach (IForeignKey metaForeignKey in metaTable.ForeignKeys)
{
if (metaForeignKey.PrimaryTable.Name == metaTable.Name)
continue;
var foreignKey = foreignKeysTrans.GetNamedChild<ForeignKeyElement>(metaForeignKey.Name);
foreignKey.PrimaryTable = tablesTrans.GetNamedChild<TableElement>(metaForeignKey.PrimaryTable.Name);
table.ForeignKeys.AddChild(foreignKey);
var foreignKeyTrans = foreignKey.BeginTransaction();
for (int i = 0; i < metaForeignKey.ForeignColumns.Count; i++)
{
var columnPair = new ColumnPairElement();
columnPair.PrimaryColumn = foreignKey.PrimaryTable.Columns.GetNamedChild<ColumnElement>(((IColumn)metaForeignKey.PrimaryColumns[i]).Name);
columnPair.ForeignColumn = foreignKey.ForeignTable.Columns.GetNamedChild<ColumnElement>(((IColumn)metaForeignKey.ForeignColumns[i]).Name);
foreignKey.AddChild(columnPair);
}
}
}
var viewTrans = Views.BeginTransaction();
foreach (IView metaView in myMeta.DefaultDatabase.Views)
{
var view = viewTrans.GetNamedChild<ViewElement>(metaView.Name);
view.Name = metaView.Name;
Views.AddChild(view);
}
var procTrans = Procedures.BeginTransaction();
foreach (IProcedure metaProcedure in myMeta.DefaultDatabase.Procedures)
{
if (metaProcedure.Type == 3)
continue;
var procedure = procTrans.GetNamedChild<ProcedureElement>(metaProcedure.Name);
procedure.Name = metaProcedure.Name;
Procedures.AddChild(procedure);
}
Engine.EnableNotify();
Engine.OnNotifyChange();
}
catch
{
MessageBox.Show("Connection failed");
}
host.RefreshProjectTree();
}