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