FrmBaseDatos, FrmDatos y FrmProcedimientos: Botón refrescar

This commit is contained in:
2013-11-26 23:35:47 +01:00
parent 0ab98aef0e
commit 101838d653
6 changed files with 180 additions and 107 deletions

View File

@@ -28,7 +28,6 @@
/// </summary> /// </summary>
private void InitializeComponent() private void InitializeComponent()
{ {
this.txtConString = new ServerExplorer.Controls.CustomTextBox();
this.lblConString = new System.Windows.Forms.Label(); this.lblConString = new System.Windows.Forms.Label();
this.btnCopiarConString = new System.Windows.Forms.Button(); this.btnCopiarConString = new System.Windows.Forms.Button();
this.menuBaseDatos = new System.Windows.Forms.MenuStrip(); this.menuBaseDatos = new System.Windows.Forms.MenuStrip();
@@ -44,6 +43,7 @@
this.btnProcs = new System.Windows.Forms.Button(); this.btnProcs = new System.Windows.Forms.Button();
this.btnExec = new System.Windows.Forms.Button(); this.btnExec = new System.Windows.Forms.Button();
this.splitContainer1 = new System.Windows.Forms.SplitContainer(); this.splitContainer1 = new System.Windows.Forms.SplitContainer();
this.btnRefresh = new System.Windows.Forms.Button();
this.lsvTablas = new ServerExplorer.Controls.CustomListView(); this.lsvTablas = new ServerExplorer.Controls.CustomListView();
this.colNombreTabla = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.colNombreTabla = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.colEsquema = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.colEsquema = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
@@ -54,23 +54,13 @@
this.colTamanho = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.colTamanho = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.colClave = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.colClave = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.colNullable = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.colNullable = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.txtConString = new ServerExplorer.Controls.CustomTextBox();
this.menuBaseDatos.SuspendLayout(); this.menuBaseDatos.SuspendLayout();
this.splitContainer1.Panel1.SuspendLayout(); this.splitContainer1.Panel1.SuspendLayout();
this.splitContainer1.Panel2.SuspendLayout(); this.splitContainer1.Panel2.SuspendLayout();
this.splitContainer1.SuspendLayout(); this.splitContainer1.SuspendLayout();
this.SuspendLayout(); this.SuspendLayout();
// //
// txtConString
//
this.txtConString.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.txtConString.Location = new System.Drawing.Point(120, 6);
this.txtConString.Name = "txtConString";
this.txtConString.ReadOnly = true;
this.txtConString.Size = new System.Drawing.Size(616, 20);
this.txtConString.TabIndex = 0;
this.txtConString.TabWidth = 8;
//
// lblConString // lblConString
// //
this.lblConString.AutoSize = true; this.lblConString.AutoSize = true;
@@ -229,24 +219,36 @@
// //
// splitContainer1.Panel1 // splitContainer1.Panel1
// //
this.splitContainer1.Panel1.Controls.Add(this.btnRefresh);
this.splitContainer1.Panel1.Controls.Add(this.lblTituloDB); this.splitContainer1.Panel1.Controls.Add(this.lblTituloDB);
this.splitContainer1.Panel1.Controls.Add(this.btnExec);
this.splitContainer1.Panel1.Controls.Add(this.lsvTablas); this.splitContainer1.Panel1.Controls.Add(this.lsvTablas);
this.splitContainer1.Panel1.Controls.Add(this.btnProcs);
this.splitContainer1.Panel1.Paint += new System.Windows.Forms.PaintEventHandler(this.splitContainer1_Panel1_Paint); this.splitContainer1.Panel1.Paint += new System.Windows.Forms.PaintEventHandler(this.splitContainer1_Panel1_Paint);
// //
// splitContainer1.Panel2 // splitContainer1.Panel2
// //
this.splitContainer1.Panel2.Controls.Add(this.lblTituloTabla); this.splitContainer1.Panel2.Controls.Add(this.lblTituloTabla);
this.splitContainer1.Panel2.Controls.Add(this.btnDocGen); this.splitContainer1.Panel2.Controls.Add(this.btnDocGen);
this.splitContainer1.Panel2.Controls.Add(this.btnExec);
this.splitContainer1.Panel2.Controls.Add(this.lsvColumnas); this.splitContainer1.Panel2.Controls.Add(this.lsvColumnas);
this.splitContainer1.Panel2.Controls.Add(this.menuBaseDatos); this.splitContainer1.Panel2.Controls.Add(this.menuBaseDatos);
this.splitContainer1.Panel2.Controls.Add(this.btnGenerar); this.splitContainer1.Panel2.Controls.Add(this.btnGenerar);
this.splitContainer1.Panel2.Controls.Add(this.btnProcs);
this.splitContainer1.Panel2.Controls.Add(this.btnVerDatos); this.splitContainer1.Panel2.Controls.Add(this.btnVerDatos);
this.splitContainer1.Size = new System.Drawing.Size(806, 511); this.splitContainer1.Size = new System.Drawing.Size(806, 511);
this.splitContainer1.SplitterDistance = 332; this.splitContainer1.SplitterDistance = 332;
this.splitContainer1.TabIndex = 17; this.splitContainer1.TabIndex = 17;
// //
// btnRefresh
//
this.btnRefresh.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.btnRefresh.Location = new System.Drawing.Point(3, 485);
this.btnRefresh.Name = "btnRefresh";
this.btnRefresh.Size = new System.Drawing.Size(75, 23);
this.btnRefresh.TabIndex = 14;
this.btnRefresh.Text = "Refresh";
this.btnRefresh.UseVisualStyleBackColor = true;
this.btnRefresh.Click += new System.EventHandler(this.btnRefresh_Click);
//
// lsvTablas // lsvTablas
// //
this.lsvTablas.AllowSorting = true; this.lsvTablas.AllowSorting = true;
@@ -261,7 +263,7 @@
this.lsvTablas.FullRowSelect = true; this.lsvTablas.FullRowSelect = true;
this.lsvTablas.Location = new System.Drawing.Point(3, 40); this.lsvTablas.Location = new System.Drawing.Point(3, 40);
this.lsvTablas.Name = "lsvTablas"; this.lsvTablas.Name = "lsvTablas";
this.lsvTablas.Size = new System.Drawing.Size(326, 468); this.lsvTablas.Size = new System.Drawing.Size(326, 439);
this.lsvTablas.Sorting = System.Windows.Forms.SortOrder.Ascending; this.lsvTablas.Sorting = System.Windows.Forms.SortOrder.Ascending;
this.lsvTablas.TabIndex = 4; this.lsvTablas.TabIndex = 4;
this.lsvTablas.UseCompatibleStateImageBehavior = false; this.lsvTablas.UseCompatibleStateImageBehavior = false;
@@ -325,6 +327,17 @@
// //
this.colNullable.Text = "Nullable"; this.colNullable.Text = "Nullable";
// //
// txtConString
//
this.txtConString.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.txtConString.Location = new System.Drawing.Point(120, 6);
this.txtConString.Name = "txtConString";
this.txtConString.ReadOnly = true;
this.txtConString.Size = new System.Drawing.Size(616, 20);
this.txtConString.TabIndex = 0;
this.txtConString.TabWidth = 8;
//
// FrmBaseDatos // FrmBaseDatos
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@@ -377,5 +390,6 @@
private System.Windows.Forms.Button btnExec; private System.Windows.Forms.Button btnExec;
private System.Windows.Forms.SplitContainer splitContainer1; private System.Windows.Forms.SplitContainer splitContainer1;
private System.Windows.Forms.ColumnHeader colNullable; private System.Windows.Forms.ColumnHeader colNullable;
private System.Windows.Forms.Button btnRefresh;
} }
} }

