using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Data; using System.Data.Common; using System.Data.Sql; using System.Data.SqlClient; using System.Configuration; /// /// Summary description for instituicao /// public class Nivel { public Nivel() { // // TODO: Add constructor logic here // } private int _id; public int id { get { return _id; } set { _id = value; } } private string _desc; public string desc { get { return _desc; } set { _desc = value; } } public void GetId(string pid) { using (SqlConnection Con = new SqlConnection(Conexao.GetConexaoAtiva())) { Con.Open(); SqlCommand cmd = new SqlCommand("SELECT * FROM NIVEL WHERE ativo = 1 and id = " + pid.ToString(), Con); SqlDataReader DR = cmd.ExecuteReader(); if (DR.HasRows) { while (DR.Read()) { id = DR.GetInt32(0); desc = DR.GetString(1); } } else { desc = ""; } DR.Close(); } } public DataSet GetAll() { using (SqlConnection Con = new SqlConnection(Conexao.GetConexaoAtiva())) { Con.Open(); SqlCommand cmd = new SqlCommand("SELECT * FROM NIVEL where ativo = 1", Con); SqlDataAdapter adapter = new SqlDataAdapter(cmd); DataSet ds = new DataSet(); adapter.Fill(ds, "DS"); return ds; } } public int Inserir() { using (SqlConnection Con = new SqlConnection(Conexao.GetConexaoAtiva())) { Con.Open(); SqlCommand cmd = new SqlCommand("insert into NIVEL (descricao) values (@descricao)", Con); cmd.Parameters.AddWithValue("@descricao", desc.ToString()); cmd.ExecuteNonQuery(); } return 0; } public void Alterar(string pid) { using (SqlConnection Con = new SqlConnection(Conexao.GetConexaoAtiva())) { Con.Open(); SqlCommand cmd = new SqlCommand("UPDATE NIVEL SET descricao = @descricao WHERE id = " + pid.ToString(), Con); cmd.Parameters.AddWithValue("@descricao", desc.ToString()); cmd.ExecuteNonQuery(); } } public void Excluir(string pid) { using (SqlConnection Con = new SqlConnection(Conexao.GetConexaoAtiva())) { Con.Open(); SqlCommand cmd = new SqlCommand("UPDATE NIVEL SET ativo = 0 WHERE id = " + pid.ToString(), Con); cmd.ExecuteNonQuery(); } } }