Ejemplo n.º 1
0
        public static List <Usuario> GetUsuarioListForSearch(string whereSql)
        {
            if (string.IsNullOrEmpty(whereSql))
            {
                whereSql = "1 = 1";
            }

            List <Usuario>      theList    = new List <Usuario>();
            Usuario             theUser    = null;
            UsuarioTableAdapter theAdapter = new UsuarioTableAdapter();

            try
            {
                UsuarioDS.UsuarioDataTable table = theAdapter.GetUsuarioForSearch(whereSql);

                if (table != null && table.Rows.Count > 0)
                {
                    foreach (UsuarioDS.UsuarioRow row in table.Rows)
                    {
                        theUser = FillUserRecord(row);
                        theList.Add(theUser);
                    }
                }
            }
            catch (Exception q)
            {
                log.Error("el error ocurrio mientras obtenia la lista de los usuarios de la base de datos", q);
                return(null);
            }
            return(theList);
        }
Ejemplo n.º 2
0
        public static Usuario GetUserById(int IdUser)
        {
            UsuarioTableAdapter localAdapter = new UsuarioTableAdapter();

            if (IdUser <= 0)
            {
                return(null);
            }

            Usuario theUser = null;

            try
            {
                UsuarioDS.UsuarioDataTable table = localAdapter.GetUsuarioById(IdUser);

                if (table != null && table.Rows.Count > 0)
                {
                    UsuarioDS.UsuarioRow row = table[0];
                    theUser = FillUserRecord(row);
                }
            }
            catch (Exception q)
            {
                log.Error("An error was ocurred while geting user data", q);
                return(null);
            }

            return(theUser);
        }
Ejemplo n.º 3
0
    public static int insertUsuario(Usuario obj)
    {
        if (string.IsNullOrEmpty(obj.nombreCompleto))
        {
            throw new ArgumentException("El nombre no puede ser nulo o vacio");
        }

        if (string.IsNullOrEmpty(obj.correo))
        {
            throw new ArgumentException("El correo no puede ser nulo o vacio");
        }


        int?id = null;
        UsuarioTableAdapter adapter = new UsuarioTableAdapter();

        adapter.insertUsuario(obj.correo, obj.password, obj.nombreCompleto, ref id);

        if (id == null || id.Value <= 0)
        {
            throw new Exception("La llave primaria no se generó correctamente");
        }
        else
        {
            enviarEmail(id.Value);
        }
        return(id.Value);
    }
Ejemplo n.º 4
0
        private void btnLogin_Click(object sender, EventArgs e)
        {
            UsuarioTableAdapter user = new UsuarioTableAdapter();
            DataTable           dtUser;
            DataTable           dtUser1;

            if (txtUser.Text != "" && txtSenha.Text != "")
            {
                dtUser  = user.VerificarUser(txtUser.Text.ToLower());
                dtUser1 = user.VerificaSenha(txtSenha.Text.ToLower());
                if (dtUser.Rows.Count == 0 || dtUser1.Rows.Count == 0)
                {
                    MessageBox.Show("Login ou/e senha incorretos!");
                }
                else
                {
                    MessageBox.Show("Login Efetuado! Seja Bem Vindo!");
                    frmInicial chama = new frmInicial();
                    chama.Propriedades = txtUser.Text;
                    chama.Show();
                    this.Hide();
                }
            }

            else
            {
                MessageBox.Show("Insira um login e/ou uma senha!!");
            }
        }
Ejemplo n.º 5
0
        private void button1_Click(object sender, EventArgs e)
        {
            UsuarioTableAdapter login = new UsuarioTableAdapter();
            DataTable           UsuarioLogin;

            UsuarioLogin = login.Login(TxtUsuario.Text, TxtSenha.Text);



            if (UsuarioLogin.Rows.Count > 0)
            {
                if (tela == 1)
                {
                    AdmForm adm = new AdmForm();
                    adm.Visible  = true;
                    this.Visible = false;
                }
                else
                {
                    secondform novo = new secondform();
                    novo.Show(this);

                    this.Visible = false;
                }
            }

            if (UsuarioLogin.Rows.Count == 0)
            {
                MessageBox.Show("Usuario ou Senha incorretos");
            }
        }
