public static void Insert(Modelo.Icone icone) { Modelo.Icone icon = icone; try { if (Select(icon.id) == null) { using (connection = new SqlConnection(connectionString)) { connection.Open(); string sqlUsuario = "INSERT INTO Icone(IconeUrl) VALUES (@iconeUrl)"; SqlCommand cmdUsuario = new SqlCommand(sqlUsuario, connection); cmdUsuario.Parameters.AddWithValue("@iconeUrl", icone.iconeUrl); cmdUsuario.ExecuteNonQuery(); } } else { Update(icone); } } catch (SystemException) { throw; } }
public static Modelo.Icone Select(int icone_id) { //instancia um novo usuario Modelo.Icone icone = null; try { using (connection = new SqlConnection(connectionString)) { //abre a conexão connection.Open(); string sqlIcone = "SELECT * FROM Icone WHERE id = @id"; SqlCommand cmdIcone = new SqlCommand(sqlIcone, connection); cmdIcone.Parameters.AddWithValue("@id", icone_id); SqlDataReader drIcones; using (drIcones = cmdIcone.ExecuteReader()) { if (drIcones.HasRows) { //lê os resultados while (drIcones.Read()) { int idIcone = (int)drIcones["id"]; string iconeUrl = (string)drIcones["IconeUrl"]; icone = new Modelo.Icone(idIcone, iconeUrl); } } } } } catch (SystemException) { throw; } return(icone); }
protected void AddIcone_Click(object sender, EventArgs e) { uploadImage(); Modelo.Icone jog = new Modelo.Icone("../Icone/" + UploadImage.FileName); DAL.DALIcons.Insert(jog); Response.Redirect("~/Administrador/Icone.aspx"); }
protected void getIcon() { if (!Page.IsPostBack) { this.dalicon = new DAL.DALIcons(); this.icon = DAL.DALIcons.Select(this.user.Icone_id); } }
protected void setIcon() { if (Request.QueryString["icone"] != null) { this.dalicone = new DAL.DALIcons(); this.icone = DAL.DALIcons.Select(int.Parse(Request.QueryString["icone"])); } }
protected void initPage() { if (Session["id"] != null) { if (Metodos.hasUser(Session["id"].ToString() ?? "")) { this.user = Metodos.getUser(Session["id"].ToString()); this.icon = Metodos.getIcone(this.user.Icone_id); } } else { Response.Redirect("~/Public/Login.aspx"); } }
public static void Delete(Modelo.Icone icone) { try { using (connection = new SqlConnection(connectionString)) { connection.Open(); string sqlIcone = "DELETE FROM Icone WHERE id = @id"; SqlCommand cmdIcone = new SqlCommand(sqlIcone, connection); cmdIcone.Parameters.AddWithValue("@id", icone.id); cmdIcone.ExecuteNonQuery(); } } catch (SystemException) { throw; } }
public static void Update(Modelo.Icone icone) { try { using (connection = new SqlConnection(connectionString)) { connection.Open(); if (Select(icone.id) != icone) { string sqlUsuario = "UPDATE Icone SET IconeUrl = @iconeUrl WHERE id = @id"; SqlCommand cmdUsuario = new SqlCommand(sqlUsuario, connection); cmdUsuario.Parameters.AddWithValue("@iconeUrl", icone.iconeUrl); cmdUsuario.Parameters.AddWithValue("@id", icone.id); cmdUsuario.ExecuteNonQuery(); } } } catch (SystemException) { throw; } }
public static List <Modelo.Icone> SelectAll() { Modelo.Icone icone; List <Modelo.Icone> icones = new List <Modelo.Icone>(); try { using (connection = new SqlConnection(connectionString)) { connection.Open(); string sqlIcones = "SELECT * FROM Icone"; SqlCommand cmdIcones = new SqlCommand(sqlIcones, connection); SqlDataReader drIcones; using (drIcones = cmdIcones.ExecuteReader()) { if (drIcones.HasRows) { while (drIcones.Read()) { int idIcone = (int)drIcones["id"]; string iconeUrl = (string)drIcones["IconeUrl"]; icone = new Modelo.Icone(idIcone, iconeUrl); icones.Add(icone); } } } } } catch (SystemException) { throw; } return(icones); }