using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Model;
using System.Data;
namespace DAL
{
public class NewsArticleDAL
{
static string sql;
static NewsArticle a;
static DataSet ds;
static DataRow dr;
public static bool Add(NewsArticle a)
{
sql = string.Format("insert into NewsArticle (AddDate,Cid,Content,Hits,Title,Writer) values ('{0}','{1}','{2}','{3}','{4}','{5}')", a.AddDate, a.Cid, a.Content, a.Hits, a.Title, a.Writer);
return DBAccess.ExecSqlCommand(sql);
}
public static bool Update(NewsArticle a)
{
sql = string.Format("update NewsArticle set AddDate='{0}',Cid='{1}',Content='{2}',Hits='{3}',Title='{4}',Writer='{5}' where id={6}", a.AddDate, a.Cid, a.Content, a.Hits, a.Title, a.Writer,a.Id);
return DBAccess.ExecSqlCommand(sql);
}
public static bool Delete(object id)
{
sql = string.Format("Delete NewsArticle where id='{0}'", id);
return DBAccess.ExecSqlCommand(sql);
}
public static NewsArticle Find(object id)
{
a = new NewsArticle();
string sql = string.Format("select * from NewsArticle where id='{0}'", id);
dr = DBAccess.GetDateRow(sql);
try
{
a.AddDate =Convert.ToDateTime(dr["AddDate"].ToString());
a.Cid = dr["Cid"];
a.Content = dr["Content"].ToString();
a.Hits=Convert.ToInt32(dr["hits"]);
a.Id = dr["id"];
a.Title = dr["Title"].ToString();
a.Writer = dr["Writer"].ToString();
return a;
}
catch
{
return null;
}
}
public static IList<NewsArticle> FindALL(object cid)
{
List<NewsArticle> list = new List<NewsArticle>();
if (cid != null && cid.ToString() != "")
{
sql = "select * from NewsArticle where cid="+cid + " order by id desc";
}
else
{
sql = "select * from NewsArticle order by id desc";
}
ds = DBAccess.GetDataSet(sql);
if (ds == null)
{
return null;
}
else
{
foreach (DataRow dr in ds.Tables[0].Rows)
{
NewsArticle a = new NewsArticle();
a.AddDate = Convert.ToDateTime(dr["addDate"].ToString());
a.Cid = dr["cid"];
a.Content = dr["Content"].ToString();
a.Hits = Convert.ToInt32(dr["hits"]);
a.Id = dr["id"];
a.Title = dr["Title"].ToString();
a.Writer = dr["Writer"].ToString();
list.Add(a);
}
return list;
}
}
public static IList<NewsArticle> FindALL(object cid,int num)
{
List<NewsArticle> list = new List<NewsArticle>();
if (cid != null && cid.ToString() != "")
{
sql = "select top " + num + " * from NewsArticle where cid=" + cid + " order by id desc";
}
else
{
sql = "select top " + num + " * from NewsArticle order by id desc";
}
ds = DBAccess.GetDataSet(sql);
if (ds == null)
{
return null;
}
else
{
foreach (DataRow dr in ds.Tables[0].Rows)
{
NewsArticle a = new NewsArticle();
a.AddDate = Convert.ToDateTime(dr["addDate"].ToString());
a.Cid = dr["cid"];
a.Content = dr["Content"].ToString();
a.Hits = Convert.ToInt32(dr["hits"]);
a.Id = dr["id"];
a.Title = dr["Title"].ToString();
a.Writer = dr["Writer"].ToString();
list.Add(a);
}
return list;
}
}
public static IList<NewsArticle> FindALLByHits()
{
List<NewsArticle> list = new List<NewsArticle>();
sql = "select top 12 * from NewsArticle order by hits desc";
ds = DBAccess.GetDataSet(sql);
if (ds == null)
{
return null;
}
else
{
foreach (DataRow dr in ds.Tables[0].Rows)
{
NewsArticle a = new NewsArticle();
a.AddDate = Convert.ToDateTime(dr["addDate"].ToString());
a.Cid = dr["cid"];
a.Content = dr["Content"].ToString();
a.Hits = Convert.ToInt32(dr["hits"]);
a.Id = dr["id"];
a.Title = dr["Title"].ToString();
a.Writer = dr["Writer"].ToString();
list.Add(a);
}
return list;
}
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Model;
using System.Data;
namespace DAL
{
public class NewsArticleDAL
{
static string sql;
static NewsArticle a;
static DataSet ds;
static DataRow dr;
public static bool Add(NewsArticle a)
{
sql = string.Format("insert into NewsArticle (AddDate,Cid,Content,Hits,Title,Writer) values ('{0}','{1}','{2}','{3}','{4}','{5}')", a.AddDate, a.Cid, a.Content, a.Hits, a.Title, a.Writer);
return DBAccess.ExecSqlCommand(sql);
}
public static bool Update(NewsArticle a)
{
sql = string.Format("update NewsArticle set AddDate='{0}',Cid='{1}',Content='{2}',Hits='{3}',Title='{4}',Writer='{5}' where id={6}", a.AddDate, a.Cid, a.Content, a.Hits, a.Title, a.Writer,a.Id);
return DBAccess.ExecSqlCommand(sql);
}
public static bool Delete(object id)
{
sql = string.Format("Delete NewsArticle where id='{0}'", id);
return DBAccess.ExecSqlCommand(sql);
}
public static NewsArticle Find(object id)
{
a = new NewsArticle();
string sql = string.Format("select * from NewsArticle where id='{0}'", id);
dr = DBAccess.GetDateRow(sql);
try
{
a.AddDate =Convert.ToDateTime(dr["AddDate"].ToString());
a.Cid = dr["Cid"];
a.Content = dr["Content"].ToString();
a.Hits=Convert.ToInt32(dr["hits"]);
a.Id = dr["id"];
a.Title = dr["Title"].ToString();
a.Writer = dr["Writer"].ToString();
return a;
}
catch
{
return null;
}
}
public static IList<NewsArticle> FindALL(object cid)
{
List<NewsArticle> list = new List<NewsArticle>();
if (cid != null && cid.ToString() != "")
{
sql = "select * from NewsArticle where cid="+cid + " order by id desc";
}
else
{
sql = "select * from NewsArticle order by id desc";
}
ds = DBAccess.GetDataSet(sql);
if (ds == null)
{
return null;
}
else
{
foreach (DataRow dr in ds.Tables[0].Rows)
{
NewsArticle a = new NewsArticle();
a.AddDate = Convert.ToDateTime(dr["addDate"].ToString());
a.Cid = dr["cid"];
a.Content = dr["Content"].ToString();
a.Hits = Convert.ToInt32(dr["hits"]);
a.Id = dr["id"];
a.Title = dr["Title"].ToString();
a.Writer = dr["Writer"].ToString();
list.Add(a);
}
return list;
}
}
public static IList<NewsArticle> FindALL(object cid,int num)
{
List<NewsArticle> list = new List<NewsArticle>();
if (cid != null && cid.ToString() != "")
{
sql = "select top " + num + " * from NewsArticle where cid=" + cid + " order by id desc";
}
else
{
sql = "select top " + num + " * from NewsArticle order by id desc";
}
ds = DBAccess.GetDataSet(sql);
if (ds == null)
{
return null;
}
else
{
foreach (DataRow dr in ds.Tables[0].Rows)
{
NewsArticle a = new NewsArticle();
a.AddDate = Convert.ToDateTime(dr["addDate"].ToString());
a.Cid = dr["cid"];
a.Content = dr["Content"].ToString();
a.Hits = Convert.ToInt32(dr["hits"]);
a.Id = dr["id"];
a.Title = dr["Title"].ToString();
a.Writer = dr["Writer"].ToString();
list.Add(a);
}
return list;
}
}
public static IList<NewsArticle> FindALLByHits()
{
List<NewsArticle> list = new List<NewsArticle>();
sql = "select top 12 * from NewsArticle order by hits desc";
ds = DBAccess.GetDataSet(sql);
if (ds == null)
{
return null;
}
else
{
foreach (DataRow dr in ds.Tables[0].Rows)
{
NewsArticle a = new NewsArticle();
a.AddDate = Convert.ToDateTime(dr["addDate"].ToString());
a.Cid = dr["cid"];
a.Content = dr["Content"].ToString();
a.Hits = Convert.ToInt32(dr["hits"]);
a.Id = dr["id"];
a.Title = dr["Title"].ToString();
a.Writer = dr["Writer"].ToString();
list.Add(a);
}
return list;
}
}
}
}