Ejemplo n.º 6
0
        public static Usuario GetUsuarioByEmail(string email)
        {
            if (string.IsNullOrEmpty(email))
            {
                throw new ArgumentException("El email del usuario no debe ser nulo o vacio");
            }
            UsuarioTableAdapter adapter = new UsuarioTableAdapter();
            UsuarioDataTable    table   = adapter.GetUsuarioByEmail(email);

            if (table.Rows.Count == 0)
            {
                return(null);
            }

            UsuarioRow row = table[0];
            Usuario    obj = new Usuario()
            {
                IdUsuario      = row.idUsuario,
                NombreCompleto = row.nombreCompleto,
                Email          = row.email,
                Password       = row.password,
                Telefono       = row.telefono,
                Direccion      = row.direccion
            };

            return(obj);
        }
Ejemplo n.º 7
0
        public static void ActualizarInventario(String observacion)
        {
            FechaInventarioTableAdapter fecha = new FechaInventarioTableAdapter();
            int var16 = 0;

            try
            {
                if (fecha.ObtenerFecha(DateTime.Now.ToString("yyyy-MM-dd")).ToString().Length != 0)
                {
                    var16 = (int)fecha.ObtenerFecha(DateTime.Now.ToString("yyyy-MM-dd"));
                }
                else
                {
                    fecha.InsertFecha(DateTime.Now.ToString("yyyy-MM-dd"));
                    var16 = (int)fecha.ObtenerFecha(DateTime.Now.ToString("yyyy-MM-dd"));
                }
            }
            catch (NullReferenceException)
            {
                fecha.InsertFecha(DateTime.Now.ToString("yyyy-MM-dd"));
                var16 = (int)fecha.ObtenerFecha(DateTime.Now.ToString("yyyy-MM-dd"));
            }


            UsuarioTableAdapter usuario = new UsuarioTableAdapter();
            int var17 = (int)usuario.ObtenerIDUsuario(FuncionesUtiles.USUARIO);

            EquipoTableAdapter equipo = new EquipoTableAdapter();
            int var18 = (int)equipo.getIdEquipo(FuncionesUtiles.INVENTARIO_EQUIPO);

            InventarioTableAdapter inventario = new InventarioTableAdapter();

            inventario.UpdateInventario(var16, var17, observacion, var18);
        }
Ejemplo n.º 8
0
        public static void UpdateUsuario(Usuario objUsuario)
        {
            if (objUsuario.UsuarioId <= 0)
            {
                throw new ArgumentException("El Usuario no puede ser menor o igual a cero.");
            }

            try
            {
                UsuarioTableAdapter localAdapter = new UsuarioTableAdapter();
                object resutl = localAdapter.UpdateUsuario(
                    string.IsNullOrEmpty(objUsuario.Nombre) ? "" : objUsuario.Nombre,
                    string.IsNullOrEmpty(objUsuario.Apellido) ? "" : objUsuario.Apellido,
                    string.IsNullOrEmpty(objUsuario.Password) ? "" : objUsuario.Password,
                    objUsuario.TipoUsuarioId,
                    string.IsNullOrEmpty(objUsuario.Email) ? "" : objUsuario.Email,
                    string.IsNullOrEmpty(objUsuario.Celular1) ? "" : objUsuario.Celular1,
                    string.IsNullOrEmpty(objUsuario.Celular2) ? "" : objUsuario.Celular2,
                    objUsuario.Nit,
                    objUsuario.UsuarioId);

                log.Debug("Se actualizo el usuario " + objUsuario.Nombre);
            }
            catch (Exception q)
            {
                log.Error("Ocurrió un error al actualizar el Usuario", q);
                throw q;
            }
        }
Ejemplo n.º 9
0
    public static bool validateEmail(string email)
    {
        bool?existeMail             = null;
        UsuarioTableAdapter adapter = new UsuarioTableAdapter();

        adapter.validateEmail(ref existeMail, email);
        return(existeMail == null ? false : true);
    }
