protected void btnAgregar_Click(object sender, EventArgs e)
        {
            lblError.Text = "";
            Empleado emp;

            try
            {
                string   nombreusuario = txtUsername.Text;
                string   nombre        = txtNombre.Text;
                string   apelldio      = txtApelldio.Text;
                string   contrasena    = txtContrasena.Text;
                DateTime horainicio    = Convert.ToDateTime(ddlHoraInicio.SelectedValue);
                DateTime horafin       = Convert.ToDateTime(ddlHoraFin.SelectedValue);

                try
                {
                    emp = new Empleado(nombreusuario, contrasena, nombre, apelldio, horainicio, horafin);
                    Session["empleado"] = emp;
                    LogicaUsuario.Agregar(emp);
                }
                catch (Exception ex)
                {
                    lblError.Text = ex.Message;
                    return;
                }

                this.DesactivarA();
                this.ActivarBM();
            }
            catch (Exception ex)
            {
                lblError.Text = ex.Message;
            }
        }
 private void btnAceptar_Click(object sender, EventArgs e)
 {
     if (Validar())
     {
         Usuario usuario = mapearAUsuario();
         LogicaUsuario.Agregar(usuario);
         MessageBox.Show("Se agregó bien");
         this.Dispose();
     }
 }
Example #3
0
        public IActionResult Registrar(Usuario user)
        {
            var OneUser = logica.Agregar(user);

            if (user != null)
            {
                return(RedirectToAction("Home"));
            }

            return(View());
        }
Example #4
0
        protected void btnRegistrarse_Click(object sender, EventArgs e)
        {
            try
            {
                Cliente c = null;

                string nombreusuario = txtUsername.Text;
                string contrasena    = txtContraseña.Text;
                string nombre        = txtNombre.Text;
                string apellido      = txtApellido.Text;
                string direccion     = txtDireccion.Text;
                int    telefono      = Convert.ToInt32(txtTelefono.Text);

                c = new Cliente(nombreusuario, contrasena, nombre, apellido, direccion, telefono);
                LogicaUsuario.Agregar(c);
            }
            catch (Exception ex)
            {
                lblError.Text        = ex.Message;
                ImageButton1.Enabled = true;
                ImageButton1.Visible = true;
            }
        }
