• No se han encontrado resultados

Ejercicio Registro Bancario

N/A
N/A
Protected

Academic year: 2022

Share "Ejercicio Registro Bancario"

Copied!
9
0
0

Texto completo

(1)

Ejercicio Registro Bancario

Atributo SelecectedIndex: Este atributo corresponde al número de índice seleccionado en un ComboBox. Los índices de ComboBox siempre se consideran desde el valor 0, la segunda opción tendrá valor de 1, la tercera valor de 2 y así sucesivamente

Variables públicas: Estas variables tienen un ámbito de alcance de todos los

procedimientos y subprocesos que están contenidos en el procedimiento donde fueron declaradas.

Variables locales: El ámbito de estas variables es únicamente el procedimiento o subproceso donde fueron declaradas

Atributo Enabled: Nos permite especificar si un control estara activado (true) o desactivado (false) durante la ejecución de una aplicación.

Evento KeyPress: Este se desencadena cuando el usuario pulsa una tecla. Permite especificar acciones que sucederán en el programa dependiendo de las teclas pulsadas por el usuario.

Clase Char: La clase Char nos permite acceder a funciones destinadas a manejar datos de tipo carácter, entre ellas tenemos:

IsDigit: Devuelve Verdadero si el carácter evaluado es un dígito

(2)

IsLetter: Devuelve Verdadero si el carácter evaluado es una letra IsWhiteSpace: Devuelve Verdadero si el carácter evaluado es un espacio en Blanco

Clase Keys: Permite acceder a las teclas del teclado, entre ellas tenemos:

Back: Tecla retroceso Alt: Tecla Alt

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;

namespace AppRegistroBancario {

public partial class FrmRegistro : Form {

//Definir variable para tamaño ID byte xTamID=0;

//Definir variable para tamaño de tipo de cuenta byte xTamCuenta=0;

//Variables para error bool xError1 = true;

bool xError2 = true;

bool xError3 = true;

bool xError4 = true;

bool xError5 = true;

public FrmRegistro() {

InitializeComponent();

}

private void LimpiarControles() {

//Limpiar controles

this.CboTipoID.SelectedIndex = 0;

this.CboTipoCuenta.SelectedIndex = 0;

this.TxtId.Text = "";

this.TxtNomCliente.Text = "";

this.TxtNroCuenta.Text = "";

}

(3)

private void FrmRegistro_Load(object sender, EventArgs e) {

}

private void CboTipoID_SelectedIndexChanged(object sender, EventArgs e) {

//Almacenar la opción seleccionada

//Cedula=10 digitos RUc= 13 digitos PASAPORTE=14 DIGITOS byte xTipoID;

xTipoID = Convert.ToByte(this.CboTipoID.SelectedIndex);

//Validar opción seleccionada if (xTipoID == 1) //Cédula {

xTamID = 10;

this.TxtId.Text = "";

this.TxtNomCliente.Clear();

this.TxtId.MaxLength = 10;

//Activar los textBox this.TxtId.Enabled = true;

this.TxtNomCliente.Enabled = true;

this.TxtId.Focus();

} else

if (xTipoID == 2) //RUC {

xTamID = 13;

this.TxtId.Text = "";

this.TxtNomCliente.Clear();

this.TxtId.MaxLength = 13;

//Activar los textBox this.TxtId.Enabled = true;

this.TxtNomCliente.Enabled = true;

this.TxtId.Focus();

} else

if (xTipoID == 3) //Pasaporte {

xTamID = 14;

this.TxtId.Text = "";

this.TxtNomCliente.Text = "";

this.TxtId.MaxLength = 14;

//Activar los textBox this.TxtId.Enabled = true;

this.TxtNomCliente.Enabled = true;

this.TxtId.Focus();

} else

(4)

{

xTamID = 0;

this.TxtId.Text = "";

this.TxtNomCliente.Clear();

this.TxtId.MaxLength = 0;

this.TxtId.Enabled = false;

this.TxtNomCliente.Enabled = false;

} }

