86 lines
2.9 KiB
C#
86 lines
2.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data.SqlClient;
|
|
using System.Windows.Forms;
|
|
using ServerExplorer.Code.DataAccess;
|
|
using ServerExplorer.Code.DataTransfer;
|
|
|
|
namespace ServerExplorer.UI
|
|
{
|
|
public partial class FrmServidores : Form
|
|
{
|
|
public FrmServidores()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
private void btnListarServidores_Click(object sender, EventArgs e)
|
|
{
|
|
List<Server> servers = ServerDA.Server_GetRegs();
|
|
|
|
lsvServidores.Items.Clear();
|
|
lsvBBDD.Items.Clear();
|
|
foreach (Server server in servers)
|
|
{
|
|
ListViewItem item = lsvServidores.Items.Add(server.Name);
|
|
item.SubItems.Add(server.Instance);
|
|
item.SubItems.Add(server.Version);
|
|
}
|
|
}
|
|
|
|
private void lsvServidores_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
if (lsvServidores.SelectedItems.Count > 0)
|
|
{
|
|
ListViewItem item = lsvServidores.SelectedItems[0];
|
|
txtServidor.Text = String.IsNullOrEmpty(item.SubItems[1].Text)
|
|
? item.SubItems[0].Text
|
|
: String.Format("{0}/{1}", item.SubItems[0].Text, item.SubItems[1].Text);
|
|
}
|
|
}
|
|
|
|
private void btnListarBBDD_Click(object sender, EventArgs e)
|
|
{
|
|
List<Database> databases = DatabaseDA.Database_GetRegs(BuildConnectionString());
|
|
|
|
lsvBBDD.Items.Clear();
|
|
foreach (Database database in databases)
|
|
{
|
|
ListViewItem item = lsvBBDD.Items.Add(database.Name);
|
|
item.SubItems.Add(database.CreateDate.ToShortDateString());
|
|
}
|
|
}
|
|
|
|
|
|
private void lsvBBDD_DoubleClick(object sender, EventArgs e)
|
|
{
|
|
if (lsvBBDD.SelectedItems.Count != 1) return;
|
|
|
|
// Llamar a la venta de la base de datos
|
|
var frm = new FrmBaseDatos(BuildConnectionString());
|
|
FrmPrincipal.AddForm(frm);
|
|
}
|
|
|
|
private string BuildConnectionString()
|
|
{
|
|
// Construir cadena de conexion
|
|
var constructor = new SqlConnectionStringBuilder();
|
|
constructor.DataSource = (!string.IsNullOrEmpty(txtServidor.Text)) ? txtServidor.Text : "localhost";
|
|
if (lsvBBDD.SelectedItems.Count > 0)
|
|
{
|
|
constructor.InitialCatalog = lsvBBDD.SelectedItems[0].SubItems[0].Text;
|
|
}
|
|
if (String.IsNullOrEmpty(txtUsuario.Text))
|
|
{
|
|
constructor.IntegratedSecurity = true;
|
|
}
|
|
else
|
|
{
|
|
constructor.UserID = txtUsuario.Text;
|
|
constructor.Password = TxtContrasenha.Text;
|
|
}
|
|
return constructor.ConnectionString;
|
|
}
|
|
}
|
|
}
|