private void btnAdicionar_Click(object sender, EventArgs e) { //conexao = new ClasseConexao(); //ds = new DataSet(); try { String ID_aluno = txtIDAluno.Text; String ID_ativ = txtIDAtiv.Text; int nota; bool parse = int.TryParse(txtNota.Text, out nota); bool n = Validar.nota(nota); var emptyTextboxes = from tb in this.Controls.OfType <TextBox>() where string.IsNullOrEmpty(tb.Text) select tb; var emptyMask = from mb in this.Controls.OfType <MaskedTextBox>() where string.IsNullOrEmpty(mb.Text) select mb; if (emptyTextboxes.Any() || emptyMask.Any() || txtNota.Text.Length > 4 || parse == false || n == false) { MessageBox.Show("Por favor tenha certeza de de todos os campos estejam preenchidos e de que a nota esteja no formato 00 (´mínimo 0, máximo 10"); } else { conexao = new ClasseConexao(); ds = new DataSet(); String check = String.Format("SELECT * FROM NOTA WHERE ID_ALUNO = '{0}' AND ID_ATIV = '{1}'", ID_aluno, ID_ativ); ds = conexao.executarSQL(check); int qnt = 0; qnt = ds.Tables[0].Rows.Count; if (qnt > 0) { MessageBox.Show("Esse registro já existe!"); } else { var confirm = MessageBox.Show("Tem certeza que deseja adicionar essa nota? Lembre-se de que ela não poderá ser alterada depois.", "Por favor confirmar", MessageBoxButtons.YesNo); if (confirm.Equals(DialogResult.Yes)) { conexao = new ClasseConexao(); ds = new DataSet(); String query = String.Format("INSERT INTO NOTA VALUES('{0}', '{1}', '{2}')", ID_ativ, ID_aluno, nota); //MessageBox.Show(query); ds = conexao.executarSQL(query); String att = String.Format("SELECT ALUNO.ID_ALUNO AS ID, ALUNO.NOME AS ALUNO, ATIVIDADE.NOME AS ATIVIDADE, NOTA.VALOR AS NOTA FROM ALUNO INNER JOIN NOTA ON ALUNO.ID_ALUNO = NOTA.ID_ALUNO INNER JOIN ATIVIDADE ON NOTA.ID_ATIV = ATIVIDADE.ID_ATIV WHERE ATIVIDADE.ID_PROFESSOR = '{0}'", comp.Id); Grid.atualizar_grid(att, pdr, dgvNotas); } else { // If 'No', do something here. } } } } catch (Exception erro) { } }
private void btnAlterar_Click(object sender, EventArgs e) { try { String ID = txtID.Text; String campo = cmbAltCampo.SelectedItem.ToString(); String valor = txtAlt.Text; String query = ""; query = String.Format("UPDATE FUNCIONARIO SET {0} = '{1}' WHERE ID_FUNCIONARIO = '{2}'", campo, valor, ID); var emptyTextboxes = from tb in this.Controls.OfType <TextBox>() where string.IsNullOrEmpty(tb.Text) select tb; if (emptyTextboxes.Any()) { MessageBox.Show("Por favor tenha certeza de que todos os campos estão preenchidos."); } else { conexao = new ClasseConexao(); ds = new DataSet(); string check = string.Format("SELECT * FROM FUNCIONARIO WHERE ID_FUNCIONARIO = '{0}'", ID); ds = conexao.executarSQL(check); int qnt = 0; qnt = ds.Tables[0].Rows.Count; if (qnt > 0) { var confirm = MessageBox.Show("Tem certeza que deseja alterar o registro?", "Por favor confirmar", MessageBoxButtons.YesNo); if (confirm.Equals(DialogResult.Yes)) { conexao = new ClasseConexao(); ds = new DataSet(); //MessageBox.Show(query); ds = conexao.executarSQL(query); } else { // If 'No', do something here. } } else { MessageBox.Show("Por favor escolha um registro válido"); } } } catch (Exception erro) { } }
public static Object atualizar_grid(String sql, String pdr, DataGridView dt) { ClasseConexao conexao = new ClasseConexao(); DataSet ds = new DataSet(); if (sql.Equals(null) || sql.Equals("")) { //placeholder sql = pdr; } ds = conexao.executarSQL(sql); dt.DataSource = ds.Tables[0]; formataGrid(dt); return(dt); }
private void button2_Click(object sender, EventArgs e) { conexao = new ClasseConexao(); ds = new DataSet(); try { String ID = txtID.Text; String query = String.Format("DELETE FROM ATIVIDADE WHERE ID_ATIV = '{0}'", ID); if (txtID.Text.Equals("") || txtID.Text.Equals(null)) { MessageBox.Show("Por favor digite um ID para continuar"); } else { string check = string.Format("SELECT * FROM ATIVIDADE WHERE ID_ATIV = '{0}'", ID); ds = conexao.executarSQL(check); int qnt = 0; qnt = ds.Tables[0].Rows.Count; if (qnt > 0) //se ja existe { var confirm = MessageBox.Show("Tem certeza que deseja excluir o registro?", "Por favor confirmar", MessageBoxButtons.YesNo); if (confirm.Equals(DialogResult.Yes)) { conexao = new ClasseConexao(); ds = new DataSet(); //MessageBox.Show(query); ds = conexao.executarSQL(query); Grid.atualizar_grid("", pdr, dgvAtiv); } else { // If 'No', do something here. } } else //se nao existe { MessageBox.Show("Esse registro não existe!"); } } } catch (Exception erro) { } }
private void button1_Click(object sender, EventArgs e) { String nome = txtNome.Text; String desc = txtDesc.Text; String id = comp.Id; var emptyTextboxes = from tb in this.Controls.OfType <TextBox>() where string.IsNullOrEmpty(tb.Text) select tb; if (emptyTextboxes.Any() || desc.Trim().Length > 100) { MessageBox.Show("Por favor preencha o nome e a descrição, e tenha certeza que a descrição tenha menos de 100 caracteres"); } else { conexao = new ClasseConexao(); ds = new DataSet(); string check = string.Format("SELECT * FROM ATIVIDADE WHERE NOME = '{0}'", nome); ds = conexao.executarSQL(check); int qnt = 0; qnt = ds.Tables[0].Rows.Count; if (qnt > 0) //se ja existe { MessageBox.Show("Essa atividade já existe nos registros"); } else { conexao = new ClasseConexao(); ds = new DataSet(); String query = String.Format("INSERT INTO ATIVIDADE VALUES ('{0}','{1}', '{2}')", nome, desc, id); ds = conexao.executarSQL(query); Grid.atualizar_grid("", pdr, dgvAtiv); } } }
private void button1_Click(object sender, EventArgs e) { conexao = new ClasseConexao(); ds = new DataSet(); try { //Variáveis referentes aos controles do formulario String nome = txtNome.Text; String email = txtEmail.Text; String sexo = cmbSexo.SelectedItem.ToString(); String senha = txtSenha.Text; String rua = txtRua.Text; int numero = int.Parse(txtNum.Text); String cep = txtCEP.Text; String cidade = txtCidade.Text; String estado = txtEstado.Text; String telefone = txtTelefone.Text; int curso; int periodo; //checa qual radio button está selecionado var rCurso = grbCurso.Controls.OfType <RadioButton>().Where(r => r.Checked).FirstOrDefault(); if (rCurso == null) { curso = 0; //MessageBox.Show("Por favor selecione um curso"); } else { curso = int.Parse(rCurso.Tag.ToString()); } var rPeriodo = grbPeriodo.Controls.OfType <RadioButton>().Where(r => r.Checked).FirstOrDefault(); if (rPeriodo == null) { periodo = 0; //MessageBox.Show("Por favor selecione um período"); } else { periodo = int.Parse(rPeriodo.Tag.ToString()); } //checa se os textbox, maskedtextbox estao vazios var emptyTextboxes = from tb in this.Controls.OfType <TextBox>() where string.IsNullOrEmpty(tb.Text) select tb; var emptyMask = from mb in this.Controls.OfType <MaskedTextBox>() where string.IsNullOrEmpty(mb.Text) select mb; if (emptyTextboxes.Any() || emptyMask.Any() || rCurso == null || rPeriodo == null) { MessageBox.Show("Por favor preencha todos os campos e selecione as opções apropriadas"); } else { //checa o nome para ver se já nao existe string check = string.Format("SELECT NOME FROM ALUNO WHERE NOME = '{0}'", nome); ds = conexao.executarSQL(check); int qnt = 0; qnt = ds.Tables[0].Rows.Count; if (qnt > 0) //se ja existe { MessageBox.Show("Esse aluno já existe nos registros"); } else //se nao existe { //MessageBox.Show(curso + "\n" + periodo); conexao = new ClasseConexao(); ds = new DataSet(); string sql = string.Format("INSERT INTO ALUNO VALUES ('{0}','{1}','{2}','{3}','{4}',{5},'{6}','{7}','{8}','{9}', {10}, {11})", nome, email, sexo, senha, rua, numero, cep, cidade, estado, telefone, curso, periodo); //MessageBox.Show(sql); ds = conexao.executarSQL(sql); } } } catch (Exception erro) { } }
private void btnCadastrar_Click(object sender, EventArgs e) { conexao = new ClasseConexao(); ds = new DataSet(); try { String nome = txtNome.Text; String sexo = cmbSexo.SelectedItem.ToString(); String rg = txtRG.Text; String cpf = txtCPF.Text; String rua = txtRua.Text; int numero = int.Parse(txtNum.Text); String bairro = txtBairro.Text; String cep = txtCEP.Text; String cidade = txtCidade.Text; String estado = txtEstado.Text; String fone = txtFone.Text; String cel = txtCel.Text; String email = txtEmail.Text; String senha = txtSenha.Text; bool Valido = Validar.Cpf(cpf); //checa se os textbox, maskedtextbox estao vazios var emptyTextboxes = from tb in this.Controls.OfType <TextBox>() where string.IsNullOrEmpty(tb.Text) select tb; var emptyMask = from mb in this.Controls.OfType <MaskedTextBox>() where string.IsNullOrEmpty(mb.Text) select mb; if (emptyTextboxes.Any() || emptyMask.Any() || Valido == false) { if (Valido == false) { MessageBox.Show("Por favor digite um CPF válido"); } else { MessageBox.Show("Por favor preencha todos os campos e selecione as opções apropriadas"); } } else { //checa o nome para ver se já nao existe string check = string.Format("SELECT NOME FROM PROFESSOR WHERE NOME = '{0}'", nome); ds = conexao.executarSQL(check); int qnt = 0; qnt = ds.Tables[0].Rows.Count; if (qnt > 0) //se ja existe { MessageBox.Show("Esse professor já existe nos registros"); } else //se nao existe { //MessageBox.Show(curso + "\n" + periodo); conexao = new ClasseConexao(); ds = new DataSet(); string sql = String.Format("INSERT INTO PROFESSOR VALUES ('{0}','{1}','{2}','{3}','{4}',{5},'{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}')", nome, sexo, rg, cpf, rua, numero, bairro, cep, cidade, estado, fone, cel, email, senha); //MessageBox.Show(sql); ds = conexao.executarSQL(sql); } } } catch (Exception erro) { } }
//botao login private void btnLogin_Click(object sender, EventArgs e) { ////validacao de usuario e senha //if (txtUser.Text.Equals("1") && txtPass.Text.Equals("1")) //{ // this.Hide(); //FrmPrincipal frmPrincipal = new FrmPrincipal(); //frmPrincipal.Show(); //} //else //{ // MessageBox.Show("Usuário ou senha incorretos"); //} string email = txtUser.Text; string senha = txtPass.Text; conexao = new ClasseConexao(); ds = new DataSet(); Compartilha comp = new Compartilha(); //get & set nivel/id string sql = String.Format("SELECT * FROM FUNCIONARIO WHERE EMAIL = '{0}' AND SENHA = '{1}'", email, senha); ds = conexao.executarSQL(sql); int conta = ds.Tables[0].Rows.Count; if (conta > 0) { comp.Nivel = ds.Tables[0].Rows[0]["CARGO"].ToString(); comp.Id = ds.Tables[0].Rows[0]["ID_FUNCIONARIO"].ToString(); comp.Nome = ds.Tables[0].Rows[0]["NOME"].ToString(); this.Hide(); FrmPrincipal frmPrincipal = new FrmPrincipal(); frmPrincipal.Show(); } else { conexao = new ClasseConexao(); ds = new DataSet(); conta = 0; sql = String.Format("SELECT * FROM PROFESSOR WHERE EMAIL = '{0}' AND SENHA = '{1}'", email, senha); ds = conexao.executarSQL(sql); conta = ds.Tables[0].Rows.Count; if (conta > 0) { comp.Nivel = "professor"; comp.Id = ds.Tables[0].Rows[0]["ID_PROFESSOR"].ToString(); comp.Nome = ds.Tables[0].Rows[0]["NOME"].ToString(); this.Hide(); FrmPrincipal frmPrincipal = new FrmPrincipal(); frmPrincipal.Show(); } else { MessageBox.Show("Usuário ou senha incorretos."); } } }
private void btnAlterar_Click(object sender, EventArgs e) { try { String ID = txtID.Text; String campo = cmbAltCampo.SelectedItem.ToString(); String valor = txtAlt.Text; String query = ""; bool IsValido; if (campo.Equals("CURSO")) { if (valor.ToUpper().Equals("BASICO")) { valor = "1"; IsValido = true; } else if (valor.ToUpper().Equals("INTERMEDIARIO")) { valor = "2"; IsValido = true; } else if (valor.ToUpper().Equals("AVANCADO")) { valor = "3"; IsValido = true; } else if (valor.ToUpper().Equals("EXPRESSO")) { valor = "4"; IsValido = true; } else { IsValido = false; } query = String.Format("UPDATE ALUNO SET ID_CURSO = '{0}' WHERE ID_ALUNO = '{1}'", valor, ID); } else if (campo.Equals("PERIODO")) { if (valor.ToUpper().Equals("MANHA")) { valor = "1"; IsValido = true; } else if (valor.ToUpper().Equals("TARDE")) { valor = "2"; IsValido = true; } else if (valor.ToUpper().Equals("NOITE")) { valor = "3"; IsValido = true; } else { IsValido = false; } query = String.Format("UPDATE ALUNO SET ID_PERIODO = '{0}' WHERE ID_ALUNO = '{1}'", valor, ID); } else { query = String.Format("UPDATE ALUNO SET {0} = '{1}' WHERE ID_ALUNO = '{2}'", campo, valor, ID); IsValido = true; } var emptyTextboxes = from tb in this.Controls.OfType <TextBox>() where string.IsNullOrEmpty(tb.Text) select tb; if (IsValido == false || emptyTextboxes.Any()) { MessageBox.Show("Por favor digite o nome do curso e do período sem acentos, e tenha certeza de que todos os campos estão preenchidos."); } else { conexao = new ClasseConexao(); ds = new DataSet(); string check = string.Format("SELECT * FROM ALUNO WHERE ID_ALUNO = '{0}'", ID); ds = conexao.executarSQL(check); int qnt = 0; qnt = ds.Tables[0].Rows.Count; if (qnt > 0) { var confirm = MessageBox.Show("Tem certeza que deseja alterar o registro?", "Por favor confirmar", MessageBoxButtons.YesNo); if (confirm.Equals(DialogResult.Yes)) { conexao = new ClasseConexao(); ds = new DataSet(); //MessageBox.Show(query); ds = conexao.executarSQL(query); } else { // If 'No', do something here. } } } } catch (Exception erro) { } }