Ejemplo n.º 10
0
    public static bool validateCodigoRecuperacion(string codigoRecuperacion)
    {
        bool?esCodigoCorrecto       = null;
        UsuarioTableAdapter adapter = new UsuarioTableAdapter();

        adapter.validateCodigoRecuperacion(codigoRecuperacion, ref esCodigoCorrecto);
        return(esCodigoCorrecto.Value);
    }
Ejemplo n.º 11
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            if (CaixasOK())
            {
                //// enquanto não temos banco de dados
                //if (txtUsuario.Text != "123" && txtSenha.Text != "123")
                //{
                //    MessageBox.Show("Usuário ou Senha inválidos");
                //    vErros++;
                //    if (vErros == 3)
                //    {
                //        MessageBox.Show("Número de tentativas esgotado...");
                //        this.Close();
                //    }
                //}
                //else
                //{
                //    Properties.Settings.Default.NivelUsuarioLogado = 1;
                //    Properties.Settings.Default.NomeUsuarioLogado = txtUsuario.Text;
                //    MDI_Menu frmMenuPrincipal = new MDI_Menu();
                //    frmMenuPrincipal.Show();
                //    this.Close();
                //}

                //Quando estivermos acessando o Banco de Dados
                if (CaixasOK())
                {
                    DataSet_Dados_do_Banco.UsuarioDataTable dtUsuario;
                    UsuarioTableAdapter taUsuario = new UsuarioTableAdapter();
                    dtUsuario = taUsuario.VerificaNivel(txtUsuario.Text, txtSenha.Text);
                    if (dtUsuario.Rows.Count == 0)
                    {
                        MessageBox.Show("Usuário ou Senha inválidos");
                        vErros++;
                        if (vErros == 3)
                        {
                            MessageBox.Show("Número de tentativas estogado...");
                            taUsuario.Dispose();
                            this.Close();
                        }
                    }
                    else
                    {
                        Properties.Settings.Default.NivelUsuarioLogado = (int)dtUsuario.Rows[0]["Nivel"];
                        Properties.Settings.Default.NomeUsuarioLogado  = txtUsuario.Text;
                        MDI_Menu frmMenuPrincipal = new MDI_Menu();
                        frmMenuPrincipal.Show();
                        this.Hide();
                    }
                }
            }
        }
Ejemplo n.º 12
0
        private void btnReg_Click(object sender, EventArgs e)
        {
            if (txtNombre.Text == "")
            {
                MessageBox.Show("Ingrese Nombre"); return;
            }
            if (txtApellido.Text == "")
            {
                MessageBox.Show("Ingrese Apellido"); return;
            }
            if (txtUser.Text == "")
            {
                MessageBox.Show("Ingrese Usuario"); return;
            }
            if (txtPass.Text == "")
            {
                MessageBox.Show("Ingrese Contraseña"); return;
            }
            if (txtconfirmPass.Text == "")
            {
                MessageBox.Show("Ingrese Confimacion Contraseña"); return;
            }
            if (txtPass.Text != txtconfirmPass.Text)
            {
                MessageBox.Show("Contraseñas no iguales"); return;
            }
            if (radioAyudante.Checked && radioAdmin.Checked)
            {
                MessageBox.Show("Seleccione una opcion"); return;
            }
            UsuarioTableAdapter user = new UsuarioTableAdapter();

            if (user.ObtenerIDUsuario(txtUser.Text) != null)
            {
                if ((int)user.ObtenerIDUsuario(txtUser.Text) != 0)
                {
                    MessageBox.Show("Usuario Existe"); return;
                }
            }

            if (radioAyudante.Checked)
            {
                user.InsertUser(txtUser.Text, 1, txtNombre.Text.ToUpper() + txtApellido.Text.ToUpper(), txtPass.Text);
            }
            if (radioAdmin.Checked)
            {
                user.InsertUser(txtUser.Text, 2, txtNombre.Text.ToUpper() + "  " + txtApellido.Text.ToUpper(), txtPass.Text);
            }

            MessageBox.Show("Usuario Creado");
            this.Close();
        }
