public int estudante_id(string cpf) { Modelo.Estudante aEstudante = new Modelo.Estudante(); SqlConnection conn = new SqlConnection(connectionString); conn.Open(); SqlCommand cmd = conn.CreateCommand(); cmd.CommandText = "Select * from Estudante Where cpf = @cpf"; cmd.Parameters.AddWithValue("@cpf", cpf); SqlDataReader dr = cmd.ExecuteReader(); int id_estudante = 0; if (dr.HasRows) { while (dr.Read()) { id_estudante = int.Parse(dr["id"].ToString()); } } dr.Close(); conn.Close(); return(id_estudante); }
public int instituicao_id(int Id) { Modelo.Estudante aEstudante = new Modelo.Estudante(); SqlConnection conn = new SqlConnection(connectionString); conn.Open(); SqlCommand cmd = conn.CreateCommand(); cmd.CommandText = "Select * from Estudante Where Id = @Id"; cmd.Parameters.AddWithValue("@Id", Id); SqlDataReader dr = cmd.ExecuteReader(); int id_instituicao = 0; if (dr.HasRows) { while (dr.Read()) { id_instituicao = int.Parse(dr["instituicao_id"].ToString()); } } dr.Close(); conn.Close(); return(id_instituicao); }
public List <Modelo.Estudante> SelectArquivoCsv(string arquivo) { StreamReader sr; string Linha; string[] linha; List <Modelo.Estudante> aListEstudante = new List <Modelo.Estudante>(); // Le arquivo com nome de imagens if (System.IO.File.Exists(arquivo)) { sr = new StreamReader(System.IO.File.OpenRead(arquivo)); try { while (sr.Peek() > -1) { Linha = sr.ReadLine(); // Le uma Linha // Separa os dados em cada linha linha = Linha.Split(';'); Modelo.Estudante aEstudante = new Modelo.Estudante( linha[0], linha[2], linha[1], "", "", 2, "", 0, 0, Convert.ToDateTime("01/01/2000") ); aListEstudante.Add(aEstudante); } } finally { sr.Close(); } } return(aListEstudante); }
public void Insert(Modelo.Estudante obj) { SqlConnection conn = new SqlConnection(connectionString); conn.Open(); SqlCommand com = conn.CreateCommand(); SqlCommand cmd = new SqlCommand("INSERT INTO Estudante (Nome, cpf, rg, email, status, carteira_foto, carteira_saldo, carteira_numero, carteira_validade, senha, administrador_id, carteira_status) VALUES (@Nome, @cpf, @rg, @email, @status, @carteira_foto, @carteira_saldo, @carteira_numero, @carteira_validade, @senha, 1, 0)", conn); cmd.Parameters.AddWithValue("@Nome", obj.nome); cmd.Parameters.AddWithValue("@cpf", obj.cpf); cmd.Parameters.AddWithValue("@rg", obj.rg); cmd.Parameters.AddWithValue("@email", obj.email); cmd.Parameters.AddWithValue("@status", obj.status); cmd.Parameters.AddWithValue("@carteira_foto", obj.carteira_foto); cmd.Parameters.AddWithValue("@carteira_saldo", obj.carteira_saldo); cmd.Parameters.AddWithValue("@carteira_numero", obj.carteira_numero); cmd.Parameters.AddWithValue("@carteira_validade", obj.carteira_validade); cmd.Parameters.AddWithValue("@senha", obj.senha); cmd.ExecuteNonQuery(); }
public Modelo.Estudante Login(string cpf, string senha) { Modelo.Estudante aEstudante = new Modelo.Estudante(); SqlConnection conn = new SqlConnection(connectionString); conn.Open(); SqlCommand cmd = conn.CreateCommand(); cmd.CommandText = "Select * from Estudante Where cpf = @cpf and senha = @senha"; cmd.Parameters.AddWithValue("@cpf", cpf); cmd.Parameters.AddWithValue("@senha", senha); SqlDataReader dr = cmd.ExecuteReader(); if (dr.HasRows) { while (dr.Read()) { aEstudante = new Modelo.Estudante( dr["nome"].ToString(), dr["cpf"].ToString(), dr["rg"].ToString(), dr["email"].ToString(), dr["senha"].ToString(), int.Parse(dr["status"].ToString()), dr["carteira_foto"].ToString(), double.Parse(dr["carteira_saldo"].ToString()), int.Parse(dr["carteira_numero"].ToString()), Convert.ToDateTime(dr["carteira_validade"].ToString()) ); aEstudante.id = Convert.ToInt32(dr["id"].ToString()); aEstudante.carteira_status = Convert.ToInt32(dr["carteira_status"].ToString()); } } dr.Close(); conn.Close(); return(aEstudante); }
public List <Modelo.Estudante> SelectAll() { List <Modelo.Estudante> aListEstudante = new List <Modelo.Estudante>(); SqlConnection conn = new SqlConnection(connectionString); conn.Open(); SqlCommand cmd = conn.CreateCommand(); cmd.CommandText = "Select * from Estudante"; SqlDataReader dr = cmd.ExecuteReader(); if (dr.HasRows) { while (dr.Read()) { Modelo.Estudante aEstudante = new Modelo.Estudante( dr["nome"].ToString(), dr["cpf"].ToString(), dr["rg"].ToString(), dr["email"].ToString(), dr["senha"].ToString(), int.Parse(dr["status"].ToString()), dr["carteira_foto"].ToString(), double.Parse(dr["carteira_saldo"].ToString()), int.Parse(dr["carteira_numero"].ToString()), Convert.ToDateTime(dr["carteira_validade"].ToString()) ); aEstudante.id = Convert.ToInt32(dr["id"].ToString()); aEstudante.carteira_status = Convert.ToInt32(dr["carteira_status"].ToString()); aListEstudante.Add(aEstudante); } } dr.Close(); conn.Close(); return(aListEstudante); }
public void Update(Modelo.Estudante obj) { SqlConnection conn = new SqlConnection(connectionString); conn.Open(); SqlCommand com = conn.CreateCommand(); SqlCommand cmd = new SqlCommand("UPDATE Estudante SET Nome = @Nome, cpf = @cpf, senha = @senha, email = @email, status = @status, carteira_foto = @carteira_foto, carteira_saldo = @carteira_saldo, carteira_numero = @carteira_numero, carteira_validade = @carteira_validade, carteira_status = @carteira_status WHERE cpf = @cpf", conn); cmd.Parameters.AddWithValue("@Id", obj.id); cmd.Parameters.AddWithValue("@Nome", obj.nome); cmd.Parameters.AddWithValue("@cpf", obj.cpf); cmd.Parameters.AddWithValue("@rg", obj.rg); cmd.Parameters.AddWithValue("@email", obj.email); cmd.Parameters.AddWithValue("@status", obj.status); cmd.Parameters.AddWithValue("@senha", obj.senha); cmd.Parameters.AddWithValue("@carteira_foto", obj.carteira_foto); cmd.Parameters.AddWithValue("@carteira_saldo", obj.carteira_saldo); cmd.Parameters.AddWithValue("@carteira_numero", obj.carteira_numero); cmd.Parameters.AddWithValue("@carteira_validade", obj.carteira_validade); cmd.Parameters.AddWithValue("@carteira_status", obj.carteira_status); cmd.ExecuteNonQuery(); }