Beispiel #1
0
        /// <summary>
        /// 获取不同的数据库操作对象
        /// </summary>
        /// <param name="cnn"></param>
        /// <returns></returns>
        public static IDbObject GetDBObject(ConnectionModel cnn)
        {
            IDbObject dbObject = null;

            if (cnn.DbType.Equals(DatabaseType.SqlServer.ToString()))
            {
                dbObject = new WEF.DbDAL.SQL2000.DbObject(cnn.ConnectionString);
            }
            else if (cnn.DbType.Equals(DatabaseType.SqlServer9.ToString()))
            {
                dbObject = new WEF.DbDAL.SQL2005.DbObject(cnn.ConnectionString);
            }
            else if (cnn.DbType.Equals(DatabaseType.MsAccess.ToString()))
            {
                dbObject = new WEF.DbDAL.OleDb.DbObject(cnn.ConnectionString);
            }
            else if (cnn.DbType.Equals(DatabaseType.Oracle.ToString()))
            {
                dbObject = new WEF.DbDAL.Oracle.DbObject(cnn.ConnectionString);
            }
            else if (cnn.DbType.Equals(DatabaseType.Sqlite3.ToString()))
            {
                dbObject = new WEF.DbDAL.SQLite.DbObject(cnn.ConnectionString);
            }
            else if (cnn.DbType.Equals(DatabaseType.MySql.ToString()))
            {
                dbObject = new WEF.DbDAL.MySql.DbObject(cnn.ConnectionString);
            }
            else if (cnn.DbType.Equals(DatabaseType.MariaDB.ToString()))
            {
                dbObject = new WEF.DbDAL.MySql.DbObject(cnn.ConnectionString);
            }
            else if (cnn.DbType.Equals(DatabaseType.PostgreSQL.ToString()))
            {
                dbObject = new WEF.DbDAL.PostgreSQL.DbObject(cnn.ConnectionString);
            }
            else
            {
                throw new Exception($"暂不支持的数据类型[{cnn.DbType}]");
            }
            return(dbObject);
        }
