Пример #1
0
        public void Atualizar(CadastroClienteDTO dto)
        {
            //recebe o objeto cliente preenchido para atualizar apartir do id do cliente
            try
            {
                bd.Conectar();

                string comando = "UPDATE cliente set nome='" + dto.ClienteNome + "',telefoneFix='" + dto.ClienteFixo1 + "',telefoneCel='" + dto.ClienteCel1 + "', " +
                                 "email='" + dto.ClienteEmail + "' " +
                                 "where idCliente = '" + dto.ClienteId + "'";
                bd.ExecutarComandoSQL(comando);
                bd.Conectar();
                string comando1 = "UPDATE endereco set rua='" + dto.ClienteLogradouro + "', numero='" + dto.ClienteNcasa + "', complemento='" + dto.ClienteComplemento + "', " +
                                  "bairro='" + dto.ClienteBairro + "', cidade='" + dto.ClienteCidade + "', uf='" + dto.ClienteUF + "', cep='" + dto.ClienteCEP + "' " +
                                  "where cliente_idCliente = '" + dto.ClienteId + "'";
                bd.ExecutarComandoSQL(comando1);
                if (dto.ClienteCPF.Length == 11)
                {
                    bd.Conectar();
                    string comando2 = "update pessoafisica set cpf='" + dto.ClienteCPF + "' where cliente_idCliente='" + dto.ClienteId + "'";
                    bd.ExecutarComandoSQL(comando2);
                }
                else if (dto.ClienteCNPJ.Length == 14)
                {
                    bd.Conectar();
                    string comando2 = "update pessoajuridica set cnpj='" + dto.ClienteCNPJ + "' where cliente_idCliente='" + dto.ClienteId + "'";
                    bd.ExecutarComandoSQL(comando2);
                }
            }
            catch (Exception erro)
            {
                throw new Exception("Erro ao tentar Cadastrar o cliente" + erro.Message);
            }
        }
        public CadastroClienteDTO Buscarr(string dto, string escolha)
        {
            dtos = new CadastroClienteDTO();

            dtos = cb.Buscar(dto, escolha);

            return(dtos);
        }
Пример #3
0
 public void Excluir(CadastroClienteDTO dto)
 {
     //Desativa o cliente
     try
     {
         bd.Conectar();
         string comando = "UPDATE cliente set statusCli='desativado' where idCliente = '" + dto.ClienteId + "'";
         bd.ExecutarComandoSQL(comando);
     }
     catch (Exception ex)
     {
         throw new Exception("Erro ao tentar excluir o funcionario: " + ex.Message);
     }
 }
Пример #4
0
        public void Inserir(CadastroClienteDTO dto)
        //recebe o objeto cliente preenchido da camada GUI
        {
            try
            {
                string nome = dto.ClienteNome.Replace("'", "''");


                bd.Conectar();
                //insere dados do cliente
                string comando = "INSERT INTO cliente(idCliente, nome, telefoneFix, telefoneCel, email, statusCli) VALUES" +
                                 " (null,'" + nome + "','" + dto.ClienteFixo1 + "','" + dto.ClienteCel1 + "','" + dto.ClienteEmail + "', 'ativado')";
                bd.ExecutarComandoSQL(comando);
                //verifica se é cpf ou cnpj que será inserido
                if (dto.ClienteEscolha == "CPF")
                {
                    bd.Conectar();
                    string comando1 = "INSERT INTO pessoafisica(cpf, cliente_idCliente) VALUES " +
                                      "('" + dto.ClienteCPF + "',LAST_INSERT_ID())";
                    bd.ExecutarComandoSQL(comando1);
                }
                else if (dto.ClienteEscolha == "CNPJ")
                {
                    bd.Conectar();
                    string comando1 = "INSERT INTO pessoajuridica(cnpj, cliente_idCliente) VALUES ('" + dto.ClienteCNPJ + "',LAST_INSERT_ID())";
                    bd.ExecutarComandoSQL(comando1);
                }
                //insere endereço do cliente
                bd.Conectar();
                string comando2 = "INSERT INTO endereco(rua, numero, complemento, bairro, cidade, uf, cep, cliente_idCliente)VALUES " +
                                  "('" + dto.ClienteLogradouro + "','" + dto.ClienteNcasa + "','" + dto.ClienteComplemento + "','" + dto.ClienteBairro + "'" +
                                  ",'" + dto.ClienteCidade + "','" + dto.ClienteUF + "','" + dto.ClienteCEP + "',LAST_INSERT_ID())";
                bd.ExecutarComandoSQL(comando2);
            }
            catch (Exception erro)
            {
                throw new Exception("Erro ao tentar atualizar o cliente" + erro.Message);
            }
        }
Пример #5
0
 public CadastroClienteDTO Buscar(string dto, string escolha)
 //recebe a string escolha para verificar se é cpf ou cnpj
 //recebe a string dto para buscar os dados do cliente apartir do CPF ou CNPJ
 {
     bd.Conectar();
     dtos = new CadastroClienteDTO();
     if (escolha == "CPF")
     {
         string comando = "select c.nome, c.telefoneFix, telefoneCel, c.email, a.rua, a.numero, a.complemento, a.bairro, a.cidade," +
                          " a.uf, a.cep, p.cpf, c.idCliente, c.statusCli from cliente c join endereco a on" +
                          " c.idCliente = a.cliente_idCliente join pessoafisica p on c.idCliente = p.cliente_idCliente " +
                          "where cpf = '" + dto + "';";
         dtos = bd.ExecutaEretornaReader(comando);
     }
     else if (escolha == "CNPJ")
     {
         string comando = "select c.nome, c.telefoneFix,c.telefoneCel, c.email, a.rua, a.numero, a.complemento, a.bairro, a.cidade, a.uf, a.cep," +
                          " p.cnpj, c.idCliente, c.statusCli from cliente c join endereco a on c.idCliente = a.cliente_idCliente join pessoajuridica p " +
                          " on c.idCliente = p.cliente_idCliente where cnpj = '" + dto + "';";
         dtos = bd.ExecutaEretornaReader(comando);
     }
     return(dtos); //retorna os dados para preencher na cama GUI
 }
Пример #6
0
        private void btnBuscarCadastro_Click(object sender, EventArgs e)
        {
            dto = dll.Buscarr(txtNumeroCPFouCNPJ.Text, cmbCPFeCNPJ.SelectedItem.ToString());
            if (string.IsNullOrWhiteSpace(txtNumeroCPFouCNPJ.Text))
            {
                MessageBox.Show("Digite o numero do CPF ou CMPJ", "Aviso!");
            }
            else if (dto.ClienteSituacao == "ativado")
            //verifica se o cliente é ativado, se for exibe no txtbox
            {
                txtNomeCliente.Text        = dto.ClienteNome;
                txtNumeroCliente1.Text     = dto.ClienteFixo1;
                txtCelularCliente1.Text    = dto.ClienteCel1;
                txtEmailCliente.Text       = dto.ClienteEmail;
                txtLogradouroCliente.Text  = dto.ClienteLogradouro;
                txtNumCasa.Text            = dto.ClienteNcasa;
                txtComplementoCliente.Text = dto.ClienteComplemento;
                txtBairroCliente.Text      = dto.ClienteBairro;
                txtCidade.Text             = dto.ClienteCidade;
                cmbUF.Text              = dto.ClienteUF;
                txtCEP.Text             = dto.ClienteCEP;
                txtNumeroCPFouCNPJ.Text = dto.ClienteCPF;
            }
            else if (dto.ClienteSituacao == "desativado")
            //verifica se o cliente esta desativa, se estiver tem a opcao de ativar
            {
                DialogResult AtivarCliente = MessageBox.Show("Cliente desativado!\nDeseja ativar o cliente ?", "Aviso",
                                                             MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button2);
                if (AtivarCliente.ToString().ToUpper() == "YES")
                {
                    if (nivelAcesso == "Admin")
                    //apenas admin podem ativar cliente assim como excluir
                    {
                        dll.AtivarCliente(dto.ClienteId);
                        MessageBox.Show("Cliente ativado com sucesso!", "Aviso!");

                        txtNomeCliente.Text        = dto.ClienteNome;
                        txtNumeroCliente1.Text     = dto.ClienteFixo1;
                        txtCelularCliente1.Text    = dto.ClienteCel1;
                        txtEmailCliente.Text       = dto.ClienteEmail;
                        txtLogradouroCliente.Text  = dto.ClienteLogradouro;
                        txtNumCasa.Text            = dto.ClienteNcasa;
                        txtComplementoCliente.Text = dto.ClienteComplemento;
                        txtBairroCliente.Text      = dto.ClienteBairro;
                        txtCidade.Text             = dto.ClienteCidade;
                        cmbUF.Text              = dto.ClienteUF;
                        txtCEP.Text             = dto.ClienteCEP;
                        txtNumeroCPFouCNPJ.Text = dto.ClienteCPF;
                    }
                    else
                    {
                        MessageBox.Show("Somente administradores podem ativar ou desativar clientes!", "Aviso!");
                        limpar();
                    }
                }

                //limpar();
            }
            else
            //se não for ativo ou desativado significa que o cliente não existe no sistema
            {
                MessageBox.Show("Cliente não cadastrado!", "Aviso!");
            }
            btnExcluir.Enabled = true;
            btnAlterar.Enabled = true;
            btnSalvar.Enabled  = false;
        }
 public void Excluirr(CadastroClienteDTO dto)
 {
     cb.Excluir(dto);
 }
 public void Atualizarr(CadastroClienteDTO dto)
 {
     cb.Atualizar(dto);
 }
        //o nome agora é cadastro cliente DAO

        public void Inserirr(CadastroClienteDTO dto)
        {
            cb.Inserir(dto);
        }