Ejemplo n.º 13
0
        private void button2_Click(object sender, EventArgs e)
        {
            string dellUser = Microsoft.VisualBasic.Interaction.InputBox("Otorgar Permiso Usuario", "Ingrese Usuario Espol", "", 600);

            if (dellUser == "")
            {
                return;
            }
            UsuarioTableAdapter user = new UsuarioTableAdapter();

            user.UpdateTipo(2, dellUser);
            MessageBox.Show("Permisos Administrador Otorgados");
        }
Ejemplo n.º 14
0
        private void btnEliminarUsuario_Click(object sender, EventArgs e)
        {
            string dellUser = Microsoft.VisualBasic.Interaction.InputBox("ELIMINAR USUARIO", "Ingrese Usuario Espol", "", 600);

            if (dellUser == "")
            {
                return;
            }
            UsuarioTableAdapter user = new UsuarioTableAdapter();

            user.UpdateTipo(3, dellUser);
            MessageBox.Show("Permisos Eliminados");
        }
Ejemplo n.º 15
0
    public static void updatePassword(string codigoRecuperacion, string password)
    {
        UsuarioTableAdapter adapter = new UsuarioTableAdapter();

        try
        {
            adapter.updatePassword(codigoRecuperacion, password);
        }
        catch (Exception ex)
        {
            Console.WriteLine("error al updatePassword" + ex);
            return;
        }
    }
Ejemplo n.º 16
0
    public static List <Usuario> getAllUsuarios()
    {
        UsuarioTableAdapter adapter = new UsuarioTableAdapter();

        UsuarioDS.UsuarioDataTable table = adapter.getAllUsuarios();

        List <Usuario> list = new List <Usuario>();

        foreach (var row in table)
        {
            Usuario obj = GetUsuarioFromRow(row);
            list.Add(obj);
        }
        return(list);
    }
Ejemplo n.º 17
0
    public static Usuario getUsuarioById(int usuarioId)
    {
        UsuarioTableAdapter adapter = new UsuarioTableAdapter();

        UsuarioDS.UsuarioDataTable table = adapter.getUsuarioById(usuarioId);

        List <Usuario> list = new List <Usuario>();

        foreach (var row in table)
        {
            Usuario obj = GetUsuarioFromRow(row);
            list.Add(obj);
        }
        return(list[0]);
    }
Ejemplo n.º 18
0
    public static void updateCodigoRecuperacion(string email)
    {
        int?id = null;
        UsuarioTableAdapter adapter = new UsuarioTableAdapter();

        try
        {
            adapter.updateCodigoRecuperacion(email, ref id);
            enviarEmailRecuperacion(id.Value);
        }
        catch (Exception ex)
        {
            Console.WriteLine("error al actualizar codigo recuperacion" + ex);
            return;
        }
    }
Ejemplo n.º 19
0
 private void btnCadastrar_Click(object sender, EventArgs e)
 {
     if (txtSenha.Text == txtRepitaSenha.Text)
     {
         UsuarioTableAdapter taPessoa = new UsuarioTableAdapter();
         taPessoa.Insert(txtUsuario.Text.ToLower(), txtEmail.Text.ToLower(), txtSenha.Text.ToLower());
         MessageBox.Show("Usuário Cadastrado com sucesso!");
         txtEmail.Text       = "";
         txtRepitaSenha.Text = "";
         txtSenha.Text       = "";
         txtUsuario.Text     = "";
     }
     else
     {
         MessageBox.Show("Senhas diferentes! /n Tente Novamente!");
     }
 }
Ejemplo n.º 20
0
        public static void DeleteUsuario(int usuarioId)
        {
            if (usuarioId <= 0)
            {
                throw new ArgumentException("El Usuario no puede ser menor o igual a cero.");
            }

            try
            {
                UsuarioTableAdapter theAdapter = new UsuarioTableAdapter();
                theAdapter.DeleteUsuario(usuarioId);
            }
            catch (Exception ex)
            {
                log.Error("Ocurrio un error al Eliminar el ClienteDireccion.", ex);
                throw ex;
            }
        }
