public void Cadastrar(BLL.Aluno alu) { SqlCommand cmd = new SqlCommand(); cmd.Connection = con.Conectar(); cmd.CommandText = @"INSERT INTO Aluno(Nome,Email,Cpf,Rg,Nascimento,Telefone,Rua_Av,Numero,Bairro,Cidade,Estado,Cep,Id_Login) VALUES(@nome,@email,@cpf,@rg,@nascimento,@telefone,@ruaav,@numero,@bairro,@cidade,@estado,@cep,@idlogin)"; cmd.Parameters.Add("@nome", SqlDbType.VarChar).Value = alu.Nome; cmd.Parameters.Add("@email", SqlDbType.VarChar).Value = alu.Email; cmd.Parameters.Add("@cpf", SqlDbType.Char).Value = alu.Cpf; cmd.Parameters.Add("@rg", SqlDbType.VarChar).Value = alu.Rg; cmd.Parameters.Add("@nascimento", SqlDbType.DateTime).Value = alu.Nascimento; cmd.Parameters.Add("@telefone", SqlDbType.VarChar).Value = alu.Telefone; cmd.Parameters.Add("@ruaav", SqlDbType.VarChar).Value = alu.RuaAv; cmd.Parameters.Add("@numero", SqlDbType.VarChar).Value = alu.Numero; cmd.Parameters.Add("@bairro", SqlDbType.VarChar).Value = alu.Bairro; cmd.Parameters.Add("@cidade", SqlDbType.VarChar).Value = alu.Cidade; cmd.Parameters.Add("@estado", SqlDbType.Char).Value = alu.Estado; cmd.Parameters.Add("@cep", SqlDbType.Char).Value = alu.Cep; cmd.Parameters.Add("@idlogin", SqlDbType.Int).Value = alu.IdLogin; cmd.ExecuteNonQuery(); con.Desconectar(); }
public BLL.Aluno PreecheAluno(BLL.Aluno a) { SqlCommand cmd = new SqlCommand(); cmd.Connection = con.Conectar(); cmd.CommandText = @"SELECT RA, Nome, CPF, Idade FROM TB_ALUNO WHERE RA = @ra"; cmd.Parameters.AddWithValue("@ra", a.Ra); SqlDataReader dr = cmd.ExecuteReader(); if (dr.HasRows) { dr.Read(); a.Ra = dr["RA"].ToString(); a.Cpf = dr["NOME"].ToString(); a.Nome = dr["CPF"].ToString(); a.Idade = Convert.ToInt16(dr["IDADE"]); dr.Close(); con.Desconectar(); } else { a.Ra = "Inválido"; } return(a); }
public BLL.Aluno Selecionar(BLL.Aluno a) { SqlCommand cmd = new SqlCommand(); cmd.Connection = con.Conectar(); cmd.CommandText = @"SELECT RA, Nome, CPF FROM Aluno WHERE RA = @ra"; cmd.Parameters.AddWithValue("@ra", a.Ra); SqlDataReader dr = cmd.ExecuteReader(); if (dr.HasRows) { dr.Read(); a.Ra = Convert.ToInt32(dr["RA"]); a.Nome = dr["Nome"].ToString(); a.Cpf = dr["CPF"].ToString(); dr.Close(); } else { a.Ra = 0; } con.Desconectar(); return(a); }
protected void btnFiltrar_Click(object sender, EventArgs e) { lo.Usuario = txtFiltro.Text; lo.Tipo = 1; lo = loDAL.PreencherPeloID1(lo); lblId.Text = lo.IdLogin.ToString(); lblUsuario.Text = lo.Usuario; alu.IdLogin = lo.IdLogin; alu = aluDAL.PreencherPeloID(alu); lblCpf.Text = alu.Cpf; lblUsuario.Visible = true; lblCpf.Visible = true; txtSenha.Visible = true; Label1.Visible = true; Label2.Visible = true; Label3.Visible = true; btnRecuperar.Visible = true; txtFiltro.Visible = false; btnFiltrar.Visible = false; btnCancelar.Visible = true; }
//Sobrecarga do metodo consultar (Filtro). public DataTable Consultar(BLL.Aluno a) { //Tabela de dados no padrão C# (String, double, float, int...). DataTable dt = new DataTable(); SqlCommand cmd = new SqlCommand(); cmd.Connection = con.Conectar(); cmd.CommandText = @"SELECT RA, Nome, CPF, Idade FROM TB_ALUNO WHERE Nome like @nome"; cmd.Parameters.AddWithValue("@nome", "%" + a.Nome + "%"); //Adaptador de dados padrão SQL para C# SqlDataAdapter da = new SqlDataAdapter(); //Configurar qual comando de consulta da.SelectCommand = cmd; //Preencher o DataTable com o resultado adaptado da consulta da.Fill(dt); con.Desconectar(); return(dt); }
//Excluir Aluno public void Excluir(BLL.Aluno alu) { SqlCommand cmd = new SqlCommand(@"DELETE FROM Aluno WHERE CodAluno = @CodAluno"); cmd.Connection = conexao.Conectar(); cmd.Parameters.AddWithValue("@CodAluno", alu.CodAluno); cmd.ExecuteNonQuery(); conexao.Desconectar(); }
/*protected void btnLogin_Click(object sender, EventArgs e) * { * Response.Redirect("Login.aspx"); * }*/ protected void btnCadastrar_Click(object sender, EventArgs e) { BLL.Aluno alu = new BLL.Aluno(); lo.Usuario = txtUsuario.Text; lo.Senha = BLL.Criptografia.getMdIHash(txtSenha.Text); lo.Tipo = 1; alu.Nome = txtNome.Text; alu.Cpf = txtCpf.Text; alu.Rg = txtRg.Text; alu.Nascimento = DateTime.Parse(txtNasc.Text); alu.Cep = txtCep.Text; alu.Estado = DropDownList.SelectedValue; alu.Bairro = txtBairro.Text; alu.Cidade = txtCidade.Text; alu.RuaAv = txtRuaAv.Text; alu.Numero = txtNum.Text; alu.Email = txtEmail.Text; alu.Telefone = txtTelefone.Text; if (CheckBox1.Checked == true) { alu.IdLogin = loDAL.Cadastrar(lo); DAL.AlunoDAL aluDAL = new DAL.AlunoDAL(); aluDAL.Cadastrar(alu); txtUsuario.Text = ""; txtNome.Text = ""; txtCpf.Text = ""; txtSenha.Text = ""; txtRg.Text = ""; txtNasc.Text = ""; txtCep.Text = ""; DropDownList.SelectedIndex = 1; txtBairro.Text = ""; txtCidade.Text = ""; txtRuaAv.Text = ""; txtNum.Text = ""; txtEmail.Text = ""; txtTelefone.Text = ""; txtNome.Focus(); Response.Write("<script>alert('Cadastro efetuado!')</script>"); } else { litAviso.Text = "Você deve concordar com termos para continuar!"; } //btnLogin_Click(null, null); }
//Consultar por Nome public DataTable ConsultarPorNome(BLL.Aluno alu) { SqlDataAdapter da = new SqlDataAdapter(@"SELECT CodAluno 'Código', Nome, Cpf CPF, Rg RG, Email 'E-mail', DataNascimento 'Data de Nascimento' FROM Aluno WHERE Nome LIKE @Nome ORDER BY Nome", conexao.Conectar()); da.SelectCommand.Parameters.AddWithValue("@Nome", alu.Nome + "%"); DataTable dt = new DataTable(); da.Fill(dt); conexao.Desconectar(); return(dt); }
public void Excluir(BLL.Aluno a) { SqlCommand cmd = new SqlCommand(); cmd.Connection = con.Conectar(); cmd.CommandText = @"DELETE FROM Aluno WHERE RA = @ra"; cmd.Parameters.AddWithValue("@ra", a.Ra); cmd.ExecuteNonQuery(); con.Desconectar(); }
public DataTable ConsultarporNome(BLL.Aluno alu) { SqlDataAdapter da = new SqlDataAdapter(@" SELECT m.CodMatricula AS 'Código da Matricula', p.NomePlano AS 'Plano', a.Nome AS 'Aluno', DataMatricula AS 'Data de Matricula', DataVencimento AS 'Data de Vencimento' FROM Matricula m JOIN Plano p ON m.CodPlano = p.CodPlano JOIN Aluno a ON a.CodAluno = m.CodAluno WHERE a.Nome LIKE @NOME ORDER BY a.Nome", con.Conectar());//passando comando sql da.SelectCommand.Parameters.AddWithValue("@NOME", alu.Nome + "%"); DataTable dt = new DataTable(); //criando o Datatable da.Fill(dt); //preenchendo o datatable con.Desconectar(); //fecha conexao return(dt); //retorna o datatable preenchido com dados }
//Atualizar Aluno public void Atualizar(BLL.Aluno alu) { SqlCommand cmd = new SqlCommand(@"UPDATE ALUNO SET Nome = @Nome, Cpf = @Cpf, Rg = @Rg, Email = @Email, DataNascimento = @DataNascimento"); cmd.Connection = conexao.Conectar(); cmd.Parameters.AddWithValue("@Nome", alu.Nome); cmd.Parameters.AddWithValue("@Cpf", alu.Cpf); cmd.Parameters.AddWithValue("@Rg", alu.Rg); cmd.Parameters.AddWithValue("@Email", alu.Email); cmd.Parameters.AddWithValue("@DataNascimento", alu.DataNascimento); cmd.ExecuteNonQuery(); conexao.Desconectar(); }
//Cadastrar Aluno public void Cadastrar(BLL.Aluno alu) { SqlCommand cmd = new SqlCommand(@"INSERT INTO Aluno (Nome, Cpf, Rg, Email, DataNascimento) VALUES (@Nome, @Cpf, @Rg, @Email, @DataNascimento)"); cmd.Connection = conexao.Conectar();//abrindo conexão //referindo os parametros da consulta cmd.Parameters.AddWithValue("@Nome", alu.Nome); cmd.Parameters.AddWithValue("@Cpf", alu.Cpf); cmd.Parameters.AddWithValue("@Rg", alu.Rg); cmd.Parameters.AddWithValue("@Email", alu.Email); cmd.Parameters.AddWithValue("@DataNascimento", alu.DataNascimento); cmd.ExecuteNonQuery(); conexao.Desconectar(); }
protected void btnCadastrar_Click(object sender, EventArgs e) { Model.Aluno objAluno = new Model.Aluno(); objAluno.Email = txtEmail.Text; objAluno.Nome = txtNome.Text; objAluno.Senha = txtSenha.Text; try { BLL.Aluno bllAluno = new BLL.Aluno(); bllAluno.CadastrarAluno(objAluno); } catch (Exception ex) { throw new Exception(ex.Message); } }
public void Cadastrar(BLL.Aluno a) { SqlCommand cmd = new SqlCommand(); cmd.Connection = con.Conectar(); cmd.CommandText = @"INSERT INTO Aluno( Nome, CPF) VALUES(@nome,@cpf)"; cmd.Parameters.AddWithValue("@nome", a.Nome); cmd.Parameters.AddWithValue("@cpf", a.Cpf); cmd.ExecuteNonQuery(); con.Desconectar(); }
private void dgvResultado_CellDoubleClick(object sender, DataGridViewCellEventArgs e) { atualizar = true; txtRa.ReadOnly = true; btnCancelar.Visible = true; btnCadastrar.Text = "atualizar"; aluno.Ra = dgvResultado.SelectedRows[0].Cells["RA"].Value.ToString(); aluno = alunoDAL.PreecheAluno(aluno); txtRa.Text = aluno.Ra; txtNome.Text = aluno.Nome; txtIdade.Text = aluno.Idade.ToString(); txtCpf.Text = aluno.Cpf; tabControl1.SelectTab(0); //Seleciona a aba Cadastrar }
public void Atualizar(BLL.Aluno a) { SqlCommand cmd = new SqlCommand(); cmd.Connection = con.Conectar(); cmd.CommandText = @"UPDATE Aluno SET Nome = @nome, CPF = @cpf WHERE RA = @ra"; cmd.Parameters.AddWithValue("@nome", a.Nome); cmd.Parameters.AddWithValue("@cpf", a.Cpf); cmd.Parameters.AddWithValue("@ra", a.Ra); cmd.ExecuteNonQuery(); con.Desconectar(); }
public DataTable Listar(BLL.Aluno alu) //ESSA LINHA É A ASSINATURA { DataTable dt = new DataTable(); //Tabela de dados padrão C#(int, strin, double...) SqlCommand cmd = new SqlCommand(); cmd.Connection = con.Conectar(); cmd.CommandText = @"SELECT Id_Aluno, Nome, Email, Cpf, Rg, Nascimento, Telefone, Rua_Av, Numero, Bairro, Cidade, Estado, Cep, Id_Login FROM Aluno WHERE Id_Login LIKE @idlogin"; cmd.Parameters.AddWithValue("@idlogin", alu.IdLogin); // ESSE É USADO NO FILTRAR DE PROFESSOR ESPECIFICO //Adaptador de dados SQL para C# SqlDataAdapter da = new SqlDataAdapter(); da.SelectCommand = cmd; da.Fill(dt);//Preenche fazendo a adaptação con.Desconectar(); return(dt); }
protected void btnCadastrar_Click(object sender, EventArgs e) { try { BLL.Aluno aluno = new BLL.Aluno(); aluno.Nome = txtNome.Text; aluno.Cpf = txtCpf.Text; DAL.AlunoDAL alunoDAL = new DAL.AlunoDAL(); alunoDAL.Cadastrar(aluno); lblMsg.Text = "Aluno cadastrado"; txtCpf.Text = ""; txtNome.Text = ""; } catch (Exception ex) { lblMsg.Text = ex.Message; } }
protected void Page_Load(object sender, EventArgs e) { int raRecibido = 0; btnAtualizar.Enabled = false; if (!IsPostBack) { //Validar se está recebendo a variável cod na URL if (Request.QueryString["cod"] != null) { //Validar se a variável veio com o valor preenchido if (Request.QueryString["cod"].ToString() != "") { int.TryParse(Request.QueryString["cod"].ToString(), out raRecibido); aluno.Ra = raRecibido; aluno = alunoDAL.Selecionar(aluno); if (aluno.Ra != 0) { txtRa.Text = aluno.Ra.ToString(); txtNome.Text = aluno.Nome; txtCpf.Text = aluno.Cpf; btnAtualizar.Enabled = true; } else { Response.Write("<script>alert('RA não localizado')</script>"); } } else { Response.Write("<script>alert('RA de aluno vazio')</script>"); } } else { Response.Write("<script>alert('RA de aluno não recebido')</script>"); } } }
//Retornar dados public BLL.Aluno RetornarDados(BLL.Aluno alu) { SqlCommand cmd = new SqlCommand("SELECT * FROM Aluno WHERE CodAluno = @CodAluno"); cmd.Connection = conexao.Conectar(); cmd.Parameters.AddWithValue("@CodAluno", alu.CodAluno); SqlDataReader dr = cmd.ExecuteReader(); if (dr.Read()) { alu.CodAluno = Convert.ToInt16(dr["CodAluno"]); alu.Nome = dr["Nome"].ToString(); alu.Cpf = dr["Cpf"].ToString(); alu.Rg = dr["Rg"].ToString(); alu.Email = dr["Email"].ToString(); alu.DataNascimento = Convert.ToDateTime(dr["DataNascimento"]); } dr.Close(); conexao.Desconectar(); return(alu); }
private void btnEditar_Click_1(object sender, EventArgs e) { //executar metodos de retorno if (dgvConsulta.RowCount > 0) { //Executar metodo de retorno dos dadoss alu.CodAluno = Convert.ToInt16(dgvConsulta.SelectedCells[0].Value); alu = aluDAL.RetornarDados(alu); //preenchendo txts txtNomeAlu.Text = alu.Nome; txtRgAlu.Text = alu.Rg; txtEmailAlu.Text = alu.Email; txtCpfAlu.Text = alu.Cpf; mtxtDataNascimentoAlu.Text = Convert.ToDateTime(alu.DataNascimento).ToString(); //redirecionando para a primeira aba tbcAlunos.SelectedTab = tbpCadastro; //editar para verdadeiro editar = true; } }
public DataTable Consultar(BLL.Aluno a) { DataTable dt = new DataTable(); SqlCommand cmd = new SqlCommand(); cmd.Connection = con.Conectar(); cmd.CommandText = @"SELECT RA, Nome, CPF FROM Aluno WHERE Nome like @nome"; cmd.Parameters.AddWithValue("@nome", "%" + a.Nome + "%"); SqlDataAdapter da = new SqlDataAdapter(); da.SelectCommand = cmd; da.Fill(dt); con.Desconectar(); return(dt); }
/*public void Excluir(BLL.Cliente cli) * { * SqlCommand cmd = new SqlCommand(); * cmd.Connection = con.Conectar(); * * cmd.CommandText = @"DELETE FROM TBCliente WHERE ID = @id"; * cmd.Parameters.AddWithValue("@id", cli.Id); * * cmd.ExecuteNonQuery(); * con.Desconectar(); * } * * public void Atualizar(BLL.Cliente cli) * { * SqlCommand cmd = new SqlCommand(); * cmd.Connection = con.Conectar(); * * cmd.CommandText = @"UPDATE TBCliente SET NOME=@nome, CPF=@cpf, TELEFONE=@telefone, EMAIL=@email WHERE ID = @id"; * * cmd.Parameters.AddWithValue("@nome", cli.Nome); * cmd.Parameters.AddWithValue("@cpf", cli.CPF); * cmd.Parameters.AddWithValue("@telefone", cli.Telefone); * cmd.Parameters.AddWithValue("@email", cli.Email); * cmd.Parameters.AddWithValue("@id", cli.Id); * * cmd.ExecuteNonQuery(); * con.Desconectar(); * }*/ public BLL.Aluno PreencherPeloID(BLL.Aluno alu) { SqlCommand cmd = new SqlCommand(); cmd.Connection = con.Conectar(); cmd.CommandText = @"SELECT Id_Aluno, Nome, Email, Cpf, Rg, Nascimento, Telefone, Rua_Av, Numero, Bairro, Cidade, Estado, Cep, Id_Login FROM Aluno WHERE Id_Login LIKE @idlogin"; cmd.Parameters.AddWithValue("@idlogin", alu.IdLogin); SqlDataReader dr = cmd.ExecuteReader(); if (dr.HasRows) { dr.Read(); alu.IdAluno = Convert.ToInt32(dr["Id_Aluno"]); alu.Nome = dr["Nome"].ToString(); alu.Email = dr["Email"].ToString(); alu.Cpf = dr["Cpf"].ToString(); alu.Rg = dr["Rg"].ToString(); alu.Nascimento = Convert.ToDateTime(dr["Nascimento"]); alu.Telefone = dr["Telefone"].ToString(); alu.RuaAv = dr["Rua_Av"].ToString(); alu.Numero = dr["Numero"].ToString(); alu.Bairro = dr["Bairro"].ToString(); alu.Cidade = dr["Cidade"].ToString(); alu.Estado = dr["Estado"].ToString(); alu.Cep = dr["Cep"].ToString(); alu.IdLogin = Convert.ToInt32(dr["Id_Login"]); dr.Close(); } else { alu.IdLogin = 0; } con.Desconectar(); return(alu); }
public void Cadastrar(BLL.Aluno a) { //Instanciar um objeto de comando SQL. SqlCommand cmd = new SqlCommand(); //Configurar a conexao. cmd.Connection = con.Conectar(); //Configurar o comando SQL. cmd.CommandText = @"INSERT INTO TB_ALUNO( RA, NOME, CPF, IDADE) VALUES(@ra,@nome,@cpf,@idade)"; //Configurar os valores. cmd.Parameters.AddWithValue("@ra", a.Ra); cmd.Parameters.AddWithValue("@nome", a.Nome); cmd.Parameters.AddWithValue("@cpf", a.Cpf); cmd.Parameters.AddWithValue("@idade", a.Idade); //Executar os comandos SQL. cmd.ExecuteNonQuery(); //Fechar a conexão com o banco de dados. con.Desconectar(); }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { if (Session["usuario"] != null) { if (Session["usuario"].ToString() != string.Empty) { Response.Write("<script>alert('Bem-vindo, " + Session["usuario"] + "')</script>"); alu.IdLogin = Convert.ToInt32(Session["idlogin"]); alu = aluDAL.PreencherPeloID(alu); Session.Add("idaluno", alu.IdAluno); string html = ""; int qtd = 0; //pega o id do usuario e faz um listar por ele System.Data.DataTable dt = cuDAL.Listar(); html += "<table style='width: 100 % '><tr>"; //Laço para Rodar todas as linhas que retornam da select do BD for (int lin = 0; lin < dt.Rows.Count; lin++) { if (qtd == 4) { html += "<tr>"; qtd = 0; } html += "<td style='width: 100%'>"; //html += "<div class='container'>"; html += "<div class='card'>"; html += "<img class='card__image' src='" + dt.Rows[lin].ItemArray[1].ToString() + "' alt='wave'/>"; //imagem html += "<div class='card-title'>"; html += "<a href='#' class='toggle-info btn'>"; html += "<span class='left'></span>"; html += "<span class='right'></span>"; html += "</a><br/>"; html += "<h2>" + dt.Rows[lin].ItemArray[2].ToString(); //nome html += "</h2>"; html += "</div>"; html += "<div class='card-flap flap1'>"; html += "<div class='card-description'>"; html += dt.Rows[lin].ItemArray[5].ToString(); //descrição html += "</div>"; html += "<div class='card-flap flap2'>"; html += "<div class='card-actions'>"; html += "<a href = 'Cursos.aspx' class='btn'>Estudar</a>"; //fazer botão com id html += "</div>"; html += "</div>"; html += "</div>"; html += "</div>"; //html += "</div>"; html += "</td>"; qtd++; if (qtd == 4) { html += "</tr>"; } } html += "</tr></table>"; litCurso.Text = html; } else { Response.Redirect("../EXTERNO/Login.aspx"); } } else { Response.Redirect("../EXTERNO/Login.aspx"); } } }