Model
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace NeoModel
- {
- public class R***eader
- {
- public R***eader()
- {
- }
- private int _id;
- public int ID
- {
- get { return _id; }
- set { _id = value; }
- }
- private string _title;
- public string Title
- {
- get { return _title; }
- set { _title = value; }
- }
- private DateTime? _pubdate;
- public DateTime? PubDate
- {
- get { return _pubdate; }
- set { _pubdate = value; }
- }
- private string _guid;
- public string Guid
- {
- get { return _guid; }
- set { _guid = value; }
- }
- private string _description;
- public string Description
- {
- get { return _description; }
- set { _description = value; }
- }
- }
- }
DAL
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Data;
- using System.Data.SqlClient;
- using NeoCommon;
- namespace NeoDAL
- {
- public class R***eaderDal
- {
- public R***eaderDal()
- {
- }
- /// <summary>
- /// 添加rss
- /// </summary>
- /// <param name="rss"></param>
- /// <returns></returns>
- public bool AddR***eader(NeoModel.R***eader rss)
- {
- string strSql = "Insert into R***eader(title,pubdate,[guid],[description]) values(@title,@pubdate,@guid,@description)";
- SqlParameter[] sp = {
- new SqlParameter("@title",rss.Title),
- new SqlParameter("@pubdate",rss.PubDate),
- new SqlParameter("@guid",rss.Guid),
- new SqlParameter("@description",rss.Description)
- };
- return DbHelperSQL.ExecuteSql(strSql, sp) > 0;
- }
- /// <summary>
- /// 判断rss是否存在
- /// </summary>
- /// <param name="guid"></param>
- /// <returns></returns>
- public bool IsExistRssByGuid(string guid)
- {
- string strSql = "SELECT COUNT(0) FROM R***eader WHERE [guid]=@guid";
- SqlParameter[] sp = {
- new SqlParameter("@guid",guid)
- };
- return Convert.ToInt32(DbHelperSQL.GetSingle(strSql, sp)) > 0;
- }
- /// <summary>
- ///
- /// </summary>
- /// <returns></returns>
- public DataTable GetRss()
- {
- string strSql = "Select * from R***eader order by pubdate desc";
- DataSet ds = DbHelperSQL.Query(strSql);
- if (ds == null || ds.Tables.Count <= 0 || ds.Tables[0].Rows.Count <= 0)
- {
- return new DataTable();
- }
- return ds.Tables[0];
- }
- }
- }
BLL
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Data;
- namespace NeoBLL
- {
- public class R***eader
- {
- NeoDAL.R***eaderDal dal = new NeoDAL.R***eaderDal();
- public R***eader() { }
- /// <summary>
- ///
- /// </summary>
- /// <param name="rss"></param>
- /// <returns></returns>
- public bool AddR***eader(NeoModel.R***eader rss)
- {
- return dal.AddR***eader(rss);
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="guid"></param>
- /// <returns></returns>
- public bool IsExistRssByGuid(string guid)
- {
- return dal.IsExistRssByGuid(guid);
- }
- public DataTable GetRss()
- {
- return dal.GetRss();
- }
- }
- }
页面源
- <%@ Page Title="" Language="C#" MasterPageFile="~/master/Oa.Master" AutoEventWireup="true"
- CodeBehind="R***eader.aspx.cs" Inherits="NeoBackground.Baidu.R***eader" %>
- <asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
- <style type="text/css">
- .title
- {
- font-size: 11pt;
- margin: 5px 0;
- background: transparent url(../p_w_picpaths/icon.rss.current.png) no-repeat 4px 50%;
- padding-left: 28px;
- word-break: break-word;
- -webkit-user-select: text;
- }
- h3, h4
- {
- padding: 0;
- }
- a
- {
- color: #036;
- }
- h3
- {
- display: block;
- -webkit-margin-before: 1em;
- -webkit-margin-after: 1em;
- -webkit-margin-start: 0px;
- -webkit-margin-end: 0px;
- font-weight: bold;
- }
- h4
- {
- display: block;
- -webkit-margin-before: 1.33em;
- -webkit-margin-after: 1.33em;
- -webkit-margin-start: 0px;
- -webkit-margin-end: 0px;
- }
- .updated
- {
- color: #666;
- font-weight: normal;
- padding-left:8px;
- margin: 5px 0;
- }
- .description
- {
- margin: 14px 20px 20px 0;
- padding-left:8px;
- max-width: 850px;
- line-height: 1.8;
- font-size: 10pt;
- word-break: break-word;
- }
- .actions
- {
- padding: 5px 8px;
- background-color: #f4f5f5;
- border-radius: 3px;
- width:99%;
- }
- div
- {
- display: block;
- width: 100%;
- }
- body
- {
- color: Black;
- cursor: default;
- font-size: 9pt;
- font-family: Segoe UI, 微软雅黑 , Tahoma;
- }
- </style>
- </asp:Content>
- <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
- <asp:Repeater ID="reprss" runat="server">
- <ItemTemplate>
- <div style=" margin:10px; padding:5px; background-color:White; border:1px #ccc solid; border-radius:4px;">
- <div>
- <h3 class="title">
- <a href="<%#Eval("guid") %>" target="_blank">
- <%#Eval("title") %></a></h3>
- <h4 class="updated">
- <%#Eval("pubdate")%>
- </h4>
- </div>
- <div class="description">
- <%#Eval("description")%><br />
- </div>
- <div class="actions">
- <a href="<%#Eval("guid") %>" target="_blank">打开页面</a>
- </div>
- </div>
- </ItemTemplate>
- </asp:Repeater>
- </asp:Content>
后台
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Xml;
- using System.Data;
- namespace NeoBackground.Baidu
- {
- public partial class R***eader : System.Web.UI.Page
- {
- NeoBLL.R***eader bll = new NeoBLL.R***eader();
- protected void Page_Load(object sender, EventArgs e)
- {
- if (!IsPostBack)
- {
- // WriterRss();
- DataTable dt = bll.GetRss();
- this.reprss.DataSource = dt;
- this.reprss.DataBind();
- }
- }
- public void WriterRss()
- {
- string url = "http://feed.cnblogs.com/news/rss";
- XmlDocument document = new XmlDocument();
- document.Load(url);//
- XmlNodeList list = document.GetElementsByTagName("item");
- if (document.HasChildNodes)
- {
- foreach (XmlNode xn in list)
- {
- if (xn.HasChildNodes)
- {
- NeoModel.R***eader rss = new NeoModel.R***eader();
- XmlNodeList xlcd = xn.ChildNodes;
- foreach (XmlNode xmlchild in xlcd)
- {
- switch (xmlchild.Name)//节点的限定名字
- {
- case "title":
- rss.Title = xmlchild.InnerText;
- break;
- case "pubDate":
- rss.PubDate = Convert.ToDateTime(xmlchild.InnerText);
- break;
- case "guid":
- rss.Guid = xmlchild.InnerText;
- break;
- case "description":
- rss.Description = xmlchild.InnerText;
- break;
- default:
- break;
- }
- }
- if (!bll.IsExistRssByGuid(rss.Guid))
- {
- bll.AddR***eader(rss);
- }
- }
- }
- }
- }
- }
- }
显示如下图:
转载于:https://blog.51cto.com/431898/1025533