From b4eea3818fc59d2cb00bd0ad2b625e74db02de82 Mon Sep 17 00:00:00 2001 From: "Valeriano A.R" Date: Mon, 14 Oct 2013 20:20:23 +0200 Subject: [PATCH] Limpieza de codigo --- ServerExplorer/{ => Code}/Utiles.cs | 6 +- ServerExplorer/CodeGen.cs | 20 +++--- ServerExplorer/Config.cs | 17 ++--- ServerExplorer/DatabaseDesc.cs | 1 - ServerExplorer/DocGen.cs | 19 +++-- ServerExplorer/Program.cs | 2 +- ServerExplorer/ServerExplorer.csproj | 75 ++++++++++---------- ServerExplorer/TablaDesc.cs | 42 +++++------ ServerExplorer/frmBaseDatos.Designer.cs | 2 +- ServerExplorer/frmBaseDatos.cs | 47 ++++++------ ServerExplorer/frmCodeGenConfig.Designer.cs | 4 +- ServerExplorer/frmCodeGenConfig.cs | 36 +++++----- ServerExplorer/frmDatos.Designer.cs | 2 +- ServerExplorer/frmDatos.cs | 16 ++--- ServerExplorer/frmExec.Designer.cs | 2 +- ServerExplorer/frmExec.cs | 60 ++++++++-------- ServerExplorer/frmPrincipal.Designer.cs | 2 +- ServerExplorer/frmPrincipal.cs | 10 +-- ServerExplorer/frmProcedimientos.Designer.cs | 2 +- ServerExplorer/frmProcedimientos.cs | 12 ++-- ServerExplorer/frmServidores.Designer.cs | 2 +- ServerExplorer/frmServidores.cs | 12 ++-- 22 files changed, 194 insertions(+), 197 deletions(-) rename ServerExplorer/{ => Code}/Utiles.cs (86%) diff --git a/ServerExplorer/Utiles.cs b/ServerExplorer/Code/Utiles.cs similarity index 86% rename from ServerExplorer/Utiles.cs rename to ServerExplorer/Code/Utiles.cs index 2dbf5f5..f70ff5b 100644 --- a/ServerExplorer/Utiles.cs +++ b/ServerExplorer/Code/Utiles.cs @@ -4,18 +4,18 @@ using System.Linq; using System.Text; using System.IO; -namespace ServerExplorer +namespace ServerExplorer.Code { public static class Utiles { public static void CrearDirectorio(this String path) { - DirectoryInfo info=null; + DirectoryInfo info = null; try { info = new DirectoryInfo(path); } - catch (Exception ) + catch (Exception) { info = new DirectoryInfo("."); } diff --git a/ServerExplorer/CodeGen.cs b/ServerExplorer/CodeGen.cs index eab287e..eed6f68 100644 --- a/ServerExplorer/CodeGen.cs +++ b/ServerExplorer/CodeGen.cs @@ -4,12 +4,14 @@ using System.Linq; using System.Text; using System.IO; using System.Data; +using ServerExplorer.Code; namespace ServerExplorer { public class CodeGen { - private static string FixNombre(string strIn){ + private static string FixNombre(string strIn) + { return strIn.Replace(' ', '_'); } @@ -147,7 +149,7 @@ namespace ServerExplorer { TipoCol tipo = c.GetTipo(); - if(tipo==TipoCol.Otro) + if (tipo == TipoCol.Otro) continue; if (strInsert1 == String.Empty) @@ -186,7 +188,7 @@ namespace ServerExplorer private static void GenerarDALActualizar(Config config, TablaDesc t, EscritorCodigo escritor) { string nombreObj = FixNombre(t.Esquema) + "_" + FixNombre(t.Nombre); - string strActualizar,strFiltroPrimario; + string strActualizar, strFiltroPrimario; // Cabecera y variables del metodo escritor.EscribeInd("public bool Actualizar(" + nombreObj + " reg)"); @@ -299,13 +301,13 @@ namespace ServerExplorer escritor.Cerrar(); } - public static Boolean GenerarCodigo(Config config,DatabaseDesc database) + public static Boolean GenerarCodigo(Config config, DatabaseDesc database) { // Asegura la existencia de los directorios destinos - if (!System.IO.Directory.Exists(config.PathRaiz)) { Utiles.CrearDirectorio(config.PathRaiz); } - if (!System.IO.Directory.Exists(config.PathDTO)) { Utiles.CrearDirectorio(config.PathDTO); } - if (!System.IO.Directory.Exists(config.PathDAL)) { Utiles.CrearDirectorio(config.PathDAL); } - if (!System.IO.Directory.Exists(config.PathExtra)) { Utiles.CrearDirectorio(config.PathExtra); } + if (!Directory.Exists(config.PathRaiz)) { Utiles.CrearDirectorio(config.PathRaiz); } + if (!Directory.Exists(config.PathDTO)) { Utiles.CrearDirectorio(config.PathDTO); } + if (!Directory.Exists(config.PathDAL)) { Utiles.CrearDirectorio(config.PathDAL); } + if (!Directory.Exists(config.PathExtra)) { Utiles.CrearDirectorio(config.PathExtra); } // Itera por cada tabla para crear sus DTO y DAL foreach (TablaDesc t in database.Tablas) @@ -337,7 +339,7 @@ namespace ServerExplorer public string Str() { sb.Remove(0, sb.Length); - for (int i=0; i < indentado; i++) + for (int i = 0; i < indentado; i++) { sb.Append("\t"); } diff --git a/ServerExplorer/Config.cs b/ServerExplorer/Config.cs index b597e4e..a0f5f67 100644 --- a/ServerExplorer/Config.cs +++ b/ServerExplorer/Config.cs @@ -14,7 +14,7 @@ namespace ServerExplorer get { return pathRaiz; } set { pathRaiz = value; } } - public String pathDAL="."; + public String pathDAL = "."; public String PathDAL { get @@ -33,7 +33,8 @@ namespace ServerExplorer public String pathDTO = "."; public String PathDTO { - get { + get + { if (pathDTO == ".") { return pathRaiz; @@ -48,7 +49,8 @@ namespace ServerExplorer public String pathExtra = "."; public String PathExtra { - get { + get + { if (pathExtra == ".") { return pathRaiz; @@ -82,13 +84,13 @@ namespace ServerExplorer lector.Close(); return config; } - + } public class TablaInfo { - public String Esquema=""; - public String Nombre=""; + public String Esquema = ""; + public String Nombre = ""; public TablaInfo() { } public TablaInfo(String esquema, String nombre) @@ -97,5 +99,4 @@ namespace ServerExplorer Nombre = nombre; } } - -} +} \ No newline at end of file diff --git a/ServerExplorer/DatabaseDesc.cs b/ServerExplorer/DatabaseDesc.cs index 4dfe7c5..cde688b 100644 --- a/ServerExplorer/DatabaseDesc.cs +++ b/ServerExplorer/DatabaseDesc.cs @@ -16,6 +16,5 @@ namespace ServerExplorer { Nombre = nombre; } - } } diff --git a/ServerExplorer/DocGen.cs b/ServerExplorer/DocGen.cs index 2aca5c8..2ddd64d 100644 --- a/ServerExplorer/DocGen.cs +++ b/ServerExplorer/DocGen.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; +using ServerExplorer.Code; namespace ServerExplorer { @@ -11,15 +12,13 @@ namespace ServerExplorer public static void GenerarDocumentacion(Config config, DatabaseDesc database) { // Asegura la existencia de los directorios destinos - if (!System.IO.Directory.Exists(config.PathRaiz)) { Utiles.CrearDirectorio(config.PathRaiz); } - if (!System.IO.Directory.Exists(config.PathDTO)) { Utiles.CrearDirectorio(config.PathDTO); } - if (!System.IO.Directory.Exists(config.PathDAL)) { Utiles.CrearDirectorio(config.PathDAL); } - if (!System.IO.Directory.Exists(config.PathExtra)) { Utiles.CrearDirectorio(config.PathExtra); } - + if (!Directory.Exists(config.PathRaiz)) { Utiles.CrearDirectorio(config.PathRaiz); } + if (!Directory.Exists(config.PathDTO)) { Utiles.CrearDirectorio(config.PathDTO); } + if (!Directory.Exists(config.PathDAL)) { Utiles.CrearDirectorio(config.PathDAL); } + if (!Directory.Exists(config.PathExtra)) { Utiles.CrearDirectorio(config.PathExtra); } // Abrir el documento que contendra la documentacion - StreamWriter escritor=new StreamWriter(config.PathExtra+"/documentacion.html"); - + StreamWriter escritor = new StreamWriter(config.PathExtra + "/documentacion.html"); // Poner cabecera de la documentacion escritor.WriteLine("" + database.Nombre + ""); @@ -29,8 +28,8 @@ namespace ServerExplorer foreach (TablaDesc t in database.Tablas) { // Cabecera de la info de tabla - escritor.WriteLine("

"+t.Esquema+"."+t.Nombre+"

"); - + escritor.WriteLine("

" + t.Esquema + "." + t.Nombre + "

"); + // Iterar las columnas escritor.WriteLine(""); escritor.WriteLine(""); @@ -46,11 +45,9 @@ namespace ServerExplorer escritor.WriteLine("
NombreTipoTamañoPrimaria
"); } - // Poner pie y cerrar fichero escritor.WriteLine(""); escritor.Close(); - } } } diff --git a/ServerExplorer/Program.cs b/ServerExplorer/Program.cs index 56f343c..313b7fa 100644 --- a/ServerExplorer/Program.cs +++ b/ServerExplorer/Program.cs @@ -15,7 +15,7 @@ namespace ServerExplorer { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); - Application.Run(new frmPrincipal()); + Application.Run(new FrmPrincipal()); } } } diff --git a/ServerExplorer/ServerExplorer.csproj b/ServerExplorer/ServerExplorer.csproj index 56fb2a3..3e64951 100644 --- a/ServerExplorer/ServerExplorer.csproj +++ b/ServerExplorer/ServerExplorer.csproj @@ -73,72 +73,72 @@ - + Form - - frmBaseDatos.cs + + FrmBaseDatos.cs - + Form - - frmCodeGenConfig.cs + + FrmCodeGenConfig.cs - + Form - - frmDatos.cs + + FrmDatos.cs - + Form - - frmExec.cs + + FrmExec.cs - + Form - - frmPrincipal.cs + + FrmPrincipal.cs - + Form - - frmProcedimientos.cs + + FrmProcedimientos.cs - + Form - - frmServidores.cs + + FrmServidores.cs - - - frmBaseDatos.cs + + + FrmBaseDatos.cs - - frmCodeGenConfig.cs + + FrmCodeGenConfig.cs - - frmDatos.cs + + FrmDatos.cs - - frmExec.cs + + FrmExec.cs - - frmPrincipal.cs + + FrmPrincipal.cs - - frmProcedimientos.cs + + FrmProcedimientos.cs - - frmServidores.cs + + FrmServidores.cs ResXFileCodeGenerator @@ -177,6 +177,7 @@ true + - + \ No newline at end of file diff --git a/ServerExplorer/TablaDesc.cs b/ServerExplorer/TablaDesc.cs index 0fbb1ee..bbd7402 100644 --- a/ServerExplorer/TablaDesc.cs +++ b/ServerExplorer/TablaDesc.cs @@ -10,8 +10,8 @@ namespace ServerExplorer { public class TablaDesc { - public String Esquema=""; - public String Nombre=""; + public String Esquema = String.Empty; + public String Nombre = String.Empty; public List Columnas = new List(); public TablaDesc() { } @@ -56,11 +56,11 @@ namespace ServerExplorer " col.TABLE_SCHEMA=@nombreEsquema " + " order by col.ORDINAL_POSITION", cnx); - prm=new SqlParameter("@nombreTabla",SqlDbType.VarChar,100); - prm.Value=nombre; + prm = new SqlParameter("@nombreTabla", SqlDbType.VarChar, 100); + prm.Value = nombre; da.SelectCommand.Parameters.Add(prm); - prm=new SqlParameter("@nombreEsquema",SqlDbType.VarChar,100); - prm.Value=esquema; + prm = new SqlParameter("@nombreEsquema", SqlDbType.VarChar, 100); + prm.Value = esquema; da.SelectCommand.Parameters.Add(prm); // Obtener datatable con las columnas @@ -76,8 +76,8 @@ namespace ServerExplorer ColumnaDesc col; // Obtener columna - col=GetCol((String)dr["Columna"]); - if (col==null) + col = GetCol((String)dr["Columna"]); + if (col == null) { col = new ColumnaDesc(); Columnas.Add(col); @@ -115,8 +115,8 @@ namespace ServerExplorer public class ColumnaDesc { - public string Nombre = ""; - public string Tipo = ""; + public string Nombre = String.Empty; + public string Tipo = String.Empty; public int Tamanho = -1; public bool Primaria = false; @@ -125,7 +125,7 @@ namespace ServerExplorer private TipoCol tipo = TipoCol.Unset; public TipoCol GetTipo() { - string stipo=Tipo.ToLower(); + string stipo = Tipo.ToLower(); if (this.tipo != TipoCol.Unset) { @@ -133,12 +133,12 @@ namespace ServerExplorer } // Numericos - if( - stipo=="bigint" || - stipo=="int" || - stipo=="smallint" || - stipo=="tinyint" || - stipo=="bigint" + if ( + stipo == "bigint" || + stipo == "int" || + stipo == "smallint" || + stipo == "tinyint" || + stipo == "bigint" ) { return TipoCol.Numerico; @@ -147,7 +147,7 @@ namespace ServerExplorer // Aproximados numericos if ( stipo == "float" || - stipo == "real" + stipo == "real" ) { return TipoCol.AproxNumerico; @@ -173,7 +173,7 @@ namespace ServerExplorer stipo == "text" || stipo == "nchar" || stipo == "nvarchar" || - stipo == "ntext" + stipo == "ntext" ) { return TipoCol.Texto; @@ -183,7 +183,7 @@ namespace ServerExplorer if ( stipo == "binary" || stipo == "varbinary" || - stipo == "image" + stipo == "image" ) { return TipoCol.Binario; @@ -191,7 +191,7 @@ namespace ServerExplorer // Booleano if ( - stipo == "bit" + stipo == "bit" ) { return TipoCol.Booleano; diff --git a/ServerExplorer/frmBaseDatos.Designer.cs b/ServerExplorer/frmBaseDatos.Designer.cs index 6f9aeb1..0138010 100644 --- a/ServerExplorer/frmBaseDatos.Designer.cs +++ b/ServerExplorer/frmBaseDatos.Designer.cs @@ -1,6 +1,6 @@ namespace ServerExplorer { - partial class frmBaseDatos + partial class FrmBaseDatos { /// /// Required designer variable. diff --git a/ServerExplorer/frmBaseDatos.cs b/ServerExplorer/frmBaseDatos.cs index f3c6636..8d3fecd 100644 --- a/ServerExplorer/frmBaseDatos.cs +++ b/ServerExplorer/frmBaseDatos.cs @@ -13,9 +13,9 @@ using System.Threading; namespace ServerExplorer { - public partial class frmBaseDatos : Form + public partial class FrmBaseDatos : Form { - private frmBaseDatos instancia; + private FrmBaseDatos instancia; private SqlConnection cnx; private Config config; private String table_schema = null; @@ -67,7 +67,7 @@ namespace ServerExplorer // en le listview desde la configuracion private void tablas_alistview() { - int i,j,n; + int i, j, n; // Desmarcar todos en caso de no haber ninguna tabla if (config.Tablas.Count == 0) @@ -78,26 +78,27 @@ namespace ServerExplorer } // Recorrer items marcando los que estan en la configuracion - n=config.Tablas.Count; - i=j=0; + n = config.Tablas.Count; + 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. + do + { + if (config.Tablas[i].Esquema. CompareTo(item.SubItems[1].Text) == 0 && config.Tablas[i].Nombre. CompareTo(item.SubItems[0].Text) == 0) { - item.Checked=true; + item.Checked = true; break; } - i=(i+1)%n; - }while(i!=j); - j=i; + i = (i + 1) % n; + } while (i != j); + j = i; } } @@ -114,7 +115,7 @@ namespace ServerExplorer return (db); } - public frmBaseDatos(String ConString) + public FrmBaseDatos(String ConString) { InitializeComponent(); @@ -123,7 +124,7 @@ namespace ServerExplorer config.ConString = ConString; } - public frmBaseDatos(Config config) + public FrmBaseDatos(Config config) { InitializeComponent(); @@ -156,11 +157,11 @@ namespace ServerExplorer ListViewItem item = lsvTablas.SelectedItems[0]; // Recordar tabla seleccionada - table_schema=item.SubItems[1].Text.ToString(); + table_schema = item.SubItems[1].Text.ToString(); table_name = item.SubItems[0].Text.ToString(); // Establecer titulo de la lista de columnas - lblTituloTabla.Text=table_schema+"."+table_name; + lblTituloTabla.Text = table_schema + "." + table_name; // Obtener descripcion de tabla TablaDesc td = new TablaDesc(); @@ -172,7 +173,7 @@ namespace ServerExplorer { ListViewItem subitem = lsvColumnas.Items.Add(col.Nombre); subitem.SubItems.Add(col.Tipo); - if (col.Tamanho>=0) + if (col.Tamanho >= 0) { subitem.SubItems.Add(String.Format("{0}", col.Tamanho)); } @@ -215,11 +216,10 @@ namespace ServerExplorer private void menuConfiguracion_Click(object sender, EventArgs e) { // Llamar a la ventana de configuracion - frmCodeGenConfig frm = new frmCodeGenConfig(config); + FrmCodeGenConfig frm = new FrmCodeGenConfig(config); frm.ShowDialog(); } - private void btnVerDatos_Click(object sender, EventArgs e) { String nombreTabla; @@ -228,7 +228,7 @@ namespace ServerExplorer if (table_schema == null || table_name == null) { return; } - nombreTabla="["+table_schema+"].["+table_name+"]"; + nombreTabla = "[" + table_schema + "].[" + table_name + "]"; // Obtener un datatable con todos los registros de la tabla. da = new SqlDataAdapter( @@ -240,7 +240,7 @@ namespace ServerExplorer cnx.Close(); // Crear y mostrar el formulario de los datos. - frmDatos form = new frmDatos(dt, nombreTabla); + FrmDatos form = new FrmDatos(dt, nombreTabla); form.MdiParent = this.MdiParent; form.Show(); @@ -267,7 +267,7 @@ namespace ServerExplorer form.Show();*/ // Crear y mostrar el formulario de los procedimientos. - frmProcedimientos form = new frmProcedimientos(config.ConString); + FrmProcedimientos form = new FrmProcedimientos(config.ConString); form.MdiParent = this.MdiParent; form.Show(); } @@ -275,7 +275,7 @@ namespace ServerExplorer private void btnExec_Click(object sender, EventArgs e) { // Crear y mostrar el formulario de exec. - frmExec form = new frmExec(config.ConString); + FrmExec form = new FrmExec(config.ConString); form.MdiParent = this.MdiParent; form.Show(); } @@ -285,6 +285,7 @@ namespace ServerExplorer { } + private void btnGenerar_Click(object sender, EventArgs e) { tablas_delistview(); @@ -317,6 +318,7 @@ namespace ServerExplorer hilo.Start(); */ } + public void GenerarDoc() { // Hacer insensible la ventana @@ -336,6 +338,5 @@ namespace ServerExplorer { } - } } diff --git a/ServerExplorer/frmCodeGenConfig.Designer.cs b/ServerExplorer/frmCodeGenConfig.Designer.cs index 7a69703..f9401a3 100644 --- a/ServerExplorer/frmCodeGenConfig.Designer.cs +++ b/ServerExplorer/frmCodeGenConfig.Designer.cs @@ -1,6 +1,6 @@ namespace ServerExplorer { - partial class frmCodeGenConfig + partial class FrmCodeGenConfig { /// /// Required designer variable. @@ -275,7 +275,7 @@ this.Controls.Add(this.lblConString); this.Name = "frmCodeGenConfig"; this.Text = "Configuracion del Generador de Codigo"; - this.Load += new System.EventHandler(this.frmCodeGenConfig_Load); + this.Load += new System.EventHandler(this.FrmCodeGenConfig_Load); this.ResumeLayout(false); this.PerformLayout(); diff --git a/ServerExplorer/frmCodeGenConfig.cs b/ServerExplorer/frmCodeGenConfig.cs index 3d1314b..38f8255 100644 --- a/ServerExplorer/frmCodeGenConfig.cs +++ b/ServerExplorer/frmCodeGenConfig.cs @@ -9,26 +9,26 @@ using System.Windows.Forms; namespace ServerExplorer { - public partial class frmCodeGenConfig : Form + public partial class FrmCodeGenConfig : Form { - Config config; + Config _config; - public frmCodeGenConfig(Config config) + public FrmCodeGenConfig(Config config) { InitializeComponent(); - this.config = config; + _config = config; } - private void frmCodeGenConfig_Load(object sender, EventArgs e) + private void FrmCodeGenConfig_Load(object sender, EventArgs e) { - txtConString.Text = config.ConString; - txtPathRaiz.Text = config.PathRaiz; - txtPathDAL.Text = config.PathDAL; - txtPathDTO.Text = config.PathDTO; - txtPathExtra.Text = config.PathExtra; - txtNSDAL.Text = config.NamespaceDAL; - txtNSDTO.Text = config.NamespaceDTO; + txtConString.Text = _config.ConString; + txtPathRaiz.Text = _config.PathRaiz; + txtPathDAL.Text = _config.PathDAL; + txtPathDTO.Text = _config.PathDTO; + txtPathExtra.Text = _config.PathExtra; + txtNSDAL.Text = _config.NamespaceDAL; + txtNSDTO.Text = _config.NamespaceDTO; } private void btnPathRaiz_Click(object sender, EventArgs e) @@ -73,12 +73,12 @@ namespace ServerExplorer private void btnAceptar_Click(object sender, EventArgs e) { - config.PathRaiz = txtPathRaiz.Text; - config.PathDAL = txtPathDAL.Text; - config.PathDTO = txtPathDTO.Text; - config.PathExtra = txtPathExtra.Text; - config.NamespaceDAL = txtNSDAL.Text; - config.NamespaceDTO = txtNSDTO.Text; + _config.PathRaiz = txtPathRaiz.Text; + _config.PathDAL = txtPathDAL.Text; + _config.PathDTO = txtPathDTO.Text; + _config.PathExtra = txtPathExtra.Text; + _config.NamespaceDAL = txtNSDAL.Text; + _config.NamespaceDTO = txtNSDTO.Text; this.Close(); } diff --git a/ServerExplorer/frmDatos.Designer.cs b/ServerExplorer/frmDatos.Designer.cs index 1959858..94eb7a4 100644 --- a/ServerExplorer/frmDatos.Designer.cs +++ b/ServerExplorer/frmDatos.Designer.cs @@ -1,6 +1,6 @@ namespace ServerExplorer { - partial class frmDatos + partial class FrmDatos { /// /// Required designer variable. diff --git a/ServerExplorer/frmDatos.cs b/ServerExplorer/frmDatos.cs index d5e53dc..4541df3 100644 --- a/ServerExplorer/frmDatos.cs +++ b/ServerExplorer/frmDatos.cs @@ -9,24 +9,18 @@ using System.Windows.Forms; namespace ServerExplorer { - public partial class frmDatos : Form + public partial class FrmDatos : Form { - public frmDatos(DataTable dt,String titulo) + public FrmDatos(DataTable dt, String titulo) { InitializeComponent(); - this.Text = titulo; + Text = titulo; dgvDatos.DataSource = dt; } - private void frmDatos_Load(object sender, EventArgs e) - { + private void frmDatos_Load(object sender, EventArgs e) { } - } - - private void dgvDatos_CellContentClick(object sender, DataGridViewCellEventArgs e) - { - - } + private void dgvDatos_CellContentClick(object sender, DataGridViewCellEventArgs e) { } } } diff --git a/ServerExplorer/frmExec.Designer.cs b/ServerExplorer/frmExec.Designer.cs index ed4aac7..310c707 100644 --- a/ServerExplorer/frmExec.Designer.cs +++ b/ServerExplorer/frmExec.Designer.cs @@ -1,6 +1,6 @@ namespace ServerExplorer { - partial class frmExec + partial class FrmExec { /// /// Required designer variable. diff --git a/ServerExplorer/frmExec.cs b/ServerExplorer/frmExec.cs index e5c34b8..e593485 100644 --- a/ServerExplorer/frmExec.cs +++ b/ServerExplorer/frmExec.cs @@ -11,20 +11,21 @@ using System.Globalization; namespace ServerExplorer { - public partial class frmExec : Form + public partial class FrmExec : Form { private string cnxString; - public frmExec(string cnxString) + public FrmExec(string cnxString) { InitializeComponent(); this.cnxString = cnxString; } - private void frmExec_Load(object sender, EventArgs e){ - + private void frmExec_Load(object sender, EventArgs e) + { + } @@ -57,7 +58,7 @@ namespace ServerExplorer // Mostrar resultados dgvDatos.DataSource = dt; } - catch(Exception ex) + catch (Exception ex) { MessageBox.Show(ex.Message); } @@ -65,11 +66,11 @@ namespace ServerExplorer private void btnGenInserts_Click(object sender, EventArgs e) { - DataTable dt=new DataTable(); + DataTable dt = new DataTable(); DataTable ddt; string destname = String.Empty; NumberFormatInfo nfi = new NumberFormatInfo(); - + // Preparar un conversor de formato numerico que use puntos para los decimales nfi.NumberDecimalSeparator = "."; @@ -82,53 +83,54 @@ namespace ServerExplorer // Ejecutar consulta dt = Exec(); } - catch(Exception ex) + catch (Exception ex) { MessageBox.Show(ex.Message); } // Preparar la datatable destino - ddt=new DataTable(); + ddt = new DataTable(); ddt.Columns.Add("Comando", typeof(String)); - + // Recorrer la tabla de datos foreach (DataRow dr in dt.Rows) { - string strColumns=String.Empty; - string strValues=String.Empty; + string strColumns = String.Empty; + string strValues = String.Empty; foreach (DataColumn dc in dt.Columns) { // El nombre de la columna if (strColumns != String.Empty) - strColumns+=", "; + strColumns += ", "; strColumns += "[" + dc.ColumnName + "]"; // El valor de la columna if (strValues != String.Empty) - strValues+=", "; + strValues += ", "; object valor = dr[dc]; if (valor == DBNull.Value) { // NULOS strValues += "NULL"; - }else - if (dc.DataType.Name.ToLower() == "string") - { - // Cadenas - strValues += "'" + ((string)valor).Replace("'", "''") + "'"; } else - if (dc.DataType.Name.ToLower() == "decimal") - { - // Decimales - strValues += ((decimal)valor).ToString(nfi); - } - else - { - // Otros - strValues += valor.ToString(); - } + if (dc.DataType.Name.ToLower() == "string") + { + // Cadenas + strValues += "'" + ((string)valor).Replace("'", "''") + "'"; + } + else + if (dc.DataType.Name.ToLower() == "decimal") + { + // Decimales + strValues += ((decimal)valor).ToString(nfi); + } + else + { + // Otros + strValues += valor.ToString(); + } } // Insertar fila a la datatable destino diff --git a/ServerExplorer/frmPrincipal.Designer.cs b/ServerExplorer/frmPrincipal.Designer.cs index 79ae729..81f21ef 100644 --- a/ServerExplorer/frmPrincipal.Designer.cs +++ b/ServerExplorer/frmPrincipal.Designer.cs @@ -1,6 +1,6 @@ namespace ServerExplorer { - partial class frmPrincipal + partial class FrmPrincipal { /// /// Required designer variable. diff --git a/ServerExplorer/frmPrincipal.cs b/ServerExplorer/frmPrincipal.cs index 396723b..75addd1 100644 --- a/ServerExplorer/frmPrincipal.cs +++ b/ServerExplorer/frmPrincipal.cs @@ -9,9 +9,9 @@ using System.Windows.Forms; namespace ServerExplorer { - public partial class frmPrincipal : Form + public partial class FrmPrincipal : Form { - public frmPrincipal() + public FrmPrincipal() { InitializeComponent(); } @@ -19,7 +19,7 @@ namespace ServerExplorer 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"); + FrmBaseDatos 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"); frm.MdiParent = this; @@ -30,7 +30,7 @@ namespace ServerExplorer private void menuBuscarServidor_Click(object sender, EventArgs e) { // Mostrar ventana de buscador de servidores - frmServidores frm = new frmServidores(); + FrmServidores frm = new FrmServidores(); frm.MdiParent = this; frm.Show(); } @@ -44,7 +44,7 @@ namespace ServerExplorer Config config = Config.Cargar(dialogo.FileName); // Crear y mostrar ventana - frmBaseDatos frm = new frmBaseDatos(config); + FrmBaseDatos frm = new FrmBaseDatos(config); frm.MdiParent = this; frm.WindowState = FormWindowState.Maximized; frm.Show(); diff --git a/ServerExplorer/frmProcedimientos.Designer.cs b/ServerExplorer/frmProcedimientos.Designer.cs index de12fa9..9804168 100644 --- a/ServerExplorer/frmProcedimientos.Designer.cs +++ b/ServerExplorer/frmProcedimientos.Designer.cs @@ -1,6 +1,6 @@ namespace ServerExplorer { - partial class frmProcedimientos + partial class FrmProcedimientos { /// /// Required designer variable. diff --git a/ServerExplorer/frmProcedimientos.cs b/ServerExplorer/frmProcedimientos.cs index ca63deb..dc7a2e7 100644 --- a/ServerExplorer/frmProcedimientos.cs +++ b/ServerExplorer/frmProcedimientos.cs @@ -11,12 +11,12 @@ using System.Data.SqlClient; namespace ServerExplorer { - public partial class frmProcedimientos : Form + public partial class FrmProcedimientos : Form { private string cnxString; private SqlConnection cnx; - public frmProcedimientos(string cnxString) + public FrmProcedimientos(string cnxString) { InitializeComponent(); @@ -35,7 +35,7 @@ namespace ServerExplorer // Obtener un datatable con todos los procedimientos de la base de datos. da = new SqlDataAdapter( - "SELECT id,name,crdate,type FROM sysobjects "+ + "SELECT id,name,crdate,type FROM sysobjects " + "WHERE (UPPER(type) = 'P' OR UPPER(type) = 'TF' OR UPPER(type) = 'TR' OR UPPER(type) = 'V') AND category = 0 " + "ORDER BY name ", cnx); @@ -79,11 +79,11 @@ namespace ServerExplorer private void lsvProcs_SelectedIndexChanged(object sender, EventArgs e) { - if (lsvProcs.SelectedItems.Count>0 ) + if (lsvProcs.SelectedItems.Count > 0) { DataTable dt; SqlDataAdapter da; - int id=(int)lsvProcs.SelectedItems[0].Tag; + int id = (int)lsvProcs.SelectedItems[0].Tag; // Obtener un datatable con el contenido del procedimiento. da = new SqlDataAdapter( @@ -99,7 +99,7 @@ namespace ServerExplorer txtProc.Text = String.Empty; foreach (DataRow dr in dt.Rows) { - txtProc.Text += ((string)dr[0]).Replace("\r","").Replace("\n","\r\n"); + txtProc.Text += ((string)dr[0]).Replace("\r", "").Replace("\n", "\r\n"); } } diff --git a/ServerExplorer/frmServidores.Designer.cs b/ServerExplorer/frmServidores.Designer.cs index 9236ddb..ed1d4f7 100644 --- a/ServerExplorer/frmServidores.Designer.cs +++ b/ServerExplorer/frmServidores.Designer.cs @@ -1,6 +1,6 @@ namespace ServerExplorer { - partial class frmServidores + partial class FrmServidores { /// /// Required designer variable. diff --git a/ServerExplorer/frmServidores.cs b/ServerExplorer/frmServidores.cs index f4a9035..009db4b 100644 --- a/ServerExplorer/frmServidores.cs +++ b/ServerExplorer/frmServidores.cs @@ -12,9 +12,9 @@ using System.Data.SqlTypes; namespace ServerExplorer { - public partial class frmServidores : Form + public partial class FrmServidores : Form { - public frmServidores() + public FrmServidores() { InitializeComponent(); } @@ -62,7 +62,7 @@ namespace ServerExplorer if (lsvServidores.SelectedItems.Count > 0) { ListViewItem item = lsvServidores.SelectedItems[0]; - if (item.SubItems[1].Text.CompareTo("")==0) + if (item.SubItems[1].Text.CompareTo("") == 0) { // Servidor sin subinstancias txtServidor.Text = item.SubItems[0].Text; @@ -70,7 +70,7 @@ namespace ServerExplorer else { // Servidor con subinstancias - txtServidor.Text = item.SubItems[0].Text+"/"+item.SubItems[1].Text; + txtServidor.Text = item.SubItems[0].Text + "/" + item.SubItems[1].Text; } } } @@ -97,7 +97,7 @@ namespace ServerExplorer DataTable dt = cnx.GetSchema("Databases"); cnx.Close(); - + // Mostrar bases de datos lsvBBDD.Items.Clear(); foreach (DataRow dr in dt.Rows) @@ -127,7 +127,7 @@ namespace ServerExplorer } // Llamar a la venta de la base de datos - frmBaseDatos frm = new frmBaseDatos(constructor.ConnectionString); + FrmBaseDatos frm = new FrmBaseDatos(constructor.ConnectionString); frm.MdiParent = this.MdiParent; frm.Show(); }