forked from pripost/NppDB.MSAccess
-
Notifications
You must be signed in to change notification settings - Fork 1
/
MSAccessTableGroup.cs
70 lines (64 loc) · 2.22 KB
/
MSAccessTableGroup.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
using System;
using System.Data;
using System.Data.OleDb;
using System.Windows.Forms;
using NppDB.Comm;
namespace NppDB.MSAccess
{
public class MSAccessTableGroup : TreeNode, IRefreshable, IMenuProvider
{
public MSAccessTableGroup()
{
SchemaName = OleDbMetaDataCollectionNames.Tables;
Text = "Tables";
SelectedImageKey = ImageKey = "Group";
}
protected string SchemaName { get; set; }
protected virtual TreeNode CreateTreeNode(DataRow dataRow)
{
return new MSAccessTable
{
Text = dataRow["table_name"].ToString()
};
}
public void Refresh()
{
var conn = (MSAccessConnect)Parent.Parent;
using (var cnn = conn.GetConnection())
{
TreeView.Cursor = Cursors.WaitCursor;
TreeView.Enabled = false;
try
{
cnn.Open();
var dt = cnn.GetSchema(SchemaName);
Nodes.Clear();
foreach (DataRow row in dt.Rows)
{
var tableName = row["table_name"] as string;
if (SchemaName == OleDbMetaDataCollectionNames.Tables && row["table_type"] as string == "VIEW") continue;
if (tableName != null && (tableName.ToUpper().StartsWith("MSYS") ||
tableName.ToUpper().StartsWith("USYS")))
continue;
Nodes.Add(CreateTreeNode(row));
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Exception");
}
finally
{
TreeView.Enabled = true;
TreeView.Cursor = null;
}
}
}
public virtual ContextMenuStrip GetMenu()
{
var menuList = new ContextMenuStrip { ShowImageMargin = false };
menuList.Items.Add(new ToolStripButton("Refresh", null, (s, e) => { Refresh(); }));
return menuList;
}
}
}