Exemplo n.º 1
0
        // 读取主表类容
        private void readMain(Equipment eq)
        {
            Command cd = new Command(eq.Address, 0x00, 0x00, 3);

            if (Gloabl.IsAdmin)
            {
                this.Invoke(new Action <string>(addText), "W: " + Parse.byteToHexStr(cd.SendByte));
            }

            if (!CommandResult.GetResult(cd))
            {
                if (eq.lostNum >= 10)
                {
                    eq.IsConnect = false;
                }
                else
                {
                    eq.lostNum++;
                }
                return;
            }
            else
            {
                eq.IsConnect = true;
                eq.lostNum   = 0;
            }
            if (Gloabl.IsAdmin)
            {
                this.Invoke(new Action <string>(addText), "R: " + Parse.byteToHexStr(cd.ResultByte));
            }

            EquipmentData data = Parse.GetRealData(cd.ResultByte, eq);

            data.EquipmentID = eq.ID;

            // 添加数据库
            EquipmentDataDal.AddOne(data);

            eq.Chroma = data.Chroma;


            // 绘制曲线
            if (eq.ID == Convert.ToInt32(seriesOne.Tag))
            {
                this.Invoke(new Action <EquipmentData>(c => addPoint(c)), data);
            }
            if (eq.AlertType == 0)
            {
                eq.ChromaAlertStr = Gloabl.NormalStr;
            }
            else
            {
                // 报警记录
                if (eq.ChromaAlertStr != data.ChromaAlertStr)
                {
                    if (eq.ChromaAlertStr.Equals(Gloabl.NormalStr, StringComparison.OrdinalIgnoreCase))
                    {
                        Alert art = new Alert();
                        art.AlertName   = data.ChromaAlertStr;
                        art.EquipmentID = eq.ID;
                        eq.AlertObject  = AlertDal.AddOneR(art);
                    }
                    else
                    {
                        eq.AlertObject.EndTime = DateTime.Now;
                        AlertDal.UpdateOne(eq.AlertObject);
                        if (!eq.ChromaAlertStr.Equals(data.ChromaAlertStr, StringComparison.OrdinalIgnoreCase))
                        {
                            Alert art = new Alert();
                            art.AlertName   = data.ChromaAlertStr;
                            art.EquipmentID = eq.ID;
                            eq.AlertObject  = AlertDal.AddOneR(art);
                        }
                    }
                    eq.ChromaAlertStr = data.ChromaAlertStr;
                }
                else
                {
                    if (!eq.ChromaAlertStr.Equals(Gloabl.NormalStr, StringComparison.OrdinalIgnoreCase))
                    {
                        eq.AlertObject.EndTime = DateTime.Now;
                        if (!AlertDal.UpdateOne(eq.AlertObject))
                        {
                            Alert art = new Alert();
                            art.AlertName   = data.ChromaAlertStr;
                            art.EquipmentID = eq.ID;
                            eq.AlertObject  = AlertDal.AddOneR(art);
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        public static void AddAlert(Equipment newData, Equipment originalData)
        {
            if (newData.Chroma >= originalData.A2)
            {
                newData.ChromaAlertStr = "高报警";
            }
            else if (newData.Chroma >= originalData.A1 && newData.Chroma < originalData.A2)
            {
                newData.ChromaAlertStr = "低报警";
            }
            else
            {
                newData.ChromaAlertStr = "无报警";
            }

            if (originalData.ChromaAlertStr != newData.ChromaAlertStr)
            {
                if (originalData.ChromaAlertStr == "无报警" || string.IsNullOrWhiteSpace(originalData.ChromaAlertStr))
                {
                    Alert art = new Alert();
                    art.AlertName            = newData.ChromaAlertStr;
                    art.EquipmentID          = originalData.ID;
                    originalData.AlertObject = AlertDal.AddOneR(art);
                }
                else
                {
                    originalData.AlertObject.EndTime = DateTime.Now;
                    AlertDal.UpdateOne(originalData.AlertObject);
                    if (!string.IsNullOrWhiteSpace(newData.ChromaAlertStr))
                    {
                        Alert art = new Alert();
                        art.AlertName            = newData.ChromaAlertStr;
                        art.EquipmentID          = originalData.ID;
                        originalData.AlertObject = AlertDal.AddOneR(art);
                    }
                }
                originalData.ChromaAlertStr = newData.ChromaAlertStr;
            }
            else
            {
                if (!string.IsNullOrWhiteSpace(originalData.ChromaAlertStr))
                {
                    originalData.AlertObject.EndTime = DateTime.Now;
                    if (!AlertDal.UpdateOne(originalData.AlertObject))
                    {
                        Alert art = new Alert();
                        art.AlertName            = newData.ChromaAlertStr;
                        art.EquipmentID          = originalData.ID;
                        originalData.AlertObject = AlertDal.AddOneR(art);
                    }
                }
                //Trace.WriteLine(string.Format("[{1}]  {0}:相同报警", eq.SensorType, DateTime.Now.ToLongTimeString()));
            }

            //if (eq.THAlertStr != data.THAlertStr)
            //{
            //    if (!string.IsNullOrWhiteSpace(eq.THAlertStr))
            //    {
            //        eq.THAlertObject.EndTime = DateTime.Now;
            //        AlertDal.UpdateOne(eq.THAlertObject);
            //        if (!string.IsNullOrWhiteSpace(data.THAlertStr))
            //        {
            //            Alert art = new Alert();
            //            art.AlertName = data.THAlertStr;
            //            art.EquipmentID = eq.ID;
            //            eq.THAlertObject = AlertDal.AddOneR(art);
            //        }
            //    }
            //    else
            //    {
            //        Alert art = new Alert();
            //        art.AlertName = data.THAlertStr;
            //        art.EquipmentID = eq.ID;
            //        eq.THAlertObject = AlertDal.AddOneR(art);
            //    }
            //    eq.THAlertStr = data.THAlertStr;
            //}
            //else
            //{
            //    if (!string.IsNullOrWhiteSpace(eq.THAlertStr))
            //    {
            //        eq.THAlertObject.EndTime = DateTime.Now;
            //        AlertDal.UpdateOne(eq.THAlertObject);
            //    }
            //}
        }