/// <summary>Constructor to build the base item</summary> /// <param name="Type">Type of item to build</param> /// <param name="Name">Name of the item</param> /// <param name="Parent">Parent of the item</param> public BaseItem(ItemType Type, string Name, BaseItem Parent) { _type = Type; _name = Name; _parent = Parent; if (_parent != null) _itemPath = _parent.ItemPath + "|" + _name; else _itemPath = "|" + _name; SetIcon(); }
/// <summary>Gets the columns in a table or view</summary> /// <param name="parent">Table or view that was expanded</param> /// <param name="server">Server item the tables are under</param> /// <param name="DatabaseName">Name of the database to look in</param> /// <returns>List of column items</returns> private List<BaseItem> GetTableViews(ItemType type, BaseItem parent, List<TableView> tableViews) { List<BaseItem> items = new List<BaseItem>(); foreach (TableView table in tableViews) { items.Add(new BaseItem(type, table.Name, parent)); } return items; }
/// <summary>Gets the folders under a table or view</summary> /// <param name="parent">Table or view to get the children of</param> /// <returns>List of folders</returns> private List<BaseItem> GetTableViewChildren(BaseItem parent) { List<BaseItem> items = new List<BaseItem>(); items.Add(new BaseItem(ItemType.Folder, "Columns", parent)); items.Add(new BaseItem(ItemType.Folder, "Keys", parent)); return items; }
/// <summary>Gets the keys in a table or view</summary> /// <param name="parent">Table or view that was expanded</param> /// <param name="server">Server item the tables are under</param> /// <param name="DatabaseName">Name of the database to look in</param> /// <returns>List of column items</returns> private List<BaseItem> GetKeys(BaseItem parent, List<Key> keys) { List<BaseItem> items = new List<BaseItem>(); foreach (Key key in keys) { items.Add(new ColumnKeyItem(key.Name, parent, key.Type)); } return items; }
/// <summary>Gets the tables or views</summary> /// <param name="parent">Folder that was expanded</param> /// <param name="server">Server item the tables are under</param> /// <param name="DatabaseName">Name of the database to look in</param> /// <returns>List of table or view items</returns> private List<BaseItem> GetFolderChildren(BaseItem parent, ServerItem server, string DatabaseName) { List<BaseItem> items = new List<BaseItem>(); string oldDatabase = server.DataAccess.SelectedDatabase; server.DataAccess.SetDatabase(DatabaseName); switch (parent.Name) { case "Tables": items = GetTableViews(ItemType.Table, parent, server.DataAccess.GetTables()); break; case "Views": items = GetTableViews(ItemType.View, parent, server.DataAccess.GetViews()); break; case "Columns": items = GetColumns(parent, server.DataAccess.GetColumns(parent.Parent.Name)); break; case "Keys": items = GetKeys(parent, server.DataAccess.GetKeys(parent.Parent.Name)); break; } server.DataAccess.SetDatabase(oldDatabase); return items; }
/// <summary>Gets the databases for a server</summary> /// <param name="server">Server to get the databases of</param> /// <returns>List of database items</returns> private List<BaseItem> GetDatabases(ServerItem server) { List<BaseItem> items = new List<BaseItem>(); List<Database> databases = server.DataAccess.GetDatabases(); foreach (Database db in databases) { BaseItem dataItem = new BaseItem(ItemType.Database, db.Name, server); items.Add(dataItem); } return items; }
/// <summary>Gets the folders under a database</summary> /// <param name="parent">Database to get the children of</param> /// <returns>List of folders</returns> private List<BaseItem> GetDatabaseChildren(BaseItem parent) { List<BaseItem> items = new List<BaseItem>(); items.Add(new BaseItem(ItemType.Folder, "Tables", parent)); items.Add(new BaseItem(ItemType.Folder, "Views", parent)); return items; }
/// <summary>Gets the columns in a table or view</summary> /// <param name="parent">Table or view that was expanded</param> /// <param name="server">Server item the tables are under</param> /// <param name="DatabaseName">Name of the database to look in</param> /// <returns>List of column items</returns> private List<BaseItem> GetColumns(BaseItem parent, List<Column> columns) { List<BaseItem> items = new List<BaseItem>(); foreach (Column col in columns) { items.Add(new ColumnKeyItem(col.Name + " (" + col.DataType + ", " + (col.IsNullable ? "null" : "not null") + ")", parent, col.Key)); } return items; }
/// <summary>Constructor</summary> /// <param name="Name">Name of the column</param> /// <param name="Parent">Parent item of the column</param> public ColumnKeyItem(string Name, BaseItem Parent, KeyType Key) : base(ItemType.Column, Name, Parent) { _key = Key; SetIcon(); }