This repository has been archived by the owner on Dec 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
EditReportSet.ascx.cs
452 lines (375 loc) · 12.1 KB
/
EditReportSet.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
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
using DotNetNuke.Services.Localization;
using System.Web.UI.WebControls;
using System.Collections;
using DotNetNuke.Common;
using DotNetNuke.Entities.Modules;
namespace DNNStuff.SQLViewPro
{
public partial class EditReportSet : PortalModuleBase
{
private const string STR_ReferringUrl = "EditReportSet_ReferringUrl";
protected DropDownList cboTheme;
protected Controls.ConnectionPickerControl cpConnection;
#region Web Form Designer Generated Code
//This call is required by the Web Form Designer.
[System.Diagnostics.DebuggerStepThrough()]private void InitializeComponent()
{
}
private void Page_Init(System.Object sender, System.EventArgs e)
{
//CODEGEN: This method call is required by the Web Form Designer
//Do not modify it using the code editor.
InitializeComponent();
}
#endregion
#region Page
// collection counts for use with move up/down binding
private int _ParameterCount;
private int _ReportCount;
private int _ReportSetId;
public int ReportSetId
{
get
{
return _ReportSetId;
}
set
{
_ReportSetId = value;
}
}
private void SaveReferringPage()
{
// save referring page
if (Request.UrlReferrer == null)
{
Session[STR_ReferringUrl] = Globals.NavigateURL();
}
else
{
// don't set if coming from a later page such as EditReport or EditParameter
if (!(Request.UrlReferrer.AbsoluteUri.ToString().Contains("EditReport/") || Request.UrlReferrer.AbsoluteUri.ToString().Contains("EditParameter/")))
{
Session[STR_ReferringUrl] = Globals.NavigateURL();
}
}
}
private void Page_Load(System.Object sender, System.EventArgs e)
{
DNNUtilities.InjectCSS(Page, ResolveUrl("Resources/Support/edit.css"));
Page.ClientScript.RegisterClientScriptInclude(GetType(), "yeti", ResolveUrl("resources/support/yetii-min.js"));
if (Request.QueryString["ReportSetId"] != null)
{
ReportSetId = int.Parse(Request.QueryString["ReportSetId"].ToString());
}
else
{
ReportSetId = -1;
}
if (!Page.IsPostBack)
{
BindSkinFolder(cboSkin);
LoadReportSet();
SaveReferringPage();
}
}
#endregion
#region Data ReportSet
private void LoadReportSet()
{
var objReportSetController = new ReportSetController();
var objReportSet = objReportSetController.GetReportSet(ReportSetId);
if (objReportSet == null)
{
// create new
txtName.Text = "New Report Set";
SaveReportSet();
Response.Redirect(NavigateReportSet(ReportSetId));
}
txtName.Text = objReportSet.ReportSetName;
var item = cboSkin.Items.FindByValue(objReportSet.ReportSetTheme);
if (item != null)
{
item.Selected = true;
}
else
{
cboSkin.Items[0].Selected = true;
}
cpConnection.ConnectionId = objReportSet.ReportSetConnectionId;
txtHeader.Text = objReportSet.ReportSetHeaderText;
txtFooter.Text = objReportSet.ReportSetFooterText;
chkDebug.Checked = objReportSet.ReportSetDebug;
txtRunCaption.Text = objReportSet.RunCaption;
txtBackCaption.Text = objReportSet.BackCaption;
txtParameterLayout.Text = objReportSet.ParameterLayout;
chkAlwaysShowParameters.Checked = objReportSet.AlwaysShowParameters;
ControlHelpers.InitDropDownByValue(ddlRenderMode, objReportSet.RenderMode);
chkAutoRun.Checked = objReportSet.AutoRun;
// report grid
BindReport();
// parameter grid
BindParameter();
}
private void SaveReportSet()
{
var objReportSetController = new ReportSetController();
var obj = new ReportSetConfig();
ReportSetId = objReportSetController.UpdateReportSet(ModuleId, ReportSetId, txtName.Text, cboSkin.SelectedItem.Value, System.Convert.ToInt32(cpConnection.ConnectionId), txtHeader.Text, txtFooter.Text, chkDebug.Checked, txtRunCaption.Text, txtBackCaption.Text, txtParameterLayout.Text, chkAlwaysShowParameters.Checked, ddlRenderMode.SelectedValue, chkAutoRun.Checked, Serialization.SerializeObject(obj, typeof(ReportSetConfig)));
}
private void BindSkinFolder(ListControl o)
{
var skinFolder = new System.IO.DirectoryInfo((string) (Server.MapPath(ResolveUrl("Skins"))));
o.Items.Clear();
o.Items.Add(new ListItem("None", "None"));
foreach (var folder in skinFolder.GetDirectories())
{
o.Items.Add(folder.Name);
}
}
#endregion
#region Data Report
// report
private void DeleteReport(int ReportId)
{
var objReportController = new ReportController();
objReportController.DeleteReport(ReportId);
}
private void MoveReport(int ReportId, int Increment)
{
var objReportController = new ReportController();
objReportController.UpdateReportOrder(ReportId, Increment);
}
private void CopyReport(int ReportId)
{
var objReportController = new ReportController();
var objReport = objReportController.GetReport(ReportId);
objReportController.UpdateReport(ReportSetId, -1, objReport.ReportTypeId, "Copy of " + objReport.ReportName, objReport.ReportTheme, objReport.ReportConnectionId, objReport.ReportHeaderText, objReport.ReportFooterText, objReport.ReportCommand, objReport.ReportConfig, -1, objReport.ReportDrilldownReportId, objReport.ReportDrilldownFieldname, objReport.ReportNoItemsText, objReport.ReportPageTitle, objReport.ReportCommandCacheTimeout, objReport.ReportMetaDescription, objReport.ReportCommandCacheScheme);
}
private void BindReport()
{
Localization.LocalizeDataGrid(ref dgReport, LocalResourceFile);
var objReportList = default(ArrayList);
var objReportSetController = new ReportSetController();
objReportList = objReportSetController.GetReportSetReport(ReportSetId);
// save Report count
_ReportCount = objReportList.Count;
// bind
dgReport.DataSource = objReportList;
dgReport.DataBind();
// commands
cmdAddReport.Visible = ReportSetId > -1;
}
#endregion
#region Data Parameter
private void DeleteParameter(int ParameterId)
{
var objParameterController = new ParameterController();
objParameterController.DeleteParameter(ParameterId);
}
private void MoveParameter(int ParameterId, int Increment)
{
var objParameterController = new ParameterController();
objParameterController.UpdateParameterOrder(ParameterId, Increment);
}
private void CopyParameter(int ParameterId)
{
var objParameterController = new ParameterController();
var objParameter = objParameterController.GetParameter(ParameterId);
var NewParameterId = 0;
NewParameterId = objParameterController.UpdateParameter(ReportSetId, -1, "Copy of " + objParameter.ParameterName, objParameter.ParameterCaption, objParameter.ParameterTypeId, objParameter.ParameterConfig, -1);
}
private void BindParameter()
{
Localization.LocalizeDataGrid(ref dgParameter, LocalResourceFile);
var objParameterList = default(ArrayList);
var objReportSetController = new ReportSetController();
objParameterList = objReportSetController.GetReportSetParameter(ReportSetId);
// save parameter count
_ParameterCount = objParameterList.Count;
// bind
dgParameter.DataSource = objParameterList;
dgParameter.DataBind();
// commands
cmdAddParameter.Visible = ReportSetId > -1;
}
#endregion
#region Navigation
protected void cmdUpdate_Click(System.Object sender, System.EventArgs e)
{
if (Page.IsValid)
{
SaveReportSet();
NavigateBack();
}
}
protected void cmdCancel_Click(System.Object sender, System.EventArgs e)
{
NavigateBack();
}
private void NavigateBack()
{
if (Session[STR_ReferringUrl] != null)
{
Response.Redirect(Session[STR_ReferringUrl].ToString());
}
}
private string NavigateReportSet(int ReportSetId)
{
return EditUrl("ReportSetId", ReportSetId.ToString(), "EditReportSet");
}
private string NavigateReport(int ReportSetId, int ReportId)
{
return EditUrl("ReportId", ReportId.ToString(), "EditReport", string.Format("ReportSetId={0}", ReportSetId));
}
private string NavigateParameter(int ReportSetId, int ParameterId)
{
return EditUrl("ParameterId", ParameterId.ToString(), "EditParameter", string.Format("ReportSetId={0}", ReportSetId));
}
#endregion
#region Report Grid
protected void cmdAddReport_Click(object sender, System.EventArgs e)
{
Response.Redirect(NavigateReport(ReportSetId, -1));
}
protected void dgReport_ItemCommand(object source, DataGridCommandEventArgs e)
{
var ReportId = int.Parse(dgReport.DataKeys[e.Item.ItemIndex].ToString());
switch (e.CommandName.ToLower())
{
case "edit":
Response.Redirect(NavigateReport(ReportSetId, ReportId));
break;
case "delete":
DeleteReport(ReportId);
BindReport();
break;
case "up":
MoveReport(ReportId, -1);
BindReport();
break;
case "down":
MoveReport(ReportId, 1);
BindReport();
break;
case "copy":
CopyReport(ReportId);
BindReport();
break;
}
}
protected void dgReport_ItemCreated(object sender, DataGridItemEventArgs e)
{
// process data rows only (skip the header, footer etc.)
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
// get a reference to the LinkButton of this row,
// and add the javascript confirmation
var lnkDelete = (LinkButton) (e.Item.FindControl("cmdDeleteReport"));
if (lnkDelete != null)
{
lnkDelete.Attributes.Add("onclick", "return confirm(\'Are you sure you want to delete this report?\');");
}
}
}
protected void dgReport_ItemDataBound(object sender, DataGridItemEventArgs e)
{
var ib = default(ImageButton);
if (e.Item.ItemType == ListItemType.Item | e.Item.ItemType == ListItemType.AlternatingItem)
{
if (e.Item.ItemIndex == 0)
{
ib = (ImageButton) (e.Item.FindControl("cmdMoveReportUp"));
if (ib != null)
{
ib.Visible = false;
}
}
else
{
if (e.Item.ItemIndex == _ReportCount - 1)
{
ib = (ImageButton) (e.Item.FindControl("cmdMoveReportDown"));
if (ib != null)
{
ib.Visible = false;
}
}
}
}
}
#endregion
#region Parameter Grid
protected void cmdAddParameter_Click(object sender, System.EventArgs e)
{
Response.Redirect(NavigateParameter(ReportSetId, -1));
}
protected void dgParameter_ItemCommand(object source, DataGridCommandEventArgs e)
{
var ParameterId = int.Parse(dgParameter.DataKeys[e.Item.ItemIndex].ToString());
switch (e.CommandName.ToLower())
{
case "edit":
Response.Redirect(NavigateParameter(ReportSetId, ParameterId));
break;
case "delete":
DeleteParameter(ParameterId);
BindParameter();
break;
case "up":
MoveParameter(ParameterId, -1);
BindParameter();
break;
case "down":
MoveParameter(ParameterId, 1);
BindParameter();
break;
case "copy":
CopyParameter(ParameterId);
BindParameter();
break;
}
}
protected void dgParameter_ItemCreated(object sender, DataGridItemEventArgs e)
{
// process data rows only (skip the header, footer etc.)
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
// get a reference to the LinkButton of this row,
// and add the javascript confirmation
var lnkDelete = (LinkButton) (e.Item.FindControl("cmdDeleteParameter"));
if (lnkDelete != null)
{
lnkDelete.Attributes.Add("onclick", "return confirm(\'Are you sure you want to delete this parameter?\');");
}
}
}
protected void dgParameter_ItemDataBound(object sender, DataGridItemEventArgs e)
{
var ib = default(ImageButton);
if (e.Item.ItemType == ListItemType.Item | e.Item.ItemType == ListItemType.AlternatingItem)
{
if (e.Item.ItemIndex == 0)
{
ib = (ImageButton) (e.Item.FindControl("cmdMoveParameterUp"));
if (ib != null)
{
ib.Visible = false;
}
}
else
{
if (e.Item.ItemIndex == _ParameterCount - 1)
{
ib = (ImageButton) (e.Item.FindControl("cmdMoveParameterDown"));
if (ib != null)
{
ib.Visible = false;
}
}
}
}
}
#endregion
}
}