En este caso como puedo hacer para validar en la capa logica que los campos no esten vacios ?, muchas gracias.
El primer codigo verifica que se ingresen letras, y el segundo que se ingresen numeros
(CAPA PRESENTACION)
Código:
namespace Presentacion.Controles
{
class ControlesValidaciones
{
public bool validarLetras(object sender, KeyPressEventArgs e)
{
if (Char.IsLetter(e.KeyChar))
{
e.Handled = false;
return false;
}
else if (Char.IsControl(e.KeyChar))
{
e.Handled = false;
return false;
}
else if (Char.IsSeparator(e.KeyChar))
{
e.Handled = false;
return false;
}
else
{
e.Handled = true;
return true;
}
}
Código:
en el formulario defino lo siguiente:public bool validarNumeros(object sender, KeyPressEventArgs e)
{
if (Char.IsDigit(e.KeyChar))
{
e.Handled = false;
return false;
}
else if (Char.IsControl(e.KeyChar))
{
e.Handled = false;
return false;
}
else if (Char.IsSeparator(e.KeyChar))
{
e.Handled = false;
return false;
}
else
{
e.Handled = true;
return true;
}
}
}
}
Código:
además yo uso una estructura de datos como Clientes, pero la tengo definida como entidad en un proyecto llamado Comunnamespace Presentacion
{
public partial class frmBancosAltas : Form
{
......................................
......................................
private bool validarCampos()
{
if ((textBox1.Text.Trim()) == String.Empty)
{
errorProvider1.SetError(textBox1, "Verificar Nombre de Banco");
return false;
}
if ((textBox2.Text.Trim()) == String.Empty)
{
errorProvider1.SetError(textBox2, "Verificar Direccion");
return false;
}
if ((textBox3.Text.Trim()) == String.Empty)
{
errorProvider1.SetError(textBox3, "Verificar Telefono");
return false;
}
else
{
return true;
}
}
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
Controles.ControlesValidaciones cv = new Controles.ControlesValidaciones();
if (cv.validarLetras(sender, e) == false)
{
errorProvider1.Clear();
toolStripStatusLabel1.Text = "";
}
}
private void textBox3_KeyPress(object sender, KeyPressEventArgs e)
{
Controles.ControlesValidaciones cv = new Controles.ControlesValidaciones();
if (cv.validarNumeros(sender, e) == false)
{
errorProvider1.Clear();
toolStripStatusLabel1.Text = "";
}
}
private void textBox2_KeyPress(object sender, KeyPressEventArgs e)
{
errorProvider1.Clear();
toolStripStatusLabel1.Text = "";
}
}
}
(ESTO PUEDE ESTAR EN LA CAPA DE LA LOGICA DE NEGOCIOS)
Código:
namespace Comun.Entidades
{
public class Clientes
{
private int nro_cliente;
private string nombre;
private string direccion;
private string telefono;
public int Nro_cliente
{
get { return this.nro_cliente; }
set { this.nro_cliente = value; }
}
public string Nombre
{
get { return this.nombre; }
set { this.nombre = value; }
}
public string Direccion
{
get { return this.direccion; }
set { this.direccion = value; }
}
public string Telefono
{
get { return this.telefono; }
set { this.telefono = value; }
}


