PageRenderTime 45ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/BlogEngine/DotNetSlave.BusinessLogic/Web/Extensions/ExtensionParameter.cs

#
C# | 260 lines | 116 code | 37 blank | 107 comment | 12 complexity | b43c474169cd5fe14f643ce1ca7b9a5f MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0, BSD-3-Clause
  1. namespace BlogEngine.Core.Web.Extensions
  2. {
  3. using System;
  4. using System.Collections.Specialized;
  5. using System.Xml.Serialization;
  6. /// <summary>
  7. /// Enumeration for parameter data types
  8. /// </summary>
  9. [Flags]
  10. public enum ParameterType
  11. {
  12. /// <summary>
  13. /// The string.
  14. /// </summary>
  15. String,
  16. /// <summary>
  17. /// The boolean.
  18. /// </summary>
  19. Boolean,
  20. /// <summary>
  21. /// The integer.
  22. /// </summary>
  23. Integer,
  24. /// <summary>
  25. /// The long number.
  26. /// </summary>
  27. Long,
  28. /// <summary>
  29. /// The float.
  30. /// </summary>
  31. Float,
  32. /// <summary>
  33. /// The double.
  34. /// </summary>
  35. Double,
  36. /// <summary>
  37. /// The decimal.
  38. /// </summary>
  39. Decimal,
  40. /// <summary>
  41. /// The drop down.
  42. /// </summary>
  43. DropDown,
  44. /// <summary>
  45. /// The list box.
  46. /// </summary>
  47. ListBox,
  48. /// <summary>
  49. /// The radio group.
  50. /// </summary>
  51. RadioGroup
  52. }
  53. /// <summary>
  54. /// Extension Parameter - serializable object
  55. /// that holds parameter attributes and collection
  56. /// of values
  57. /// </summary>
  58. [Serializable]
  59. public class ExtensionParameter
  60. {
  61. #region Constants and Fields
  62. /// <summary>
  63. /// The extension parameter name.
  64. /// </summary>
  65. private string name = string.Empty;
  66. #endregion
  67. #region Constructors and Destructors
  68. /// <summary>
  69. /// Initializes a new instance of the <see cref="ExtensionParameter"/> class.
  70. /// Default constructor required for serialization
  71. /// </summary>
  72. public ExtensionParameter()
  73. {
  74. this.SelectedValue = string.Empty;
  75. this.ParamType = ParameterType.String;
  76. this.MaxLength = 100;
  77. this.Label = string.Empty;
  78. }
  79. /// <summary>
  80. /// Initializes a new instance of the <see cref="ExtensionParameter"/> class.
  81. /// Constructor
  82. /// </summary>
  83. /// <param name="name">
  84. /// Parameter Name
  85. /// </param>
  86. public ExtensionParameter(string name)
  87. {
  88. this.SelectedValue = string.Empty;
  89. this.ParamType = ParameterType.String;
  90. this.MaxLength = 100;
  91. this.Label = string.Empty;
  92. this.name = name;
  93. }
  94. #endregion
  95. #region Properties
  96. /// <summary>
  97. /// Gets or sets a value indicating whether is Primary Key field
  98. /// </summary>
  99. [XmlElement]
  100. public bool KeyField { get; set; }
  101. /// <summary>
  102. /// Gets or sets Used as label in the UI controls
  103. /// </summary>
  104. [XmlElement]
  105. public string Label { get; set; }
  106. /// <summary>
  107. /// Gets or sets Maximum number of characters stored in the value fields
  108. /// </summary>
  109. [XmlElement]
  110. public int MaxLength { get; set; }
  111. /// <summary>
  112. /// Gets or sets Parameter Name, often used as ID in the UI
  113. /// </summary>
  114. [XmlElement]
  115. public string Name
  116. {
  117. get
  118. {
  119. return this.name;
  120. }
  121. set
  122. {
  123. this.name = value.Trim().Replace(" ", string.Empty);
  124. }
  125. }
  126. /// <summary>
  127. /// Gets or sets Parameter Type
  128. /// </summary>
  129. [XmlElement]
  130. //// [XmlElement(IsNullable = true)]
  131. public ParameterType ParamType { get; set; }
  132. /// <summary>
  133. /// Gets or sets a value indicating whether values for parameter required
  134. /// </summary>
  135. [XmlElement]
  136. public bool Required { get; set; }
  137. /// <summary>
  138. /// Gets or sets selected value in parameter lists (dropdown, listbox etc.)
  139. /// </summary>
  140. [XmlElement]
  141. public string SelectedValue { get; set; }
  142. /// <summary>
  143. /// Gets or sets a collection of values for given parameter
  144. /// </summary>
  145. [XmlElement]
  146. public StringCollection Values { get; set; }
  147. #endregion
  148. #region Public Methods
  149. /// <summary>
  150. /// Add single value to value collection
  151. /// </summary>
  152. /// <param name="val">
  153. /// String Value
  154. /// </param>
  155. public void AddValue(string val)
  156. {
  157. if (this.Values == null)
  158. {
  159. this.Values = new StringCollection();
  160. }
  161. this.Values.Add(val);
  162. }
  163. /// <summary>
  164. /// Add single value to collection
  165. /// </summary>
  166. /// <param name="val">
  167. /// Value object
  168. /// </param>
  169. public void AddValue(object val)
  170. {
  171. if (this.Values == null)
  172. {
  173. this.Values = new StringCollection();
  174. }
  175. this.Values.Add(val.ToString());
  176. }
  177. /// <summary>
  178. /// Delete value in parameter value collection
  179. /// </summary>
  180. /// <param name="rowIndex">
  181. /// Row Index.
  182. /// </param>
  183. public void DeleteValue(int rowIndex)
  184. {
  185. this.Values.RemoveAt(rowIndex);
  186. }
  187. /// <summary>
  188. /// Update value for scalar (single value) parameter
  189. /// </summary>
  190. /// <param name="val">
  191. /// Scalar Value
  192. /// </param>
  193. public void UpdateScalarValue(string val)
  194. {
  195. if (this.Values == null || this.Values.Count == 0)
  196. {
  197. this.AddValue(val);
  198. }
  199. else
  200. {
  201. this.Values[0] = val;
  202. }
  203. }
  204. /// <summary>
  205. /// Update value for scalar (single value) parameter
  206. /// </summary>
  207. /// <param name="val">
  208. /// Scalar Value
  209. /// </param>
  210. public void UpdateScalarValue(object val)
  211. {
  212. if (this.Values == null || this.Values.Count == 0)
  213. {
  214. this.AddValue(val);
  215. }
  216. else
  217. {
  218. this.Values[0] = val.ToString();
  219. }
  220. }
  221. #endregion
  222. }
  223. }