Usar un modo mas estándar para listar procedimientos

This commit is contained in:
2013-11-23 15:37:40 +01:00
parent ce7148acdc
commit c15a11a1db
2 changed files with 24 additions and 44 deletions

View File

@@ -30,6 +30,7 @@
{ {
this.lsvProcs = new ServerExplorer.Controls.CustomListView(); this.lsvProcs = new ServerExplorer.Controls.CustomListView();
this.colNombre = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.colNombre = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.colSchema = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.colFecha = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.colFecha = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
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 System.Windows.Forms.TextBox(); this.txtProc = new System.Windows.Forms.TextBox();
@@ -48,15 +49,15 @@
| System.Windows.Forms.AnchorStyles.Right))); | System.Windows.Forms.AnchorStyles.Right)));
this.lsvProcs.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] { this.lsvProcs.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
this.colNombre, this.colNombre,
this.colSchema,
this.colFecha, this.colFecha,
this.colTipo}); this.colTipo});
this.lsvProcs.Font = new System.Drawing.Font("Lucida Console", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.lsvProcs.Font = new System.Drawing.Font("Segoe UI", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.lsvProcs.FullRowSelect = true; this.lsvProcs.FullRowSelect = true;
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(261, 369); this.lsvProcs.Size = new System.Drawing.Size(352, 478);
this.lsvProcs.Sorting = System.Windows.Forms.SortOrder.Ascending;
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;
@@ -67,6 +68,10 @@
this.colNombre.Text = "Nombre"; this.colNombre.Text = "Nombre";
this.colNombre.Width = 120; this.colNombre.Width = 120;
// //
// colSchema
//
this.colSchema.Text = "Schema";
//
// colFecha // colFecha
// //
this.colFecha.Text = "Fecha"; this.colFecha.Text = "Fecha";
@@ -87,7 +92,7 @@
this.txtProc.Multiline = true; this.txtProc.Multiline = true;
this.txtProc.Name = "txtProc"; this.txtProc.Name = "txtProc";
this.txtProc.ScrollBars = System.Windows.Forms.ScrollBars.Both; this.txtProc.ScrollBars = System.Windows.Forms.ScrollBars.Both;
this.txtProc.Size = new System.Drawing.Size(309, 366); this.txtProc.Size = new System.Drawing.Size(352, 475);
this.txtProc.TabIndex = 1; this.txtProc.TabIndex = 1;
// //
// splitContainer1 // splitContainer1
@@ -106,15 +111,15 @@
// splitContainer1.Panel2 // splitContainer1.Panel2
// //
this.splitContainer1.Panel2.Controls.Add(this.txtProc); this.splitContainer1.Panel2.Controls.Add(this.txtProc);
this.splitContainer1.Size = new System.Drawing.Size(583, 372); this.splitContainer1.Size = new System.Drawing.Size(717, 481);
this.splitContainer1.SplitterDistance = 264; this.splitContainer1.SplitterDistance = 355;
this.splitContainer1.TabIndex = 2; this.splitContainer1.TabIndex = 2;
// //
// FrmProcedimientos // FrmProcedimientos
// //
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(607, 396); this.ClientSize = new System.Drawing.Size(741, 505);
this.Controls.Add(this.splitContainer1); this.Controls.Add(this.splitContainer1);
this.Name = "FrmProcedimientos"; this.Name = "FrmProcedimientos";
this.Text = "frmProcedimientos"; this.Text = "frmProcedimientos";
@@ -135,5 +140,6 @@
private System.Windows.Forms.TextBox txtProc; private System.Windows.Forms.TextBox txtProc;
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;
} }
} }

View File

@@ -36,9 +36,7 @@ namespace ServerExplorer.UI
// 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 id,name,crdate,type FROM sysobjects " + "SELECT ROUTINE_NAME Name, ROUTINE_SCHEMA [Schema], CREATED CreateDate, ROUTINE_TYPE [Type] FROM INFORMATION_SCHEMA.ROUTINES",
"WHERE (UPPER(type) = 'P' OR UPPER(type) = 'TF' OR UPPER(type) = 'TR' OR UPPER(type) = 'V') AND category = 0 " +
"ORDER BY name ",
cnx); cnx);
dt = new DataTable(); dt = new DataTable();
cnx.Open(); cnx.Open();
@@ -49,33 +47,11 @@ namespace ServerExplorer.UI
lsvProcs.Items.Clear(); lsvProcs.Items.Clear();
foreach (DataRow dr in dt.Rows) foreach (DataRow dr in dt.Rows)
{ {
ListViewItem item = lsvProcs.Items.Add((String)dr["name"]); ListViewItem item = lsvProcs.Items.Add((String)dr["Name"]);
item.SubItems.Add(((DateTime)dr["crdate"]).ToShortDateString()); item.SubItems.Add((string)dr["Schema"]);
string type = ((string)dr["type"]).ToUpper().Trim(); item.SubItems.Add(((DateTime)dr["CreateDate"]).ToShortDateString());
if (type == "P") item.SubItems.Add((string)dr["Type"]);
{
item.SubItems.Add("Proc");
}
else if (type == "TF")
{
item.SubItems.Add("Func");
}
else if (type == "TR")
{
item.SubItems.Add("Trigg");
}
else if (type == "V")
{
item.SubItems.Add("View");
}
else
{
item.SubItems.Add("Unk: \"" + (string)dr["type"] + "\"");
}
item.Tag = dr["id"];
} }
} }
private void lsvProcs_SelectedIndexChanged(object sender, EventArgs e) private void lsvProcs_SelectedIndexChanged(object sender, EventArgs e)
@@ -84,13 +60,12 @@ namespace ServerExplorer.UI
{ {
DataTable dt; DataTable dt;
SqlDataAdapter da; SqlDataAdapter da;
int id = (int)lsvProcs.SelectedItems[0].Tag; string Schema, Name;
Name = lsvProcs.SelectedItems[0].SubItems[0].Text;
// Obtener un datatable con el contenido del procedimiento. Schema = lsvProcs.SelectedItems[0].SubItems[1].Text;
da = new SqlDataAdapter( da = new SqlDataAdapter("SELECT ROUTINE_DEFINITION from INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_NAME=@Name AND ROUTINE_SCHEMA=@Schema", cnx);
"SELECT text FROM syscomments WHERE id = @id ORDER BY colid", da.SelectCommand.Parameters.AddWithValue("@Name", Name);
cnx); da.SelectCommand.Parameters.AddWithValue("@Schema", Schema);
da.SelectCommand.Parameters.AddWithValue("@id", id);
dt = new DataTable(); dt = new DataTable();
cnx.Open(); cnx.Open();
da.Fill(dt); da.Fill(dt);
@@ -102,7 +77,6 @@ namespace ServerExplorer.UI
{ {
txtProc.Text += ((string)dr[0]).Replace("\r", "").Replace("\n", "\r\n"); txtProc.Text += ((string)dr[0]).Replace("\r", "").Replace("\n", "\r\n");
} }
} }
} }
} }