View File

@@ -155,32 +155,31 @@ namespace ServerExplorer.UI
private void lsvTablas_SelectedIndexChanged(object sender, EventArgs e) private void lsvTablas_SelectedIndexChanged(object sender, EventArgs e)
{ {
if (lsvTablas.SelectedItems.Count == 1) if (lsvTablas.SelectedItems.Count != 1) { return; }
// Determinar tabla seleccionada
ListViewItem item = lsvTablas.SelectedItems[0];
// Recordar tabla seleccionada
tableSchema = item.SubItems[1].Text.ToString();
tableName = item.SubItems[0].Text.ToString();
// Establecer titulo de la lista de columnas
lblTituloTabla.Text = tableSchema + "." + tableName;
// Obtener descripcion de tabla
TablaDesc td = new TablaDesc();
td.FillDesc(tableSchema, tableName, cnx);
// Mostrar "columnas" de las tablas
lsvColumnas.Items.Clear();
foreach (ColumnaDesc col in td.Columnas)
{ {
// Determinar tabla seleccionada ListViewItem subitem = lsvColumnas.Items.Add(col.Nombre);
ListViewItem item = lsvTablas.SelectedItems[0]; subitem.SubItems.Add(col.Tipo);
subitem.SubItems.Add((col.Tamanho >= 0) ? String.Format("{0}", col.Tamanho) : string.Empty);
// Recordar tabla seleccionada subitem.SubItems.Add(col.Primaria ? "PK" : string.Empty);
tableSchema = item.SubItems[1].Text.ToString(); subitem.SubItems.Add(col.Nullable ? "Null" : "NotNull");
tableName = item.SubItems[0].Text.ToString();
// Establecer titulo de la lista de columnas
lblTituloTabla.Text = tableSchema + "." + tableName;
// Obtener descripcion de tabla
TablaDesc td = new TablaDesc();
td.FillDesc(item.SubItems[1].Text, item.SubItems[0].Text, cnx);
// Mostrar "columnas" de las tablas
lsvColumnas.Items.Clear();
foreach (ColumnaDesc col in td.Columnas)
{
ListViewItem subitem = lsvColumnas.Items.Add(col.Nombre);
subitem.SubItems.Add(col.Tipo);
subitem.SubItems.Add((col.Tamanho >= 0) ? String.Format("{0}", col.Tamanho) : string.Empty);
subitem.SubItems.Add(col.Primaria ? "PK" : string.Empty);
subitem.SubItems.Add(col.Nullable ? "Null" : "NotNull");
}
} }
} }
@@ -213,48 +212,18 @@ namespace ServerExplorer.UI
private void btnVerDatos_Click(object sender, EventArgs e) private void btnVerDatos_Click(object sender, EventArgs e)
{ {
String nombreTabla; // Obtener descripcion de tabla
DataTable dt; TablaDesc td = new TablaDesc();
SqlDataAdapter da; td.FillDesc(tableSchema, tableName, cnx);
if (tableSchema == null || tableName == null) { return; }
nombreTabla = "[" + tableSchema + "].[" + tableName + "]";
// Obtener un datatable con todos los registros de la tabla.
da = new SqlDataAdapter(
"select * from " + nombreTabla,
cnx);
dt = new DataTable();
cnx.Open();
da.Fill(dt);
cnx.Close();
// Crear y mostrar el formulario de los datos. // Crear y mostrar el formulario de los datos.
FrmDatos form = new FrmDatos(dt, nombreTabla); FrmDatos form = new FrmDatos(td, config.ConnectionString);
FrmPrincipal.AddForm(form); FrmPrincipal.AddForm(form);
} }
private void btnProcs_Click(object sender, EventArgs e) private void btnProcs_Click(object sender, EventArgs e)
{ {
/*DataTable dt;
SqlDataAdapter da;
// Obtener un datatable con todos los registros de la tabla.
da = new SqlDataAdapter(
"SELECT id,name,crdate FROM sysobjects WHERE type = 'P' AND category = 0 ORDER BY name ",
cnx);
dt = new DataTable();
cnx.Open();
da.Fill(dt);
cnx.Close();
// Crear y mostrar el formulario de los datos.
frmDatos form = new frmDatos(dt, "Procedimientos");
FrmPrincipal.AddForm(form);*/
// Crear y mostrar el formulario de los procedimientos. // Crear y mostrar el formulario de los procedimientos.
FrmProcedimientos form = new FrmProcedimientos(config.ConnectionString); FrmProcedimientos form = new FrmProcedimientos(config.ConnectionString);
FrmPrincipal.AddForm(form); FrmPrincipal.AddForm(form);
@@ -325,5 +294,10 @@ namespace ServerExplorer.UI
{ {
} }
private void btnRefresh_Click(object sender, EventArgs e)
{
Initialize();
}
} }
} }

