protected void Button1_Click(object sender, EventArgs e) { try { string usuario = txtUser.Text.Trim(); string nombre = txtNombre.Text.Trim(); string contraseña = txtContra.Text.Trim(); string direccion = txtDireccion.Text.Trim(); string tarjeta = txttarjeta.Text.Trim(); if (lstTel.Items.Count == 0) { throw new Exception("Debe cargar al menos un telefono."); } List <int> ListaTel = new List <int>(); for (int i = 0; lstTel.Items.Count > i; i++) { int telefono = 0; if (!int.TryParse(lstTel.Items[i].Value, out telefono)) { throw new Exception("El telefono no tiene forma numerica."); } if (telefono < 0) { throw new Exception("El telefono debe ser un numero positivo"); } ListaTel.Add(telefono); } Cliente cli = new Cliente(usuario, txtContra.Text, txtNombre.Text, txttarjeta.Text, txtDireccion.Text, ListaTel); LogicaUsuarios.Agregar(cli); lblmensaje.Text = ("Se ha agregado correctamente el cliente con el usuario " + usuario); AgregadoOK(); Session["cli"] = cli; //cargo el cliente en la session para usarlo mas tarde } catch (Exception ex) { lblmensaje.Text = ex.Message; } }
protected void btnAgregar_Click(object sender, EventArgs e) { try { string usuario = txtuser.Text.Trim(); string contraseña = txtpass.Text.Trim(); string nombre = txtnombre.Text.Trim(); string cargo = ddlCargos.SelectedValue; Administrador admin = new Administrador(usuario, txtpass.Text, txtnombre.Text, ddlCargos.SelectedValue); LogicaUsuarios.Agregar(admin); EstadoInicial(); lblMensaje.Text = ("Se ha Agregado correctamente el administrador con el usuario " + usuario); } catch (Exception ex) { lblMensaje.Text = ex.Message; } }