forked from siteserver/cms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPageTrackerContentRank.cs
204 lines (180 loc) · 6.72 KB
/
PageTrackerContentRank.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Web.UI.WebControls;
using BaiRong.Core;
using BaiRong.Core.Model.Enumerations;
using SiteServer.BackgroundPages.Core;
using SiteServer.CMS.Core;
namespace SiteServer.BackgroundPages.Plugins
{
public class PageTrackerContentRank : BasePageCms
{
public DataGrid dgContents;
public LinkButton pageFirst;
public LinkButton pageLast;
public LinkButton pageNext;
public LinkButton pagePrevious;
public Label currentPage;
private List<KeyValuePair<int, int>> _accessNumPairList = new List<KeyValuePair<int, int>>();
private Hashtable todayAccessNumHashtable = new Hashtable();
private int totalAccessNum = 0;
public double GetAccessNumBarWidth(int accessNum)
{
double width = 0;
if (totalAccessNum > 0)
{
width = Convert.ToDouble(accessNum) / Convert.ToDouble(totalAccessNum);
width = Math.Round(width, 2) * 100;
}
return width;
}
public int GetTodayAccessNum(int pageContentID)
{
var todayAccessNum = 0;
if (todayAccessNumHashtable[pageContentID] != null)
{
todayAccessNum = Convert.ToInt32(todayAccessNumHashtable[pageContentID]);
}
return todayAccessNum;
}
public void Page_Load(object sender, EventArgs e)
{
if (IsForbidden) return;
PageUtils.CheckRequestParameter("PublishmentSystemID");
_accessNumPairList = DataProvider.TrackingDao.GetContentAccessNumPairList(PublishmentSystemId);
todayAccessNumHashtable = DataProvider.TrackingDao.GetTodayContentAccessNumHashtable(PublishmentSystemId);
foreach (var pair in _accessNumPairList)
{
var accessNum = pair.Value;
totalAccessNum += accessNum;
}
if (!IsPostBack)
{
BindGrid();
}
}
public void MyDataGrid_Page(object sender, DataGridPageChangedEventArgs e)
{
dgContents.CurrentPageIndex = e.NewPageIndex;
BindGrid();
}
public void BindGrid()
{
var arraylist = new ArrayList();
foreach (var pair in _accessNumPairList)
{
var pageContentId = pair.Key;
var accessNum = pair.Value;
var pageContentIdWithAccessNum = new PageContentIDWithAccessNum(pageContentId, accessNum);
arraylist.Add(pageContentIdWithAccessNum);
}
dgContents.DataSource = arraylist;
dgContents.ItemDataBound += MyDataGrid_ItemDataBound;
dgContents.PageSize = PublishmentSystemInfo.Additional.PageSize;
dgContents.DataBind();
if (dgContents.CurrentPageIndex > 0)
{
pageFirst.Enabled = true;
pagePrevious.Enabled = true;
}
else
{
pageFirst.Enabled = false;
pagePrevious.Enabled = false;
}
if (dgContents.CurrentPageIndex + 1 == dgContents.PageCount)
{
pageLast.Enabled = false;
pageNext.Enabled = false;
}
else
{
pageLast.Enabled = true;
pageNext.Enabled = true;
}
currentPage.Text = $"{dgContents.CurrentPageIndex + 1}/{dgContents.PageCount}";
}
void MyDataGrid_ItemDataBound(object sender, DataGridItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
var ltlTitle = (Literal)e.Item.FindControl("ltlTitle");
var pageContentIdWithAccessNum = e.Item.DataItem as PageContentIDWithAccessNum;
if (pageContentIdWithAccessNum != null && pageContentIdWithAccessNum.PageContentID > 0)
{
var contentInfo = DataProvider.ContentDao.GetContentInfo(ETableStyle.BackgroundContent, PublishmentSystemInfo.AuxiliaryTableForContent, pageContentIdWithAccessNum.PageContentID);
if (contentInfo != null && !string.IsNullOrEmpty(contentInfo.Title))
{
ltlTitle.Text = WebUtils.GetContentTitle(PublishmentSystemInfo, contentInfo,
PageUtils.GetPluginsUrl(nameof(PageTrackerContentRank), new NameValueCollection
{
{"PublishmentSystemID", PublishmentSystemId.ToString()}
}));
}
else
{
e.Item.Visible = false;
}
}
}
}
protected void NavigationButtonClick(object sender, EventArgs e)
{
var button = (LinkButton)sender;
var direction = button.CommandName;
switch (direction.ToUpper())
{
case "FIRST":
dgContents.CurrentPageIndex = 0;
break;
case "PREVIOUS":
dgContents.CurrentPageIndex =
Math.Max(dgContents.CurrentPageIndex - 1, 0);
break;
case "NEXT":
dgContents.CurrentPageIndex =
Math.Min(dgContents.CurrentPageIndex + 1,
dgContents.PageCount - 1);
break;
case "LAST":
dgContents.CurrentPageIndex = dgContents.PageCount - 1;
break;
}
BindGrid();
}
public class PageContentIDWithAccessNum
{
protected int m_intPageContentID;
protected int m_intAccessNum;
public PageContentIDWithAccessNum(int pageContentID, int accessNum)
{
m_intPageContentID = pageContentID;
m_intAccessNum = accessNum;
}
public int PageContentID
{
get
{
return m_intPageContentID;
}
set
{
m_intPageContentID = value;
}
}
public int AccessNum
{
get
{
return m_intAccessNum;
}
set
{
m_intAccessNum = value;
}
}
}
}
}