private void carregarInfPalavra() { // Carregar dados da palavra proibida nos itens do groupBox PalavrasProibidas p = palavrasDAO.select(Convert.ToInt16(dataGridView.CurrentRow.Cells["ID"].Value.ToString())); textPalavra.Text = p.Palavra; }
public void delete(int id) { PalavrasProibidas palavraExc = db.PalavrasProibidas.Where(x => x.Id == id).First(); db.PalavrasProibidas.Remove(palavraExc); db.SaveChanges(); }
public void update(PalavrasProibidas palavraInf) { PalavrasProibidas palavraAlt = db.PalavrasProibidas.Where(x => x.Id == palavraInf.Id).First(); palavraAlt.Palavra = palavraInf.Palavra; db.SaveChanges(); }
private void salvarPalavra() { #region Validação de campos errorProvider.SetError(textPalavra, string.Empty); if (textPalavra.Text.Trim().Equals("")) { errorProvider.SetError(textPalavra, "Digite uma palavra válida"); textPalavra.Focus(); return; } #endregion PalavrasProibidas palavra = new PalavrasProibidas(); palavra.Palavra = textPalavra.Text.Trim(); switch (groupBoxPalavras.Text) { case "Inclusão de Palavra Proibida": if (!palavrasDAO.validacaoPalavra(textPalavra.Text.Trim())) { errorProvider.SetError(textPalavra, "Palavra já cadastrada"); return; } palavrasDAO.insert(palavra); break; case "Alteração de Palavra Proibida": palavra.Id = Convert.ToInt16(dataGridView.CurrentRow.Cells["ID"].Value.ToString()); if (!palavrasDAO.validacaoPalavra(textPalavra.Text.Trim())) { errorProvider.SetError(textPalavra, "Palavra já cadastrada"); return; } palavrasDAO.update(palavra); break; } limparCampos(); carregarPalavras(); }
private void btSalvar_Click(object sender, EventArgs e) { #region Validação dos componentes if (textNome.Text.Trim().Equals("")) { MessageBox.Show("Digite um nome válido.", "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Information); textNome.Focus(); return; } if (comboTipo.SelectedIndex == -1) { MessageBox.Show("Selecione um tipo de usuário válido.", "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Information); comboTipo.Focus(); return; } #endregion #region Verifica se existe alguma palavra proibida na senha //Verifica se existe alguma palavra proibida na senha. PalavrasProibidas palavra = new PalavrasProibidas(); DataTable dts = new DataTable(); dts = palavra.select(" where nome like '%" + textSenha.Text + "%'"); if (dts.Rows.Count == 1) { MessageBox.Show("Esta senha possui uma palavra proibida pelo sistema. Por favor escolha outra senha.", "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Information); textSenha.Focus(); return; } #endregion try { #region Verifica se o nome de usuario já esta sendo utilizado Usuarios usuarios = new Usuarios(); DataTable dt = new DataTable(); ////Verifica se o nome ja esta sendo utilizado pelo usuario que tas alterando. dt = usuarios.select(" where nome = '" + textNome.Text + "'" + " and id_login != " + id2); if (dt.Rows.Count == 1) { MessageBox.Show("Este nome de usuário já esta sendo utilizado.", "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Information); textNome.Focus(); textNome.Clear(); return; } #endregion #region Validação da politica de senha if (textSenha.Text.Trim().Equals("") && textConfirmeSenha.Text.Trim().Equals("")) { usuarios.Id = Convert.ToInt16(id2); usuarios.Nome = textNome.Text.Trim(); //usuarios.Senha = getMD5(textSenha.Text.Trim()); usuarios.IsAdmin = comboTipo.SelectedItem.ToString(); usuarios.updateVerificaSenha(); } else { //Verifica se a senha digitada nos dois campos sao iguais. if (textSenha.Text.Trim() != textConfirmeSenha.Text.Trim()) { MessageBox.Show("Senha incorreta.", "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Information); textConfirmeSenha.Focus(); return; } //Verifica o tamanho da senha, pra ela ter no minimo 6 caracteres. if (textSenha.Text.Length < 6) { MessageBox.Show("Senha muito fraca.", "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Information); textSenha.Focus(); return; } //Verifica o tamanho da senha, pra ela ter no máximo 12 caracteres. if (textSenha.Text.Length > 12) { MessageBox.Show("A Senha pode ter no máximo 12 caracteres.", "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Information); textSenha.Focus(); return; } //Verifica o tamanho da senha, pra ela ter no minimo 6 caracteres. if (textConfirmeSenha.Text.Length < 6) { MessageBox.Show("Senha muito fraca.", "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Information); textConfirmeSenha.Focus(); return; } //Verifica o tamanho da senha, pra ela ter no máximo 12 caracteres. if (textConfirmeSenha.Text.Length > 12) { MessageBox.Show("A Senha pode ter no máximo 12 caracteres.", "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Information); textConfirmeSenha.Focus(); return; } var regexEsp = new Regex("^[a-zA-Z0-9 ]*$"); //Verificar se existe pelo menos um número ou caracter especial digitado na senha. if (!textSenha.Text.Any(c => char.IsDigit(c)) && regexEsp.IsMatch(textSenha.Text)) { MessageBox.Show("Senha muito fraca. Tem que ter pelo menos um número ou caracter especial digitado na senha.", "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Information); textConfirmeSenha.Focus(); return; } //Verificar se existe pelo menos um número ou caracter especial digitado na senha. if (!textConfirmeSenha.Text.Any(c => char.IsDigit(c)) && regexEsp.IsMatch(textConfirmeSenha.Text)) { MessageBox.Show("Senha muito fraca. Tem que ter pelo menos um número ou caracter especial digitado na senha.", "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Information); textConfirmeSenha.Focus(); return; } //Verifica se existe pelo menos uma letra maiúscula. if (!textSenha.Text.Any(c => char.IsUpper(c))) { MessageBox.Show("Senha muito fraca. Tem que ter pelo menos um caracter maiúsculo na senha.", "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Information); textSenha.Focus(); return; } //Verifica se existe pelo menos uma letra maiúscula. if (!textConfirmeSenha.Text.Any(c => char.IsUpper(c))) { MessageBox.Show("Senha muito fraca. Tem que ter pelo menos um caracter maiúsculo na senha.", "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Information); textConfirmeSenha.Focus(); return; } //Verifica se existe pelo menos um caracter minúsculo. if (!textSenha.Text.Any(c => char.IsLower(c))) { MessageBox.Show("Senha muito fraca. Tem que ter pelo menos um caracter minúsculo na senha.", "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Information); textSenha.Focus(); return; } //Verifica se existe pelo menos um caracter minúsculo. if (!textConfirmeSenha.Text.Any(c => char.IsLower(c))) { MessageBox.Show("Senha muito fraca. Tem que ter pelo menos um caracter minúsculo na senha.", "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Information); textConfirmeSenha.Focus(); return; } #region Alterar os dados usuarios.Id = Convert.ToInt16(id2); usuarios.Nome = textNome.Text.Trim(); //Utilização do SALT na senha usuarios.Senha = getMD5(textSenha.Text.Trim() + "1Sport8Fitne55%"); usuarios.IsAdmin = comboTipo.SelectedItem.ToString(); usuarios.update(); #endregion } MessageBox.Show("Usuário Alterado com Sucesso."); #endregion #region Gravar o log //Geracao de log Logs logs = new Logs(); string linha; using (StreamReader reader = new StreamReader("user.txt")) { linha = reader.ReadLine(); } logs.IdUsuario = Convert.ToInt16(linha.ToString()); logs.IdAcao = 12; logs.Data = DateTime.Today.ToString("dd/MM/yyyy"); logs.Hora = DateTime.Now.ToString("HH:mm"); logs.insert(); #endregion this.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public void insert(PalavrasProibidas palavraInf) { db.PalavrasProibidas.Add(palavraInf); db.SaveChanges(); }
private void btSalvar_Click(object sender, EventArgs e) { #region Validação dos componentes do cadastro //Verifica se o campo esta vazio if (textNome.Text.Trim().Equals("")) { MessageBox.Show("Digite um nome válido.", "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Information); textNome.Focus(); return; } //Verifica se o campo esta vazio if (maskedTextCpf.Text.Trim().Length < 14) { MessageBox.Show("Digite um cpf válido.", "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Information); maskedTextCpf.Focus(); return; } //Verifica se o campo esta vazio if (dateNasc.Text.Trim().Length < 10) { MessageBox.Show("Digite uma data de nascimento válida.", "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Information); dateNasc.Focus(); return; } //Verifica se o campo esta vazio if (comboEstado.SelectedIndex == -1) { MessageBox.Show("Selecione um estado.", "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Information); comboEstado.Focus(); return; } //Verifica se o campo esta vazio if (comboCidade.SelectedIndex == -1) { MessageBox.Show("Digite uma cidade válida.", "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Information); comboCidade.Focus(); return; } //Verifica se o campo esta vazio if (textBairro.Text.Trim().Equals("")) { MessageBox.Show("Digite um nome válido.", "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Information); textBairro.Focus(); return; } //Verifica se o campo esta vazio if (textEndereco.Text.Trim().Equals("")) { MessageBox.Show("Digite um endereço válido.", "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Information); textEndereco.Focus(); return; } //Verifica se o campo esta vazio if (maskedTextCep.Text.Trim().Length < 9) { MessageBox.Show("Digite um CEP válido.", "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Information); dateNasc.Focus(); return; } //Verifica se a senha são diferentes if (textSenha.Text.Trim() != textConfirmeSenha.Text.Trim()) { MessageBox.Show("Senha incorreta.", "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Information); textConfirmeSenha.Focus(); return; } //Verifica se o campo esta vazio if (textEmail.Text.Trim().Equals("")) { MessageBox.Show("Digite um email válido.", "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Information); textEmail.Focus(); return; } #endregion #region Validação de Email string email = textEmail.Text; Regex rg = new Regex(@"^[A-Za-z0-9](([_\.\-]?[a-zA-Z0-9]+)*)@([A-Za-z0-9]+)(([\.\-]?[a-zA-Z0-9]+)*)\.([A-Za-z]{2,})$"); if (rg.IsMatch(email)) { //MessageBox.Show("Email Valido!"); } else { MessageBox.Show("Email Inválido!"); textEmail.Focus(); return; } #endregion #region Validação de CPF if (maskedTextCpf.Text == "111,111,111-11") { MessageBox.Show("CPF INVÁLIDO!"); maskedTextCpf.Focus(); return; } else if (maskedTextCpf.Text == "222,222,222-22") { MessageBox.Show("CPF INVÁLIDO!"); maskedTextCpf.Focus(); return; } else if (maskedTextCpf.Text == "333,333,333-33") { MessageBox.Show("CPF INVÁLIDO!"); maskedTextCpf.Focus(); return; } else if (maskedTextCpf.Text == "444,444,444-44") { MessageBox.Show("CPF INVÁLIDO!"); maskedTextCpf.Focus(); return; } else if (maskedTextCpf.Text == "555,555,555-55") { MessageBox.Show("CPF INVÁLIDO!"); maskedTextCpf.Focus(); return; } else if (maskedTextCpf.Text == "666,666,666-66") { MessageBox.Show("CPF INVÁLIDO!"); maskedTextCpf.Focus(); return; } else if (maskedTextCpf.Text == "777,777,777-77") { MessageBox.Show("CPF INVÁLIDO!"); maskedTextCpf.Focus(); return; } else if (maskedTextCpf.Text == "888,888,888-88") { MessageBox.Show("CPF INVÁLIDO!"); maskedTextCpf.Focus(); return; } else if (maskedTextCpf.Text == "999,999,999-99") { MessageBox.Show("CPF INVÁLIDO!"); maskedTextCpf.Focus(); return; } #endregion #region Verifica se existe alguma palavra proibida na senha //Verifica se existe alguma palavra proibida na senha. PalavrasProibidas palavra = new PalavrasProibidas(); DataTable dts = new DataTable(); dts = palavra.select(" where nome like '%" + textSenha.Text + "%'"); if (dts.Rows.Count == 1) { MessageBox.Show("Esta senha possui uma palavra proibida pelo sistema. Por favor escolha outra senha.", "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Information); textSenha.Focus(); return; } #endregion #region Verifica se o email ja esta sendo utilizado //Verifica se o email ja esta sendo utilizado. Alunos aluno = new Alunos(); DataTable dt = new DataTable(); dt = aluno.selectVerificacaoEmail(" where email = '" + textEmail.Text + "' and id_aluno != " + id2); if (dt.Rows.Count == 1) { MessageBox.Show("Este email já esta sendo utilizado.", "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Information); textEmail.Focus(); textEmail.Clear(); return; } #endregion #region Validação do CPF int primeiroDigitoVerif, segundoDigitoVerif, soma = 0, j = 0; // Deixar somente os números do documento string documento = Regex.Replace(maskedTextCpf.Text, @"[^\d]", ""); for (int i = 10; i >= 2; i--) { soma += i * Convert.ToInt16(documento[j].ToString()); j++; } primeiroDigitoVerif = 11 - (soma % 11); if (primeiroDigitoVerif == 10 || primeiroDigitoVerif == 11) { primeiroDigitoVerif = 0; } if (primeiroDigitoVerif != Convert.ToInt16(documento[documento.Length - 2].ToString())) { MessageBox.Show("CPF INVÁLIDO!"); maskedTextCpf.Focus(); return; } else { j = 0; soma = 0; for (int i = 11; i > 2; i--) { soma += i * Convert.ToInt16(documento[j].ToString()); j++; } soma += 2 * primeiroDigitoVerif; segundoDigitoVerif = 11 - (soma % 11); if (segundoDigitoVerif != Convert.ToInt16(documento[documento.Length - 1].ToString())) { MessageBox.Show("CPF INVÁLIDO!"); maskedTextCpf.Focus(); return; } } #endregion #region Salvar os dados try { //Verifica se o campos das senhas esta vazias if (textSenha.Text.Trim().Equals("") && textConfirmeSenha.Text.Trim().Equals("")) { Alunos alunos = new Alunos(); alunos.Id = Convert.ToInt16(id2); alunos.Nome = textNome.Text.Trim(); alunos.Cpf = maskedTextCpf.Text; alunos.DataNasc = dateNasc.Text; alunos.Cep = maskedTextCep.Text; alunos.Endereco = textEndereco.Text.Trim(); alunos.Bairro = textBairro.Text.Trim(); alunos.TelefoneRes = maskedTextTelefoneRes.Text; alunos.TelefoneCel = maskedTextTelefoneCel.Text; alunos.Email = textEmail.Text.Trim(); //alunos.Senha = getMD5(textSenha.Text.Trim()); alunos.Observacao = textObservacao.Text.Trim(); alunos.IdCidade = Convert.ToInt16(comboCidade.SelectedValue.ToString()); // Comando para gravar o sexo do aluno if (this.radioMasc.Checked == true) { alunos.Sexo = Convert.ToChar('M'); } else { alunos.Sexo = Convert.ToChar('F'); } string linha; using (StreamReader reader = new StreamReader("user.txt")) { linha = reader.ReadLine(); } alunos.IdUsuario = Convert.ToInt16(linha.ToString()); // Console.WriteLine("USUARIO: " + Convert.ToInt16(linha.ToString())); alunos.updateVerificaSenha(); MessageBox.Show("Aluno Alterado com Sucesso."); this.Close(); } //Verifica se tem algo digitado nos campos das senhas else { #region Verificação da politica de senha //Verifica o tamanho da senha, pra ela ter no minimo 6 caracteres. if (textSenha.Text.Length < 6) { MessageBox.Show("Senha muito fraca.", "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Information); textSenha.Focus(); return; } //Verifica o tamanho da senha, pra ela ter no máximo 12 caracteres. if (textSenha.Text.Length > 12) { MessageBox.Show("A Senha pode ter no máximo 12 caracteres.", "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Information); textSenha.Focus(); return; } //Verifica o tamanho da senha, pra ela ter no minimo 6 caracteres. if (textConfirmeSenha.Text.Length < 6) { MessageBox.Show("Senha muito fraca.", "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Information); textConfirmeSenha.Focus(); return; } //Verifica o tamanho da senha, pra ela ter no máximo 12 caracteres. if (textConfirmeSenha.Text.Length > 12) { MessageBox.Show("A Senha pode ter no máximo 12 caracteres.", "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Information); textConfirmeSenha.Focus(); return; } var regexEsp = new Regex("^[a-zA-Z0-9 ]*$"); //Verificar se existe pelo menos um número ou caracter especial digitado na senha. if (!textSenha.Text.Any(c => char.IsDigit(c)) && regexEsp.IsMatch(textSenha.Text)) { MessageBox.Show("Senha muito fraca. Tem que ter pelo menos um número ou caracter especial digitado na senha.", "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Information); textConfirmeSenha.Focus(); return; } //Verificar se existe pelo menos um número ou caracter especial digitado na senha. if (!textConfirmeSenha.Text.Any(c => char.IsDigit(c)) && regexEsp.IsMatch(textConfirmeSenha.Text)) { MessageBox.Show("Senha muito fraca. Tem que ter pelo menos um número ou caracter especial digitado na senha.", "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Information); textConfirmeSenha.Focus(); return; } //Verifica se existe pelo menos uma letra maiúscula. if (!textSenha.Text.Any(c => char.IsUpper(c))) { MessageBox.Show("Senha muito fraca. Tem que ter pelo menos um caracter maiúsculo na senha.", "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Information); textSenha.Focus(); return; } //Verifica se existe pelo menos uma letra maiúscula. if (!textConfirmeSenha.Text.Any(c => char.IsUpper(c))) { MessageBox.Show("Senha muito fraca. Tem que ter pelo menos um caracter maiúsculo na senha.", "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Information); textConfirmeSenha.Focus(); return; } //Verifica se existe pelo menos um caracter minúsculo. if (!textSenha.Text.Any(c => char.IsLower(c))) { MessageBox.Show("Senha muito fraca. Tem que ter pelo menos um caracter minúsculo na senha.", "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Information); textSenha.Focus(); return; } //Verifica se existe pelo menos um caracter minúsculo. if (!textConfirmeSenha.Text.Any(c => char.IsLower(c))) { MessageBox.Show("Senha muito fraca. Tem que ter pelo menos um caracter minúsculo na senha.", "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Information); textConfirmeSenha.Focus(); return; } #endregion Alunos alunos = new Alunos(); alunos.Id = Convert.ToInt16(id2); alunos.Nome = textNome.Text.Trim(); alunos.Cpf = maskedTextCpf.Text; alunos.DataNasc = dateNasc.Text; alunos.Cep = maskedTextCep.Text; alunos.Endereco = textEndereco.Text.Trim(); alunos.Bairro = textBairro.Text.Trim(); alunos.TelefoneRes = maskedTextTelefoneRes.Text; alunos.TelefoneCel = maskedTextTelefoneCel.Text; alunos.Email = textEmail.Text.Trim(); alunos.Senha = getMD5(textSenha.Text.Trim() + "1Sport8Fitne55%"); alunos.Observacao = textObservacao.Text.Trim(); alunos.IdCidade = Convert.ToInt16(comboCidade.SelectedValue.ToString()); // Comando para gravar o sexo do aluno if (this.radioMasc.Checked == true) { alunos.Sexo = Convert.ToChar('M'); } else { alunos.Sexo = Convert.ToChar('F'); } string linha; using (StreamReader reader = new StreamReader("user.txt")) { linha = reader.ReadLine(); } alunos.IdUsuario = Convert.ToInt16(linha.ToString()); // Console.WriteLine("USUARIO: " + Convert.ToInt16(linha.ToString())); alunos.update(); MessageBox.Show("Aluno Alterado com Sucesso."); this.Close(); } #region Gravar o log //Geracao de log Logs logs = new Logs(); string linha2; using (StreamReader reader = new StreamReader("user.txt")) { linha2 = reader.ReadLine(); } logs.IdUsuario = Convert.ToInt16(linha2.ToString()); logs.IdAcao = 14; logs.Data = DateTime.Today.ToString("dd/MM/yyyy"); logs.Hora = DateTime.Now.ToString("HH:mm"); logs.insert(); #endregion } catch (Exception ex) { MessageBox.Show(ex.Message); } #endregion }