using System;
using CMS.GlobalHelper;
using CMS.SettingsProvider;
using CMS.UIControls;
public partial class CMSModules_AdminControls_Controls_Class_ClassQueries : CMSUserControl
{
#region "Private fields"
private int mClassID = 0;
private string mEditPageUrl = null;
#endregion
#region "Public properties"
///
/// ID of the class to edit queries.
///
public int ClassID
{
get
{
return mClassID;
}
set
{
mClassID = value;
}
}
///
/// URL of the page holding the editing tasks.
///
public string EditPageUrl
{
get
{
return mEditPageUrl;
}
set
{
mEditPageUrl = value;
}
}
///
/// Indicates if control is used on live site.
///
public override bool IsLiveSite
{
get
{
return base.IsLiveSite;
}
set
{
uniGrid.IsLiveSite = value;
base.IsLiveSite = value;
}
}
#endregion
#region "Page events"
protected void Page_Load(object sender, EventArgs e)
{
if (StopProcessing)
{
}
else
{
// Initialize the controls
uniGrid.OnAction += new OnActionEventHandler(uniGrid_OnAction);
uniGrid.GridName = "~/CMSModules/AdminControls/Controls/Class/ClassQueries.xml";
uniGrid.IsLiveSite = IsLiveSite;
uniGrid.ZeroRowsText = GetString("general.nodatafound");
// If the ClassID was specified
if (ClassID > 0)
{
uniGrid.WhereCondition = "ClassID=" + ClassID;
}
else
{
// Otherwise hide the UniGrid to avoid unexpected behaviour
uniGrid.Visible = false;
}
}
}
#endregion
#region "UniGrid handling"
///
/// Handles the UniGrid's OnAction event.
///
/// Name of item (button) that throws event
/// ID (value of Primary key) of corresponding data row
protected void uniGrid_OnAction(string actionName, object actionArgument)
{
if (CMSString.Equals(actionName, "edit", true))
{
RedirectToEditUrl(actionArgument);
}
else if (CMSString.Equals(actionName, "delete", true))
{
int queryId = ValidationHelper.GetInteger(actionArgument, -1);
if (queryId > 0)
{
QueryProvider.DeleteQuery(queryId);
}
}
}
#endregion
#region "Private methods"
///
/// Redirects to page where user can edit a selected query.
///
/// ID of the query selected in UniGrid
private void RedirectToEditUrl(object actionArgument)
{
string actionArg = ValidationHelper.GetString(actionArgument, string.Empty);
if (actionArg == string.Empty)
{
return;
}
string editUrl = string.Format("{0}?queryid={1}&classid={2}", EditPageUrl, actionArg, ClassID);
URLHelper.Redirect(editUrl);
}
#endregion
}