View File

@@ -29,6 +29,7 @@
private void InitializeComponent() private void InitializeComponent()
{ {
this.dgvDatos = new System.Windows.Forms.DataGridView(); this.dgvDatos = new System.Windows.Forms.DataGridView();
this.btnRefresh = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.dgvDatos)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.dgvDatos)).BeginInit();
this.SuspendLayout(); this.SuspendLayout();
// //
@@ -41,19 +42,31 @@
| System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right))); | System.Windows.Forms.AnchorStyles.Right)));
this.dgvDatos.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; this.dgvDatos.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dgvDatos.Location = new System.Drawing.Point(12, 12); this.dgvDatos.Location = new System.Drawing.Point(12, 18);
this.dgvDatos.Name = "dgvDatos"; this.dgvDatos.Name = "dgvDatos";
this.dgvDatos.ReadOnly = true; this.dgvDatos.ReadOnly = true;
this.dgvDatos.Size = new System.Drawing.Size(347, 308); this.dgvDatos.Size = new System.Drawing.Size(347, 273);
this.dgvDatos.TabIndex = 0; this.dgvDatos.TabIndex = 0;
this.dgvDatos.CellDoubleClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.dgvDatos_CellDoubleClick); this.dgvDatos.CellDoubleClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.dgvDatos_CellDoubleClick);
this.dgvDatos.CellFormatting += new System.Windows.Forms.DataGridViewCellFormattingEventHandler(this.dgvDatos_CellFormatting); this.dgvDatos.CellFormatting += new System.Windows.Forms.DataGridViewCellFormattingEventHandler(this.dgvDatos_CellFormatting);
// //
// btnRefresh
//
this.btnRefresh.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.btnRefresh.Location = new System.Drawing.Point(12, 297);
this.btnRefresh.Name = "btnRefresh";
this.btnRefresh.Size = new System.Drawing.Size(75, 23);
this.btnRefresh.TabIndex = 1;
this.btnRefresh.Text = "Refresh";
this.btnRefresh.UseVisualStyleBackColor = true;
this.btnRefresh.Click += new System.EventHandler(this.btnRefresh_Click);
//
// FrmDatos // FrmDatos
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(371, 332); this.ClientSize = new System.Drawing.Size(371, 332);
this.Controls.Add(this.btnRefresh);
this.Controls.Add(this.dgvDatos); this.Controls.Add(this.dgvDatos);
this.Name = "FrmDatos"; this.Name = "FrmDatos";
this.Text = "frmDatos"; this.Text = "frmDatos";
@@ -66,5 +79,6 @@
#endregion #endregion
private System.Windows.Forms.DataGridView dgvDatos; private System.Windows.Forms.DataGridView dgvDatos;
private System.Windows.Forms.Button btnRefresh;
} }
} }