Ejemplo n.º 21
0
        public static int InsertUser(Usuario obj)
        {
            int?idUsuario = 0;

            if (obj == null)
            {
                throw new ArgumentException("El usuario no debe ser nulo");
            }

            UsuarioTableAdapter adapter = new UsuarioTableAdapter();

            adapter.Insert(obj.NombreCompleto, obj.Email, obj.Password, obj.Telefono, obj.Direccion, ref idUsuario);
            if (idUsuario == 0)
            {
                throw new ArgumentException("Error al insertar un nuevo usuario");
            }

            return(idUsuario.Value);
        }
Ejemplo n.º 22
0
    public static Usuario autenticarUsuario(string username, string password)
    {
        UsuarioTableAdapter adapter = new UsuarioTableAdapter();

        UsuarioDS.UsuarioDataTable table = adapter.autenticarUsuario(username, password);

        if (table == null || table.Rows.Count > 1)
        {
            throw new Exception("La consulta retornó un numero incorrecto de filas");
        }
        if (table.Rows.Count == 0)
        {
            return(null);
        }
        UsuarioDS.UsuarioRow row = table[0];
        return(new Usuario()
        {
            correo = row.correo,
            usuarioId = row.usuarioId,
            nombreCompleto = row.nombre
        });
    }
Ejemplo n.º 23
0
        public static Usuario GetUsuarioById(int idUsuario)
        {
            UsuarioTableAdapter adapter = new UsuarioTableAdapter();
            UsuarioDataTable    table   = adapter.GetUsuarioById(idUsuario);

            if (table.Rows.Count == 0)
            {
                return(null);
            }

            UsuarioRow row = table[0];
            Usuario    obj = new Usuario()
            {
                IdUsuario      = row.idUsuario,
                NombreCompleto = row.nombreCompleto,
                Email          = row.email,
                Password       = row.password,
                Telefono       = row.telefono,
                Direccion      = row.direccion
            };

            return(obj);
        }
Ejemplo n.º 24
0
        public static void InsertUsuario(Usuario objUsuario)
        {
            try
            {
                UsuarioTableAdapter localAdapter = new UsuarioTableAdapter();
                object resutl = localAdapter.InsertUsuario(
                    string.IsNullOrEmpty(objUsuario.Nombre) ? "" : objUsuario.Nombre,
                    string.IsNullOrEmpty(objUsuario.Apellido) ? "" : objUsuario.Apellido,
                    string.IsNullOrEmpty(objUsuario.Password) ? "" : objUsuario.Password,
                    objUsuario.TipoUsuarioId,
                    string.IsNullOrEmpty(objUsuario.Email) ? "" : objUsuario.Email,
                    string.IsNullOrEmpty(objUsuario.Celular1) ? "" : objUsuario.Celular1,
                    string.IsNullOrEmpty(objUsuario.Celular2) ? "" : objUsuario.Celular2,
                    objUsuario.Nit);

                log.Debug("Se insertó el usuario " + objUsuario.Nombre);
            }
            catch (Exception q)
            {
                log.Error("Ocurrió un error al insertar el Usuario", q);
                throw q;
            }
        }
Ejemplo n.º 25
0
    public static int updateSenha(int usuarioId, String newPass, String oldPass)
    {
        if (string.IsNullOrEmpty(newPass))
        {
            throw new ArgumentException("La contraseña no puede ser nulo o vacio");
        }

        if (string.IsNullOrEmpty(oldPass))
        {
            throw new ArgumentException("La contraseña no puede ser nulo o vacio");
        }

        int?id = null;
        UsuarioTableAdapter adapter = new UsuarioTableAdapter();

        adapter.updateSenha(usuarioId, oldPass, newPass, ref id);

        if (id == null || id.Value <= 0)
        {
            throw new Exception("La llave primaria no se generó correctamente");
        }

        return(id.Value);
    }
