Example #1
0
        public void CadUsuario(trfUsuario Usuario)
        {
            //limpar parametros para garantir o funcionamento
            SQL.LimparParametros();

            SQL.AdicionarParametro(new SqlParameter("@Nome", Usuario.Nome));
            SQL.AdicionarParametro(new SqlParameter("@Sobrenome", Usuario.Sobrenome));
            SQL.AdicionarParametro(new SqlParameter("@Email", Usuario.Email));
            SQL.AdicionarParametro(new SqlParameter("@CPF", Usuario.CPF));
            SQL.AdicionarParametro(new SqlParameter("@Celular", Usuario.Celular));
            SQL.AdicionarParametro(new SqlParameter("@Sexo", Usuario.Sexo));
            SQL.AdicionarParametro(new SqlParameter("@Cidade", Usuario.Cidade));
            SQL.AdicionarParametro(new SqlParameter("@Estado", Usuario.Estado));
            SQL.AdicionarParametro(new SqlParameter("@Bairro", Usuario.Bairro));
            SQL.AdicionarParametro(new SqlParameter("@Rua", Usuario.Rua));
            SQL.AdicionarParametro(new SqlParameter("@Senha", Usuario.Senha));

            SQL.ExecutarScalar("CadUsuario");
        }
Example #2
0
        private void button4_Click(object sender, EventArgs e)
        {
            if (txtNome.Text == string.Empty || txtSNome.Text == string.Empty || txtCPF.Text == string.Empty || txtCelular.Text == string.Empty || comboSexo.Text == string.Empty || txtCidade.Text == string.Empty || comboEstado.Text == string.Empty || txtBairro.Text == string.Empty || txtRua.Text == string.Empty || txtSenha.Text == string.Empty || txtCSenha.Text == string.Empty || txtNumero.Text == string.Empty || txtCEP.Text == string.Empty)
            {
                MessageBox.Show("Há campos vazios!", "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            else
            {
            }
            int    v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11;
            string Pontos;

            Pontos = txtCPF.Text.Replace(".", "").Replace("/", "").Replace("-", "");
            try
            {
                v1  = Convert.ToInt32(Pontos.Substring(0, 1));
                v2  = Convert.ToInt32(Pontos.Substring(1, 1));
                v3  = Convert.ToInt32(Pontos.Substring(2, 1));
                v4  = Convert.ToInt32(Pontos.Substring(3, 1));
                v5  = Convert.ToInt32(Pontos.Substring(4, 1));
                v6  = Convert.ToInt32(Pontos.Substring(5, 1));
                v7  = Convert.ToInt32(Pontos.Substring(6, 1));
                v8  = Convert.ToInt32(Pontos.Substring(7, 1));
                v9  = Convert.ToInt32(Pontos.Substring(8, 1));
                v10 = Convert.ToInt32(Pontos.Substring(9, 1));
                v11 = Convert.ToInt32(Pontos.Substring(10, 1));

                int soma1, soma2;
                soma1 = (v1 * 10 + v2 * 9 + v3 * 8 + v4 * 7 + v5 * 6 + v6 * 5 + v7 * 4 + v8 * 3 + v9 * 2) % 11;
                if (soma1 < 2)
                {
                    soma1 = 0;
                }
                else
                {
                    soma1 = 11 - soma1;
                }

                soma2 = (v1 * 11 + v2 * 10 + v3 * 9 + v4 * 8 + v5 * 7 + v6 * 6 + v7 * 5 + v8 * 4 + v9 * 3 + v10 * 2) % 11;
                if (soma2 < 2)
                {
                    soma2 = 0;
                }
                else
                {
                    soma2 = 11 - soma2;
                }



                if ((v10 == soma1 && v11 == soma2))
                {
                }
                else
                {
                    MessageBox.Show("CPF Inválido", "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }
            catch
            {
                MessageBox.Show("Estão faltando Valores", "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (txtSenha.Text == txtCSenha.Text)
            {
                trfUsuario Usuario = new trfUsuario();

                Usuario.Nome      = txtNome.Text;
                Usuario.Sobrenome = txtSNome.Text;
                Usuario.Email     = txtEmail.Text;
                Usuario.CPF       = txtCPF.Text;
                Usuario.Celular   = txtCelular.Text;
                Usuario.Sexo      = comboSexo.Text;
                Usuario.Cidade    = txtCidade.Text;
                Usuario.Estado    = comboEstado.Text;
                Usuario.Bairro    = txtBairro.Text;
                Usuario.Rua       = txtRua.Text;
                Usuario.Senha     = txtSenha.Text;
                Usuario.Nº        = txtNumero.Text;
                Usuario.CEP       = txtCEP.Text;

                negUsuario neg = new negUsuario();
                neg.CadUsuario(Usuario);

                txtNome.Text     = "";
                txtSNome.Text    = "";
                txtEmail.Text    = "";
                txtCPF.Text      = "";
                txtCelular.Text  = "";
                comboSexo.Text   = "";
                txtCidade.Text   = "";
                comboEstado.Text = "";
                txtBairro.Text   = "";
                txtRua.Text      = "";
                txtSenha.Text    = "";
                txtCSenha.Text   = "";
                txtNumero.Text   = "";
                txtCEP.Text      = "";

                MessageBox.Show("Cadastrado com sucesso.", "Criar conta", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                MessageBox.Show("As senhas não correspondem!", "Erro", MessageBoxButtons.OK);
            }
        }