Beispiel #2
0
        public void RunSql()
        {
            var sql = AutoTextBox.TextBox.Text;

            stopwatch.Restart();

            LoadForm.ShowLoading(this);

            Task.Factory.StartNew(() =>
            {
                WEF.DbDAL.IDbObject dbObject = null;

                if (ConnectionModel.DbType.Equals(DatabaseType.SqlServer.ToString()))
                {
                    dbObject = new WEF.DbDAL.SQL2000.DbObject(ConnectionModel.ConnectionString);
                }
                else if (ConnectionModel.DbType.Equals(DatabaseType.SqlServer9.ToString()))
                {
                    dbObject = new WEF.DbDAL.SQL2005.DbObject(ConnectionModel.ConnectionString);
                }
                else if (ConnectionModel.DbType.Equals(DatabaseType.MsAccess.ToString()))
                {
                    dbObject = new WEF.DbDAL.OleDb.DbObject(ConnectionModel.ConnectionString);
                }
                else if (ConnectionModel.DbType.Equals(DatabaseType.Oracle.ToString()))
                {
                    dbObject = new WEF.DbDAL.Oracle.DbObject(ConnectionModel.ConnectionString);
                }
                else if (ConnectionModel.DbType.Equals(DatabaseType.Sqlite3.ToString()))
                {
                    dbObject = new WEF.DbDAL.SQLite.DbObject(ConnectionModel.ConnectionString);
                }
                else if (ConnectionModel.DbType.Equals(DatabaseType.MySql.ToString()))
                {
                    dbObject = new WEF.DbDAL.MySql.DbObject(ConnectionModel.ConnectionString);
                }
                else if (ConnectionModel.DbType.Equals(DatabaseType.MariaDB.ToString()))
                {
                    dbObject = new WEF.DbDAL.MySql.DbObject(ConnectionModel.ConnectionString);
                }
                else if (ConnectionModel.DbType.Equals(DatabaseType.PostgreSQL.ToString()))
                {
                    dbObject = new WEF.DbDAL.PostgreSQL.DbObject(ConnectionModel.ConnectionString);
                }
                else
                {
                    LoadForm.HideLoading(1);
                    this.Invoke(new Action(() =>
                    {
                        MessageBox.Show(this, "不支持的数据库类型!");
                    }));
                    return;
                }

                if (string.IsNullOrEmpty(sql))
                {
                    LoadForm.HideLoading(1);

                    this.Invoke(new Action(() =>
                    {
                        MessageBox.Show(this, "sql内容不能为空!");
                    }));

                    return;
                }

                this.Invoke(new Action(() =>
                {
                    if (!string.IsNullOrWhiteSpace(AutoTextBox.TextBox.SelectedText))
                    {
                        sql = AutoTextBox.TextBox.SelectedText.Trim();

                        if (string.IsNullOrEmpty(sql))
                        {
                            LoadForm.HideLoading(1);
                            MessageBox.Show(this, "sql内容不能为空!");
                            return;
                        }
                    }

                    dataGridView1.DataSource = null;
                }));

                if (sql.IndexOf("select", StringComparison.InvariantCultureIgnoreCase) >= 0)
                {
                    try
                    {
                        int max = 50;

                        var ds = dbObject.Query(ConnectionModel.Database, sql);

                        if (ds != null && ds.Tables != null)
                        {
                            var dt = ds.Tables[0];

                            if (dt != null && dt.Rows.Count > 0)
                            {
                                var count = dt.Rows.Count;

                                if (count > max)
                                {
                                    for (int i = max; i < count; i++)
                                    {
                                        dt.Rows.RemoveAt(max);
                                    }
                                }


                                var dList = new List <int>();

                                for (int i = 0; i < dt.Columns.Count; i++)
                                {
                                    if (dt.Columns[i].DataType == typeof(DateTime))
                                    {
                                        dList.Add(i);
                                    }
                                }


                                dataGridView1.Invoke(new Action(() =>
                                {
                                    dataGridView1.DataSource = dt;

                                    if (dList.Any())
                                    {
                                        foreach (var item in dList)
                                        {
                                            dataGridView1.Columns[item].DefaultCellStyle.Format = "yyyy-MM-dd HH:mm:ss.fff";
                                        }
                                    }

                                    lbl_execute.Text = $"当前显示{(max > count ? count : max)}行,影响数据行数:{count} 耗时:{stopwatch.Elapsed.TotalSeconds} 秒";
                                }));
                            }
                        }
                        LoadForm.HideLoading();
                    }
                    catch (Exception ex)
                    {
                        LoadForm.HideLoading();
                        this.Invoke(new Action(() =>
                        {
                            MessageBox.Show(this, $"查询发生异常,ex:" + ex.Message);
                        }));
                    }
                }
                else
                {
                    try
                    {
                        var count = dbObject.ExecuteSql(ConnectionModel.Database, sql);

                        lbl_execute.Invoke(new Action(() =>
                        {
                            lbl_execute.Text = $"影响数据行数:{count} 耗时:{stopwatch.Elapsed.TotalMilliseconds} 毫秒";
                        }));

                        LoadForm.HideLoading();
                    }
                    catch (Exception ex)
                    {
                        LoadForm.HideLoading();
                        this.Invoke(new Action(() =>
                        {
                            MessageBox.Show(this, $"操作发生异常,ex:" + ex.Message);
                        }));
                    }
                }
            });
        }
