Ejemplo n.º 1
0
        private void DatabaseList_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.Cursor = Cursors.WaitCursor;

            database       = DatabaseList.Text;
            SPList.Enabled = DatabaseList.SelectedIndex != -1;
            AllProceduresCheckbox.Enabled = SPList.Enabled;
            AllProceduresCheckbox.Checked = false;
            SPList.Text = string.Empty;
            SPList.Items.Clear();
            procedures.Clear();
            SPSQL.Clear();
            SPTextBox.Text = string.Empty;

            if (string.IsNullOrEmpty(database))
            {
                return;
            }

            var connectionString = string.Format(@"Server={0};Initial Catalog={1};Integrated Security=SSPI", server, database);

            using (var conn = new SqlConnection(connectionString))
            {
                try
                {
                    conn.Open();

                    var sql = @"
                        SELECT ROUTINE_NAME, ROUTINE_DEFINITION
                        FROM information_schema.routines 
                        WHERE routine_type = 'PROCEDURE' AND ROUTINE_NAME LIKE 'fe_%'
                        ORDER BY ROUTINE_NAME ASC;";

                    using (var cmd = new SqlCommand(sql, conn))
                    {
                        using (var result = cmd.ExecuteReader())
                        {
                            if (result.HasRows)
                            {
                                while (result.Read())
                                {
                                    SPList.Items.Add(result["ROUTINE_NAME"]);
                                }
                            }

                            result.Close();
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                    return;
                }
                finally
                {
                    conn.Close();
                    this.Cursor = Cursors.Default;
                }
            }

            SPList.Focus();
        }