예제 #1
0
        public static bool Alterar(Clientes cliente)
        {
            try
            {
                using (OracleCommand c = ConexaoOracle.ObterConexao().CreateCommand())
                {
                    c.CommandType = System.Data.CommandType.Text;
                    c.CommandText = "UPDATE clientes SET bairroid=:bairroid, nome=:nome, estado=:estado, endereco=:endereco, numero=:numero, observacao=:observacao, ativo=:ativo WHERE clienteid = :codigo";
                    c.Parameters.Add("bairroid", OracleType.Int32).Value = cliente.getBairroId();
                    c.Parameters.Add("nome", OracleType.VarChar).Value = cliente.getNome();
                    c.Parameters.Add("estado", OracleType.VarChar).Value = cliente.getEstado();
                    c.Parameters.Add("endereco", OracleType.VarChar).Value = cliente.getEndereco();
                    c.Parameters.Add("numero", OracleType.VarChar).Value = cliente.getNumero();
                    c.Parameters.Add("observacao", OracleType.VarChar).Value = cliente.getObservacao();
                    c.Parameters.Add("codigo", OracleType.Int32).Value = cliente.getClienteId();
                    c.Parameters.Add("ativo", OracleType.Int32).Value = cliente.getAtivo();

                    c.ExecuteNonQuery();
                    return true;
                }
            }
            catch (OracleException e)
            {
                throw e;
            }
        }
예제 #2
0
        private void bEfetivar_Click(object sender, EventArgs e)
        {
            try
            {
                int checkAtivo;
                String numero = "";

                if (rdCelular.Checked)
                {
                    numero = mtbCelular.Text;
                }
                else
                {
                    if (rdResidencial.Checked)
                    {
                        numero = mtbResidencial.Text;
                    }
                }

                if (botao == 1)
                {
                    if (tbNome.Text.Equals("") || tbEndereco.Text.Equals("") || (mtbResidencial.Text.Equals("") && mtbCelular.Text.Equals("")) || cbBairro.Text.Equals("") || tbEstado.Text.Equals(""))
                    {
                        MessageBox.Show("Preencha todos os campos obrigatórios: *");
                    }
                    else
                    {
                        if (cbAtivo.Checked)
                        {
                            checkAtivo = 1;
                        }
                        else
                        {
                            checkAtivo = 0;
                        }
                        if (tbObservacao.Text == "")
                        {
                            tbObservacao.Text = " ";
                        }
                        Clientes cliente = new Clientes(tbNome.Text, BairroDAO.BuscaNome(cbBairro.Text), numero, tbEndereco.Text, tbEstado.Text, tbObservacao.Text, checkAtivo);
                        if (ClienteDAO.Inserir(cliente))
                        {
                            bCancelar_Click(sender, e);
                            MessageBox.Show("Cliente " + cliente.getNome() + " foi cadastrado com sucesso!");
                        }
                    }
                }

                if (botao == 2)
                {
                    if (tbCodigo.Text.Equals("") || tbNome.Text.Equals("") || tbEndereco.Text.Equals("") || (mtbResidencial.Text.Equals("") && mtbCelular.Text.Equals("")) || cbBairro.Text.Equals("") || tbEstado.Text.Equals(""))
                    {
                        MessageBox.Show("Preencha todos os campos obrigatórios: *");
                    }
                    else
                    {
                        if (cbAtivo.Checked)
                        {
                            checkAtivo = 1;
                        }
                        else
                        {
                            checkAtivo = 0;
                        }
                        if (tbObservacao.Text == "")
                        {
                            tbObservacao.Text = " ";
                        }
                        Clientes cliente = new Clientes(int.Parse(tbCodigo.Text), tbNome.Text, BairroDAO.BuscaNome(cbBairro.Text), numero, tbEndereco.Text, tbEstado.Text, tbObservacao.Text, checkAtivo);
                        if (ClienteDAO.Alterar(cliente))
                        {
                            bCancelar_Click(sender, e);
                            MessageBox.Show("Cliente " + cliente.getNome() + " foi alterado com sucesso!");
                        }
                    }
                }
            }catch(Exception ex){
                if (ex.Message.Contains("UniqueConstraint"))
                {
                    MessageBox.Show("Um valor único não foi informado.");
                }
                else
                {
                    MessageBox.Show("Ocorreu um erro, contate o administrador do sistema.");
                }
            }
        }
