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)
|
||||
|
||||
Reference in New Issue
Block a user