/Epi Info 7.1.4.0 Release - Web Enter Integration/Epi.Windows.Enter/Forms/ViewExplorer.cs

# · C# · 379 lines · 248 code · 57 blank · 74 comment · 42 complexity · 4a0b212fc3ae918758468463bd092db6 MD5 · raw file

  1. #region Namespaces
  2. using System;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.Drawing;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using Epi.Fields;
  10. using Epi.Windows;
  11. using Epi.Windows.Controls;
  12. using Epi.Windows.Enter.PresentationLogic;
  13. using Epi.EnterCheckCodeEngine;
  14. #endregion //Namespaces
  15. namespace Epi.Windows.Enter
  16. {
  17. #region Public Delegates
  18. /// <summary>
  19. /// Delegate for page selection
  20. /// </summary>
  21. /// <param name="page">The page that was selected</param>
  22. public delegate void ViewExplorerPageSelectedEventHandler(Page page);
  23. /// <summary>
  24. /// Delegate for first record selection
  25. /// </summary>
  26. public delegate void ViewExplorerGoToFirstRecordSelectedEventHandler();
  27. /// <summary>
  28. /// Delegate for previous record selection
  29. /// </summary>
  30. public delegate void ViewExplorerGoToPreviousRecordSelectedEventHandler();
  31. /// <summary>
  32. /// Delegate for next record selection
  33. /// </summary>
  34. public delegate void ViewExplorerGoToNextRecordSelectedEventHandler();
  35. /// <summary>
  36. /// Delegate for last record selection
  37. /// </summary>
  38. public delegate void ViewExplorerGoToLastRecordSelectedEventHandler();
  39. /// <summary>
  40. /// Delegate to load a specific record
  41. /// </summary>
  42. /// <param name="recordId">The record Id of the record to be loaded</param>
  43. public delegate void ViewExplorerLoadRecordSpecifiedEventHandler(string recordId);
  44. /// <summary>
  45. /// Delegate to run check code
  46. /// </summary>
  47. /// <param name="checkCode">Enter module check code.</param>
  48. public delegate void ViewExplorerRunCheckCodeEventHandler(string checkCode);
  49. #endregion //Public Delegates
  50. /// <summary>
  51. /// Enter's view explorer
  52. /// </summary>
  53. public partial class ViewExplorer : Epi.Windows.Docking.DockWindow
  54. {
  55. public event GuiMediator.OpenPageEventHandler OpenPageEvent;
  56. public event GuiMediator.ClosePageEventHandler ClosePageEvent;
  57. public event GuiMediator.GotoRecordEventHandler GotoRecordEvent;
  58. #region Private Members
  59. private Epi.Page currentPage = null;
  60. private RunTimeView view = null;
  61. #endregion
  62. #region Public Events
  63. /// <summary>
  64. /// Declaration of Load Record Specified Event Handler
  65. /// </summary>
  66. public event ViewExplorerLoadRecordSpecifiedEventHandler GoToSpecifiedRecord;
  67. #endregion
  68. #region Constructors
  69. /// <summary>
  70. /// Constructor for View Explorer
  71. /// </summary>
  72. public ViewExplorer(MainForm frm) : base(frm)
  73. {
  74. InitializeComponent();
  75. }
  76. #endregion //Constructors
  77. #region Private Methods
  78. #endregion Private Methods
  79. #region Public Methods
  80. /// <summary>
  81. /// Resets the view explorer to its original state
  82. /// </summary>
  83. public void Reset()
  84. {
  85. if (viewTree.Nodes.Count > 0)
  86. {
  87. viewTree.Nodes.Clear();
  88. }
  89. }
  90. /// <summary>
  91. /// Attach the view
  92. /// </summary>
  93. /// <param name="view">The view to be loaded</param>
  94. public void LoadView(RunTimeView view)
  95. {
  96. #region Input Validation
  97. if (view == null)
  98. {
  99. throw new ArgumentNullException("view");
  100. }
  101. #endregion Input validation
  102. Epi.Windows.Controls.ViewNode viewNode = new Epi.Windows.Controls.ViewNode(view.View);
  103. viewNode.ImageIndex = 76;
  104. viewNode.SelectedImageIndex = 76;
  105. viewTree.Nodes.Add(viewNode);
  106. foreach (PageNode page in viewTree.Nodes[0].Nodes)
  107. {
  108. page.ImageIndex = 17;
  109. page.SelectedImageIndex = 17;
  110. }
  111. viewTree.ExpandAll();
  112. this.view = view;
  113. }
  114. /// <summary>
  115. /// Attach the view
  116. /// </summary>
  117. /// <param name="pView">The view to be loaded</param>
  118. /// <param name="pPage">The Page to be loaded</param>
  119. public void LoadView(RunTimeView pView, Page pPage)
  120. {
  121. #region Input Validation
  122. if (view == null)
  123. {
  124. throw new ArgumentNullException("view");
  125. }
  126. #endregion Input validation
  127. Epi.Windows.Controls.ViewNode viewNode = new Epi.Windows.Controls.ViewNode(pView.View);
  128. viewTree.Nodes.Clear();
  129. viewNode.ImageIndex = 76;
  130. viewNode.SelectedImageIndex = 76;
  131. viewTree.Nodes.Add(viewNode);
  132. foreach (PageNode page in viewTree.Nodes[0].Nodes)
  133. {
  134. page.ImageIndex = 17;
  135. page.SelectedImageIndex = 17;
  136. }
  137. viewTree.ExpandAll();
  138. this.view = pView;
  139. for (int i = 0; i < viewTree.Nodes[0].Nodes.Count; i++)
  140. {
  141. PageNode page = (PageNode) viewTree.Nodes[0].Nodes[i];
  142. if (page.Text == pPage.Name)
  143. {
  144. viewTree.SelectedNode = viewTree.Nodes[0].Nodes[i];
  145. break;
  146. }
  147. }/**/
  148. }
  149. /// <summary>
  150. /// Selects a view based on view name
  151. /// </summary>
  152. /// <param name="viewName">The name of the view</param>
  153. public void SelectView(string viewName)
  154. {
  155. foreach (TreeNode node in viewTree.Nodes[0].Nodes)
  156. {
  157. if (node is ViewNode)
  158. {
  159. if (((ViewNode)node).View.Name.Equals(viewName))
  160. {
  161. if (node.Nodes.Count > 0)
  162. {
  163. viewTree.CollapseAll();
  164. viewTree.SelectedNode = node.Nodes[0];
  165. }
  166. }
  167. }
  168. }
  169. }
  170. /// <summary>
  171. /// Obtains the rec status
  172. /// </summary>
  173. /// <param name="recStatus">The record's status</param>
  174. /// <returns>The boolean form of the record status</returns>
  175. public bool GetRecStatus(int recStatus)
  176. {
  177. #region Input Validation
  178. if (recStatus < 0)
  179. {
  180. throw new ArgumentOutOfRangeException("Record Status");
  181. }
  182. #endregion //Input Validation
  183. if (recStatus == 0)
  184. {
  185. return (false);
  186. }
  187. else
  188. {
  189. return (true);
  190. }
  191. }
  192. /// <summary>
  193. /// Attach the next page of the view
  194. /// </summary>
  195. public void GoToNextPage()
  196. {
  197. if (viewTree.SelectedNode != viewTree.Nodes[0].LastNode)
  198. {
  199. viewTree.SelectedNode = viewTree.Nodes[0].Nodes[viewTree.SelectedNode.Index + 1];
  200. }
  201. }
  202. /// <summary>
  203. /// Navigate to the first page of the view
  204. /// </summary>
  205. public void GoToFirstPage()
  206. {
  207. if (viewTree.Nodes.Count > 0)
  208. {
  209. if (viewTree.SelectedNode != viewTree.Nodes[0].Nodes[0])
  210. {
  211. viewTree.SelectedNode = viewTree.Nodes[0].Nodes[0];
  212. }
  213. }
  214. }
  215. /// <summary>
  216. /// Navigate to the previous page of the view
  217. /// </summary>
  218. public void GoToPreviousPage()
  219. {
  220. if (viewTree.SelectedNode != viewTree.Nodes[0].Nodes[0])
  221. {
  222. viewTree.SelectedNode = viewTree.Nodes[0].Nodes[viewTree.SelectedNode.Index - 1];
  223. }
  224. }
  225. /// <summary>
  226. /// Navigate to a specific page of the view
  227. /// </summary>
  228. public void GoToSpecificPage(string pagePosition)
  229. {
  230. foreach (PageNode pageNode in viewTree.Nodes[0].Nodes)
  231. {
  232. if (pageNode.Page.Position == int.Parse(pagePosition))
  233. {
  234. viewTree.SelectedNode = pageNode;
  235. }
  236. }
  237. }
  238. public void Render()
  239. {
  240. if (this.currentPage != null)
  241. {
  242. PageNode SelectedNode = null;
  243. if (this.viewTree.SelectedNode is PageNode)
  244. {
  245. SelectedNode = (PageNode)this.viewTree.SelectedNode;
  246. }
  247. foreach (PageNode TestNode in this.viewTree.Nodes[0].Nodes)
  248. {
  249. if (TestNode.Page == this.currentPage)
  250. {
  251. if (TestNode != SelectedNode)
  252. {
  253. this.viewTree.SelectedNode = TestNode;
  254. }
  255. }
  256. }
  257. }
  258. }
  259. #endregion //Public Methods
  260. #region Private Events
  261. /// <summary>
  262. /// Handles the After Selection event of the tree view
  263. /// </summary>
  264. /// <param name="sender">Object that fired the event</param>
  265. /// <param name="e">Tree View supplied event parameters</param>
  266. private void viewTree_AfterSelect(object sender, TreeViewEventArgs e)
  267. {
  268. if (e.Node is PageNode)
  269. {
  270. if (this.currentPage != ((PageNode)e.Node).Page)
  271. {
  272. if (OpenPageEvent != null)
  273. {
  274. Page selectedPage = ((PageNode)e.Node).Page;
  275. if (this.currentPage.view.Name == ((PageNode)e.Node).Page.view.Name)
  276. {
  277. int pageId = ((PageNode)e.Node).Page.Id;
  278. foreach (Page page in currentPage.view.Pages)
  279. {
  280. if (page.Id == pageId)
  281. {
  282. selectedPage = page;
  283. break;
  284. }
  285. }
  286. }
  287. OpenPageEvent(this, new PageSelectedEventArgs(selectedPage));
  288. }
  289. }
  290. }
  291. }
  292. #endregion //Private Events
  293. #region Public Properties
  294. /// <summary>
  295. /// Gets the currently selected page
  296. /// </summary>
  297. public Page SelectedPage
  298. {
  299. get
  300. {
  301. if (viewTree.SelectedNode != null && viewTree.SelectedNode is PageNode)
  302. {
  303. return ((PageNode)viewTree.SelectedNode).Page;
  304. }
  305. else
  306. {
  307. return null;
  308. }
  309. }
  310. }
  311. public RunTimeView View
  312. {
  313. get { return this.view; }
  314. set { this.view = value; }
  315. }
  316. public Epi.Page CurrentPage
  317. {
  318. set { this.currentPage = value; }
  319. }
  320. #endregion //Public Properties
  321. }
  322. }