public void ShowViewDDL(TreeView treeView1)
        {
            var dataTable = new DataTable();
            Connection.MySqlConnection.Open();
            MySqlCommand mySqlCommand = new MySqlCommand("SELECT VIEW_DEFINITION FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_SCHEMA = '"+Connection.CurrentUser.Database+"' AND TABLE_NAME = '"+treeView1.SelectedNode.Text+"';", Connection.MySqlConnection);
            MySqlDataReader mySqlReader;
            try
            {
                mySqlReader = mySqlCommand.ExecuteReader();
                if (mySqlReader.HasRows)
                {
                    dataTable.Load(mySqlReader);
                    mySqlReader.Close();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return;
            }
            Connection.MySqlConnection.Close();

            var sql = "CREATE ALGORITHM=UNDEFINED DEFINER='" + Connection.CurrentUser.Username + "'@'" +
                      Connection.CurrentUser.Server + "'";
            sql += " SQL SECURITY DEFINER VIEW "+treeView1.SelectedNode.Text;
            sql += " AS " + dataTable.Rows[0][0].ToString();
            var form = new DDLView(new UserManager(Connection),sql);
            form.Object = "View";
            form.Objectname = treeView1.SelectedNode.Text;
            form.Show();
        }
        public void ShowProccedureDDL( TreeView treeView1)
        {
            var dataTable = new DataTable();
            Connection.MySqlConnection.Open();
            MySqlCommand mySqlCommand = new MySqlCommand("SELECT  param_list,body  FROM mysql.proc WHERE NAME='" + treeView1.SelectedNode.Text + "' and db = '" + Connection.CurrentUser.Database + "' and type ='PROCEDURE';", Connection.MySqlConnection);
            MySqlDataReader mySqlReader;
            try
            {
                mySqlReader = mySqlCommand.ExecuteReader();
                if (mySqlReader.HasRows)
                {
                    dataTable.Load(mySqlReader);
                    mySqlReader.Close();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return;
            }
            Connection.MySqlConnection.Close();

            var sql = "CREATE DEFINER='" + Connection.CurrentUser.Username + "'@'" + Connection.CurrentUser.Server +
                      "' PROCEDURE " + treeView1.SelectedNode.Text + "\n (" + Encoding.UTF8.GetString((byte[])dataTable.Rows[0][0]) + ")\n ";

            sql +=Encoding.UTF8.GetString((byte[])dataTable.Rows[0][1]) + "\n";
            var form = new DDLView(new UserManager(Connection),sql);
            form.Object = "PROCEDURE";
            form.Objectname = treeView1.SelectedNode.Text;
            form.Show();
        }
        public void ShowTriggerDDL(TreeView treeView1)
        {
            var dataTable = new DataTable();
            Connection.MySqlConnection.Open();
            MySqlCommand mySqlCommand = new MySqlCommand("SELECT ACTION_TIMING,EVENT_MANIPULATION,EVENT_OBJECT_TABLE,ACTION_STATEMENT FROM INFORMATION_SCHEMA.TRIGGERS WHERE TRIGGER_SCHEMA='"+Connection.CurrentUser.Database+"' And TRIGGER_NAME='" + treeView1.SelectedNode.Text + "';", Connection.MySqlConnection);
            MySqlDataReader mySqlReader;
            try
            {
                mySqlReader = mySqlCommand.ExecuteReader();
                if (mySqlReader.HasRows)
                {
                    dataTable.Load(mySqlReader);
                    mySqlReader.Close();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return;
            }
            Connection.MySqlConnection.Close();

            var sql = "CREATE DEFINER='" + Connection.CurrentUser.Username + "'@'" + Connection.CurrentUser.Server +
                      "' TRIGGER";
            sql+=" "+Connection.CurrentUser.Database+"."+treeView1.SelectedNode.Text;
            sql += " "+dataTable.Rows[0][0].ToString();
            sql += " " + dataTable.Rows[0][1].ToString()+" ON";
            sql += " " + dataTable.Rows[0][2].ToString() + " FOR EACH ROW\n";
            sql += " " + dataTable.Rows[0][3].ToString();
            var form = new DDLView(new UserManager(Connection),sql);
            form.Object = "TRIGGER";
            form.Objectname = treeView1.SelectedNode.Text;
            form.Show();
        }
        public void ShowIndexDDL(TreeView treeView1)
        {
            Console.WriteLine("am a Index");
            var dataTable = new DataTable();
            Connection.MySqlConnection.Open();
            MySqlCommand mySqlCommand = new MySqlCommand("SELECT NON_UNIQUE,TABLE_NAME,COLUMN_NAME,INDEX_TYPE FROM  INFORMATION_SCHEMA.STATISTICS WHERE INDEX_SCHEMA='"+Connection.CurrentUser.Database+"' AND INDEX_NAME='" + treeView1.SelectedNode.Text + "';", Connection.MySqlConnection);
            MySqlDataReader mySqlReader;
            try
            {
                mySqlReader = mySqlCommand.ExecuteReader();
                if (mySqlReader.HasRows)
                {
                    dataTable.Load(mySqlReader);
                    mySqlReader.Close();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return;
            }
            Connection.MySqlConnection.Close();

            var sql = " ";
            if(dataTable.Rows[0][0].ToString().Equals("0"))

                 sql = "CREATE UNIQUE INDEX";
            else
            {
                sql = "CREATE INDEX";
            }
            sql += " " + treeView1.SelectedNode.Text+"\n";
            sql += "ON " + dataTable.Rows[0][1].ToString();
            sql+="("+dataTable.Rows[0][2]+")\n";
            sql += "USING " + dataTable.Rows[0][3].ToString();
            var form = new DDLView(new UserManager(Connection),sql);
            form.Object = "Index";
            form.Objectname = treeView1.SelectedNode.Text;
            form.tableindex = treeView1.SelectedNode.Parent.Parent.Text;
            form.Show();
        }