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>
private void InitializeComponent()
{
this.txtConString = new ServerExplorer.Controls.CustomTextBox();
this.lblConString = new System.Windows.Forms.Label();
this.btnCopiarConString = new System.Windows.Forms.Button();
this.menuBaseDatos = new System.Windows.Forms.MenuStrip();
@@ -44,6 +43,7 @@
this.btnProcs = new System.Windows.Forms.Button();
this.btnExec = new System.Windows.Forms.Button();
this.splitContainer1 = new System.Windows.Forms.SplitContainer();
this.btnRefresh = new System.Windows.Forms.Button();
this.lsvTablas = new ServerExplorer.Controls.CustomListView();
this.colNombreTabla = ((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.colClave = ((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.splitContainer1.Panel1.SuspendLayout();
this.splitContainer1.Panel2.SuspendLayout();
this.splitContainer1.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
//
this.lblConString.AutoSize = true;
@@ -229,24 +219,36 @@
//
// splitContainer1.Panel1
//
this.splitContainer1.Panel1.Controls.Add(this.btnRefresh);
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.btnProcs);
this.splitContainer1.Panel1.Paint += new System.Windows.Forms.PaintEventHandler(this.splitContainer1_Panel1_Paint);
//
// splitContainer1.Panel2
//
this.splitContainer1.Panel2.Controls.Add(this.lblTituloTabla);
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.menuBaseDatos);
this.splitContainer1.Panel2.Controls.Add(this.btnGenerar);
this.splitContainer1.Panel2.Controls.Add(this.btnProcs);
this.splitContainer1.Panel2.Controls.Add(this.btnVerDatos);
this.splitContainer1.Size = new System.Drawing.Size(806, 511);
this.splitContainer1.SplitterDistance = 332;
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
//
this.lsvTablas.AllowSorting = true;
@@ -261,7 +263,7 @@
this.lsvTablas.FullRowSelect = true;
this.lsvTablas.Location = new System.Drawing.Point(3, 40);
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.TabIndex = 4;
this.lsvTablas.UseCompatibleStateImageBehavior = false;
@@ -325,6 +327,17 @@
//
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
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@@ -377,5 +390,6 @@
private System.Windows.Forms.Button btnExec;
private System.Windows.Forms.SplitContainer splitContainer1;
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)
{
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 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(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");
}
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)
{
String nombreTabla;
DataTable dt;
SqlDataAdapter da;
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();
// Obtener descripcion de tabla
TablaDesc td = new TablaDesc();
td.FillDesc(tableSchema, tableName, cnx);
// Crear y mostrar el formulario de los datos.
FrmDatos form = new FrmDatos(dt, nombreTabla);
FrmDatos form = new FrmDatos(td, config.ConnectionString);
FrmPrincipal.AddForm(form);
}
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.
FrmProcedimientos form = new FrmProcedimientos(config.ConnectionString);
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()
{
this.dgvDatos = new System.Windows.Forms.DataGridView();
this.btnRefresh = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.dgvDatos)).BeginInit();
this.SuspendLayout();
//
@@ -41,19 +42,31 @@
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
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.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.CellDoubleClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.dgvDatos_CellDoubleClick);
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
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(371, 332);
this.Controls.Add(this.btnRefresh);
this.Controls.Add(this.dgvDatos);
this.Name = "FrmDatos";
this.Text = "frmDatos";
@@ -66,5 +79,6 @@
#endregion
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.Text;
using System.Windows.Forms;
using ServerExplorer.Code;
using System.Data.SqlClient;
namespace ServerExplorer.UI
{
public partial class FrmDatos : Form
{
#region Declarations
private TablaDesc tablaDesc = null;
private string conexionString = string.Empty;
#endregion
#region Form life cycle
public FrmDatos(DataTable dt, String titulo)
public FrmDatos(TablaDesc tablaDesc, string conexionString)
{
InitializeComponent();
Text = titulo;
dgvDatos.DataSource = dt;
this.tablaDesc = tablaDesc;
this.conexionString = conexionString;
LoadDataFromTable();
}
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
}
}

View File

@@ -35,6 +35,7 @@
this.colTipo = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.txtProc = new ServerExplorer.Controls.CustomTextBox();
this.splitContainer1 = new System.Windows.Forms.SplitContainer();
this.btnRefresh = new System.Windows.Forms.Button();
this.splitContainer1.Panel1.SuspendLayout();
this.splitContainer1.Panel2.SuspendLayout();
this.splitContainer1.SuspendLayout();
@@ -57,7 +58,7 @@
this.lsvProcs.GridLines = true;
this.lsvProcs.Location = new System.Drawing.Point(0, 0);
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.UseCompatibleStateImageBehavior = false;
this.lsvProcs.View = System.Windows.Forms.View.Details;
@@ -107,6 +108,7 @@
//
// splitContainer1.Panel1
//
this.splitContainer1.Panel1.Controls.Add(this.btnRefresh);
this.splitContainer1.Panel1.Controls.Add(this.lsvProcs);
//
// splitContainer1.Panel2
@@ -116,6 +118,17 @@
this.splitContainer1.SplitterDistance = 355;
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
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@@ -142,5 +155,6 @@
private System.Windows.Forms.SplitContainer splitContainer1;
private System.Windows.Forms.ColumnHeader colTipo;
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
{
#region Declarations
private string cnxString;
private SqlConnection cnx;
#endregion
#region Form life cycle
public FrmProcedimientos(string cnxString)
{
InitializeComponent();
this.cnxString = cnxString;
cnx = new SqlConnection(cnxString);
}
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;
SqlDataAdapter da;
// Establecer conexion
cnx = new SqlConnection(cnxString);
// Obtener un datatable con todos los procedimientos de la base de datos.
da = new SqlDataAdapter(
"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;
string Schema, Name;
Name = lsvProcs.SelectedItems[0].SubItems[0].Text;
Schema = lsvProcs.SelectedItems[0].SubItems[1].Text;
da = new SqlDataAdapter("SELECT ROUTINE_DEFINITION from INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_NAME=@Name AND ROUTINE_SCHEMA=@Schema", cnx);
da.SelectCommand.Parameters.AddWithValue("@Name", Name);
da.SelectCommand.Parameters.AddWithValue("@Schema", Schema);
dt = new DataTable();
cnx.Open();
da.Fill(dt);
cnx.Close();
DataTable dt;
SqlDataAdapter da;
da = new SqlDataAdapter("SELECT ROUTINE_DEFINITION from INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_NAME=@Name AND ROUTINE_SCHEMA=@Schema", cnx);
da.SelectCommand.Parameters.AddWithValue("@Name", name);
da.SelectCommand.Parameters.AddWithValue("@Schema", schema);
dt = new DataTable();
cnx.Open();
da.Fill(dt);
cnx.Close();
// Mostrar el contenido del procedimiento
txtProc.Text = String.Empty;
foreach (DataRow dr in dt.Rows)
{
txtProc.Text += ((string)dr[0]).Replace("\r", "").Replace("\n", "\r\n");
}
// Mostrar el contenido del procedimiento
txtProc.Text = String.Empty;
foreach (DataRow dr in dt.Rows)
{
txtProc.Text += ((string)dr[0]).Replace("\r", "").Replace("\n", "\r\n");
}
}
#endregion
}
}