SECI  1
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Events
Help.cs
Go to the documentation of this file.
1 using System;
2 using System.Collections.Generic;
3 using System.ComponentModel;
4 using System.Data;
5 using System.Drawing;
6 using System.Text;
7 using System.Windows.Forms;
8 using System.Xml;
9 using System.IO;
10 
11 namespace Sample_Environment_Control_Interface.Dialogs.Help
12 {
13  public partial class HelpForm : Form
14  {
15  private Dictionary<String, String> _pages = new Dictionary<String, String>();
16 
17  private DirectoryInfo _helpDirectory;
18 
19  public HelpForm()
20  {
21  InitializeComponent();
22  }
23 
24  private void Help_Load(object sender, EventArgs e)
25  {
26  loadTreeViewXML();
27  loadInstrumentXML();
28 
29  treeView1.Refresh();
30  if (treeView1.Nodes != null && treeView1.Nodes.Count != 0)
31  {
32  treeView1_AfterSelect(this, new TreeViewEventArgs(treeView1.Nodes[0]));
33  }
34  }
35 
36  private void loadTreeViewXML()
37  {
38  try
39  {
40  treeView1.Nodes.Clear();
41 
42  XmlDocument dom = new XmlDocument();
43  String filepath = Seci.SeciInterface.SeciStatus.ExecutionDir + "/Help Contents/";
44  _helpDirectory = new DirectoryInfo(filepath);
45 
46  dom.Load(filepath + "TreeView.xml");
47 
48  //Select the top level categories
49  XmlNodeList nodelist = dom.SelectNodes("/contents/category");
50 
51  parseNodeList(nodelist);
52  }
53  catch (Exception ex)
54  {
55  MessageBox.Show("Could not open help files! Looking in " + _helpDirectory.FullName, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
56  Seci.SeciInterface.Error_LogError("loadTreeViewXML", ex);
57  }
58  }
59 
60  private void loadInstrumentXML()
61  {
62  try
63  {
64  XmlDocument dom = new XmlDocument();
65 
66  FileInfo fi = new FileInfo(_helpDirectory.FullName + "InstrumentHelp.xml");
67 
68  if (fi.Exists)
69  {
70  dom.Load(fi.FullName);
71 
72  //Select the top level categories
73  XmlNodeList nodelist = dom.SelectNodes("/contents/category");
74 
75  parseNodeList(nodelist);
76  }
77  else
78  {
79  //Create file
80  fi.Create();
81  StreamWriter sw = new StreamWriter(fi.FullName);
82 
83  try
84  {
85  sw.WriteLine("<?xml version=\"1.0\" encoding=\"utf-8\" ?>");
86  sw.WriteLine("<contents>");
87  sw.WriteLine("</contents>");
88  }
89  catch
90  {
91  }
92  finally
93  {
94  sw.Close();
95  }
96 
97  }
98  }
99  catch (Exception ex)
100  {
101  Seci.SeciInterface.Error_LogError("loadInstrumentXML", ex);
102  }
103  }
104 
105  private void parseNodeList(XmlNodeList nodelist)
106  {
107  foreach (XmlNode node in nodelist)
108  {
109  XmlDocument nodeDoc = new XmlDocument();
110  nodeDoc.LoadXml(node.OuterXml);
111 
112  String title = nodeDoc.SelectSingleNode("/category/title").InnerXml.Trim();
113  String page = nodeDoc.SelectSingleNode("/category/page").InnerXml.Trim();
114 
115  treeView1.Nodes.Add(title);
116 
117  _pages.Add(title, page);
118 
119  //Select the subcategories (if any)
120  XmlNodeList sublist = nodeDoc.SelectNodes("/category/subcategory");
121 
122  foreach (XmlNode sub in sublist)
123  {
124  XmlDocument subDoc = new XmlDocument();
125  subDoc.LoadXml(sub.OuterXml);
126 
127  String subTitle = subDoc.SelectSingleNode("/subcategory/title").InnerXml.Trim();
128  String subPage = subDoc.SelectSingleNode("/subcategory/page").InnerXml.Trim();
129 
130  treeView1.Nodes[treeView1.Nodes.Count - 1].Nodes.Add(subTitle);
131 
132  _pages.Add(subTitle, subPage);
133  }
134  }
135  }
136 
137  private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
138  {
139  try
140  {
141  if (_pages.ContainsKey(e.Node.Text))
142  {
143  String fileName = _pages[e.Node.Text].ToString();
144 
145  webBrowser1.Url = new Uri(_helpDirectory.FullName + _pages[e.Node.Text].ToString());
146  }
147  }
148  catch
149  {
150  MessageBox.Show("Could not find selected page.", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
151  }
152  }
153 
154  }
155 }
void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
Definition: Help.cs:137
void Help_Load(object sender, EventArgs e)
Definition: Help.cs:24