📄 article.cs
字号:
using System;
using System.Collections.Generic;
using System.Web;
using Castle.ActiveRecord;
using Castle.ActiveRecord.Queries;
using Castle.Components.Validator;
using NHibernate.Expression;
using System.Text.RegularExpressions;
using DNNLite.DesktopModules.Comment;
namespace DNNLite.DesktopModules.Article
{
[ActiveRecord( DynamicUpdate=true )]
public class Article:
ActiveRecordValidationBase<Article>
{
private int _ID;
///<summary>
///文章ID
///</summary>
[PrimaryKey( PrimaryKeyType.Native)]
public int Id
{
get { return _ID; }
set { _ID = value; }
}
private string _TitleIntact;
///<summary>
///完整标题
///</summary>
[Property("TitleIntact",NotNull=true ),ValidateNonEmpty("文章标题不能为空")]
public string TitleIntact
{
get { return _TitleIntact; }
set { _TitleIntact = value; }
}
private string _Subheading;
///<summary>
///副标题
///</summary>
[Property("Subheading")]
public string Subheading
{
get { return _Subheading; }
set { _Subheading = value; }
}
private string _Author;
///<summary>
///作者
///</summary>
[Property("Author")]
public string Author
{
get { return _Author; }
set { _Author = value; }
}
private string _CopyFrom;
///<summary>
///来源
///</summary>
[Property("CopyFrom")]
public string CopyFrom
{
get { return _CopyFrom; }
set { _CopyFrom = value; }
}
private string _Keyword;
///<summary>
///关键字
///</summary>
[Property("Keyword")]
public string Keyword
{
get { return _Keyword; }
set { _Keyword = value; }
}
private string _IncludePic;
///<summary>
///标题前缀 1--[图文] 2--[组图] 3--[推荐] 4--[注意]
///</summary>
[Property("IncludePic")]
public string IncludePic
{
get { return _IncludePic; }
set { _IncludePic = value; }
}
private string _TitleFontColor;
///<summary>
///标题字体颜色
///</summary>
[Property("TitleFontColor")]
public string TitleFontColor
{
get { return _TitleFontColor; }
set { _TitleFontColor = value; }
}
private string _TitleFontType;
///<summary>
///
///</summary>
[Property("TitleFontType")]
public string TitleFontType
{
get { return _TitleFontType; }
set { _TitleFontType = value; }
}
private bool _ShowCommentLink;
///<summary>
///列表显示时是否在标题旁显示“评论”链接
///</summary>
[Property("ShowCommentLink")]
public bool ShowCommentLink
{
get { return _ShowCommentLink; }
set { _ShowCommentLink = value; }
}
private string _Intro;
///<summary>
///简介
///</summary>
[Property("Intro")]
public string Intro
{
get { return _Intro; }
set { _Intro = value; }
}
private string _PaginationType;
///<summary>
///内容分页方式 0--不分页 1--自动分页 2--手动分页
///</summary>
[Property("PaginationType")]
public string PaginationType
{
get { return _PaginationType; }
set { _PaginationType = value; }
}
private int _MaxCharPerPage=100;
///<summary>
///自动分页时的每页大约字符数(包含HTML标记)
///</summary>
[Property("MaxCharPerPage")]
public int MaxCharPerPage
{
get { return _MaxCharPerPage; }
set { _MaxCharPerPage = value; }
}
private string _Content;
///<summary>
///内容
///</summary>
[Property("Content",Length=9000)]
public string Content
{
get { return _Content; }
set { _Content = value; }
}
private string _Stars;
///<summary>
///状态
///</summary>
[Property("Stars")]
public string Stars
{
get { return _Stars; }
set { _Stars = value; }
}
private int _articleTabId;
/// <summary>
/// 文章所在页面
/// </summary>
[Property()]
public int ArticleTabId { get { return _articleTabId; } set { _articleTabId=value ;} }
private string _linkUrl;
/// <summary>
/// 外部链接URL
/// </summary>
[Property()]
public string LinkUrl
{
get { return _linkUrl; }
set { _linkUrl = value; }
}
private string _aritcleKey;
/// <summary>
/// 唯一Key
/// </summary>
[Property(Update= false ,NotNull=true )]
public string AritcleKey
{
get { return _aritcleKey; }
set { _aritcleKey = value; }
}
private DateTime _createTime;
/// <summary>
/// 添加时间
/// </summary>
[Property(Update=false)]
public DateTime CreateTime
{
get { return _createTime; }
set { _createTime = value; }
}
private DateTime _updateTime;
/// <summary>
/// 更新时间
/// </summary>
[Property()]
public DateTime UpdateTime
{
get { return _updateTime; }
set { _updateTime = value; }
}
//private IList<ArticleClass> _belongsClass=new List<ArticleClass >();
///// <summary>
///// 所属分类
///// </summary>
//[HasAndBelongsToMany(typeof( ArticleClass ), Lazy = true, BatchSize = 10,
// ColumnKey = "Article", ColumnRef = "ArticleClass"
// , Table = "ArticleRefClass"
// )]
//public IList<ArticleClass> BelongsClass
//{
// get { return _belongsClass; }
// set { _belongsClass = value; }
//}
private string _img;
/// <summary>
/// 新闻图片,图片新闻用
/// </summary>
[Property()]
public string Img
{
get { return _img; }
set { _img = value; }
}
private bool _isTop;
/// <summary>
/// 是否置顶
/// </summary>
public bool IsTop
{
get { return _isTop; }
set { _isTop = value; }
}
/// <summary>
/// 实际用于保存是否置顶顺序的字段
/// </summary>
[Property("IsTop")]
public byte TopSort
{
get { return (byte)(_isTop ? 1 : 0); }
set { _isTop = (value == 1); }
}
private int _hits;
/// <summary>
/// 点击数
/// </summary>
[Property()]
public int Hits
{
get { return _hits; }
set { _hits = value; }
}
/// <summary>
/// 文章链接
/// </summary>
public string ArticleUrl
{
get
{
if (string.IsNullOrEmpty(_linkUrl))
return Comm.Comm.NavigateURL(_articleTabId,"ctl=" ,"articleid=" + _ID.ToString());
else
return Comm.Comm.ResolveUrl(_linkUrl);
}
}
/// <summary>
/// 评论Key
/// </summary>
public string CommentKey
{
get
{
return _aritcleKey + "-" + _ID.ToString();
}
}
#region "文章分页"
public int GetPageCount()
{
if (_PaginationType == "0")
{
return 1;
}
if (_PaginationType == "1")
{
if (_MaxCharPerPage > 0)
{
return (int)Math.Ceiling( ((double )_Content.Length)/_MaxCharPerPage );
}
}
if (_PaginationType == "2")
{
string pattern = "<div style=\"page-break-after: always\"><span style=\"display: none\"> </span></div>";
Regex r = new Regex(pattern, RegexOptions.Multiline | RegexOptions.IgnoreCase);
return r.Matches(_Content).Count+1;
}
return 1;
}
public string GetContent(int pageno)
{
if (_PaginationType == "0")
{
return _Content;
}
if (_PaginationType == "1")
{
if (_MaxCharPerPage > 0)
{
if ((pageno + 1) * _MaxCharPerPage < _Content.Length)
{
return _Content.Substring(pageno * _MaxCharPerPage, _MaxCharPerPage);
}
else
{
return _Content.Substring(pageno * _MaxCharPerPage);
}
}
}
if (_PaginationType == "2")
{
string pattern = "<div style=\"page-break-after: always\"><span style=\"display: none\"> </span></div>";
Regex r = new Regex(pattern, RegexOptions.Multiline | RegexOptions.IgnoreCase);
MatchCollection mc = r.Matches(_Content);
if (mc.Count == 0) { return _Content; }
if (pageno <= mc.Count)
{
if (pageno == 0) { return _Content.Substring(0, mc[0].Index); }
if (pageno == mc.Count)
{
return
_Content.Substring(mc[pageno - 1].Index).Replace(pattern, "");
}
else
{
return
_Content.Substring(mc[pageno - 1].Index, mc[pageno].Index - mc[pageno - 1].Index).Replace(pattern, "");
}
}
}
return "";
}
#endregion
#region 增加点击数的JS
/// <summary>
/// 增加点击数的JS
/// </summary>
public string AddHitsScript
{
get
{
string url= Comm.Comm.ResolveUrl("~/DesktopModules/Article/SetHits.aspx?articleid=" + _ID.ToString());
return "<script src='"+url +"' type='text/javascript' ></script>";
}
}
#endregion
#region 获得点击数的JS
/// <summary>
/// 获取点击数的JS
/// </summary>
public string GetHitsScript
{
get
{
string url = Comm.Comm.ResolveUrl("~/DesktopModules/Article/GetHits.aspx?articleid=" + _ID.ToString());
return "<script src='" + url + "' type='text/javascript' ></script>";
}
}
#endregion
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -