-
Notifications
You must be signed in to change notification settings - Fork 39
/
EventRpt.ascx.cs
389 lines (346 loc) · 15 KB
/
EventRpt.ascx.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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
#region Copyright
//
// DotNetNuke® - http://www.dotnetnuke.com
// Copyright (c) 2002-2018
// by DotNetNuke Corporation
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
// documentation files (the "Software"), to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
// to permit persons to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or substantial portions
// of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
// TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
// CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#endregion
using System;
using System.Collections;
using System.Data;
using System.Diagnostics;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Components;
using DotNetNuke.Services.Exceptions;
using DotNetNuke.Services.Localization;
namespace DotNetNuke.Modules.Events
{
public partial class EventRpt : EventBase
{
#region Event Handlers
private ArrayList _selectedEvents;
private void Page_Load(object sender, EventArgs e)
{
try
{
SetupViewControls(EventIcons, EventIcons2, SelectCategory, SelectLocation);
if (Page.IsPostBack == false)
{
BindDataGrid();
}
}
catch (Exception exc) //Module failed to load
{
Exceptions.ProcessModuleLoadException(this, exc);
}
}
#endregion
#region Helper Functions
private int _rptItemCount;
public int PageNumber
{
get
{
if (!ReferenceEquals(ViewState["PageNumber"], null))
{
return Convert.ToInt32(ViewState["PageNumber"]);
}
return 0;
}
set { ViewState["PageNumber"] = value; }
}
private void BindDataGrid()
{
//Default sort from settings
var sortDirection = default(SortDirection);
if (Settings.EventsListSortDirection == "ASC")
{
sortDirection = SortDirection.Ascending;
}
else
{
sortDirection = SortDirection.Descending;
}
var sortExpression = (EventInfo.SortFilter) GetListSortExpression(Settings.EventsListSortColumn);
// Get Events/Sub-Calendar Events
_selectedEvents = Get_ListView_Events(SelectCategory.SelectedCategory,
SelectLocation.SelectedLocation);
EventInfo.SortExpression = sortExpression;
EventInfo.SortDirection = sortDirection;
_selectedEvents.Sort();
var tcc = new TokenReplaceControllerClass(ModuleId, LocalResourceFile);
var eventTable = new DataTable("Events");
eventTable.Columns.Add("EventText", Type.GetType("System.String"));
eventTable.Columns.Add("Tooltip", Type.GetType("System.String"));
if (Settings.Eventtooltiplist)
{
toolTipManager.TargetControls.Clear();
}
var dgRow = default(DataRow);
var clientIdCount = 1;
foreach (EventInfo objEvent in _selectedEvents)
{
dgRow = eventTable.NewRow();
var blAddSubModuleName = false;
if (objEvent.ModuleID != ModuleId && objEvent.ModuleTitle != null &&
Settings.Addsubmodulename)
{
blAddSubModuleName = true;
}
var isEvtEditor = IsEventEditor(objEvent, false);
var tmpText = Settings.Templates.txtListRptBody;
var tmpTooltip = "";
if (Settings.Eventtooltiplist)
{
tmpTooltip = ToolTipCreate(objEvent, Settings.Templates.txtTooltipTemplateTitle,
Settings.Templates.txtTooltipTemplateBody, isEvtEditor);
dgRow["Tooltip"] = tmpTooltip;
}
if (!Settings.ListViewTable)
{
var tooltip = HttpUtility.HtmlEncode(tmpTooltip);
tmpText = AddTooltip(clientIdCount, tooltip, tmpText);
clientIdCount++;
}
dgRow["EventText"] = tcc.TokenReplaceEvent(objEvent, tmpText, null, blAddSubModuleName, isEvtEditor);
eventTable.Rows.Add(dgRow);
}
var pgEvents = new PagedDataSource();
var dvEvents = new DataView(eventTable);
pgEvents.DataSource = dvEvents;
pgEvents.AllowPaging = true;
pgEvents.PageSize = Settings.RptColumns * Settings.RptRows;
pgEvents.CurrentPageIndex = PageNumber;
if (pgEvents.PageCount > 1)
{
rptTRPager.Visible = true;
var pages = new ArrayList();
for (var i = 0; i <= pgEvents.PageCount - 1; i++)
{
pages.Add(i + 1);
}
rptPager.DataSource = pages;
rptPager.DataBind();
}
else
{
rptTRPager.Visible = false;
}
if (pgEvents.CurrentPageIndex + 1 < pgEvents.PageCount)
{
_rptItemCount = pgEvents.PageSize;
}
else
{
_rptItemCount = eventTable.Rows.Count - pgEvents.CurrentPageIndex * pgEvents.PageSize;
}
rptEvents.DataSource = pgEvents;
rptEvents.DataBind();
}
#endregion
#region Control Events
protected void SelectCategory_CategorySelected(object sender, CommandEventArgs e)
{
//Store the other selection(s) too.
SelectLocation.StoreLocations();
BindDataGrid();
}
protected void SelectLocation_LocationSelected(object sender, CommandEventArgs e)
{
//Store the other selection(s) too.
SelectCategory.StoreCategories();
BindDataGrid();
}
private int _rptCurrentItemCount;
private bool _rptAlternate = true;
protected void rptEvents_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
var rptColumns = Settings.RptColumns;
var columnWidth = "\"" + Convert.ToInt32((double) 100 / Settings.RptColumns) + "%\"";
switch (e.Item.ItemType)
{
case ListItemType.Header:
const string rptHeaderTable = "<table class=\"RptRepeater\">";
var rptHeaderStart =
"<tr id=\"rptTRHeader\" ><th id=\"rptTDHeader\" class=\"RptHeader\" colspan=\"" +
Settings.RptColumns + "\">";
const string rptHeaderEnd = "</th></tr>";
var rptHeaderBody =
Settings.Templates.txtListRptHeader.Replace(
"[event:repeaterheadertext]",
Localization.GetString("TokenListRptHeader", LocalResourceFile));
rptHeaderBody = rptHeaderBody.Replace("[event:repeaterzeroeventstext]",
Localization.GetString(
"TokenListRptHeaderZeroEvents", LocalResourceFile));
var tcc = new TokenReplaceControllerClass(ModuleId, LocalResourceFile);
if (_rptItemCount == 0)
{
rptHeaderBody = tcc.TokenOneParameter(rptHeaderBody, "IFZEROEVENTS", true);
}
else
{
rptHeaderBody = tcc.TokenOneParameter(rptHeaderBody, "IFZEROEVENTS", false);
}
var rptHeader = (Literal) e.Item.FindControl("rptHeader");
if (Settings.ListViewTable)
{
rptHeader.Text = rptHeaderTable;
if (!string.IsNullOrEmpty(rptHeaderBody))
{
rptHeader.Text = rptHeader.Text + rptHeaderStart + rptHeaderBody + rptHeaderEnd;
}
}
else
{
rptHeader.Text = rptHeaderBody;
}
break;
case ListItemType.Footer:
var rptFooterStart =
"<tr id=\"rptTRFooter\"><td id=\"rptTDFooter\" class=\"RptFooter\" colspan=\"" +
Settings.RptColumns + "\">";
const string rptFooterEnd = "</td></tr>";
const string rptFooterTable = "</table>";
var rptFooterBody =
Settings.Templates.txtListRptFooter.Replace(
"[event:repeaterfootertext]",
Localization.GetString("TokenListRptFooter", LocalResourceFile));
var rptFooter = (Literal) e.Item.FindControl("rptFooter");
if (Settings.ListViewTable)
{
if (!string.IsNullOrEmpty(rptFooterBody))
{
rptFooter.Text = rptFooterStart + rptFooterBody + rptFooterEnd;
}
rptFooter.Text = rptFooter.Text + rptFooterTable;
}
else
{
rptFooter.Text = rptFooterBody;
}
break;
default:
var rptBody = (Literal) e.Item.FindControl("rptBody");
var rptRowBody = Convert.ToString(DataBinder.Eval(e.Item.DataItem, "EventText"));
_rptCurrentItemCount++;
if (Settings.ListViewTable)
{
var rptBodyStart = "<td [event:repeatertooltip] width=" + columnWidth + ">";
const string rptBodyEnd = "</td>";
var rptRowStart = "";
if ((_rptCurrentItemCount - 1) % rptColumns == 0)
{
_rptAlternate = !_rptAlternate;
var rptCellClass = "RptNormal";
if (_rptAlternate)
{
rptCellClass = "RptAlternate";
}
rptRowStart = "<tr class=\"" + rptCellClass + "\" >" + rptBodyStart;
}
else
{
rptRowStart = rptBodyStart;
}
var rptRowEnd = "";
if (_rptCurrentItemCount % rptColumns == 0)
{
rptRowEnd = rptBodyEnd + "</tr>";
}
else if (_rptItemCount == _rptCurrentItemCount)
{
// ReSharper disable RedundantAssignment
for (var i = 1; i <= rptColumns - _rptCurrentItemCount % rptColumns; i++)
{
// ReSharper restore RedundantAssignment
rptRowEnd += "<td width=" + columnWidth + " ></td>";
}
rptRowEnd += "</tr>";
}
else
{
rptRowEnd = rptBodyEnd;
}
var tooltip = "";
if (Settings.Eventtooltiplist)
{
tooltip = HttpUtility.HtmlEncode(
Convert.ToString(DataBinder.Eval(e.Item.DataItem, "Tooltip")));
}
rptBody.Text = AddTooltip(_rptCurrentItemCount, tooltip, rptRowStart) + rptRowBody +
rptRowEnd;
}
else
{
rptBody.Text = rptRowBody;
}
break;
}
}
private string AddTooltip(int itemCount, string toolTip, string body)
{
var fullTooltip = "";
if (Settings.Eventtooltiplist)
{
var ttClientId = "ctlEvents_Mod_" + ModuleId + "_RptRowBody_" + itemCount;
fullTooltip = "ID=\"" + ttClientId + "\" title=\"" + toolTip + "\"";
toolTipManager.TargetControls.Add(ClientID, true);
}
return body.Replace("[event:repeatertooltip]", fullTooltip);
}
protected void rptPages_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
switch (e.Item.ItemType)
{
case ListItemType.Header:
break;
case ListItemType.Footer:
break;
default:
var lnkPage = (LinkButton) e.Item.FindControl("cmdPage");
if (int.Parse(lnkPage.CommandArgument) == PageNumber + 1)
{
lnkPage.Style.Add("cursor", "text");
lnkPage.Style.Add("text-decoration", "none");
lnkPage.Attributes.Add("onclick", "javascript:return false;");
lnkPage.CssClass = "RptPagerCurrentPage";
}
break;
}
}
protected void rptPages_ItemCommand(object source, RepeaterCommandEventArgs e)
{
PageNumber = Convert.ToInt32(e.CommandArgument) - 1;
BindDataGrid();
}
#endregion
#region Web Form Designer Generated Code
//This call is required by the Web Form Designer.
[DebuggerStepThrough]
private void InitializeComponent()
{ }
private void Page_Init(object sender, EventArgs e)
{
//CODEGEN: This method call is required by the Web Form Designer
//Do not modify it using the code editor.
InitializeComponent();
}
#endregion
}
}