Beispiel #3
0
        /// <summary>
        /// 刷新数据库表和视图
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void 刷新ToolStripMenuItem2_Click(object sender, EventArgs e)
        {
            TreeNode node = Treeview.SelectedNode;

            if (node.Level == 3)
            {
                node = node.Parent;
            }
            if (node.Level == 4)
            {
                node = node.Parent.Parent;
            }

            node.Nodes.Clear();

            Connection conModel = null;

            try
            {
                conModel = _ConnectList.Find(delegate(Connection con) { return(con.ID.ToString().Equals(node.Parent.Tag.ToString())); });

                IDbObject dbObject;

                if (conModel.DbType.Equals(DatabaseType.MsAccess.ToString()))
                {
                    dbObject = new WEF.DbDAL.OleDb.DbObject(conConnectionString);
                    ShowTablesAndViews(node, dbObject.GetTables(""), dbObject.GetVIEWs(""));
                }
                else if (conModel.DbType.Equals(DatabaseType.SqlServer.ToString()))
                {
                    dbObject = new WEF.DbDAL.SQL2000.DbObject(conConnectionString);
                    ShowTablesAndViews(node, dbObject.GetTables(node.Text), dbObject.GetVIEWs(node.Text));
                }
                else if (conModel.DbType.Equals(DatabaseType.SqlServer9.ToString()))
                {
                    dbObject = new WEF.DbDAL.SQL2005.DbObject(conConnectionString);
                    ShowTablesAndViews(node, dbObject.GetTables(node.Text), dbObject.GetVIEWs(node.Text));
                }
                else if (conModel.DbType.Equals(DatabaseType.Oracle.ToString()))
                {
                    dbObject = new WEF.DbDAL.Oracle.DbObject(conConnectionString);
                    ShowTablesAndViews(node, dbObject.GetTables(node.Text), dbObject.GetVIEWs(node.Text));
                }
                else if (conModel.DbType.Equals(DatabaseType.MySql.ToString()))
                {
                    dbObject = new WEF.DbDAL.MySql.DbObject(conConnectionString);
                    ShowTablesAndViews(node, dbObject.GetTables(node.Text), dbObject.GetVIEWs(node.Text));
                }
                else if (conModel.DbType.Equals(DatabaseType.Sqlite3.ToString()))
                {
                    dbObject = new WEF.DbDAL.SQLite.DbObject(conConnectionString);
                    ShowTablesAndViews(node, dbObject.GetTables(node.Text), dbObject.GetVIEWs(node.Text));
                }
                else if (conModel.DbType.Equals(DatabaseType.MongoDB.ToString()))
                {
                    var mongoDBTool = MongoDBTool.Connect(conConnectionString);
                    ShowCollections(node, mongoDBTool.GetCollections(node.Text));
                }
                node.ExpandAll();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "出错啦!", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Beispiel #4
0
        /// <summary>
        /// 获取数据库服务器
        /// </summary>
        private void getDatabaseinfo()
        {
            LoadForm.ShowLoading(this);

            TreeNode node = Treeview.SelectedNode;

            Task.Factory.StartNew(() =>
            {
                try
                {
                    Connection conModel = null;

                    this.Invoke(new Action(() =>
                    {
                        conModel = _ConnectList.Find(delegate(Connection con) { return(con.ID.ToString().Equals(node.Tag.ToString())); });
                    }));


                    conConnectionString = conModel.ConnectionString;

                    IDbObject dbObject;

                    if (conModel.DbType.Equals(DatabaseType.MsAccess.ToString()))
                    {
                        dbObject = new WEF.DbDAL.OleDb.DbObject(conConnectionString);

                        TreeNode tnode = null;

                        this.Invoke(new Action(() =>
                        {
                            tnode     = new TreeNode(conModel.Database, 1, 1);
                            tnode.Tag = conConnectionString;
                            tnode.ContextMenuStrip = contextMenuStripOneDataBase;
                            node.Nodes.Add(tnode);
                        }));

                        var tables = dbObject.GetTables("");

                        var views = dbObject.GetVIEWs("");


                        this.Invoke(new Action(() =>
                        {
                            ShowTablesAndViews(tnode, tables, views);
                        }));
                    }
                    else if (conModel.DbType.Equals(DatabaseType.Sqlite3.ToString()))
                    {
                        dbObject = new WEF.DbDAL.SQLite.DbObject(conConnectionString);

                        TreeNode tnode = null;

                        this.Invoke(new Action(() =>
                        {
                            tnode     = new TreeNode(conModel.Database, 1, 1);
                            tnode.Tag = conConnectionString;
                            tnode.ContextMenuStrip = contextMenuStripOneDataBase;
                            node.Nodes.Add(tnode);
                        }));

                        var tables = dbObject.GetTables("");

                        var views = dbObject.GetVIEWs("");


                        this.Invoke(new Action(() =>
                        {
                            ShowTablesAndViews(tnode, tables, views);
                        }));
                    }
                    else if (conModel.DbType.Equals(DatabaseType.SqlServer.ToString()) || conModel.DbType.Equals(DatabaseType.SqlServer9.ToString()))
                    {
                        if (conModel.DbType.Equals(DatabaseType.SqlServer.ToString()))
                        {
                            dbObject = new WEF.DbDAL.SQL2000.DbObject(conConnectionString);
                        }
                        else
                        {
                            dbObject = new WEF.DbDAL.SQL2005.DbObject(conConnectionString);
                        }

                        if (conModel.Database.Equals("all"))
                        {
                            DataTable dt = dbObject.GetDBList();

                            foreach (DataRow dr in dt.Rows)
                            {
                                TreeNode tnode = null;

                                this.Invoke(new Action(() =>
                                {
                                    tnode     = new TreeNode(dr[0].ToString(), 1, 1);
                                    tnode.Tag = conConnectionString.Replace("master", dr[0].ToString());
                                    tnode.ContextMenuStrip = contextMenuStripOneDataBase;
                                    node.Nodes.Add(tnode);
                                }));

                                var tables = dbObject.GetTables(tnode.Text);

                                var views = dbObject.GetVIEWs(tnode.Text);

                                this.Invoke(new Action(() =>
                                {
                                    ShowTablesAndViews(tnode, tables, views);
                                }));
                            }
                        }
                        else
                        {
                            TreeNode tnode = null;

                            this.Invoke(new Action(() =>
                            {
                                tnode     = new TreeNode(conModel.Database, 1, 1);
                                tnode.Tag = conConnectionString;
                                tnode.ContextMenuStrip = contextMenuStripOneDataBase;
                                node.Nodes.Add(tnode);
                            }));

                            var tables = dbObject.GetTables(tnode.Text);

                            var views = dbObject.GetVIEWs(tnode.Text);

                            this.Invoke(new Action(() =>
                            {
                                ShowTablesAndViews(tnode, tables, views);
                            }));
                        }
                    }
                    else if (conModel.DbType.Equals(DatabaseType.Oracle.ToString()))
                    {
                        dbObject = new WEF.DbDAL.Oracle.DbObject(conConnectionString);

                        TreeNode tnode = null;

                        this.Invoke(new Action(() =>
                        {
                            tnode     = new TreeNode(conModel.Database, 1, 1);
                            tnode.Tag = conConnectionString;
                            tnode.ContextMenuStrip = contextMenuStripOneDataBase;
                            node.Nodes.Add(tnode);
                        }));

                        var tables = dbObject.GetTables(tnode.Text);

                        var views = dbObject.GetVIEWs(tnode.Text);

                        this.Invoke(new Action(() =>
                        {
                            ShowTablesAndViews(tnode, tables, views);
                        }));
                    }
                    else if (conModel.DbType.Equals(DatabaseType.MySql.ToString()))
                    {
                        dbObject = new WEF.DbDAL.MySql.DbObject(conConnectionString);

                        if (conModel.Database.Equals("all"))
                        {
                            DataTable dt = dbObject.GetDBList();

                            foreach (DataRow dr in dt.Rows)
                            {
                                TreeNode tnode = null;

                                this.Invoke(new Action(() =>
                                {
                                    tnode     = new TreeNode(dr[0].ToString(), 1, 1);
                                    tnode.Tag = conConnectionString.Replace("master", dr[0].ToString());
                                    tnode.ContextMenuStrip = contextMenuStripOneDataBase;
                                    node.Nodes.Add(tnode);
                                }));

                                var tables = dbObject.GetTables(tnode.Text);

                                var views = dbObject.GetVIEWs(tnode.Text);

                                this.Invoke(new Action(() =>
                                {
                                    ShowTablesAndViews(tnode, tables, views);
                                }));
                            }
                        }
                        else
                        {
                            TreeNode tnode = null;

                            this.Invoke(new Action(() =>
                            {
                                tnode     = new TreeNode(conModel.Database, 1, 1);
                                tnode.Tag = conConnectionString;
                                tnode.ContextMenuStrip = contextMenuStripOneDataBase;
                                node.Nodes.Add(tnode);
                            }));

                            var tables = dbObject.GetTables(tnode.Text);

                            var views = dbObject.GetVIEWs(tnode.Text);

                            this.Invoke(new Action(() =>
                            {
                                ShowTablesAndViews(tnode, tables, views);
                            }));
                        }
                    }
                    else if (conModel.DbType.Equals(DatabaseType.PostgreSQL.ToString()))
                    {
                        dbObject = new WEF.DbDAL.PostgreSQL.DbObject(conConnectionString);

                        if (conModel.Database.Equals("all"))
                        {
                            DataTable dt = dbObject.GetDBList();

                            foreach (DataRow dr in dt.Rows)
                            {
                                TreeNode tnode = null;

                                this.Invoke(new Action(() =>
                                {
                                    tnode     = new TreeNode(dr[0].ToString(), 1, 1);
                                    tnode.Tag = conConnectionString.Replace("postgres", dr[0].ToString());
                                    tnode.ContextMenuStrip = contextMenuStripOneDataBase;
                                    node.Nodes.Add(tnode);
                                }));

                                var tables = dbObject.GetTables(tnode.Text);

                                var views = dbObject.GetVIEWs(tnode.Text);

                                this.Invoke(new Action(() =>
                                {
                                    ShowTablesAndViews(tnode, tables, views);
                                }));
                            }
                        }
                        else
                        {
                            TreeNode tnode = null;

                            this.Invoke(new Action(() =>
                            {
                                tnode     = new TreeNode(conModel.Database, 1, 1);
                                tnode.Tag = conConnectionString;
                                tnode.ContextMenuStrip = contextMenuStripOneDataBase;
                                node.Nodes.Add(tnode);
                            }));

                            var tables = dbObject.GetTables(tnode.Text);

                            var views = dbObject.GetVIEWs(tnode.Text);

                            this.Invoke(new Action(() =>
                            {
                                ShowTablesAndViews(tnode, tables, views);
                            }));
                        }
                    }
                    else if (conModel.DbType.Equals(DatabaseType.MongoDB.ToString()))
                    {
                        var dataBaseName = "admin";

                        var mongoDBTool = MongoDBTool.Connect(conConnectionString);

                        if (conModel.Database.Equals("all"))
                        {
                            var dataBaseNames = mongoDBTool.GetDataBases();

                            foreach (var dbs in dataBaseNames)
                            {
                                TreeNode tnode = null;

                                this.Invoke(new Action(() =>
                                {
                                    tnode     = new TreeNode(dbs, 1, 1);
                                    tnode.Tag = conConnectionString.Replace(dataBaseName, dbs);
                                    tnode.ContextMenuStrip = contextMenuStripOneMongoDB;
                                    node.Nodes.Add(tnode);
                                }));

                                var cs = mongoDBTool.GetCollections(dbs);

                                this.Invoke(new Action(() =>
                                {
                                    ShowCollections(tnode, cs);
                                }));
                            }
                        }
                        else
                        {
                            dataBaseName = conModel.Database;

                            TreeNode tnode = null;

                            this.Invoke(new Action(() =>
                            {
                                tnode     = new TreeNode(conModel.Database, 1, 1);
                                tnode.Tag = conConnectionString;
                                tnode.ContextMenuStrip = contextMenuStripOneMongoDB;
                                node.Nodes.Add(tnode);
                            }));

                            var collections = mongoDBTool.GetCollections(dataBaseName);

                            this.Invoke(new Action(() =>
                            {
                                ShowCollections(tnode, collections);
                            }));
                        }
                    }
                    LoadForm.HideLoading();
                }
                catch (Exception ex)
                {
                    LoadForm.HideLoading();
                    MessageBox.Show(ex.Message, "出错啦!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                finally
                {
                    this.Invoke(new Action(() =>
                    {
                        node.Expand();
                    }));
                }
            });
        }
Beispiel #5
0
        /// <summary>
        /// 加载
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ContentForm_Load(object sender, EventArgs e)
        {
            LoadForm.ShowLoading(this);

            if (ConnectionModel != null)
            {
                this.DatabaseName = ConnectionModel.Database;
                this.TableName    = ConnectionModel.TableName;
                this.IsView       = ConnectionModel.IsView;
            }



            Task.Factory.StartNew(() =>
            {
                WEF.DbDAL.IDbObject dbObject = null;

                if (ConnectionModel.DbType.Equals(DatabaseType.SqlServer.ToString()))
                {
                    dbObject = new WEF.DbDAL.SQL2000.DbObject(ConnectionModel.ConnectionString);
                }
                else if (ConnectionModel.DbType.Equals(DatabaseType.SqlServer9.ToString()))
                {
                    dbObject = new WEF.DbDAL.SQL2005.DbObject(ConnectionModel.ConnectionString);
                }
                else if (ConnectionModel.DbType.Equals(DatabaseType.MsAccess.ToString()))
                {
                    dbObject = new WEF.DbDAL.OleDb.DbObject(ConnectionModel.ConnectionString);
                }
                else if (ConnectionModel.DbType.Equals(DatabaseType.Oracle.ToString()))
                {
                    dbObject = new WEF.DbDAL.Oracle.DbObject(ConnectionModel.ConnectionString);
                }
                else if (ConnectionModel.DbType.Equals(DatabaseType.Sqlite3.ToString()))
                {
                    dbObject = new WEF.DbDAL.SQLite.DbObject(ConnectionModel.ConnectionString);
                }
                else if (ConnectionModel.DbType.Equals(DatabaseType.MySql.ToString()))
                {
                    dbObject = new WEF.DbDAL.MySql.DbObject(ConnectionModel.ConnectionString);
                }
                else if (ConnectionModel.DbType.Equals(DatabaseType.MongoDB.ToString()))
                {
                    dbObject = new WEF.DbDAL.MySql.DbObject(ConnectionModel.ConnectionString);
                }
                else if (ConnectionModel.DbType.Equals(DatabaseType.PostgreSQL.ToString()))
                {
                    dbObject = new WEF.DbDAL.PostgreSQL.DbObject(ConnectionModel.ConnectionString);
                }
                else
                {
                    LoadForm.HideLoading(1);
                    MessageBox.Show("未知数据库类型!");
                    return;
                }

                DataTable primarykeydt = dbObject.GetKeyName(DatabaseName, TableName);


                if (primarykeydt.Rows.Count == 0)
                {
                    MessageBox.Show("当前表找不到任何主键,请选择上面的列表行来添加主键");
                }

                this.Invoke(new Action(() =>
                {
                    cnnTxt.Text = ConnectionModel.ConnectionString;

                    #region structure

                    columnsdt = dbObject.GetColumnInfoList(DatabaseName, TableName);

                    gridColumns.DataSource = columnsdt;

                    #endregion

                    cbPrimarykey.Items.Clear();

                    if (null != primarykeydt && primarykeydt.Rows.Count > 0)
                    {
                        foreach (DataRow dr in primarykeydt.Rows)
                        {
                            cbPrimarykey.Items.Add(dr["ColumnName"].ToString());
                        }

                        cbPrimarykey.SelectedIndex = 0;
                    }



                    txtClassName.Text = TableName.Trim().Replace(' ', '_');
                    txtnamespace.Text = UtilsHelper.ReadNamespace();
                }));
                LoadForm.HideLoading(1);
            });
        }
Beispiel #6
0
        /// <summary>
        /// 执行sql
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void autoTextBox1_KeyUp(object sender, System.Windows.Forms.KeyEventArgs e)
        {
            string sql = ((TextBox)sender).Text.Trim();

            ShortcutKeyHelper.Run(sender, e, () =>
            {
                stopwatch.Restart();

                LoadForm.ShowLoading(this);

                Task.Factory.StartNew(() =>
                {
                    WEF.DbDAL.IDbObject dbObject = null;

                    if (ConnectionModel.DbType.Equals(DatabaseType.SqlServer.ToString()))
                    {
                        dbObject = new WEF.DbDAL.SQL2000.DbObject(ConnectionModel.ConnectionString);
                    }
                    else if (ConnectionModel.DbType.Equals(DatabaseType.SqlServer9.ToString()))
                    {
                        dbObject = new WEF.DbDAL.SQL2005.DbObject(ConnectionModel.ConnectionString);
                    }
                    else if (ConnectionModel.DbType.Equals(DatabaseType.MsAccess.ToString()))
                    {
                        dbObject = new WEF.DbDAL.OleDb.DbObject(ConnectionModel.ConnectionString);
                    }
                    else if (ConnectionModel.DbType.Equals(DatabaseType.Oracle.ToString()))
                    {
                        dbObject = new WEF.DbDAL.Oracle.DbObject(ConnectionModel.ConnectionString);
                    }
                    else if (ConnectionModel.DbType.Equals(DatabaseType.Sqlite3.ToString()))
                    {
                        dbObject = new WEF.DbDAL.SQLite.DbObject(ConnectionModel.ConnectionString);
                    }
                    else if (ConnectionModel.DbType.Equals(DatabaseType.MySql.ToString()))
                    {
                        dbObject = new WEF.DbDAL.MySql.DbObject(ConnectionModel.ConnectionString);
                    }
                    else
                    {
                        LoadForm.HideLoading(1);
                        MessageBox.Show("不支持的数据库类型!");
                        return;
                    }

                    if (string.IsNullOrEmpty(sql))
                    {
                        MessageBox.Show("sql内容不能为空!");
                        return;
                    }

                    this.Invoke(new Action(() =>
                    {
                        if (!string.IsNullOrWhiteSpace(((TextBox)sender).SelectedText))
                        {
                            sql = ((TextBox)sender).SelectedText.Trim();

                            if (string.IsNullOrEmpty(sql))
                            {
                                MessageBox.Show("sql内容不能为空!");
                                return;
                            }
                        }

                        dataGridView1.DataSource = null;
                    }));

                    if (string.Compare(sql, "select", true) >= 0)
                    {
                        try
                        {
                            int max = 50;

                            var dt = dbObject.GetTabData(ConnectionModel.Database, sql, max);

                            if (dt != null && dt.Rows.Count > 0)
                            {
                                var count = dt.Rows.Count;

                                if (count > max)
                                {
                                    for (int i = max; i < count; i++)
                                    {
                                        dt.Rows.RemoveAt(max);
                                    }
                                }


                                var dList = new List <int>();

                                for (int i = 0; i < dt.Columns.Count; i++)
                                {
                                    if (dt.Columns[i].DataType == typeof(DateTime))
                                    {
                                        dList.Add(i);
                                    }
                                }


                                dataGridView1.Invoke(new Action(() =>
                                {
                                    dataGridView1.DataSource = dt;

                                    if (dList.Any())
                                    {
                                        foreach (var item in dList)
                                        {
                                            dataGridView1.Columns[item].DefaultCellStyle.Format = "yyyy-MM-dd HH:mm:ss.fff";
                                        }
                                    }

                                    lbl_execute.Text = $"当前显示{(max > count ? count : max)}行,影响数据行数:{count} 耗时:{stopwatch.Elapsed.TotalSeconds} 秒";
                                }));
                            }
                        }
                        catch (Exception ex)
                        {
                            this.Invoke(new Action(() =>
                            {
                                MessageBox.Show(this, $"查询发生异常,ex:" + ex.Message);
                            }));
                        }
                    }
                    else
                    {
                        try
                        {
                            var count = dbObject.ExecuteSql(ConnectionModel.Database, sql);

                            lbl_execute.Invoke(new Action(() =>
                            {
                                lbl_execute.Text = $"影响数据行数:{count} 耗时:{stopwatch.Elapsed.TotalMilliseconds} 毫秒";
                            }));
                        }
                        catch (Exception ex)
                        {
                            this.Invoke(new Action(() =>
                            {
                                MessageBox.Show(this, $"操作发生异常,ex:" + ex.Message);
                            }));
                        }
                    }
                    LoadForm.HideLoading();
                });
            });

            ShortcutKeyHelper.AllSelect(sender, e);
        }