PageRenderTime 145ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/Epi Info 7.1.4.0 Release - Web Enter Integration/Epi.Core/Services/Fields/OptionField.cs

#
C# | 296 lines | 209 code | 32 blank | 55 comment | 7 complexity | e6ea664c2986413f337d513e6b2c531a MD5 | raw file
  1. using System;
  2. using System.ComponentModel;
  3. using System.Data;
  4. using System.Collections.Specialized;
  5. using System.Collections.Generic;
  6. using System.Xml;
  7. using Epi;
  8. using Epi.Collections;
  9. using Epi.Data;
  10. using Epi.Data.Services;
  11. namespace Epi.Fields
  12. {
  13. /// <summary>
  14. /// Option Field
  15. /// </summary>
  16. public class OptionField : InputFieldWithoutSeparatePrompt, IFieldWithCheckCodeAfter, IFieldWithCheckCodeClick
  17. {
  18. #region Private Class Members
  19. private XmlElement viewElement;
  20. private XmlNode fieldNode;
  21. private bool showTextOnRight = true;
  22. private string checkCodeAfter = string.Empty;
  23. private string checkCodeClick = string.Empty;
  24. private string pattern = string.Empty;
  25. private string locations = string.Empty;
  26. private List<string> options = null;
  27. private BackgroundWorker _updater;
  28. private BackgroundWorker _inserter;
  29. #endregion
  30. #region Public Events
  31. #endregion
  32. #region Constructors
  33. /// <summary>
  34. /// OptionField Constructor
  35. /// </summary>
  36. /// <param name="page"><see cref="Epi.View"/> <see cref="Epi.Page"/> object.</param>
  37. public OptionField(Page page)
  38. : base(page)
  39. {
  40. genericDbColumnType = GenericDbColumnType.Int16;
  41. dbColumnType = DbType.Int16;
  42. }
  43. /// <summary>
  44. /// OptionField Constructor
  45. /// </summary>
  46. /// <param name="view"><see cref="Epi.Project"/> <see cref="Epi.View"/> object.</param>
  47. public OptionField(View view)
  48. : base(view)
  49. {
  50. genericDbColumnType = GenericDbColumnType.Int16;
  51. dbColumnType = DbType.Int16;
  52. }
  53. /// <summary>
  54. /// OptionField Constructor
  55. /// </summary>
  56. /// <param name="page"><see cref="Epi.View"/> <see cref="Epi.Page"/> object.</param>
  57. /// <param name="viewElement">View data represented as an XML element.</param>
  58. public OptionField(Page page, XmlElement viewElement)
  59. : base(page)
  60. {
  61. this.viewElement = viewElement;
  62. this.Page = page;
  63. }
  64. /// <summary>
  65. /// OptionField Constructor
  66. /// </summary>
  67. /// <param name="view"><see cref="Epi.Project"/> <see cref="Epi.View"/> object.</param>
  68. /// <param name="fieldNode">OptionField data represented as an XML node.</param>
  69. public OptionField(View view, XmlNode fieldNode)
  70. : base(view)
  71. {
  72. this.fieldNode = fieldNode;
  73. this.view.Project.Metadata.GetFieldData(this, this.fieldNode);
  74. }
  75. /// <summary>
  76. /// Load OptionField data from data row.
  77. /// </summary>
  78. /// <param name="row">A row of data in a <see cref="System.Data.DataTable"/>.</param>
  79. public override void LoadFromRow(DataRow row)
  80. {
  81. base.LoadFromRow(row);
  82. showTextOnRight = (bool)row["ShowTextOnRight"];
  83. pattern = string.Empty;
  84. if (row["Pattern"] is string)
  85. {
  86. pattern = (string)row["Pattern"];
  87. }
  88. string list = row["List"].ToString();
  89. if (list.Contains("||"))
  90. {
  91. list = list.Substring(0, list.IndexOf("||"));
  92. }
  93. string[] listArray = (list).Split(',');
  94. this.options = new List<string>(listArray);
  95. }
  96. public OptionField Clone()
  97. {
  98. OptionField clone = (OptionField)this.MemberwiseClone();
  99. base.AssignMembers(clone);
  100. return clone;
  101. }
  102. #endregion Constructors
  103. #region Public Properties
  104. /// <summary>
  105. /// Returns field type
  106. /// </summary>
  107. public override MetaFieldType FieldType
  108. {
  109. get
  110. {
  111. return MetaFieldType.Option;
  112. }
  113. }
  114. /// <summary>
  115. /// Returns a fully-typed current record value
  116. /// </summary>
  117. public string CurrentRecordValue
  118. {
  119. get
  120. {
  121. if (base.CurrentRecordValueObject == null) return string.Empty;
  122. else return CurrentRecordValueObject.ToString();
  123. }
  124. set
  125. {
  126. base.CurrentRecordValueObject = value;
  127. }
  128. }
  129. /// <summary>
  130. /// Gets/sets the Show Text on Right flag.
  131. /// </summary>
  132. public bool ShowTextOnRight
  133. {
  134. get
  135. {
  136. return (showTextOnRight);
  137. }
  138. set
  139. {
  140. showTextOnRight = value;
  141. }
  142. }
  143. /// <summary>
  144. /// Gets/sets the after Check Code.
  145. /// </summary>
  146. public string CheckCodeAfter
  147. {
  148. get
  149. {
  150. return (checkCodeAfter);
  151. }
  152. set
  153. {
  154. checkCodeAfter = value;
  155. }
  156. }
  157. /// <summary>
  158. /// Gets/sets the click Check Code.
  159. /// </summary>
  160. public string CheckCodeClick
  161. {
  162. get
  163. {
  164. return (checkCodeClick);
  165. }
  166. set
  167. {
  168. checkCodeClick = value;
  169. }
  170. }
  171. public string Pattern
  172. {
  173. get { return pattern; }
  174. set { pattern = value; }
  175. }
  176. public string Locations
  177. {
  178. get { return locations; }
  179. set { locations = value; }
  180. }
  181. /// <summary>
  182. /// Gets/sets the options collection
  183. /// </summary>
  184. public List<string> Options
  185. {
  186. get
  187. {
  188. if (options == null)
  189. {
  190. return new List<string>();
  191. }
  192. else
  193. {
  194. return options;
  195. }
  196. }
  197. set
  198. {
  199. this.options = value;
  200. }
  201. }
  202. #endregion
  203. #region Protected Properties
  204. #endregion Protected Properties
  205. #region Public Methods
  206. public override string GetDbSpecificColumnType()
  207. {
  208. return GetProject().CollectedData.GetDatabase().GetDbSpecificColumnType(GenericDbColumnType.Int16);
  209. }
  210. /// <summary>
  211. /// Deletes the field
  212. /// </summary>
  213. public override void Delete()
  214. {
  215. GetMetadata().DeleteField(this);
  216. view.MustRefreshFieldCollection = true;
  217. }
  218. public string GetOptionsString()
  219. {
  220. string optionsString = string.Empty;
  221. foreach (string option in Options)
  222. {
  223. optionsString = optionsString + option + ',';
  224. }
  225. optionsString = optionsString.TrimEnd(new char[] { ',' });
  226. optionsString = optionsString + "||" + locations;
  227. return optionsString;
  228. }
  229. /// <summary>
  230. /// The view element of the field
  231. /// </summary>
  232. public XmlElement ViewElement
  233. {
  234. get
  235. {
  236. return viewElement;
  237. }
  238. set
  239. {
  240. viewElement = value;
  241. }
  242. }
  243. #endregion
  244. #region Protected Methods
  245. /// <summary>
  246. /// Inserts the field to the database
  247. /// </summary>
  248. protected override void InsertField()
  249. {
  250. this.Id = GetMetadata().CreateField(this);
  251. base.OnFieldAdded();
  252. }
  253. /// <summary>
  254. /// Update the field to the database
  255. /// </summary>
  256. protected override void UpdateField()
  257. {
  258. GetMetadata().UpdateField(this);
  259. }
  260. #endregion Protected Methods
  261. #region Event Handlers
  262. #endregion Event Handlers
  263. }
  264. }