#region Copyright
//
// DotNetNukeŽ - http://www.dotnetnuke.com
// Copyright (c) 2002-2011
// 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 DotNetNuke.Common.Utilities;
using DotNetNuke.Entities.Modules;
using DotNetNuke.Services.Localization;
using DotNetNuke.Services.Mail;
using DotNetNuke.Services.Vendors;
using DotNetNuke.UI.Skins.Controls;
using DotNetNuke.UI.Utilities;
using Globals = DotNetNuke.Common.Globals;
#endregion
namespace DotNetNuke.Modules.Admin.Vendors
{
/// -----------------------------------------------------------------------------
///
/// The EditAffiliate PortalModuleBase is used to add/edit an Affiliate
///
///
///
///
///
/// [cnurse] 9/21/2004 Updated to reflect design changes for Help, 508 support
/// and localisation
///
/// -----------------------------------------------------------------------------
public partial class EditAffiliate : PortalModuleBase
{
#region Private Members
private int AffiliateId = -1;
private int VendorId = -1;
public new int PortalId
{
get
{
if (Globals.IsHostTab(PortalSettings.ActiveTab.TabID))
{
return -1;
}
return PortalSettings.PortalId;
}
}
#endregion
#region Event Handlers
/// -----------------------------------------------------------------------------
///
/// Page_Load runs when the control is loaded
///
///
///
///
/// [cnurse] 9/21/2004 Updated to reflect design changes for Help, 508 support
/// and localisation
///
/// -----------------------------------------------------------------------------
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
cmdCancel.Click += OnCancelClick;
cmdDelete.Click += OnDeleteClick;
cmdSend.Click += OnSendClick;
cmdUpdate.Click += OnUpdateClick;
if ((Request.QueryString["VendorId"] != null))
{
VendorId = Int32.Parse(Request.QueryString["VendorId"]);
}
if ((Request.QueryString["AffilId"] != null))
{
AffiliateId = Int32.Parse(Request.QueryString["AffilId"]);
}
//this needs to execute always to the client script code is registred in InvokePopupCal
cmdStartCalendar.NavigateUrl = Calendar.InvokePopupCal(txtStartDate);
cmdEndCalendar.NavigateUrl = Calendar.InvokePopupCal(txtEndDate);
if (Page.IsPostBack == false)
{
var objAffiliates = new AffiliateController();
if (AffiliateId != Null.NullInteger)
{
//Obtain a single row of banner information
var objAffiliate = objAffiliates.GetAffiliate(AffiliateId, VendorId, PortalId);
if (objAffiliate != null)
{
if (!Null.IsNull(objAffiliate.StartDate))
{
txtStartDate.Text = objAffiliate.StartDate.ToShortDateString();
}
if (!Null.IsNull(objAffiliate.EndDate))
{
txtEndDate.Text = objAffiliate.EndDate.ToShortDateString();
}
txtCPC.Text = objAffiliate.CPC.ToString("#0.0####");
txtCPA.Text = objAffiliate.CPA.ToString("#0.0####");
}
else //security violation attempt to access item not related to this Module
{
Response.Redirect(EditUrl("VendorId", VendorId.ToString()), true);
}
}
else
{
txtCPC.Text = 0.ToString("#0.0####");
txtCPA.Text = 0.ToString("#0.0####");
cmdDelete.Visible = false;
}
}
}
/// -----------------------------------------------------------------------------
///
/// cmdCancel_Click runs when the Cancel Button is clicked
///
///
///
///
/// [cnurse] 9/21/2004 Updated to reflect design changes for Help, 508 support
/// and localisation
///
/// -----------------------------------------------------------------------------
protected void OnCancelClick(object sender, EventArgs e)
{
//Redirect back to the portal home page
Response.Redirect(EditUrl("VendorId", VendorId.ToString()), true);
}
/// -----------------------------------------------------------------------------
///
/// cmdDelete_Click runs when the Delete Button is clicked
///
///
///
///
/// [cnurse] 9/21/2004 Updated to reflect design changes for Help, 508 support
/// and localisation
///
/// -----------------------------------------------------------------------------
protected void OnDeleteClick(object sender, EventArgs e)
{
if (AffiliateId != -1)
{
var objAffiliates = new AffiliateController();
objAffiliates.DeleteAffiliate(AffiliateId);
//Redirect back to the portal home page
Response.Redirect(EditUrl("VendorId", VendorId.ToString()), true);
}
}
/// -----------------------------------------------------------------------------
///
/// cmdSend_Click runs when the Send Notification Button is clicked
///
///
///
///
/// [cnurse] 9/21/2004 Updated to reflect design changes for Help, 508 support
/// and localisation
///
/// -----------------------------------------------------------------------------
protected void OnSendClick(object sender, EventArgs e)
{
var objVendors = new VendorController();
var objVendor = objVendors.GetVendor(VendorId, PortalId);
if (objVendor != null)
{
if (!Null.IsNull(objVendor.Email))
{
var custom = new ArrayList
{
objVendor.VendorName,
Globals.GetPortalDomainName(PortalSettings.PortalAlias.HTTPAlias, Request, true) + "/" + Globals.glbDefaultPage + "?AffiliateId=" + VendorId
};
var errorMsg = Mail.SendMail(PortalSettings.Email,
objVendor.Email,
"",
Localization.GetSystemMessage(PortalSettings, "EMAIL_AFFILIATE_NOTIFICATION_SUBJECT"),
Localization.GetSystemMessage(PortalSettings, "EMAIL_AFFILIATE_NOTIFICATION_BODY", Localization.GlobalResourceFile, custom),
"",
"",
"",
"",
"",
"");
string strMessage;
if (String.IsNullOrEmpty(errorMsg))
{
strMessage = Localization.GetString("NotificationSuccess", LocalResourceFile);
UI.Skins.Skin.AddModuleMessage(this, strMessage, ModuleMessage.ModuleMessageType.GreenSuccess);
}
else
{
strMessage = Localization.GetString("NotificationFailure", LocalResourceFile);
strMessage = string.Format(strMessage, errorMsg);
UI.Skins.Skin.AddModuleMessage(this, strMessage, ModuleMessage.ModuleMessageType.RedError);
}
}
}
}
/// -----------------------------------------------------------------------------
///
/// cmdUpdate_Click runs when the Update Button is clicked
///
///
///
///
/// [cnurse] 9/21/2004 Updated to reflect design changes for Help, 508 support
/// and localisation
///
/// -----------------------------------------------------------------------------
protected void OnUpdateClick(object sender, EventArgs e)
{
if (Page.IsValid)
{
var objAffiliate = new AffiliateInfo
{
AffiliateId = AffiliateId,
VendorId = VendorId,
StartDate = !String.IsNullOrEmpty(txtStartDate.Text) ? DateTime.Parse(txtStartDate.Text) : Null.NullDate,
EndDate = !String.IsNullOrEmpty(txtEndDate.Text) ? DateTime.Parse(txtEndDate.Text) : Null.NullDate,
CPC = double.Parse(txtCPC.Text),
CPA = double.Parse(txtCPA.Text)
};
var objAffiliates = new AffiliateController();
if (AffiliateId == -1)
{
objAffiliates.AddAffiliate(objAffiliate);
}
else
{
objAffiliates.UpdateAffiliate(objAffiliate);
}
//Redirect back to the portal home page
Response.Redirect(EditUrl("VendorId", VendorId.ToString()), true);
}
}
#endregion
}
}