PageRenderTime 83ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/Epi Info 7.1.4.0 Release - Web Enter Integration/Epi.ImportExport/Epi2000/View.cs

#
C# | 462 lines | 293 code | 47 blank | 122 comment | 14 complexity | 5135d2fd71f05141cbd366dfac759d92 MD5 | raw file
  1. using System;
  2. using System.Data;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using Epi.Collections;
  6. namespace Epi.Epi2000
  7. {
  8. /// <summary>
  9. /// A view in Epi2000 format
  10. /// </summary>
  11. public class View
  12. {
  13. #region Fields
  14. private string name = string.Empty;
  15. private bool isRelatedView = false;
  16. private bool isWideTableView = false;
  17. private string checkCodeVariableDefinitions = string.Empty;
  18. private string checkCodeBefore = string.Empty;
  19. private string checkCodeAfter = string.Empty;
  20. private string recordCheckCodeBefore = string.Empty;
  21. private string recordCheckCodeAfter = string.Empty;
  22. //private bool mustRefreshFieldCollection = false;
  23. //private string dataTableName = string.Empty;
  24. private List<string> dataTableNames = new List<string>();
  25. private int id = 0;
  26. private Epi2000.View parentView;
  27. /// <summary>
  28. /// Collection of all pages of the view
  29. /// </summary>
  30. protected List<Page> pages = null;
  31. /// <summary>
  32. /// Project this view is part of.
  33. /// </summary>
  34. protected Project project;
  35. #endregion Fields
  36. #region Constructors
  37. /// <summary>
  38. /// Default constructor for a View
  39. /// </summary>
  40. public View()
  41. {
  42. }
  43. /// <summary>
  44. /// Constructor to build a view from a Epi 2000 project
  45. /// </summary>
  46. /// <param name="proj"></param>
  47. public View(Project proj)
  48. {
  49. project = proj;
  50. }
  51. /// <summary>
  52. /// Copy a view
  53. /// </summary>
  54. /// <param name="other"></param>
  55. public void CopyTo(Epi.View other)
  56. {
  57. other.Name = this.NameWithoutPrefix;
  58. other.IsRelatedView = this.IsRelatedView;
  59. /*
  60. other.CheckCodeVariableDefinitions = this.CheckCodeVariableDefinitions;
  61. other.CheckCodeBefore = this.CheckCodeBefore;
  62. other.WebSurveyId = this.CheckCodeAfter;
  63. other.RecordCheckCodeBefore = this.RecordCheckCodeBefore;
  64. other.RecordCheckCodeAfter = this.RecordCheckCodeAfter;
  65. other.IsRelatedView = this.IsRelatedView;*/
  66. }
  67. /// <summary>
  68. /// Constructs a new view from a data row
  69. /// </summary>
  70. /// <param name="row">Data row containing view information</param>
  71. /// <param name="proj"></param>
  72. public View(DataRow row, Project proj)
  73. {
  74. project = proj;
  75. Name = row[ColumnNames.NAME].ToString();
  76. System.Text.StringBuilder CheckCode = new System.Text.StringBuilder();
  77. // DefineVariable CheckCode Block
  78. if (!string.IsNullOrEmpty(row[ColumnNames.CHECK_CODE_VARIABLE_DEFINITIONS].ToString()))
  79. {
  80. CheckCode.Append("\nDefineVariables\n\t");
  81. CheckCode.Append(row[ColumnNames.CHECK_CODE_VARIABLE_DEFINITIONS].ToString().Replace("\n","\n\t\t"));
  82. CheckCode.Append("\nEnd-DefineVariables");
  83. }
  84. // View CheckCode Block
  85. if (
  86. (!string.IsNullOrEmpty(row[ColumnNames.CHECK_CODE_BEFORE].ToString()))
  87. ||
  88. (!string.IsNullOrEmpty(row[ColumnNames.CHECK_CODE_AFTER].ToString()))
  89. )
  90. {
  91. CheckCode.Append("\nView\n\t");
  92. if (!string.IsNullOrEmpty(row[ColumnNames.CHECK_CODE_BEFORE].ToString()))
  93. {
  94. CheckCode.Append("Before\n\t\t");
  95. //CheckCodeBefore = row[ColumnNames.CHECK_CODE_BEFORE].ToString().Replace("\n", "\n\t\t\t");
  96. CheckCode.Append(row[ColumnNames.CHECK_CODE_BEFORE].ToString().Replace("\n", "\n\t\t\t"));
  97. CheckCode.Append("\n\tEnd-Before\n");
  98. }
  99. if (!string.IsNullOrEmpty(row[ColumnNames.CHECK_CODE_AFTER].ToString()))
  100. {
  101. CheckCode.Append("After\n\t\t");
  102. //CheckCodeAfter = row[ColumnNames.CHECK_CODE_AFTER].ToString().Replace("\n", "\n\t\t\t");
  103. CheckCode.Append(row[ColumnNames.CHECK_CODE_AFTER].ToString().Replace("\n", "\n\t\t\t"));
  104. CheckCode.Append("\n\tEnd-After\n\t\t");
  105. }
  106. CheckCode.Append("\nEnd-View");
  107. }
  108. // Record CheckCode Block
  109. if (
  110. (!string.IsNullOrEmpty(row[ColumnNames.RECORD_CHECK_CODE_BEFORE].ToString()))
  111. ||
  112. (!string.IsNullOrEmpty(row[ColumnNames.RECORD_CHECK_CODE_AFTER].ToString()))
  113. )
  114. {
  115. CheckCode.Append("\nRecord\n\t");
  116. if (!string.IsNullOrEmpty(row[ColumnNames.RECORD_CHECK_CODE_BEFORE].ToString()))
  117. {
  118. CheckCode.Append("Before\n\t\t");
  119. //CheckCodeBefore = row[ColumnNames.RECORD_CHECK_CODE_BEFORE].ToString().Replace("\n", "\n\t\t\t");
  120. CheckCode.Append(row[ColumnNames.RECORD_CHECK_CODE_BEFORE].ToString().Replace("\n", "\n\t\t\t"));
  121. CheckCode.Append("\n\tEnd-Before\n");
  122. }
  123. if (!string.IsNullOrEmpty(row[ColumnNames.RECORD_CHECK_CODE_AFTER].ToString()))
  124. {
  125. CheckCode.Append("After\n\t\t");
  126. //CheckCodeAfter = row[ColumnNames.RECORD_CHECK_CODE_AFTER].ToString().Replace("\n", "\n\t\t\t");
  127. CheckCode.Append(row[ColumnNames.RECORD_CHECK_CODE_AFTER].ToString().Replace("\n", "\n\t\t\t"));
  128. CheckCode.Append("\n\tEnd-After\n\t\t");
  129. }
  130. CheckCode.Append("\nEnd-Record");
  131. }
  132. CheckCodeBefore = CheckCode.ToString();
  133. /*
  134. CheckCodeVariableDefinitions = row[ColumnNames.CHECK_CODE_VARIABLE_DEFINITIONS].ToString();
  135. CheckCodeBefore = row[ColumnNames.CHECK_CODE_BEFORE].ToString();
  136. CheckCodeAfter = row[ColumnNames.CHECK_CODE_AFTER].ToString();
  137. RecordCheckCodeBefore = row[ColumnNames.RECORD_CHECK_CODE_BEFORE].ToString();
  138. RecordCheckCodeAfter = row[ColumnNames.RECORD_CHECK_CODE_AFTER].ToString();*/
  139. // dataTableName = row[ColumnNames.DATA_TABLE_NAME].ToString();
  140. dataTableNames.Add(row[ColumnNames.DATA_TABLE_NAME].ToString());
  141. if (dataTableNames[0].Contains(";"))
  142. {
  143. IsWideTableView = true;
  144. string[] tableNames = dataTableNames[0].Split(';');
  145. dataTableNames.Clear();
  146. foreach (string s in tableNames)
  147. {
  148. dataTableNames.Add(s);
  149. }
  150. }
  151. }
  152. #endregion Constructors
  153. #region Public Properties
  154. /// <summary>
  155. /// Returns the name of the view
  156. /// </summary>
  157. public string Name
  158. {
  159. get
  160. {
  161. return (name);
  162. }
  163. set
  164. {
  165. name = value;
  166. }
  167. }
  168. /// <summary>
  169. /// Gets the name of the view's data table
  170. /// </summary>
  171. public string TableName
  172. {
  173. get
  174. {
  175. if (TableNames.Count <= 0)
  176. {
  177. return string.Empty;
  178. }
  179. else
  180. {
  181. return TableNames[0];
  182. }
  183. }
  184. }
  185. /// <summary>
  186. /// Gets the names of all the view's data tables
  187. /// </summary>
  188. public List<string> TableNames
  189. {
  190. get
  191. {
  192. return dataTableNames;
  193. }
  194. }
  195. /// <summary>
  196. /// /// Returns the name of the view with the prefix
  197. /// </summary>
  198. public string NameWithPrefix
  199. {
  200. get
  201. {
  202. if (Name.ToLower().StartsWith("view"))
  203. {
  204. return Name;
  205. }
  206. else
  207. {
  208. return ("view" + Name);
  209. }
  210. }
  211. }
  212. /// <summary>
  213. /// /// Returns the name of the view without the prefix
  214. /// </summary>
  215. public string NameWithoutPrefix
  216. {
  217. get
  218. {
  219. if (Name.ToLower().StartsWith("view"))
  220. {
  221. return Name.Substring(4);
  222. }
  223. else
  224. {
  225. return Name;
  226. }
  227. }
  228. }
  229. /// <summary>
  230. /// Gets or sets the IsRelatedView attribute
  231. /// </summary>
  232. public bool IsRelatedView
  233. {
  234. get
  235. {
  236. return (isRelatedView);
  237. }
  238. set
  239. {
  240. isRelatedView = value;
  241. }
  242. }
  243. /// <summary>
  244. /// Gets or sets the IsWideTableView attribute
  245. /// </summary>
  246. public bool IsWideTableView
  247. {
  248. get
  249. {
  250. return (isWideTableView);
  251. }
  252. set
  253. {
  254. isWideTableView = value;
  255. }
  256. }
  257. /// <summary>
  258. /// Gets or sets the CheckCodeVariableDefinitions attribute
  259. /// </summary>
  260. public string CheckCodeVariableDefinitions
  261. {
  262. get
  263. {
  264. return (checkCodeVariableDefinitions);
  265. }
  266. set
  267. {
  268. checkCodeVariableDefinitions = value;
  269. }
  270. }
  271. /// <summary>
  272. /// Gets or sets the CheckCodeAfter attribute
  273. /// </summary>
  274. public string CheckCodeAfter
  275. {
  276. get
  277. {
  278. return (checkCodeAfter);
  279. }
  280. set
  281. {
  282. checkCodeAfter = value;
  283. }
  284. }
  285. /// <summary>
  286. /// Gets or sets the CheckCodeBefore attribute
  287. /// </summary>
  288. public string CheckCodeBefore
  289. {
  290. get
  291. {
  292. return (checkCodeBefore);
  293. }
  294. set
  295. {
  296. checkCodeBefore = value;
  297. }
  298. }
  299. /// <summary>
  300. /// Gets or sets the CheckCodeAfter attribute
  301. /// </summary>
  302. public string RecordCheckCodeAfter
  303. {
  304. get
  305. {
  306. return (recordCheckCodeAfter);
  307. }
  308. set
  309. {
  310. recordCheckCodeAfter = value;
  311. }
  312. }
  313. /// <summary>
  314. /// Gets or sets the RecordCheckCodeBefore attribute
  315. /// </summary>
  316. public string RecordCheckCodeBefore
  317. {
  318. get
  319. {
  320. return (recordCheckCodeBefore);
  321. }
  322. set
  323. {
  324. recordCheckCodeBefore = value;
  325. }
  326. }
  327. //public string FullName
  328. //{
  329. // get
  330. // {
  331. // return (Project.FullName + StringLiterals.COLON + this.Name);
  332. // }
  333. //}
  334. ///// <summary>
  335. ///// Overrides TableName property value
  336. ///// </summary>
  337. ///// <param name="tableName"></param>
  338. //public void SetTableName(string tableName)
  339. //{
  340. // this.TableName = tableName;
  341. //}
  342. /// <summary>
  343. /// Gets or sets the Id attribute
  344. /// </summary>
  345. public virtual int Id
  346. {
  347. get
  348. {
  349. return id;
  350. }
  351. set
  352. {
  353. id = value;
  354. }
  355. }
  356. /// <summary>
  357. /// View that this view is related to if IsRelatedView = true.
  358. /// </summary>
  359. public View ParentView
  360. {
  361. get { return parentView; }
  362. set { parentView = value; }
  363. }
  364. /// <summary>
  365. /// Returns a collection of all pages of the view
  366. /// </summary>
  367. public List<Page> Pages
  368. {
  369. get
  370. {
  371. if (pages == null)
  372. {
  373. // pages = GetMetadata().GetViewPages(this);
  374. pages = this.project.Metadata.GetViewPages(this);
  375. }
  376. return (pages);
  377. }
  378. }
  379. #endregion Public Methods
  380. #region Public Methods
  381. /// <summary>
  382. /// Returns the project object
  383. /// </summary>
  384. /// <returns></returns>
  385. public Epi2000.Project GetProject()
  386. {
  387. return (Epi2000.Project)project;
  388. }
  389. /// <summary>
  390. /// Gets the record count for the current view
  391. /// </summary>
  392. /// <returns>Record count</returns>
  393. public int GetRecordCount()
  394. {
  395. return (this.GetProject().CollectedData.GetRecordCount(this));
  396. }
  397. /// <summary>
  398. /// Strips the view name of it's prefix.
  399. /// </summary>
  400. /// <param name="viewName"></param>
  401. /// <returns></returns>
  402. public static string StripViewNameOfPrefix(string viewName)
  403. {
  404. if (viewName.ToLower().StartsWith("view"))
  405. {
  406. return viewName.Substring(4);
  407. }
  408. else
  409. {
  410. return (viewName);
  411. }
  412. }
  413. #endregion Public Methods
  414. }
  415. }