Limpieza usando recomendaciones de R#
This commit is contained in:
@@ -10,17 +10,17 @@ namespace ServerExplorer.Code
|
|||||||
{
|
{
|
||||||
#region Data parameters
|
#region Data parameters
|
||||||
|
|
||||||
private string conString = "";
|
private string _conString = "";
|
||||||
[XmlAttribute("ConnectionString")]
|
[XmlAttribute("ConnectionString")]
|
||||||
public string ConnectionString
|
public string ConnectionString
|
||||||
{
|
{
|
||||||
get { return conString; }
|
get { return _conString; }
|
||||||
set { conString = value; }
|
set { _conString = value; }
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<TablaInfo> tablas = new List<TablaInfo>();
|
private readonly List<TablaInfo> _tablas = new List<TablaInfo>();
|
||||||
[XmlArray("Tablas")]
|
[XmlArray("Tablas")]
|
||||||
public List<TablaInfo> Tablas { get { return tablas; } }
|
public List<TablaInfo> Tablas { get { return _tablas; } }
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@@ -28,17 +28,17 @@ namespace ServerExplorer.Code
|
|||||||
|
|
||||||
public void Guardar(String fichero)
|
public void Guardar(String fichero)
|
||||||
{
|
{
|
||||||
XmlSerializer seriador = new XmlSerializer(typeof(Config));
|
var seriador = new XmlSerializer(typeof(Config));
|
||||||
StreamWriter escritor = new StreamWriter(fichero);
|
var escritor = new StreamWriter(fichero);
|
||||||
seriador.Serialize(escritor, this);
|
seriador.Serialize(escritor, this);
|
||||||
escritor.Close();
|
escritor.Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Config Cargar(String fichero)
|
public static Config Cargar(String fichero)
|
||||||
{
|
{
|
||||||
XmlSerializer seriador = new XmlSerializer(typeof(Config));
|
var seriador = new XmlSerializer(typeof(Config));
|
||||||
StreamReader lector = new StreamReader(fichero);
|
var lector = new StreamReader(fichero);
|
||||||
Config config = (Config)seriador.Deserialize(lector);
|
var config = (Config)seriador.Deserialize(lector);
|
||||||
lector.Close();
|
lector.Close();
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
@@ -49,20 +49,20 @@ namespace ServerExplorer.Code
|
|||||||
[Serializable]
|
[Serializable]
|
||||||
public class TablaInfo
|
public class TablaInfo
|
||||||
{
|
{
|
||||||
private string esquema = string.Empty;
|
private string _esquema = string.Empty;
|
||||||
[XmlAttribute("Esquema")]
|
[XmlAttribute("Esquema")]
|
||||||
public string Esquema
|
public string Esquema
|
||||||
{
|
{
|
||||||
get { return esquema; }
|
get { return _esquema; }
|
||||||
set { esquema = value; }
|
set { _esquema = value; }
|
||||||
}
|
}
|
||||||
|
|
||||||
private string nombre = string.Empty;
|
private string _nombre = string.Empty;
|
||||||
[XmlAttribute("Nombre")]
|
[XmlAttribute("Nombre")]
|
||||||
public string Nombre
|
public string Nombre
|
||||||
{
|
{
|
||||||
get { return nombre; }
|
get { return _nombre; }
|
||||||
set { nombre = value; }
|
set { _nombre = value; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Xml.Serialization;
|
using System.Xml.Serialization;
|
||||||
|
|
||||||
namespace ServerExplorer.Code
|
namespace ServerExplorer.Code
|
||||||
@@ -9,16 +7,16 @@ namespace ServerExplorer.Code
|
|||||||
[Serializable]
|
[Serializable]
|
||||||
public class DatabaseDesc
|
public class DatabaseDesc
|
||||||
{
|
{
|
||||||
private string nombre = string.Empty;
|
private string _nombre = string.Empty;
|
||||||
[XmlAttribute("Nombre")]
|
[XmlAttribute("Nombre")]
|
||||||
public string Nombre
|
public string Nombre
|
||||||
{
|
{
|
||||||
get { return nombre; }
|
get { return _nombre; }
|
||||||
set { nombre = value; }
|
set { _nombre = value; }
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<TablaDesc> tablas = new List<TablaDesc>();
|
private readonly List<TablaDesc> _tablas = new List<TablaDesc>();
|
||||||
[XmlArray("Tablas")]
|
[XmlArray("Tablas")]
|
||||||
public List<TablaDesc> Tablas { get { return tablas; } }
|
public List<TablaDesc> Tablas { get { return _tablas; } }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,4 @@
|
|||||||
using System;
|
using System.IO;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.IO;
|
|
||||||
using ServerExplorer.Code;
|
|
||||||
|
|
||||||
namespace ServerExplorer.Code
|
namespace ServerExplorer.Code
|
||||||
{
|
{
|
||||||
@@ -13,7 +8,7 @@ namespace ServerExplorer.Code
|
|||||||
{
|
{
|
||||||
// Abrir el documento que contendra la documentacion
|
// Abrir el documento que contendra la documentacion
|
||||||
string fixedDatabaseName = database.Nombre.Replace(' ', '_');
|
string fixedDatabaseName = database.Nombre.Replace(' ', '_');
|
||||||
StreamWriter escritor = new StreamWriter(fixedDatabaseName + ".documentacion.html");
|
var escritor = new StreamWriter(fixedDatabaseName + ".documentacion.html");
|
||||||
|
|
||||||
// Poner cabecera de la documentacion
|
// Poner cabecera de la documentacion
|
||||||
escritor.WriteLine("<!DOCTYPE html>");
|
escritor.WriteLine("<!DOCTYPE html>");
|
||||||
|
|||||||
@@ -1,9 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Data;
|
using System.Data;
|
||||||
using System.Data.Sql;
|
|
||||||
using System.Data.SqlClient;
|
using System.Data.SqlClient;
|
||||||
using System.Xml.Serialization;
|
using System.Xml.Serialization;
|
||||||
|
|
||||||
@@ -14,25 +11,31 @@ namespace ServerExplorer.Code
|
|||||||
{
|
{
|
||||||
#region Data parameters
|
#region Data parameters
|
||||||
|
|
||||||
private String esquema = String.Empty;
|
private String _esquema = String.Empty;
|
||||||
|
|
||||||
[XmlAttribute("Esquema")]
|
[XmlAttribute("Esquema")]
|
||||||
public string Esquema
|
public string Esquema
|
||||||
{
|
{
|
||||||
get { return esquema; }
|
get { return _esquema; }
|
||||||
set { esquema = value; }
|
set { _esquema = value; }
|
||||||
}
|
}
|
||||||
|
|
||||||
private String nombre = String.Empty;
|
private String _nombre = String.Empty;
|
||||||
|
|
||||||
[XmlAttribute("Nombre")]
|
[XmlAttribute("Nombre")]
|
||||||
public string Nombre
|
public string Nombre
|
||||||
{
|
{
|
||||||
get { return nombre; }
|
get { return _nombre; }
|
||||||
set { nombre = value; }
|
set { _nombre = value; }
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<ColumnaDesc> columnas = new List<ColumnaDesc>();
|
private readonly List<ColumnaDesc> _columnas = new List<ColumnaDesc>();
|
||||||
|
|
||||||
[XmlArray("Columnas")]
|
[XmlArray("Columnas")]
|
||||||
public List<ColumnaDesc> Columnas { get { return columnas; } }
|
public List<ColumnaDesc> Columnas
|
||||||
|
{
|
||||||
|
get { return _columnas; }
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@@ -43,7 +46,7 @@ namespace ServerExplorer.Code
|
|||||||
{
|
{
|
||||||
foreach (ColumnaDesc col in Columnas)
|
foreach (ColumnaDesc col in Columnas)
|
||||||
{
|
{
|
||||||
if (col.Nombre.CompareTo(nombre) == 0)
|
if (String.Compare(col.Nombre, nombre, StringComparison.Ordinal) == 0)
|
||||||
{
|
{
|
||||||
return (col);
|
return (col);
|
||||||
}
|
}
|
||||||
@@ -53,41 +56,35 @@ namespace ServerExplorer.Code
|
|||||||
|
|
||||||
public void FillDesc(String esquema, String nombre, SqlConnection cnx)
|
public void FillDesc(String esquema, String nombre, SqlConnection cnx)
|
||||||
{
|
{
|
||||||
SqlParameter prm;
|
|
||||||
DataTable dt;
|
|
||||||
SqlDataAdapter da;
|
|
||||||
|
|
||||||
// establecer esquema y nombre
|
// establecer esquema y nombre
|
||||||
Esquema = esquema;
|
Esquema = esquema;
|
||||||
Nombre = nombre;
|
Nombre = nombre;
|
||||||
|
|
||||||
// Preparar comando y parametros
|
// Preparar comando y parametros
|
||||||
da = new SqlDataAdapter(
|
var da = new SqlDataAdapter(@"
|
||||||
"SELECT col.COLUMN_NAME AS Columna, " +
|
SELECT col.COLUMN_NAME AS Columna,
|
||||||
" col.DATA_TYPE AS Tipo, " +
|
col.DATA_TYPE AS Tipo,
|
||||||
" col.CHARACTER_MAXIMUM_LENGTH AS Tamanho, " +
|
col.CHARACTER_MAXIMUM_LENGTH AS Tamanho,
|
||||||
" c.CONSTRAINT_TYPE AS TipoClave, " +
|
c.CONSTRAINT_TYPE AS TipoClave,
|
||||||
" col.IS_NULLABLE AS Nullable " +
|
col.IS_NULLABLE AS Nullable
|
||||||
" FROM INFORMATION_SCHEMA.COLUMNS AS col " +
|
FROM INFORMATION_SCHEMA.COLUMNS AS col
|
||||||
" LEFT JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE AS k " +
|
LEFT JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE AS k
|
||||||
" ON col.COLUMN_NAME=k.COLUMN_NAME AND " +
|
ON col.COLUMN_NAME=k.COLUMN_NAME AND
|
||||||
" col.TABLE_NAME=k.TABLE_NAME AND " +
|
col.TABLE_NAME=k.TABLE_NAME AND
|
||||||
" col.TABLE_SCHEMA=k.TABLE_SCHEMA " +
|
col.TABLE_SCHEMA=k.TABLE_SCHEMA
|
||||||
" LEFT JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS AS c " +
|
LEFT JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS AS c
|
||||||
" ON k.CONSTRAINT_NAME=c.CONSTRAINT_NAME " +
|
ON k.CONSTRAINT_NAME=c.CONSTRAINT_NAME
|
||||||
" WHERE col.TABLE_NAME=@nombreTabla AND " +
|
WHERE col.TABLE_NAME=@nombreTabla AND
|
||||||
" col.TABLE_SCHEMA=@nombreEsquema " +
|
col.TABLE_SCHEMA=@nombreEsquema
|
||||||
" ORDER BY col.ORDINAL_POSITION",
|
ORDER BY col.ORDINAL_POSITION
|
||||||
cnx);
|
", cnx);
|
||||||
prm = new SqlParameter("@nombreTabla", SqlDbType.VarChar, 100);
|
var prm = new SqlParameter("@nombreTabla", SqlDbType.VarChar, 100) {Value = nombre};
|
||||||
prm.Value = nombre;
|
|
||||||
da.SelectCommand.Parameters.Add(prm);
|
da.SelectCommand.Parameters.Add(prm);
|
||||||
prm = new SqlParameter("@nombreEsquema", SqlDbType.VarChar, 100);
|
prm = new SqlParameter("@nombreEsquema", SqlDbType.VarChar, 100) {Value = esquema};
|
||||||
prm.Value = esquema;
|
|
||||||
da.SelectCommand.Parameters.Add(prm);
|
da.SelectCommand.Parameters.Add(prm);
|
||||||
|
|
||||||
// Obtener datatable con las columnas
|
// Obtener datatable con las columnas
|
||||||
dt = new DataTable();
|
var dt = new DataTable();
|
||||||
cnx.Open();
|
cnx.Open();
|
||||||
da.Fill(dt);
|
da.Fill(dt);
|
||||||
cnx.Close();
|
cnx.Close();
|
||||||
@@ -96,10 +93,8 @@ namespace ServerExplorer.Code
|
|||||||
Columnas.Clear();
|
Columnas.Clear();
|
||||||
foreach (DataRow dr in dt.Rows)
|
foreach (DataRow dr in dt.Rows)
|
||||||
{
|
{
|
||||||
ColumnaDesc col;
|
|
||||||
|
|
||||||
// Obtener columna
|
// Obtener columna
|
||||||
col = GetCol((String)dr["Columna"]);
|
ColumnaDesc col = GetCol((String) dr["Columna"]);
|
||||||
if (col == null)
|
if (col == null)
|
||||||
{
|
{
|
||||||
col = new ColumnaDesc();
|
col = new ColumnaDesc();
|
||||||
@@ -107,20 +102,20 @@ namespace ServerExplorer.Code
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Establecer datos de la columna
|
// Establecer datos de la columna
|
||||||
col.Nombre = (String)dr["Columna"];
|
col.Nombre = (String) dr["Columna"];
|
||||||
col.Tipo = ((String)dr["Tipo"]).ToLower();
|
col.Tipo = ((String) dr["Tipo"]).ToLower();
|
||||||
if (dr["Tamanho"] != DBNull.Value)
|
if (dr["Tamanho"] != DBNull.Value)
|
||||||
{
|
{
|
||||||
col.Tamanho = (int)dr["Tamanho"];
|
col.Tamanho = (int) dr["Tamanho"];
|
||||||
}
|
}
|
||||||
if (dr["TipoClave"] != DBNull.Value)
|
if (dr["TipoClave"] != DBNull.Value)
|
||||||
{
|
{
|
||||||
if (((String)dr["TipoClave"]).Contains("PRIMARY"))
|
if (((String) dr["TipoClave"]).Contains("PRIMARY"))
|
||||||
{
|
{
|
||||||
col.Primaria = true;
|
col.Primaria = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
string strNullable=((String)dr["Nullable"]).ToLower();
|
string strNullable = ((String) dr["Nullable"]).ToLower();
|
||||||
col.Nullable = (strNullable == "yes");
|
col.Nullable = (strNullable == "yes");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -149,58 +144,64 @@ namespace ServerExplorer.Code
|
|||||||
{
|
{
|
||||||
#region Data properties
|
#region Data properties
|
||||||
|
|
||||||
private string nombre = String.Empty;
|
private string _nombre = String.Empty;
|
||||||
|
|
||||||
[XmlAttribute("Nombre")]
|
[XmlAttribute("Nombre")]
|
||||||
public string Nombre
|
public string Nombre
|
||||||
{
|
{
|
||||||
get { return nombre; }
|
get { return _nombre; }
|
||||||
set { nombre = value; }
|
set { _nombre = value; }
|
||||||
}
|
}
|
||||||
|
|
||||||
private string tipo = String.Empty;
|
private string _tipo = String.Empty;
|
||||||
|
|
||||||
[XmlAttribute("Tipo")]
|
[XmlAttribute("Tipo")]
|
||||||
public string Tipo
|
public string Tipo
|
||||||
{
|
{
|
||||||
get { return tipo; }
|
get { return _tipo; }
|
||||||
set { tipo = value; }
|
set { _tipo = value; }
|
||||||
}
|
}
|
||||||
|
|
||||||
private int tamanho = -1;
|
private int _tamanho = -1;
|
||||||
|
|
||||||
[XmlAttribute("Tamanho")]
|
[XmlAttribute("Tamanho")]
|
||||||
public int Tamanho
|
public int Tamanho
|
||||||
{
|
{
|
||||||
get { return tamanho; }
|
get { return _tamanho; }
|
||||||
set { tamanho = value; }
|
set { _tamanho = value; }
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool nullable = false;
|
private bool _nullable;
|
||||||
|
|
||||||
[XmlAttribute("Nullable")]
|
[XmlAttribute("Nullable")]
|
||||||
public bool Nullable
|
public bool Nullable
|
||||||
{
|
{
|
||||||
get { return nullable; }
|
get { return _nullable; }
|
||||||
set { nullable = value; }
|
set { _nullable = value; }
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool primaria = false;
|
private bool _primaria;
|
||||||
|
|
||||||
[XmlAttribute("Primaria")]
|
[XmlAttribute("Primaria")]
|
||||||
public bool Primaria
|
public bool Primaria
|
||||||
{
|
{
|
||||||
get { return primaria; }
|
get { return _primaria; }
|
||||||
set { primaria = value; }
|
set { _primaria = value; }
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region GetTipo
|
#region GetTipo
|
||||||
|
|
||||||
private TipoCol _tipo = TipoCol.Unset;
|
private TipoCol _tipoCol = TipoCol.Unset;
|
||||||
|
|
||||||
public TipoCol GetTipo()
|
public TipoCol GetTipo()
|
||||||
{
|
{
|
||||||
string strTipo = Tipo.ToLower();
|
string strTipo = Tipo.ToLower();
|
||||||
|
|
||||||
if (_tipo != TipoCol.Unset)
|
if (_tipoCol != TipoCol.Unset)
|
||||||
{
|
{
|
||||||
return _tipo;
|
return _tipoCol;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Numericos
|
// Numericos
|
||||||
@@ -212,7 +213,7 @@ namespace ServerExplorer.Code
|
|||||||
strTipo == "bigint"
|
strTipo == "bigint"
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
_tipo = TipoCol.Numerico;
|
_tipoCol = TipoCol.Numerico;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Aproximados numericos
|
// Aproximados numericos
|
||||||
@@ -221,7 +222,7 @@ namespace ServerExplorer.Code
|
|||||||
strTipo == "real"
|
strTipo == "real"
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
_tipo = TipoCol.AproxNumerico;
|
_tipoCol = TipoCol.AproxNumerico;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tiempo
|
// Tiempo
|
||||||
@@ -234,7 +235,7 @@ namespace ServerExplorer.Code
|
|||||||
strTipo == "time"
|
strTipo == "time"
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
_tipo = TipoCol.Tiempo;
|
_tipoCol = TipoCol.Tiempo;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Texto
|
// Texto
|
||||||
@@ -247,7 +248,7 @@ namespace ServerExplorer.Code
|
|||||||
strTipo == "ntext"
|
strTipo == "ntext"
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
_tipo = TipoCol.Texto;
|
_tipoCol = TipoCol.Texto;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Binario
|
// Binario
|
||||||
@@ -257,7 +258,7 @@ namespace ServerExplorer.Code
|
|||||||
strTipo == "image"
|
strTipo == "image"
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
_tipo = TipoCol.Binario;
|
_tipoCol = TipoCol.Binario;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Booleano
|
// Booleano
|
||||||
@@ -265,13 +266,13 @@ namespace ServerExplorer.Code
|
|||||||
strTipo == "bit"
|
strTipo == "bit"
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
_tipo = TipoCol.Booleano;
|
_tipoCol = TipoCol.Booleano;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Otro
|
// Otro
|
||||||
_tipo = TipoCol.Otro;
|
_tipoCol = TipoCol.Otro;
|
||||||
|
|
||||||
return _tipo;
|
return _tipoCol;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|||||||
@@ -1,7 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
|
||||||
namespace ServerExplorer.Code
|
namespace ServerExplorer.Code
|
||||||
@@ -10,7 +7,7 @@ namespace ServerExplorer.Code
|
|||||||
{
|
{
|
||||||
public static void CrearDirectorio(this String path)
|
public static void CrearDirectorio(this String path)
|
||||||
{
|
{
|
||||||
DirectoryInfo info = null;
|
DirectoryInfo info;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
info = new DirectoryInfo(path);
|
info = new DirectoryInfo(path);
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
using ServerExplorer.UI;
|
using ServerExplorer.UI;
|
||||||
|
|
||||||
|
|||||||
@@ -1,37 +1,29 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.ComponentModel;
|
|
||||||
using System.Data;
|
using System.Data;
|
||||||
using System.Drawing;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
using System.Data.Sql;
|
|
||||||
using System.Data.SqlClient;
|
using System.Data.SqlClient;
|
||||||
using System.Xml.Serialization;
|
using System.Xml.Serialization;
|
||||||
using System.Threading;
|
|
||||||
using ServerExplorer.Code;
|
using ServerExplorer.Code;
|
||||||
|
|
||||||
namespace ServerExplorer.UI
|
namespace ServerExplorer.UI
|
||||||
{
|
{
|
||||||
public partial class FrmBaseDatos : Form
|
public partial class FrmBaseDatos : Form
|
||||||
{
|
{
|
||||||
private FrmBaseDatos instancia;
|
private SqlConnection _cnx;
|
||||||
private SqlConnection cnx;
|
private Config _config;
|
||||||
private Config config;
|
private String _tableSchema;
|
||||||
private String tableSchema = null;
|
private String _tableName;
|
||||||
private String tableName = null;
|
|
||||||
|
|
||||||
private void Initialize()
|
private void Initialize()
|
||||||
{
|
{
|
||||||
// Establecer conexion
|
// Establecer conexion
|
||||||
txtConString.Text = config.ConnectionString;
|
txtConString.Text = _config.ConnectionString;
|
||||||
cnx = new SqlConnection(config.ConnectionString);
|
_cnx = new SqlConnection(_config.ConnectionString);
|
||||||
|
|
||||||
// Obtener lista de tablas
|
// Obtener lista de tablas
|
||||||
cnx.Open();
|
_cnx.Open();
|
||||||
DataTable dt = cnx.GetSchema("Tables");
|
DataTable dt = _cnx.GetSchema("Tables");
|
||||||
cnx.Close();
|
_cnx.Close();
|
||||||
|
|
||||||
// Mostrar todas las tablas
|
// Mostrar todas las tablas
|
||||||
lsvTablas.Items.Clear();
|
lsvTablas.Items.Clear();
|
||||||
@@ -52,12 +44,12 @@ namespace ServerExplorer.UI
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private void TablesFromListView()
|
private void TablesFromListView()
|
||||||
{
|
{
|
||||||
config.Tablas.Clear();
|
_config.Tablas.Clear();
|
||||||
foreach (ListViewItem item in lsvTablas.Items)
|
foreach (ListViewItem item in lsvTablas.Items)
|
||||||
{
|
{
|
||||||
if (item.Checked)
|
if (item.Checked)
|
||||||
{
|
{
|
||||||
config.Tablas.Add(new TablaInfo
|
_config.Tablas.Add(new TablaInfo
|
||||||
{
|
{
|
||||||
Esquema = item.SubItems[1].Text,
|
Esquema = item.SubItems[1].Text,
|
||||||
Nombre = item.SubItems[0].Text
|
Nombre = item.SubItems[0].Text
|
||||||
@@ -71,10 +63,10 @@ namespace ServerExplorer.UI
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private void TablesToListView()
|
private void TablesToListView()
|
||||||
{
|
{
|
||||||
int i, j, n;
|
int j;
|
||||||
|
|
||||||
// Desmarcar todos en caso de no haber ninguna tabla
|
// 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)
|
foreach (ListViewItem item in lsvTablas.Items)
|
||||||
item.Checked = false;
|
item.Checked = false;
|
||||||
@@ -82,20 +74,15 @@ namespace ServerExplorer.UI
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Recorrer items marcando los que estan en la configuracion
|
// Recorrer items marcando los que estan en la configuracion
|
||||||
n = config.Tablas.Count;
|
int n = _config.Tablas.Count;
|
||||||
i = j = 0;
|
int i = j = 0;
|
||||||
foreach (ListViewItem item in lsvTablas.Items)
|
foreach (ListViewItem item in lsvTablas.Items)
|
||||||
{
|
{
|
||||||
item.Checked = false;
|
item.Checked = false;
|
||||||
String tablename =
|
|
||||||
item.SubItems[1].Text + // Esquema
|
|
||||||
item.SubItems[0].Text; // Nombre tabla
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
if (config.Tablas[i].Esquema.
|
if (String.Compare(_config.Tablas[i].Esquema, item.SubItems[1].Text, StringComparison.Ordinal) == 0 &&
|
||||||
CompareTo(item.SubItems[1].Text) == 0 &&
|
String.Compare(_config.Tablas[i].Nombre, item.SubItems[0].Text, StringComparison.Ordinal) == 0)
|
||||||
config.Tablas[i].Nombre.
|
|
||||||
CompareTo(item.SubItems[0].Text) == 0)
|
|
||||||
{
|
{
|
||||||
item.Checked = true;
|
item.Checked = true;
|
||||||
break;
|
break;
|
||||||
@@ -109,31 +96,28 @@ namespace ServerExplorer.UI
|
|||||||
|
|
||||||
public DatabaseDesc CrearDatabaseDesc()
|
public DatabaseDesc CrearDatabaseDesc()
|
||||||
{
|
{
|
||||||
DatabaseDesc db = new DatabaseDesc { Nombre = cnx.Database };
|
var db = new DatabaseDesc { Nombre = _cnx.Database };
|
||||||
foreach (TablaInfo t in config.Tablas)
|
foreach (TablaInfo t in _config.Tablas)
|
||||||
{
|
{
|
||||||
TablaDesc td = new TablaDesc();
|
var td = new TablaDesc();
|
||||||
td.FillDesc(t.Esquema, t.Nombre, cnx);
|
td.FillDesc(t.Esquema, t.Nombre, _cnx);
|
||||||
db.Tablas.Add(td);
|
db.Tablas.Add(td);
|
||||||
}
|
}
|
||||||
return (db);
|
return (db);
|
||||||
}
|
}
|
||||||
|
|
||||||
public FrmBaseDatos(String ConnectionString)
|
public FrmBaseDatos(String connectionString)
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
|
||||||
instancia = this;
|
_config = new Config {ConnectionString = connectionString};
|
||||||
config = new Config();
|
|
||||||
config.ConnectionString = ConnectionString;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public FrmBaseDatos(Config config)
|
public FrmBaseDatos(Config config)
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
|
||||||
instancia = this;
|
_config = config;
|
||||||
this.config = config;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -143,14 +127,14 @@ namespace ServerExplorer.UI
|
|||||||
Initialize();
|
Initialize();
|
||||||
|
|
||||||
// Establecer titulos
|
// Establecer titulos
|
||||||
lblTituloDB.Text = cnx.Database;
|
lblTituloDB.Text = _cnx.Database;
|
||||||
lblTituloTabla.Text = "";
|
lblTituloTabla.Text = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
private void btnCopiarConString_Click(object sender, EventArgs e)
|
private void btnCopiarConString_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
// Copiar la cadena de conexion al portapapeles
|
// 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)
|
private void lsvTablas_SelectedIndexChanged(object sender, EventArgs e)
|
||||||
@@ -161,15 +145,15 @@ namespace ServerExplorer.UI
|
|||||||
ListViewItem item = lsvTablas.SelectedItems[0];
|
ListViewItem item = lsvTablas.SelectedItems[0];
|
||||||
|
|
||||||
// Recordar tabla seleccionada
|
// Recordar tabla seleccionada
|
||||||
tableSchema = item.SubItems[1].Text.ToString();
|
_tableSchema = item.SubItems[1].Text;
|
||||||
tableName = item.SubItems[0].Text.ToString();
|
_tableName = item.SubItems[0].Text;
|
||||||
|
|
||||||
// Establecer titulo de la lista de columnas
|
// Establecer titulo de la lista de columnas
|
||||||
lblTituloTabla.Text = tableSchema + "." + tableName;
|
lblTituloTabla.Text = _tableSchema + @"." + _tableName;
|
||||||
|
|
||||||
// Obtener descripcion de tabla
|
// Obtener descripcion de tabla
|
||||||
TablaDesc td = new TablaDesc();
|
var td = new TablaDesc();
|
||||||
td.FillDesc(tableSchema, tableName, cnx);
|
td.FillDesc(_tableSchema, _tableName, _cnx);
|
||||||
|
|
||||||
// Mostrar "columnas" de las tablas
|
// Mostrar "columnas" de las tablas
|
||||||
lsvColumnas.Items.Clear();
|
lsvColumnas.Items.Clear();
|
||||||
@@ -185,21 +169,21 @@ namespace ServerExplorer.UI
|
|||||||
|
|
||||||
private void menuCargar_Click(object sender, EventArgs e)
|
private void menuCargar_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
OpenFileDialog dialogo = new OpenFileDialog();
|
var dialogo = new OpenFileDialog();
|
||||||
if (dialogo.ShowDialog() == DialogResult.OK)
|
if (dialogo.ShowDialog() == DialogResult.OK)
|
||||||
{
|
{
|
||||||
config = Config.Cargar(dialogo.FileName);
|
_config = Config.Cargar(dialogo.FileName);
|
||||||
Initialize();
|
Initialize();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void menuGuardar_Click(object sender, EventArgs e)
|
private void menuGuardar_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
SaveFileDialog dialogo = new SaveFileDialog();
|
var dialogo = new SaveFileDialog();
|
||||||
if (dialogo.ShowDialog() == DialogResult.OK)
|
if (dialogo.ShowDialog() == DialogResult.OK)
|
||||||
{
|
{
|
||||||
TablesFromListView();
|
TablesFromListView();
|
||||||
config.Guardar(dialogo.FileName);
|
_config.Guardar(dialogo.FileName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -212,14 +196,14 @@ namespace ServerExplorer.UI
|
|||||||
|
|
||||||
private void btnVerDatos_Click(object sender, EventArgs e)
|
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
|
// Obtener descripcion de tabla
|
||||||
TablaDesc td = new TablaDesc();
|
var td = new TablaDesc();
|
||||||
td.FillDesc(tableSchema, tableName, cnx);
|
td.FillDesc(_tableSchema, _tableName, _cnx);
|
||||||
|
|
||||||
// Crear y mostrar el formulario de los datos.
|
// 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);
|
FrmPrincipal.AddForm(form);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -227,14 +211,14 @@ namespace ServerExplorer.UI
|
|||||||
private void btnProcs_Click(object sender, EventArgs e)
|
private void btnProcs_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
// Crear y mostrar el formulario de los procedimientos.
|
// Crear y mostrar el formulario de los procedimientos.
|
||||||
FrmProcedimientos form = new FrmProcedimientos(config.ConnectionString);
|
var form = new FrmProcedimientos(_config.ConnectionString);
|
||||||
FrmPrincipal.AddForm(form);
|
FrmPrincipal.AddForm(form);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void btnExec_Click(object sender, EventArgs e)
|
private void btnExec_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
// Crear y mostrar el formulario de exec.
|
// Crear y mostrar el formulario de exec.
|
||||||
FrmExec form = new FrmExec(config.ConnectionString);
|
var form = new FrmExec(_config.ConnectionString);
|
||||||
FrmPrincipal.AddForm(form);
|
FrmPrincipal.AddForm(form);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -249,8 +233,8 @@ namespace ServerExplorer.UI
|
|||||||
TablesFromListView();
|
TablesFromListView();
|
||||||
DatabaseDesc db = CrearDatabaseDesc();
|
DatabaseDesc db = CrearDatabaseDesc();
|
||||||
|
|
||||||
XmlSerializer seriador = new XmlSerializer(typeof(DatabaseDesc));
|
var seriador = new XmlSerializer(typeof(DatabaseDesc));
|
||||||
seriador.Serialize(System.Console.Out, db);
|
seriador.Serialize(Console.Out, db);
|
||||||
|
|
||||||
//CodeGen.GenerarCodigo(config, db);
|
//CodeGen.GenerarCodigo(config, db);
|
||||||
}
|
}
|
||||||
@@ -258,7 +242,7 @@ namespace ServerExplorer.UI
|
|||||||
private void btnDocGen_Click(object sender, EventArgs e)
|
private void btnDocGen_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
// Hacer insensible la ventana
|
// Hacer insensible la ventana
|
||||||
this.Parent.Enabled = false;
|
Parent.Enabled = false;
|
||||||
|
|
||||||
// Obtener informacion.
|
// Obtener informacion.
|
||||||
TablesFromListView();
|
TablesFromListView();
|
||||||
@@ -268,7 +252,7 @@ namespace ServerExplorer.UI
|
|||||||
DocGen.GenerarDocumentacion(db);
|
DocGen.GenerarDocumentacion(db);
|
||||||
|
|
||||||
// Hace sensible la ventana
|
// Hace sensible la ventana
|
||||||
this.Parent.Enabled = true;
|
Parent.Enabled = true;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
tablas_delistview();
|
tablas_delistview();
|
||||||
@@ -280,7 +264,7 @@ namespace ServerExplorer.UI
|
|||||||
public void GenerarDoc()
|
public void GenerarDoc()
|
||||||
{
|
{
|
||||||
// Hacer insensible la ventana
|
// Hacer insensible la ventana
|
||||||
this.Enabled = false;
|
Enabled = false;
|
||||||
|
|
||||||
// Obtener informacion.
|
// Obtener informacion.
|
||||||
DatabaseDesc db = CrearDatabaseDesc();
|
DatabaseDesc db = CrearDatabaseDesc();
|
||||||
@@ -289,7 +273,7 @@ namespace ServerExplorer.UI
|
|||||||
DocGen.GenerarDocumentacion(db);
|
DocGen.GenerarDocumentacion(db);
|
||||||
|
|
||||||
// Hace sensible la ventana
|
// Hace sensible la ventana
|
||||||
this.Enabled = true;
|
Enabled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void splitContainer1_Panel1_Paint(object sender, PaintEventArgs e)
|
private void splitContainer1_Panel1_Paint(object sender, PaintEventArgs e)
|
||||||
|
|||||||
@@ -1,10 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.ComponentModel;
|
|
||||||
using System.Data;
|
using System.Data;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
using ServerExplorer.Code;
|
using ServerExplorer.Code;
|
||||||
using System.Data.SqlClient;
|
using System.Data.SqlClient;
|
||||||
@@ -15,8 +11,8 @@ namespace ServerExplorer.UI
|
|||||||
{
|
{
|
||||||
#region Declarations
|
#region Declarations
|
||||||
|
|
||||||
private TablaDesc tablaDesc = null;
|
private readonly TablaDesc _tablaDesc;
|
||||||
private string conexionString = string.Empty;
|
private readonly string _conexionString = string.Empty;
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@@ -25,8 +21,8 @@ namespace ServerExplorer.UI
|
|||||||
public FrmDatos(TablaDesc tablaDesc, string conexionString)
|
public FrmDatos(TablaDesc tablaDesc, string conexionString)
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
this.tablaDesc = tablaDesc;
|
_tablaDesc = tablaDesc;
|
||||||
this.conexionString = conexionString;
|
_conexionString = conexionString;
|
||||||
LoadDataFromTable();
|
LoadDataFromTable();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -60,11 +56,11 @@ namespace ServerExplorer.UI
|
|||||||
|
|
||||||
private void LoadDataFromTable()
|
private void LoadDataFromTable()
|
||||||
{
|
{
|
||||||
Text = tablaDesc.Esquema + "." + tablaDesc.Nombre;
|
Text = _tablaDesc.Esquema + @"." + _tablaDesc.Nombre;
|
||||||
string tableFullName = "[" + tablaDesc.Esquema + "].[" + tablaDesc.Nombre + "]";
|
string tableFullName = "[" + _tablaDesc.Esquema + "].[" + _tablaDesc.Nombre + "]";
|
||||||
DataTable dt= new DataTable();
|
var dt= new DataTable();
|
||||||
SqlConnection cnx = new SqlConnection(conexionString);
|
var cnx = new SqlConnection(_conexionString);
|
||||||
SqlDataAdapter da = new SqlDataAdapter( "select * from " + tableFullName, cnx);
|
var da = new SqlDataAdapter( "select * from " + tableFullName, cnx);
|
||||||
cnx.Open();
|
cnx.Open();
|
||||||
da.Fill(dt);
|
da.Fill(dt);
|
||||||
cnx.Close();
|
cnx.Close();
|
||||||
|
|||||||
@@ -1,13 +1,9 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.ComponentModel;
|
|
||||||
using System.Data;
|
using System.Data;
|
||||||
using System.Drawing;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Windows.Forms;
|
|
||||||
using System.Data.SqlClient;
|
using System.Data.SqlClient;
|
||||||
|
using System.Drawing;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
|
||||||
namespace ServerExplorer.UI
|
namespace ServerExplorer.UI
|
||||||
{
|
{
|
||||||
@@ -15,7 +11,7 @@ namespace ServerExplorer.UI
|
|||||||
{
|
{
|
||||||
#region Declarations
|
#region Declarations
|
||||||
|
|
||||||
private string cnxString;
|
private readonly string _cnxString;
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@@ -25,7 +21,7 @@ namespace ServerExplorer.UI
|
|||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
|
||||||
this.cnxString = cnxString;
|
_cnxString = cnxString;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
@@ -51,7 +47,7 @@ namespace ServerExplorer.UI
|
|||||||
{
|
{
|
||||||
// Obtener el nombre de la tabla destino
|
// Obtener el nombre de la tabla destino
|
||||||
string destTable = Microsoft.VisualBasic.Interaction.InputBox("Nombre de la tabla destino", "tabla destino", String.Empty,
|
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);
|
DataTable dt = GenerarInserts(destTable);
|
||||||
dgvDatos.DataSource = dt;
|
dgvDatos.DataSource = dt;
|
||||||
@@ -79,16 +75,12 @@ namespace ServerExplorer.UI
|
|||||||
|
|
||||||
private DataTable Exec()
|
private DataTable Exec()
|
||||||
{
|
{
|
||||||
SqlConnection cnx;
|
|
||||||
DataTable dt;
|
|
||||||
SqlDataAdapter da;
|
|
||||||
|
|
||||||
// Establecer conexion
|
// Establecer conexion
|
||||||
cnx = new SqlConnection(cnxString);
|
var cnx = new SqlConnection(_cnxString);
|
||||||
|
|
||||||
// Obtener resultado en un datatable.
|
// Obtener resultado en un datatable.
|
||||||
da = new SqlDataAdapter(txtCommand.Text, cnx);
|
var da = new SqlDataAdapter(txtCommand.Text, cnx);
|
||||||
dt = new DataTable();
|
var dt = new DataTable();
|
||||||
cnx.Open();
|
cnx.Open();
|
||||||
da.Fill(dt);
|
da.Fill(dt);
|
||||||
cnx.Close();
|
cnx.Close();
|
||||||
@@ -98,14 +90,12 @@ namespace ServerExplorer.UI
|
|||||||
|
|
||||||
private DataTable GenerarInserts(string destTable)
|
private DataTable GenerarInserts(string destTable)
|
||||||
{
|
{
|
||||||
DataTable dataTable = new DataTable();
|
var nfi = new NumberFormatInfo { NumberDecimalSeparator = "." };
|
||||||
DataTable destDataTable;
|
|
||||||
NumberFormatInfo nfi = new NumberFormatInfo { NumberDecimalSeparator = "." };
|
|
||||||
|
|
||||||
dataTable = Exec();
|
DataTable dataTable = Exec();
|
||||||
|
|
||||||
// Preparar la datatable destino
|
// Preparar la datatable destino
|
||||||
destDataTable = new DataTable();
|
var destDataTable = new DataTable();
|
||||||
destDataTable.Columns.Add("Comando", typeof(String));
|
destDataTable.Columns.Add("Comando", typeof(String));
|
||||||
|
|
||||||
// Recorrer la tabla de datos
|
// Recorrer la tabla de datos
|
||||||
|
|||||||
@@ -1,10 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
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.Windows.Forms;
|
||||||
using ServerExplorer.Code;
|
using ServerExplorer.Code;
|
||||||
using ServerExplorer.Controls;
|
using ServerExplorer.Controls;
|
||||||
@@ -15,7 +10,7 @@ namespace ServerExplorer.UI
|
|||||||
{
|
{
|
||||||
#region Declarations
|
#region Declarations
|
||||||
|
|
||||||
private static FrmPrincipal currentInstance;
|
private static FrmPrincipal _currentInstance;
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@@ -23,7 +18,7 @@ namespace ServerExplorer.UI
|
|||||||
|
|
||||||
public FrmPrincipal()
|
public FrmPrincipal()
|
||||||
{
|
{
|
||||||
currentInstance = this;
|
_currentInstance = this;
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -35,12 +30,12 @@ namespace ServerExplorer.UI
|
|||||||
|
|
||||||
public static void AddForm(Form frm)
|
public static void AddForm(Form frm)
|
||||||
{
|
{
|
||||||
frm.MdiParent = currentInstance;
|
frm.MdiParent = _currentInstance;
|
||||||
frm.WindowState = FormWindowState.Maximized;
|
frm.WindowState = FormWindowState.Maximized;
|
||||||
frm.Show();
|
frm.Show();
|
||||||
currentInstance.listChilds.Add(frm);
|
_currentInstance.listChilds.Add(frm);
|
||||||
frm.FormClosed += currentInstance.FrmPrincipal_OnChildClose;
|
frm.FormClosed += _currentInstance.FrmPrincipal_OnChildClose;
|
||||||
currentInstance.RefreshWindowButtons();
|
_currentInstance.RefreshWindowButtons();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void FrmPrincipal_OnChildClose(object sender, FormClosedEventArgs e)
|
protected void FrmPrincipal_OnChildClose(object sender, FormClosedEventArgs e)
|
||||||
@@ -90,7 +85,7 @@ namespace ServerExplorer.UI
|
|||||||
private void menuConectarPRUEBAS_Click(object sender, EventArgs e)
|
private void menuConectarPRUEBAS_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
// Crear ventana de la base de datos de pruebas
|
// 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=DANTE;Initial Catalog=BD_AlfonsoRodriguez;Integrated Security=True");
|
||||||
//frmBaseDatos frm = new frmBaseDatos("Data Source=OSKURITO;Initial Catalog=BD_AlfonsoRodriguez;Integrated Security=True");
|
//frmBaseDatos frm = new frmBaseDatos("Data Source=OSKURITO;Initial Catalog=BD_AlfonsoRodriguez;Integrated Security=True");
|
||||||
FrmPrincipal.AddForm(frm);
|
FrmPrincipal.AddForm(frm);
|
||||||
@@ -99,22 +94,21 @@ namespace ServerExplorer.UI
|
|||||||
private void menuBuscarServidor_Click(object sender, EventArgs e)
|
private void menuBuscarServidor_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
// Mostrar ventana de buscador de servidores
|
// Mostrar ventana de buscador de servidores
|
||||||
FrmServidores frm = new FrmServidores();
|
var frm = new FrmServidores();
|
||||||
FrmPrincipal.AddForm(frm);
|
FrmPrincipal.AddForm(frm);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void menuConectarA_Click(object sender, EventArgs e)
|
private void menuConectarA_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
// Cargar configuracion
|
// Cargar configuracion
|
||||||
OpenFileDialog dialogo = new OpenFileDialog();
|
var dialogo = new OpenFileDialog();
|
||||||
if (dialogo.ShowDialog() == DialogResult.OK)
|
if (dialogo.ShowDialog() != DialogResult.OK) return;
|
||||||
{
|
|
||||||
Config config = Config.Cargar(dialogo.FileName);
|
|
||||||
|
|
||||||
// Crear y mostrar ventana
|
Config config = Config.Cargar(dialogo.FileName);
|
||||||
FrmBaseDatos frm = new FrmBaseDatos(config);
|
|
||||||
FrmPrincipal.AddForm(frm);
|
// Crear y mostrar ventana
|
||||||
}
|
var frm = new FrmBaseDatos(config);
|
||||||
|
FrmPrincipal.AddForm(frm);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ namespace ServerExplorer.UI
|
|||||||
{
|
{
|
||||||
#region Declarations
|
#region Declarations
|
||||||
|
|
||||||
private SqlConnection cnx;
|
private readonly SqlConnection _cnx;
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@@ -19,7 +19,7 @@ namespace ServerExplorer.UI
|
|||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
|
||||||
cnx = new SqlConnection(cnxString);
|
_cnx = new SqlConnection(cnxString);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void frmProcedimientos_Load(object sender, EventArgs e)
|
private void frmProcedimientos_Load(object sender, EventArgs e)
|
||||||
@@ -35,9 +35,8 @@ namespace ServerExplorer.UI
|
|||||||
{
|
{
|
||||||
if (lsvProcs.SelectedItems.Count <= 0) { return; }
|
if (lsvProcs.SelectedItems.Count <= 0) { return; }
|
||||||
|
|
||||||
string schema, name;
|
string name = lsvProcs.SelectedItems[0].SubItems[0].Text;
|
||||||
name = lsvProcs.SelectedItems[0].SubItems[0].Text;
|
string schema = lsvProcs.SelectedItems[0].SubItems[1].Text;
|
||||||
schema = lsvProcs.SelectedItems[0].SubItems[1].Text;
|
|
||||||
LoadProcedure(schema, name);
|
LoadProcedure(schema, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -52,17 +51,14 @@ namespace ServerExplorer.UI
|
|||||||
|
|
||||||
private void LoadProcedures()
|
private void LoadProcedures()
|
||||||
{
|
{
|
||||||
DataTable dt;
|
|
||||||
SqlDataAdapter da;
|
|
||||||
|
|
||||||
// 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(
|
var 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",
|
||||||
cnx);
|
_cnx);
|
||||||
dt = new DataTable();
|
var dt = new DataTable();
|
||||||
cnx.Open();
|
_cnx.Open();
|
||||||
da.Fill(dt);
|
da.Fill(dt);
|
||||||
cnx.Close();
|
_cnx.Close();
|
||||||
|
|
||||||
// Mostrar todos los procedimientos
|
// Mostrar todos los procedimientos
|
||||||
lsvProcs.Items.Clear();
|
lsvProcs.Items.Clear();
|
||||||
@@ -87,14 +83,14 @@ namespace ServerExplorer.UI
|
|||||||
(sp.type = N'P' OR sp.type = N'RF' OR sp.type='PC')
|
(sp.type = N'P' OR sp.type = N'RF' OR sp.type='PC')
|
||||||
and
|
and
|
||||||
(sp.name=@name and SCHEMA_NAME(sp.schema_id)=@schema)
|
(sp.name=@name and SCHEMA_NAME(sp.schema_id)=@schema)
|
||||||
", cnx);
|
", _cnx);
|
||||||
|
|
||||||
da.SelectCommand.Parameters.AddWithValue("@Name", name);
|
da.SelectCommand.Parameters.AddWithValue("@Name", name);
|
||||||
da.SelectCommand.Parameters.AddWithValue("@Schema", schema);
|
da.SelectCommand.Parameters.AddWithValue("@Schema", schema);
|
||||||
var dt = new DataTable();
|
var dt = new DataTable();
|
||||||
cnx.Open();
|
_cnx.Open();
|
||||||
da.Fill(dt);
|
da.Fill(dt);
|
||||||
cnx.Close();
|
_cnx.Close();
|
||||||
|
|
||||||
// Mostrar el contenido del procedimiento
|
// Mostrar el contenido del procedimiento
|
||||||
txtProc.Text = String.Empty;
|
txtProc.Text = String.Empty;
|
||||||
|
|||||||
@@ -1,14 +1,8 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.ComponentModel;
|
|
||||||
using System.Data;
|
using System.Data;
|
||||||
using System.Drawing;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Windows.Forms;
|
|
||||||
using System.Data.Sql;
|
using System.Data.Sql;
|
||||||
using System.Data.SqlClient;
|
using System.Data.SqlClient;
|
||||||
using System.Data.SqlTypes;
|
using System.Windows.Forms;
|
||||||
|
|
||||||
namespace ServerExplorer.UI
|
namespace ServerExplorer.UI
|
||||||
{
|
{
|
||||||
@@ -32,28 +26,9 @@ namespace ServerExplorer.UI
|
|||||||
lsvBBDD.Items.Clear();
|
lsvBBDD.Items.Clear();
|
||||||
foreach (DataRow dr in servidores.Rows)
|
foreach (DataRow dr in servidores.Rows)
|
||||||
{
|
{
|
||||||
// Nombre del servidor
|
|
||||||
ListViewItem item = lsvServidores.Items.Add((String)dr["ServerName"]);
|
ListViewItem item = lsvServidores.Items.Add((String)dr["ServerName"]);
|
||||||
|
item.SubItems.Add((dr["InstanceName"] == DBNull.Value) ? string.Empty : (String)dr["InstanceName"]);
|
||||||
// Nombre de la instancia
|
item.SubItems.Add((dr["Version"] == DBNull.Value) ? "???" : (String) dr["Version"]);
|
||||||
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"]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -62,41 +37,20 @@ namespace ServerExplorer.UI
|
|||||||
if (lsvServidores.SelectedItems.Count > 0)
|
if (lsvServidores.SelectedItems.Count > 0)
|
||||||
{
|
{
|
||||||
ListViewItem item = lsvServidores.SelectedItems[0];
|
ListViewItem item = lsvServidores.SelectedItems[0];
|
||||||
if (item.SubItems[1].Text.CompareTo("") == 0)
|
txtServidor.Text = String.IsNullOrEmpty(item.SubItems[1].Text)
|
||||||
{
|
? item.SubItems[0].Text
|
||||||
// Servidor sin subinstancias
|
: String.Format("{0}/{1}", item.SubItems[0].Text, item.SubItems[1].Text);
|
||||||
txtServidor.Text = item.SubItems[0].Text;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Servidor con subinstancias
|
|
||||||
txtServidor.Text = item.SubItems[0].Text + "/" + item.SubItems[1].Text;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void btnListarBBDD_Click(object sender, EventArgs e)
|
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
|
// Obtener todas las bases de datos
|
||||||
SqlConnection cnx = new SqlConnection(constructor.ConnectionString);
|
var cnx = new SqlConnection(BuildConnectionString());
|
||||||
cnx.Open();
|
cnx.Open();
|
||||||
DataTable dt = cnx.GetSchema("Databases");
|
DataTable dt = cnx.GetSchema("Databases");
|
||||||
cnx.Close();
|
cnx.Close();
|
||||||
|
|
||||||
|
|
||||||
// Mostrar bases de datos
|
// Mostrar bases de datos
|
||||||
lsvBBDD.Items.Clear();
|
lsvBBDD.Items.Clear();
|
||||||
foreach (DataRow dr in dt.Rows)
|
foreach (DataRow dr in dt.Rows)
|
||||||
@@ -109,26 +63,32 @@ namespace ServerExplorer.UI
|
|||||||
|
|
||||||
private void lsvBBDD_DoubleClick(object sender, EventArgs e)
|
private void lsvBBDD_DoubleClick(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (lsvBBDD.SelectedItems.Count == 1)
|
if (lsvBBDD.SelectedItems.Count != 1) return;
|
||||||
{
|
|
||||||
// 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Llamar a la venta de la base de datos
|
// Llamar a la venta de la base de datos
|
||||||
FrmBaseDatos frm = new FrmBaseDatos(constructor.ConnectionString);
|
var frm = new FrmBaseDatos(BuildConnectionString());
|
||||||
FrmPrincipal.AddForm(frm);
|
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