public void AtualizarAlunoDB(Alunos aluno) { try { IDbCommand updateCmd = conexao.CreateCommand(); updateCmd.CommandText = "update Alunos set nome = @nome, sobrenome = @sobrenome, telefone = @telefone, ra = @ra where id = @id"; IDbDataParameter paramNome = new SqlParameter("nome", aluno.nome); IDbDataParameter paramSobrenome = new SqlParameter("sobrenome", aluno.sobrenome); IDbDataParameter paramTelefone = new SqlParameter("telefone", aluno.telefone); IDbDataParameter paramRa = new SqlParameter("ra", aluno.ra); updateCmd.Parameters.Add(paramNome); updateCmd.Parameters.Add(paramSobrenome); updateCmd.Parameters.Add(paramTelefone); updateCmd.Parameters.Add(paramRa); IDbDataParameter paramID = new SqlParameter("id", aluno.id); updateCmd.Parameters.Add(paramID); updateCmd.ExecuteNonQuery(); } catch (Exception ex) { throw new Exception(ex.Message); } finally { conexao.Close(); } }
public void Excluir(Alunos Entidade) { var AlunoExcluir = BancoDeDados.Alunos.First(x => x.Id == Entidade.Id); BancoDeDados.Set <Alunos>().Remove(AlunoExcluir); BancoDeDados.SaveChanges(); }
static void Main(string[] args) { string[,] arrayAlunos = new string[1, 6]; int idAluno = 0; var opcaoMenu = ShowMenu(); var classAlunos = new Alunos(); while (true) { switch (opcaoMenu) { case "1": { classAlunos.AdicionarAlunos(ref arrayAlunos, ref idAluno); } break; case "2": { classAlunos.ListaALunos(arrayAlunos); } break; case "3": { classAlunos.AlterarAlunos(arrayAlunos); } break; case "4": { classAlunos.ExcluirAlunos(arrayAlunos); } break; case "5": { Environment.Exit(0); } break; default: { Console.WriteLine("Opção inválida."); } break; } opcaoMenu = ShowMenu(); } }
public JsonResult Pesquisa_expecifica(string txt_pesquisa) { var lista = db.Alunos.Where(x => x.Nome.Contains(txt_pesquisa)); StringBuilder str = new StringBuilder(); IList <Alunos> Lista_Alunos = new List <Alunos>(); str.Append("<table width=\"100%\" border=\"1\">"); str.Append("<tr><th>Id</th><th>Nome</th><th>Sexo</th><th>Editar</th></tr>"); foreach (var item in lista) { if (item.Ativo != false) { Alunos a = new Alunos(); a.Nome = item.Nome; a.Sexo = item.Sexo; Lista_Alunos.Add(a); str.Append("<tr><td>" + item.Id_Aluno + "</td><td>" + item.Nome + "</td><td>" + item.Sexo + "</td><td> @Html.ActionLink(\"Editar\", \"Editar\", new { id = " + item.Id_Aluno + " }) </ td ></tr>"); } } return(Json(new { tbl_alunos = str.ToString() }, JsonRequestBehavior.AllowGet)); }
public static void Main (string[] args) { Aluno[] alunos = new Alunos[15]; for (int x=0;x<=15;x++){ Console.WriteLine("\nNome do Aluno[0]º: ",x+1); alunos[x].nome = Console.ReadLine(); Console.WriteLine("\nNota 1 do Aluno[0]º ",x+1); alunos[x].nota1 = Console.ReadLine(); Console.WriteLine("\nNota 2 do Aluno[0]º ",x+1); alunos[x].nota2 = Console.ReadLine(); alunos[x].media = ((alunos[x].nota1 + alunos[x].nota2) / 2); Console.Clear(); } for (int x=0;x<=15;x++){ if (alunos[x].media>=7){ Console.ForegroundColor = ConsoleColor.Blue; Console.WriteLine("Aluno {0},teve as notas {1} e notas {2}, obtendo a média de {3}.\n O aluno(a) foi aprovado!",alunos[x].nome,alunos[x].nota1,alunos[x].nota2,alunos[x].media); }else{ Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Aluno {0},teve as notas {1} e notas {2}, obtendo a média de {3}.\n O aluno(a) foi reprovado!",alunos[x].nome,alunos[x].nota1,alunos[x].nota2,alunos[x].media); } } }
private void btnCadastrar_Click(object sender, EventArgs e) { Alunos aluno = new Alunos(); aluno.Nome = txtNome.Text; aluno.Matricula = txtNumeroDaMatricula.Text; aluno.Nota_01 = Convert.ToDouble(txtNota1.Text); aluno.Nota_02 = Convert.ToDouble(txtNota2.Text); aluno.Nota_03 = Convert.ToDouble(txtNota3.Text); aluno.Frequencia = Convert.ToInt32(txtFrequencia.Text); if (string.IsNullOrEmpty(txtCodigo.Text)) { int id = new AlunosRepositorio().Inserir(aluno); txtCodigo.Text = Convert.ToString(id); MessageBox.Show("O aluno " + aluno.Nome + " foi cadastrado com sucesso"); } else { int id = Convert.ToInt32(txtCodigo.Text); aluno.Id = id; bool alterou = new AlunosRepositorio().Alterar(aluno); if (alterou) { MessageBox.Show("Registro alterado com sucesso"); } else { MessageBox.Show("Não foi possível alterar"); } } }
// PUT: api/Aluno/5 public List <Alunos> Put(int id, Alunos aluno) { Alunos _aluno = new Alunos(); _aluno.Atualizar(id, aluno); return(_aluno.ListaAlunos()); }
public async Task <ActionResult <Alunos> > PostAlunos(Alunos alunos) { _context.Alunos.Add(alunos); await _context.SaveChangesAsync(); return(CreatedAtAction("GetAlunos", new { id = alunos.Id }, alunos)); }
public List <Alunos> ObeterTodos() { List <Alunos> alunos = new List <Alunos>(); SqlCommand command = new BancoDados().ObterConexao(); command.CommandText = "SELECT id, nome, codigo_matricula, nota_1, nota_2, nota_3, frequencia, situacao FROM alunos"; DataTable table = new DataTable(); table.Load(command.ExecuteReader()); foreach (DataRow linha in table.Rows) { Alunos aluno = new Alunos() { Id = Convert.ToInt32(linha[0].ToString()), Nome = linha[1].ToString(), CodigoMatricula = linha[2].ToString(), Nota_1 = Convert.ToDouble(linha[3].ToString()), Nota_2 = Convert.ToDouble(linha[4].ToString()), Nota_3 = Convert.ToDouble(linha[5].ToString()), Frequencia = Convert.ToInt32(linha[6].ToString()), Situacao = linha[7].ToString() }; alunos.Add(aluno); } return(alunos); }
// GET: Alunos public ActionResult Index() { var tipo = Convert.ToString(Session["Tipo"]); var user = Convert.ToString(Session["EmailUsuario"]); var inst = Convert.ToString(Session["FaculdadeId"]); var Nomeinst = Convert.ToString(Session["EmailFaculdade"]); Alunos alunosPortal = db.Alunos.FirstOrDefault(a => a.NomeCompleto == User.Identity.Name); if (tipo == "Master") { return(View(db.Alunos.Where(m => m.EmailFaculdade == Nomeinst).ToList())); } if (tipo == "Aluno") { return(View(db.Alunos.Where(a => a.EmailUsuario == user).ToList())); } if (tipo == "Professor") { return(View()); } else { return(View()); } }
public async Task <IActionResult> PutAlunos(long id, Alunos alunos) { if (id != alunos.Id) { return(BadRequest()); } _context.Entry(alunos).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!AlunosExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> Edit(int id, [Bind("AlunosId,Nome")] Alunos alunos) { if (id != alunos.AlunosId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(alunos); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!AlunosExists(alunos.AlunosId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(alunos)); }
public void AdicionarAluno(long codigoAluno) { var ocorrenciaAluno = new OcorrenciaAluno(codigoAluno, this); Alunos = Alunos ?? new List <OcorrenciaAluno>(); Alunos.Add(ocorrenciaAluno); }
public void InserirAlunoDB(Alunos aluno) { try { IDbCommand insertCmd = conexao.CreateCommand(); insertCmd.CommandText = "insert into Alunos (nome, sobrenome, telefone, ra) values (@nome, @sobrenome, @telefone, @ra)"; IDbDataParameter paramNome = new SqlParameter("nome", aluno.nome); insertCmd.Parameters.Add(paramNome); IDbDataParameter paramSobrenome = new SqlParameter("sobrenome", aluno.sobrenome); insertCmd.Parameters.Add(paramSobrenome); IDbDataParameter paramTelefone = new SqlParameter("telefone", aluno.telefone); insertCmd.Parameters.Add(paramTelefone); IDbDataParameter paramRa = new SqlParameter("ra", aluno.ra); insertCmd.Parameters.Add(paramRa); insertCmd.ExecuteNonQuery(); } catch (Exception ex) { throw new Exception(ex.Message); } finally { conexao.Close(); } }
public JsonResult Salvar(Pessoas pessoa, string tipo, Professores professor) { //A variável p traz do banco de dados na tabela Pessoas o primeiro registro que tem o cpf igual ao cpf digitado pelo usuário. // a.cpf = da tabela do banco da dados. // pessoa.cpf = o que o usuário digitou. var p = dbContext.Pessoas.FirstOrDefault(a => a.Cpf == pessoa.Cpf); // Se o cpf (variável p) for diferente de nulo, ou seja já consta na tabela. Então retorna "CPF já cadastrado." if (p != null) { return(Json("CPF já cadastrado.")); } //Se o cpf for nulo, não consta na tabela, a pessoa pode se cadastrar. dbContext.Pessoas.Add(pessoa); dbContext.SaveChanges(); p = dbContext.Pessoas.FirstOrDefault(a => a.Cpf == pessoa.Cpf); if (tipo == "Aluno") { Alunos aluno = new Alunos(); aluno.PessoaId = p.Id; dbContext.Alunos.Add(aluno); dbContext.SaveChanges(); } else if (tipo == "Professor") { professor.PessoaId = p.Id; dbContext.Professores.Add(professor); dbContext.SaveChanges(); } return(Json("Salvo com Sucesso!")); }
private void Pesquisar() { Alunos alu = new Alunos(tbNome.Text); gvAlunos.DataSource = alu.PesqAlunos(); gvAlunos.DataBind(); }
public async Task HandleFile(IFileListEntry[] files) { Alunos.Clear(); if (files.Length != 0) { file = files.FirstOrDefault(); var dados = new StreamReader(file.Data); if (file != null) { while (true) { var info = await dados.ReadLineAsync(); if (info == null) { break; } var aluno = info.Split(';'); if (aluno[0] != "Id") { Alunos.Add(new Aluno { Matricula = Convert.ToInt32(aluno[0]), Nome = aluno[1], CursoId = Convert.ToInt32(aluno[2]) }); } } } } }
protected void RemoveExistingAlunos() { foreach (var aluno in turma.alunos) { Alunos.Remove(Alunos.Where(x => x.Matricula == aluno.Matricula).FirstOrDefault()); } }
public List <Alunos> ObterTodos() { List <Alunos> alunos = new List <Alunos>(); SqlCommand comando = new BancoDados().ObterConexao(); comando.CommandText = "SELECT id,nome,codigo_matricula,nota_01,nota_02,nota_03,frequencia, faltas FROM aluno"; DataTable tabela = new DataTable(); tabela.Load(comando.ExecuteReader()); foreach (DataRow linha in tabela.Rows) { Alunos aluno = new Alunos() { Id = Convert.ToInt32(linha[0].ToString()), Nome = linha[1].ToString(), Matricula = linha[2].ToString(), Nota1 = Convert.ToDouble(linha[3].ToString()), Nota2 = Convert.ToDouble(linha[4].ToString()), Nota3 = Convert.ToDouble(linha[5].ToString()), frequencia = Convert.ToInt32(linha[6].ToString()), Faltas = Convert.ToInt16(linha[7].ToString()) }; alunos.Add(aluno); } return(alunos); }
private void MapearModalidades(AlunosFormViewModel obj, Alunos aluno) { if (!obj.PostModalidades.Any()) { return; } var excluir = aluno.Modalidades.Where(m => !obj.PostModalidades.Any(p => p == m.ModalidadeID)).ToList(); var adicionar = obj.PostModalidades.Where(p => !aluno.Modalidades.Any(a => a.ModalidadeID == p)); if (excluir.Any()) { foreach (var modalidade in excluir) { aluno.removeModalidade(modalidade.Modalidade); } } if (!adicionar.Any()) { return; } foreach (var id in adicionar) { var modalidade = _context.Modalidades.Find(id); if (modalidade == null) { continue; } aluno.AddModalidade(modalidade); } }
public JsonResult Lista_Tudo() { var lista = db.Alunos.ToList().OrderBy(x => x.Nome); StringBuilder str = new StringBuilder(); IList <Alunos> Lista_Alunos = new List <Alunos>(); str.Append("<table width=\"100%\" border=\"1\">"); str.Append("<tr><th>Id</th><th>Nome</th><th>Sexo</th><th>Editar</th></tr>"); foreach (var item in lista) { if (item.Ativo != false) { Alunos a = new Alunos(); a.Nome = item.Nome; a.Sexo = item.Sexo; Lista_Alunos.Add(a); str.Append("<tr><td>" + item.Id_Aluno + "</td><td>" + item.Nome + "</td><td>" + item.Sexo + "</td><td> <a href=/Alunos/Editar?Id_Aluno=" + item.Id_Aluno + ">Editar</a> </td></tr>"); } } return(Json(new { tbl_alunos = str.ToString(), Lista_Alunos }, JsonRequestBehavior.AllowGet)); }
protected void Page_Load(object sender, EventArgs e) { Alunos a = new Alunos(); gvCidades.DataSource = a.RecuperarCidades(); gvCidades.DataBind(); }
static void Main(string[] args) { var alunos = new Alunos(); //Gera um objeto aluno para pegar a base de dados contida nele var bdd = alunos.CarregaBaseDeDados(); //Pega a base de dados contida na classe alunos var tela = new GerarInterface(); //Gera um objeto de interface gráfica var opcao = tela.GerarMenuInicial(); //Gera o primeiro menu para escolha de submenus //Looping infinito para repetir o menu while (true) { switch (opcao) { case 1: tela.GerarMenuListagemRegistros(bdd); break; //Submenu para listagem de registros case 2: tela.GerarMenuInserirRegistros(bdd); break; //Submenu para inserir novos registros case 3: tela.GerarMenuRemoveRegistros(bdd); break; //Submenu para remover registros case 4: tela.GerarMenuAlteraRegistros(bdd); break; //Submenu para alterar as notas de um registro case 5: return; //Quebra o looping e fecha o console } opcao = tela.GerarMenuInicial(); //Chama recursivamente o menu inicial } }
static void MenuExibir(Alunos al) { al.ListarAlunos(); Console.WriteLine("--------------------------------------------"); Console.WriteLine("\nPressione ENTER para voltar ao menu principal"); Console.ReadLine(); }
private string TurmaAlunos() { string retorno = "Alunos na Sala"; Alunos.ForEach(c => retorno += $"\n Nome:{c.Nome} RA:{c.NumeroMatricula}"); return(retorno); }
public Alunos ObterPeloCodigo(int codigo) { connection.Open(); SqlCommand comando = new SqlCommand(); comando.Connection = connection; comando.CommandText = @"SELECT id, nome, matricula, nota01, nota02, nota03, frequencia FROM alunos WHERE id = @ID"; comando.Parameters.AddWithValue("@ID", codigo); DataTable tabelaEmMemoria = new DataTable(); tabelaEmMemoria.Load(comando.ExecuteReader()); if (tabelaEmMemoria.Rows.Count == 0) { return(null); } Alunos aluno = new Alunos(); aluno.Id = Convert.ToInt32(tabelaEmMemoria.Rows[0][0]); aluno.Nome = tabelaEmMemoria.Rows[0][1].ToString(); aluno.Matricula = tabelaEmMemoria.Rows[0][2].ToString(); aluno.Nota01 = Convert.ToDouble(tabelaEmMemoria.Rows[0][3].ToString()); aluno.Nota02 = Convert.ToDouble(tabelaEmMemoria.Rows[0][4].ToString()); aluno.Nota03 = Convert.ToDouble(tabelaEmMemoria.Rows[0][5].ToString()); connection.Close(); return(aluno); }
private void AplicarFiltro() { if (pesquisaPorNome == null) { pesquisaPorNome = ""; } var resultado = CopiaListaAlunos.Where(n => n.Nome.ToLowerInvariant() .Contains(PesquisaPorNome.ToLowerInvariant().Trim())).ToList(); var removerDaLista = Alunos.Except(resultado).ToList(); foreach (var item in removerDaLista) { Alunos.Remove(item); } for (int index = 0; index < resultado.Count; index++) { var item = resultado[index]; if (index + 1 > Alunos.Count || !Alunos[index].Equals(item)) { Alunos.Insert(index, item); } } }
public bool Alterar(Alunos alunos) { connection.Open(); SqlCommand comando = new SqlCommand(); comando.Connection = connection; comando.CommandText = @"UPDATE alunos SET nome = @NOME, matricula = @MATRICULA, nota01 = @NOTA01, nota01 = @NOTA02, nota01 = @NOTA03, frequencia = @FREQUENCIA WHERE id = @ID"; comando.Parameters.AddWithValue("@NOME", alunos.Nome); comando.Parameters.AddWithValue("@MATRICULA", alunos.Matricula); comando.Parameters.AddWithValue("@NOTA01", alunos.Nota01); comando.Parameters.AddWithValue("@NOTA02", alunos.Nota02); comando.Parameters.AddWithValue("@NOTA03", alunos.Nota03); comando.Parameters.AddWithValue("@FREQUENCIA", alunos.Frequencia); int quantidadeAlterada = comando.ExecuteNonQuery(); connection.Close(); return(quantidadeAlterada == 1); }
// POST: api/Aluno public List <Alunos> Post(Alunos aluno) { Alunos _aluno = new Alunos(); _aluno.Inserir(aluno); return(_aluno.ListarAluno()); }
public async Task <IActionResult> Edit(int id, [Bind("Id,Nome,Email,DataNascimento,DataCadastro,Matricula,Ativo")] Alunos alunos) { if (id != alunos.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(alunos); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!AlunosExists(alunos.Id)) { return(NotFound()); } else { throw; } } TempData["UltimoAluno"] = $"{alunos.Id}- {alunos.Nome}"; ViewData["UltimoAluno"] = $"{alunos.Id}- {alunos.Nome}"; return(RedirectToAction(nameof(Index))); } return(View(alunos)); }