Refactorings

This commit is contained in:
2017-01-27 11:20:39 +01:00
parent 7983598bbe
commit ad041035f9
17 changed files with 101 additions and 305 deletions

View File

@@ -6,15 +6,19 @@ using ServerExplorer.Code.DataTransfer;
namespace ServerExplorer.Code.DataAccess
{
class DatabaseDA
public class DatabaseDA
{
public static List<Database> Database_GetRegs(string conexionString)
{
var databases = new List<Database>();
var cnx = new SqlConnection(conexionString);
cnx.Open();
DataTable dt = cnx.GetSchema("Databases");
cnx.Close();
dt.DefaultView.Sort = "database_name ASC, create_date ASC";
dt = dt.DefaultView.ToTable();
foreach (DataRow dr in dt.Rows)
{
databases.Add(new Database

View File

@@ -6,13 +6,17 @@ using ServerExplorer.Code.DataTransfer;
namespace ServerExplorer.Code.DataAccess
{
class ServerDA
public class ServerDA
{
public static List<Server> Server_GetRegs()
{
var servers = new List<Server>();
SqlDataSourceEnumerator enumerador = SqlDataSourceEnumerator.Instance;
DataTable dtServers = enumerador.GetDataSources();
dtServers.DefaultView.Sort = "ServerName ASC, InstanceName ASC, Version ASC";
dtServers = dtServers.DefaultView.ToTable();
foreach (DataRow dr in dtServers.Rows)
{
servers.Add(new Server

View File

@@ -1,11 +1,36 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using ServerExplorer.Code.DataTransfer;
namespace ServerExplorer.Code.DataAccess
{
class TableDA
public class TableDA
{
public static List<Table> Table_GetRegs(string conexionString)
{
var tables = new List<Table>();
var cnx = new SqlConnection(conexionString);
cnx.Open();
DataTable dt = cnx.GetSchema("Tables");
cnx.Close();
dt.DefaultView.Sort = "TABLE_SCHEMA ASC, TABLE_NAME ASC, TABLE_TYPE ASC";
dt = dt.DefaultView.ToTable();
// Mostrar todas las tablas
foreach (DataRow dr in dt.Rows)
{
tables.Add(new Table
{
Schema = (string)dr["TABLE_SCHEMA"],
Name = (string)dr["TABLE_NAME"],
Type = (string)dr["TABLE_TYPE"]
});
}
return tables;
}
}
}

View File

@@ -5,7 +5,7 @@ using System.Xml.Serialization;
namespace ServerExplorer.Code.DataTransfer
{
[Serializable]
class Column
public class Column
{
[XmlAttribute]
public string Name { get; set; }

View File

@@ -6,7 +6,7 @@ using System.Xml.Serialization;
namespace ServerExplorer.Code.DataTransfer
{
[Serializable]
class Database
public class Database
{
[XmlAttribute]
public string Name { get; set; }

View File

@@ -5,7 +5,7 @@ using System.Xml.Serialization;
namespace ServerExplorer.Code.DataTransfer
{
[Serializable]
internal class Server
public class Server
{
[XmlAttribute]
public string Name { get; set; }

View File

@@ -6,13 +6,14 @@ using System.Xml.Serialization;
namespace ServerExplorer.Code.DataTransfer
{
[Serializable]
class Table
public class Table
{
[XmlAttribute]
public string Schema { get; set; }
[XmlAttribute]
public string Name { get; set; }
[XmlAttribute]
public string Type { get; set; }
private readonly List<Column> _columns = new List<Column>();

View File

@@ -4,7 +4,7 @@ using System.Xml.Serialization;
namespace ServerExplorer.Code.DataTransfer
{
[Serializable]
class User
public class User
{
[XmlAttribute]
public bool ImplicitUser { get; set; }

View File

@@ -18,7 +18,7 @@ namespace ServerExplorer.Controls
[DllImport("User32.dll", CharSet = CharSet.Auto)]
private static extern IntPtr SendMessage(IntPtr h, int msg, int wParam, int[] lParam);
public void SetTabWidth(int tabWidth)
protected void SetTabWidth(int tabWidth)
{
SendMessage(this.Handle, EM_SETTABSTOPS, 1, new int[] { tabWidth * 4 });
}

View File

@@ -11,22 +11,22 @@ namespace ServerExplorer.Controls
{
#region Properties
private Form window = null;
private Form _window = null;
public Form Window
{
get { return window; }
set { window = value; }
get { return _window; }
set { _window = value; }
}
private bool active = false;
private bool _active = false;
public bool Active
{
get { return active; }
get { return _active; }
set
{
active = value;
_active = value;
//Font = active ? fntActive : fntNormal;
ForeColor = active ? Color.Black : Color.Gray;
ForeColor = _active ? Color.Black : Color.Gray;
}
}
@@ -47,8 +47,8 @@ namespace ServerExplorer.Controls
void WindowButton_Click(object sender, EventArgs e)
{
if (window == null) { return; }
window.Activate();
if (_window == null) { return; }
_window.Activate();
}
#endregion

View File

@@ -1,63 +0,0 @@
//------------------------------------------------------------------------------
// <auto-generated>
// Este código fue generado por una herramienta.
// Versión de runtime:4.0.30319.488
//
// Los cambios en este archivo podrían causar un comportamiento incorrecto y se perderán si
// se vuelve a generar el código.
// </auto-generated>
//------------------------------------------------------------------------------
namespace ServerExplorer.Properties {
using System;
/// <summary>
/// Clase de recurso con establecimiento inflexible de tipos, para buscar cadenas traducidas, etc.
/// </summary>
// StronglyTypedResourceBuilder generó automáticamente esta clase
// a través de una herramienta como ResGen o Visual Studio.
// Para agregar o quitar un miembro, edite el archivo .ResX y, a continuación, vuelva a ejecutar ResGen
// con la opción /str o vuelva a generar su proyecto de VS.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources {
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal Resources() {
}
/// <summary>
/// Devuelve la instancia de ResourceManager almacenada en caché utilizada por esta clase.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("ServerExplorer.Properties.Resources", typeof(Resources).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// Reemplaza la propiedad CurrentUICulture del subproceso actual para todas las
/// búsquedas de recursos mediante esta clase de recurso con establecimiento inflexible de tipos.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set {
resourceCulture = value;
}
}
}
}

View File

@@ -1,117 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@@ -1,26 +0,0 @@
//------------------------------------------------------------------------------
// <auto-generated>
// Este código fue generado por una herramienta.
// Versión de runtime:4.0.30319.488
//
// Los cambios en este archivo podrían causar un comportamiento incorrecto y se perderán si
// se vuelve a generar el código.
// </auto-generated>
//------------------------------------------------------------------------------
namespace ServerExplorer.Properties {
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "10.0.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
public static Settings Default {
get {
return defaultInstance;
}
}
}
}

View File

@@ -1,7 +0,0 @@
<?xml version='1.0' encoding='utf-8'?>
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)">
<Profiles>
<Profile Name="(Default)" />
</Profiles>
<Settings />
</SettingsFile>

View File

@@ -148,25 +148,6 @@
<EmbeddedResource Include="UI\FrmServidores.resx">
<DependentUpon>FrmServidores.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
<SubType>Designer</SubType>
</EmbeddedResource>
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
<DesignTime>True</DesignTime>
</Compile>
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
<Compile Include="Properties\Settings.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Settings.settings</DependentUpon>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">

View File

@@ -45,8 +45,8 @@
this.splitContainer1 = new System.Windows.Forms.SplitContainer();
this.btnRefresh = new System.Windows.Forms.Button();
this.lsvTablas = new ServerExplorer.Controls.CustomListView();
this.colNombreTabla = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.colEsquema = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.colNombreTabla = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.colTipo = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.lsvColumnas = new ServerExplorer.Controls.CustomListView();
this.colNombreColumna = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
@@ -83,13 +83,12 @@
//
// menuBaseDatos
//
this.menuBaseDatos.Dock = System.Windows.Forms.DockStyle.None;
this.menuBaseDatos.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.archivoToolStripMenuItem,
this.menuConfiguracion});
this.menuBaseDatos.Location = new System.Drawing.Point(7, 195);
this.menuBaseDatos.Location = new System.Drawing.Point(0, 0);
this.menuBaseDatos.Name = "menuBaseDatos";
this.menuBaseDatos.Size = new System.Drawing.Size(195, 24);
this.menuBaseDatos.Size = new System.Drawing.Size(806, 24);
this.menuBaseDatos.TabIndex = 9;
this.menuBaseDatos.Text = "menuBaseDatos";
this.menuBaseDatos.Visible = false;
@@ -100,6 +99,7 @@
this.archivoToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.menuCargar,
this.menuGuardar});
this.archivoToolStripMenuItem.MergeIndex = 0;
this.archivoToolStripMenuItem.Name = "archivoToolStripMenuItem";
this.archivoToolStripMenuItem.Size = new System.Drawing.Size(92, 20);
this.archivoToolStripMenuItem.Text = "Base de Datos";
@@ -107,14 +107,14 @@
// menuCargar
//
this.menuCargar.Name = "menuCargar";
this.menuCargar.Size = new System.Drawing.Size(116, 22);
this.menuCargar.Size = new System.Drawing.Size(152, 22);
this.menuCargar.Text = "Cargar";
this.menuCargar.Click += new System.EventHandler(this.menuCargar_Click);
//
// menuGuardar
//
this.menuGuardar.Name = "menuGuardar";
this.menuGuardar.Size = new System.Drawing.Size(116, 22);
this.menuGuardar.Size = new System.Drawing.Size(152, 22);
this.menuGuardar.Text = "Guardar";
this.menuGuardar.Click += new System.EventHandler(this.menuGuardar_Click);
//
@@ -231,7 +231,6 @@
this.splitContainer1.Panel2.Controls.Add(this.lblTituloTabla);
this.splitContainer1.Panel2.Controls.Add(this.btnDocGen);
this.splitContainer1.Panel2.Controls.Add(this.lsvColumnas);
this.splitContainer1.Panel2.Controls.Add(this.menuBaseDatos);
this.splitContainer1.Panel2.Controls.Add(this.btnGenerar);
this.splitContainer1.Panel2.Controls.Add(this.btnVerDatos);
this.splitContainer1.Size = new System.Drawing.Size(806, 511);
@@ -257,8 +256,8 @@
| System.Windows.Forms.AnchorStyles.Right)));
this.lsvTablas.CheckBoxes = true;
this.lsvTablas.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
this.colNombreTabla,
this.colEsquema,
this.colNombreTabla,
this.colTipo});
this.lsvTablas.FullRowSelect = true;
this.lsvTablas.Location = new System.Drawing.Point(3, 40);
@@ -270,15 +269,15 @@
this.lsvTablas.View = System.Windows.Forms.View.Details;
this.lsvTablas.SelectedIndexChanged += new System.EventHandler(this.lsvTablas_SelectedIndexChanged);
//
// colEsquema
//
this.colEsquema.Text = "Esquema";
//
// colNombreTabla
//
this.colNombreTabla.Text = "Tabla";
this.colNombreTabla.Width = 169;
//
// colEsquema
//
this.colEsquema.Text = "Esquema";
//
// colTipo
//
this.colTipo.Text = "Tipo";
@@ -346,6 +345,7 @@
this.Controls.Add(this.splitContainer1);
this.Controls.Add(this.btnCopiarConString);
this.Controls.Add(this.lblConString);
this.Controls.Add(this.menuBaseDatos);
this.Controls.Add(this.txtConString);
this.MainMenuStrip = this.menuBaseDatos;
this.Name = "FrmBaseDatos";
@@ -355,7 +355,6 @@
this.menuBaseDatos.PerformLayout();
this.splitContainer1.Panel1.ResumeLayout(false);
this.splitContainer1.Panel2.ResumeLayout(false);
this.splitContainer1.Panel2.PerformLayout();
this.splitContainer1.ResumeLayout(false);
this.ResumeLayout(false);
this.PerformLayout();

View File

@@ -4,6 +4,9 @@ using System.Windows.Forms;
using System.Data.SqlClient;
using System.Xml.Serialization;
using ServerExplorer.Code;
using System.Collections.Generic;
using ServerExplorer.Code.DataTransfer;
using ServerExplorer.Code.DataAccess;
namespace ServerExplorer.UI
{
@@ -20,22 +23,16 @@ namespace ServerExplorer.UI
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
List<Table> tables = TableDA.Table_GetRegs(_config.ConnectionString);
lsvTablas.Items.Clear();
foreach (DataRow dr in dt.Rows)
foreach (Table table in tables)
{
ListViewItem item = lsvTablas.Items.Add((String)dr["TABLE_NAME"]);
item.SubItems.Add((String)dr["TABLE_SCHEMA"]);
item.SubItems.Add((String)dr["TABLE_TYPE"]);
ListViewItem item = lsvTablas.Items.Add(table.Schema);
item.SubItems.Add(table.Name);
item.SubItems.Add(table.Type);
}
TablesToListView();
// Limpiar Columnas
TablesToListView();
lsvColumnas.Items.Clear();
}
@@ -51,8 +48,8 @@ namespace ServerExplorer.UI
{
_config.Tablas.Add(new TablaInfo
{
Esquema = item.SubItems[1].Text,
Nombre = item.SubItems[0].Text
Esquema = item.SubItems[0].Text,
Nombre = item.SubItems[1].Text
});
}
}
@@ -81,8 +78,8 @@ namespace ServerExplorer.UI
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)
if (String.Compare(_config.Tablas[i].Esquema, item.SubItems[0].Text, StringComparison.Ordinal) == 0 &&
String.Compare(_config.Tablas[i].Nombre, item.SubItems[1].Text, StringComparison.Ordinal) == 0)
{
item.Checked = true;
break;
@@ -120,8 +117,6 @@ namespace ServerExplorer.UI
_config = config;
}
private void frmBaseDatos_Load(object sender, EventArgs e)
{
Initialize();
@@ -145,8 +140,8 @@ namespace ServerExplorer.UI
ListViewItem item = lsvTablas.SelectedItems[0];
// Recordar tabla seleccionada
_tableSchema = item.SubItems[1].Text;
_tableName = item.SubItems[0].Text;
_tableSchema = item.SubItems[0].Text;
_tableName = item.SubItems[1].Text;
// Establecer titulo de la lista de columnas
lblTituloTabla.Text = _tableSchema + @"." + _tableName;