using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
using System.Web;
using System.Web.Caching;
using System.Web.UI;
namespace OpenFlashChart
{
[Designer(typeof(ChartControlDesigner)), Description("Chart control for open flash chart"), ToolboxData("<{0}:OpenFlashChartControl runat=\"server\" >{0}:OpenFlashChartControl>")]
public class OpenFlashChartControl : Control
{
private string width;
private string height;
private string externalSWFfile;
private string externalSWFObjectFile;
private string loadingmsg;
private OpenFlashChart chart;
private string chart_json;
private bool _enableCache;
///
/// Used to hold internal chart
///
public OpenFlashChart Chart
{
get
{
return chart;
}
set
{
chart = value;
chart_json = value.ToString();
ViewState["chart_json"] = chart_json;
}
}
private string ChartJson
{
get
{
if (ViewState["chart_json"] != null)
return ViewState["chart_json"].ToString();
return chart_json;
}
}
private string datafile;
[DefaultValue("600px")]
[Category("Appearance")]
[PersistenceMode(PersistenceMode.Attribute)]
public string Width
{
get
{
width = "600px";
if (this.ViewState["width"] != null)
{
width = this.ViewState["width"].ToString();
}
return width;
}
set
{
if (!value.EndsWith("%") && !value.EndsWith("px"))
value = value + "px";
this.ViewState["width"] = value;
width = value;
}
}
[DefaultValue("300px")]
[Category("Appearance")]
[PersistenceMode(PersistenceMode.Attribute)]
public string Height
{
get
{
height = "300px";
if (this.ViewState["height"] != null)
{
height = this.ViewState["height"].ToString();
}
return height;
}
set
{
if (!value.EndsWith("%") && !value.EndsWith("px"))
value = value + "px";
this.ViewState["height"] = value;
height = value;
}
}
[Category("Appearance")]
[PersistenceMode(PersistenceMode.Attribute)]
public string ExternalSWFfile
{
get
{
if (this.ViewState["externalswffile"] != null)
{
externalSWFfile = this.ViewState["externalswffile"].ToString();
}
if (!string.IsNullOrEmpty(externalSWFfile))
{
if (externalSWFfile.StartsWith("~"))
{
externalSWFfile = this.ResolveUrl(externalSWFfile);
}
}
return externalSWFfile;
}
set
{
this.ViewState["externalswffile"] = value.Trim();
externalSWFfile = value.Trim();
}
}
[Category("Appearance")]
[PersistenceMode(PersistenceMode.Attribute)]
public string ExternalSWFObjectFile
{
get
{
if (this.ViewState["externalswfobjectfile"] != null)
{
externalSWFObjectFile = this.ViewState["externalswfobjectfile"].ToString();
}
if (!string.IsNullOrEmpty(externalSWFObjectFile))
{
if (externalSWFObjectFile.StartsWith("~"))
{
externalSWFObjectFile = this.ResolveUrl(externalSWFObjectFile);
}
}
return externalSWFObjectFile;
}
set
{
this.ViewState["externalswfobjectfile"] = value.Trim();
externalSWFObjectFile = value.Trim();
}
}
public string DataFile
{
get
{
if (this.ViewState["datafile"] != null)
{
datafile = this.ViewState["datafile"].ToString();
}
if (!string.IsNullOrEmpty(datafile))
{
if (datafile.StartsWith("~"))
{
datafile = this.ResolveUrl(datafile);
}
}
return datafile;
}
set
{
this.ViewState["datafile"] = value;
datafile = value;
}
}
public string LoadingMsg
{
get { return loadingmsg; }
set { loadingmsg = value; }
}
public bool EnableCache
{
get { return _enableCache; }
set { _enableCache = value; }
}
protected override void OnInit(EventArgs e)
{
const string key = "swfobject";
string swfobjectfile = ExternalSWFObjectFile;
if (string.IsNullOrEmpty(ExternalSWFObjectFile))
swfobjectfile = Page.ClientScript.GetWebResourceUrl(this.GetType(), "OpenFlashChart.swfobject.js");
if (!this.Page.ClientScript.IsClientScriptBlockRegistered(key))
{
this.Page.ClientScript.RegisterClientScriptBlock(this.Page.GetType(), key, "");
}
base.OnInit(e);
}
public override void RenderControl(HtmlTextWriter writer)
{
StringBuilder builder = new StringBuilder();
if (string.IsNullOrEmpty(ExternalSWFfile))
ExternalSWFfile = Page.ClientScript.GetWebResourceUrl(this.GetType(), "OpenFlashChart.open-flash-chart.swf");
builder.AppendFormat("
", this.ClientID);
builder.AppendLine("
");
builder.AppendLine("");
writer.Write(builder.ToString());
base.RenderControl(writer);
}
}
}