using System;
using System.Data;
using System.Collections;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using CMS.CMSHelper;
using CMS.Controls;
using CMS.GlobalHelper;
using CMS.PortalControls;
using CMS.PortalEngine;
using CMS.SettingsProvider;
using CMS.DocumentEngine;
using TreeNode = CMS.DocumentEngine.TreeNode;
public partial class CMSWebParts_Events_EventCalendar : CMSAbstractWebPart
{
#region "Public properties"
///
/// Gets or sets the value that indicates whether permissions are checked.
///
public bool CheckPermissions
{
get
{
return ValidationHelper.GetBoolean(GetValue("CheckPermissions"), calItems.CheckPermissions);
}
set
{
SetValue("CheckPermissions", value);
calItems.CheckPermissions = value;
repEvent.CheckPermissions = value;
}
}
///
/// Gets or sets the class names.
///
public string ClassNames
{
get
{
return DataHelper.GetNotEmpty(ValidationHelper.GetString(GetValue("ClassNames"), calItems.ClassNames), calItems.ClassNames);
}
set
{
SetValue("ClassNames", value);
calItems.ClassNames = value;
repEvent.ClassNames = value;
}
}
///
/// Gets or sets the value that indicates whether data are combined with default control.
///
public bool CombineWithDefaultCulture
{
get
{
return ValidationHelper.GetBoolean(GetValue("CombineWithDefaultCulture"), calItems.CombineWithDefaultCulture);
}
set
{
SetValue("CombineWithDefaultCulture", value);
calItems.CombineWithDefaultCulture = value;
repEvent.CombineWithDefaultCulture = value;
}
}
///
/// Gets or sets the culture code.
///
public string CultureCode
{
get
{
return DataHelper.GetNotEmpty(ValidationHelper.GetString(GetValue("CultureCode"), calItems.CultureCode), calItems.CultureCode);
}
set
{
SetValue("CultureCode", value);
calItems.CultureCode = value;
repEvent.CultureCode = value;
}
}
///
/// Gets or sets the max. relative level.
///
public int MaxRelativeLevel
{
get
{
return ValidationHelper.GetInteger(GetValue("MaxRelativeLevel"), calItems.MaxRelativeLevel);
}
set
{
SetValue("MaxRelativeLevel", value);
calItems.MaxRelativeLevel = value;
}
}
///
/// Gets or sets the order by value.
///
public string OrderBy
{
get
{
return DataHelper.GetNotEmpty(ValidationHelper.GetString(GetValue("OrderBy"), calItems.OrderBy), calItems.OrderBy);
}
set
{
SetValue("OrderBy", value);
calItems.OrderBy = value;
}
}
///
/// Gets or sets the path.
///
public string Path
{
get
{
return DataHelper.GetNotEmpty(ValidationHelper.GetString(GetValue("Path"), calItems.Path), calItems.Path);
}
set
{
SetValue("Path", value);
calItems.Path = value;
}
}
///
/// Gets or sets the value that indicates whether related node is on the lef side.
///
public bool RelatedNodeIsOnTheLeftSide
{
get
{
return ValidationHelper.GetBoolean(GetValue("RelatedNodeIsOnTheLeftSide"), calItems.RelatedNodeIsOnTheLeftSide);
}
set
{
SetValue("RelatedNodeIsOnTheLeftSide", value);
calItems.RelatedNodeIsOnTheLeftSide = value;
}
}
///
/// Gets or sets the relationship name.
///
public string RelationshipName
{
get
{
return DataHelper.GetNotEmpty(ValidationHelper.GetString(GetValue("RelationshipName"), calItems.RelationshipName), calItems.RelationshipName);
}
set
{
SetValue("RelationshipName", value);
calItems.RelationshipName = value;
}
}
///
/// Gets or sets the relationShip with node guid.
///
public Guid RelationshipWithNodeGuid
{
get
{
return ValidationHelper.GetGuid(GetValue("RelationshipWithNodeGuid"), calItems.RelationshipWithNodeGuid);
}
set
{
SetValue("RelationshipWithNodeGuid", value);
calItems.RelationshipWithNodeGuid = value;
}
}
///
/// Gets or sets the value that indicates whether selected documents must be only published.
///
public bool SelectOnlyPublished
{
get
{
return ValidationHelper.GetBoolean(GetValue("SelectOnlyPublished"), calItems.SelectOnlyPublished);
}
set
{
SetValue("SelectOnlyPublished", value);
calItems.SelectOnlyPublished = value;
repEvent.SelectOnlyPublished = value;
}
}
///
/// Gets or sets the site name.
///
public string SiteName
{
get
{
return DataHelper.GetNotEmpty(ValidationHelper.GetString(GetValue("SiteName"), calItems.SiteName), calItems.SiteName);
}
set
{
SetValue("SiteName", value);
calItems.SiteName = value;
repEvent.SiteName = value;
}
}
///
/// Gets or sets the name of the transforamtion which is used for displaying the results.
///
public string TransformationName
{
get
{
return DataHelper.GetNotEmpty(ValidationHelper.GetString(GetValue("TransformationName"), "cms.bookingevent.EventCalendarItem"), "cms.bookingevent.EventCalendarItem");
}
set
{
SetValue("TransformationName", value);
calItems.TransformationName = value;
}
}
///
/// Gets or sets the where condition.
///
public string WhereCondition
{
get
{
return DataHelper.GetNotEmpty(ValidationHelper.GetString(GetValue("WhereCondition"), calItems.WhereCondition), calItems.WhereCondition);
}
set
{
SetValue("WhereCondition", value);
calItems.WhereCondition = value;
repEvent.WhereCondition = value;
}
}
///
/// Gets or sets the field of event start date.
///
public string DayField
{
get
{
return DataHelper.GetNotEmpty(ValidationHelper.GetString(GetValue("DayField"), "EventDate"), "EventDate");
}
set
{
SetValue("DayField", value);
calItems.DayField = value;
}
}
///
/// Gets or sets the field of event end date.
///
public string EventEndField
{
get
{
return ValidationHelper.GetString(GetValue("EventEndField"), calItems.EventEndField);
}
set
{
SetValue("EventEndField", value);
calItems.EventEndField = value;
}
}
///
/// Gets or sets the no event transformation name.
///
public string NoEventTransformationName
{
get
{
return DataHelper.GetNotEmpty(GetValue("NoEventTransformationName"), "cms.bookingevent.calendarnoevent");
}
set
{
SetValue("NoEventTransformationName", value);
calItems.NoEventTransformationName = value;
}
}
///
/// Indicates whether the day number is displayed or cell is full filled by the transformation.
/// Current day is saved in the "__day" column.
///
public bool HideDefaultDayNumber
{
get
{
return ValidationHelper.GetBoolean(GetValue("HideDefaultDayNumber"), calItems.HideDefaultDayNumber);
}
set
{
SetValue("HideDefaultDayNumber", value);
calItems.HideDefaultDayNumber = value;
}
}
///
/// Gets or sets the columns to retrieve.
///
public string Columns
{
get
{
return DataHelper.GetNotEmpty(ValidationHelper.GetString(GetValue("Columns"), calItems.Columns), calItems.Columns);
}
set
{
SetValue("Columns", value);
calItems.Columns = value;
repEvent.Columns = value;
}
}
///
/// Gets or sets the SkinID which should be used.
///
public override string SkinID
{
get
{
return base.SkinID;
}
set
{
base.SkinID = value;
if ((calItems != null) && (PageCycle < PageCycleEnum.Initialized))
{
calItems.SkinID = SkinID;
}
}
}
///
/// Calendar control.
///
public CMSCalendar CalendarControl
{
get
{
return calItems;
}
}
///
/// Filter name.
///
public string FilterName
{
get
{
return ValidationHelper.GetString(GetValue("FilterName"), calItems.FilterName);
}
set
{
SetValue("FilterName", value);
calItems.FilterName = value;
}
}
///
/// Gets or sets the cache minutes.
///
public override int CacheMinutes
{
get
{
return base.CacheMinutes;
}
set
{
base.CacheMinutes = value;
calItems.CacheMinutes = value;
repEvent.CacheMinutes = value;
}
}
///
/// Gets or sets the cache item dependencies.
///
public override string CacheDependencies
{
get
{
return base.CacheDependencies;
}
set
{
base.CacheDependencies = value;
calItems.CacheDependencies = value;
repEvent.CacheDependencies = value;
}
}
///
/// Gets or sets the name of the cache item. If not explicitly specified, the name is automatically
/// created based on the control unique ID
///
public override string CacheItemName
{
get
{
return base.CacheItemName;
}
set
{
base.CacheItemName = value;
calItems.CacheItemName = value;
if (!String.IsNullOrEmpty(value))
{
repEvent.CacheItemName = value + "detail";
}
else
{
repEvent.CacheItemName = string.Empty;
}
}
}
#endregion
#region "Repeater properties"
///
/// Event detail transformation.
///
public string EventDetailTransformation
{
get
{
return DataHelper.GetNotEmpty(GetValue("EventDetailTransformation"), "cms.bookingevent.Default");
}
set
{
SetValue("EventDetailTransformation", value);
repEvent.SelectedItemTransformationName = value;
}
}
#endregion
///
/// Content loaded event handler.
///
public override void OnContentLoaded()
{
base.OnContentLoaded();
SetupControl();
}
///
/// Reloads control data.
///
public override void ReloadData()
{
base.ReloadData();
SetupControl();
calItems.ReloadData(true);
repEvent.ReloadData(true);
}
///
/// Initializes the control properties.
///
protected void SetupControl()
{
if (StopProcessing)
{
calItems.StopProcessing = true;
}
else
{
calItems.ControlContext = repEvent.ControlContext = ControlContext;
// Calendar properties
calItems.CacheItemName = CacheItemName;
calItems.CacheDependencies = CacheDependencies;
calItems.CacheMinutes = CacheMinutes;
calItems.CheckPermissions = CheckPermissions;
calItems.ClassNames = ClassNames;
calItems.CombineWithDefaultCulture = CombineWithDefaultCulture;
calItems.CultureCode = CultureCode;
calItems.MaxRelativeLevel = MaxRelativeLevel;
calItems.OrderBy = OrderBy;
calItems.WhereCondition = WhereCondition;
calItems.Columns = Columns;
calItems.Path = Path;
calItems.SelectOnlyPublished = SelectOnlyPublished;
calItems.SiteName = SiteName;
calItems.FilterName = FilterName;
calItems.RelationshipName = RelationshipName;
calItems.RelationshipWithNodeGuid = RelationshipWithNodeGuid;
calItems.RelatedNodeIsOnTheLeftSide = RelatedNodeIsOnTheLeftSide;
calItems.TransformationName = TransformationName;
calItems.NoEventTransformationName = NoEventTransformationName;
calItems.DayField = DayField;
calItems.EventEndField = EventEndField;
calItems.HideDefaultDayNumber = HideDefaultDayNumber;
calItems.TodaysDate = CMSContext.ConvertDateTime(DateTime.Now, this);
bool detail = false;
// If calendar event path is defined event is loaded in accordance to the selected path
string eventPath = QueryHelper.GetString("CalendarEventPath", null);
if (!String.IsNullOrEmpty(eventPath))
{
detail = true;
repEvent.Path = eventPath;
// Set selected date to specific document
TreeNode node = TreeHelper.GetDocument(SiteName, eventPath, CultureCode, CombineWithDefaultCulture, ClassNames, SelectOnlyPublished, CheckPermissions, CMSContext.CurrentUser);
if (node != null)
{
object value = node.GetValue(DayField);
if (ValidationHelper.GetDateTime(value, DataHelper.DATETIME_NOT_SELECTED) != DataHelper.DATETIME_NOT_SELECTED)
{
calItems.TodaysDate = CMSContext.ConvertDateTime((DateTime)value, this);
}
}
}
// By default select current event from current document value
PageInfo currentPage = CMSContext.CurrentPageInfo;
if ((currentPage != null) && (ClassNames.ToLowerCSafe().Contains(currentPage.ClassName.ToLowerCSafe())))
{
detail = true;
repEvent.Path = currentPage.NodeAliasPath;
// Set selected date to current document
object value = CMSContext.CurrentDocument.GetValue(DayField);
if (ValidationHelper.GetDateTime(value, DataHelper.DATETIME_NOT_SELECTED) != DataHelper.DATETIME_NOT_SELECTED)
{
calItems.TodaysDate = CMSContext.ConvertDateTime((DateTime)value, this);
// Get name of coupled class ID column
string idColumn = CMSContext.CurrentDocument.CoupledClassIDColumn;
if (!string.IsNullOrEmpty(idColumn))
{
// Set selected item ID and the ID column name so it is possible to highlight specific event in the calendar
calItems.SelectedItemIDColumn = idColumn;
calItems.SelectedItemID = ValidationHelper.GetInteger(CMSContext.CurrentDocument.GetValue(idColumn), 0);
}
}
}
if (detail)
{
// Setup the detail repeater
repEvent.Visible = true;
repEvent.StopProcessing = false;
repEvent.SelectedItemTransformationName = EventDetailTransformation;
repEvent.ClassNames = ClassNames;
repEvent.Columns = Columns;
if (!String.IsNullOrEmpty(CacheItemName))
{
repEvent.CacheItemName = CacheItemName + "|detail";
}
repEvent.CacheDependencies = CacheDependencies;
repEvent.CacheMinutes = CacheMinutes;
repEvent.CheckPermissions = CheckPermissions;
repEvent.CombineWithDefaultCulture = CombineWithDefaultCulture;
repEvent.CultureCode = CultureCode;
repEvent.SelectOnlyPublished = SelectOnlyPublished;
repEvent.SiteName = SiteName;
repEvent.WhereCondition = WhereCondition;
}
}
}
///
/// Applies given stylesheet skin.
///
public override void ApplyStyleSheetSkin(Page page)
{
calItems.SkinID = SkinID;
base.ApplyStyleSheetSkin(page);
}
///
/// Clear cache.
///
public override void ClearCache()
{
calItems.ClearCache();
repEvent.ClearCache();
}
}