Académique Documents
Professionnel Documents
Culture Documents
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;
namespace CapaDatos
{
public class DCondominio
{
private int _IdCondominio;
private string _Nombre_Condominio;
private string _Direccion;
private string _Telefono;
//Constructor Vacío
public DCondominio()
{
//Metodo Insertar
public string Insertar(DCondominio Condominio)
{
string rpta = "";
SqlConnection SqlCon = new SqlConnection();
try
{
//Código
SqlCon.ConnectionString = Conexion.Cn;
SqlCon.Open();
//Establecer el Comando
SqlCommand SqlCmd = new SqlCommand();
SqlCmd.Connection = SqlCon;
SqlCmd.CommandText = "spinsertar_Condominio";
SqlCmd.CommandType = CommandType.StoredProcedure;
//Metodo Editar
public string Editar(DCondominio Condominio)
{
string rpta = "";
SqlConnection SqlCon = new SqlConnection();
try
{
//Código
SqlCon.ConnectionString = Conexion.Cn;
SqlCon.Open();
//Establecer el Comando
SqlCommand SqlCmd = new SqlCommand();
SqlCmd.Connection = SqlCon;
SqlCmd.CommandText = "speditar_Condominio";
SqlCmd.CommandType = CommandType.StoredProcedure;
//Metodo Eliminar
public string Eliminar(DCondominio Condominio)
{
string rpta = "";
SqlConnection SqlCon = new SqlConnection();
try
{
//Código
SqlCon.ConnectionString = Conexion.Cn;
SqlCon.Open();
//Establecer el Comando
SqlCommand SqlCmd = new SqlCommand();
SqlCmd.Connection = SqlCon;
SqlCmd.CommandText = "speliminar_Condominio";
SqlCmd.CommandType = CommandType.StoredProcedure;
//Metodo Mostrar
public DataTable Mostrar()
{
DataTable DtResultado = new DataTable("Condominio");
SqlConnection SqlCon = new SqlConnection();
try
{
SqlCon.ConnectionString = Conexion.Cn;
SqlCommand SqlCmd = new SqlCommand();
SqlCmd.Connection = SqlCon;
SqlCmd.CommandText = "spmostrar_Condominio";
SqlCmd.CommandType = CommandType.StoredProcedure;
//Metodo BuscarNombre_Condominio
public DataTable BuscarNombre_Condominio (DCondominio Condominio)
{
DataTable DtResultado = new DataTable("Condominio");
SqlConnection SqlCon = new SqlConnection();
try
{
SqlCon.ConnectionString = Conexion.Cn;
SqlCommand SqlCmd = new SqlCommand();
SqlCmd.Connection = SqlCon;
SqlCmd.CommandText = "spbuscar_Condominio";
SqlCmd.CommandType = CommandType.StoredProcedure;
using CapaDatos;
using System.Data;
namespace CapaNegocio
{
public class NCondominio
{
//Método Insertar que llama al método Insertar de la clase DCondominio
//de la CapaDatos
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using CapaNegocio;
namespace CapaPresentacion
{
public partial class FrmCondominio : Form
{
private bool IsNuevo = false;
}
//Método para ocultar columnas
private void OcultarColumnas()
{
this.dataListado.Columns[0].Visible = false;
this.dataListado.Columns[1].Visible = false;
}
//Método Mostrar
private void Mostrar()
{
this.dataListado.DataSource = NCondominio.Mostrar();
this.OcultarColumnas();
lblTotal.Text = "Total de Registros: " +
Convert.ToString(dataListado.Rows.Count);
}
//Método BuscarNombre
private void BuscarNombre()
{
this.dataListado.DataSource =
NCondominio.BuscarNombre_Condominio(this.txtBuscar.Text);
this.OcultarColumnas();
lblTotal.Text = "Total de Registros: " +
Convert.ToString(dataListado.Rows.Count);
}
private void FrmCondominio_Load(object sender, EventArgs e)
{
this.Top = 0;
this.Left = 0;
this.Mostrar();
this.Habilitar(false);
this.Botones();
}
}
else
{
rpta =
NCondominio.Editar(Convert.ToInt32(this.txtIdcondominio.Text),
this.txtNombre.Text.Trim().ToUpper(),
this.txtDireccion.Text.Trim().ToUpper(),
this.txtTelefono.Text.Trim()
);
}
if (rpta.Equals("OK"))
{
if (this.IsNuevo)
{
this.MensajeOk("Se Insertó de forma correcta el
registro");
}
else
{
this.MensajeOk("Se Actualizó de forma correcta el
registro");
}
}
else
{
this.MensajeError(rpta);
}
this.IsNuevo = false;
this.IsEditar = false;
this.Botones();
this.Limpiar();
this.Mostrar();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message + ex.StackTrace);
}
}
this.tabControl1.SelectedIndex = 1;
}
if (Opcion == DialogResult.OK)
{
string Codigo;
string Rpta = "";
if (Rpta.Equals("OK"))
{
this.MensajeOk("Se Eliminó Correctamente el
registro");
}
else
{
this.MensajeError(Rpta);
}
}
}
this.Mostrar();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message + ex.StackTrace);
}
}