Limpieza usando recomendaciones de R#
This commit is contained in:
@@ -1,37 +1,29 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
using System.Data.Sql;
|
||||
using System.Data.SqlClient;
|
||||
using System.Xml.Serialization;
|
||||
using System.Threading;
|
||||
using ServerExplorer.Code;
|
||||
|
||||
namespace ServerExplorer.UI
|
||||
{
|
||||
public partial class FrmBaseDatos : Form
|
||||
{
|
||||
private FrmBaseDatos instancia;
|
||||
private SqlConnection cnx;
|
||||
private Config config;
|
||||
private String tableSchema = null;
|
||||
private String tableName = null;
|
||||
private SqlConnection _cnx;
|
||||
private Config _config;
|
||||
private String _tableSchema;
|
||||
private String _tableName;
|
||||
|
||||
private void Initialize()
|
||||
{
|
||||
// Establecer conexion
|
||||
txtConString.Text = config.ConnectionString;
|
||||
cnx = new SqlConnection(config.ConnectionString);
|
||||
txtConString.Text = _config.ConnectionString;
|
||||
_cnx = new SqlConnection(_config.ConnectionString);
|
||||
|
||||
// Obtener lista de tablas
|
||||
cnx.Open();
|
||||
DataTable dt = cnx.GetSchema("Tables");
|
||||
cnx.Close();
|
||||
_cnx.Open();
|
||||
DataTable dt = _cnx.GetSchema("Tables");
|
||||
_cnx.Close();
|
||||
|
||||
// Mostrar todas las tablas
|
||||
lsvTablas.Items.Clear();
|
||||
@@ -52,12 +44,12 @@ namespace ServerExplorer.UI
|
||||
/// </summary>
|
||||
private void TablesFromListView()
|
||||
{
|
||||
config.Tablas.Clear();
|
||||
_config.Tablas.Clear();
|
||||
foreach (ListViewItem item in lsvTablas.Items)
|
||||
{
|
||||
if (item.Checked)
|
||||
{
|
||||
config.Tablas.Add(new TablaInfo
|
||||
_config.Tablas.Add(new TablaInfo
|
||||
{
|
||||
Esquema = item.SubItems[1].Text,
|
||||
Nombre = item.SubItems[0].Text
|
||||
@@ -71,10 +63,10 @@ namespace ServerExplorer.UI
|
||||
/// </summary>
|
||||
private void TablesToListView()
|
||||
{
|
||||
int i, j, n;
|
||||
int j;
|
||||
|
||||
// Desmarcar todos en caso de no haber ninguna tabla
|
||||
if (config.Tablas.Count == 0)
|
||||
if (_config.Tablas.Count == 0)
|
||||
{
|
||||
foreach (ListViewItem item in lsvTablas.Items)
|
||||
item.Checked = false;
|
||||
@@ -82,20 +74,15 @@ namespace ServerExplorer.UI
|
||||
}
|
||||
|
||||
// Recorrer items marcando los que estan en la configuracion
|
||||
n = config.Tablas.Count;
|
||||
i = j = 0;
|
||||
int n = _config.Tablas.Count;
|
||||
int i = j = 0;
|
||||
foreach (ListViewItem item in lsvTablas.Items)
|
||||
{
|
||||
item.Checked = false;
|
||||
String tablename =
|
||||
item.SubItems[1].Text + // Esquema
|
||||
item.SubItems[0].Text; // Nombre tabla
|
||||
do
|
||||
{
|
||||
if (config.Tablas[i].Esquema.
|
||||
CompareTo(item.SubItems[1].Text) == 0 &&
|
||||
config.Tablas[i].Nombre.
|
||||
CompareTo(item.SubItems[0].Text) == 0)
|
||||
if (String.Compare(_config.Tablas[i].Esquema, item.SubItems[1].Text, StringComparison.Ordinal) == 0 &&
|
||||
String.Compare(_config.Tablas[i].Nombre, item.SubItems[0].Text, StringComparison.Ordinal) == 0)
|
||||
{
|
||||
item.Checked = true;
|
||||
break;
|
||||
@@ -109,31 +96,28 @@ namespace ServerExplorer.UI
|
||||
|
||||
public DatabaseDesc CrearDatabaseDesc()
|
||||
{
|
||||
DatabaseDesc db = new DatabaseDesc { Nombre = cnx.Database };
|
||||
foreach (TablaInfo t in config.Tablas)
|
||||
var db = new DatabaseDesc { Nombre = _cnx.Database };
|
||||
foreach (TablaInfo t in _config.Tablas)
|
||||
{
|
||||
TablaDesc td = new TablaDesc();
|
||||
td.FillDesc(t.Esquema, t.Nombre, cnx);
|
||||
var td = new TablaDesc();
|
||||
td.FillDesc(t.Esquema, t.Nombre, _cnx);
|
||||
db.Tablas.Add(td);
|
||||
}
|
||||
return (db);
|
||||
}
|
||||
|
||||
public FrmBaseDatos(String ConnectionString)
|
||||
public FrmBaseDatos(String connectionString)
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
instancia = this;
|
||||
config = new Config();
|
||||
config.ConnectionString = ConnectionString;
|
||||
_config = new Config {ConnectionString = connectionString};
|
||||
}
|
||||
|
||||
public FrmBaseDatos(Config config)
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
instancia = this;
|
||||
this.config = config;
|
||||
_config = config;
|
||||
}
|
||||
|
||||
|
||||
@@ -143,14 +127,14 @@ namespace ServerExplorer.UI
|
||||
Initialize();
|
||||
|
||||
// Establecer titulos
|
||||
lblTituloDB.Text = cnx.Database;
|
||||
lblTituloDB.Text = _cnx.Database;
|
||||
lblTituloTabla.Text = "";
|
||||
}
|
||||
|
||||
private void btnCopiarConString_Click(object sender, EventArgs e)
|
||||
{
|
||||
// Copiar la cadena de conexion al portapapeles
|
||||
System.Windows.Forms.Clipboard.SetText(txtConString.Text);
|
||||
Clipboard.SetText(txtConString.Text);
|
||||
}
|
||||
|
||||
private void lsvTablas_SelectedIndexChanged(object sender, EventArgs e)
|
||||
@@ -161,15 +145,15 @@ namespace ServerExplorer.UI
|
||||
ListViewItem item = lsvTablas.SelectedItems[0];
|
||||
|
||||
// Recordar tabla seleccionada
|
||||
tableSchema = item.SubItems[1].Text.ToString();
|
||||
tableName = item.SubItems[0].Text.ToString();
|
||||
_tableSchema = item.SubItems[1].Text;
|
||||
_tableName = item.SubItems[0].Text;
|
||||
|
||||
// Establecer titulo de la lista de columnas
|
||||
lblTituloTabla.Text = tableSchema + "." + tableName;
|
||||
lblTituloTabla.Text = _tableSchema + @"." + _tableName;
|
||||
|
||||
// Obtener descripcion de tabla
|
||||
TablaDesc td = new TablaDesc();
|
||||
td.FillDesc(tableSchema, tableName, cnx);
|
||||
var td = new TablaDesc();
|
||||
td.FillDesc(_tableSchema, _tableName, _cnx);
|
||||
|
||||
// Mostrar "columnas" de las tablas
|
||||
lsvColumnas.Items.Clear();
|
||||
@@ -185,21 +169,21 @@ namespace ServerExplorer.UI
|
||||
|
||||
private void menuCargar_Click(object sender, EventArgs e)
|
||||
{
|
||||
OpenFileDialog dialogo = new OpenFileDialog();
|
||||
var dialogo = new OpenFileDialog();
|
||||
if (dialogo.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
config = Config.Cargar(dialogo.FileName);
|
||||
_config = Config.Cargar(dialogo.FileName);
|
||||
Initialize();
|
||||
}
|
||||
}
|
||||
|
||||
private void menuGuardar_Click(object sender, EventArgs e)
|
||||
{
|
||||
SaveFileDialog dialogo = new SaveFileDialog();
|
||||
var dialogo = new SaveFileDialog();
|
||||
if (dialogo.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
TablesFromListView();
|
||||
config.Guardar(dialogo.FileName);
|
||||
_config.Guardar(dialogo.FileName);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -212,14 +196,14 @@ namespace ServerExplorer.UI
|
||||
|
||||
private void btnVerDatos_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (string.IsNullOrEmpty(tableSchema) || string.IsNullOrEmpty(tableName)) { return; }
|
||||
if (string.IsNullOrEmpty(_tableSchema) || string.IsNullOrEmpty(_tableName)) { return; }
|
||||
|
||||
// Obtener descripcion de tabla
|
||||
TablaDesc td = new TablaDesc();
|
||||
td.FillDesc(tableSchema, tableName, cnx);
|
||||
var td = new TablaDesc();
|
||||
td.FillDesc(_tableSchema, _tableName, _cnx);
|
||||
|
||||
// Crear y mostrar el formulario de los datos.
|
||||
FrmDatos form = new FrmDatos(td, config.ConnectionString);
|
||||
var form = new FrmDatos(td, _config.ConnectionString);
|
||||
FrmPrincipal.AddForm(form);
|
||||
}
|
||||
|
||||
@@ -227,14 +211,14 @@ namespace ServerExplorer.UI
|
||||
private void btnProcs_Click(object sender, EventArgs e)
|
||||
{
|
||||
// Crear y mostrar el formulario de los procedimientos.
|
||||
FrmProcedimientos form = new FrmProcedimientos(config.ConnectionString);
|
||||
var form = new FrmProcedimientos(_config.ConnectionString);
|
||||
FrmPrincipal.AddForm(form);
|
||||
}
|
||||
|
||||
private void btnExec_Click(object sender, EventArgs e)
|
||||
{
|
||||
// Crear y mostrar el formulario de exec.
|
||||
FrmExec form = new FrmExec(config.ConnectionString);
|
||||
var form = new FrmExec(_config.ConnectionString);
|
||||
FrmPrincipal.AddForm(form);
|
||||
}
|
||||
|
||||
@@ -249,8 +233,8 @@ namespace ServerExplorer.UI
|
||||
TablesFromListView();
|
||||
DatabaseDesc db = CrearDatabaseDesc();
|
||||
|
||||
XmlSerializer seriador = new XmlSerializer(typeof(DatabaseDesc));
|
||||
seriador.Serialize(System.Console.Out, db);
|
||||
var seriador = new XmlSerializer(typeof(DatabaseDesc));
|
||||
seriador.Serialize(Console.Out, db);
|
||||
|
||||
//CodeGen.GenerarCodigo(config, db);
|
||||
}
|
||||
@@ -258,7 +242,7 @@ namespace ServerExplorer.UI
|
||||
private void btnDocGen_Click(object sender, EventArgs e)
|
||||
{
|
||||
// Hacer insensible la ventana
|
||||
this.Parent.Enabled = false;
|
||||
Parent.Enabled = false;
|
||||
|
||||
// Obtener informacion.
|
||||
TablesFromListView();
|
||||
@@ -268,7 +252,7 @@ namespace ServerExplorer.UI
|
||||
DocGen.GenerarDocumentacion(db);
|
||||
|
||||
// Hace sensible la ventana
|
||||
this.Parent.Enabled = true;
|
||||
Parent.Enabled = true;
|
||||
|
||||
/*
|
||||
tablas_delistview();
|
||||
@@ -280,7 +264,7 @@ namespace ServerExplorer.UI
|
||||
public void GenerarDoc()
|
||||
{
|
||||
// Hacer insensible la ventana
|
||||
this.Enabled = false;
|
||||
Enabled = false;
|
||||
|
||||
// Obtener informacion.
|
||||
DatabaseDesc db = CrearDatabaseDesc();
|
||||
@@ -289,7 +273,7 @@ namespace ServerExplorer.UI
|
||||
DocGen.GenerarDocumentacion(db);
|
||||
|
||||
// Hace sensible la ventana
|
||||
this.Enabled = true;
|
||||
Enabled = true;
|
||||
}
|
||||
|
||||
private void splitContainer1_Panel1_Paint(object sender, PaintEventArgs e)
|
||||
|
||||
@@ -1,10 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
using ServerExplorer.Code;
|
||||
using System.Data.SqlClient;
|
||||
@@ -15,8 +11,8 @@ namespace ServerExplorer.UI
|
||||
{
|
||||
#region Declarations
|
||||
|
||||
private TablaDesc tablaDesc = null;
|
||||
private string conexionString = string.Empty;
|
||||
private readonly TablaDesc _tablaDesc;
|
||||
private readonly string _conexionString = string.Empty;
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -25,8 +21,8 @@ namespace ServerExplorer.UI
|
||||
public FrmDatos(TablaDesc tablaDesc, string conexionString)
|
||||
{
|
||||
InitializeComponent();
|
||||
this.tablaDesc = tablaDesc;
|
||||
this.conexionString = conexionString;
|
||||
_tablaDesc = tablaDesc;
|
||||
_conexionString = conexionString;
|
||||
LoadDataFromTable();
|
||||
}
|
||||
|
||||
@@ -60,11 +56,11 @@ namespace ServerExplorer.UI
|
||||
|
||||
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);
|
||||
Text = _tablaDesc.Esquema + @"." + _tablaDesc.Nombre;
|
||||
string tableFullName = "[" + _tablaDesc.Esquema + "].[" + _tablaDesc.Nombre + "]";
|
||||
var dt= new DataTable();
|
||||
var cnx = new SqlConnection(_conexionString);
|
||||
var da = new SqlDataAdapter( "select * from " + tableFullName, cnx);
|
||||
cnx.Open();
|
||||
da.Fill(dt);
|
||||
cnx.Close();
|
||||
|
||||
@@ -1,13 +1,9 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
using System.Data.SqlClient;
|
||||
using System.Drawing;
|
||||
using System.Globalization;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace ServerExplorer.UI
|
||||
{
|
||||
@@ -15,7 +11,7 @@ namespace ServerExplorer.UI
|
||||
{
|
||||
#region Declarations
|
||||
|
||||
private string cnxString;
|
||||
private readonly string _cnxString;
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -25,7 +21,7 @@ namespace ServerExplorer.UI
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
this.cnxString = cnxString;
|
||||
_cnxString = cnxString;
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -51,7 +47,7 @@ namespace ServerExplorer.UI
|
||||
{
|
||||
// Obtener el nombre de la tabla destino
|
||||
string destTable = Microsoft.VisualBasic.Interaction.InputBox("Nombre de la tabla destino", "tabla destino", String.Empty,
|
||||
this.Top + (this.Height / 2), this.Left + (this.Width / 2));
|
||||
Top + (Height / 2), Left + (Width / 2));
|
||||
|
||||
DataTable dt = GenerarInserts(destTable);
|
||||
dgvDatos.DataSource = dt;
|
||||
@@ -79,16 +75,12 @@ namespace ServerExplorer.UI
|
||||
|
||||
private DataTable Exec()
|
||||
{
|
||||
SqlConnection cnx;
|
||||
DataTable dt;
|
||||
SqlDataAdapter da;
|
||||
|
||||
// Establecer conexion
|
||||
cnx = new SqlConnection(cnxString);
|
||||
var cnx = new SqlConnection(_cnxString);
|
||||
|
||||
// Obtener resultado en un datatable.
|
||||
da = new SqlDataAdapter(txtCommand.Text, cnx);
|
||||
dt = new DataTable();
|
||||
var da = new SqlDataAdapter(txtCommand.Text, cnx);
|
||||
var dt = new DataTable();
|
||||
cnx.Open();
|
||||
da.Fill(dt);
|
||||
cnx.Close();
|
||||
@@ -98,14 +90,12 @@ namespace ServerExplorer.UI
|
||||
|
||||
private DataTable GenerarInserts(string destTable)
|
||||
{
|
||||
DataTable dataTable = new DataTable();
|
||||
DataTable destDataTable;
|
||||
NumberFormatInfo nfi = new NumberFormatInfo { NumberDecimalSeparator = "." };
|
||||
var nfi = new NumberFormatInfo { NumberDecimalSeparator = "." };
|
||||
|
||||
dataTable = Exec();
|
||||
DataTable dataTable = Exec();
|
||||
|
||||
// Preparar la datatable destino
|
||||
destDataTable = new DataTable();
|
||||
var destDataTable = new DataTable();
|
||||
destDataTable.Columns.Add("Comando", typeof(String));
|
||||
|
||||
// Recorrer la tabla de datos
|
||||
|
||||
@@ -1,10 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
using ServerExplorer.Code;
|
||||
using ServerExplorer.Controls;
|
||||
@@ -15,7 +10,7 @@ namespace ServerExplorer.UI
|
||||
{
|
||||
#region Declarations
|
||||
|
||||
private static FrmPrincipal currentInstance;
|
||||
private static FrmPrincipal _currentInstance;
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -23,7 +18,7 @@ namespace ServerExplorer.UI
|
||||
|
||||
public FrmPrincipal()
|
||||
{
|
||||
currentInstance = this;
|
||||
_currentInstance = this;
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
@@ -35,12 +30,12 @@ namespace ServerExplorer.UI
|
||||
|
||||
public static void AddForm(Form frm)
|
||||
{
|
||||
frm.MdiParent = currentInstance;
|
||||
frm.MdiParent = _currentInstance;
|
||||
frm.WindowState = FormWindowState.Maximized;
|
||||
frm.Show();
|
||||
currentInstance.listChilds.Add(frm);
|
||||
frm.FormClosed += currentInstance.FrmPrincipal_OnChildClose;
|
||||
currentInstance.RefreshWindowButtons();
|
||||
_currentInstance.listChilds.Add(frm);
|
||||
frm.FormClosed += _currentInstance.FrmPrincipal_OnChildClose;
|
||||
_currentInstance.RefreshWindowButtons();
|
||||
}
|
||||
|
||||
protected void FrmPrincipal_OnChildClose(object sender, FormClosedEventArgs e)
|
||||
@@ -90,7 +85,7 @@ namespace ServerExplorer.UI
|
||||
private void menuConectarPRUEBAS_Click(object sender, EventArgs e)
|
||||
{
|
||||
// Crear ventana de la base de datos de pruebas
|
||||
FrmBaseDatos frm = new FrmBaseDatos("Data Source=SSSRV3;Initial Catalog=PRUEBAS;User ID=sa;Password=SLsssrv3");
|
||||
var frm = new FrmBaseDatos("Data Source=SSSRV3;Initial Catalog=PRUEBAS;User ID=sa;Password=SLsssrv3");
|
||||
//frmBaseDatos frm = new frmBaseDatos("Data Source=DANTE;Initial Catalog=BD_AlfonsoRodriguez;Integrated Security=True");
|
||||
//frmBaseDatos frm = new frmBaseDatos("Data Source=OSKURITO;Initial Catalog=BD_AlfonsoRodriguez;Integrated Security=True");
|
||||
FrmPrincipal.AddForm(frm);
|
||||
@@ -99,22 +94,21 @@ namespace ServerExplorer.UI
|
||||
private void menuBuscarServidor_Click(object sender, EventArgs e)
|
||||
{
|
||||
// Mostrar ventana de buscador de servidores
|
||||
FrmServidores frm = new FrmServidores();
|
||||
var frm = new FrmServidores();
|
||||
FrmPrincipal.AddForm(frm);
|
||||
}
|
||||
|
||||
private void menuConectarA_Click(object sender, EventArgs e)
|
||||
{
|
||||
// Cargar configuracion
|
||||
OpenFileDialog dialogo = new OpenFileDialog();
|
||||
if (dialogo.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
Config config = Config.Cargar(dialogo.FileName);
|
||||
var dialogo = new OpenFileDialog();
|
||||
if (dialogo.ShowDialog() != DialogResult.OK) return;
|
||||
|
||||
// Crear y mostrar ventana
|
||||
FrmBaseDatos frm = new FrmBaseDatos(config);
|
||||
FrmPrincipal.AddForm(frm);
|
||||
}
|
||||
Config config = Config.Cargar(dialogo.FileName);
|
||||
|
||||
// Crear y mostrar ventana
|
||||
var frm = new FrmBaseDatos(config);
|
||||
FrmPrincipal.AddForm(frm);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace ServerExplorer.UI
|
||||
{
|
||||
#region Declarations
|
||||
|
||||
private SqlConnection cnx;
|
||||
private readonly SqlConnection _cnx;
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace ServerExplorer.UI
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
cnx = new SqlConnection(cnxString);
|
||||
_cnx = new SqlConnection(cnxString);
|
||||
}
|
||||
|
||||
private void frmProcedimientos_Load(object sender, EventArgs e)
|
||||
@@ -35,9 +35,8 @@ namespace ServerExplorer.UI
|
||||
{
|
||||
if (lsvProcs.SelectedItems.Count <= 0) { return; }
|
||||
|
||||
string schema, name;
|
||||
name = lsvProcs.SelectedItems[0].SubItems[0].Text;
|
||||
schema = lsvProcs.SelectedItems[0].SubItems[1].Text;
|
||||
string name = lsvProcs.SelectedItems[0].SubItems[0].Text;
|
||||
string schema = lsvProcs.SelectedItems[0].SubItems[1].Text;
|
||||
LoadProcedure(schema, name);
|
||||
}
|
||||
|
||||
@@ -52,17 +51,14 @@ namespace ServerExplorer.UI
|
||||
|
||||
private void LoadProcedures()
|
||||
{
|
||||
DataTable dt;
|
||||
SqlDataAdapter da;
|
||||
|
||||
// Obtener un datatable con todos los procedimientos de la base de datos.
|
||||
da = new SqlDataAdapter(
|
||||
var da = new SqlDataAdapter(
|
||||
"SELECT ROUTINE_NAME Name, ROUTINE_SCHEMA [Schema], CREATED CreateDate, ROUTINE_TYPE [Type] FROM INFORMATION_SCHEMA.ROUTINES",
|
||||
cnx);
|
||||
dt = new DataTable();
|
||||
cnx.Open();
|
||||
_cnx);
|
||||
var dt = new DataTable();
|
||||
_cnx.Open();
|
||||
da.Fill(dt);
|
||||
cnx.Close();
|
||||
_cnx.Close();
|
||||
|
||||
// Mostrar todos los procedimientos
|
||||
lsvProcs.Items.Clear();
|
||||
@@ -87,14 +83,14 @@ namespace ServerExplorer.UI
|
||||
(sp.type = N'P' OR sp.type = N'RF' OR sp.type='PC')
|
||||
and
|
||||
(sp.name=@name and SCHEMA_NAME(sp.schema_id)=@schema)
|
||||
", cnx);
|
||||
", _cnx);
|
||||
|
||||
da.SelectCommand.Parameters.AddWithValue("@Name", name);
|
||||
da.SelectCommand.Parameters.AddWithValue("@Schema", schema);
|
||||
var dt = new DataTable();
|
||||
cnx.Open();
|
||||
_cnx.Open();
|
||||
da.Fill(dt);
|
||||
cnx.Close();
|
||||
_cnx.Close();
|
||||
|
||||
// Mostrar el contenido del procedimiento
|
||||
txtProc.Text = String.Empty;
|
||||
|
||||
@@ -1,14 +1,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
using System.Data.Sql;
|
||||
using System.Data.SqlClient;
|
||||
using System.Data.SqlTypes;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace ServerExplorer.UI
|
||||
{
|
||||
@@ -32,28 +26,9 @@ namespace ServerExplorer.UI
|
||||
lsvBBDD.Items.Clear();
|
||||
foreach (DataRow dr in servidores.Rows)
|
||||
{
|
||||
// Nombre del servidor
|
||||
ListViewItem item = lsvServidores.Items.Add((String)dr["ServerName"]);
|
||||
|
||||
// Nombre de la instancia
|
||||
if (dr["InstanceName"] == System.DBNull.Value)
|
||||
{
|
||||
item.SubItems.Add("");
|
||||
}
|
||||
else
|
||||
{
|
||||
item.SubItems.Add((String)dr["InstanceName"]);
|
||||
}
|
||||
|
||||
// Numero de version
|
||||
if (dr["Version"] == System.DBNull.Value)
|
||||
{
|
||||
item.SubItems.Add("???");
|
||||
}
|
||||
else
|
||||
{
|
||||
item.SubItems.Add((String)dr["Version"]);
|
||||
}
|
||||
item.SubItems.Add((dr["InstanceName"] == DBNull.Value) ? string.Empty : (String)dr["InstanceName"]);
|
||||
item.SubItems.Add((dr["Version"] == DBNull.Value) ? "???" : (String) dr["Version"]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,41 +37,20 @@ namespace ServerExplorer.UI
|
||||
if (lsvServidores.SelectedItems.Count > 0)
|
||||
{
|
||||
ListViewItem item = lsvServidores.SelectedItems[0];
|
||||
if (item.SubItems[1].Text.CompareTo("") == 0)
|
||||
{
|
||||
// Servidor sin subinstancias
|
||||
txtServidor.Text = item.SubItems[0].Text;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Servidor con subinstancias
|
||||
txtServidor.Text = item.SubItems[0].Text + "/" + item.SubItems[1].Text;
|
||||
}
|
||||
txtServidor.Text = String.IsNullOrEmpty(item.SubItems[1].Text)
|
||||
? item.SubItems[0].Text
|
||||
: String.Format("{0}/{1}", item.SubItems[0].Text, item.SubItems[1].Text);
|
||||
}
|
||||
}
|
||||
|
||||
private void btnListarBBDD_Click(object sender, EventArgs e)
|
||||
{
|
||||
// Construir cadena de conexion
|
||||
SqlConnectionStringBuilder constructor = new SqlConnectionStringBuilder();
|
||||
constructor.DataSource = txtServidor.Text;
|
||||
if (String.IsNullOrEmpty(txtUsuario.Text))
|
||||
{
|
||||
constructor.IntegratedSecurity = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
constructor.UserID = txtUsuario.Text;
|
||||
constructor.Password = TxtContrasenha.Text;
|
||||
}
|
||||
|
||||
// Obtener todas las bases de datos
|
||||
SqlConnection cnx = new SqlConnection(constructor.ConnectionString);
|
||||
var cnx = new SqlConnection(BuildConnectionString());
|
||||
cnx.Open();
|
||||
DataTable dt = cnx.GetSchema("Databases");
|
||||
cnx.Close();
|
||||
|
||||
|
||||
// Mostrar bases de datos
|
||||
lsvBBDD.Items.Clear();
|
||||
foreach (DataRow dr in dt.Rows)
|
||||
@@ -109,26 +63,32 @@ namespace ServerExplorer.UI
|
||||
|
||||
private void lsvBBDD_DoubleClick(object sender, EventArgs e)
|
||||
{
|
||||
if (lsvBBDD.SelectedItems.Count == 1)
|
||||
{
|
||||
// Construir cadena de conexion final
|
||||
SqlConnectionStringBuilder constructor = new SqlConnectionStringBuilder();
|
||||
constructor.DataSource = (!string.IsNullOrEmpty(txtServidor.Text)) ? txtServidor.Text : "localhost";
|
||||
constructor.InitialCatalog = (String)lsvBBDD.SelectedItems[0].SubItems[0].Text;
|
||||
if (txtUsuario.Text.CompareTo("") == 0)
|
||||
{
|
||||
constructor.IntegratedSecurity = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
constructor.UserID = txtUsuario.Text;
|
||||
constructor.Password = TxtContrasenha.Text;
|
||||
}
|
||||
if (lsvBBDD.SelectedItems.Count != 1) return;
|
||||
|
||||
// Llamar a la venta de la base de datos
|
||||
FrmBaseDatos frm = new FrmBaseDatos(constructor.ConnectionString);
|
||||
FrmPrincipal.AddForm(frm);
|
||||
// Llamar a la venta de la base de datos
|
||||
var frm = new FrmBaseDatos(BuildConnectionString());
|
||||
FrmPrincipal.AddForm(frm);
|
||||
}
|
||||
|
||||
private string BuildConnectionString()
|
||||
{
|
||||
// Construir cadena de conexion
|
||||
var constructor = new SqlConnectionStringBuilder();
|
||||
constructor.DataSource = (!string.IsNullOrEmpty(txtServidor.Text)) ? txtServidor.Text : "localhost";
|
||||
if (lsvBBDD.SelectedItems.Count > 0)
|
||||
{
|
||||
constructor.InitialCatalog = lsvBBDD.SelectedItems[0].SubItems[0].Text;
|
||||
}
|
||||
if (String.IsNullOrEmpty(txtUsuario.Text))
|
||||
{
|
||||
constructor.IntegratedSecurity = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
constructor.UserID = txtUsuario.Text;
|
||||
constructor.Password = TxtContrasenha.Text;
|
||||
}
|
||||
return constructor.ConnectionString;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user