Exemplo n.º 1
0
        private void button1_Click(object sender, EventArgs e)
        {
            Boolean hayErrores = validateInputs();

            if (hayErrores)
            {
                MessageBox.Show(mensajesDeError.ToString(), "", MessageBoxButtons.OK);
            }
            else
            {
                if (isEdit)
                {//editando un usuario
                    currentUsuario.nombre    = this.nombre.Text;
                    currentUsuario.apellido  = this.apellido.Text;
                    currentUsuario.dni       = this.dni.Text;
                    currentUsuario.direccion = this.direccion.Text;
                    currentUsuario.telefono  = this.telefono.Text;
                    currentUsuario.alias     = this.alias.Text;
                    currentUsuario.email     = this.email.Text;
                    currentUsuario.nombre    = this.nombre.Text;
                    currentUsuario.idioma    = ((KeyValuePair <Idioma, string>) this.comboBox1.SelectedItem).Key;

                    currentUsuario.componentePermisos = new List <ComponentePermiso>();
                    asociarPermisos(currentUsuario.componentePermisos);
                    bool error = false;
                    try
                    {
                        servicioSeguridad.modificarUsuario(currentUsuario);
                    }
                    catch (Exception exe)
                    {
                        error = true;
                        StringBuilder sb = new StringBuilder();


                        if (exe.Message == "PERMISOS")
                        {
                            sb.Append(traducciones["com.td.permisos.esenciales"]);
                        }
                        else if (exe.Message == "REPETIDOS")
                        {
                            sb.Append(traducciones["com.td.repetidos"]);
                        }
                        else
                        {
                            sb.Append(exe.Message);
                        }
                        MessageBox.Show(sb.ToString(), "", MessageBoxButtons.OK);
                    }
                    if (!error)
                    {
                        MessageBox.Show(traducciones["com.td.completado"], "", MessageBoxButtons.OK);
                        this.parentForm.listarDefault();
                        this.parentForm.desbloquearControles();
                        this.Close();
                    }
                }
                else
                {//creando uno nuevo
                    Usuario usuario = new Usuario();
                    usuario.nombre             = this.nombre.Text;
                    usuario.apellido           = this.apellido.Text;
                    usuario.dni                = this.dni.Text;
                    usuario.direccion          = this.direccion.Text;
                    usuario.telefono           = this.telefono.Text;
                    usuario.alias              = this.alias.Text;
                    usuario.email              = this.email.Text;
                    usuario.nombre             = this.nombre.Text;
                    usuario.componentePermisos = new List <ComponentePermiso>();
                    asociarPermisos(usuario.componentePermisos);
                    usuario.idioma = ((KeyValuePair <Idioma, string>) this.comboBox1.SelectedItem).Key;
                    bool error = false;
                    try
                    {
                        servicioSeguridad.crearUsuario(usuario);
                    }
                    catch (Exception exe)
                    {
                        error = true;
                        StringBuilder sb = new StringBuilder();


                        if (exe.Message == "PERMISOS")
                        {
                            sb.Append(traducciones["com.td.permisos.esenciales"]);
                        }
                        else if (exe.Message == "REPETIDOS")
                        {
                            sb.Append(traducciones["com.td.repetidos"]);
                        }
                        else
                        {
                            sb.Append(exe.Message);
                        }
                        MessageBox.Show(sb.ToString(), "", MessageBoxButtons.OK);
                    }
                    if (!error)
                    {
                        MessageBox.Show(traducciones["com.td.completado"], "", MessageBoxButtons.OK);
                        this.parentForm.listarDefault();
                        this.Close();
                    }
                }
            }
        }