/// <summary> /// 创建树 /// </summary> /// <param name="SubSystem"></param> public void InitTree(Dev_Monitor SubSystem) { bool isEmpty = SubSystem == null || ((SubSystem.ChildrenList == null || SubSystem.ChildrenList.Length == 0) && SubSystem.MonitorNodeList == null); EffectiveInfoContainer.SetActive(!isEmpty); EmptyValueText.SetActive(isEmpty); if (isEmpty) { return; } CurrentSystem = SubSystem; nodes = new ObservableList <TreeNode <TreeViewItem> >(); CreateRootMonitorNode(SubSystem.MonitorNodeList, nodes); if (SubSystem.ChildrenList != null) { foreach (var child in SubSystem.ChildrenList) { var rootNode = GetDevNode(child); nodes.Add(rootNode); CreateChildNode(child, rootNode); } } Tree.Start(); Tree.Nodes = nodes; if (!IsNormalState) { SortAlarm(); } if (scrollBar) { scrollBar.value = 1; } }
public void Init(object treeNodeTag, Text describe) { //Todo:确定数据中是否有告警状态 if (treeNodeTag is Dev_Monitor) { Dev_Monitor dev = treeNodeTag as Dev_Monitor; ValueText.text = "/"; StatusText.text = ""; } else if (treeNodeTag is DevMonitorNode) { describe.text = string.Format("<color=#6DECFEFF>{0}</color>", describe.text); DevMonitorNode node = treeNodeTag as DevMonitorNode; if (string.IsNullOrEmpty(node.Value)) { ValueText.text = "<color=#6DECFEFF>/</color>"; } else { ValueText.text = string.Format("<color=#6DECFEFF>{0}{1}</color>", node.Value, node.Unit); } StatusText.text = ""; } else { ValueText.text = ""; StatusText.text = ""; } }
/// <summary> /// 创建子节点(监控+设备) /// </summary> /// <param name="subDev"></param> /// <param name="treeNode"></param> private void CreateChildNode(Dev_Monitor subDev, TreeNode <TreeViewItem> treeNode) { DevMonitorNode[] nodeList = subDev.MonitorNodeList; if (treeNode.Nodes == null) { treeNode.Nodes = new ObservableList <TreeNode <TreeViewItem> >(); } if (nodeList != null && nodeList.Length != 0) { foreach (var item in nodeList) { TreeNode <TreeViewItem> node = GetDevMonitorNode(item); treeNode.Nodes.Add(node); } } if (subDev.ChildrenList != null) { foreach (var child in subDev.ChildrenList) { var devNode = GetDevNode(child); treeNode.Nodes.Add(devNode); CreateChildNode(child, devNode); } } }
/// <summary> /// 显示界面 /// </summary> /// <param name="kksCode"></param> public void Show(DevInfo devInfo) { string kksCode = devInfo.KKSCode; if (string.IsNullOrEmpty(kksCode)) { UGUIMessageBox.Show("KKS编码为空,请录入设备KKS编码!"); return; } kksCode = "J0GCQ41"; Dev_Monitor monitorInfo = CommunicationObject.Instance.GetDevMonitor(kksCode); if (monitorInfo == null) { UGUIMessageBox.Show("设备监控数据为空..."); return; } Bg.SetActive(true); TitleText.text = string.Format("{0}监控信息", devInfo.Name); if (SubSystemItem.CurrentSelectItem != null) { SubSystemItem.CurrentSelectItem.DeselectItem(); } ShowSubSystemInfo(kksCode); //ShowSubSystemInfo(kksCode); }
/// <summary> /// 显示界面 /// </summary> /// <param name="kksCode"></param> public void Show(DevInfo devInfo) { string kksCode = devInfo.KKSCode; if (string.IsNullOrEmpty(kksCode)) { UGUIMessageBox.Show("KKS编码为空,请录入设备KKS编码!"); return; } //kksCode = "J0GCQ41"; recordTime = DateTime.Now; Dev_Monitor monitorInfo = null; #if UNITY_EDITOR monitorInfo = InitTestMonitor(); Debug.LogError("Unity.Editor.启用测试数据"); #else monitorInfo = CommunicationObject.Instance.GetDevMonitor(kksCode); #endif Debug.LogErrorFormat("GetDevMonitor,costTime:{0} s", (DateTime.Now - recordTime).TotalSeconds); recordTime = DateTime.Now; if (monitorInfo == null) { UGUIMessageBox.Show("设备监控数据为空..."); return; } Bg.SetActive(true); TitleText.text = string.Format("{0}监控信息", devInfo.Name); MainInfo.InitMainDevInfo(monitorInfo.MonitorNodeList); //1.设备本身监控信息 DevSubSystem.InitDevSubSystem(monitorInfo.ChildrenList); Debug.LogErrorFormat("InitDevSubSystem,costTime:{0} s", (DateTime.Now - recordTime).TotalSeconds); recordTime = DateTime.Now; }
/// <summary> /// 设置父节点监控值,同时遍历设置子节点的值(暂时不用) /// </summary> /// <param name="tags"></param> /// <param name="parentNode"></param> private void SetParentMonitorNodes(List <string> tags, Dev_Monitor parentNode) { //根据测点列表,返回一个字典(键:测点名称TagName 值: opc对接获取的值) Dictionary <string, string> tagToValueDic = new Dictionary <string, string>(); string opcServerIp = AppContext.OPCServerIP; opc = new OPCReadAuto(opcServerIp); foreach (var item in tags) { if (!tagToValueDic.ContainsKey(item)) { string tagNameValue = opc.getOPC(item); if (tagNameValue.Equals("BAD")) { tagToValueDic.Add(item, "*"); } else { tagToValueDic.Add(item, tagNameValue); } } } opc.DisConnected(); //断开opc SetMonitorNodeValue(parentNode, tagToValueDic); }
private bool HasMonitorNode(Dev_Monitor dvm) { bool bReturn = false; if (dvm.MonitorNodeList == null || dvm.MonitorNodeList.Count() == 0) { bReturn = false; } else { bReturn = true; } if (bReturn) { return(bReturn); } else { if (dvm.ChildrenList != null && dvm.ChildrenList.Count() > 0) { foreach (Dev_Monitor item in dvm.ChildrenList) { bReturn = HasMonitorNode(item); if (bReturn) { return(bReturn); } } } } return(bReturn); }
private Dev_Monitor RandomMonitor(string describe) { Dev_Monitor monitor = new Dev_Monitor(); monitor.Name = describe; List <DevMonitorNode> nodeList = new List <DevMonitorNode>(); DevMonitorNode node1 = new DevMonitorNode(); node1.Describe = describe + "线圈温度1"; node1.Value = UnityEngine.Random.Range(25.1f, 35f).ToString("f2"); node1.Unit = "°C"; DevMonitorNode node2 = new DevMonitorNode(); node2.Describe = describe + "线圈温度2"; node2.Value = UnityEngine.Random.Range(25.1f, 35f).ToString("f2"); node2.Unit = "°C"; nodeList.Add(node1); nodeList.Add(node2); monitor.MonitorNodeList = nodeList.ToArray(); return(monitor); }
private List <Dev_Monitor> GetChildMonitorDev(string KKS, bool bFlag) { List <Dev_Monitor> child = new List <Dev_Monitor>(); List <DbModel.Location.AreaAndDev.KKSCode> DevList = db.KKSCodes.Where(p => p.ParentCode == KKS).ToList(); foreach (DbModel.Location.AreaAndDev.KKSCode item in DevList) { Dev_Monitor dev = new Dev_Monitor(); dev.Name = item.Name; dev.KKSCode = item.Code; dev.MonitorNodeList = GetDevMonitorNodeListByKKS(dev.KKSCode); dev.ChildrenList = GetChildMonitorDev(dev.KKSCode, bFlag); if (!bFlag && dev.MonitorNodeList == null && dev.ChildrenList == null) { continue; } child.Add(dev); } if (child.Count == 0) { child = null; } return(child); }
/// <summary> /// 根据KKS获取设备的信息、监控项,及设备树 /// </summary> /// <param name="KKS"></param> /// <param name="bFlag"></param> /// <returns></returns> public Dev_Monitor GetDevMonitorInfoByKKS(string KKS, bool bFlag) { Dev_Monitor send = new Dev_Monitor(); DbModel.Location.AreaAndDev.KKSCode dev = db.KKSCodes.FirstOrDefault(p => p.Code == KKS); if (dev == null) { send = null; return(send); } string strDevName = dev.Name; string strDevKKs = dev.Code; send.Name = strDevName; send.KKSCode = strDevKKs; string strTags = ""; send.MonitorNodeList = GetDevMonitorNodeListByKKS(strDevKKs, ref strTags); send.ChildrenList = GetChildMonitorDev(strDevKKs, bFlag, ref strTags); List <DevMonitorNode> dataList = GetSomesisList(strTags); send = InsertDataToEveryDev(send, ref dataList); return(send); }
//Todo:关闭界面的时候,取消选中 public void Init(Dev_Monitor systemInfo, Sprite normalSprite) { IsSelect = false; SystemInfo = systemInfo; Normal = normalSprite; TargetGraphic.overrideSprite = Normal; SetDescribeInfo(systemInfo.Name, GetEffectiveNodeList(systemInfo)); }
/// <summary> /// 设置按钮背景 /// </summary> /// <param name="item"></param> /// <param name="Index"></param> private void InitItemInfo(DevSubSystemItem item, int Index, Dev_Monitor systemInfo) { if (Index % 2 == 0) { item.Init(systemInfo, singleOddSprite); } else { item.Init(systemInfo, doubleEvenSprite); } }
private void AnalysisMonitorInfo(Dev_Monitor dm, ref string strResult) { if (dm.MonitorNodeList != null && dm.MonitorNodeList.Count > 0) { foreach (DevMonitorNode item in dm.MonitorNodeList) { strResult += "{\"kks\":\"" + item.KKS + "\",\"t\":" + item.Time + ",\"value\":\"" + item.Value + "\",\"unit\":\"" + item.Unit + "\":},\r\n"; } } return; }
private void CreateTree(Dev_Monitor devMonitor) { if (devMonitor == null) { return; } TreeViewItem root = GetTreeNode(devMonitor); TreeView1.Items.Add(root); CreateChildrenTreeNode(root, devMonitor); }
/// <summary> /// 获取设备节点 /// </summary> /// <param name="devNode"></param> /// <returns></returns> private TreeNode <TreeViewItem> GetDevNode(Dev_Monitor devNode) { int monitorNodeNum = GetEffectiveNodeList(devNode); string name = string.Format("{0} ({1})", devNode.Name, monitorNodeNum); var treeItem = new TreeViewItem(name); treeItem.Tag = devNode; var node = new TreeNode <TreeViewItem>(treeItem); return(node); }
private TreeViewItem GetTreeNode(Dev_Monitor devMonitor) { if (devMonitor == null) { return(null); } TreeViewItem node = new TreeViewItem(); node.Header = devMonitor.Name; node.Tag = devMonitor; return(node); }
private Dev_Monitor InsertDataToEveryDev(Dev_Monitor Dm, List <TModel.Location.AreaAndDev.DevMonitorNode> dataList) { Dev_Monitor send = new Dev_Monitor(); string strDevKKs = Dm.KKSCode; List <TModel.Location.AreaAndDev.DevMonitorNode> MonitorNodeList = dataList.FindAll(p => p.ParentKKS == strDevKKs); if (Dm.MonitorNodeList != null) { foreach (TModel.Location.AreaAndDev.DevMonitorNode item in Dm.MonitorNodeList) { //string strNodeKKS = item.KKS; TModel.Location.AreaAndDev.DevMonitorNode data = MonitorNodeList.Find(p => p.KKS == item.KKS); //DevMonitorNode data = dataList.Find(p => p.TagName == item.TagName); if (data == null || MonitorNodeList.Count == 0) { data = dataList.Find(p => p.TagName == item.TagName); } else { } if (data != null) { item.Value = data.Value; item.Time = data.Time; } } } if (Dm.ChildrenList != null && Dm.ChildrenList.Count > 0) { foreach (Dev_Monitor item2 in Dm.ChildrenList) { Dev_Monitor ChildDm = InsertDataToEveryDev(item2, dataList); if (ChildDm != null) { if (send.ChildrenList == null) { send.ChildrenList = new List <Dev_Monitor>(); } send.ChildrenList.Add(ChildDm); } } } send.KKSCode = Dm.KKSCode; send.Name = Dm.Name; send.MonitorNodeList = Dm.MonitorNodeList; return(send); }
private void CreateChildrenTreeNode(TreeViewItem parent, Dev_Monitor devMonitor) { if (devMonitor.ChildrenList != null) { foreach (Dev_Monitor monitor in devMonitor.ChildrenList) { TreeViewItem subNode = GetTreeNode(monitor); parent.Items.Add(subNode); CreateChildrenTreeNode(subNode, monitor); } } }
private List <Dev_Monitor> GetChildMonitorDev(DbModel.Location.AreaAndDev.KKSCode KKS) { Dictionary <string, Dev_Monitor> devMoniters = new Dictionary <string, Dev_Monitor>(); List <DbModel.Location.AreaAndDev.KKSCode> childrenKKS = KKS.Children; if (childrenKKS != null) { List <string> kksList = new List <string>(); foreach (DbModel.Location.AreaAndDev.KKSCode item in childrenKKS) { kksList.Add(item.Code);//获取所有的子kks //Dev_Monitor dev = new Dev_Monitor(); //dev.Name = item.Name; //dev.KKSCode = item.Code; //dev.MonitorNodeList = GetDevMonitorNodeListByKKS(dev.KKSCode); //dev.ChildrenList = GetChildMonitorDev(item, bFlag); //child.Add(dev); } var monitorList = GetDevMonitorNodeListByKKS(kksList);//从数据库获取 if (monitorList != null) { foreach (DbModel.Location.AreaAndDev.KKSCode item in childrenKKS) { kksList.Add(item.Code); Dev_Monitor dev = new Dev_Monitor(); dev.Name = item.Name; dev.KKSCode = item.Code; dev.MonitorNodeList = monitorList.Where(i => i.ParentKKS == item.Code).ToList();//放到相应的对象中 //dev.ChildrenList = GetChildMonitorDev(item, bFlag); devMoniters.Add(item.Code, dev); } foreach (DbModel.Location.AreaAndDev.KKSCode item in childrenKKS) { Dev_Monitor dev = devMoniters[item.Code]; dev.ChildrenList = GetChildMonitorDev(item);//递归找子物体 } } } if (devMoniters.Count == 0) { return(null); } return(devMoniters.Values.ToList()); }
/// <summary> /// 通过kks,获取机组运行状态 /// </summary> /// <param name="kks"></param> /// <param name="onDataRecieved"></param> private void TryGetPowerValueByKKS(string kks, Action <bool> onDataRecieved = null) { Dev_Monitor monitorInfo = null; ThreadManager.Run(() => { monitorInfo = CommunicationObject.Instance.GetDevMonitor(kks); }, () => { bool isGroupOn = GetStateByDevMonitor(monitorInfo); if (onDataRecieved != null) { onDataRecieved(isGroupOn); } }, ""); }
private void TreeView1_OnSelectedItemChanged(object sender, RoutedPropertyChangedEventArgs <object> e) { TreeViewItem node = TreeView1.SelectedItem as TreeViewItem; if (node == null) { return; } Dev_Monitor monitor = node.Tag as Dev_Monitor; if (monitor == null) { return; } DataGrid1.ItemsSource = monitor.MonitorNodeList; }
/// <summary> /// 获取有效监控节点 /// </summary> /// <param name="node"></param> /// <param name="nodeList"></param> /// <returns></returns> private int GetEffectiveNodeList(Dev_Monitor dev) { int value = 0; if (dev.MonitorNodeList != null) { value += dev.MonitorNodeList.Length; } if (dev.ChildrenList != null) { foreach (var subDev in dev.ChildrenList) { value += GetEffectiveNodeList(subDev); } } return(value); }
/// <summary> /// 实时获取sis数据 /// </summary> /// <param name="tags"></param> /// <returns></returns> public Dev_Monitor getNowDevMonitorInfoByTags(string tags) { try { //替换特殊字符 // 空格 - %20 // " - %22 // # - %23 // % - %25 // & - %26 // ( - %28 // ) - %29 // + - %2B // , - %2C // / - %2F // : - %3A // ; - %3B // < - %3C // = - %3D // > - %3E // ? - %3F // @ - %40 // \ - %5C // | - %7C tags = tags.Replace(" ", "%20").Replace("#", "%23").Replace("+", "%2B").Replace("/", "%2F"); Dev_Monitor monitor = new Dev_Monitor(); List <TModel.Location.AreaAndDev.DevMonitorNode> nodesList = new List <TModel.Location.AreaAndDev.DevMonitorNode>(); List <SisData> sisList = WebApiHelper.GetEntity <List <SisData> >("http://10.146.33.9:20080/MIS/GetRtMonTagInfosByNames?tagNames=" + tags); foreach (SisData sisData in sisList) { TModel.Location.AreaAndDev.DevMonitorNode dev = new TModel.Location.AreaAndDev.DevMonitorNode(); dev.TagName = sisData.Name; dev.Value = sisData.Value; dev.Unit = sisData.Unit; dev.ParentKKS = sisData.Desc; nodesList.Add(dev); } monitor.MonitorNodeList.AddRange(nodesList); return(monitor); } catch (Exception ex) { Log.Error("DevService.getNowDevMonitorInfoByTags:" + ex.ToString()); return(null); } }
private bool GetHasOrNo(Dev_Monitor dvm) { bool bReturn = false; if (dvm.MonitorNodeList == null || dvm.MonitorNodeList.Count() == 0) { bReturn = false; } else { foreach (DevMonitorNode item2 in dvm.MonitorNodeList) { if (item2.Value != "" && item2.Value != null && item2.Value != "null") { bReturn = true; break; } } } if (bReturn) { return(bReturn); } else { if (dvm.ChildrenList == null || dvm.ChildrenList.Count() == 0) { bReturn = false; return(bReturn); } else { foreach (Dev_Monitor item in dvm.ChildrenList) { bReturn = GetHasOrNo(item); if (bReturn) { return(bReturn); } } } } return(bReturn); }
/// <summary> /// 根据KKS获取设备的信息、监控项,及设备树 /// </summary> /// <param name="KKS"></param> /// <param name="bFlag"></param> /// <returns></returns> public Dev_Monitor GetDevMonitorInfoByKKS(string KKS, bool bFlag) { Dev_Monitor send = new Dev_Monitor(); DbModel.Location.AreaAndDev.KKSCode dev = db.KKSCodes.FirstOrDefault(p => p.Code == KKS); if (dev == null) { send = null; return(send); } send.Name = dev.Name; send.KKSCode = dev.Code; send.MonitorNodeList = GetDevMonitorNodeListByKKS(send.KKSCode); send.ChildrenList = GetChildMonitorDev(send.KKSCode, bFlag); return(send); }
private Dev_Monitor InsertDataToEveryDev(Dev_Monitor Dm, ref List <DevMonitorNode> dataList) { Dev_Monitor send = new Dev_Monitor(); string strDevKKs = Dm.KKSCode; List <DevMonitorNode> MonitorNodeList = dataList.FindAll(p => p.ParentKKS == strDevKKs); if (Dm.MonitorNodeList != null) { foreach (DevMonitorNode item in Dm.MonitorNodeList) { string strNodeKKS = item.KKS; DevMonitorNode data = MonitorNodeList.Find(p => p.KKS == strNodeKKS); if (data != null) { item.Value = data.Value; item.Time = data.Time; } } } if (Dm.ChildrenList != null && Dm.ChildrenList.Count > 0) { foreach (Dev_Monitor item2 in Dm.ChildrenList) { Dev_Monitor ChildDm = InsertDataToEveryDev(item2, ref dataList); if (ChildDm != null) { if (send.ChildrenList == null) { send.ChildrenList = new List <Dev_Monitor>(); } send.ChildrenList.Add(ChildDm); } } } send.KKSCode = Dm.KKSCode; send.Name = Dm.Name; send.MonitorNodeList = Dm.MonitorNodeList; return(send); }
public Dev_Monitor GetDevMonitor(string KKS, bool isShowAll) { Dev_Monitor monitor = new Dev_Monitor(); DbModel.Location.AreaAndDev.KKSCode kksCode = KKSCodes.FirstOrDefault(p => p.Code == KKS); if (kksCode == null) { string dirPath = AppDomain.CurrentDomain.BaseDirectory + "Data\\DeviceData\\" + KKS + ".xml"; if (File.Exists(dirPath)) { var list = XmlSerializeHelper.LoadFromFile <TModel.Location.AreaAndDev.DevMonitorNodeList>(dirPath); monitor.Name = KKS; monitor.KKSCode = KKS; monitor.MonitorNodeList = list; } else { monitor = null; } } else { monitor.Name = kksCode.Name; monitor.KKSCode = kksCode.Code; var monitorNodeList = GetDevMonitorNodeListByKKS(kksCode.Code); monitor.MonitorNodeList = monitorNodeList; monitor.ChildrenList = GetChildMonitorDev(kksCode); if (isShowAll == false) { monitor.RemoveEmpty(); } monitor.AddChildrenMonitorNodes(); } if (monitor != null) { monitor.SetEmpty(); } return(monitor); }
private bool GetStateByDevMonitor(Dev_Monitor monitorTemp) { try { DevMonitorNode[] nodeGroup = monitorTemp.MonitorNodeList; if (nodeGroup == null || nodeGroup.Length == 0) { Debug.LogError("Error:PowerGroupStateManage.GetStateByDevMonitor->MonitorNode is null!"); return(false); } else { DevMonitorNode node = nodeGroup[0]; float value = node.Value.ToFloat(); return(value > 0); } }catch (Exception e) { return(false); } }
/// <summary> /// 设置监控节点的值 /// </summary> /// <param name="parent"></param> /// <param name="tagToValueDic"></param> private void SetMonitorNodeValue(Dev_Monitor parent, Dictionary <string, string> tagToValueDic) { if (tagToValueDic == null || tagToValueDic.Count == 0) { return; } if (parent.MonitorNodeList != null) { foreach (var node in parent.MonitorNodeList) { if (tagToValueDic.ContainsKey(node.TagName)) { node.Value = tagToValueDic[node.TagName]; } } } if (parent.ChildrenList != null) { foreach (var child in parent.ChildrenList) { SetMonitorNodeValue(child, tagToValueDic); } } }
public void Show(Dev_Monitor devMonitor) { CreateTree(devMonitor); this.Show(); }