private void btnChangePass_Click(object sender, EventArgs e)
        {
            List <TextVerifyDTO> textVerify = new List <TextVerifyDTO>();

            string Error = string.Empty;

            if (isCPF)
            {
                var user = new NaturalPerson
                           (
                    txtDoc.Text,
                    txtPass.Text
                           );

                textVerify.Add(new TextVerifyDTO(user.Senha, "Senha", 5, 10));

                foreach (string erro in TelaDeCadastro.NullOrEmpty(textVerify))
                {
                    Error += erro + "\n";
                }

                if (txtPass.Text.Length >= 5 && txtPass.Text != txtConfirmPass.Text)
                {
                    Error += "A senha confirmada está divergente da digitada no campo 'Senha'.\n";
                }

                if (string.IsNullOrEmpty(Error) || string.IsNullOrWhiteSpace(Error))
                {
                    if (NaturalPersonBLL.UpdatePass(user))
                    {
                        MessageBox.Show("A senha foi alterada com sucesso.", "Senha Alterada");
                        btnClean_Click(sender, e);
                    }
                    else
                    {
                        MessageBox.Show("Ocorreu um erro e a senha não foi alterada. Entrar em contato com o Administrador caso o erro persista.", "Senha não alterada");
                        btnClean_Click(sender, e);
                    }
                }
                else
                {
                    MessageBox.Show(Error);
                }
            }
            else
            {
                var user = new LegalPerson
                           (
                    txtDoc.Text,
                    txtPass.Text
                           );

                textVerify.Add(new TextVerifyDTO(user.Senha, "Senha", 5, 10));

                foreach (string erro in TelaDeCadastro.NullOrEmpty(textVerify))
                {
                    Error += erro + "\n";
                }

                if (txtPass.Text.Length >= 5 && txtPass.Text != txtConfirmPass.Text)
                {
                    Error += "A senha confirmada está divergente da digitada no campo 'Senha'.\n";
                }

                if (string.IsNullOrEmpty(Error) || string.IsNullOrWhiteSpace(Error))
                {
                    if (LegalPersonBLL.UpdatePass(user))
                    {
                        MessageBox.Show("A senha foi alterada com sucesso.", "Senha Alterada");
                        btnClean_Click(sender, e);
                    }
                    else
                    {
                        MessageBox.Show("Ocorreu um erro e a senha não foi alterada. Entrar em contato com o Administrador caso o erro persista.", "Senha não alterada");
                        btnClean_Click(sender, e);
                    }
                }
                else
                {
                    MessageBox.Show(Error);
                }
            }
        }
        private void btnFind_Click(object sender, EventArgs e)
        {
            string doc   = txtDocFind.Text,
                   Error = string.Empty;

            if (doc.Length == 11)//TAMANHO DO CPF
            {
                if (NaturalPerson.VerifyCPF(doc))
                {
                    isCPF = true;
                    if (NaturalPersonBLL.HasCPF(doc))
                    {
                        var person = NaturalPersonBLL.GetUserByCPF(doc);

                        txtName.Text = person.Nome;
                        txtDoc.Text  = person.CPF;
                        txtPass.Text = txtConfirmPass.Text = txtGeneratedPass.Text = string.Empty;

                        btnChangePass.Enabled = true;
                    }
                    else
                    {
                        Error += "CPF não encontrado na base de dados.";
                    }
                }
                else
                {
                    Error += "CPF Inválido.";
                }
            }
            else
            {
                if (doc.Length == 14)//TAMANHO DO CNPJ
                {
                    if (LegalPerson.VerifyCNPJ(doc))
                    {
                        isCPF = false;
                        if (LegalPersonBLL.HasCNPJ(doc))
                        {
                            var person = LegalPersonBLL.GetUserByCNPJ(doc);

                            txtName.Text = person.NomeFantasia;
                            txtDoc.Text  = person.CNPJ;
                            txtPass.Text = txtConfirmPass.Text = txtGeneratedPass.Text = string.Empty;

                            btnChangePass.Enabled = true;
                        }
                        else
                        {
                            Error += "CNPJ não encontrado na base de dados.";
                        }
                    }
                    else
                    {
                        Error += "CNPJ Inválido.";
                    }
                }
                else
                {
                    //NÃO É NEM CPF NEM CNPJ
                    Error += "Não é um CPF ou CNPJ válido.";
                }
            }

            if (!(string.IsNullOrEmpty(Error)) && !(string.IsNullOrWhiteSpace(Error)))
            {
                MessageBox.Show(Error);
            }
        }
        private void btnFind_Click(object sender, EventArgs e)
        {
            string doc   = textBox1.Text,
                   Error = string.Empty;

            string[] date;

            if (doc.Length == 11)//TAMANHO DO CPF
            {
                if (NaturalPerson.VerifyCPF(doc))
                {
                    isCPF = true;
                    if (NaturalPersonBLL.HasCPF(doc))
                    {
                        var person = NaturalPersonBLL.GetUserByCPF(doc);
                        person.Contatos = UserBLL.ListContacts(person.UserID);

                        date = person.DataNascimento.Date.ToString().Substring(0, 10).Split('/');

                        lblDate.Text          = "Data de Nasc.:";
                        lblDOC.Text           = "CPF:";
                        lblNome.Text          = "Nome:";
                        dateTimePicker1.Value = person.DataNascimento;


                        txtName.Text                = person.Nome;
                        txtDOC.Text                 = person.CPF;
                        txtEmail.Text               = person.Email;
                        txtBirthDate.Text           = $"{date[0]}/{date[1]}/{date[2]}";
                        txtContact.Text             = person.Contatos[0].Contact;
                        lblFirstContact.Text        = person.Contatos[0].ID;
                        lblFirstContact.Visible     = false;
                        txtContactSecundary.Text    = person.Contatos[1].Contact;
                        lblSecondaryContact.Text    = person.Contatos[1].ID;
                        lblSecondaryContact.Visible = false;
                        txtCEP.Text                 = person.CEP;
                        txtDistrict.Text            = person.Bairro;
                        txtStreet.Text              = person.Rua;
                        txtNumber.Text              = person.Numero;
                        txtTown.Text                = person.Cidade;
                        txtEstado.Text              = person.Estado;
                        txtComplement.Text          = person.Complemento;

                        btnRefresh.Enabled = true;
                    }
                    else
                    {
                        Error += "CPF não encontrado na base de dados.";
                    }
                }
                else
                {
                    Error += "CPF Inválido.";
                }
            }
            else
            {
                if (doc.Length == 14)//TAMANHO DO CNPJ
                {
                    if (LegalPerson.VerifyCNPJ(doc))
                    {
                        isCPF = false;
                        if (LegalPersonBLL.HasCNPJ(doc))
                        {
                            var person = LegalPersonBLL.GetUserByCNPJ(doc);
                            person.Contatos = UserBLL.ListContacts(person.UserID);

                            date = person.DataFundacao.Date.ToString().Substring(0, 10).Split('/');

                            lblDate.Text          = "Data de Fund.:";
                            lblDOC.Text           = "CNPJ:";
                            lblNome.Text          = "Nome Fantasia:";
                            dateTimePicker1.Value = person.DataFundacao;

                            txtName.Text                = person.NomeFantasia;
                            txtDOC.Text                 = person.CNPJ;
                            txtEmail.Text               = person.Email;
                            txtBirthDate.Text           = $"{date[0]}/{date[1]}/{date[2]}";
                            txtContact.Text             = person.Contatos[0].Contact;
                            lblFirstContact.Text        = person.Contatos[0].ID;
                            lblFirstContact.Visible     = false;
                            txtContactSecundary.Text    = person.Contatos[1].Contact;
                            lblSecondaryContact.Text    = person.Contatos[1].ID;
                            lblSecondaryContact.Visible = false;
                            txtCEP.Text                 = person.CEP;
                            txtDistrict.Text            = person.Bairro;
                            txtStreet.Text              = person.Rua;
                            txtNumber.Text              = person.Numero;
                            txtTown.Text                = person.Cidade;
                            txtEstado.Text              = person.Estado;
                            txtComplement.Text          = person.Complemento;

                            btnRefresh.Enabled = true;
                        }
                        else
                        {
                            Error += "CNPJ não encontrado na base de dados.";
                        }
                    }
                    else
                    {
                        Error += "CNPJ Inválido.";
                    }
                }
                else
                {
                    //NÃO É NEM CPF NEM CNPJ
                    Error += "Não é um CPF ou CNPJ válido.";
                }
            }

            if (!(string.IsNullOrEmpty(Error)) && !(string.IsNullOrWhiteSpace(Error)))
            {
                MessageBox.Show(Error);
            }
        }
