public List <ClienteVIP> Read()
        {
            List <ClienteVIP> lista = new List <ClienteVIP>();

            SqlCommand cmd = new SqlCommand();

            cmd.Connection  = conn;
            cmd.CommandText = @"SELECT p.Id, p.Nome, p.Email, pr.Titulo
                                FROM Pessoa p, Professor pr
                                WHERE p.Id = pr.Id";

            SqlDataReader reader = cmd.ExecuteReader();

            while (reader.Read())
            {
                ClienteVIP cli = new ClienteVIP();
                cli.Id     = (int)reader["Id"];
                cli.Nome   = (string)reader["Nome"];
                cli.Email  = (string)reader["Email"];
                cli.Titulo = (string)reader["Titulo"];

                lista.Add(cli);
            }

            return(lista);
        }
    public ICliente DeepCopy()
    {
        ClienteVIP deepcopy = (ClienteVIP)ShallowCopy();

        deepcopy.endereco            = new EnderecoCliente();
        deepcopy.endereco.bairro     = this.endereco.bairro;
        deepcopy.endereco.logradouro = this.endereco.logradouro;
        deepcopy.endereco.cidade     = this.endereco.cidade;
        return(deepcopy);
    }
        public void Create(ClienteVIP clienteVip)
        {
            SqlCommand cmd = new SqlCommand();

            cmd.Connection = conn;
            // usando a procedure
            cmd.CommandText = "InsereProfessor";
            // chama o exec
            cmd.CommandType = System.Data.CommandType.StoredProcedure;

            cmd.Parameters.AddWithValue("@nome", clienteVip.Nome);
            cmd.Parameters.AddWithValue("@email", clienteVip.Email);
            cmd.Parameters.AddWithValue("@senha", clienteVip.Senha);
            cmd.Parameters.AddWithValue("@titulo", clienteVip.Titulo);

            cmd.ExecuteNonQuery();
        }
Ejemplo n.º 4
0
        public Pessoa Login(string email, string senha)
        {
            SqlCommand cmd = new SqlCommand();

            cmd.Connection  = conn;
            cmd.CommandText = @"select * from Usuarios 
                where Email = @email AND Senha = @senha";

            cmd.Parameters.AddWithValue("@email", email);
            cmd.Parameters.AddWithValue("@senha", senha);

            SqlDataReader reader = cmd.ExecuteReader();

            if (reader.Read())
            {
                // Polimorfismo
                if ((string)reader["Tipo"] == "ClienteVIP")
                {
                    ClienteVIP clienteVip = new ClienteVIP();
                    clienteVip.Id     = (int)reader["Id"];
                    clienteVip.Nome   = (string)reader["Nome"];
                    clienteVip.Email  = (string)reader["Email"];
                    clienteVip.Tipo   = (string)reader["Tipo"];
                    clienteVip.Titulo = (string)reader["Titulo"];

                    return(clienteVip);
                }
                else
                {
                    Funcionario funcionario = new Funcionario();
                    funcionario.Id    = (int)reader["Id"];
                    funcionario.Nome  = (string)reader["Nome"];
                    funcionario.Email = (string)reader["Email"];
                    funcionario.Tipo  = (string)reader["Tipo"];

                    return(funcionario);
                }
            }

            return(null);
        }