View File

@@ -6,19 +6,28 @@ using System.Drawing;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Windows.Forms; using System.Windows.Forms;
using ServerExplorer.Code;
using System.Data.SqlClient;
namespace ServerExplorer.UI namespace ServerExplorer.UI
{ {
public partial class FrmDatos : Form public partial class FrmDatos : Form
{ {
#region Declarations
private TablaDesc tablaDesc = null;
private string conexionString = string.Empty;
#endregion
#region Form life cycle #region Form life cycle
public FrmDatos(DataTable dt, String titulo) public FrmDatos(TablaDesc tablaDesc, string conexionString)
{ {
InitializeComponent(); InitializeComponent();
this.tablaDesc = tablaDesc;
Text = titulo; this.conexionString = conexionString;
dgvDatos.DataSource = dt; LoadDataFromTable();
} }
private void frmDatos_Load(object sender, EventArgs e) { } private void frmDatos_Load(object sender, EventArgs e) { }
@@ -40,6 +49,28 @@ namespace ServerExplorer.UI
} }
} }
private void btnRefresh_Click(object sender, EventArgs e)
{
LoadDataFromTable();
}
#endregion
#region Private methods
private void LoadDataFromTable()
{
Text = tablaDesc.Esquema + "." + tablaDesc.Nombre;
string tableFullName = "[" + tablaDesc.Esquema + "].[" + tablaDesc.Nombre + "]";
DataTable dt= new DataTable();
SqlConnection cnx = new SqlConnection(conexionString);
SqlDataAdapter da = new SqlDataAdapter( "select * from " + tableFullName, cnx);
cnx.Open();
da.Fill(dt);
cnx.Close();
dgvDatos.DataSource = dt;
}
#endregion #endregion
} }
} }

View File

@@ -35,6 +35,7 @@
this.colTipo = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.colTipo = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.txtProc = new ServerExplorer.Controls.CustomTextBox(); this.txtProc = new ServerExplorer.Controls.CustomTextBox();
this.splitContainer1 = new System.Windows.Forms.SplitContainer(); this.splitContainer1 = new System.Windows.Forms.SplitContainer();
this.btnRefresh = new System.Windows.Forms.Button();
this.splitContainer1.Panel1.SuspendLayout(); this.splitContainer1.Panel1.SuspendLayout();
this.splitContainer1.Panel2.SuspendLayout(); this.splitContainer1.Panel2.SuspendLayout();
this.splitContainer1.SuspendLayout(); this.splitContainer1.SuspendLayout();
@@ -57,7 +58,7 @@
this.lsvProcs.GridLines = true; this.lsvProcs.GridLines = true;
this.lsvProcs.Location = new System.Drawing.Point(0, 0); this.lsvProcs.Location = new System.Drawing.Point(0, 0);
this.lsvProcs.Name = "lsvProcs"; this.lsvProcs.Name = "lsvProcs";
this.lsvProcs.Size = new System.Drawing.Size(352, 478); this.lsvProcs.Size = new System.Drawing.Size(352, 449);
this.lsvProcs.TabIndex = 0; this.lsvProcs.TabIndex = 0;
this.lsvProcs.UseCompatibleStateImageBehavior = false; this.lsvProcs.UseCompatibleStateImageBehavior = false;
this.lsvProcs.View = System.Windows.Forms.View.Details; this.lsvProcs.View = System.Windows.Forms.View.Details;
@@ -107,6 +108,7 @@
// //
// splitContainer1.Panel1 // splitContainer1.Panel1
// //
this.splitContainer1.Panel1.Controls.Add(this.btnRefresh);
this.splitContainer1.Panel1.Controls.Add(this.lsvProcs); this.splitContainer1.Panel1.Controls.Add(this.lsvProcs);
// //
// splitContainer1.Panel2 // splitContainer1.Panel2
@@ -116,6 +118,17 @@
this.splitContainer1.SplitterDistance = 355; this.splitContainer1.SplitterDistance = 355;
this.splitContainer1.TabIndex = 2; this.splitContainer1.TabIndex = 2;
// //
// btnRefresh
//
this.btnRefresh.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.btnRefresh.Location = new System.Drawing.Point(3, 455);
this.btnRefresh.Name = "btnRefresh";
this.btnRefresh.Size = new System.Drawing.Size(75, 23);
this.btnRefresh.TabIndex = 1;
this.btnRefresh.Text = "Refresh";
this.btnRefresh.UseVisualStyleBackColor = true;
this.btnRefresh.Click += new System.EventHandler(this.btnRefresh_Click);
//
// FrmProcedimientos // FrmProcedimientos
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@@ -142,5 +155,6 @@
private System.Windows.Forms.SplitContainer splitContainer1; private System.Windows.Forms.SplitContainer splitContainer1;
private System.Windows.Forms.ColumnHeader colTipo; private System.Windows.Forms.ColumnHeader colTipo;
private System.Windows.Forms.ColumnHeader colSchema; private System.Windows.Forms.ColumnHeader colSchema;
private System.Windows.Forms.Button btnRefresh;
} }
} }

View File

@@ -14,26 +14,56 @@ namespace ServerExplorer.UI
{ {
public partial class FrmProcedimientos : Form public partial class FrmProcedimientos : Form
{ {
#region Declarations
private string cnxString; private string cnxString;
private SqlConnection cnx; private SqlConnection cnx;
#endregion
#region Form life cycle
public FrmProcedimientos(string cnxString) public FrmProcedimientos(string cnxString)
{ {
InitializeComponent(); InitializeComponent();
this.cnxString = cnxString; this.cnxString = cnxString;
cnx = new SqlConnection(cnxString);
} }
private void frmProcedimientos_Load(object sender, EventArgs e) private void frmProcedimientos_Load(object sender, EventArgs e)
{
LoadProcedures();
}
#endregion
#region Events
private void lsvProcs_SelectedIndexChanged(object sender, EventArgs e)
{
if (lsvProcs.SelectedItems.Count <= 0) { return; }
string schema, name;
name = lsvProcs.SelectedItems[0].SubItems[0].Text;
schema = lsvProcs.SelectedItems[0].SubItems[1].Text;
LoadProcedure(schema, name);
}
private void btnRefresh_Click(object sender, EventArgs e)
{
LoadProcedures();
}
#endregion
#region Private methods
private void LoadProcedures()
{ {
DataTable dt; DataTable dt;
SqlDataAdapter da; SqlDataAdapter da;
// Establecer conexion
cnx = new SqlConnection(cnxString);
// Obtener un datatable con todos los procedimientos de la base de datos. // Obtener un datatable con todos los procedimientos de la base de datos.
da = new SqlDataAdapter( da = new SqlDataAdapter(
"SELECT ROUTINE_NAME Name, ROUTINE_SCHEMA [Schema], CREATED CreateDate, ROUTINE_TYPE [Type] FROM INFORMATION_SCHEMA.ROUTINES", "SELECT ROUTINE_NAME Name, ROUTINE_SCHEMA [Schema], CREATED CreateDate, ROUTINE_TYPE [Type] FROM INFORMATION_SCHEMA.ROUTINES",
@@ -54,30 +84,26 @@ namespace ServerExplorer.UI
} }
} }
private void lsvProcs_SelectedIndexChanged(object sender, EventArgs e) private void LoadProcedure(string schema, string name)
{ {
if (lsvProcs.SelectedItems.Count > 0) DataTable dt;
{ SqlDataAdapter da;
DataTable dt; da = new SqlDataAdapter("SELECT ROUTINE_DEFINITION from INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_NAME=@Name AND ROUTINE_SCHEMA=@Schema", cnx);
SqlDataAdapter da; da.SelectCommand.Parameters.AddWithValue("@Name", name);
string Schema, Name; da.SelectCommand.Parameters.AddWithValue("@Schema", schema);
Name = lsvProcs.SelectedItems[0].SubItems[0].Text; dt = new DataTable();
Schema = lsvProcs.SelectedItems[0].SubItems[1].Text; cnx.Open();
da = new SqlDataAdapter("SELECT ROUTINE_DEFINITION from INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_NAME=@Name AND ROUTINE_SCHEMA=@Schema", cnx); da.Fill(dt);
da.SelectCommand.Parameters.AddWithValue("@Name", Name); cnx.Close();
da.SelectCommand.Parameters.AddWithValue("@Schema", Schema);
dt = new DataTable();
cnx.Open();
da.Fill(dt);
cnx.Close();
// Mostrar el contenido del procedimiento // Mostrar el contenido del procedimiento
txtProc.Text = String.Empty; txtProc.Text = String.Empty;
foreach (DataRow dr in dt.Rows) foreach (DataRow dr in dt.Rows)
{ {
txtProc.Text += ((string)dr[0]).Replace("\r", "").Replace("\n", "\r\n"); txtProc.Text += ((string)dr[0]).Replace("\r", "").Replace("\n", "\r\n");
}
} }
} }
#endregion
} }
} }