/// <summary>
        /// 创建一个数据库架构实例
        /// </summary>
        /// <param name="db">数据提供程序实例</param>
        /// <returns></returns>
        public static DbSchema Create(Database db)
        {
            DbSchema schema = null;

            switch (db.DatabaseType)
            {
            case DatabaseType.SqlServer:
                schema = new SqlServerSchema(db);
                break;

            case DatabaseType.Oracle:
                schema = new OracleSchema(db);
                break;

            case DatabaseType.MySql:
                schema = new MySqlSchema(db);
                break;

            case DatabaseType.DB2:
                schema = new DB2Schema(db);
                break;

            case DatabaseType.SQLite:
                schema = new SQLiteSchema(db);
                break;

            case DatabaseType.OleDb:
                schema = new OleDbSchema(db);
                break;

            default:
                break;
            }

            return(schema);
        }
Beispiel #2
0
        private void btnGetTables_Click(object sender, EventArgs e)
        {
            //清空树列表
            tvTables.Nodes.Clear();

            //根节点
            TreeNode firstNode = new TreeNode();

            firstNode.Text = "数据库";
            tvTables.Nodes.Add(firstNode);

            string dbType  = cbDbType.Text;
            string connUrl = txtConnectionUrl.Text;

            CircleProgressBarDialog dialog = new CircleProgressBarDialog();

            dialog.Start(new EventHandler <CircleProgressBarEventArgs>(delegate(object senders, CircleProgressBarEventArgs args)
            {
                try
                {
                    DBSchema.DbSchema schemaObj = DBSchema.DbSchemaFactory.Create(dbType, connUrl);

                    if (schemaObj != null)
                    {
                        List <SuperCodeFactory.DBSchema.SchemaObject.SOTable> tableList = schemaObj.GetTableList(schemaObj.GetDatabaseList()[0]);

                        if (tableList != null)
                        {
                            foreach (SuperCodeFactory.DBSchema.SchemaObject.SOTable table in tableList)
                            {
                                //报告进度
                                ((CircleProgressBarDialog)senders).ReportProgress((int)(((float)tableList.IndexOf(table) / (float)tableList.Count) * 100), 100);

                                //添加表格节点
                                TreeNode tableNode = new TreeNode();
                                tableNode.Text     = "表格(" + table.Name + ")";
                                tableNode.Tag      = table;

                                if (IsHandleCreated)
                                {
                                    Invoke(new MethodInvoker(delegate()
                                    {
                                        firstNode.Nodes.Add(tableNode);
                                    }));
                                }

                                if (table.ColumnList != null)
                                {
                                    foreach (SuperCodeFactory.DBSchema.SchemaObject.SOColumn col in table.ColumnList)
                                    {
                                        //添加字段节点
                                        TreeNode columnNode = new TreeNode();
                                        columnNode.Text     = "字段(" + col.Name + "," + col.DataType + ")";
                                        columnNode.Tag      = col;

                                        if (IsHandleCreated)
                                        {
                                            Invoke(new MethodInvoker(delegate()
                                            {
                                                tableNode.Nodes.Add(columnNode);
                                            }));
                                        }
                                    }
                                }
                            }
                        }

                        //展开根节点
                        if (IsHandleCreated)
                        {
                            Invoke(new MethodInvoker(delegate()
                            {
                                firstNode.Expand();
                            }));
                        }
                    }

                    try
                    {
                        Thread.Sleep(100);
                    }
                    catch (Exception ex) { }
                }
                catch (Exception ex)
                {
                    dialog.TopMost = false;
                    MessageBox.Show("操作失败!Ex:" + ex.ToString());
                }
            }));
        }