private void btnAtualizar_Click(object sender, EventArgs e) { if (!possuiCamposVazios()) { try { //--Abrindo a conexão if (conexao_SQL.State != ConnectionState.Open) { conexao_SQL.Open(); } //--Inicializando um comando SELECT para ver se aquele nome já existe String select = "SELECT senha FROM tblCliente WHERE senha IN ('" + txtSenha.Text + "')"; comando_SQL = new SqlCommand(select, conexao_SQL); SqlDataReader tem_senha = comando_SQL.ExecuteReader(); //--Lendo a resposta tem_senha.Read(); //-- ".HasRows" é uma propriedade que mostra se teve alguma resposta if (!tem_senha.HasRows) { //--Fechando o SELECT para poder reutilizar tem_senha.Close(); if (validacao_email.IsMatch(txtEmail.Text)) { try { String select_email = "SELECT email FROM tblCliente WHERE email IN ('" + txtEmail.Text + "')"; comando_SQL = new SqlCommand(select_email, conexao_SQL); SqlDataReader email_existente = comando_SQL.ExecuteReader(); if (email_existente.HasRows) { if (txtSenha.Text.Equals(txtRepetirSenha.Text)) { this.Hide(); FrmConfirmarEmail frm = new FrmConfirmarEmail("não_possui", txtSenha.Text, txtEmail.Text, "senha"); frm.ShowDialog(); if (FrmConfirmarEmail.atualizacao_SUCCESS) { this.Close(); } else { this.Show(); txtEmail.ResetText(); txtRepetirSenha.ResetText(); txtSenha.ResetText(); } } else { lblAviso.Text = "As senhas não são iguais"; lblAviso.Visible = true; } } else { email_existente.Close(); lblAviso.Text = "Este email não existe"; lblAviso.Visible = true; } } catch (Exception) { } } else { lblAviso.Text = "O email não é valido"; lblAviso.Visible = true; } } else { tem_senha.Close(); lblAviso.Text = "Não se repete a mesma senha que esqueceu"; lblAviso.Visible = true; } } catch (Exception ex) { MessageBox.Show(ex.Message); conexao_SQL.Close(); } } else { lblAviso.Text = "Existem campos vazios"; lblAviso.Visible = true; } }
private void btnCadastrar_Click(object sender, EventArgs e) { if (!possuiCamposVazios()) { if (validacao_email.IsMatch(txtEmail.Text)) { try { //--Abrindo a conexão if (conexao_SQL.State != ConnectionState.Open) { conexao_SQL.Open(); } //--Inicializando um comando SELECT para ver se aquele nome já existe String select = "SELECT email FROM tblCliente WHERE email IN ('" + txtEmail.Text + "')"; comando_SQL = new SqlCommand(select, conexao_SQL); SqlDataReader tem_email = comando_SQL.ExecuteReader(); //--Lendo a resposta tem_email.Read(); //-- ".HasRows" é uma propriedade que mostra se teve alguma resposta if (!tem_email.HasRows) { //--Fechando o SELECT para poder reutilizar tem_email.Close(); //--Abrindo uma nova conexão if (conexao_SQL.State != ConnectionState.Open) { conexao_SQL.Open(); } //--Inicializando um comando SELECT para ver se aquele nome já existe String select_usuario = "SELECT usuario FROM tblCliente WHERE usuario IN ('" + txtUsuario.Text + "')"; comando_SQL = new SqlCommand(select_usuario, conexao_SQL); SqlDataReader tem_usuario = comando_SQL.ExecuteReader(); //--Lendo a resposta tem_usuario.Read(); //-- ".HasRows" é uma propriedade que mostra se teve alguma resposta if (!tem_usuario.HasRows) { //--Fechando o SELECT para poder reutilizar tem_usuario.Close(); if (txtSenha.Text.Equals(txtRepetirSenha.Text)) { cadastro_SUCCESS = true; Conexao.nome_usuario = txtUsuario.Text; this.Hide(); FrmConfirmarEmail frm = new FrmConfirmarEmail(txtUsuario.Text, txtSenha.Text, txtEmail.Text, "cadastro", fotoCliente.Image, loc_img); frm.ShowDialog(); if (FrmConfirmarEmail.atualizacao_SUCCESS) { this.Close(); Conexao.imagem_cliente = fotoCliente.Image; } else { this.Show(); txtEmail.ResetText(); txtRepetirSenha.ResetText(); txtSenha.ResetText(); txtUsuario.ResetText(); } } else { lblAviso.Text = "As senhas não são iguais"; lblAviso.Visible = true; } } else { lblAviso.Text = "Este nome de usuário já existe"; lblAviso.Visible = true; //--Fechando o SELECT para poder reutilizar tem_usuario.Close(); conexao_SQL.Close(); } } else { lblAviso.Text = "Este email está em outra conta"; lblAviso.Visible = true; //--Fechando o SELECT para poder reutilizar tem_email.Close(); conexao_SQL.Close(); } } catch (Exception ex) { MessageBox.Show(ex.Message); conexao_SQL.Close(); } } else { lblAviso.Text = "O email não é valido"; lblAviso.Visible = true; } } else { lblAviso.Text = "Existem campos vazios"; lblAviso.Visible = true; } }