示例#4
0
        /// <summary>
        /// Botão responsável por capturar os valores dos campos de cadastro de empresa.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnRegister_Click(object sender, EventArgs e)
        {
            //Endereço
            string Error = string.Empty;

            string[] date = txtFundacaoData.Text.Split('/');

            LegalPerson user = new LegalPerson
                               (
                txtCNPJ.Text,
                txtNameEmpresa.Text,
                DateTime.Parse($"{date[2]} - {date[1]} - {date[0]}"),
                txtSenhaCNJP.Text,
                " ", //CODIGO
                txtEmailCNPJ.Text,
                " ", //PALAVRASECRETA
                txtCEPcnpj.Text,
                txtRuaCNPJ.Text,
                txtBairroCNPJ.Text,
                txtCidadeCNPJ.Text,
                txtEstadoCNPJ.Text,
                txtNumeroCNPJ.Text,
                txtComplementoCNPJ.Text
                               );


            List <Contacts> Contatos = new List <Contacts>
            {
                new Contacts
                {
                    Contact = txtContatoCNPJ.Text.Length > 0 ? txtContatoCNPJ.Text:""
                },
                new Contacts
                {
                    Contact = txtContatoSecundarioCNPJ.Text.Length > 0 ? txtContatoSecundarioCNPJ.Text:""
                }
            };

            List <TextVerifyDTO> textVerify = new List <TextVerifyDTO>
            {
                new TextVerifyDTO(user.NomeFantasia, "Nome Fantasia", 3, 25),
                //new TextVerify(user.DataFundacao.Date.ToString(),"Data de Fundação", 8, 8),
                new TextVerifyDTO(user.CNPJ, "CNPJ", 14, 14),
                new TextVerifyDTO(user.Senha, "Senha", 5, 10),
                new TextVerifyDTO(user.Email, "Email", 5, 10),
                new TextVerifyDTO(Contatos[0].Contact, "Contato", 10, 11),
                new TextVerifyDTO(user.CEP, "CEP", 8, 8),
                new TextVerifyDTO(user.Rua, "Rua", 3, 100),
                new TextVerifyDTO(user.Bairro, "Bairro", 3, 100),
                new TextVerifyDTO(user.Numero, "Número", 1, 10),
                new TextVerifyDTO(user.Estado, "Estado", 3, 25),
                new TextVerifyDTO(user.Cidade, "Cidade", 3, 40)
            };

            foreach (string erro in NullOrEmpty(textVerify))
            {
                Error += erro + "\n";
            }

            if (!LegalPerson.VerifyCNPJ(user.CNPJ))
            {
                Error += "CNPJ inválido.";
            }


            if (string.IsNullOrWhiteSpace(txtConfirmarSenhaCNPJ.Text))
            {
                Error += "A senha deve ser confirmada no campo 'Confirmar Senha'.\n";
            }
            else
            {
                if (user.Senha != txtConfirmarSenhaCNPJ.Text)
                {
                    Error += "As senha não coincidem nos campos de 'Senha' e 'Confirmar Senha'.\n";
                }
            }

            if (!string.IsNullOrWhiteSpace(Contatos[1].Contact) || !string.IsNullOrEmpty(Contatos[1].Contact))
            {
                if (Contatos[1].Contact.Length >= 10)
                {
                    if (Contatos[0].Contact == Contatos[1].Contact)
                    {
                        Error += "Os contatos confirmados não devem ser iguais.\n";
                    }
                }
                else
                {
                    Error += "O contato secundário deve ter no mínimo 10 números.\n";
                }
            }

            if (LegalPersonBLL.HasCNPJ(user.CNPJ))
            {
                Error += "O CNPJ digitado já consta cadastrado no sistema.\n";
            }

            if (LegalPersonBLL.HasEmail(user.Email))
            {
                Error += "O e-mail digitado já consta cadastrado no sistema.\n";
            }

            if (string.IsNullOrEmpty(Error) || string.IsNullOrWhiteSpace(Error))
            {
                user.Contatos = Contatos;

                if (LegalPersonBLL.RegisterUser(user))
                {
                    MessageBox.Show("O novo usuário foi adicionado com sucesso.");
                }
                else
                {
                    MessageBox.Show("Ocorreu um erro e não foi possível realizar o cadastro no sistema. Contate o Administrador para maiores informações.");
                }
            }
            else
            {
                MessageBox.Show(Error);
            }
        }
        private void btnRefresh_Click(object sender, EventArgs e)
        {
            List <TextVerifyDTO> textVerify = new List <TextVerifyDTO>();

            string[] date  = txtBirthDate.Text.Split('/');
            string   Error = string.Empty;

            List <Contacts> Contatos = new List <Contacts>
            {
                new Contacts
                {
                    Contact = txtContact.Text.Length > 0 ? txtContact.Text:"",
                    ID      = lblFirstContact.Text.Length > 0 ? lblFirstContact.Text:""
                },
                new Contacts
                {
                    Contact = txtContactSecundary.Text.Length > 0 ? txtContactSecundary.Text:"",
                    ID      = lblSecondaryContact.Text.Length > 0 ? lblSecondaryContact.Text:""
                }
            };

            if (isCPF)
            {
                var user = new NaturalPerson
                           (
                    txtDOC.Text,
                    txtName.Text.ToUpper(),
                    DateTime.Parse($"{date[2]} - {date[1]} - {date[0]}"),
                    "",
                    " ", //CODIGO
                    txtEmail.Text.ToUpper(),
                    " ", //PALAVRASECRETA
                    txtCEP.Text,
                    txtStreet.Text.ToUpper(),
                    txtDistrict.Text.ToUpper(),
                    txtTown.Text.ToUpper(),
                    txtEstado.Text.ToUpper(),
                    txtNumber.Text,
                    txtComplement.Text.ToUpper()
                           );

                textVerify.Add(new TextVerifyDTO(user.Nome, "Nome", 3, 25));
                textVerify.Add(new TextVerifyDTO(user.Email, "Email", 5, 10));
                textVerify.Add(new TextVerifyDTO(Contatos[0].Contact, "Contato", 10, 11));
                textVerify.Add(new TextVerifyDTO(user.CEP, "CEP", 8, 8));
                textVerify.Add(new TextVerifyDTO(user.Rua, "Rua", 3, 100));
                textVerify.Add(new TextVerifyDTO(user.Bairro, "Bairro", 3, 100));
                textVerify.Add(new TextVerifyDTO(user.Numero, "Número", 1, 10));
                textVerify.Add(new TextVerifyDTO(user.Estado, "Estado", 3, 25));
                textVerify.Add(new TextVerifyDTO(user.Cidade, "Cidade", 3, 40));

                user.Contatos = Contatos;

                foreach (string erro in TelaDeCadastro.NullOrEmpty(textVerify))
                {
                    Error += erro + "\n";
                }

                if (!string.IsNullOrWhiteSpace(Contatos[1].Contact) || !string.IsNullOrEmpty(Contatos[1].Contact))
                {
                    if (Contatos[1].Contact.Length >= 10)
                    {
                        if (Contatos[0].Contact == Contatos[1].Contact)
                        {
                            Error += "Os contatos confirmados não devem ser iguais.\n";
                        }
                    }
                    else
                    {
                        Error += "O contato secundário deve ter no mínimo 10 números.\n";
                    }
                }

                if (string.IsNullOrEmpty(Error) || string.IsNullOrWhiteSpace(Error))
                {
                    if (isCPF)
                    {
                        if (NaturalPersonBLL.UpdateUser(user))
                        {
                            MessageBox.Show("O usuário foi atualizado com sucesso.");
                            btnClean_Click(sender, e);
                        }
                        else
                        {
                            MessageBox.Show("Ocorreu um erro e não foi possível realizar a atualização do usuário. Contate o Administrador para maiores informações.");
                            btnClean_Click(sender, e);
                        }
                    }
                }
                else
                {
                    MessageBox.Show(Error);
                }
            }
            else
            {
                var user = new LegalPerson
                           (
                    txtDOC.Text,
                    txtName.Text.ToUpper(),
                    DateTime.Parse($"{date[2]} - {date[1]} - {date[0]}"),
                    "",
                    " ", //CODIGO
                    txtEmail.Text.ToUpper(),
                    " ", //PALAVRASECRETA
                    txtCEP.Text,
                    txtStreet.Text.ToUpper(),
                    txtDistrict.Text.ToUpper(),
                    txtTown.Text.ToUpper(),
                    txtEstado.Text.ToUpper(),
                    txtNumber.Text,
                    txtComplement.Text.ToUpper()
                           );

                textVerify.Add(new TextVerifyDTO(user.NomeFantasia, "Nome Fantasia", 3, 25));
                textVerify.Add(new TextVerifyDTO(user.Email, "Email", 5, 10));
                textVerify.Add(new TextVerifyDTO(Contatos[0].Contact, "Contato", 10, 11));
                textVerify.Add(new TextVerifyDTO(user.CEP, "CEP", 8, 8));
                textVerify.Add(new TextVerifyDTO(user.Rua, "Rua", 3, 100));
                textVerify.Add(new TextVerifyDTO(user.Bairro, "Bairro", 3, 100));
                textVerify.Add(new TextVerifyDTO(user.Numero, "Número", 1, 10));
                textVerify.Add(new TextVerifyDTO(user.Estado, "Estado", 3, 25));
                textVerify.Add(new TextVerifyDTO(user.Cidade, "Cidade", 3, 40));

                user.Contatos = Contatos;

                foreach (string erro in TelaDeCadastro.NullOrEmpty(textVerify))
                {
                    Error += erro + "\n";
                }

                if (!string.IsNullOrWhiteSpace(Contatos[1].Contact) || !string.IsNullOrEmpty(Contatos[1].Contact))
                {
                    if (Contatos[1].Contact.Length >= 10)
                    {
                        if (Contatos[0].Contact == Contatos[1].Contact)
                        {
                            Error += "Os contatos confirmados não devem ser iguais.\n";
                        }
                    }
                    else
                    {
                        Error += "O contato secundário deve ter no mínimo 10 números.\n";
                    }
                }

                if (string.IsNullOrEmpty(Error) || string.IsNullOrWhiteSpace(Error))
                {
                    if (LegalPersonBLL.UpdateUser(user))
                    {
                        MessageBox.Show("O usuário foi atualizado com sucesso.");
                        btnClean_Click(sender, e);
                    }
                    else
                    {
                        MessageBox.Show("Ocorreu um erro e não foi possível realizar a atualização do usuário. Contate o Administrador para maiores informações.");
                        btnClean_Click(sender, e);
                    }
                }
                else
                {
                    MessageBox.Show(Error);
                }
            }
        }