File: D:/HostingSpaces/TDijk1/erp-apps.eu/wwwroot/ERPApps/ERPWebParts/Documents/AdActionButton.ascx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using CMS.CMSHelper;
using CMS.TreeEngine;
using CMS.DataEngine;
using CMS.SettingsProvider;
using CMS.GlobalHelper;
using CMS.PortalControls;
using CMS.DocumentEngine;
using CMS.Helpers;
/// <summary>
/// Action button to handle events in list of ads in vendor zone
/// </summary>
public partial class ERPApps_ERPWebParts_Documents_AdActionButton : CMSAbstractWebPart
{
#region "Properties"
/// <summary>
/// Text of the link
/// </summary>
public string Text;
/// <summary>
/// Text displayed after the action is performed
/// </summary>
public string AfterText;
/// <summary>
/// Type of action
/// </summary>
public string Action;
/// <summary>
/// Node to be used for the action
/// </summary>
public int NodeID;
/// <summary>
/// Javascript connected to the generated link
/// </summary>
public string OnClick;
/// <summary>
/// CSS class assigned to the generated link
/// </summary>
public string CssClass;
TreeNode mNode;
private TreeNode Node
{
get
{
if ( mNode == null )
{
mNode = TreeHelper.SelectSingleNode(NodeID);
}
return mNode;
}
}
#endregion
#region "On events"
public override void OnContentLoaded()
{
base.OnContentLoaded();
btnAction.Text = Text;
btnAction.Click += new EventHandler(btnAction_Click);
if ( OnClick != null )
{
btnAction.OnClientClick = OnClick;
}
if ( CssClass != null )
{
btnAction.CssClass = CssClass;
}
}
#endregion
/// <summary>
/// Custom actions to handle various tasks invoked by the vendor.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void btnAction_Click(object sender, EventArgs e)
{
switch ( Action )
{
case "delete":
DeleteAd();
break;
}
}
#region "Methods"
/// <summary>
/// Clears cache for afftected ad and vendor.
/// </summary>
private void ClearCache()
{
CacheHelper.TouchKey("nodeid|" + Node.NodeID);
CacheHelper.TouchKey("advendorid|" + ValidationHelper.GetInteger(Node.GetValue("AdVendorID"), 0));
}
private void AfterAction()
{
if ( AfterText != null )
{
btnAction.Text = AfterText;
}
panelRefresh.Visible = true;
}
/// <summary>
/// Deletes the ad
/// </summary>
private void DeleteAd()
{
if ( Node == null )
{
return;
}
if ( Node.Delete(false, true) )
{
ClearCache();
AfterAction();
}
}
#endregion
}