diff --git a/ServerExplorer/ServerExplorer.suo b/ServerExplorer/ServerExplorer.suo index ab4ae6d..4437704 100644 Binary files a/ServerExplorer/ServerExplorer.suo and b/ServerExplorer/ServerExplorer.suo differ diff --git a/ServerExplorer/ServerExplorer/CodeGenConfig.cs b/ServerExplorer/ServerExplorer/CodeGenConfig.cs index 080cf2b..cde384b 100644 --- a/ServerExplorer/ServerExplorer/CodeGenConfig.cs +++ b/ServerExplorer/ServerExplorer/CodeGenConfig.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.IO; -using System.Runtime.Serialization; using System.Xml.Serialization; namespace ServerExplorer @@ -14,11 +13,8 @@ namespace ServerExplorer public String PathDTO=""; public String PathExtra=""; public List Tablas = new List(); - - public CodeGenConfig() - { - // Nada - } + + public CodeGenConfig() { } public void Guardar(String fichero){ Type[] tipos={typeof(CodeGenTablaInfo)}; diff --git a/ServerExplorer/ServerExplorer/ServerExplorer.csproj b/ServerExplorer/ServerExplorer/ServerExplorer.csproj index 6f575b8..7c2f653 100644 --- a/ServerExplorer/ServerExplorer/ServerExplorer.csproj +++ b/ServerExplorer/ServerExplorer/ServerExplorer.csproj @@ -95,6 +95,7 @@ + frmBaseDatos.cs @@ -152,4 +153,4 @@ --> - + \ No newline at end of file diff --git a/ServerExplorer/ServerExplorer/TablaDesc.cs b/ServerExplorer/ServerExplorer/TablaDesc.cs new file mode 100644 index 0000000..5b4ecfe --- /dev/null +++ b/ServerExplorer/ServerExplorer/TablaDesc.cs @@ -0,0 +1,114 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Data; +using System.Data.Sql; +using System.Data.SqlClient; + +namespace ServerExplorer +{ + public class TablaDesc + { + public String Esquema=""; + public String Nombre=""; + public List Columnas = new List(); + + public TablaDesc() { } + + // Obtener una columna existente + private ColumnaDesc GetCol(String nombre) + { + foreach (ColumnaDesc col in Columnas) + { + if (col.Nombre.CompareTo(nombre) == 0) + { + return (col); + } + } + return null; + } + + public void FillDesc(String esquema, String nombre, SqlConnection cnx) + { + SqlParameter prm; + DataTable dt; + SqlDataAdapter da; + + // establecer esquema y nombre + Esquema = esquema; + Nombre = nombre; + + // Preparar comando y parametros + da = new SqlDataAdapter( + "select col.COLUMN_NAME as Columna, " + + " col.DATA_TYPE as Tipo, " + + " col.CHARACTER_MAXIMUM_LENGTH as Tamanho, " + + " c.CONSTRAINT_TYPE as TipoClave " + + " from INFORMATION_SCHEMA.COLUMNS as col " + + " left join INFORMATION_SCHEMA.KEY_COLUMN_USAGE as k " + + " on col.COLUMN_NAME=k.COLUMN_NAME and " + + " col.TABLE_NAME=k.TABLE_NAME and " + + " col.TABLE_SCHEMA=k.TABLE_SCHEMA " + + " left join INFORMATION_SCHEMA.TABLE_CONSTRAINTS as c " + + " on k.CONSTRAINT_NAME=c.CONSTRAINT_NAME " + + " WHERE col.TABLE_NAME=@nombreTabla AND " + + " col.TABLE_SCHEMA=@nombreEsquema " + + " order by col.ORDINAL_POSITION", + cnx); + 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; + da.SelectCommand.Parameters.Add(prm); + + // Obtener datatable con las columnas + dt = new DataTable(); + cnx.Open(); + da.Fill(dt); + cnx.Close(); + + // Recorrer datatable estableciendo la lista de columnas + Columnas.Clear(); + foreach (DataRow dr in dt.Rows) + { + ColumnaDesc col; + + // Obtener columna + col=GetCol((String)dr["Columna"]); + if (col==null) + { + col = new ColumnaDesc(); + Columnas.Add(col); + } + + // Establecer datos de la columna + col.Nombre = (String)dr["Columna"]; + col.Tipo = (String)dr["Tipo"]; + if (dr["Tamanho"] != DBNull.Value) + { + col.Tamanho = (int)dr["Tamanho"]; + } + col.Primaria = false; + if (dr["TipoClave"] != DBNull.Value) + { + if (((String)dr["TipoClave"]).CompareTo("PRIMARY_KEY") == 0) + { + col.Primaria = true; + } + } + } + } + } + + public class ColumnaDesc + { + public String Nombre = ""; + public String Tipo = ""; + public int Tamanho = -1; + public bool Primaria = false; + + public ColumnaDesc() { } + } +} diff --git a/ServerExplorer/ServerExplorer/bin/Debug/ServerExplorer.exe b/ServerExplorer/ServerExplorer/bin/Debug/ServerExplorer.exe index 1fa4d4a..e59eeac 100644 Binary files a/ServerExplorer/ServerExplorer/bin/Debug/ServerExplorer.exe and b/ServerExplorer/ServerExplorer/bin/Debug/ServerExplorer.exe differ diff --git a/ServerExplorer/ServerExplorer/bin/Debug/ServerExplorer.pdb b/ServerExplorer/ServerExplorer/bin/Debug/ServerExplorer.pdb index 2c91f7f..20f61e6 100644 Binary files a/ServerExplorer/ServerExplorer/bin/Debug/ServerExplorer.pdb and b/ServerExplorer/ServerExplorer/bin/Debug/ServerExplorer.pdb differ diff --git a/ServerExplorer/ServerExplorer/frmBaseDatos.cs b/ServerExplorer/ServerExplorer/frmBaseDatos.cs index 644aafa..857d791 100644 --- a/ServerExplorer/ServerExplorer/frmBaseDatos.cs +++ b/ServerExplorer/ServerExplorer/frmBaseDatos.cs @@ -8,6 +8,7 @@ using System.Text; using System.Windows.Forms; using System.Data.Sql; using System.Data.SqlClient; +using System.Xml.Serialization; namespace ServerExplorer { @@ -203,6 +204,12 @@ namespace ServerExplorer } } + TablaDesc td = new TablaDesc(); + td.FillDesc(item.SubItems[1].Text,item.SubItems[0].Text,cnx); + Type[] tipos = { typeof(ColumnaDesc) }; + XmlSerializer seriador = new XmlSerializer(typeof(TablaDesc),tipos); + seriador.Serialize(System.Console.Out, td); + } } diff --git a/ServerExplorer/ServerExplorer/frmPrincipal.cs b/ServerExplorer/ServerExplorer/frmPrincipal.cs index 4c69926..9437242 100644 --- a/ServerExplorer/ServerExplorer/frmPrincipal.cs +++ b/ServerExplorer/ServerExplorer/frmPrincipal.cs @@ -20,7 +20,8 @@ namespace ServerExplorer { // 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=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"); frm.MdiParent = this; frm.WindowState = FormWindowState.Maximized; frm.Show(); diff --git a/ServerExplorer/ServerExplorer/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache b/ServerExplorer/ServerExplorer/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache index a7a358c..66a5136 100644 Binary files a/ServerExplorer/ServerExplorer/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache and b/ServerExplorer/ServerExplorer/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache differ diff --git a/ServerExplorer/ServerExplorer/obj/Debug/ResGen.read.1.tlog b/ServerExplorer/ServerExplorer/obj/Debug/ResGen.read.1.tlog index 5fdcbd3..3af54e4 100644 Binary files a/ServerExplorer/ServerExplorer/obj/Debug/ResGen.read.1.tlog and b/ServerExplorer/ServerExplorer/obj/Debug/ResGen.read.1.tlog differ diff --git a/ServerExplorer/ServerExplorer/obj/Debug/ResGen.write.1.tlog b/ServerExplorer/ServerExplorer/obj/Debug/ResGen.write.1.tlog index d1fec80..b4133fa 100644 Binary files a/ServerExplorer/ServerExplorer/obj/Debug/ResGen.write.1.tlog and b/ServerExplorer/ServerExplorer/obj/Debug/ResGen.write.1.tlog differ diff --git a/ServerExplorer/ServerExplorer/obj/Debug/ServerExplorer.csproj.FileListAbsolute.txt b/ServerExplorer/ServerExplorer/obj/Debug/ServerExplorer.csproj.FileListAbsolute.txt index d25bfac..7d0118f 100644 --- a/ServerExplorer/ServerExplorer/obj/Debug/ServerExplorer.csproj.FileListAbsolute.txt +++ b/ServerExplorer/ServerExplorer/obj/Debug/ServerExplorer.csproj.FileListAbsolute.txt @@ -20,3 +20,15 @@ C:\Users\val\Desktop\ServerExplorer\ServerExplorer\obj\Debug\ServerExplorer.Prop C:\Users\val\Desktop\ServerExplorer\ServerExplorer\obj\Debug\ResGen.read.1.tlog C:\Users\val\Desktop\ServerExplorer\ServerExplorer\obj\Debug\ResGen.write.1.tlog C:\Users\val\Desktop\ServerExplorer\ServerExplorer\obj\Debug\ServerExplorer.frmCodeGenConfig.resources +C:\Users\var\Desktop\ServerExplorer\ServerExplorer\obj\Debug\ServerExplorer.exe +C:\Users\var\Desktop\ServerExplorer\ServerExplorer\obj\Debug\ServerExplorer.pdb +C:\Users\var\Desktop\ServerExplorer\ServerExplorer\bin\Debug\ServerExplorer.exe +C:\Users\var\Desktop\ServerExplorer\ServerExplorer\bin\Debug\ServerExplorer.pdb +C:\Users\var\Desktop\ServerExplorer\ServerExplorer\obj\Debug\ResolveAssemblyReference.cache +C:\Users\var\Desktop\ServerExplorer\ServerExplorer\obj\Debug\ServerExplorer.frmBaseDatos.resources +C:\Users\var\Desktop\ServerExplorer\ServerExplorer\obj\Debug\ServerExplorer.frmCodeGenConfig.resources +C:\Users\var\Desktop\ServerExplorer\ServerExplorer\obj\Debug\ServerExplorer.frmPrincipal.resources +C:\Users\var\Desktop\ServerExplorer\ServerExplorer\obj\Debug\ServerExplorer.frmServidores.resources +C:\Users\var\Desktop\ServerExplorer\ServerExplorer\obj\Debug\ServerExplorer.Properties.Resources.resources +C:\Users\var\Desktop\ServerExplorer\ServerExplorer\obj\Debug\ResGen.read.1.tlog +C:\Users\var\Desktop\ServerExplorer\ServerExplorer\obj\Debug\ResGen.write.1.tlog diff --git a/ServerExplorer/ServerExplorer/obj/Debug/ServerExplorer.exe b/ServerExplorer/ServerExplorer/obj/Debug/ServerExplorer.exe index 1fa4d4a..e59eeac 100644 Binary files a/ServerExplorer/ServerExplorer/obj/Debug/ServerExplorer.exe and b/ServerExplorer/ServerExplorer/obj/Debug/ServerExplorer.exe differ diff --git a/ServerExplorer/ServerExplorer/obj/Debug/ServerExplorer.pdb b/ServerExplorer/ServerExplorer/obj/Debug/ServerExplorer.pdb index 2c91f7f..20f61e6 100644 Binary files a/ServerExplorer/ServerExplorer/obj/Debug/ServerExplorer.pdb and b/ServerExplorer/ServerExplorer/obj/Debug/ServerExplorer.pdb differ