using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CMS.DataEngine;
using CMS.FormControls;
using CMS.FormEngine;
using CMS.GlobalHelper;
using CMS.CMSHelper;
using CMS.ExtendedControls;
using CMS.SettingsProvider;
using CMS.SiteProvider;
public partial class CMSFormControls_Basic_MetaFileUploadControl : FormEngineUserControl
{
#region "Variables"
private string mValue = null;
#endregion
#region "Properties"
///
/// Gets or sets the enabled state of the control.
///
public override bool Enabled
{
get
{
return fileUploader.Enabled;
}
set
{
fileUploader.Enabled = value;
}
}
///
/// Gets or sets field value.
///
public override object Value
{
get
{
return mValue;
}
set
{
mValue = (value != null ? value.ToString() : null);
}
}
///
/// Field info object.
///
public override FormFieldInfo FieldInfo
{
get
{
return base.FieldInfo;
}
set
{
base.FieldInfo = value;
fileUploader.FieldInfo = value;
}
}
///
/// Indicates if control is placed on live site.
///
public override bool IsLiveSite
{
get
{
return fileUploader.IsLiveSite;
}
set
{
fileUploader.IsLiveSite = value;
}
}
#endregion
#region "Page events"
protected void Page_Load(object sender, EventArgs e)
{
// Set control properties from parent Form
if (Form != null)
{
Form.OnBeforeRedirect += new EventHandler(Form_OnBeforeRedirect);
if (Form is UIForm)
{
BaseInfo info = ((UIForm)Form).EditedObject as BaseInfo;
if (info != null)
{
fileUploader.ObjectType = info.TypeInfo.ObjectType;
if (info.Generalized.ObjectSiteID > 0)
{
fileUploader.SiteID = info.Generalized.ObjectSiteID;
}
fileUploader.ObjectID = info.Generalized.ObjectID;
}
}
else if (Form.EditedObject is IDataClass)
{
IDataClass item = Form.EditedObject as IDataClass;
if (item != null)
{
fileUploader.ObjectType = item.ClassName;
if (!string.IsNullOrEmpty(Form.SiteName))
{
fileUploader.SiteID = SiteInfoProvider.GetSiteID(Form.SiteName);
}
fileUploader.ObjectID = item.ID;
}
}
// Set metafile category
fileUploader.Category = ValidationHelper.GetString(GetValue("ObjectCategory"), CMSConstants.OBJECT_CATEGORY_THUMBNAIL);
}
// Set style properties of control
if (!String.IsNullOrEmpty(ControlStyle))
{
fileUploader.Attributes.Add("style", ControlStyle);
ControlStyle = null;
}
if (!String.IsNullOrEmpty(CssClass))
{
fileUploader.CssClass = CssClass;
CssClass = null;
}
CheckFieldEmptiness = false;
}
private void Form_OnBeforeRedirect(object sender, EventArgs e)
{
if (Form.Mode == FormModeEnum.Insert)
{
// Set ID of created object
if (Form is UIForm)
{
BaseInfo info = ((UIForm)Form).EditedObject as BaseInfo;
if (info != null)
{
fileUploader.ObjectID = info.Generalized.ObjectID;
}
}
else if (Form.EditedObject is IDataClass)
{
IDataClass item = Form.EditedObject as IDataClass;
if (item != null)
{
fileUploader.ObjectID = item.ID;
}
}
// Upload new metafile
fileUploader.UploadFile();
}
}
#endregion
}