123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- using System.ServiceModel;
- using System.Threading;
- using System.Configuration;
- namespace Aitex.Core.Backend
- {
- public partial class MainView : Form
- {
- private NotifyIcon _notifyIcon = new NotifyIcon();
- Dictionary<string,UserControl> _views;
- object _msgLock = new object();
- List<string> _events = new List<string>();
- public MainView()
- {
- InitializeComponent();
- _views = new Dictionary<string, UserControl>();
- _views.Add("ABOUT_CONFIG",new About());
- _views.Add("IO_CONFIG",new IoDataView());
- _views.Add("PUMP_CONFIG", new PumpView());
- _views.Add("DEVICE_CONFIG", new DeviceConfigBackendView());
- _views.Add("SYSTEM_CONFIG", new SystemConfigView());
- //_views.Add("INTERLOCK_CONFIG", new SwInterlock());
- _views.Add("LICENSE_CONFIG", new LicenseView());
-
- foreach(var item in _views)
- splitContainer2.Panel2.Controls.Add(item.Value);
- ////defaut view
- ShowView("ABOUT_CONFIG");
- _timer.Interval = 250;
- _timer.AutoReset = true;
- _timer.Elapsed += new System.Timers.ElapsedEventHandler(_timer_Elapsed);
- Load += new EventHandler(MainView_Load);
- VisibleChanged += new EventHandler(MainView_VisibleChanged);
- this.SizeChanged += new EventHandler(MainView_SizeChanged);
- }
- void MainView_SizeChanged(object sender, EventArgs e)
- {
- foreach (var item in _views)
- {
- item.Value.Width = this.splitContainer1.Panel2.Width;
- item.Value.Height = this.splitContainer1.Panel2.Height;
- }
- }
- void MainView_VisibleChanged(object sender, EventArgs e)
- {
- if (!Visible)
- {
- _timer.Stop();
- }
- else
- {
- _timer.Start();
- }
- }
- System.Timers.Timer _timer = new System.Timers.Timer();
- void _timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
- {
- Action act = () =>
- {
- if (_events.Count > 0)
- {
- List<string> list1 = null;
- lock (_msgLock)
- {
- list1 = _events.ToList();
- _events.Clear();
- }
- //while (listBox_Event.Items.Count > 10)
- // listBox_Event.Items.RemoveAt(0);
- //if (list1 != null)
- //{
- // listBox_Event.Items.AddRange(list1.ToArray());
- // listBox_Event.SelectedIndex = listBox_Event.Items.Count - 1;
- //}
- }
- };
- BeginInvoke(act);
- }
- /// <summary>
- /// 当用户登录后台时在窗体左上角标题栏显示当前反应腔的设备编号
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- void MainView_Load(object sender, EventArgs e)
- {
- //this.Text = string.Format("{0}【{1}】后台界面登入", Reactor.PmName, Reactor.Config.VariationName);
- }
- /// <summary>
- /// 不允许用户直接关闭后台界面窗口程序,退出PM程序必须通过点击任务栏图标实现程序退出
- /// </summary>
- /// <param name="e"></param>
- protected override void OnFormClosing(FormClosingEventArgs e)
- {
- if (e.CloseReason == CloseReason.UserClosing)
- {
- e.Cancel = true;
- Hide();
- return;
- }
- }
- public void StopUpdate()
- {
- (_views["IO_CONFIG"] as IoDataView).Close();
- _timer.Stop();
- }
- public void AddCustomView(string name, UserControl uc)
- {
- if (uc == null)
- return;
- this.treeView1.Nodes.Add(new TreeNode() { Tag = name, Text = name });
- uc.Hide();
- _views.Add(name, uc);
- splitContainer2.Panel2.Controls.Add(uc);
- uc.Width = splitContainer2.Panel2.Width;
- uc.Height = splitContainer2.Panel2.Height;
- }
- /// <summary>
- /// disable close box on the title bar
- /// </summary>
- protected override CreateParams CreateParams
- {
- get
- {
- int CS_NOCLOSE = 0x200;
- CreateParams parameters = base.CreateParams;
- parameters.ClassStyle |= CS_NOCLOSE;
- return parameters;
- }
- }
- /// <summary>
- /// 显示对应的视图界面
- /// </summary>
- /// <param name="viewName"></param>
- private void ShowView(string viewName)
- {
- foreach (var item in _views)
- {
- if (item.Key != viewName)
- item.Value.Hide();
- else
- item.Value.Show();
- }
- }
- /// <summary>
- /// PM腔页面切换事件处理
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
- {
- var viewName = (string)e.Node.Tag;
- ShowView(viewName);
- }
- /// <summary>
- /// 退出PM后台服务界面
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btnLogout_Click(object sender, EventArgs e)
- {
- Hide();
- }
- /// <summary>
- /// 单独复位当前反应腔
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void SysReset_Click(object sender, EventArgs e)
- {
- //Reactor.PostEvent(new Command.ResetCommand());
- }
- }
- }
|