(2012-03-31)

This commit is contained in:
2012-03-31 00:00:00 +02:00
parent f7ebb8c065
commit ddbac16407
14 changed files with 139 additions and 8 deletions

Binary file not shown.

View File

@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.Serialization;
using System.Xml.Serialization;
namespace ServerExplorer
@@ -15,10 +14,7 @@ namespace ServerExplorer
public String PathExtra="";
public List<CodeGenTablaInfo> Tablas = new List<CodeGenTablaInfo>();
public CodeGenConfig()
{
// Nada
}
public CodeGenConfig() { }
public void Guardar(String fichero){
Type[] tipos={typeof(CodeGenTablaInfo)};

View File

@@ -95,6 +95,7 @@
</Compile>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="TablaDesc.cs" />
<EmbeddedResource Include="frmBaseDatos.resx">
<DependentUpon>frmBaseDatos.cs</DependentUpon>
</EmbeddedResource>

View File

@@ -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<ColumnaDesc> Columnas = new List<ColumnaDesc>();
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() { }
}
}

View File

@@ -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);
}
}

View File

@@ -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();

View File

@@ -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