Esempio n. 1
0
        /// <summary>
        /// Event button to movie delete
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btn_DeleteClienteClick(object sender, EventArgs e)
        {
            DialogResult result = MessageBox.Show("Deseja Realmente Exluir Esse Cliente?", "Exclusão", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation);

            if (result == DialogResult.Yes)
            {
                try
                {
                    ClienteController.DeleteCliente(idCliente);
                    this.Close();
                }
                catch (Exception error)
                {
                    MessageBox.Show(error.Message, "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Esempio n. 2
0
        private async Task VerificaCamposAsync(int id)
        {
            #region Mensagens de retorno
            string vazio       = "Campo vazio";
            string nulo        = "Preencha o campo: ";
            string finalizado  = "Cadastro finalizado com sucesso!";
            string emails      = "Os e-mails não coincidem!";
            string senhas      = "As senhas não coincidem!";
            string dadosInsuf  = "Dados insuficientes no campo: ";
            string caracter    = "': este campos não aceita caracteres especiais.";
            string caracterInv = "Caracteres inválidos";
            string senhaCurta  = "A senha deve ter mais de 6 caracteres!";
            string atualizado  = "Cadastro atualizado com sucesso!";
            #endregion

            Cliente cliente;

            #region Variáveis

            #region Others

            /* String categoria    = etClienteCategoriaCnh.Items[etClienteCategoriaCnh.SelectedIndex];
             * String uf           = etClienteUf.Items[etClienteUf.SelectedIndex];
             * String conta        = etClienteTipoConta.Items[etClienteTipoConta.SelectedIndex];*/
            #endregion

            #region Dados Pessoais
            string nome          = etClienteNome.Text;
            string rg            = etClienteRg.Text;
            string cpf           = etClienteCpf.Text;
            string sexo          = etClienteSexo.Items[etClienteSexo.SelectedIndex];
            string dataNascto    = etClienteDataNascto.Text;
            string celular       = etClienteCelular.Text;
            string celular2      = etClienteCelular02.Text;
            int    IdTipoUsuario = 2;
            int    IdStatus      = 4;
            int    idCliente     = 1;
            #endregion

            #region Endereço
            string endereco    = etClienteEndereco.Text;
            string numero      = etClienteNumero.Text;
            string complemento = etClienteComplemento.Text;
            string bairro      = etClienteBairro.Text;
            string cidade      = etClienteCidade.Text;
            string cep         = etClienteCep.Text;
            string uf          = etClienteUf.Text;
            #endregion

            #region Dados bancários
            string   numeroCartao = etClienteNumeroCartao.Text;
            int      idBandeira   = 1;
            string   bandeira     = etClienteBandeira.Text;
            string   dataValidade = etClienteValidadeCartao.Text;
            string   nomeImpresso = etClienteNomeImpresso.Text;
            int      codSeguranca = Convert.ToInt32(etClienteCodSeguranca.Text);
            DateTime dataCadastro = DateTime.Now;
            #endregion

            #region Email e senha
            string email     = etClienteEmail.Text;
            string confemail = etClienteConfEmail.Text;
            string senha     = etClienteSenha.Text;
            string confsenha = etClienteConfSenha.Text;
            #endregion

            #endregion

            try
            {
                #region Valida - Dados Pessoais
                if (etClienteNome.IsVisible)
                {
                    #region Campos
                    if (string.IsNullOrEmpty(nome))                         // NOME
                    {
                        await DisplayAlert(vazio, nulo + lblClienteNome.Text, "OK");
                    }
                    else if (nome.Length < 6)
                    {
                        await DisplayAlert("Dados insuficientes", dadosInsuf + lblClienteNome.Text, "OK");
                    }

                    else if (string.IsNullOrEmpty(rg))                      // RG
                    {
                        await DisplayAlert(vazio, nulo + lblClienteRg.Text, "OK");
                    }
                    else if (rg.Length < 9)
                    {
                        await DisplayAlert("Dados insuficientes", dadosInsuf + lblClienteRg.Text, "OK");
                    }
                    else if (ValidaCampos.CaracterEspecial(rg))
                    {
                        await DisplayAlert(caracterInv, "'" + lblClienteRg.Text + caracter, "OK");
                    }

                    else if (string.IsNullOrEmpty(cpf))                     // CPF
                    {
                        await DisplayAlert(vazio, nulo + lblClienteCpf.Text, "OK");
                    }
                    else if (cpf.Length < 11)
                    {
                        await DisplayAlert("Dados insuficientes", dadosInsuf + lblClienteCpf.Text, "OK");
                    }
                    else if (ValidaCampos.CaracterEspecial(cpf))
                    {
                        await DisplayAlert(caracterInv, "'" + lblClienteCpf.Text + caracter, "OK");
                    }

                    else if (string.IsNullOrEmpty(sexo))                    // SEXO
                    {
                        await DisplayAlert(vazio, nulo + lblClienteSexo.Text, "OK");
                    }

                    else if (string.IsNullOrEmpty(dataNascto))              // DATA DE NASCIMENTO
                    {
                        await DisplayAlert(vazio, nulo + lblClienteDataNascto.Text, "OK");
                    }
                    else if (dataNascto.Length < 8)
                    {
                        await DisplayAlert("Dados insuficientes", dadosInsuf + lblClienteDataNascto.Text, "OK");
                    }

                    else if (string.IsNullOrEmpty(celular))                 // CELULAR
                    {
                        await DisplayAlert(vazio, nulo + lblClienteCelular.Text, "OK");
                    }
                    else if (celular.Length < 9)
                    {
                        await DisplayAlert("Dados insuficientes", dadosInsuf + lblClienteCelular.Text, "OK");
                    }
                    else if (ValidaCampos.CaracterEspecial(celular))
                    {
                        await DisplayAlert(caracterInv, "'" + lblClienteCelular.Text + caracter, "OK");
                    }

                    else if (string.IsNullOrEmpty(celular2))                // CELULAR 02
                    {
                        await DisplayAlert(vazio, nulo + lblClienteCelular02.Text, "OK");
                    }
                    else if (celular2.Length < 9)
                    {
                        await DisplayAlert("Dados insuficientes", dadosInsuf + lblClienteCelular02.Text, "OK");
                    }
                    else if (ValidaCampos.CaracterEspecial(celular2))
                    {
                        await DisplayAlert(caracterInv, "'" + lblClienteCelular02.Text + caracter, "OK");
                    }
                    #endregion

                    #region Verifica o CPF

                    /* var verificar = await control.GetCpf(cpf);
                     *
                     * string verificaCpf = verificar.Ccpf.ToString();
                     *
                     * if (verificaCpf != null)
                     * {
                     *  lblAlerta.IsVisible = true;
                     *  lblAlerta.Text = "";
                     *  lblAlerta.Text = "CPF já cadastrado!";
                     * }
                     * else
                     * { */

                    #endregion

                    DadosPessoaisNotVisible();

                    if (verificaOperacao == 1)
                    {
                        btnEndereco.IsEnabled = true;
                    }

                    btnAvancar.IsVisible = false;

                    btnAvancar2.IsVisible = true;

                    if (verificaOperacao == 1)       // INSERT
                    {
                        btnVoltar.IsVisible = true;
                    }
                    else                            // UPDATE
                    {
                        stBtnVoltar.IsVisible = true;
                    }

                    lblAlerta.IsVisible = false;

                    EnderecoVisible();
                }
                #endregion

                #region Valida - Endereço
                else if (etClienteEndereco.IsVisible)
                {
                    #region Campos
                    if (string.IsNullOrEmpty(endereco))                         // ENDEREÇO
                    {
                        await DisplayAlert(vazio, nulo + lblClienteEndereco.Text, "OK");
                    }
                    else if (endereco.Length < 5)
                    {
                        await DisplayAlert("Dados insuficientes", dadosInsuf + lblClienteEndereco.Text, "OK");
                    }

                    else if (string.IsNullOrEmpty(numero))                      // NUMERO
                    {
                        await DisplayAlert(vazio, nulo + lblClienteNumero.Text, "OK");
                    }
                    else if (ValidaCampos.CaracterEspecial(numero))
                    {
                        await DisplayAlert(caracterInv, "'" + lblClienteNumero.Text + caracter, "OK");
                    }

                    else if (string.IsNullOrEmpty(complemento))                 // COMPLEMENTO
                    {
                        await DisplayAlert(vazio, nulo + lblClienteCompl.Text, "OK");
                    }

                    else if (string.IsNullOrEmpty(bairro))                      // BAIRRO
                    {
                        await DisplayAlert(vazio, nulo + lblClienteBairro.Text, "OK");
                    }
                    else if (bairro.Length < 5)
                    {
                        await DisplayAlert("Dados insuficientes", dadosInsuf + lblClienteBairro.Text, "OK");
                    }

                    else if (string.IsNullOrEmpty(cidade))                      // CIDADE
                    {
                        await DisplayAlert(vazio, nulo + lblClienteCidade.Text, "OK");
                    }
                    else if (cidade.Length < 6)
                    {
                        await DisplayAlert("Dados insuficientes", dadosInsuf + lblClienteCidade.Text, "OK");
                    }

                    else if (string.IsNullOrEmpty(cep))                         // CEP
                    {
                        await DisplayAlert(vazio, nulo + lblClienteCep.Text, "OK");
                    }
                    else if (cep.Length < 8)
                    {
                        await DisplayAlert("Dados insuficientes", dadosInsuf + lblClienteCep.Text, "OK");
                    }
                    else if (ValidaCampos.CaracterEspecial(cep))
                    {
                        await DisplayAlert(caracterInv, "'" + lblClienteCep.Text + caracter, "OK");
                    }

                    else if (string.IsNullOrEmpty(uf))                          // UF
                    {
                        await DisplayAlert(vazio, nulo + lblClienteUf.Text, "OK");
                    }
                    else if (uf.Length < 2)
                    {
                        await DisplayAlert("Dados insuficientes", dadosInsuf + lblClienteUf.Text, "OK");
                    }
                    else if (ValidaCampos.CaracterEspecial(uf))
                    {
                        await DisplayAlert(caracterInv, "'" + lblClienteUf.Text + caracter, "OK");
                    }
                    #endregion

                    else
                    {
                        EnderecoNotVisible();

                        if (verificaOperacao != 2)  // insert
                        {
                            btnDadosBancarios.IsEnabled = true;

                            DadosBancariosVisible();
                        }
                        else                        // update
                        {
                            btnAvancar2.IsVisible = false;
                            btnSalvar.IsVisible   = true;

                            EmailSenhaVisible();
                        }
                        lblAlerta.IsVisible = false;
                    }
                }
                #endregion

                #region Valida - Dados bancários
                else if (btnDadosBancarios.IsEnabled && etClienteNumeroCartao.IsVisible)
                {
                    if (string.IsNullOrEmpty(numeroCartao))                     // NUMERO CARTAO
                    {
                        await DisplayAlert(vazio, nulo + lblClienteNumeroCartao.Text, "OK");
                    }
                    else if (numeroCartao.Length < 15)
                    {
                        await DisplayAlert("Dados insuficientes", dadosInsuf + lblClienteNumeroCartao.Text, "OK");
                    }
                    else if (ValidaCampos.CaracterEspecial(numeroCartao))
                    {
                        await DisplayAlert(caracterInv, "'" + lblClienteNumeroCartao.Text + caracter, "OK");
                    }

                    else if (string.IsNullOrEmpty(dataValidade))                // DATA VALIDADE CARTAO
                    {
                        await DisplayAlert(vazio, nulo + lblClienteValidadeCartao.Text, "OK");
                    }
                    else if (dataValidade.Length < 6)
                    {
                        await DisplayAlert("Dados insuficientes", dadosInsuf + lblClienteValidadeCartao.Text, "OK");
                    }

                    else if (string.IsNullOrEmpty(codSeguranca.ToString()))     // CODIGO SEGURANÇA
                    {
                        await DisplayAlert(vazio, nulo + lblClienteCodSeguranca.Text, "OK");
                    }
                    else if (codSeguranca.ToString().Length < 3)
                    {
                        await DisplayAlert("Dados insuficientes", dadosInsuf + lblClienteCodSeguranca.Text, "OK");
                    }
                    else if (ValidaCampos.CaracterEspecial(codSeguranca.ToString()))
                    {
                        await DisplayAlert(caracterInv, "'" + lblClienteCodSeguranca.Text + caracter, "OK");
                    }

                    else if (string.IsNullOrEmpty(nomeImpresso))                // NOME IMPRESSO
                    {
                        await DisplayAlert(vazio, nulo + lblClienteNomeImpresso.Text, "OK");
                    }
                    else if (nomeImpresso.Length < 6)
                    {
                        await DisplayAlert("Dados insuficientes", dadosInsuf + lblClienteNomeImpresso.Text, "OK");
                    }

                    else if (string.IsNullOrEmpty(bandeira))                    // BANDEIRA
                    {
                        await DisplayAlert(vazio, nulo + lblClienteBandeira.Text, "OK");
                    }
                    else if (bandeira.Length < 4)
                    {
                        await DisplayAlert("Dados insuficientes", dadosInsuf + lblClienteBandeira.Text, "OK");
                    }

                    else
                    {
                        DadosBancariosNotVisible();

                        btnAvancar2.IsVisible  = false;
                        btnFinalizar.IsVisible = true;

                        lblAlerta.IsVisible = false;

                        EmailSenhaVisible();
                    }
                }
                #endregion

                else if (etClienteEmail.IsVisible)
                {
                    #region Valida - Email e senha
                    if (string.IsNullOrEmpty(email))                        // EMAIL
                    {
                        await DisplayAlert(vazio, nulo + lblClienteEmail.Text, "OK");
                    }
                    else if (string.IsNullOrEmpty(senha))                   // SENHA
                    {
                        await DisplayAlert(vazio, nulo + lblClienteSenha.Text, "OK");
                    }
                    else if (senha.Length < 6)                              // SENHA
                    {
                        await DisplayAlert("Dados insuficientes", senhaCurta, "OK");
                    }

                    else if (!ValidaCampos.IsEmail(email))                  // VALIDANDO E-MAIL
                    {
                        await DisplayAlert(caracterInv, "E-mail inválido!", "OK");
                    }
                    #endregion

                    #region Insert

                    else if (verificaOperacao == 1)
                    {
                        if (string.IsNullOrEmpty(confemail))               // CONFIRMAÇÃO DE EMAIL
                        {
                            await DisplayAlert(vazio, nulo + lblClienteConfEmail.Text, "OK");
                        }

                        else if (!email.Equals(confemail))                      // COMPARA E-MAIL
                        {
                            await DisplayAlert("Emails", emails, "OK");
                        }

                        else if (string.IsNullOrEmpty(confsenha))               // CONFIRMAÇÃO DE SENHA
                        {
                            await DisplayAlert(vazio, nulo + lblClienteConfSenha.Text, "OK");
                        }

                        else if (!senha.Equals(confsenha))                  // COMPARA SENHA
                        {
                            await DisplayAlert("Senhas", senhas, "OK");
                        }

                        else
                        {
                            //-------------------------------------------------------------------------
                            // Salvando ...

                            #region Cliente()
                            cliente = new Cliente
                                          (nome, rg, cpf, sexo, dataNascto, celular, celular2, endereco, numero,
                                          complemento, bairro, cidade, cep, uf, email, senha, IdTipoUsuario, IdStatus
                                          );
                            #endregion

                            etClienteSexo.SelectedItem = "F";

                            #region INSERT

                            if (id == 1)
                            {
                                await control.PostAsync(cliente);       // Insert -Tab. Cliente

                                // Captura o IdCliente gerado no banco
                                Cliente clien = await control.GetCpf(cpf);

                                #region CartaoCredito()

                                CartaoCredito cartao = new CartaoCredito()
                                {
                                    IdCliente          = clien.IdCliente,
                                    Ccpf               = cpf,
                                    CNumeroCartao      = numeroCartao,
                                    IdBandeira         = idBandeira,
                                    CDataValidade      = dataValidade,
                                    CCodigoSeg         = codSeguranca,
                                    CDataCadastro      = DateTime.Now,
                                    IdStatus           = 4,
                                    CDataInativacao    = null,
                                    CUltimaAtualizacao = null,
                                    BandeiraDescricao  = bandeira,
                                    NomeImpresso       = nomeImpresso
                                };
                                #endregion

                                await controlCartao.PostCartaoAsync(cartao);    // Insert - Tab. Cartao

                                btnFinalizar.IsVisible = false;
                                btnVoltar.IsVisible    = false;
                                lblAlerta.IsVisible    = false;

                                await DisplayAlert("Sucesso!", "Cadastro realizado com sucesso!", "OK");

                                EmailSenhaNotVisible();

                                // Direciona para a tela de login
                                await Navigation.PushModalAsync(new Views.Login());

                                //btnLogar.IsVisible     = true;
                            }

                            #endregion
                        }
                    }
                    #endregion

                    else
                    {
                        //-------------------------------------------------------------------------
                        // Salvando ...

                        #region Cliente()
                        cliente = new Cliente
                                      (nome, rg, cpf, sexo, dataNascto, celular, celular2, endereco, numero,
                                      complemento, bairro, cidade, cep, uf, email, senha, IdTipoUsuario, IdStatus
                                      );
                        #endregion

                        #region UPDATE

                        if (id == 2)
                        {
                            await control.UpdateCliente(cliente, idCli);

                            await DisplayAlert("Sucesso!", "Cadastro realizado com sucesso!", "OK");  // Confirma a atualização

                            EmailSenhaNotVisible();

                            btnSalvar.IsVisible = false;

                            await Navigation.PushModalAsync(new Views.LgMinhaContaa());  // Direciona para 'Minha Conta'
                        }

                        #endregion

                        //-------------------------------------------------------------------------
                    }
                }
            }
            catch (Exception ex)
            {
                if (ex.Source != null)
                {
                    //await DisplayAlert("Erro", ex.ToString(), "OK");
                    await DisplayAlert("Erro", ex.ToString(), "OK");

                    Console.WriteLine("Exception source: {0}", ex.Source);

                    // Caso não seja possível realizar o processo de cadastro total (de todas as classes),
                    // é excluído o que já foi cadastrado.

                    #region Exclui registros cadastrados caso não tenha sido possível inserir os dados em todas as classes envolvidas
                    Cliente clien = await control.GetCpf(cpf);

                    // Pega o ID do cliente gerado  ----  //int idCliente = clien.IdCliente;

                    if (control.GetCpf(cpf) != null)
                    {
                        await control.DeleteCliente(idCliente);
                    }
                    #endregion
                }
                throw;
            }
        }