Example #1
0
        public List <DadosUsuario> ListVendedorWithLista()
        {
            List <DadosUsuario> lista = new List <DadosUsuario>();

            using (var connection = GetConnection())
            {
                try
                {
                    command.Connection  = connection;
                    command.CommandText = "select * from tb_vendedor";
                    command.CommandType = CommandType.Text;
                    SqlDataReader reader = command.ExecuteReader();
                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            DadosUsuario obj = new DadosUsuario();
                            obj.IdVendedor = reader.GetInt32(0);
                            obj.Login      = reader.GetString(1);
                            obj.Nome       = reader.GetString(2);
                            obj.SobreNome  = reader.GetString(3);
                            obj.Email      = reader.GetString(4);
                            obj.Telefone   = reader.GetString(5);
                            obj.Cargo      = reader.GetInt32(6);
                            lista.Add(obj);
                        }
                    }
                }
                catch (Exception ex)
                {
                    lista = null;
                }
                return(lista);
            }
        }
Example #2
0
        //cadastro de novo usuario
        public string InsertUsuario(DadosUsuario Usuario)
        {
            using (var connection = GetConnection())
            {
                connection.Open();
                string rpta = "";
                try
                {
                    command.Connection  = connection;
                    command.CommandText = "CadastroUsuario";
                    command.CommandType = CommandType.StoredProcedure;
                    command.Parameters.AddWithValue("@login", Usuario.Login);
                    command.Parameters.AddWithValue("@nome", Usuario.Nome);
                    command.Parameters.AddWithValue("@sobre_nome", Usuario.SobreNome);
                    command.Parameters.AddWithValue("@email", Usuario.Email);
                    command.Parameters.AddWithValue("@telefone", Usuario.Telefone);
                    command.Parameters.AddWithValue("@id_cargo", Usuario.Cargo);
                    command.Parameters.AddWithValue("@senha", Usuario.Senha);

                    rpta = command.ExecuteNonQuery() == 1 ? "OK" : "Erro ao inserir cadastro de usuario";
                }
                catch (Exception ex)
                {
                    rpta = ex.Message;
                }
                return(rpta);
            }
        }
Example #3
0
        //editando o cadastro do usuario
        public string Edit(DadosUsuario Usuario)
        {
            using (var connection = GetConnection())
            {
                connection.Open();
                string rpta = "";
                try
                {
                    command.Connection  = connection;
                    command.CommandText = "UPDATE tb_vendedor SET login=@login, nome=@nome, sobre_nome=@sobre_nome, email=@email, telefone=@telefone, cargo=@cargo, senha=@senha" +
                                          "WHERE id_vendedor=@id_vendedor";
                    command.CommandType = CommandType.Text;
                    command.Parameters.AddWithValue("@id_vendedor", Usuario.IdVendedor);
                    command.Parameters.AddWithValue("@login", Usuario.Login);
                    command.Parameters.AddWithValue("@nome", Usuario.Nome);
                    command.Parameters.AddWithValue("@sobre_nome", Usuario.SobreNome);
                    command.Parameters.AddWithValue("@email", Usuario.Email);
                    command.Parameters.AddWithValue("@telefone", Usuario.Telefone);
                    command.Parameters.AddWithValue("@cargo", Usuario.Cargo);
                    command.Parameters.AddWithValue("@senha", Usuario.Senha);

                    rpta = command.ExecuteNonQuery() == 1 ? "OK" : "Erro ao atualizar usuario";
                }
                catch (Exception ex)
                {
                    rpta = ex.Message;
                }
                finally
                {
                    connection.Close();
                }
                return(rpta);
            }
        }
Example #4
0
        //verificando se o usuario ja existe
        public bool Validate(DadosUsuario Usuario)
        {
            using (var connection = GetConnection())
            {
                try
                {
                    connection.Open();
                    command.Connection  = connection;
                    command.CommandText = "SELECT login FROM tb_vendedor WHERE login = @login";
                    command.CommandType = CommandType.Text;
                    command.Parameters.AddWithValue("@login", Usuario.Login);

                    var result = command.ExecuteScalar();
                    if (result != null)
                    {
                        return(true);
                    }
                }
                catch (Exception ex)
                {
                }
                return(false);
            }
        }