现在的位置: 首页 > 综合 > 正文

数据操作层ACCSEE

2013年09月15日 ⁄ 综合 ⁄ 共 6010字 ⁄ 字号 评论关闭
using System;
using System.Collections;
using System.Text;
using System.Configuration;
using System.Data;
using System.Data.OleDb;
using Solog.Model;
using Solog.IDbTask;
namespace Solog.AcessTask
{
    
/// <summary>
    
/// 数据操作层
    
/// </summary>

    public class SqlProfile:IDataTask
    
{
        
提取Blog文章

        
//获取top10文章列表
        public ArticleInfo[] TopArticles()
        
{
            GetData getdata 
= new GetData();
            ArrayList arrArt 
= new ArrayList();
            
string cmdsql = "";
            cmdsql 
+= "select top 10 L.*,C.cate_Name  from blog_Content AS L,blog_Category AS C where L.log_CateID=C.cate_ID";
            cmdsql 
+= " order by log_ID desc";
            OleDbDataReader dr 
= getdata.GetReader(cmdsql);
            
while (dr.Read())
            
{
                ArticleInfo inf 
= SqlHelper.ConvertToArticleInfo(dr, new ArticleInfo());
                arrArt.Add(inf);
            }

            dr.Close();
            
return (ArticleInfo[])arrArt.ToArray(typeof(ArticleInfo));
        }



        
public ArticleInfo[] SearchResult(string searchKey)
        
{
            GetData getdata 
= new GetData();
            ArrayList arrArt 
= new ArrayList();
            
string sqlfilter="";
            sqlfilter 
+= "where L.log_Title like '%" + searchKey + "%'";
            
string cmdsql = "";
            cmdsql 
+= "select  L.*,C.cate_Name  from blog_Content AS L,blog_Category AS C " + sqlfilter;
            cmdsql 
+= "and L.log_CateID=C.cate_ID order by log_ID desc";
            OleDbDataReader dr 
= getdata.GetReader(cmdsql);
            
while (dr.Read())
            
{
                ArticleInfo inf 
= SqlHelper.ConvertToArticleInfo(dr, new ArticleInfo());
                arrArt.Add(inf);
            }

            dr.Close();
            
return (ArticleInfo[])arrArt.ToArray(typeof(ArticleInfo));
 
        }


        
/// <summary>
        
/// 获取评论数据
        
/// </summary>
        
/// <returns></returns>


        
public DataSet ListComment()
        
{
            
string cmdsql = "select top 5 blog_ID,left(comm_Content,10)as comment from blog_Comment order by comm_ID desc";
            GetData getdata 
= new GetData();
            DataSet ds 
= getdata.GetDataset(cmdsql);
            
return ds;
        }


        
public DataSet ListCate()
        
{
          GetData getdata 
= new GetData();
          
          
string querystring = "select cate_ID,cate_Name,cate_order  from blog_Category";
          DataSet ds 
= getdata.GetDataset(querystring);
           
return ds;

        }

        
//public DataTable listCate()
        
//{
        
//    OleDbDataReader dr = ListCate();
        
//    DataTable dt = new DataTable("category");
            
        
//    dt.Columns.Add("cateID", typeof(Int32));
        
//    dt.Columns.Add("cateName",typeof(string));
            
        
//    while (dr.Read())
        
//    {
        
//        DataRow myrow = dt.NewRow();
        
//        myrow["cateID"]=dr["cate_ID"];
        
//        myrow["cateName"] = dr["cate_Name"];
        
//        dt.Rows.Add(myrow);
        
//    }
        
//    return dt;

        
//}

        
//获取views.aspx查看文章
        public OleDbDataReader GetArticleReader(int id)
        
{
            GetData getdata 
= new GetData();
            
int contentId = id;
            
string querystring = "select L.*,C.cate_Name from blog_Content as L,blog_Category as C where L.log_ID=" + contentId + " and L.log_CateID=C.cate_ID ";
            OleDbDataReader dr 
= getdata.GetReader(querystring);
            
return dr;
        }

        
public DataSet GetArticle(int id)
        
{
            GetData getdata 
= new GetData();
            
int contentId = id;
            
string querystring = "select L.*,C.cate_Name from blog_Content as L,blog_Category as C where L.log_ID=" + contentId + " and L.log_CateID=C.cate_ID ";
            DataSet ds 
= getdata.GetDataset(querystring);
            
return ds;
        }

        
//获取要编辑的文章内容
        public ArticleInfo EditArtInfo(int id)
        
{
            ArticleInfo inf
=new ArticleInfo();
            OleDbDataReader dr 
= GetArticleReader(id);
            
while (dr.Read())
            
{
               inf 
=SqlHelper.ConvertToArticleInfo(dr, new ArticleInfo());
            }

            
return inf;

        }

        
//获取ID文章的评论
        public DataSet GetComment(int id)
        
{
            GetData getdata 
= new GetData();
            
int contentId = id;
            
string querystring=

抱歉!评论已关闭.