예제 #3
0
        public static bool ValidaCaracter(Clientes cliente)
        {
            for(int i = 0; i < cliente.getNome().Length; i++)
                    if (cliente.getNome()[i].Equals('0') || cliente.getNome()[i].Equals('1') || cliente.getNome()[i].Equals('2') || cliente.getNome()[i].Equals('3') || cliente.getNome()[i].Equals('4') || cliente.getNome()[i].Equals('5') || cliente.getNome()[i].Equals('6') ||  cliente.getNome()[i].Equals('7') || cliente.getNome()[i].Equals('8') || cliente.getNome()[i].Equals('9'))
                        throw new CaracterInvalidoException("O nome não pode conter caracter numérico!");

            for (int i = 0; i < cliente.getNome().Length; i++)
                if (cliente.getNome()[i].Equals('*') || cliente.getNome()[i].Equals('&') || cliente.getNome()[i].Equals('(') || cliente.getNome()[i].Equals(')') || cliente.getNome()[i].Equals('!') || cliente.getNome()[i].Equals('@') || cliente.getNome()[i].Equals('#') || cliente.getNome()[i].Equals('$') || cliente.getNome()[i].Equals('%') || cliente.getNome()[i].Equals('¨') || cliente.getNome()[i].Equals('-') || cliente.getNome()[i].Equals('_') || cliente.getNome()[i].Equals('+') || cliente.getNome()[i].Equals('=') || cliente.getNome()[i].Equals('§') || cliente.getNome()[i].Equals(',') || cliente.getNome()[i].Equals('.') || cliente.getNome()[i].Equals('/') || cliente.getNome()[i].Equals('?') || cliente.getNome()[i].Equals(':') || cliente.getNome()[i].Equals(';') || cliente.getNome()[i].Equals('|') || cliente.getNome()[i].Equals(']') || cliente.getNome()[i].Equals('}') || cliente.getNome()[i].Equals('{') || cliente.getNome()[i].Equals('['))
                    throw new CaracterInvalidoException("O nome não pode conter caracter especial!");
            int qtdEspaco = 0;
            for (int i = 0; i < cliente.getNumero().Length; i++)
                if (cliente.getNumero()[i].Equals(' '))
                    qtdEspaco++;
            if(qtdEspaco > 1)
                throw new CaracterInvalidoException("O telefone não pode conter espaço!");
            return true;
        }
예제 #4
0
 public static bool Inserir(Clientes cliente)
 {
     try
     {
         using (OracleCommand c = ConexaoOracle.ObterConexao().CreateCommand())
         {
             c.CommandType = System.Data.CommandType.Text;
             c.CommandText = "INSERT into CLIENTES values(CLIENTES_SEQ.NEXTVAL, :bairroid, :nome, :estado, :endereco, :numero, :observacao, :ativo)";
             c.Parameters.Add("bairroid", OracleType.Int32).Value = cliente.getBairroId();
             c.Parameters.Add("nome", OracleType.VarChar).Value = cliente.getNome();
             c.Parameters.Add("estado", OracleType.VarChar).Value = cliente.getEstado();
             c.Parameters.Add("endereco", OracleType.VarChar).Value = cliente.getEndereco();
             c.Parameters.Add("numero", OracleType.VarChar).Value = cliente.getNumero();
             c.Parameters.Add("observacao", OracleType.VarChar).Value = cliente.getObservacao();
             c.Parameters.Add("ativo", OracleType.Int32).Value = cliente.getAtivo();
             c.ExecuteNonQuery();
             return true;
         }
     }
     catch (OracleException e)
     {
         throw e;
     }
 }