Ejemplo n.º 26
0
        private void bindingNavigatorAddNewItem_Click(object sender, EventArgs e)
        {
            string NuevoInventario = Microsoft.VisualBasic.Interaction.InputBox("NUEVO EQUIPO", "Ingrese Numero de Inventario Equipo", "", 600);

            try
            {
                if (NuevoInventario == "")
                {
                    return;
                }

                if (this.equipoTableAdapter.ObtenerInventarioEquipo(NuevoInventario).ToString().Length != 0)
                {
                    MessageBox.Show("Numero Ingresado ya Exite");
                    return;
                }
            }
            catch (NullReferenceException)
            {
                this.equipoTableAdapter.InsertInventario(NuevoInventario);

                int var1  = (int)this.equipoTableAdapter.ObtenerInventarioEquipo(NuevoInventario);
                int var2  = (int)FuncionesEquipo.cpu.ObtenerIDCPU("N/A");
                int var3  = (int)this.equipoTableAdapter.getIdNombreOficina("N/A");
                int var4  = (int)FuncionesEquipo.micro.ObtenerIdMicro("N/A");
                int var5  = (int)FuncionesEquipo.telefono.ObtenerIdTelefono("N/A");
                int var6  = (int)FuncionesEquipo.pp.ObtenerIdPP("N/A");
                int var7  = (int)FuncionesEquipo.radio.ObtenerIdRadio("N/A");
                int var8  = (int)FuncionesEquipo.pantalla.ObtenerIdPantalla("N/A");
                int var9  = (int)FuncionesEquipo.teclado.ObtenerIdTeclado("N/A");
                int var10 = (int)FuncionesEquipo.mouse.ObtenerIdMouse("N/A");
                int var11 = (int)FuncionesEquipo.parlante.ObtenerIdParlante("N/A");
                int var12 = (int)FuncionesEquipo.regulador.ObtenerIdRegulador("N/A");
                int var13 = (int)FuncionesEquipo.impresora.ObtenerIdImpresora("N/A");
                int var14 = (int)FuncionesEquipo.proyector.ObtenerIdProyector("N/A");
                int var15 = (int)this.equipoTableAdapter.getIdPropietario("JOSE FLORES");


                this.equipoTableAdapter.InsertEquipo((int)this.equipoTableAdapter.ObtenerInventarioEquipo(NuevoInventario),
                                                     (int)FuncionesEquipo.cpu.ObtenerIDCPU("N/A"), (int)this.equipoTableAdapter.getIdNombreOficina("N/A"), (int)FuncionesEquipo.micro.ObtenerIdMicro("N/A"),
                                                     (int)FuncionesEquipo.telefono.ObtenerIdTelefono("N/A"), (int)FuncionesEquipo.pp.ObtenerIdPP("N/A"),
                                                     (int)FuncionesEquipo.radio.ObtenerIdRadio("N/A"), (int)FuncionesEquipo.pantalla.ObtenerIdPantalla("N/A"), (int)FuncionesEquipo.teclado.ObtenerIdTeclado("N/A"),
                                                     (int)FuncionesEquipo.mouse.ObtenerIdMouse("N/A"), (int)FuncionesEquipo.parlante.ObtenerIdParlante("N/A"), (int)FuncionesEquipo.regulador.ObtenerIdRegulador("N/A"),
                                                     (int)FuncionesEquipo.impresora.ObtenerIdImpresora("N/A"), (int)FuncionesEquipo.proyector.ObtenerIdProyector("N/A"), (int)this.equipoTableAdapter.getIdPropietario("JOSE FLORES"));

                FechaInventarioTableAdapter fecha = new FechaInventarioTableAdapter();
                int var16 = 0;
                try
                {
                    if (fecha.ObtenerFecha(DateTime.Now.ToString("yyyy-MM-dd")).ToString().Length != 0)
                    {
                        var16 = (int)fecha.ObtenerFecha(DateTime.Now.ToString("yyyy-MM-dd"));
                    }
                    else
                    {
                        fecha.InsertFecha(DateTime.Now.ToString("yyyy-MM-dd"));
                        var16 = (int)fecha.ObtenerFecha(DateTime.Now.ToString("yyyy-MM-dd"));
                    }
                }
                catch (NullReferenceException)
                {
                    fecha.InsertFecha(DateTime.Now.ToString("yyyy-MM-dd"));
                    var16 = (int)fecha.ObtenerFecha(DateTime.Now.ToString("yyyy-MM-dd"));
                }

                UsuarioTableAdapter usuario = new UsuarioTableAdapter();
                int var17 = (int)usuario.ObtenerIDUsuario(FuncionesUtiles.USUARIO);

                int var18 = (int)this.equipoTableAdapter.getIdEquipo(NuevoInventario);

                InventarioTableAdapter inventario = new InventarioTableAdapter();
                inventario.InsertInventario(var16, var17, "", var18);

                this.equipoTableAdapter.Fill(this.sistemasFCNMDataSet.Equipo);
                busqueda(NuevoInventario);
            }
        }
