Advertisement
Guest User

MenuService

a guest
Oct 15th, 2013
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.79 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Data.OleDb;
  6. using System.Data.SqlClient;
  7. using System.Web.Configuration;
  8. using System.Data;
  9.  
  10. namespace WebApplication3.classi
  11. {
  12.     public class NewsService
  13.     {
  14.         public News CaricaNotizia(int id)
  15.         {
  16.             database db = new database();
  17.             News notizia = null;
  18.             string querypagina = "SELECT * FROM NEWS";
  19.             OleDbDataReader reader = db.EseguiReader(querypagina);
  20.             if (reader.Read())
  21.             {
  22.                 notizia = new News();
  23.                 notizia.id = Int32.Parse(reader["id"].ToString());
  24.                 notizia.titolo = reader["titolo"].ToString();
  25.                 notizia.contenuto = reader["contenuto"].ToString();
  26.             }
  27.             return notizia;
  28.         }
  29.  
  30.         public bool delNotizia(int _id)
  31.         {
  32.  
  33.             database db = new database();
  34.             string query = "delete from notizie where id=" + _id;
  35.             return db.AggiornaDB(query);
  36.  
  37.         }
  38.  
  39.         public List<News> mlistanews()
  40.         {
  41.             database db = new database();
  42.             List<News> notizia = new List<News>();
  43.             News n;
  44.             string querypagina = "SELECT * FROM NOTIZIE";
  45.             OleDbDataReader reader = db.EseguiReader(querypagina);
  46.             while (reader.Read())
  47.             {
  48.                 n = new News();
  49.                 n.id = Int32.Parse(reader["id"].ToString());
  50.                 n.titolo = reader["titolo"].ToString();
  51.                 notizia.Add(n);
  52.             }
  53.             return notizia;
  54.         }
  55.  
  56.          
  57.         public int insertNotizia(News n)
  58.         {
  59.             Data.DB.OleDbDatabase db = new Data.DB.OleDbDatabase();
  60.             OleDbCommand cmd = new OleDbCommand();
  61.             cmd.CommandText = "INSERT INTO NOTIZIE (titolo,contenuto,data) VALUES (?,?,?)";
  62.             cmd.Parameters.AddWithValue("titolo", n.titolo);
  63.             cmd.Parameters.AddWithValue("contenuto", n.contenuto);
  64.             cmd.Parameters.AddWithValue("data", n.data);
  65.             return db.EseguiNonQuery(cmd);
  66.  
  67.  
  68.         }
  69.         public int aggNotizia(News n)
  70.         {
  71.             Data.DB.OleDbDatabase db = new Data.DB.OleDbDatabase();
  72.             OleDbCommand cmd = new OleDbCommand();
  73.             cmd.CommandText = "UPDATE NOTIZIe SET titolo=?, contenuto=? data=? WHERE id=?";
  74.             cmd.Parameters.AddWithValue("titolo", n.titolo);
  75.             cmd.Parameters.AddWithValue("contenuto", n.contenuto);
  76.             cmd.Parameters.AddWithValue("data", n.data);
  77.             cmd.Parameters.AddWithValue("id", n.id);
  78.             int cotto;
  79.             cotto = db.EseguiNonQuery(cmd);
  80.             if (cotto == 1) return (1); else return (0);
  81.         }
  82.     }
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement