Exemple #1
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);
            }
        }
Exemple #2
0
        private void button4_Click(object sender, EventArgs e)
        {
            if (txtNome.Text == string.Empty || txtSNome.Text == string.Empty || txtCPF.Text == string.Empty || comboSexo.Text == string.Empty || txtCidade.Text == string.Empty || comboEstado.Text == string.Empty || txtBairro.Text == string.Empty || txtRua.Text == string.Empty || txtNumero.Text == string.Empty || txtCEP.Text == string.Empty)
            {
                MessageBox.Show("Insira alguma informação para alterar!", "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (txtSenha.Text == string.Empty)
            {
                MessageBox.Show("Insira a senha para confirmar", "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            SqlConnection com = new SqlConnection(@"Data Source = SERVER151; Initial Catalog = Teste190; User ID = sa; Password = Admin2018@");

            //cria a instrução de consulta ao banco
            string query = "select * from Usuarios where Email = '" + Login.usuarioConectado + "' and Senha = '" + txtSenha.Text + "'";

            //cria o objeto command
            SqlDataAdapter adapter = new SqlDataAdapter(query, com);

            //instancia o dataset
            DataSet ds = new DataSet();

            //preenche o dataset
            adapter.Fill(ds, "a");

            if (ds.Tables[0].Rows.Count > 0)
            ////if (txtUsuario.Text == "*****@*****.**" & txtLSenha.Text == "123")
            {
                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
                {
                }
                this.conexaoSQLServer.Open();
                this.sqlcmd       = new SqlCommand();
                sqlcmd.Connection = conexaoSQLServer;
                if (sqlcmd.Parameters.Count == 0)
                {
                    this.sqlcmd.CommandText = "update Usuarios set nome = '" + txtNome.Text + "', Sobrenome = '" + txtSNome.Text + "', cpf = '" + txtCPF.Text + "', Sexo = '" + comboSexo.Text + "', cidade = '" + txtCidade.Text + "', estado = '" + comboEstado.Text + "', bairro = '" + txtBairro.Text + "', rua = '" + txtRua.Text + "', nº = '" + txtNumero.Text + "', cep = '" + txtCEP.Text + "' where Email = '" + Login.usuarioConectado + "'";
                }
            }

            else
            {
                MessageBox.Show("Senha inválida");
                return;
            }

            int iresultado = this.sqlcmd.ExecuteNonQuery();

            if (iresultado <= 0)
            {
                MessageBox.Show("Falha ao incluir no banco de dados.");
                return;
            }
            else
            {
                if (MessageBox.Show("Informações atualizadas!", "Menssagem do sistema ", MessageBoxButtons.OK, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    this.Close();
                }
            }
            this.conexaoSQLServer.Close();
        }