MainView.cs 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using System.ServiceModel;
  10. using System.Threading;
  11. using System.Configuration;
  12. namespace Aitex.Core.Backend
  13. {
  14. public partial class MainView : Form
  15. {
  16. private NotifyIcon _notifyIcon = new NotifyIcon();
  17. Dictionary<string,UserControl> _views;
  18. object _msgLock = new object();
  19. List<string> _events = new List<string>();
  20. public MainView()
  21. {
  22. InitializeComponent();
  23. _views = new Dictionary<string, UserControl>();
  24. _views.Add("ABOUT_CONFIG",new About());
  25. _views.Add("IO_CONFIG",new IoDataView());
  26. _views.Add("PUMP_CONFIG", new PumpView());
  27. _views.Add("DEVICE_CONFIG", new DeviceConfigBackendView());
  28. _views.Add("SYSTEM_CONFIG", new SystemConfigView());
  29. //_views.Add("INTERLOCK_CONFIG", new SwInterlock());
  30. _views.Add("LICENSE_CONFIG", new LicenseView());
  31. foreach(var item in _views)
  32. splitContainer2.Panel2.Controls.Add(item.Value);
  33. ////defaut view
  34. ShowView("ABOUT_CONFIG");
  35. _timer.Interval = 250;
  36. _timer.AutoReset = true;
  37. _timer.Elapsed += new System.Timers.ElapsedEventHandler(_timer_Elapsed);
  38. Load += new EventHandler(MainView_Load);
  39. VisibleChanged += new EventHandler(MainView_VisibleChanged);
  40. this.SizeChanged += new EventHandler(MainView_SizeChanged);
  41. }
  42. void MainView_SizeChanged(object sender, EventArgs e)
  43. {
  44. foreach (var item in _views)
  45. {
  46. item.Value.Width = this.splitContainer1.Panel2.Width;
  47. item.Value.Height = this.splitContainer1.Panel2.Height;
  48. }
  49. }
  50. void MainView_VisibleChanged(object sender, EventArgs e)
  51. {
  52. if (!Visible)
  53. {
  54. _timer.Stop();
  55. }
  56. else
  57. {
  58. _timer.Start();
  59. }
  60. }
  61. System.Timers.Timer _timer = new System.Timers.Timer();
  62. void _timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
  63. {
  64. Action act = () =>
  65. {
  66. if (_events.Count > 0)
  67. {
  68. List<string> list1 = null;
  69. lock (_msgLock)
  70. {
  71. list1 = _events.ToList();
  72. _events.Clear();
  73. }
  74. //while (listBox_Event.Items.Count > 10)
  75. // listBox_Event.Items.RemoveAt(0);
  76. //if (list1 != null)
  77. //{
  78. // listBox_Event.Items.AddRange(list1.ToArray());
  79. // listBox_Event.SelectedIndex = listBox_Event.Items.Count - 1;
  80. //}
  81. }
  82. };
  83. BeginInvoke(act);
  84. }
  85. /// <summary>
  86. /// 当用户登录后台时在窗体左上角标题栏显示当前反应腔的设备编号
  87. /// </summary>
  88. /// <param name="sender"></param>
  89. /// <param name="e"></param>
  90. void MainView_Load(object sender, EventArgs e)
  91. {
  92. //this.Text = string.Format("{0}【{1}】后台界面登入", Reactor.PmName, Reactor.Config.VariationName);
  93. }
  94. /// <summary>
  95. /// 不允许用户直接关闭后台界面窗口程序,退出PM程序必须通过点击任务栏图标实现程序退出
  96. /// </summary>
  97. /// <param name="e"></param>
  98. protected override void OnFormClosing(FormClosingEventArgs e)
  99. {
  100. if (e.CloseReason == CloseReason.UserClosing)
  101. {
  102. e.Cancel = true;
  103. Hide();
  104. return;
  105. }
  106. }
  107. public void StopUpdate()
  108. {
  109. (_views["IO_CONFIG"] as IoDataView).Close();
  110. _timer.Stop();
  111. }
  112. public void AddCustomView(string name, UserControl uc)
  113. {
  114. if (uc == null)
  115. return;
  116. this.treeView1.Nodes.Add(new TreeNode() { Tag = name, Text = name });
  117. uc.Hide();
  118. _views.Add(name, uc);
  119. splitContainer2.Panel2.Controls.Add(uc);
  120. uc.Width = splitContainer2.Panel2.Width;
  121. uc.Height = splitContainer2.Panel2.Height;
  122. }
  123. /// <summary>
  124. /// disable close box on the title bar
  125. /// </summary>
  126. protected override CreateParams CreateParams
  127. {
  128. get
  129. {
  130. int CS_NOCLOSE = 0x200;
  131. CreateParams parameters = base.CreateParams;
  132. parameters.ClassStyle |= CS_NOCLOSE;
  133. return parameters;
  134. }
  135. }
  136. /// <summary>
  137. /// 显示对应的视图界面
  138. /// </summary>
  139. /// <param name="viewName"></param>
  140. private void ShowView(string viewName)
  141. {
  142. foreach (var item in _views)
  143. {
  144. if (item.Key != viewName)
  145. item.Value.Hide();
  146. else
  147. item.Value.Show();
  148. }
  149. }
  150. /// <summary>
  151. /// PM腔页面切换事件处理
  152. /// </summary>
  153. /// <param name="sender"></param>
  154. /// <param name="e"></param>
  155. private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
  156. {
  157. var viewName = (string)e.Node.Tag;
  158. ShowView(viewName);
  159. }
  160. /// <summary>
  161. /// 退出PM后台服务界面
  162. /// </summary>
  163. /// <param name="sender"></param>
  164. /// <param name="e"></param>
  165. private void btnLogout_Click(object sender, EventArgs e)
  166. {
  167. Hide();
  168. }
  169. /// <summary>
  170. /// 单独复位当前反应腔
  171. /// </summary>
  172. /// <param name="sender"></param>
  173. /// <param name="e"></param>
  174. private void SysReset_Click(object sender, EventArgs e)
  175. {
  176. //Reactor.PostEvent(new Command.ResetCommand());
  177. }
  178. }
  179. }