private void CboTipoCuenta_SelectedIndexChanged(object sender, EventArgs e) {

//Cuenta de ahorros=8 digitos //Cuenta corriente = 11 digitos

//Capturar la opción seleccionada por el usuario byte xTipoCuenta;

xTipoCuenta = Convert.ToByte(this.CboTipoCuenta.SelectedIndex);

if (xTipoCuenta == 1) //ahorros {

xTamCuenta = 8;

this.TxtNroCuenta.Text = "";

this.TxtNroCuenta.MaxLength = 8;

this.TxtNroCuenta.Enabled = true;

this.TxtNroCuenta.Focus();

} else

if (xTipoCuenta == 2) //CORRIENTE {

xTamCuenta = 11;

this.TxtNroCuenta.Text = "";

this.TxtNroCuenta.MaxLength = 11;

this.TxtNroCuenta.Enabled = true;

this.TxtNroCuenta.Focus();

} else {

xTamCuenta = 0;

this.TxtNroCuenta.Text = "";

this.TxtNroCuenta.Enabled = false;

} }

private void TxtId_TextChanged(object sender, EventArgs e) {

}

private void TxtId_KeyPress(object sender, KeyPressEventArgs e) {

(5)

//Validar que solo se acepten digitos en el ID //Preguntar si es digito o la tecla retroceso

if (Char.IsDigit(e.KeyChar) || e.KeyChar==Convert.ToChar(Keys.Back)) {

e.Handled = false; //Aceptarlo }

else {

e.Handled = true; //Rechazar }

}

private void TxtNomCliente_TextChanged(object sender, EventArgs e) {

}

private void TxtNomCliente_KeyPress(object sender, KeyPressEventArgs e) {

//Permitir letras, espacio en blanco y retroceso if (Char.IsLetter(e.KeyChar) ||

Char.IsWhiteSpace(e.KeyChar)

|| e.KeyChar==Convert.ToChar(Keys.Back)) {

e.Handled = false; //aceptar caracter

} else {

e.Handled = true; //Rechazar caracter }

}

private void CmdLimpiar_Click(object sender, EventArgs e) {

//Limpiar controles this.LimpiarControles();

//Deshabilitar controles de entrada this.CboTipoID.Enabled = false;

this.CboTipoCuenta.Enabled = false;

this.TxtNomCliente.Enabled = false;

this.TxtId.Enabled = false;

this.TxtNroCuenta.Enabled = false;

//Habilite el boton nuevo

this.CmdNuevaCuenta.Enabled = true;

(6)

//Deshabilite los botones Validar y Limpiar this.CmdValidar.Enabled = false;

this.CmdLimpiar.Enabled = false;

}

private void CmdNuevaCuenta_Click(object sender, EventArgs e) {

//Limpiar controles this.LimpiarControles();

//Activar Combos

this.CboTipoID.Enabled = true;

this.CboTipoCuenta.Enabled = true;

//Activar Validar y Limpiar

this.CmdNuevaCuenta.Enabled = false;

this.CmdValidar.Enabled = true;

this.CmdLimpiar.Enabled = true;

this.CboTipoID.Focus();

}

private void CboTipoID_Validating(object sender, CancelEventArgs e) {

//Capturar opción seleccionada sbyte xTipoID;

xTipoID = (sbyte)this.CboTipoID.SelectedIndex;

//Validar si se escogio opción seleccione o ninguna if (xTipoID == 0 || xTipoID == -1)

{

this.errorProvider1.SetError(CboTipoID, @"Debe seleccionar el Tipo de ID");

this.CboTipoID.Focus();

xError1 = true;

return;

}

//Indicar acción cuando no hay error

this.errorProvider1.SetError(CboTipoID, "");

xError1 = false;

}

private void TxtId_Validating(object sender, CancelEventArgs e) {

//Capturar el id ingresado string xID;

xID = this.TxtId.Text.Trim();

//Validar que tenga el tamaño correcto

if (xID.Length!= xTamID ) {

(7)

this.errorProvider1.SetError(TxtId,

@"La identificación debe tener "+xTamID +" digitos");

this.TxtId.Focus();

xError2=true;

return;

}

//indicar acción si no hay error

this.errorProvider1.SetError(TxtId,"");

xError2=false;

}

private void CmdValidar_Click(object sender, EventArgs e) {

//Verificar si no hay errores en el ingreso de los datos if (xError1 || xError2 || xError3 || xError4 || xError5) {

MessageBox.Show("Hay errores en el formulario, por favor revisar");

return;

} else {

MessageBox.Show("Se registraron correctamente los datos");

//Deshabilitar controles de entrada this.CboTipoID.Enabled = false;

this.CboTipoCuenta.Enabled = false;

this.TxtId.Enabled = false;

this.TxtNomCliente.Enabled = false;

this.TxtNroCuenta.Enabled = false;

//Habilite el boton nuevo

this.CmdNuevaCuenta.Enabled = true;

//Deshabilite los botones Validar y Limpiar this.CmdValidar.Enabled = false;

this.CmdLimpiar.Enabled = false;

} }

private void TxtNomCliente_Validating(object sender, CancelEventArgs e) {

//Capturar nombre ingresado string xNomCliente;

xNomCliente = this.TxtNomCliente.Text.Trim();

//Validar un mínimo de tres caracteres if (xNomCliente.Length < 3)

{

this.errorProvider1.SetError(TxtNomCliente,

(8)

@"El nombre debe tener un mínimo de tres caracteres");

this.TxtNomCliente.Focus();

xError3 = true;

return;

}

//Acción si no hay error

this.errorProvider1.SetError(TxtNomCliente, "");

xError3 = false;

}

private void CboTipoCuenta_Validating(object sender, CancelEventArgs e) {

//Capturar tipo de cuenta seleccionada sbyte xTipoCuenta;

xTipoCuenta = (sbyte)this.CboTipoCuenta.SelectedIndex;

//Validar opción

if (xTipoCuenta == 0 || xTipoCuenta == -1) {

this.errorProvider1.SetError(CboTipoCuenta, @"Debe seleccionar el Tipo de cuenta");

this.CboTipoCuenta.Focus();

xError4 = true;

return;

}

//Acción si no hay error

this.errorProvider1.SetError(CboTipoCuenta,"");

xError4 = false;

}

private void TxtNroCuenta_Validating(object sender, CancelEventArgs e) {

//Capturar el dato ingresado string xNroCuenta;

xNroCuenta = this.TxtNroCuenta.Text.Trim();

//Validar tamaño correcto del número de cuenta if(xNroCuenta.Length!= xTamCuenta )

{

this.errorProvider1.SetError(TxtNroCuenta,

@"El número de cuenta debe tener " + xTamCuenta + " digitos");

this.TxtNroCuenta.Focus();

xError5 = true;

return;

}

//Acción si esta correcto

this.errorProvider1.SetError(TxtNroCuenta, "");

(9)

xError5 = false;

} } }

Referencias

Documento similar

Jerez (2017) desarrolló la tesis titulada “La comunicación educativa en la lecto - escritura de los estudiantes de tercer año de educación general básica de

Se determinó que si existe relación directa moderada y positiva entre las variables habilidades sociales y el rendimiento académico en su ámbito personal en los estudiantes de

Un equipo defiende y el otro tiene el balón en su poder.. Estos últimos, deberán recepcionar el balón dentro de un cuadrado para conseguir

1. LAS GARANTÍAS CONSTITUCIONALES.—2. C) La reforma constitucional de 1994. D) Las tres etapas del amparo argentino. F) Las vías previas al amparo. H) La acción es judicial en

Primeros ecos de la Revolución griega en España: Alberto Lista y el filohelenismo liberal conservador español 369 Dimitris Miguel Morfakidis Motos.. Palabras de clausura

El CFA es una herramienta estadística multivalente, que permite probar las posibles relaciones entre variables observadas y variables latentes (Suhr 2019); las

Se obtiene una ecuación resultante final donde el malestar psicológico guarda una relación directa con las variables neuroticismo (bajo-medio-alto), salud general (los