private List <DevMonitorNode> GetDevMonitorNodeListByKKS(string KKS) { List <DevMonitorNode> NodeList = null; List <DevMonitorNode> NodeList2 = new List <DevMonitorNode>(); string strKKS = KKS.Replace(" ", ""); DbModel.Location.AreaAndDev.DevMonitorNode Node1 = db.DevMonitorNodes.FirstOrDefault(p => p.KKS == strKKS); if (Node1 != null) { NodeList = new List <DevMonitorNode>(); DevMonitorNode Node = new DevMonitorNode(); Node.Id = Node1.Id; Node.KKS = Node1.KKS; Node.TagName = Node1.TagName; Node.DataBaseName = Node1.DataBaseName; Node.DataBaseTagName = Node1.DataBaseTagName; Node.Describe = Node1.Describe; Node.Value = Node1.Value; Node.Unit = Node1.Unit; Node.DataType = Node1.DataType; Node.TagType = Node1.TagType; NodeList.Add(Node); } DbRawSqlQuery <DbModel.Location.AreaAndDev.DevMonitorNode> query2 = db.Db.Database.SqlQuery <DbModel.Location.AreaAndDev.DevMonitorNode>("select * from DevMonitorNodes where KKS like '%" + strKKS + "_%' and Id != " + Convert.ToString(Node1.Id)); if (query2 == null) { return(NodeList); } List <DbModel.Location.AreaAndDev.DevMonitorNode> MonitorNodeList = query2.ToList(); foreach (DbModel.Location.AreaAndDev.DevMonitorNode item in MonitorNodeList) { if (NodeList == null) { NodeList = new List <DevMonitorNode>(); } DevMonitorNode NodeMonitor = new DevMonitorNode(); NodeMonitor.Id = item.Id; NodeMonitor.KKS = item.KKS; NodeMonitor.TagName = item.TagName; NodeMonitor.DataBaseName = item.DataBaseName; NodeMonitor.DataBaseTagName = item.DataBaseTagName; NodeMonitor.Describe = item.Describe; NodeMonitor.Value = item.Value; NodeMonitor.Unit = item.Unit; NodeMonitor.DataType = item.DataType; NodeMonitor.TagType = item.TagType; NodeList.Add(NodeMonitor); } return(NodeList); }
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); }
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="devNode"></param> /// <returns></returns> private TreeNode <TreeViewItem> GetDevMonitorNode(DevMonitorNode devNode) { var treeItem = new TreeViewItem(devNode.Describe); treeItem.Tag = devNode; var node = new TreeNode <TreeViewItem>(treeItem); return(node); }
//Todo:关闭界面的时候,取消选中 public void Init(DevMonitorNode systemInfo, Sprite normalSprite) { SystemInfo = systemInfo; Normal = normalSprite; TargetGraphic.overrideSprite = Normal; SubSystemText.text = systemInfo.Describe; SetDescribeInfo(systemInfo.Describe); ValueText.text = string.Format("{0}{1}", systemInfo.Value, systemInfo.Unit); }
/// <summary> /// 设置按钮背景 /// </summary> /// <param name="item"></param> /// <param name="Index"></param> private void InitItemInfo(MainInfoItem item, int Index, DevMonitorNode systemInfo) { if (Index % 2 == 0) { item.Init(systemInfo, singleOddSprite); } else { item.Init(systemInfo, doubleEvenSprite); } }
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); }
private void GetDevMonitorInfoByNodeTag_Click(object sender, RoutedEventArgs e) { string strResult = ""; string strNodeTag = TbNodeTag.Text; DevMonitorNode[] lst = client.GetSomesisList(strNodeTag); if (lst != null && lst.Count() > 0) { int nCount = lst.Count(); for (int i = 0; i < nCount; i++) { DevMonitorNode item = lst[i]; System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1)); DateTime dt = startTime.AddSeconds(item.Time); strResult += "{\"kks\":\"" + item.KKS + "\",\"Name\":" + item.Describe + "\",\"t\":" + dt + ",\"value\":\"" + item.Value + "\",\"unit\":\"" + item.Unit + "\":},\r\n"; } } TbKKSResult.Text = strResult; }
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); } }
private void SaveSisToDb(List <sis> sisList, bool isSaveToHistory, Action <List <DevMonitorNode> > callback) { List <DevMonitorNode> monitorNodes = new List <DevMonitorNode>(); try { foreach (sis item in sisList) { string strTag = item.kks; //DevMonitorNode Dmn = bll.DevMonitorNodes.DbSet.Where(p => p.KKS == item.kks).FirstOrDefault(); DevMonitorNode Dmn = bll.DevMonitorNodes.DbSet.Where(p => p.TagName == strTag).FirstOrDefault(); if (Dmn == null) { continue; } Dmn.Value = item.value; Dmn.Time = item.t + nEightHourSecond; bll.DevMonitorNodes.Edit(Dmn);//修改数据库数据 monitorNodes.Add(Dmn); } if (isSaveToHistory) { foreach (var mn in monitorNodes) { DevMonitorNodeHistory Dmnh = mn.ToHistory(); bll.DevMonitorNodeHistorys.Add(Dmnh); } } } catch (Exception ex) { string messgae = ex.Message; Log.Error(LogTags.KKS, "SaveSisToDb:" + ex); } if (callback != null) { callback(monitorNodes); } }
public override bool TickFunction() { if (isEnd == 1)//执行完成 { isEnd = 0; try { Bll db = Bll.NewBllNoRelation(); List <DevMonitorNode> allList = db.DevMonitorNodes.ToList(); #region 保存 /* * int count = allList.Count; * //一次取30条 * int pageCount = 0; * if (count % 30 > 0) * { * pageCount = count/30 + 1; * } * else * { * pageCount = count / 30; * } * //Log.Info("pageCount:" + pageCount); * for (int i = 0; i < pageCount; i++) * { * List<DevMonitorNode> list = allList.GetRange(i,30); * // List<DevMonitorNode> list = allList.FindAll(p=>p.TagName.Contains("30LCA42AA101C")); * //每次获取50条 * List<SisData> sisList = getSisList(list); * if (sisList == null || sisList.Count == 0) * { * //Log.Error("DevMonitorNodeThread:opc"); #region * //try * //{ * // string opcServerIp = AppContext.OPCServerIP; * // OPCReadAuto opc = new OPCReadAuto(opcServerIp); * // if (opc.IsConnected) * // { * // foreach (DevMonitorNode node in nodeList) * // { * // string tagName = node.TagName; * // string tagNameValue = opc.getOPC(tagName); * // node.Value = tagNameValue; * // node.Time = TimeConvert.ToStamp(DateTime.Now); * // } * // db.DevMonitorNodes.EditRange(nodeList); * // } * * //} * //catch (Exception ex) * //{ * // return false; * //} #endregion * } * else * { * string saveSql = ""; * Dictionary<string, SisData> dic = sisList.ToDictionary(key => key.Name.Trim(), value => value); * Log.Info("DevMonitorNodeThread: dic.count="+dic.Count); * int dicCount = 0; * foreach (DevMonitorNode dev in list) * { * if (dic.ContainsKey(dev.TagName.Trim())) * { * SisData dataT = dic[dev.TagName.Trim()]; * dev.Unit = dataT.Unit; * dev.Describe = dataT.Desc; * dev.Value = dataT.Value; * saveSql = string.Format(@"update devmonitornodes set `Describe`='{0}',`Value`='{1}',Unit='{2}' where Id={3};", dev.Describe.Trim(), dev.Value, dev.Unit, dev.Id); * string result = db.DevMonitorNodes.AddorEditBySql(saveSql); * Log.Info("sql:"+result); * Log.Info("DevMonitorNodeThread: 更新sis数据,i=" + i + "结果:" + result); * //saveSql += string.Format(@"update devmonitornodes set `Describe`='{0}',`Value`='{1}',Unit='{2}' where Id={3};",dev.Describe.Trim(),dev.Value,dev.Unit,dev.Id); * dicCount++; * } * } * //Log.Info("dicCount:" + dicCount); * // string result= db.DevMonitorNodes.AddorEditBySql(saveSql); * //bool result = db.DevMonitorNodes.EditRange(list); * //Log.Info("DevMonitorNodeThread: 更新sis数据,i="+i+"结果:"+result); * } * * } */ #endregion #region 单条保存 JsonSerializerSettings setting = new JsonSerializerSettings(); setting.NullValueHandling = NullValueHandling.Ignore; for (int i = 0; i < allList.Count; i++) { DevMonitorNode dev = allList[i]; string tags = dev.TagName.Trim(); tags = tags.Replace(" ", "%20").Replace("#", "%23").Replace("+", "%2B").Replace("/", "%2F"); string result = WebApiHelper.GetString("http://10.146.33.9:20080/MIS/GetRtMonTagInfosByNames?tagNames=" + tags); List <SisData> sisList = JsonConvert.DeserializeObject <List <SisData> >(result, setting);//只有一条 SisData sis = sisList[0]; string saveSql = string.Format(@"update devmonitornodes set `Describe`='{0}',`Value`='{1}',Unit='{2}' where Id={3};", dev.Describe, sis.Value, sis.Unit, dev.Id); Log.Info("DevMonitorNodeThread:id:" + dev.Id + ",tagName:" + dev.TagName + ",value:" + sis.Value + ",unit:" + sis.Unit); string saveResult = db.DevMonitorNodes.AddorEditBySql(saveSql); } #endregion } catch (Exception ex) { Log.Error("DevMonitorNodeThread:" + ex.ToString()); } isEnd = 1; } return(true); }
private Dev_Monitor InitTestMonitor() { Dev_Monitor monitor = new Dev_Monitor(); monitor.Name = "#3机#1闭式冷却水泵"; List <DevMonitorNode> nodeList = new List <DevMonitorNode>(); DevMonitorNode node1 = new DevMonitorNode(); node1.Describe = "#3机#1闭式冷却水泵电机定子线圈温度1"; node1.Value = "25.8"; node1.Unit = "°C"; DevMonitorNode node2 = new DevMonitorNode(); node2.Describe = "#3机#1闭式冷却水泵电机定子线圈温度2"; node2.Value = "26.2"; node2.Unit = "°C"; nodeList.Add(node1); nodeList.Add(node2); monitor.MonitorNodeList = nodeList.ToArray(); List <Dev_Monitor> sonList = new List <Dev_Monitor>(); Dev_Monitor sonfirst = RandomMonitor("#3机#1闭式冷却水泵驱动端轴承1"); Dev_Monitor sonSeond = RandomMonitor("#3机#1闭式冷却水泵非驱动端轴承2"); sonList.Add(sonfirst); sonList.Add(sonSeond); monitor.ChildrenList = sonList.ToArray(); List <Dev_Monitor> GrandsonList1 = new List <Dev_Monitor>(); Dev_Monitor grandsonFirst = RandomMonitor("#3机#1闭式冷却水泵驱动端轴承3"); Dev_Monitor grandsonSeond = RandomMonitor("#3机#1闭式冷却水泵非驱动端轴承4"); GrandsonList1.Add(grandsonFirst); GrandsonList1.Add(grandsonSeond); sonfirst.ChildrenList = GrandsonList1.ToArray(); List <Dev_Monitor> GrandsonList2 = new List <Dev_Monitor>(); Dev_Monitor grandsonthird = RandomMonitor("#3机#1闭式冷却水泵驱动端轴承5"); Dev_Monitor grandsonfotrh = RandomMonitor("#3机#1闭式冷却水泵非驱动端轴承6"); GrandsonList2.Add(grandsonthird); GrandsonList2.Add(grandsonfotrh); sonSeond.ChildrenList = GrandsonList2.ToArray(); List <Dev_Monitor> subSystem = new List <Dev_Monitor>(); Dev_Monitor monitorT = new Dev_Monitor(); monitorT.Name = "#3机#1闭式冷却水泵进口过滤器差压变送器"; Dev_Monitor monitorT2 = new Dev_Monitor(); monitorT2.Name = "#3机#1闭式冷却水泵进口过滤器差压变送器一次门"; subSystem.Add(monitorT); subSystem.Add(monitorT2); grandsonFirst.ChildrenList = subSystem.ToArray(); grandsonthird.ChildrenList = subSystem.ToArray(); return(monitor); }