Example #5
0
        protected void btAgregarModal_Click(object sender, EventArgs e)
        {
            try
            {
                if (docAdmin.Text == "")
                {
                    lbError3.Text = ("ERROR: Ingrese un Documento.");
                    ClientScript.RegisterStartupScript(this.GetType(), "myScript", "<script>javascript: vpi();</script>");
                }

                if (agregarContrasenia.Text != agregarContraseniaConfirm.Text)
                {
                    lbError3.Text = "La contrasenia no coincide, vuelva a ingresarla";
                    ClientScript.RegisterStartupScript(this.GetType(), "myScript", "<script>javascript: vpi();</script>");
                }

                else
                {
                    Administrador nuevoAdmin = new Administrador();

                    nuevoAdmin.Documento     = Convert.ToInt32(docAdmin.Text);
                    nuevoAdmin.UsuarioNombre = usAdmin.Text;
                    nuevoAdmin.Nombre        = nombreAdmin.Text;
                    nuevoAdmin.Apellido      = apellidoAdmin.Text;
                    nuevoAdmin.Cargo         = Convert.ToInt32(ddlCargo.SelectedValue);

                    byte[] stringAByte = System.Text.ASCIIEncoding.ASCII.GetBytes(agregarContrasenia.Text);
                    string contrasenia = Convert.ToBase64String(stringAByte);
                    nuevoAdmin.Contrasenia = contrasenia;

                    int resultado = LogicaUsuario.Agregar(nuevoAdmin, Convert.ToInt32(ddlCargo.SelectedValue));

                    if (resultado == 2)
                    {
                        lbError.Text = "Administrador agregado..";
                        CargarGrilla();

                        ddlListar.SelectedIndex = 0;
                        docAdmin.Text           = "";
                        usAdmin.Text            = "";
                        nombreAdmin.Text        = "";
                        apellidoAdmin.Text      = "";
                    }

                    else if (resultado == 1)
                    {
                        lbError3.Text = " El Documento ingresado ya se encuentra registrado.";
                        ClientScript.RegisterStartupScript(this.GetType(), "myScript", "<script>javascript: vpi();</script>");
                    }

                    else
                    {
                        lbError3.Text = "No se ha agregado, éste usuario ya se encuentra registrado con otro Cargo..";
                        ClientScript.RegisterStartupScript(this.GetType(), "myScript", "<script>javascript: vpi();</script>");
                    }
                }
            }

            catch (Exception ex)
            {
                lbError3.Text = ex.Message;
                ClientScript.RegisterStartupScript(this.GetType(), "myScript", "<script>javascript: vpi();</script>");
            }
        }
    protected void imgbtnAgregar_Click(object sender, ImageClickEventArgs e)
    {
        try
        {
            int cedula;

            try
            {
                cedula = Convert.ToInt32(txtCedula.Text);
            }
            catch
            {
                throw new ExcepcionPresentacion("Ingrese una cédula válida, sin puntos ni guiones");
            }

            string nombreCompleto = null;

            if (txtNombreCompleto.Text != String.Empty)
            {
                nombreCompleto = txtNombreCompleto.Text;
            }

            string nombreUsuario = null;

            if (txtNombreUsuario.Text != String.Empty)
            {
                nombreUsuario = txtNombreUsuario.Text;
            }

            string contrasenia = null;

            if (txtContrasenia.Text != txtConfirmacion.Text)
            {
                throw new ExcepcionPresentacion("Las contraseñas no coinciden");
            }

            if (txtContrasenia.Text != String.Empty)
            {
                contrasenia = txtContrasenia.Text;
            }

            string direccion = null;

            if (txtDireccion.Text != String.Empty)
            {
                direccion = txtDireccion.Text;
            }

            long numeroTarjeta;

            try
            {
                numeroTarjeta = Convert.ToInt64(txtNroTarjeta.Text);
            }
            catch
            {
                throw new ExcepcionPresentacion("Ingrese número de tarjeta válido");
            }

            int telefono;

            try
            {
                telefono = Convert.ToInt32(txtTelefono.Text);
            }
            catch
            {
                throw new ExcepcionPresentacion("Ingrese número de teléfono válido");
            }
            string imagen = imgAvatar.ImageUrl;

            if (subirImagen.HasFile)
            {
                imagen = "~/uploads/usuarios/" + nombreUsuario + ".jpg";
            }

            bool Eliminado = false;


            try
            {
                if (subirImagen.HasFile)
                {
                    string imagenLocal = subirImagen.PostedFile.FileName;

                    string extension = imagenLocal.Substring(imagenLocal.Length - 4, 4);

                    if (extension.ToLower() != ".jpg" && extension.ToLower() != ".png" && extension.ToLower() != ".gif" && extension.ToLower() != ".jpeg")
                    {
                        throw new ExcepcionPresentacion("Formato de imagen no válido");
                    }

                    string imagenServidor = Server.MapPath("~/uploads/usuarios/") + nombreUsuario + ".jpg";

                    System.IO.File.Copy(imagenLocal, imagenServidor, true);
                }
            }

            catch (ApplicationException ex)
            {
                throw ex;
            }
            catch
            {
                throw new ExcepcionPresentacion("No se pudo subir el archivo.");
            }

            UsuarioRegistrado registrado = new UsuarioRegistrado(cedula, nombreCompleto, nombreUsuario, contrasenia, imagen, direccion, numeroTarjeta, telefono, Eliminado);

            UsuarioRegistrado registradoEliminado = (UsuarioRegistrado)LogicaUsuario.Buscar(cedula, false);

            if (registradoEliminado != null)
            {
                LogicaUsuario.Modificar(registrado);
            }
            else
            {
                LogicaUsuario.Agregar(registrado);
            }

            LimpiarFormulario();

            lblMensaje.ForeColor = System.Drawing.Color.Green;
            lblMensaje.CssClass  = "labelok";
            lblMensaje.Text      = "Usuario Agregado con éxito";
        }

        catch (ApplicationException ex)
        {
            lblMensaje.ForeColor = System.Drawing.Color.Red;
            lblMensaje.CssClass  = "labelerror";
            lblMensaje.Text      = "¡ERROR! " + ex.Message + ".";
        }

        catch
        {
            lblMensaje.ForeColor = System.Drawing.Color.Red;
            lblMensaje.CssClass  = "labelerror";
            lblMensaje.Text      = "Se produjo un error al agregar el usuario.";
        }
    }