/Server/AjaxControlToolkit/PieChart/PieChart.cs

http://ajaxcontroltoolkit.codeplex.com · C# · 249 lines · 168 code · 31 blank · 50 comment · 11 complexity · a3a001dfddbc40a3f7cdc1771f57884b MD5 · raw file

  1. using System;
  2. using System.Collections;
  3. using System.ComponentModel.Design.Serialization;
  4. using System.Data;
  5. using System.Configuration;
  6. using System.Reflection;
  7. using System.Web;
  8. using System.Web.Security;
  9. using System.Web.UI;
  10. using System.Web.UI.WebControls;
  11. using System.Web.UI.WebControls.WebParts;
  12. using System.Web.UI.HtmlControls;
  13. using System.Web.Script;
  14. using System.ComponentModel;
  15. using System.Xml;
  16. using System.IO;
  17. using System.Collections.Generic;
  18. using System.Collections.Specialized;
  19. using System.Globalization;
  20. using AjaxControlToolkit;
  21. using System.Text;
  22. using System.Web.Script.Serialization;
  23. using System.Diagnostics;
  24. using System.Drawing;
  25. using System.Drawing.Design;
  26. #region [ Resources ]
  27. [assembly: System.Web.UI.WebResource("PieChart.PieChart.js", "application/x-javascript")]
  28. [assembly: System.Web.UI.WebResource("PieChart.PieChart.debug.js", "application/x-javascript")]
  29. [assembly: WebResource("PieChart.PieChart.css", "text/css", PerformSubstitution = true)]
  30. #endregion
  31. namespace AjaxControlToolkit
  32. {
  33. /// <summary>
  34. /// PieChart creates Piechart with the specified values.
  35. /// </summary>
  36. [Designer("AjaxControlToolkit.PieChartDesigner, AjaxControlToolkit")]
  37. [RequiredScript(typeof(CommonToolkitScripts))]
  38. [ClientCssResource("PieChart.PieChart.css")]
  39. [ClientScriptResource("Sys.Extended.UI.PieChart", "PieChart.PieChart.js")]
  40. public class PieChart : ScriptControlBase
  41. {
  42. private PieChartValueCollection pieChartValueList = null;
  43. #region [ Constructors ]
  44. /// <summary>
  45. /// Initializes a new PieChart Control.
  46. /// </summary>
  47. public PieChart()
  48. : base(true, HtmlTextWriterTag.Div)
  49. {
  50. }
  51. #endregion
  52. #region [Private Properties]
  53. /// <summary>
  54. /// Gets whether control is in design mode or not.
  55. /// </summary>
  56. private bool IsDesignMode
  57. {
  58. get
  59. {
  60. return (HttpContext.Current == null);
  61. }
  62. }
  63. #endregion
  64. #region [ Public Properties ]
  65. /// <summary>
  66. /// Width of PieChart.
  67. /// </summary>
  68. [ExtenderControlProperty]
  69. [DefaultValue(null)]
  70. [ClientPropertyName("chartWidth")]
  71. public string ChartWidth
  72. {
  73. get;
  74. set;
  75. }
  76. /// <summary>
  77. /// Height of PieChart.
  78. /// </summary>
  79. [ExtenderControlProperty]
  80. [DefaultValue(null)]
  81. [ClientPropertyName("chartHeight")]
  82. public string ChartHeight
  83. {
  84. get;
  85. set;
  86. }
  87. /// <summary>
  88. /// Title of PieChart.
  89. /// </summary>
  90. [ExtenderControlProperty]
  91. [DefaultValue("")]
  92. [ClientPropertyName("chartTitle")]
  93. public string ChartTitle
  94. {
  95. get;
  96. set;
  97. }
  98. /// <summary>
  99. /// Provide list of PieChartValue to client side. Need help from PieChartValues property
  100. /// for designer experience support, cause Editor always blocks the property
  101. /// ability to provide values to client side as ExtenderControlProperty on run time.
  102. /// </summary>
  103. [PersistenceMode(PersistenceMode.InnerProperty)]
  104. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  105. [Browsable(false)]
  106. [EditorBrowsable(EditorBrowsableState.Never)]
  107. [ExtenderControlProperty(true, true)]
  108. public PieChartValueCollection PieChartClientValues
  109. {
  110. get
  111. {
  112. return pieChartValueList;
  113. }
  114. }
  115. /// <summary>
  116. /// defines series related to PieChart.
  117. /// </summary>
  118. [PersistenceMode(PersistenceMode.InnerProperty)]
  119. [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
  120. [DefaultValue(null)]
  121. [NotifyParentProperty(true)]
  122. [Editor(typeof(PieChartValueCollectionEditor), typeof(UITypeEditor))]
  123. public PieChartValueCollection PieChartValues
  124. {
  125. get
  126. {
  127. if (pieChartValueList == null)
  128. pieChartValueList = new PieChartValueCollection();
  129. return pieChartValueList;
  130. }
  131. }
  132. /// <summary>
  133. /// CSS/Theme file name of PieChart.
  134. /// </summary>
  135. [ExtenderControlProperty]
  136. [DefaultValue("PieChart")]
  137. [ClientPropertyName("theme")]
  138. public string Theme
  139. {
  140. get;
  141. set;
  142. }
  143. /// <summary>
  144. /// CSS/Theme file name of PieChart.
  145. /// </summary>
  146. [ExtenderControlProperty]
  147. [DefaultValue("")]
  148. [ClientPropertyName("chartTitleColor")]
  149. public string ChartTitleColor
  150. {
  151. get;
  152. set;
  153. }
  154. #endregion
  155. #region [ Members ]
  156. /// <summary>
  157. /// On Init to validate data.
  158. /// </summary>
  159. /// <param name="e"></param>
  160. protected override void OnInit(EventArgs e)
  161. {
  162. base.OnInit(e);
  163. if (!IsDesignMode)
  164. {
  165. foreach (PieChartValue pieChartValue in PieChartValues)
  166. {
  167. if (pieChartValue.Category == null || pieChartValue.Category.Trim() == "")
  168. {
  169. throw new Exception("Category is missing in the PieChartValue. Please provide a Category in the PieChartValue.");
  170. }
  171. if (pieChartValue.Data == null)
  172. {
  173. throw new Exception("Data is missing in the PieChartValue. Please provide a Data in the PieChartValue.");
  174. }
  175. }
  176. }
  177. }
  178. /// <summary>
  179. /// CreateChilds call to create child controls for PieChart.
  180. /// </summary>
  181. internal void CreateChilds()
  182. {
  183. this.Controls.Clear();
  184. this.CreateChildControls();
  185. }
  186. /// <summary>
  187. /// CreateChildControls creates html controls for a PieChart control.
  188. /// </summary>
  189. protected override void CreateChildControls()
  190. {
  191. GenerateHtmlInputControls();
  192. }
  193. /// <summary>
  194. /// GenerateHtmlInputControls creates parent div for PieChart control.
  195. /// </summary>
  196. /// <returns>Return the client id of parent div that contains all other html controls.</returns>
  197. protected string GenerateHtmlInputControls()
  198. {
  199. HtmlGenericControl parent = new HtmlGenericControl("div");
  200. parent.ID = "_ParentDiv";
  201. parent.Attributes.Add("style", "border-style:solid; border-width:1px;");
  202. Controls.Add(parent);
  203. return parent.ClientID;
  204. }
  205. /// <summary>
  206. /// DescribeComponent creates propreties in ScriptComponentDescriptor for child controls in PieChart.
  207. /// </summary>
  208. /// <param name="descriptor">Descriptor object which will accpet server components to convert in client script.</param>
  209. protected override void DescribeComponent(ScriptComponentDescriptor descriptor)
  210. {
  211. base.DescribeComponent(descriptor);
  212. if (!IsDesignMode)
  213. {
  214. }
  215. }
  216. #endregion
  217. }
  218. }