private void textPesquisa_TextChanged(object sender, EventArgs e) { Treinadores func = new Treinadores(); dataGridViewTreinadores.DataSource = func.select("where nome like '%" + textPesquisa.Text + "%'"); // dataGridViewTreinadores.DataSource = func.select("where nome like '%"+textPesquisa.Text+ "%' or sobrenome like '%" + textPesquisa.Text + "%'"); }
public ArrayList selectArray(string options = "") { ArrayList dados = new ArrayList(); MySqlConnection cn = new MySqlConnection(dbConnection.Conecta); cn.Open(); MySqlCommand cmd = new MySqlCommand("select * from treinadores " + options, cn); MySqlDataReader dr = cmd.ExecuteReader(); while (dr.Read()) { Treinadores trein = new Treinadores(); trein.Id = Convert.ToInt16(dr["id_treinador"]); trein.Nome = dr["nome"].ToString(); trein.Email = dr["email"].ToString(); trein.TelefoneRes = dr["telefoneRes"].ToString(); trein.TelefoneCel = dr["telefoneCel"].ToString(); trein.DataNasc = dr["dataNasc"].ToString(); trein.Cpf = dr["cpf"].ToString(); trein.Cep = dr["cep"].ToString(); trein.Endereco = dr["endereco"].ToString(); trein.Bairro = dr["bairro"].ToString(); trein.Observacao = dr["observacao"].ToString(); dados.Add(trein); } dr.Close(); cn.Close(); return(dados); }
private void btDeletar_Click(object sender, EventArgs e) { try { DialogResult resposta = MessageBox.Show("Excluir o Treinador '" + dataGridViewTreinadores.CurrentRow.Cells[2].Value.ToString() + "' ?", "Atenção", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (resposta == DialogResult.Yes) { try { Treinadores trein = new Treinadores(); trein.Id = Convert.ToInt16(dataGridViewTreinadores.CurrentRow.Cells[1].Value); trein.delete(); //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 = 24; logs.Data = DateTime.Today.ToString("dd/MM/yyyy"); logs.Hora = DateTime.Now.ToString("HH:mm"); logs.insert(); FrmTabTreinadores_Activated(sender, e); } catch (Exception ex) { MessageBox.Show(ex.Message); } } } catch { MessageBox.Show("Não há treinadores cadastrados.", "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
public FrmAltTreinadores(int id) { InitializeComponent(); Treinadores treinadores = new Treinadores(); ArrayList array = treinadores.selectArray("where id_treinador = " + id); foreach (Treinadores treinador in array) { id2 = treinador.Id; textNome.Text = treinador.Nome; maskedTextCpf.Text = treinador.Cpf; dateNasc.Text = treinador.DataNasc; maskedTextCep.Text = treinador.Cep; textEndereco.Text = treinador.Endereco; textBairro.Text = treinador.Bairro; maskedTextTelefoneRes.Text = treinador.TelefoneRes; maskedTextTelefoneCel.Text = treinador.TelefoneCel; textEmail.Text = treinador.Email; textObservacao.Text = treinador.Observacao; } }
private void FrmAltTreino_Activated(object sender, EventArgs e) { #region Carrega os Alunos try { Alunos aluno = new Alunos(); ArrayList array = aluno.selectArray("order by nome"); comboAluno.DataSource = array; comboAluno.DisplayMember = "nome"; comboAluno.ValueMember = "id"; } catch { } #endregion #region Carrega os Treinadores try { Treinadores treinador = new Treinadores(); ArrayList array = treinador.selectArray("order by nome"); comboTreinador.DataSource = array; comboTreinador.DisplayMember = "nome"; comboTreinador.ValueMember = "id"; } catch { } #endregion #region Carrega os Objetivos try { Objetivo objetivo = new Objetivo(); ArrayList array = objetivo.selectArray("order by nome"); comboObjetivo.DataSource = array; comboObjetivo.DisplayMember = "nome"; comboObjetivo.ValueMember = "id"; } catch { } #endregion #region Carrega os Grupos Musculares try { GrupoMuscular grupo = new GrupoMuscular(); ArrayList array = grupo.selectArray("order by nome"); comboGrupoMuscular.DataSource = array; comboGrupoMuscular.DisplayMember = "nome"; comboGrupoMuscular.ValueMember = "id"; } catch { } #endregion comboAluno.SelectedValue = idAluno; comboTreinador.SelectedValue = idTreinador; comboObjetivo.SelectedValue = idObjetivo; }
private void FrmTabTreinadores_Activated(object sender, EventArgs e) { Treinadores func = new Treinadores(); dataGridViewTreinadores.DataSource = func.select(); }
private void btSalvar_Click(object sender, EventArgs e) { #region Validação dos componentes do sistema //Verifica se o componente 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 componente 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 componente 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 componente esta vazio if (maskedTextCep.Text.Trim().Length < 9) { MessageBox.Show("Digite um CEP válido.", "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Information); maskedTextCep.Focus(); return; } //Verifica se o componente 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 componente esta vazio if (textBairro.Text.Trim().Equals("")) { MessageBox.Show("Digite um bairro válido.", "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Information); textBairro.Focus(); return; } //Verifica se o componente esta vazio if (textEmail.Text.Trim().Equals("")) { MessageBox.Show("Digite um email válido.", "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Information); textEmail.Focus(); return; } #region Verifica se o Email é valido 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; } 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 Verifica se o Email ja esta sendo utilizado //Verifica se o Email ja esta sendo utilizado Treinadores treinador = new Treinadores(); DataTable dt = new DataTable(); dt = treinador.selectVerificacaoEmail(" where email = '" + textEmail.Text + "'"); if (dt.Rows.Count == 1) { MessageBox.Show("Este email já esta sendo utilizado.", "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Information); textEmail.Focus(); textEmail.Clear(); return; } #endregion #endregion #region Salvar os dados Treinadores trein = new Treinadores(); trein.Nome = textNome.Text.Trim(); trein.Cpf = maskedTextCpf.Text; trein.DataNasc = dateNasc.Text; trein.Cep = maskedTextCep.Text; trein.Endereco = textEndereco.Text.Trim(); trein.Bairro = textBairro.Text.Trim(); trein.TelefoneRes = maskedTextTelefoneRes.Text; trein.TelefoneCel = maskedTextTelefoneCel.Text; trein.Email = textEmail.Text.Trim(); trein.Observacao = textObservacao.Text.Trim(); trein.insert(); #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 = 6; logs.Data = DateTime.Today.ToString("dd/MM/yyyy"); logs.Hora = DateTime.Now.ToString("HH:mm"); logs.insert(); #endregion #region Limpar os componentes da janela textNome.Clear(); maskedTextCpf.Clear(); this.dateNasc.Value = DateTime.Now.Date; maskedTextCep.Clear(); textEndereco.Clear(); textBairro.Clear(); maskedTextTelefoneRes.Clear(); maskedTextTelefoneCel.Clear(); textEmail.Clear(); textObservacao.Clear(); textNome.Focus(); #endregion this.Close(); }