示例#1
0
        private void FaultWarnList_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            ListViewHitTestInfo info = FaultWarnList.HitTest(e.X, e.Y);
            var item = info.Item as ListViewItem;

            int      errornumber = int.Parse(item.SubItems[1].Text);
            warnInfo form        = new warnInfo(faultDevice[new KeyValuePair <string, int>(standloneid, errornumber)], "default");

            form.Show();
        }
示例#2
0
        /// <summary>
        /// 报警检测(改成数据库较为方便)
        /// </summary>
        /// <param name="faultDevice"></param>
        /// <param name="deviceState"></param>
        public void errorCheckAndShow(ref ConcurrentDictionary <KeyValuePair <string, int>, dataStructure.faultWarnData> faultDevice, dataStructure.device deviceState)
        {
            if ((deviceState.canError & 0x0080) > 0)
            {
                int faultNumber = deviceState.canError & 0x7f;
                //faultData.faultID = deviceState.id;  //报警ID
                //faultData.faultTime = deviceState.time;//报警时间
                //faultData.runningTime = deviceState.runningTime;//运行时间
                if (faultNumber != 0)
                {
                    if (faultDevice.ContainsKey(new KeyValuePair <string, int>(deviceState.id, faultNumber)))  //如果已经有该ID的该类型报警
                    {
                        int errorState = 0;
                        if (faultDevice[new KeyValuePair <string, int>(deviceState.id, faultNumber)].errorState.LastOrDefault() == 2)
                        {
                            errorState = 0;
                        }
                        else
                        {
                            errorState = 1;
                        }
                        int errorCount = ++faultDevice[new KeyValuePair <string, int>(deviceState.id, faultNumber)].errorCount;
                        faultDevice[new KeyValuePair <string, int>(deviceState.id, faultNumber)].faultTime.Add(deviceState.time);
                        faultDevice[new KeyValuePair <string, int>(deviceState.id, faultNumber)].errorState.Add(errorState);
                        if (faultNumber == 40)
                        {
                            faultDevice[new KeyValuePair <string, int>(deviceState.id, faultNumber)].errorValue.Add(deviceState.liftMotorCurrent);
                        }
                        else
                        if (faultNumber == 41)
                        {
                            faultDevice[new KeyValuePair <string, int>(deviceState.id, faultNumber)].errorValue.Add(deviceState.liftMotorTemperature);
                        }
                        else
                        {
                            faultDevice[new KeyValuePair <string, int>(deviceState.id, faultNumber)].errorValue.Add(0);
                        }
                        // faultDevice[new KeyValuePair<string, int>(deviceState.id, faultNumber)].runningTime = deviceState.runningTime;
                        //存入储存队列
                        //   dataStructure.faultWarnData save = faultDevice[new KeyValuePair<string, int>(deviceState.id, faultNumber)];

                        this.Invoke((Action)(
                                        () =>
                        {
                            ListViewItem li = FaultWarnList.Items.Cast <ListViewItem>().FirstOrDefault(x => x.SubItems[1].Text == faultNumber.ToString());
                            if (li != null)
                            {
                                FaultWarnList.BeginUpdate();
                                li.SubItems[0].Text = deviceState.time.ToString("HH:mm:ss");
                                li.SubItems[2].Text = errorCount.ToString();
                                li.BackColor = Color.Red;
                                FaultWarnList.EndUpdate();
                            }


                            if (btnFaultWarn.Enabled == true)
                            {
                                warningTimer.Enabled = true;
                            }
                        }));
                    }
                    else
                    {
                        dataStructure.faultWarnData errorData = new dataStructure.faultWarnData();
                        errorData.faultID = deviceState.id;
                        //errorData.runningTime = deviceState.runningTime;
                        errorData.errorNumber = faultNumber;
                        errorData.faultTime   = new List <DateTime>();
                        errorData.errorValue  = new List <int>();
                        errorData.errorState  = new List <int>();
                        errorData.faultTime.Add(deviceState.time);
                        errorData.errorState.Add(0);
                        if (faultNumber == 40)
                        {
                            errorData.errorValue.Add(deviceState.liftMotorCurrent);
                        }
                        else
                        if (faultNumber == 41)
                        {
                            errorData.errorValue.Add(deviceState.liftMotorCurrent);
                        }
                        else
                        {
                            errorData.errorValue.Add(0);
                        }
                        // errorData.errorArea = dictOfIdAndArea[deviceState.id].Country;
                        //  errorData.errorContent = dataStructure.errorDictionary[errorData.errorNumber];
                        errorData.errorLevel = 1;
                        //  errorData.errorMethod = dataStructure.errorMethod[errorData.errorNumber];
                        errorData.errorCount = 1;
                        faultDevice.TryAdd(new KeyValuePair <string, int>(deviceState.id, faultNumber), errorData);

                        //报警表格中添加信息
                        ListViewItem item = new ListViewItem(deviceState.time.ToString("HH:mm:ss"));
                        item.SubItems.Add(errorData.errorNumber.ToString());
                        //item.SubItems.Add(dictOfIdAndArea[errorData.faultID].Country);
                        item.SubItems.Add(errorData.errorCount.ToString());
                        // item.SubItems.Add(errorData.runningTime.ToString());
                        item.BackColor = Color.Red;
                        this.Invoke((Action)(
                                        () => {
                            FaultWarnList.Items.Add(item);
                            if (btnFaultWarn.Enabled == true)
                            {
                                warningTimer.Enabled = true;
                            }
                        })
                                    );
                        //errorDeviceDataQueue.Enqueue(faultData);  //推入存储队列

                        //item.SubItems.Add(onlineDeviceNowTimeData["20" + deviceId].canCourse.ToString() + "公里");
                        //if (i % 2 == 0)
                        //{
                        //    item.BackColor = Color.LightSlateGray;
                        //}
                        //i++;
                        //.Items.Add(item);
                    }
                }
            }
            else
            {
                int faultNumber = deviceState.canError & 0x7f;
                int errorCount  = 0;
                if (faultDevice.ContainsKey(new KeyValuePair <string, int>(deviceState.id, faultNumber)))
                {
                    errorCount = ++faultDevice[new KeyValuePair <string, int>(deviceState.id, faultNumber)].errorCount;
                    faultDevice[new KeyValuePair <string, int>(deviceState.id, faultNumber)].faultTime.Add(deviceState.time);
                    faultDevice[new KeyValuePair <string, int>(deviceState.id, faultNumber)].errorState.Add(2);
                    if (faultNumber == 40)
                    {
                        faultDevice[new KeyValuePair <string, int>(deviceState.id, faultNumber)].errorValue.Add(deviceState.liftMotorCurrent);
                    }
                    else
                    if (faultNumber == 41)
                    {
                        faultDevice[new KeyValuePair <string, int>(deviceState.id, faultNumber)].errorValue.Add(deviceState.liftMotorTemperature);
                    }
                    else
                    {
                        faultDevice[new KeyValuePair <string, int>(deviceState.id, faultNumber)].errorValue.Add(0);
                    }
                }
                this.Invoke((Action)(
                                () => {
                    ListViewItem li = FaultWarnList.Items.Cast <ListViewItem>().FirstOrDefault(x => x.SubItems[1].Text == faultNumber.ToString());


                    if (li != null)
                    {
                        FaultWarnList.BeginUpdate();
                        li.SubItems[0].Text = deviceState.time.ToString("HH:mm:ss");
                        li.SubItems[2].Text = errorCount.ToString();
                        li.BackColor = Color.Green;
                        FaultWarnList.EndUpdate();
                    }
                })
                            );

                //ListViewItem li = FaultWarnList.Items.Cast<ListViewItem>().First(x => x.Text == deviceState.id && x.SubItems[2].Text == faultNumber.ToString());
                //li.BackColor = Color.Green;
            }
        }