Esempio n. 1
0
        private void tvDataBaseInfo_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
        {
            DataTable table = null;

            try
            {
                if (e.Node.Level == 2)
                {
                    _dbServer.Database = e.Node.Parent.Text;
                    table = _entiyBiz.GetMemorySTable(e.Node.Parent.Text, e.Node.Text, _dbServer);
                }
                else if ((e.Node.Level == 1) && (e.Node.Nodes.Count > 0))
                {
                    _dbServer.Database = e.Node.Text;
                    DataTable schema = null;
                    if (_dbServer.DatabaseType == DataBaseType.Oracle)
                    {
                        schema = _entiyBiz.GetSchema("Tables", new string[] { _dbServer.Database });
                    }
                    else
                    {
                        schema = _entiyBiz.GetSchema("Tables", null);
                    }
                    dataTables = new DataSet();
                    for (int i = 0; i < schema.Rows.Count; i++)
                    {
                        string tblName = "";
                        if (_dbServer.DatabaseType == DataBaseType.Oracle)
                        {
                            tblName = schema.Rows[i][1].ToString();
                        }
                        else
                        {
                            tblName = schema.Rows[i][2].ToString();
                        }
                        dataTables.Tables.Add(_entiyBiz.GetMemorySTable(_dbServer.Database, tblName, _dbServer));
                    }
                }
                if (table != null)
                {
                    dgvTableInfo.DataSource = table;
                }
            }
            catch (Exception exception)
            {
                MsgHelper.ShowErr(exception.Message);
            }
        }
Esempio n. 2
0
        private void LoadTreeView(DbServerInfo server, AutoEntityBiz entiyBiz)
        {
            string collectionName = DbSchemaString.Databases;

            string[] restrictionValues = null;
            switch (server.DatabaseType)
            {
            case DataBaseType.SqlServer:
                collectionName = DbSchemaString.Databases;
                break;

            case DataBaseType.Oracle:
                collectionName = DbSchemaString.Users;
                break;

            case DataBaseType.MySql:
                collectionName = DbSchemaString.Databases;
                break;

            case DataBaseType.SQLite:
                collectionName = DbSchemaString.Tables;    //对SQLite,只有唯一的Main数据库,没有数据库清单表
                break;

            case DataBaseType.PostgreSql:
                collectionName = DbSchemaString.Databases;
                break;

            default:
                break;
            }

            try
            {
                DataTable schema = entiyBiz.GetSchema(collectionName, null);
                tvDataBaseInfo.Nodes.Clear();
                TreeNode node = new TreeNode();
                node.ToolTipText = "请您点选后,在按鼠标右键";
                node.Text        = server.ServerName;
                for (int i = 0; i < schema.Rows.Count; i++)
                {
                    TreeNode node2 = new TreeNode();
                    string   str2  = schema.Rows[i][0].ToString();
                    if (server.DatabaseType == DataBaseType.MySql)
                    {
                        str2 = schema.Rows[i][1].ToString();
                    }
                    server.Database = str2;
                    if (server.DatabaseType == DataBaseType.Oracle)
                    {
                        restrictionValues = new string[] { str2 };
                    }
                    else if (server.DatabaseType == DataBaseType.MySql)
                    {
                        string[] strArray2 = new string[2];
                        strArray2[1]      = str2;
                        restrictionValues = strArray2;
                    }
                    DataTable table2 = entiyBiz.GetSchema("Tables", restrictionValues);
                    DataView  dv     = table2.DefaultView;
                    table2.DefaultView.Sort = "TABLE_NAME ASC";
                    for (int j = 0; j < dv.Count; j++)
                    {
                        string str3 = "";
                        if (server.DatabaseType == DataBaseType.Oracle)
                        {
                            str3 = dv[j][1].ToString();
                        }
                        else
                        {
                            str3 = dv[j][2].ToString();
                        }
                        TreeNode node3 = new TreeNode();
                        node3.ToolTipText = "请您点选后,在按鼠标右键";
                        node3.Text        = str3;
                        node2.Nodes.Add(node3);
                    }
                    node2.ToolTipText = "请您点选后,在按鼠标右键";
                    node2.Text        = str2;
                    node.Nodes.Add(node2);
                    //对于SQLite,终止循环
                    if (server.DatabaseType == DataBaseType.SQLite)
                    {
                        break;
                    }
                }
                tvDataBaseInfo.Nodes.Add(node);

                //展开默认的数据库表树
                string strDefuatExpandDBName = server.Database;
                foreach (TreeNode tnode in tvDataBaseInfo.Nodes)
                {
                    ExpandDefaultDB(tnode, strDefuatExpandDBName);
                }
            }
            catch (Exception exception)
            {
                MsgHelper.ShowErr(exception.Message);
            }
        }