|
@@ -31,308 +31,357 @@ using System.Windows.Media.Imaging;
|
|
|
using System.Windows.Navigation;
|
|
|
using System.Windows.Shapes;
|
|
|
|
|
|
-namespace parkMonitor {
|
|
|
- /// <summary>
|
|
|
- /// MainWindow.xaml 的交互逻辑
|
|
|
- /// </summary>
|
|
|
- public partial class MainWindow : Window {
|
|
|
- List<ObjectTreeRootVM> lstObjectTree = new List<ObjectTreeRootVM>();
|
|
|
-
|
|
|
- public MainWinVM winVM = new MainWinVM();
|
|
|
-
|
|
|
- //List<PcStatusPanelVM> lstCentralVM = new List<PcStatusPanelVM>();
|
|
|
-
|
|
|
- MainBll bll = new MainBll();
|
|
|
-
|
|
|
- //NumMachineDetailVMCtl numMachineDetailVMCtl = new NumMachineDetailVMCtl();
|
|
|
- //Dictionary<DeviceType, ObjectTreeRootVM> mapTree = new Dictionary<DeviceType, ObjectTreeRootVM>();
|
|
|
-
|
|
|
- //PcStatusVMCtl centralPanelVMCtl = new PcStatusVMCtl();
|
|
|
- //UIExample example = new UIExample();
|
|
|
- ObjectVM selectedTreeVM = null;
|
|
|
- ObservableCollection<DevDetailItemVM> selectedDetailItemVM = null;
|
|
|
- XmlCtl xmlConfig = new XmlCtl();
|
|
|
- private bool isScrollLogBox = true;
|
|
|
-
|
|
|
- public MainWindow() {
|
|
|
- InitializeComponent();
|
|
|
-
|
|
|
- //winform 样式
|
|
|
- System.Windows.Forms.Application.EnableVisualStyles();
|
|
|
- System.Windows.Forms.Application.SetCompatibleTextRenderingDefault(false);
|
|
|
-
|
|
|
- MainModel.ins.mainWin = this;
|
|
|
- MainModel.ins.xmlConfig = xmlConfig;
|
|
|
- loadConfig();
|
|
|
-
|
|
|
- DataContext = winVM;
|
|
|
- clearLogText();
|
|
|
-
|
|
|
- //initTestData();
|
|
|
-
|
|
|
- //initVM();
|
|
|
- //winVM.panel.pcStatusCtl.cpu.Num = 50;
|
|
|
-
|
|
|
- bll.init();
|
|
|
-
|
|
|
- //example
|
|
|
- //UIExample.ins.init();
|
|
|
-
|
|
|
- //测试-模拟异步操作
|
|
|
- //Task.Run(() => {
|
|
|
- // try {
|
|
|
- // Thread.Sleep(1500);
|
|
|
-
|
|
|
- // //UIExample.ins.changeNumMachine("001");
|
|
|
- // //UIExample.ins.removeNumMachine("002");
|
|
|
- // //UIExample.ins.changeLogInfo(">web server losed");
|
|
|
- // //UIExample.ins.changeLogInfo(">tcp connect refused");
|
|
|
- // } catch(Exception ex) {
|
|
|
- // Debug.WriteLine(ex.ToString());
|
|
|
- // }
|
|
|
- //});
|
|
|
- }
|
|
|
-
|
|
|
- /// <summary>init ViewModel</summary>
|
|
|
- //private void initVM() {
|
|
|
-
|
|
|
- //}
|
|
|
-
|
|
|
- private void loadConfig() {
|
|
|
- try {
|
|
|
- MainModel md = MainModel.ins;
|
|
|
- PLCConfigMd plc = md.plcConfigMd;
|
|
|
-
|
|
|
- xmlConfig.load(SysConst.configPath() + "config.xml");
|
|
|
-
|
|
|
- //debug
|
|
|
- bool isDebug = xmlConfig.attrBool("parkMonitor.win.debug", false);
|
|
|
- if(isDebug) {
|
|
|
- win.WindowState = WindowState.Normal;
|
|
|
- win.WindowStyle = WindowStyle.SingleBorderWindow;
|
|
|
- }
|
|
|
-
|
|
|
- //plc
|
|
|
- var xmlPLC = xmlConfig.child("parkMonitor.config.PLC");
|
|
|
- plc.timeGap = xmlPLC.valueInt("timeGap", 2000);
|
|
|
- //plc.strIp = xmlPLC.value("ip", "192.168.0.10");
|
|
|
- //plc.strPort = xmlPLC.value("port", "502");
|
|
|
- //plc.strStation = xmlPLC.value("station", "1");
|
|
|
-
|
|
|
- } catch(Exception) {
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /// <summary>测试数据</summary>
|
|
|
- private void initTestData() {
|
|
|
- DataContext = winVM = new DesignMainWinVM();
|
|
|
- }
|
|
|
-
|
|
|
- //树形菜单-选中item事件
|
|
|
- private void treeObjectInfo_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e) {
|
|
|
- try {
|
|
|
- ObjectVM data = e.NewValue as ObjectVM;
|
|
|
- //非叶子节点
|
|
|
- if(data == null) {
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- selectedTreeVM = null;
|
|
|
- btnReset.Visibility = Visibility.Collapsed;
|
|
|
-
|
|
|
- //test
|
|
|
- //Debug.WriteLine(data.Pkey);
|
|
|
- MonitorServer monitor = EquipmentSimpleFactory.ins.FindEquipment(EquipmentName.Monitor) as MonitorServer;
|
|
|
- var detailVM = monitor.getSelectedDetailViewModel(data);
|
|
|
- if(detailVM == null) {
|
|
|
- //UIExample.ins.clickTree(data);
|
|
|
- winVM.DevInfoDetail = null;
|
|
|
- selectedTreeVM = null;
|
|
|
- selectedDetailItemVM = null;
|
|
|
- return;
|
|
|
- } else {
|
|
|
- winVM.DevInfoDetail = detailVM;
|
|
|
-
|
|
|
- selectedTreeVM = data;
|
|
|
- selectedDetailItemVM = detailVM;
|
|
|
-
|
|
|
- //if(data.CanReset) {
|
|
|
- // btnReset.Visibility = Visibility.Visible;
|
|
|
- //}
|
|
|
- }
|
|
|
- } catch(Exception) {
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- //Debug.WriteLine("设备名 :" + data.Name);
|
|
|
- //Debug.WriteLine("设备类型:" + data.DevType);
|
|
|
- //Debug.WriteLine("主键 :" + data.Pkey);
|
|
|
- //winVM.DevInfoDetail[0].Data = (new Random()).Next(100).ToString();
|
|
|
- //winVM.DevInfoDetail = new System.Collections.ObjectModel.ObservableCollection<DevDetailItemVM>();
|
|
|
- //winVM.DevInfoDetail.Add(new DevDetailItemVM() { Name = "aaaa", Data = "111" });
|
|
|
- //winVM.DevInfoDetail.Add(new DevDetailItemVM() { Name = "bbbbb", Data = "221" });
|
|
|
- }
|
|
|
-
|
|
|
- private void txtLog_PreviewKeyDown(object sender, KeyEventArgs e) {
|
|
|
- e.Handled = true;
|
|
|
- }
|
|
|
-
|
|
|
- public void clearLogText() {
|
|
|
- //logTextLen = 0;
|
|
|
- rtxtLog.Document.Blocks.Clear();
|
|
|
- rtxtLog.Document.LineHeight = 2;
|
|
|
- //TextRange tr = new TextRange(rtxtLog.Document.ContentEnd, rtxtLog.Document.ContentEnd);
|
|
|
- //tr.Text = "\r\n";
|
|
|
- removeFirstLog();
|
|
|
- }
|
|
|
-
|
|
|
- public void removeFirstLog() {
|
|
|
- Block block = rtxtLog.Document.Blocks.FirstOrDefault();
|
|
|
- if(block != null) {
|
|
|
- rtxtLog.Document.Blocks.Remove(block);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- //int logTextLen = 0;
|
|
|
- private void addLogText(string text, Brush color) {
|
|
|
- rtxtLog.Document.Blocks.Add(new Paragraph(new Run(text) { Foreground = color }) { LineHeight = 1 });
|
|
|
- //TextRange tr = new TextRange(rtxtLog.Document.ContentEnd, rtxtLog.Document.ContentEnd);
|
|
|
- //tr.Text = text;
|
|
|
- //tr.ApplyPropertyValue(TextElement.ForegroundProperty, color);
|
|
|
- }
|
|
|
-
|
|
|
- public void addLogText(UILogModel data) {
|
|
|
- bool isScrollLogBox = IsScrolledToEnd(rtxtLog);
|
|
|
- addLogText(data.info, data.color);
|
|
|
- if(isScrollLogBox) {
|
|
|
- scrollLogToEnd();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public void setLogText(List<UILogModel> data) {
|
|
|
- bool isScrollLogBox = IsScrolledToEnd(rtxtLog);
|
|
|
- //var startPos = rtxtLog.Selection.Start;
|
|
|
- //var endPos = rtxtLog.Selection.End;
|
|
|
-
|
|
|
- clearLogText();
|
|
|
- for(int i = 0; i < data.Count; ++i) {
|
|
|
- addLogText(data[i].info, data[i].color);
|
|
|
- }
|
|
|
-
|
|
|
- //rtxtLog.Selection.Select(startPos, endPos);
|
|
|
-
|
|
|
- if(isScrollLogBox) {
|
|
|
- scrollLogToEnd();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /// <summary>设置日志信息</summary>
|
|
|
- //public void setLogText(string text) {
|
|
|
- // bool isScrollLogBox = (txtLog.SelectionStart == txtLog.Text.Length);
|
|
|
- // int idx = txtLog.SelectionStart;
|
|
|
- // winVM.LogInfo = text;
|
|
|
- // txtLog.SelectionStart = idx;
|
|
|
-
|
|
|
- // if(isScrollLogBox) {
|
|
|
- // scrollLogToEnd();
|
|
|
- // }
|
|
|
- //}
|
|
|
-
|
|
|
- private bool IsScrolledToEnd(RichTextBox textBox) {
|
|
|
- return textBox.VerticalOffset + textBox.ViewportHeight >= textBox.ExtentHeight;
|
|
|
- }
|
|
|
-
|
|
|
- /// <summary>滚动日志框到底部</summary>
|
|
|
- private void scrollLogToEnd() {
|
|
|
- //txtLog.SelectionStart = txtLog.Text.Length;
|
|
|
- //txtLog.SelectionLength = 0;
|
|
|
- //txtLog.ScrollToEnd();
|
|
|
-
|
|
|
- rtxtLog.ScrollToEnd();
|
|
|
- }
|
|
|
-
|
|
|
- //点击关闭按钮事件
|
|
|
- private void btnClose_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) {
|
|
|
- OkBoxWin win = new OkBoxWin();
|
|
|
- language.Language lng = language.Language.ins;
|
|
|
-
|
|
|
- win.show(this, lng.exit, lng.sureExit);
|
|
|
-
|
|
|
- if(win.isOk) {
|
|
|
- Close();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private void grdDevTreeType_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) {
|
|
|
- winVM.IsDevTreeShowList = !winVM.IsDevTreeShowList;
|
|
|
- }
|
|
|
-
|
|
|
- private void win_Closed(object sender, EventArgs e) {
|
|
|
- CmdServer.ins.send(CmdType.MainWinClosed);
|
|
|
-
|
|
|
- xmlConfig.save();
|
|
|
- }
|
|
|
-
|
|
|
- /// <summary>点击复位按钮</summary>
|
|
|
- private void btnReset_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) {
|
|
|
- if(selectedTreeVM == null) {
|
|
|
- return;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /// <summary>点击写入按钮</summary>
|
|
|
- private void lstDetailInfo_ClickWrite(object sender, RoutedEventArgs e) {
|
|
|
- try {
|
|
|
- int idx = lstDetailInfo.SelectedIndex;
|
|
|
- if(selectedDetailItemVM == null) {
|
|
|
- return;
|
|
|
- }
|
|
|
- if(idx < 0 || idx >= selectedDetailItemVM.Count) {
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- DevDetailItemVM itemVM = selectedDetailItemVM[idx];
|
|
|
-
|
|
|
- WritePLCWin win = new WritePLCWin();
|
|
|
- win.show(this, selectedTreeVM.Name, itemVM);
|
|
|
- if(!win.isOk) {
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- string val = win.value;
|
|
|
- MonitorServer monitor = EquipmentSimpleFactory.ins.FindEquipment(EquipmentName.Monitor) as MonitorServer;
|
|
|
- monitor.writeData(selectedTreeVM, idx, val);
|
|
|
- } catch(Exception) {
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /// <summary>点击复位按钮</summary>
|
|
|
- private void lstDetailInfo_ClickReset(object sender, RoutedEventArgs e) {
|
|
|
- try {
|
|
|
- int idx = lstDetailInfo.SelectedIndex;
|
|
|
- if(selectedDetailItemVM == null) {
|
|
|
- return;
|
|
|
- }
|
|
|
- if(idx < 0 || idx >= selectedDetailItemVM.Count) {
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- DevDetailItemVM itemVM = selectedDetailItemVM[idx];
|
|
|
-
|
|
|
- OkBoxWin win = new OkBoxWin();
|
|
|
- win.show(this, "确定复位?", "复位<" + itemVM.Name + ">?");
|
|
|
- if(!win.isOk) {
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- //PLCMonitorServer.ins.writeData(selectedTreeVM, idx, "0");
|
|
|
- MonitorServer monitor = EquipmentSimpleFactory.ins.FindEquipment(EquipmentName.Monitor) as MonitorServer;
|
|
|
- monitor.restData(selectedTreeVM, idx);
|
|
|
- } catch(Exception) {
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+namespace parkMonitor
|
|
|
+{
|
|
|
+ /// <summary>
|
|
|
+ /// MainWindow.xaml 的交互逻辑
|
|
|
+ /// </summary>
|
|
|
+ public partial class MainWindow : Window
|
|
|
+ {
|
|
|
+ List<ObjectTreeRootVM> lstObjectTree = new List<ObjectTreeRootVM>();
|
|
|
+
|
|
|
+ public MainWinVM winVM = new MainWinVM();
|
|
|
+
|
|
|
+ //List<PcStatusPanelVM> lstCentralVM = new List<PcStatusPanelVM>();
|
|
|
+
|
|
|
+ MainBll bll = new MainBll();
|
|
|
+
|
|
|
+ //NumMachineDetailVMCtl numMachineDetailVMCtl = new NumMachineDetailVMCtl();
|
|
|
+ //Dictionary<DeviceType, ObjectTreeRootVM> mapTree = new Dictionary<DeviceType, ObjectTreeRootVM>();
|
|
|
+
|
|
|
+ //PcStatusVMCtl centralPanelVMCtl = new PcStatusVMCtl();
|
|
|
+ //UIExample example = new UIExample();
|
|
|
+ ObjectVM selectedTreeVM = null;
|
|
|
+ ObservableCollection<DevDetailItemVM> selectedDetailItemVM = null;
|
|
|
+ XmlCtl xmlConfig = new XmlCtl();
|
|
|
+ private bool isScrollLogBox = true;
|
|
|
+
|
|
|
+ public MainWindow()
|
|
|
+ {
|
|
|
+ InitializeComponent();
|
|
|
+
|
|
|
+ //winform 样式
|
|
|
+ System.Windows.Forms.Application.EnableVisualStyles();
|
|
|
+ System.Windows.Forms.Application.SetCompatibleTextRenderingDefault(false);
|
|
|
+
|
|
|
+ MainModel.ins.mainWin = this;
|
|
|
+ //MainModel.ins.xmlConfig = xmlConfig;
|
|
|
+ //loadConfig();
|
|
|
+
|
|
|
+ DataContext = winVM;
|
|
|
+ clearLogText();
|
|
|
+
|
|
|
+ //initTestData();
|
|
|
+
|
|
|
+ //initVM();
|
|
|
+ //winVM.panel.pcStatusCtl.cpu.Num = 50;
|
|
|
+
|
|
|
+ bll.init();
|
|
|
+
|
|
|
+ //example
|
|
|
+ //UIExample.ins.init();
|
|
|
+
|
|
|
+ //测试-模拟异步操作
|
|
|
+ //Task.Run(() => {
|
|
|
+ // try {
|
|
|
+ // Thread.Sleep(1500);
|
|
|
+
|
|
|
+ // //UIExample.ins.changeNumMachine("001");
|
|
|
+ // //UIExample.ins.removeNumMachine("002");
|
|
|
+ // //UIExample.ins.changeLogInfo(">web server losed");
|
|
|
+ // //UIExample.ins.changeLogInfo(">tcp connect refused");
|
|
|
+ // } catch(Exception ex) {
|
|
|
+ // Debug.WriteLine(ex.ToString());
|
|
|
+ // }
|
|
|
+ //});
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>init ViewModel</summary>
|
|
|
+ //private void initVM() {
|
|
|
+
|
|
|
+ //}
|
|
|
+
|
|
|
+ //private void loadConfig()
|
|
|
+ //{
|
|
|
+ // try
|
|
|
+ // {
|
|
|
+ // MainModel md = MainModel.ins;
|
|
|
+ // PLCConfigMd plc = md.plcConfigMd;
|
|
|
+
|
|
|
+ // xmlConfig.load(SysConst.configPath() + "config.xml");
|
|
|
+
|
|
|
+ // //debug
|
|
|
+ // bool isDebug = xmlConfig.attrBool("parkMonitor.win.debug", false);
|
|
|
+ // if (isDebug)
|
|
|
+ // {
|
|
|
+ // win.WindowState = WindowState.Normal;
|
|
|
+ // win.WindowStyle = WindowStyle.SingleBorderWindow;
|
|
|
+ // }
|
|
|
+
|
|
|
+ // //plc
|
|
|
+ // var xmlPLC = xmlConfig.child("parkMonitor.config.PLC");
|
|
|
+ // plc.timeGap = xmlPLC.valueInt("timeGap", 2000);
|
|
|
+ // //plc.strIp = xmlPLC.value("ip", "192.168.0.10");
|
|
|
+ // //plc.strPort = xmlPLC.value("port", "502");
|
|
|
+ // //plc.strStation = xmlPLC.value("station", "1");
|
|
|
+
|
|
|
+ // }
|
|
|
+ // catch (Exception)
|
|
|
+ // {
|
|
|
+
|
|
|
+ // }
|
|
|
+ //}
|
|
|
+
|
|
|
+ /// <summary>测试数据</summary>
|
|
|
+ private void initTestData()
|
|
|
+ {
|
|
|
+ DataContext = winVM = new DesignMainWinVM();
|
|
|
+ }
|
|
|
+
|
|
|
+ //树形菜单-选中item事件
|
|
|
+ private void treeObjectInfo_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ ObjectVM data = e.NewValue as ObjectVM;
|
|
|
+ //非叶子节点
|
|
|
+ if (data == null)
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ selectedTreeVM = null;
|
|
|
+ btnReset.Visibility = Visibility.Collapsed;
|
|
|
+
|
|
|
+ //test
|
|
|
+ //Debug.WriteLine(data.Pkey);
|
|
|
+ MonitorServer monitor = EquipmentSimpleFactory.ins.FindEquipment(EquipmentName.Monitor) as MonitorServer;
|
|
|
+ var detailVM = monitor.getSelectedDetailViewModel(data);
|
|
|
+ if (detailVM == null)
|
|
|
+ {
|
|
|
+ //UIExample.ins.clickTree(data);
|
|
|
+ winVM.DevInfoDetail = null;
|
|
|
+ selectedTreeVM = null;
|
|
|
+ selectedDetailItemVM = null;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ winVM.DevInfoDetail = detailVM;
|
|
|
+
|
|
|
+ selectedTreeVM = data;
|
|
|
+ selectedDetailItemVM = detailVM;
|
|
|
+
|
|
|
+ //if(data.CanReset) {
|
|
|
+ // btnReset.Visibility = Visibility.Visible;
|
|
|
+ //}
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (Exception)
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ //Debug.WriteLine("设备名 :" + data.Name);
|
|
|
+ //Debug.WriteLine("设备类型:" + data.DevType);
|
|
|
+ //Debug.WriteLine("主键 :" + data.Pkey);
|
|
|
+ //winVM.DevInfoDetail[0].Data = (new Random()).Next(100).ToString();
|
|
|
+ //winVM.DevInfoDetail = new System.Collections.ObjectModel.ObservableCollection<DevDetailItemVM>();
|
|
|
+ //winVM.DevInfoDetail.Add(new DevDetailItemVM() { Name = "aaaa", Data = "111" });
|
|
|
+ //winVM.DevInfoDetail.Add(new DevDetailItemVM() { Name = "bbbbb", Data = "221" });
|
|
|
+ }
|
|
|
+
|
|
|
+ private void txtLog_PreviewKeyDown(object sender, KeyEventArgs e)
|
|
|
+ {
|
|
|
+ e.Handled = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void clearLogText()
|
|
|
+ {
|
|
|
+ //logTextLen = 0;
|
|
|
+ rtxtLog.Document.Blocks.Clear();
|
|
|
+ rtxtLog.Document.LineHeight = 2;
|
|
|
+ //TextRange tr = new TextRange(rtxtLog.Document.ContentEnd, rtxtLog.Document.ContentEnd);
|
|
|
+ //tr.Text = "\r\n";
|
|
|
+ removeFirstLog();
|
|
|
+ }
|
|
|
+
|
|
|
+ public void removeFirstLog()
|
|
|
+ {
|
|
|
+ Block block = rtxtLog.Document.Blocks.FirstOrDefault();
|
|
|
+ if (block != null)
|
|
|
+ {
|
|
|
+ rtxtLog.Document.Blocks.Remove(block);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //int logTextLen = 0;
|
|
|
+ private void addLogText(string text, Brush color)
|
|
|
+ {
|
|
|
+ rtxtLog.Document.Blocks.Add(new Paragraph(new Run(text) { Foreground = color }) { LineHeight = 1 });
|
|
|
+ //TextRange tr = new TextRange(rtxtLog.Document.ContentEnd, rtxtLog.Document.ContentEnd);
|
|
|
+ //tr.Text = text;
|
|
|
+ //tr.ApplyPropertyValue(TextElement.ForegroundProperty, color);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void addLogText(UILogModel data)
|
|
|
+ {
|
|
|
+ bool isScrollLogBox = IsScrolledToEnd(rtxtLog);
|
|
|
+ addLogText(data.info, data.color);
|
|
|
+ if (isScrollLogBox)
|
|
|
+ {
|
|
|
+ scrollLogToEnd();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setLogText(List<UILogModel> data)
|
|
|
+ {
|
|
|
+ bool isScrollLogBox = IsScrolledToEnd(rtxtLog);
|
|
|
+ //var startPos = rtxtLog.Selection.Start;
|
|
|
+ //var endPos = rtxtLog.Selection.End;
|
|
|
+
|
|
|
+ clearLogText();
|
|
|
+ for (int i = 0; i < data.Count; ++i)
|
|
|
+ {
|
|
|
+ addLogText(data[i].info, data[i].color);
|
|
|
+ }
|
|
|
+
|
|
|
+ //rtxtLog.Selection.Select(startPos, endPos);
|
|
|
+
|
|
|
+ if (isScrollLogBox)
|
|
|
+ {
|
|
|
+ scrollLogToEnd();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>设置日志信息</summary>
|
|
|
+ //public void setLogText(string text) {
|
|
|
+ // bool isScrollLogBox = (txtLog.SelectionStart == txtLog.Text.Length);
|
|
|
+ // int idx = txtLog.SelectionStart;
|
|
|
+ // winVM.LogInfo = text;
|
|
|
+ // txtLog.SelectionStart = idx;
|
|
|
+
|
|
|
+ // if(isScrollLogBox) {
|
|
|
+ // scrollLogToEnd();
|
|
|
+ // }
|
|
|
+ //}
|
|
|
+
|
|
|
+ private bool IsScrolledToEnd(RichTextBox textBox)
|
|
|
+ {
|
|
|
+ return textBox.VerticalOffset + textBox.ViewportHeight >= textBox.ExtentHeight;
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>滚动日志框到底部</summary>
|
|
|
+ private void scrollLogToEnd()
|
|
|
+ {
|
|
|
+ //txtLog.SelectionStart = txtLog.Text.Length;
|
|
|
+ //txtLog.SelectionLength = 0;
|
|
|
+ //txtLog.ScrollToEnd();
|
|
|
+
|
|
|
+ rtxtLog.ScrollToEnd();
|
|
|
+ }
|
|
|
+
|
|
|
+ //点击关闭按钮事件
|
|
|
+ private void btnClose_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
|
|
|
+ {
|
|
|
+ OkBoxWin win = new OkBoxWin();
|
|
|
+ language.Language lng = language.Language.ins;
|
|
|
+
|
|
|
+ win.show(this, lng.exit, lng.sureExit);
|
|
|
+
|
|
|
+ if (win.isOk)
|
|
|
+ {
|
|
|
+ Close();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void grdDevTreeType_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
|
|
|
+ {
|
|
|
+ winVM.IsDevTreeShowList = !winVM.IsDevTreeShowList;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void win_Closed(object sender, EventArgs e)
|
|
|
+ {
|
|
|
+ CmdServer.ins.send(CmdType.MainWinClosed);
|
|
|
+
|
|
|
+ xmlConfig.save();
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>点击复位按钮</summary>
|
|
|
+ private void btnReset_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
|
|
|
+ {
|
|
|
+ if (selectedTreeVM == null)
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>点击写入按钮</summary>
|
|
|
+ private void lstDetailInfo_ClickWrite(object sender, RoutedEventArgs e)
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ int idx = lstDetailInfo.SelectedIndex;
|
|
|
+ if (selectedDetailItemVM == null)
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (idx < 0 || idx >= selectedDetailItemVM.Count)
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ DevDetailItemVM itemVM = selectedDetailItemVM[idx];
|
|
|
+
|
|
|
+ WritePLCWin win = new WritePLCWin();
|
|
|
+ win.show(this, selectedTreeVM.Name, itemVM);
|
|
|
+ if (!win.isOk)
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ string val = win.value;
|
|
|
+ MonitorServer monitor = EquipmentSimpleFactory.ins.FindEquipment(EquipmentName.Monitor) as MonitorServer;
|
|
|
+ monitor.writeData(selectedTreeVM, idx, val);
|
|
|
+ }
|
|
|
+ catch (Exception)
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>点击复位按钮</summary>
|
|
|
+ private void lstDetailInfo_ClickReset(object sender, RoutedEventArgs e)
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ int idx = lstDetailInfo.SelectedIndex;
|
|
|
+ if (selectedDetailItemVM == null)
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (idx < 0 || idx >= selectedDetailItemVM.Count)
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ DevDetailItemVM itemVM = selectedDetailItemVM[idx];
|
|
|
+
|
|
|
+ OkBoxWin win = new OkBoxWin();
|
|
|
+ win.show(this, "确定复位?", "复位<" + itemVM.Name + ">?");
|
|
|
+ if (!win.isOk)
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ //PLCMonitorServer.ins.writeData(selectedTreeVM, idx, "0");
|
|
|
+ MonitorServer monitor = EquipmentSimpleFactory.ins.FindEquipment(EquipmentName.Monitor) as MonitorServer;
|
|
|
+ monitor.restData(selectedTreeVM, idx);
|
|
|
+ }
|
|
|
+ catch (Exception)
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|