Miscellaneous changes. Keep original end of line characters.
This commit is contained in:
@@ -1,289 +1,289 @@
|
||||
using System;
|
||||
using System.Data;
|
||||
using System.Windows.Forms;
|
||||
using System.Data.SqlClient;
|
||||
using System.Xml.Serialization;
|
||||
using ServerExplorer.Code;
|
||||
|
||||
namespace ServerExplorer.UI
|
||||
{
|
||||
public partial class FrmBaseDatos : Form
|
||||
{
|
||||
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);
|
||||
|
||||
// Obtener lista de tablas
|
||||
_cnx.Open();
|
||||
DataTable dt = _cnx.GetSchema("Tables");
|
||||
_cnx.Close();
|
||||
|
||||
// Mostrar todas las tablas
|
||||
lsvTablas.Items.Clear();
|
||||
foreach (DataRow dr in dt.Rows)
|
||||
{
|
||||
ListViewItem item = lsvTablas.Items.Add((String)dr["TABLE_NAME"]);
|
||||
item.SubItems.Add((String)dr["TABLE_SCHEMA"]);
|
||||
item.SubItems.Add((String)dr["TABLE_TYPE"]);
|
||||
}
|
||||
TablesToListView();
|
||||
|
||||
// Limpiar Columnas
|
||||
lsvColumnas.Items.Clear();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Metodo para copiar las tablas seleccionadas en el listview a la configuracion
|
||||
/// </summary>
|
||||
private void TablesFromListView()
|
||||
{
|
||||
_config.Tablas.Clear();
|
||||
foreach (ListViewItem item in lsvTablas.Items)
|
||||
{
|
||||
if (item.Checked)
|
||||
{
|
||||
_config.Tablas.Add(new TablaInfo
|
||||
{
|
||||
Esquema = item.SubItems[1].Text,
|
||||
Nombre = item.SubItems[0].Text
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Metodo para seleccionar las tablas en le listview desde la configuracion
|
||||
/// </summary>
|
||||
private void TablesToListView()
|
||||
{
|
||||
int j;
|
||||
|
||||
// Desmarcar todos en caso de no haber ninguna tabla
|
||||
if (_config.Tablas.Count == 0)
|
||||
{
|
||||
foreach (ListViewItem item in lsvTablas.Items)
|
||||
item.Checked = false;
|
||||
return;
|
||||
}
|
||||
|
||||
// Recorrer items marcando los que estan en la configuracion
|
||||
int n = _config.Tablas.Count;
|
||||
int i = j = 0;
|
||||
foreach (ListViewItem item in lsvTablas.Items)
|
||||
{
|
||||
item.Checked = false;
|
||||
do
|
||||
{
|
||||
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;
|
||||
}
|
||||
i = (i + 1) % n;
|
||||
} while (i != j);
|
||||
j = i;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public DatabaseDesc CrearDatabaseDesc()
|
||||
{
|
||||
var db = new DatabaseDesc { Nombre = _cnx.Database };
|
||||
foreach (TablaInfo t in _config.Tablas)
|
||||
{
|
||||
var td = new TablaDesc();
|
||||
td.FillDesc(t.Esquema, t.Nombre, _cnx);
|
||||
db.Tablas.Add(td);
|
||||
}
|
||||
return (db);
|
||||
}
|
||||
|
||||
public FrmBaseDatos(String connectionString)
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
_config = new Config {ConnectionString = connectionString};
|
||||
}
|
||||
|
||||
public FrmBaseDatos(Config config)
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
_config = config;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void frmBaseDatos_Load(object sender, EventArgs e)
|
||||
{
|
||||
Initialize();
|
||||
|
||||
// Establecer titulos
|
||||
lblTituloDB.Text = _cnx.Database;
|
||||
lblTituloTabla.Text = "";
|
||||
}
|
||||
|
||||
private void btnCopiarConString_Click(object sender, EventArgs e)
|
||||
{
|
||||
// Copiar la cadena de conexion al portapapeles
|
||||
Clipboard.SetText(txtConString.Text);
|
||||
}
|
||||
|
||||
private void lsvTablas_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
if (lsvTablas.SelectedItems.Count != 1) { return; }
|
||||
|
||||
// Determinar tabla seleccionada
|
||||
ListViewItem item = lsvTablas.SelectedItems[0];
|
||||
|
||||
// Recordar tabla seleccionada
|
||||
_tableSchema = item.SubItems[1].Text;
|
||||
_tableName = item.SubItems[0].Text;
|
||||
|
||||
// Establecer titulo de la lista de columnas
|
||||
lblTituloTabla.Text = _tableSchema + @"." + _tableName;
|
||||
|
||||
// Obtener descripcion de tabla
|
||||
var td = new TablaDesc();
|
||||
td.FillDesc(_tableSchema, _tableName, _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");
|
||||
}
|
||||
}
|
||||
|
||||
private void menuCargar_Click(object sender, EventArgs e)
|
||||
{
|
||||
var dialogo = new OpenFileDialog();
|
||||
if (dialogo.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
_config = Config.Cargar(dialogo.FileName);
|
||||
Initialize();
|
||||
}
|
||||
}
|
||||
|
||||
private void menuGuardar_Click(object sender, EventArgs e)
|
||||
{
|
||||
var dialogo = new SaveFileDialog();
|
||||
if (dialogo.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
TablesFromListView();
|
||||
_config.Guardar(dialogo.FileName);
|
||||
}
|
||||
}
|
||||
|
||||
private void menuConfiguracion_Click(object sender, EventArgs e)
|
||||
{
|
||||
//// Llamar a la ventana de configuracion
|
||||
//FrmCodeGenConfig frm = new FrmCodeGenConfig(config);
|
||||
//frm.ShowDialog();
|
||||
}
|
||||
|
||||
private void btnVerDatos_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (string.IsNullOrEmpty(_tableSchema) || string.IsNullOrEmpty(_tableName)) { return; }
|
||||
|
||||
// Obtener descripcion de tabla
|
||||
var td = new TablaDesc();
|
||||
td.FillDesc(_tableSchema, _tableName, _cnx);
|
||||
|
||||
// Crear y mostrar el formulario de los datos.
|
||||
var form = new FrmDatos(td, _config.ConnectionString);
|
||||
FrmPrincipal.AddForm(form);
|
||||
}
|
||||
|
||||
|
||||
private void btnProcs_Click(object sender, EventArgs e)
|
||||
{
|
||||
// Crear y mostrar el formulario de los procedimientos.
|
||||
var form = new FrmProcedimientos(_config.ConnectionString);
|
||||
FrmPrincipal.AddForm(form);
|
||||
}
|
||||
|
||||
private void btnExec_Click(object sender, EventArgs e)
|
||||
{
|
||||
// Crear y mostrar el formulario de exec.
|
||||
var form = new FrmExec(_config.ConnectionString);
|
||||
FrmPrincipal.AddForm(form);
|
||||
}
|
||||
|
||||
|
||||
private void menuBaseDatos_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void btnGenerar_Click(object sender, EventArgs e)
|
||||
{
|
||||
TablesFromListView();
|
||||
DatabaseDesc db = CrearDatabaseDesc();
|
||||
|
||||
var seriador = new XmlSerializer(typeof(DatabaseDesc));
|
||||
seriador.Serialize(Console.Out, db);
|
||||
|
||||
//CodeGen.GenerarCodigo(config, db);
|
||||
}
|
||||
|
||||
private void btnDocGen_Click(object sender, EventArgs e)
|
||||
{
|
||||
// Hacer insensible la ventana
|
||||
Parent.Enabled = false;
|
||||
|
||||
// Obtener informacion.
|
||||
TablesFromListView();
|
||||
DatabaseDesc db = CrearDatabaseDesc();
|
||||
|
||||
// Escribir documentacion
|
||||
DocGen.GenerarDocumentacion(db);
|
||||
|
||||
// Hace sensible la ventana
|
||||
Parent.Enabled = true;
|
||||
|
||||
/*
|
||||
tablas_delistview();
|
||||
Thread hilo=new Thread(new ThreadStart(instancia.GenerarDoc));
|
||||
hilo.Start();
|
||||
*/
|
||||
}
|
||||
|
||||
public void GenerarDoc()
|
||||
{
|
||||
// Hacer insensible la ventana
|
||||
Enabled = false;
|
||||
|
||||
// Obtener informacion.
|
||||
DatabaseDesc db = CrearDatabaseDesc();
|
||||
|
||||
// Escribir documentacion
|
||||
DocGen.GenerarDocumentacion(db);
|
||||
|
||||
// Hace sensible la ventana
|
||||
Enabled = true;
|
||||
}
|
||||
|
||||
private void splitContainer1_Panel1_Paint(object sender, PaintEventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void btnRefresh_Click(object sender, EventArgs e)
|
||||
{
|
||||
Initialize();
|
||||
}
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.Data;
|
||||
using System.Windows.Forms;
|
||||
using System.Data.SqlClient;
|
||||
using System.Xml.Serialization;
|
||||
using ServerExplorer.Code;
|
||||
|
||||
namespace ServerExplorer.UI
|
||||
{
|
||||
public partial class FrmBaseDatos : Form
|
||||
{
|
||||
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);
|
||||
|
||||
// Obtener lista de tablas
|
||||
_cnx.Open();
|
||||
DataTable dt = _cnx.GetSchema("Tables");
|
||||
_cnx.Close();
|
||||
|
||||
// Mostrar todas las tablas
|
||||
lsvTablas.Items.Clear();
|
||||
foreach (DataRow dr in dt.Rows)
|
||||
{
|
||||
ListViewItem item = lsvTablas.Items.Add((String)dr["TABLE_NAME"]);
|
||||
item.SubItems.Add((String)dr["TABLE_SCHEMA"]);
|
||||
item.SubItems.Add((String)dr["TABLE_TYPE"]);
|
||||
}
|
||||
TablesToListView();
|
||||
|
||||
// Limpiar Columnas
|
||||
lsvColumnas.Items.Clear();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Metodo para copiar las tablas seleccionadas en el listview a la configuracion
|
||||
/// </summary>
|
||||
private void TablesFromListView()
|
||||
{
|
||||
_config.Tablas.Clear();
|
||||
foreach (ListViewItem item in lsvTablas.Items)
|
||||
{
|
||||
if (item.Checked)
|
||||
{
|
||||
_config.Tablas.Add(new TablaInfo
|
||||
{
|
||||
Esquema = item.SubItems[1].Text,
|
||||
Nombre = item.SubItems[0].Text
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Metodo para seleccionar las tablas en le listview desde la configuracion
|
||||
/// </summary>
|
||||
private void TablesToListView()
|
||||
{
|
||||
int j;
|
||||
|
||||
// Desmarcar todos en caso de no haber ninguna tabla
|
||||
if (_config.Tablas.Count == 0)
|
||||
{
|
||||
foreach (ListViewItem item in lsvTablas.Items)
|
||||
item.Checked = false;
|
||||
return;
|
||||
}
|
||||
|
||||
// Recorrer items marcando los que estan en la configuracion
|
||||
int n = _config.Tablas.Count;
|
||||
int i = j = 0;
|
||||
foreach (ListViewItem item in lsvTablas.Items)
|
||||
{
|
||||
item.Checked = false;
|
||||
do
|
||||
{
|
||||
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;
|
||||
}
|
||||
i = (i + 1) % n;
|
||||
} while (i != j);
|
||||
j = i;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public DatabaseDesc CrearDatabaseDesc()
|
||||
{
|
||||
var db = new DatabaseDesc { Nombre = _cnx.Database };
|
||||
foreach (TablaInfo t in _config.Tablas)
|
||||
{
|
||||
var td = new TablaDesc();
|
||||
td.FillDesc(t.Esquema, t.Nombre, _cnx);
|
||||
db.Tablas.Add(td);
|
||||
}
|
||||
return (db);
|
||||
}
|
||||
|
||||
public FrmBaseDatos(String connectionString)
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
_config = new Config {ConnectionString = connectionString};
|
||||
}
|
||||
|
||||
public FrmBaseDatos(Config config)
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
_config = config;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void frmBaseDatos_Load(object sender, EventArgs e)
|
||||
{
|
||||
Initialize();
|
||||
|
||||
// Establecer titulos
|
||||
lblTituloDB.Text = _cnx.Database;
|
||||
lblTituloTabla.Text = "";
|
||||
}
|
||||
|
||||
private void btnCopiarConString_Click(object sender, EventArgs e)
|
||||
{
|
||||
// Copiar la cadena de conexion al portapapeles
|
||||
Clipboard.SetText(txtConString.Text);
|
||||
}
|
||||
|
||||
private void lsvTablas_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
if (lsvTablas.SelectedItems.Count != 1) { return; }
|
||||
|
||||
// Determinar tabla seleccionada
|
||||
ListViewItem item = lsvTablas.SelectedItems[0];
|
||||
|
||||
// Recordar tabla seleccionada
|
||||
_tableSchema = item.SubItems[1].Text;
|
||||
_tableName = item.SubItems[0].Text;
|
||||
|
||||
// Establecer titulo de la lista de columnas
|
||||
lblTituloTabla.Text = _tableSchema + @"." + _tableName;
|
||||
|
||||
// Obtener descripcion de tabla
|
||||
var td = new TablaDesc();
|
||||
td.FillDesc(_tableSchema, _tableName, _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");
|
||||
}
|
||||
}
|
||||
|
||||
private void menuCargar_Click(object sender, EventArgs e)
|
||||
{
|
||||
var dialogo = new OpenFileDialog();
|
||||
if (dialogo.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
_config = Config.Cargar(dialogo.FileName);
|
||||
Initialize();
|
||||
}
|
||||
}
|
||||
|
||||
private void menuGuardar_Click(object sender, EventArgs e)
|
||||
{
|
||||
var dialogo = new SaveFileDialog();
|
||||
if (dialogo.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
TablesFromListView();
|
||||
_config.Guardar(dialogo.FileName);
|
||||
}
|
||||
}
|
||||
|
||||
private void menuConfiguracion_Click(object sender, EventArgs e)
|
||||
{
|
||||
//// Llamar a la ventana de configuracion
|
||||
//FrmCodeGenConfig frm = new FrmCodeGenConfig(config);
|
||||
//frm.ShowDialog();
|
||||
}
|
||||
|
||||
private void btnVerDatos_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (string.IsNullOrEmpty(_tableSchema) || string.IsNullOrEmpty(_tableName)) { return; }
|
||||
|
||||
// Obtener descripcion de tabla
|
||||
var td = new TablaDesc();
|
||||
td.FillDesc(_tableSchema, _tableName, _cnx);
|
||||
|
||||
// Crear y mostrar el formulario de los datos.
|
||||
var form = new FrmDatos(td, _config.ConnectionString);
|
||||
FrmPrincipal.AddForm(form);
|
||||
}
|
||||
|
||||
|
||||
private void btnProcs_Click(object sender, EventArgs e)
|
||||
{
|
||||
// Crear y mostrar el formulario de los procedimientos.
|
||||
var form = new FrmProcedimientos(_config.ConnectionString);
|
||||
FrmPrincipal.AddForm(form);
|
||||
}
|
||||
|
||||
private void btnExec_Click(object sender, EventArgs e)
|
||||
{
|
||||
// Crear y mostrar el formulario de exec.
|
||||
var form = new FrmExec(_config.ConnectionString);
|
||||
FrmPrincipal.AddForm(form);
|
||||
}
|
||||
|
||||
|
||||
private void menuBaseDatos_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void btnGenerar_Click(object sender, EventArgs e)
|
||||
{
|
||||
TablesFromListView();
|
||||
DatabaseDesc db = CrearDatabaseDesc();
|
||||
|
||||
var seriador = new XmlSerializer(typeof(DatabaseDesc));
|
||||
seriador.Serialize(Console.Out, db);
|
||||
|
||||
//CodeGen.GenerarCodigo(config, db);
|
||||
}
|
||||
|
||||
private void btnDocGen_Click(object sender, EventArgs e)
|
||||
{
|
||||
// Hacer insensible la ventana
|
||||
Parent.Enabled = false;
|
||||
|
||||
// Obtener informacion.
|
||||
TablesFromListView();
|
||||
DatabaseDesc db = CrearDatabaseDesc();
|
||||
|
||||
// Escribir documentacion
|
||||
DocGen.GenerarDocumentacion(db);
|
||||
|
||||
// Hace sensible la ventana
|
||||
Parent.Enabled = true;
|
||||
|
||||
/*
|
||||
tablas_delistview();
|
||||
Thread hilo=new Thread(new ThreadStart(instancia.GenerarDoc));
|
||||
hilo.Start();
|
||||
*/
|
||||
}
|
||||
|
||||
public void GenerarDoc()
|
||||
{
|
||||
// Hacer insensible la ventana
|
||||
Enabled = false;
|
||||
|
||||
// Obtener informacion.
|
||||
DatabaseDesc db = CrearDatabaseDesc();
|
||||
|
||||
// Escribir documentacion
|
||||
DocGen.GenerarDocumentacion(db);
|
||||
|
||||
// Hace sensible la ventana
|
||||
Enabled = true;
|
||||
}
|
||||
|
||||
private void splitContainer1_Panel1_Paint(object sender, PaintEventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void btnRefresh_Click(object sender, EventArgs e)
|
||||
{
|
||||
Initialize();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user