Ejemplo n.º 27
0
        private void btnAgregar_Click(object sender, EventArgs e)//evento que te activa al dar clic al boton agregar
        {
            try
            {
                if (txtNombre.Text != "" && txtApellidos.Text != "" && txtTelefono.MaskFull && cboTipo.Text != "" && txtCedula.MaskFull && txtContrasena.TextLength >= 6 && txtContrasena.Text == txtReContrasena.Text)
                {
                    //Quita todos los label de error
                    UsuarioTableAdapter adapter = new UsuarioTableAdapter();                                                                                                                                                   //objeto para utilizar los querys de tblUsuario
                    UsuarioDataTable    data;                                                                                                                                                                                  //objeto que almacena data proveniente de tblUsuario

                    string Cedula = metodos.Filtrar(txtCedula);                                                                                                                                                                //quita los guiones de la cedula

                    string telefono = metodos.Filtrar(txtTelefono);                                                                                                                                                            //quita los guiones del telefono

                    data = adapter.BuscarPorCedulaU(Cedula);                                                                                                                                                                   //busca si hay un usuario en tblUsuario con la cedula ingresada

                    if (data.Count == 0)                                                                                                                                                                                       //si no hay ninguna fila significa que noy un usuario con la cedula ingresada
                    {
                        if (txtContrasena.Text == txtReContrasena.Text)                                                                                                                                                        //verifica que las contraseñas ingresadas sean la misma
                        {
                            if (MessageBox.Show($"¿Está seguro que desea añadir al usuario {txtNombre.Text} {txtApellidos.Text} al sistema?", "Añadir", MessageBoxButtons.YesNo) == DialogResult.Yes)                          //pregunta si de verdad desea añadir este usuario, si es si ocurre lo siguiente
                            {
                                string contrasena = null;                                                                                                                                                                      //string para guardar la contraseña del usuario que usa el sistema
                                contrasena = metodos.InputBox("Reingresar contraseña", $"Reescriba su contraseña {usuario.Nombre}", ref contrasena);                                                                           //muestra una ventana donde el usuario que esta agregando a otro usuario ingrese su contraseña para verificar que de verdad es el

                                if (contrasena == usuario.Contra)                                                                                                                                                              //si la contraseña corresponde al usuario que usa el sistema
                                {
                                    int tipoUsuario = cboTipo.Text == "Administrador" ? 1 : 2;                                                                                                                                 //determina que tipo de usuario se registro
                                    adapter.InsertarU(tipoUsuario, telefono, txtContrasena.Text, Cedula, txtNombre.Text.Trim(), txtApellidos.Text.Trim(), txtDireccion.Text.Trim(), true);                                     //se inserta el usuario con la informacion que se ingresó
                                    log.Info($"Se agregó al sistema el usuario {txtNombre.Text} {txtApellidos.Text} de cédula {Cedula} como {cboTipo.Text} por el administrador {usuario.Nombre} {usuario.Apellidos}");        // se registra que se ingresó un usuario nuevo y su cedula
                                    MessageBox.Show($"{txtNombre.Text} {txtApellidos.Text} ha sido añadido al sistema como {cboTipo.Text} exitosamente", "Agregar usuario", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); //le notifica al usuario que se agregó el nuevo usuario
                                    this.Limpiar();                                                                                                                                                                            //se limpia toda la ventana
                                }
                                else//si la contraseña no es igual a la del usuario que usa el sistema
                                {
                                    log.Warn($"Se intentó agregar al sistema el usuario {txtNombre.Text} {txtApellidos.Text} de cédula {Cedula} como {cboTipo.Text}, " +
                                             $"pero no se pudo confirmar la identidad del administrador {usuario.Nombre} {usuario.Apellidos} ingresando la siguiente contraseña incorrecta: {txtContrasena.Text}"); //notifica que se intentó agregar un usuario pero fracasó la autenticacion
                                    MessageBox.Show("La contraseña ingresada no coincide con su usuario, vuelva a intentarlo", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);                              //notifica al usuario que La contraseña ingresada no coincide con su usuario
                                }
                            }
                            else//si se responde que no
                            {
                                this.Limpiar();//se limpia toda la ventana
                            }
                        }
                        else//si las contraseñas ingresadas no coinciden
                        {
                            MessageBox.Show("Las contraseñas ingresadas no coinciden, favor verificar", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                            txtContrasena.Text   = ""; //limpia el textbox de la contraseña
                            txtReContrasena.Text = ""; //limpia el textbox para verificar la contraseña
                        }
                    }
                    else//si ya hay un usuario con la cedula ingresa
                    {
                        log.Warn($"Se intentó agregar al sistema el usuario {txtNombre.Text} {txtApellidos.Text} de cédula {Cedula} como {cboTipo.Text}, pero ya hay un usuario con esta cédula con anterioridad " +
                                 $"por el administrador {usuario.Nombre} {usuario.Apellidos}");                                                                                                  //notifica que se intentó ingresar un usuario con una cedula que ya pertenece a otro usuario
                        MessageBox.Show("Ya se encuentra un usuario ingresado con esta cedula.\n\nFavor ingresar otra cedula y/o usuario", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); //le notifica al usuario mediante un mensaje que ya hay un usuario ingresado con esta cedula
                    }
                }
                else//si no se ingresó toda la informacion necesaria
                {
                    cboTipo.SelectedItem = 0;
                    this.ErrorAgregar();//no permite que algun campo obligatorio esté vacío
                }
            }
            catch (Exception error)
            {
                log.Error($"Error: {error.Message}", error);
                MessageBox.Show($"Error: {error.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Ejemplo n.º 28
0
    public static void updateUsuario(Usuario obj)
    {
        UsuarioTableAdapter adapter = new UsuarioTableAdapter();

        adapter.updateUsuario(obj.correo, obj.nombreCompleto, obj.usuarioId);
    }
Ejemplo n.º 29
0
 public UserDAOImpl()
 {
     adapter = new UsuarioTableAdapter();
 }
 public UsuarioType autenticar(String codigo, String claveweb)
 {
     UsuarioTableAdapter UsuarioTa = new UsuarioTableAdapter();
     DataSetBanca.UsuarioDataTable UsuarioDt = UsuarioTa.ConsultarUsuarioPorCredencial(codigo, claveweb);
     if (UsuarioDt.Rows.Count > 0)
     {
         UsuarioType usuarioType = new UsuarioType();
         usuarioType.usuarioId = Int32.Parse(UsuarioDt.Rows[0]["usuario_id"].ToString());
         usuarioType.codigo = UsuarioDt.Rows[0]["codigo"].ToString();
         usuarioType.codigoEmpresa = UsuarioDt.Rows[0]["codigo_empresa"].ToString();
         return usuarioType;
     }
     else
     {
         return null;
     }
 }
Ejemplo n.º 31
0
    public static void deleteUsuario(int usuarioId)
    {
        UsuarioTableAdapter adapter = new UsuarioTableAdapter();

        adapter.deleteUsuario(usuarioId);
    }