-
Notifications
You must be signed in to change notification settings - Fork 10
/
EditVendors.ascx.cs
417 lines (384 loc) · 17.8 KB
/
EditVendors.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
#region Copyright
//
// DotNetNuke® - http://www.dotnetnuke.com
// Copyright (c) 2002-2014
// 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
#region Usings
using System;
using System.Collections;
using Dnn.Modules.Vendors.Components;
using DotNetNuke.Common.Utilities;
using DotNetNuke.Entities.Modules;
using DotNetNuke.Entities.Tabs;
using DotNetNuke.Services.Exceptions;
using DotNetNuke.Services.Localization;
using DotNetNuke.Services.Mail;
using DotNetNuke.UI;
using DotNetNuke.UI.Skins.Controls;
using Globals = DotNetNuke.Common.Globals;
using DotNetNuke.Framework.JavaScriptLibraries;
#endregion
namespace Dnn.Modules.Vendors
{
/// -----------------------------------------------------------------------------
/// <summary>
/// The EditVendors PortalModuleBase is used to add/edit a Vendor
/// </summary>
/// <remarks>
/// </remarks>
/// <history>
/// [cnurse] 9/17/2004 Updated to reflect design changes for Help, 508 support
/// and localisation
/// </history>
/// -----------------------------------------------------------------------------
public partial class EditVendors : PortalModuleBase
{
public int VendorID = -1;
protected DotNetNuke.Web.UI.WebControls.DnnUrlControl ctlLogo;
protected DotNetNuke.UI.UserControls.Address addresssVendor;
protected DotNetNuke.UI.UserControls.ModuleAuditControl ctlAudit;
#region Private Methods
/// <summary>
/// Return url redirects to the previous page, with or without filter info
/// </summary>
/// <param name="filter"></param>
/// <history>
/// [erikvb] 10/18/2007
/// </history>
private void ReturnUrl(string filter)
{
Response.Redirect(string.IsNullOrEmpty(filter.Trim()) ? Globals.NavigateURL() : Globals.NavigateURL(TabId, Null.NullString, "filter=" + filter), true);
}
/// -----------------------------------------------------------------------------
/// <summary>
/// AddModuleMessage adds a module message
/// </summary>
/// <param name="message">The message</param>
/// <param name="type">The type of message</param>
/// <history>
/// [cnurse] 08/24/2006
/// </history>
/// -----------------------------------------------------------------------------
private void AddModuleMessage(string message, ModuleMessage.ModuleMessageType type)
{
DotNetNuke.UI.Skins.Skin.AddModuleMessage(this, Localization.GetString(message, LocalResourceFile), type);
}
#endregion
#region Event Handlers
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
JavaScript.RequestRegistration(CommonJs.DnnPlugins);
}
/// -----------------------------------------------------------------------------
/// <summary>
/// Page_Load runs when the control is loaded
/// </summary>
/// <remarks>
/// </remarks>
/// <history>
/// [cnurse] 9/17/2004 Updated to reflect design changes for Help, 508 support
/// and localisation
/// </history>
/// -----------------------------------------------------------------------------
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
cmdCancel.Click += OnCancelClick;
cmdDelete.Click += OnDeleteClick;
cmdUpdate.Click += OnUpdateClick;
try
{
var blnBanner = false;
var blnSignup = false;
if ((Request.QueryString["VendorID"] != null))
{
VendorID = Int32.Parse(Request.QueryString["VendorID"]);
}
if (Request.QueryString["ctl"] != null && VendorID == -1)
{
blnSignup = true;
}
if (Request.QueryString["banner"] != null)
{
blnBanner = true;
}
if (Page.IsPostBack == false)
{
ctlLogo.FileFilter = Globals.glbImageFileTypes;
addresssVendor.ModuleId = ModuleId;
addresssVendor.StartTabIndex = 4;
var objVendors = new VendorsController();
if (VendorID != -1)
{
VendorInfo objVendor;
if (Globals.IsHostTab(PortalSettings.ActiveTab.TabID) && UserInfo.IsSuperUser)
{
//Get Host Vendor
objVendor = objVendors.GetVendor(VendorID, Null.NullInteger);
}
else
{
//Get Portal Vendor
objVendor = objVendors.GetVendor(VendorID, PortalId);
}
if (objVendor != null)
{
txtVendorName.Text = objVendor.VendorName;
txtFirstName.Text = objVendor.FirstName;
txtLastName.Text = objVendor.LastName;
ctlLogo.Url = objVendor.LogoFile;
addresssVendor.Unit = objVendor.Unit;
addresssVendor.Street = objVendor.Street;
addresssVendor.City = objVendor.City;
addresssVendor.Region = objVendor.Region;
addresssVendor.Country = objVendor.Country;
addresssVendor.Postal = objVendor.PostalCode;
addresssVendor.Telephone = objVendor.Telephone;
addresssVendor.Fax = objVendor.Fax;
addresssVendor.Cell = objVendor.Cell;
txtEmail.Text = objVendor.Email;
txtWebsite.Text = objVendor.Website;
chkAuthorized.Checked = objVendor.Authorized;
txtKeyWords.Text = objVendor.KeyWords;
ctlAudit.CreatedByUser = objVendor.CreatedByUser;
ctlAudit.CreatedDate = objVendor.CreatedDate.ToString();
}
//use dispatch method to load modules
var banners = ControlUtilities.LoadControl<Banners>(this, TemplateSourceDirectory.Remove(0, Globals.ApplicationPath.Length) + "/Banners.ascx");
banners.ID = "/Banners.ascx";
banners.VendorID = VendorID;
banners.ModuleConfiguration = ModuleConfiguration;
divBanners.Controls.Add(banners);
var affiliates = ControlUtilities.LoadControl<Affiliates>(this, TemplateSourceDirectory.Remove(0, Globals.ApplicationPath.Length) + "/Affiliates.ascx");
affiliates.ID = "/Affiliates.ascx";
affiliates.VendorID = VendorID;
affiliates.ModuleConfiguration = ModuleConfiguration;
divAffiliates.Controls.Add(affiliates);
}
else
{
chkAuthorized.Checked = true;
ctlAudit.Visible = false;
cmdDelete.Visible = false;
pnlBanners.Visible = false;
pnlAffiliates.Visible = false;
}
if (blnSignup || blnBanner)
{
rowVendor1.Visible = false;
rowVendor2.Visible = false;
pnlVendor.Visible = false;
cmdDelete.Visible = false;
ctlAudit.Visible = false;
if (blnBanner)
{
cmdUpdate.Visible = false;
}
else
{
cmdUpdate.Text = "Signup";
}
}
else
{
TabInfo objTab = TabController.Instance.GetTabByName("Vendors", Globals.IsHostTab(PortalSettings.ActiveTab.TabID) ? Null.NullInteger : PortalId);
if (objTab != null)
{
ViewState["filter"] = Request.QueryString["filter"];
}
}
}
}
catch (Exception exc) //Module failed to load
{
Exceptions.ProcessModuleLoadException(this, exc);
}
}
/// -----------------------------------------------------------------------------
/// <summary>
/// cmdCancel_Click runs when the Cancel button is clicked.
/// </summary>
/// <remarks>
/// </remarks>
/// <history>
/// [cnurse] 9/17/2004 Updated to reflect design changes for Help, 508 support
/// and localisation
/// </history>
/// -----------------------------------------------------------------------------
protected void OnCancelClick(object sender, EventArgs e)
{
try
{
ReturnUrl(Convert.ToString(ViewState["filter"]));
}
catch (Exception exc) //Module failed to load
{
Exceptions.ProcessModuleLoadException(this, exc);
}
}
/// -----------------------------------------------------------------------------
/// <summary>
/// cmdDelete_Click runs when the Delete button is clicked.
/// </summary>
/// <remarks>
/// </remarks>
/// <history>
/// [cnurse] 9/17/2004 Updated to reflect design changes for Help, 508 support
/// and localisation
/// </history>
/// -----------------------------------------------------------------------------
protected void OnDeleteClick(object sender, EventArgs e)
{
try
{
if (VendorID != -1)
{
var objVendors = new VendorsController();
objVendors.DeleteVendor(VendorID);
}
Response.Redirect(Globals.NavigateURL());
}
catch (Exception exc) //Module failed to load
{
Exceptions.ProcessModuleLoadException(this, exc);
}
}
/// -----------------------------------------------------------------------------
/// <summary>
/// cmdUpdate_Click runs when the Update button is clicked.
/// </summary>
/// <remarks>
/// </remarks>
/// <history>
/// [cnurse] 9/17/2004 Updated to reflect design changes for Help, 508 support
/// and localisation
/// </history>
/// -----------------------------------------------------------------------------
protected void OnUpdateClick(object sender, EventArgs e)
{
try
{
if (Page.IsValid)
{
int portalID;
if (Globals.IsHostTab(PortalSettings.ActiveTab.TabID))
{
portalID = -1;
}
else
{
portalID = PortalId;
}
var objVendors = new VendorsController();
var objVendor = new VendorInfo
{
PortalId = portalID,
VendorId = VendorID,
VendorName = txtVendorName.Text,
Unit = addresssVendor.Unit,
Street = addresssVendor.Street,
City = addresssVendor.City,
Region = addresssVendor.Region,
Country = addresssVendor.Country,
PostalCode = addresssVendor.Postal,
Telephone = addresssVendor.Telephone,
Fax = addresssVendor.Fax,
Cell = addresssVendor.Cell,
Email = txtEmail.Text,
Website = txtWebsite.Text,
FirstName = txtFirstName.Text,
LastName = txtLastName.Text,
UserName = UserInfo.UserID.ToString(),
LogoFile = ctlLogo.Url,
KeyWords = txtKeyWords.Text,
Authorized = chkAuthorized.Checked
};
if (VendorID == -1)
{
try
{
VendorID = objVendors.AddVendor(objVendor);
}
catch(Exception exc)
{
//AddModuleMessage("ErrorAddVendor", ModuleMessage.ModuleMessageType.RedError);
Exceptions.ProcessModuleLoadException(this, exc);
return;
}
}
else
{
VendorInfo vendorCheck = objVendors.GetVendor(VendorID, portalID);
if (vendorCheck != null)
{
objVendors.UpdateVendor(objVendor);
}
else
{
Response.Redirect(Globals.NavigateURL());
}
}
if (cmdUpdate.Text == "Signup")
{
var custom = new ArrayList();
custom.Add(DateTime.Now.ToString());
custom.Add(txtVendorName.Text);
custom.Add(txtFirstName.Text);
custom.Add(txtLastName.Text);
custom.Add(addresssVendor.Unit);
custom.Add(addresssVendor.Street);
custom.Add(addresssVendor.City);
custom.Add(addresssVendor.Region);
custom.Add(addresssVendor.Country);
custom.Add(addresssVendor.Postal);
custom.Add(addresssVendor.Telephone);
custom.Add(addresssVendor.Fax);
custom.Add(addresssVendor.Cell);
custom.Add(txtEmail.Text);
custom.Add(txtWebsite.Text);
//send email to Admin
Mail.SendEmail(PortalSettings.Email,
PortalSettings.Email,
Localization.GetSystemMessage(PortalSettings, "EMAIL_VENDOR_REGISTRATION_ADMINISTRATOR_SUBJECT"),
Localization.GetSystemMessage(PortalSettings, "EMAIL_VENDOR_REGISTRATION_ADMINISTRATOR_BODY", Localization.GlobalResourceFile, custom));
//send email to vendor
custom.Clear();
custom.Add(txtFirstName.Text);
custom.Add(txtLastName.Text);
custom.Add(txtVendorName.Text);
Mail.SendEmail(PortalSettings.Email,
txtEmail.Text,
Localization.GetSystemMessage(PortalSettings, "EMAIL_VENDOR_REGISTRATION_SUBJECT"),
Localization.GetSystemMessage(PortalSettings, "EMAIL_VENDOR_REGISTRATION_BODY", Localization.GlobalResourceFile, custom));
ReturnUrl(txtVendorName.Text.Substring(0, 1));
}
else
{
ReturnUrl(Convert.ToString(ViewState["filter"]));
}
}
}
catch (Exception exc) //Module failed to load
{
Exceptions.ProcessModuleLoadException(this, exc);
}
}
#endregion
}
}