/Trunk/Library/UI/WebControls/DataGrids/DNNMultiStateBoxColumn.cs

# · C# · 298 lines · 151 code · 15 blank · 132 comment · 10 complexity · 4657437e328c601eb312062a87c61969 MD5 · raw file

  1. #region Copyright
  2. //
  3. // DotNetNukeŽ - http://www.dotnetnuke.com
  4. // Copyright (c) 2002-2012
  5. // by DotNetNuke Corporation
  6. //
  7. // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
  8. // documentation files (the "Software"), to deal in the Software without restriction, including without limitation
  9. // the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
  10. // to permit persons to whom the Software is furnished to do so, subject to the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be included in all copies or substantial portions
  13. // of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
  16. // TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  17. // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
  18. // CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  19. // DEALINGS IN THE SOFTWARE.
  20. #endregion
  21. #region Usings
  22. using System.Web;
  23. using System.Web.UI.WebControls;
  24. using DotNetNuke.Common.Utilities;
  25. #endregion
  26. namespace DotNetNuke.UI.WebControls
  27. {
  28. /// -----------------------------------------------------------------------------
  29. /// Project: DotNetNuke
  30. /// Namespace: DotNetNuke.UI.WebControls
  31. /// Class: DNNMultiStateBoxColumn
  32. /// -----------------------------------------------------------------------------
  33. /// <summary>
  34. /// The DNNMultiStateBoxColumn control provides a DNNMultiState Box column for a Data Grid
  35. /// </summary>
  36. /// <history>
  37. /// [cnurse] 02/16/2006 created
  38. /// </history>
  39. /// -----------------------------------------------------------------------------
  40. public class DNNMultiStateBoxColumn : TemplateColumn
  41. {
  42. private bool mAutoPostBack = true;
  43. private string mDataField = Null.NullString;
  44. private bool mEnabled = true;
  45. private string mEnabledField = Null.NullString;
  46. private string mImagePath = "";
  47. private string mSelectedStateKey = "";
  48. private DNNMultiStateCollection mStates;
  49. /// -----------------------------------------------------------------------------
  50. /// <summary>
  51. /// Constructs the DNNMultiStateBoxColumn
  52. /// </summary>
  53. /// <history>
  54. /// [cnurse] 02/16/2006 Created
  55. /// </history>
  56. /// -----------------------------------------------------------------------------
  57. public DNNMultiStateBoxColumn() : this(false)
  58. {
  59. }
  60. /// -----------------------------------------------------------------------------
  61. /// <summary>
  62. /// Constructs the MultiStateBoxColumn, with an optional AutoPostBack (where each change
  63. /// of state of the control causes a Post Back)
  64. /// </summary>
  65. /// <param name="autoPostBack">Optional set the control to postback</param>
  66. /// <history>
  67. /// [cnurse] 02/16/2006 Created
  68. /// </history>
  69. /// -----------------------------------------------------------------------------
  70. public DNNMultiStateBoxColumn(bool autoPostBack)
  71. {
  72. AutoPostBack = autoPostBack;
  73. }
  74. /// -----------------------------------------------------------------------------
  75. /// <summary>
  76. /// Gets and sets whether the column fires a postback when the control changes
  77. /// </summary>
  78. /// <value>A Boolean</value>
  79. /// <history>
  80. /// [cnurse] 02/16/2006 Created
  81. /// </history>
  82. /// -----------------------------------------------------------------------------
  83. public bool AutoPostBack
  84. {
  85. get
  86. {
  87. return mAutoPostBack;
  88. }
  89. set
  90. {
  91. mAutoPostBack = value;
  92. }
  93. }
  94. /// -----------------------------------------------------------------------------
  95. /// <summary>
  96. /// Gets and sets the selected state of the DNNMultiStateBox (unless DataBound)
  97. /// </summary>
  98. /// <value>A Boolean</value>
  99. /// <history>
  100. /// [cnurse] 02/21/2006 Created
  101. /// </history>
  102. /// -----------------------------------------------------------------------------
  103. public string SelectedStateKey
  104. {
  105. get
  106. {
  107. return mSelectedStateKey;
  108. }
  109. set
  110. {
  111. mSelectedStateKey = value;
  112. }
  113. }
  114. /// -----------------------------------------------------------------------------
  115. /// <summary>
  116. /// The Data Field that the column should bind to
  117. /// changed
  118. /// </summary>
  119. /// <value>A Boolean</value>
  120. /// <history>
  121. /// [cnurse] 02/16/2006 Created
  122. /// </history>
  123. /// -----------------------------------------------------------------------------
  124. public string DataField
  125. {
  126. get
  127. {
  128. return mDataField;
  129. }
  130. set
  131. {
  132. mDataField = value;
  133. }
  134. }
  135. /// -----------------------------------------------------------------------------
  136. /// <summary>
  137. /// An flag that indicates whether the control is enabled (this is overridden if
  138. /// the EnabledField is set)
  139. /// changed
  140. /// </summary>
  141. /// <value>A Boolean</value>
  142. /// <history>
  143. /// [cnurse] 02/16/2006 Created
  144. /// </history>
  145. /// -----------------------------------------------------------------------------
  146. public bool Enabled
  147. {
  148. get
  149. {
  150. return mEnabled;
  151. }
  152. set
  153. {
  154. mEnabled = value;
  155. }
  156. }
  157. /// -----------------------------------------------------------------------------
  158. /// <summary>
  159. /// The Data Field that determines whether the control is Enabled
  160. /// changed
  161. /// </summary>
  162. /// <value>A String</value>
  163. /// <history>
  164. /// [cnurse] 02/16/2006 Created
  165. /// </history>
  166. /// -----------------------------------------------------------------------------
  167. public string EnabledField
  168. {
  169. get
  170. {
  171. return mEnabledField;
  172. }
  173. set
  174. {
  175. mEnabledField = value;
  176. }
  177. }
  178. /// -----------------------------------------------------------------------------
  179. /// <summary>
  180. /// Gets and sets the image path of the DNNMultiStateBox
  181. /// </summary>
  182. /// <value>A Boolean</value>
  183. /// <history>
  184. /// [cnurse] 02/21/2006 Created
  185. /// </history>
  186. /// -----------------------------------------------------------------------------
  187. public string ImagePath
  188. {
  189. get
  190. {
  191. return mImagePath;
  192. }
  193. set
  194. {
  195. mImagePath = value;
  196. }
  197. }
  198. /// -----------------------------------------------------------------------------
  199. /// <summary>
  200. /// Gets and sets the state collection of the DNNMultiStateBox
  201. /// </summary>
  202. /// <value>A Boolean</value>
  203. /// <history>
  204. /// [cnurse] 02/21/2006 Created
  205. /// </history>
  206. /// -----------------------------------------------------------------------------
  207. public DNNMultiStateCollection States
  208. {
  209. get
  210. {
  211. if (mStates == null)
  212. {
  213. mStates = new DNNMultiStateCollection(new DNNMultiStateBox());
  214. }
  215. return mStates;
  216. }
  217. set
  218. {
  219. mStates = value;
  220. }
  221. }
  222. /// -----------------------------------------------------------------------------
  223. /// <summary>
  224. /// Creates a DNNMultiStateBoxColumnTemplate
  225. /// </summary>
  226. /// <returns>A DNNMultiStateBoxColumnTemplate</returns>
  227. /// <history>
  228. /// [cnurse] 02/16/2006 created
  229. /// </history>
  230. /// -----------------------------------------------------------------------------
  231. private DNNMultiStateBoxColumnTemplate CreateTemplate(ListItemType type)
  232. {
  233. bool isDesignMode = false;
  234. if (HttpContext.Current == null)
  235. {
  236. isDesignMode = true;
  237. }
  238. var template = new DNNMultiStateBoxColumnTemplate(type);
  239. if (type != ListItemType.Header)
  240. {
  241. template.AutoPostBack = AutoPostBack;
  242. }
  243. template.DataField = DataField;
  244. template.Enabled = Enabled;
  245. template.EnabledField = EnabledField;
  246. template.ImagePath = ImagePath;
  247. foreach (DNNMultiState objState in States)
  248. {
  249. template.States.Add(objState);
  250. }
  251. template.SelectedStateKey = SelectedStateKey;
  252. if (type == ListItemType.Header)
  253. {
  254. template.Text = HeaderText;
  255. template.AutoPostBack = true;
  256. }
  257. template.DesignMode = isDesignMode;
  258. return template;
  259. }
  260. /// -----------------------------------------------------------------------------
  261. /// <summary>
  262. /// Initialises the Column
  263. /// </summary>
  264. /// <history>
  265. /// [cnurse] 02/16/2006 created
  266. /// </history>
  267. /// -----------------------------------------------------------------------------
  268. public override void Initialize()
  269. {
  270. ItemTemplate = CreateTemplate(ListItemType.Item);
  271. EditItemTemplate = CreateTemplate(ListItemType.EditItem);
  272. HeaderTemplate = CreateTemplate(ListItemType.Header);
  273. if (HttpContext.Current == null)
  274. {
  275. HeaderStyle.Font.Names = new[] {"Tahoma, Verdana, Arial"};
  276. HeaderStyle.Font.Size = new FontUnit("10pt");
  277. HeaderStyle.Font.Bold = true;
  278. }
  279. ItemStyle.HorizontalAlign = HorizontalAlign.Center;
  280. HeaderStyle.HorizontalAlign = HorizontalAlign.Center;
  281. }
  282. }
  283. }