/
ViewAdminPayment.ascx.cs
447 lines (381 loc) · 19.3 KB
/
ViewAdminPayment.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
//
// DotNetNuke® - http://www.dotnetnuke.com
// Copyright (c) 2002-2009
// 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.
//
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Resources;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using Bitboxx.DNNModules.BBStore.Providers.Payment;
using DotNetNuke.Common;
using DotNetNuke.Common.Utilities;
using DotNetNuke.Entities.Modules;
using DotNetNuke.Entities.Modules.Actions;
using DotNetNuke.Security.Roles;
using DotNetNuke.Services.Exceptions;
using DotNetNuke.Services.Localization;
using DotNetNuke.UI.Skins.Controls;
using DotNetNuke.UI.UserControls;
namespace Bitboxx.DNNModules.BBStore
{
/// -----------------------------------------------------------------------------
/// <summary>
/// The ViewBBStore class displays the content
/// </summary>
/// <remarks>
/// </remarks>
/// <history>
/// </history>
/// -----------------------------------------------------------------------------
partial class ViewAdminPayment : PortalModuleBase
{
#region Private Members
private const string Currency = "EUR";
private BBStoreController _controller;
#endregion
#region Public Properties
public BBStoreController Controller
{
get
{
if (_controller == null)
_controller = new BBStoreController();
return _controller;
}
}
protected string CurrentLanguage
{
get { return System.Threading.Thread.CurrentThread.CurrentCulture.Name; }
}
protected string DefaultLanguage
{
get { return this.PortalSettings.DefaultLanguage; }
}
#endregion
#region Event Handlers
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
string FileName = System.IO.Path.GetFileNameWithoutExtension(this.AppRelativeVirtualPath);
if (this.ID != null)
//this will fix it when its placed as a ChildUserControl
this.LocalResourceFile = this.LocalResourceFile.Replace(this.ID, FileName);
else
// this will fix it when its dynamically loaded using LoadControl method
this.LocalResourceFile = this.LocalResourceFile + FileName + ".ascx.resx";
}
protected void Page_Load(object sender, System.EventArgs e)
{
try
{
ShowPaymentProviders();
}
catch (Exception exc)
{
//Module failed to load
Exceptions.ProcessModuleLoadException(this, exc);
}
}
protected void cmdUpdate_Click(object sender, EventArgs e)
{
UpdatePaymentProvider();
Response.Redirect(Globals.NavigateURL(), true);
}
protected void cmdCancel_Click(object sender, EventArgs e)
{
Response.Redirect(Globals.NavigateURL(), true);
}
#endregion
#region Helper Methods
private void ShowPaymentProviders()
{
// Payment Providers
List<PaymentProviderInfo> lst = Controller.GetPaymentProviders(CurrentLanguage);
if (lst.Count == 0)
lst = Controller.GetPaymentProviders(DefaultLanguage);
if (lst.Count > 0)
{
// Lets populate thbe Usergroups into Collection
RoleController RoleController = new RoleController();
ArrayList colArrayList = RoleController.GetPortalRoles(PortalId);
// Create a ListItemCollection to hold the Roles
ListItemCollection colRoles = new ListItemCollection();
// Add all defined Roles to the List
foreach (RoleInfo Role in colArrayList)
{
ListItem RoleListItem = new ListItem();
RoleListItem.Text = Role.RoleName;
RoleListItem.Value = Role.RoleID.ToString();
colRoles.Add(RoleListItem);
}
ListItem SelectRoleListItem = new ListItem();
SelectRoleListItem.Text = Localization.GetString("SelectRole.Text", this.LocalResourceFile);
SelectRoleListItem.Value = "-1";
colRoles.Insert(0, SelectRoleListItem);
// And now we need the Payment Provider for this subscriber (Portal)
List<SubscriberPaymentProviderInfo> lstSub = Controller.GetSubscriberPaymentProviders(PortalId, 0);
Table myTable = new Table();
myTable.Attributes.Add("class","dnnGrid");
myTable.ID = "tblPaymentProvider";
// First the header row
TableHeaderRow tr = new TableHeaderRow();
TableHeaderCell th = new TableHeaderCell();
th.Attributes.Add("class","dnnGridHeader");
LabelControl dnnLbl = LoadControl("~/controls/LabelControl.ascx") as LabelControl;
dnnLbl.HelpText = Localization.GetString("ppEnabled.Help", this.LocalResourceFile);
dnnLbl.Text = Localization.GetString("ppEnabled.Header", this.LocalResourceFile);
th.Controls.Add(dnnLbl);
tr.Controls.Add(th);
th = new TableHeaderCell();
th.Attributes.Add("class", "dnnGridHeader");
dnnLbl = LoadControl("~/controls/LabelControl.ascx") as LabelControl;
dnnLbl.Text = Localization.GetString("Vieworder.Header", this.LocalResourceFile);
dnnLbl.HelpText = Localization.GetString("Vieworder.Help", this.LocalResourceFile);
th.Controls.Add(dnnLbl);
tr.Controls.Add(th);
th = new TableHeaderCell();
th.Attributes.Add("class", "dnnGridHeader");
dnnLbl = LoadControl("~/controls/LabelControl.ascx") as LabelControl;
dnnLbl.Text = Localization.GetString("Paymentprovider.Header", this.LocalResourceFile);
dnnLbl.HelpText = Localization.GetString("Paymentprovider.Help", this.LocalResourceFile);
th.Controls.Add(dnnLbl);
tr.Controls.Add(th);
th = new TableHeaderCell();
th.Attributes.Add("class", "dnnGridHeader");
dnnLbl = LoadControl("~/controls/LabelControl.ascx") as LabelControl;
dnnLbl.Text = Localization.GetString("Price.Header", this.LocalResourceFile);
dnnLbl.HelpText = Localization.GetString("Price.Help", this.LocalResourceFile);
th.Controls.Add(dnnLbl);
tr.Controls.Add(th);
th = new TableHeaderCell();
th.Attributes.Add("class", "dnnGridHeader");
dnnLbl = LoadControl("~/controls/LabelControl.ascx") as LabelControl;
dnnLbl.Text = Localization.GetString("Tax.Header", this.LocalResourceFile);
dnnLbl.HelpText = Localization.GetString("Tax.Help", this.LocalResourceFile);
th.Controls.Add(dnnLbl);
tr.Controls.Add(th);
th = new TableHeaderCell();
th.Attributes.Add("class", "dnnGridHeader");
dnnLbl = LoadControl("~/controls/LabelControl.ascx") as LabelControl;
dnnLbl.Text = Localization.GetString("Userrole.Header", this.LocalResourceFile);
dnnLbl.HelpText = Localization.GetString("Userrole.Help", this.LocalResourceFile);
th.Controls.Add(dnnLbl);
tr.Controls.Add(th);
myTable.Controls.Add(tr);
// and next the Provider Rows
TableRow myRow;
TableCell tblCell;
int i = 0;
foreach (PaymentProviderInfo pp in lst)
{
// Skip if no Control defined
if (pp.ProviderControl.Trim() == String.Empty)
continue;
i++;
//Is this Provider in the List for the Subscriber (Portal) ?
SubscriberPaymentProviderInfo Sub = lstSub.Find(sub => sub.PaymentProviderId == pp.PaymentProviderId);
bool isChecked = (Sub != null && Sub.IsEnabled);
string itemStyle = (i%2 == 1 ? "dnnGridItem" : "dnnGridAltItem");
myRow = new TableRow();
// The Checkbox cell (first Column)
tblCell = new TableCell();
tblCell.Attributes.Add("class",itemStyle);
CheckBox chk = new CheckBox();
chk.ID = "chkEnabled" + pp.PaymentProviderId.ToString();
chk.EnableViewState = true;
chk.Checked = isChecked;
tblCell.Controls.Add(chk);
myRow.Controls.Add(tblCell);
// The Vieworder cell
tblCell = new TableCell();
tblCell.Attributes.Add("class", itemStyle);
TextBox txt = new TextBox();
txt.ID = "txtViewOrder" + pp.PaymentProviderId.ToString();
txt.EnableViewState = true;
txt.Columns = 2;
if (Sub != null)
txt.Text = Sub.ViewOrder.ToString();
else
txt.Text = "0";
tblCell.Controls.Add(txt);
myRow.Controls.Add(tblCell);
// The PaymentProvider-Cell
tblCell = new TableCell();
tblCell.Attributes.Add("class", itemStyle);
PaymentProviderBase ctrl = this.LoadControl(@"~\DesktopModules\BBStore\Providers\Payment\" + pp.ProviderControl.Trim() + ".ascx") as PaymentProviderBase;
ctrl.DisplayMode = ViewMode.Edit;
ctrl.Title = pp.ProviderName;
ctrl.EnableViewState = true;
if (Sub != null)
{
ctrl.Properties = Sub.PaymentProviderProperties;
ctrl.Cost = Sub.Cost;
}
ctrl.ID = "pp" + pp.PaymentProviderId.ToString();
tblCell.Controls.Add(ctrl);
myRow.Controls.Add(tblCell);
// We need to create the taxpercent control first (needed by TaxControl)
TextBox txtTaxPercent = new TextBox();
txtTaxPercent.ID = "txtTaxPercent" + pp.PaymentProviderId.ToString();
txtTaxPercent.EnableViewState = true;
txtTaxPercent.Columns = 6;
if (Sub != null)
txtTaxPercent.Text = String.Format("{0:f1}", Sub.TaxPercent);
else
txtTaxPercent.Text = String.Format("{0:f1}", 0.00m);
// The Price cell
tblCell = new TableCell();
tblCell.Attributes.Add("class", itemStyle);
Label lbl = new Label();
lbl.Text = LocalizeString("lblCost.Text")+ ": ";
tblCell.Controls.Add(lbl);
TaxControl txtPrice = LoadControl("Controls/TaxControl.ascx") as TaxControl;
txtPrice.ID = "txtPrice" + pp.PaymentProviderId.ToString();
txtPrice.EnableViewState = true;
txtPrice.Orientation = "verticalhorizontal";
txtPrice.Mode = "gross";
txtPrice.PercentControl = txtTaxPercent;
if (Sub != null)
txtPrice.Value = Sub.Cost;
else
txtPrice.Value = 0.00m;
tblCell.Controls.Add(txtPrice);
tblCell.Controls.Add(new HtmlGenericControl("hr"));
lbl = new Label();
lbl.Text = LocalizeString("lblCostPercent.Text") + ": ";
tblCell.Controls.Add(lbl);
TextBox txtCostPercent = new TextBox();
txtCostPercent.ID = "txtCostPercent" + pp.PaymentProviderId.ToString();
txtCostPercent.EnableViewState = true;
txtCostPercent.Columns = 6;
if (Sub != null)
txtCostPercent.Text = String.Format("{0:f1}", Sub.CostPercent);
else
txtCostPercent.Text = String.Format("{0:f1}", 0.0m);
tblCell.Controls.Add(txtCostPercent);
myRow.Controls.Add(tblCell);
// The Tax cell
tblCell = new TableCell();
tblCell.Attributes.Add("class", itemStyle);
tblCell.Controls.Add(txtTaxPercent);
myRow.Controls.Add(tblCell);
// The RoleDropdown Column
tblCell = new TableCell();
tblCell.Attributes.Add("class", itemStyle);
DropDownList ddl = new DropDownList();
ddl.ID = "ddlUserRole" + pp.PaymentProviderId.ToString();
ddl.EnableViewState = true;
ddl.DataSource = colRoles;
ddl.DataBind();
if (Sub != null)
ddl.SelectedValue = Sub.Role.ToString();
tblCell.Controls.Add(ddl);
myRow.Controls.Add(tblCell);
myTable.Controls.Add(myRow);
}
phPayment.Controls.Add(myTable);
}
else
{
string message = Localization.GetString("NoPaymentprovider.Message", this.LocalResourceFile);
DotNetNuke.UI.Skins.Skin.AddModuleMessage(this, message, ModuleMessage.ModuleMessageType.YellowWarning);
}
}
private void UpdatePaymentProvider()
{
List<SubscriberPaymentProviderInfo> lstSub = Controller.GetSubscriberPaymentProviders(PortalId, 0);
List<PaymentProviderInfo> lst = Controller.GetPaymentProviders(CurrentLanguage);
if (lst.Count == 0)
lst = Controller.GetPaymentProviders(DefaultLanguage);
if (lst.Count > 0)
{
foreach (PaymentProviderInfo pp in lst)
{
Boolean isChecked = false;
string paymentProviderProperties = "";
decimal cost = 0.00m;
decimal costPercent = 0.0m;
decimal taxPercent = 0.00m;
int viewOrder = 0;
string role = "";
//Is this Provider in the List for the Subscriber (Portal) ?
SubscriberPaymentProviderInfo Sub = lstSub.Find(sub => sub.PaymentProviderId == pp.PaymentProviderId);
CheckBox chk = Globals.FindControlRecursiveDown(phPayment, "chkEnabled" + pp.PaymentProviderId.ToString()) as CheckBox;
if (chk != null)
isChecked = chk.Checked;
TextBox txt = Globals.FindControlRecursiveDown(phPayment, "txtVieworder" + pp.PaymentProviderId.ToString()) as TextBox;
if (txt != null)
Int32.TryParse(txt.Text, out viewOrder);
PaymentProviderBase ppb = Globals.FindControlRecursiveDown(phPayment, "pp" + pp.PaymentProviderId.ToString()) as PaymentProviderBase;
if (ppb != null)
{
paymentProviderProperties = ppb.Properties;
}
TaxControl tax = Globals.FindControlRecursiveDown(phPayment, "txtPrice" + pp.PaymentProviderId.ToString()) as TaxControl;
if (tax != null)
cost = tax.Value;
txt = Globals.FindControlRecursiveDown(phPayment, "txtCostPercent" + pp.PaymentProviderId.ToString()) as TextBox;
if (txt != null)
decimal.TryParse(txt.Text, out costPercent);
txt = Globals.FindControlRecursiveDown(phPayment, "txtTaxPercent" + pp.PaymentProviderId.ToString()) as TextBox;
if (txt != null)
decimal.TryParse(txt.Text, out taxPercent);
DropDownList ddl = Globals.FindControlRecursiveDown(phPayment, "ddlUserRole" + pp.PaymentProviderId.ToString()) as DropDownList;
if (ddl != null && ddl.SelectedIndex > 0)
{
role = ddl.SelectedValue;
}
if (Sub == null)
{
Sub = new SubscriberPaymentProviderInfo();
Sub.PaymentProviderId = pp.PaymentProviderId;
Sub.PortalId = PortalId;
Sub.Cost = cost;
Sub.CostPercent = costPercent;
Sub.SubscriberId = 0;
Sub.ViewOrder = viewOrder;
Sub.IsEnabled = isChecked;
Sub.Role = role;
Sub.PaymentProviderProperties = paymentProviderProperties;
Sub.TaxPercent = taxPercent;
Controller.NewSubscriberPaymentProvider(Sub);
}
else
{
Sub.PaymentProviderId = pp.PaymentProviderId;
Sub.PortalId = PortalId;
Sub.Cost = cost;
Sub.CostPercent = costPercent;
Sub.SubscriberId = 0;
Sub.ViewOrder = viewOrder;
Sub.IsEnabled = isChecked;
Sub.Role = role;
Sub.PaymentProviderProperties = paymentProviderProperties;
Sub.TaxPercent = taxPercent;
Controller.UpdateSubscriberPaymentProvider(Sub);
}
}
}
}
#endregion
}
}