Exemplo n.º 1
0
        /// <summary>
        /// 验证状态信息,对状态对比变化时生成事件记录
        /// </summary>
        /// <param name="item">巡检项</param>
        /// <param name="devid">控制器ID</param>
        /// <param name="taginfo">状态信息tag标记值</param>
        private string validateSate(string taginfo)
        {
            if (string.IsNullOrEmpty(taginfo))
            {
                return(taginfo);
            }
            Dictionary <string, string[]> dictstate = new Dictionary <string, string[]>();

            string[] alarm = { "4号门报警", "3号门报警", "2号门报警", "1号门报警" };
            dictstate.Add("报警", alarm);
            alarm = new string[] { "火警", "无效刷卡", "联动报警", "非法闯入", "超时", "胁迫" };
            dictstate.Add("警报", alarm);
            alarm = new string[] { "芯片故障", "系统故障4", "时钟故障", "系统故障2", "系统故障1" };
            dictstate.Add("故障", alarm);
            alarm = new string[] { "按钮4状态", "按钮3状态", "按钮2状态", "按钮1状态" };
            dictstate.Add("按钮", alarm);
            alarm = new string[] { "门磁4状态", "门磁3状态", "门磁2状态", "门磁1状态" };
            dictstate.Add("门磁", alarm);
            alarm = new string[] { "继4状态", "继3状态", "继2状态", "继1状态" };
            dictstate.Add("继电器", alarm);
            //火警报警,WG板子使用火警事件记录来反映的
            string strstate = this.getStateDoorCard(basefun.valtag(taginfo, "{刷卡卡号}"),
                                                    basefun.valtag(taginfo, "状态编号"), basefun.valtag(taginfo, "读卡器"));

            if ("火警报警" == strstate)
            {
                taginfo = basefun.setvaltag(taginfo, "火警", "1");
                foreach (string k in dictstate["报警"])
                {
                    taginfo = basefun.setvaltag(taginfo, k, "1");
                }
            }
            //检查前后状态改变;alarmmsg报警信息,isalarm当前是否报警改变
            string         msg = "", alarmmsg = "", msgsigal = "";
            bool           isalarm = false;
            NameObjectList psevent = new NameObjectList();

            psevent["控制器"] = this.devid;
            DateTime dt = DateTime.MinValue;

            try
            {
                psevent["时间"] = dt = Convert.ToDateTime(basefun.valtag(taginfo, "{当前时间}"));
            }
            catch { dt = DateTime.MinValue; }
            if (dt < DateTime.Today.AddYears(-3) || dt > DateTime.Today.AddYears(3))
            {
                NameValueCollection datainfo = new NameValueCollection();
                datainfo["操作"] = "巡检状态";
                ServiceTool.LogMessage(taginfo, datainfo, EventLogEntryType.FailureAudit);
                if (null == dtobj)
                {
                    return(taginfo);
                }
                try { dt = Convert.ToDateTime(dtobj); }
                catch { return(taginfo); }
                if (dt < DateTime.Today.AddYears(-3) || dt > DateTime.Today.AddYears(3))
                {
                    return(taginfo);
                }
                psevent["时间"] = dtobj;
            }
            else
            {
                dtobj = psevent["时间"];
            }
            alarm = new string[] { "警报", "报警", "故障", "按钮", "门磁", "继电器" };
            foreach (string state in alarm)
            {
                //对比状态生成事件
                psevent["事件"] = state;
                string tagorgi   = this.tagInfos[state];
                string tagnews   = "";
                bool   ischanged = false;
                int    inum      = 5;
                foreach (string st in dictstate[state])
                {
                    inum--;
                    string valorg = basefun.valtag(tagorgi, st);
                    if (string.IsNullOrEmpty(valorg))
                    {
                        valorg = "0";
                    }
                    string valnew = basefun.valtag(taginfo, st);
                    tagnews = basefun.setvaltag(tagnews, st, valnew);
                    if ("警报" == state && "1" == valnew)
                    {
                        if (string.IsNullOrEmpty(alarmmsg))
                        {
                            alarmmsg = st;
                        }
                        else
                        {
                            alarmmsg += "," + st;
                        }
                    }
                    if (valorg == valnew && ("报警" != state || !isalarm))
                    {
                        continue;
                    }
                    ischanged = true;
                    if ("警报" == state)
                    {
                        continue;
                    }
                    //处理事件
                    if ("报警" == state || "故障" == state)
                    {
                        if ("报警" == state)
                        {
                            psevent["编号"] = inum.ToString();
                            psevent["内容"] = st + "(" + alarmmsg + ")";
                        }
                        else
                        {
                            psevent.Remove("编号");
                            psevent["内容"] = st;
                        }
                        msg = basefun.setvaltag(msg, st, valnew);
                        try
                        {
                            Monitor.Enter(objquery);
                            if ("1" == valnew)
                            {
                                this.query.ExecuteNonQuery("发生道闸事件", psevent, psevent, psevent);
                            }
                            else
                            {
                                this.query.ExecuteNonQuery("结束道闸事件", psevent, psevent, psevent);
                            }
                        }
                        finally
                        {
                            Monitor.PulseAll(objquery);
                            Monitor.Exit(objquery);
                        }
                    }
                    else
                    {
                        psevent["编号"] = inum.ToString();
                        psevent["内容"] = st + "变位 " + valnew;
                        msgsigal      = basefun.setvaltag(msgsigal, st, valnew);
                        try
                        {
                            Monitor.Enter(objquery);
                            this.query.ExecuteNonQuery("道闸变位事件", psevent, psevent, psevent);
                        }
                        finally
                        {
                            Monitor.PulseAll(objquery);
                            Monitor.Exit(objquery);
                        }
                    }
                }//foreach (string st in dictstate[state])
                this.tagInfos[state] = tagnews;
                if (!ischanged)
                {
                    continue;
                }
                psevent["类别"] = state;
                psevent["内容"] = tagnews;
                try
                {
                    Monitor.Enter(objquery);
                    this.query.ExecuteNonQuery("道闸巡检状态", psevent, psevent, psevent);
                }
                finally
                {
                    Monitor.PulseAll(objquery);
                    Monitor.Exit(objquery);
                }
                //报警内容变化时,先结束原警报事件
                if ("警报" == state)
                {
                    isalarm = !string.IsNullOrEmpty(alarmmsg);
                    if (!isalarm)
                    {
                        foreach (string a in dictstate[state])
                        {
                            msg = basefun.setvaltag(msg, a, "0");
                        }
                    }
                    psevent.Remove("编号");
                    try
                    {
                        Monitor.Enter(objquery);
                        this.query.ExecuteNonQuery("结束道闸事件", psevent, psevent, psevent);
                    }
                    finally
                    {
                        Monitor.PulseAll(objquery);
                        Monitor.Exit(objquery);
                    }
                }
            }//foreach (string state in alarm)
            if (string.IsNullOrEmpty(this.Alarm.tag))
            {
                this.Alarm.tag       = taginfo;
                this.Alarm.dtReceive = DateTime.Now;
            }
            if (string.IsNullOrEmpty(this.Signal.tag))
            {
                this.Signal.tag       = taginfo;
                this.Signal.dtReceive = DateTime.Now;
            }
            if (string.IsNullOrEmpty(msg) && string.IsNullOrEmpty(msgsigal))
            {
                return(taginfo);
            }
            if (!string.IsNullOrEmpty(msg))
            {
                alarm = alarmmsg.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                foreach (string a in alarm)
                {
                    msg = basefun.setvaltag(msg, a, "1");
                }
                this.Alarm.dtReceive = DateTime.Now;
                this.Alarm.tag       = taginfo;
                this.Signal.tag      = taginfo;
                DvAlarmEventArgs arg = new DvAlarmEventArgs(this.devid, this.station, dt, taginfo);
                arg.TagAlarm = msg;
                this.RaiseAlarm(arg);
            }
            if (!string.IsNullOrEmpty(msgsigal))
            {
                this.Signal.dtReceive = DateTime.Now;
                this.Signal.tag       = taginfo;
                this.Alarm.tag        = taginfo;
                DvSignalEventArgs arg = new DvSignalEventArgs(this.devid, this.station, dt, taginfo);
                arg.TagSignal = msgsigal;
                this.RaiseSignal(arg);
            }
            return(taginfo);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 验证状态信息,对状态对比变化时生成事件记录
        /// </summary>
        /// <param name="item">巡检项</param>
        /// <param name="devid">控制器ID</param>
        /// <param name="taginfo">状态信息tag标记值</param>
        private void validateSate(ListViewItem item, string devid, string taginfo, string Type)
        {
            if (null == item || string.IsNullOrEmpty(devid) || string.IsNullOrEmpty(taginfo))
            {
                return;
            }
            Dictionary <string, string[]> dictstate = new Dictionary <string, string[]>();

            string[] alarm = { "4号门报警", "3号门报警", "2号门报警", "1号门报警" };
            dictstate.Add("报警", alarm);
            alarm = new string[] { "火警", "无效刷卡", "联动报警", "非法闯入", "超时", "胁迫" };
            dictstate.Add("警报", alarm);
            alarm = new string[] { "芯片故障", "系统故障4", "时钟故障", "系统故障2", "系统故障1" };
            dictstate.Add("故障", alarm);
            alarm = new string[] { "按钮4状态", "按钮3状态", "按钮2状态", "按钮1状态" };
            dictstate.Add("按钮", alarm);
            alarm = new string[] { "门磁4状态", "门磁3状态", "门磁2状态", "门磁1状态" };
            dictstate.Add("门磁", alarm);
            alarm = new string[] { "继4状态", "继3状态", "继2状态", "继1状态" };
            dictstate.Add("继电器", alarm);

            //检查前后状态改变;alarmmsg报警信息,isalarm当前是否报警改变
            string         msg = "", alarmmsg = "";
            bool           isalarm = false;
            NameObjectList psevent = new NameObjectList();

            psevent["控制器"] = new Guid(devid);
            psevent["时间"]  = basefun.valtag(taginfo, "{当前时间}");
            alarm          = new string[] { "警报", "报警", "故障", "按钮", "门磁", "继电器" };
            foreach (string state in alarm)
            {
                string    filter = "控制器='{0}' and 类别='{1}'";
                DataRow[] drs    = this.tabStateDoor.Select(string.Format(filter, devid, state));
                DataRow   dr     = null;
                if (null == drs || drs.Length < 1)
                {
                    dr         = this.tabStateDoor.NewRow();
                    dr["控制器"]  = devid;
                    dr["类别"]   = state;
                    dr["更新日期"] = basefun.valtag(taginfo, "{刷卡时间}");
                    this.tabStateDoor.Rows.Add(dr);
                }
                else
                {
                    dr = drs[0];
                }
                //对比状态生成事件
                psevent["事件"] = state;
                string tagorgi   = Convert.ToString(dr["内容"]);
                string tagnews   = "";
                bool   ischanged = false;
                int    inum      = 5;
                foreach (string st in dictstate[state])
                {
                    inum--;
                    string valorg = basefun.valtag(tagorgi, st);
                    if (string.IsNullOrEmpty(valorg))
                    {
                        valorg = "0";
                    }
                    string valnew = basefun.valtag(taginfo, st);
                    tagnews = basefun.setvaltag(tagnews, st, valnew);
                    if ("警报" == state && "1" == valnew)
                    {
                        if (string.IsNullOrEmpty(alarmmsg))
                        {
                            alarmmsg = st;
                        }
                        else
                        {
                            alarmmsg += "," + st;
                        }
                    }
                    if (valorg == valnew && ("报警" != state || !isalarm))
                    {
                        continue;
                    }
                    ischanged = true;
                    if ("警报" == state)
                    {
                        continue;
                    }
                    //处理事件
                    if ("报警" == state || "故障" == state)
                    {
                        if ("报警" == state)
                        {
                            psevent["编号"] = inum.ToString();
                            psevent["内容"] = st + "(" + alarmmsg + ")";
                            msg          += ";" + st + "(" + alarmmsg + ")";
                        }
                        else
                        {
                            psevent.Remove("编号");
                            psevent["内容"] = st;
                            msg          += ";" + st;
                        }
                        if ("1" == valnew)
                        {
                            this.Query.ExecuteNonQuery("发生门禁事件", psevent, psevent, psevent);
                        }
                        else
                        {
                            this.Query.ExecuteNonQuery("结束门禁事件", psevent, psevent, psevent);
                        }
                    }
                    else
                    {
                        psevent["编号"] = inum.ToString();
                        psevent["内容"] = st + "变位 " + valnew;
                        // msg += ";" + st + "变位 " + valnew;
                        this.Query.ExecuteNonQuery("门禁变位事件", psevent, psevent, psevent);
                    }
                }//foreach (string st in dictstate[state])
                if (!ischanged)
                {
                    continue;
                }
                psevent["类别"] = state;
                psevent["内容"] = dr["内容"] = tagnews;
                this.Query.ExecuteNonQuery("门禁巡检状态", psevent, psevent, psevent);
                //报警内容变化时,先结束原警报事件
                if ("警报" == state)
                {
                    isalarm = !string.IsNullOrEmpty(alarmmsg);
                    psevent.Remove("编号");
                    this.Query.ExecuteNonQuery("结束门禁事件", psevent, psevent, psevent);
                }
            }//foreach (string state in alarm)
            //刷卡记录
            string dtcard  = basefun.valtag(taginfo, "{刷卡时间}");
            string devname = item.Text.Substring(0, item.Text.IndexOf("("));

            if (!string.IsNullOrEmpty(dtcard) && DateTime.MinValue < Convert.ToDateTime(dtcard))
            {
                string rsl = basefun.valtag(taginfo, "状态编号");
                rsl = this.getStateDoorCard(rsl);
                msg = rsl;
            }
            if (string.IsNullOrEmpty(msg))
            {
                return;
            }
            if (msg.StartsWith(";"))
            {
                msg = msg.Substring(1);
            }
            if (string.IsNullOrEmpty(doorName))
            {
                return;
            }
            DataView dvinfo = gridViewInfo.DataSource as DataView;
            DataRow  drinfo = dvinfo.Table.NewRow();

            if (msg == "正常")
            {
                drinfo["时间"]    = basefun.valtag(taginfo, "{刷卡时间}");
                drinfo["采集记录数"] = dataCount;
            }
            else
            {
                drinfo["时间"]    = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                drinfo["采集记录数"] = dataCount;
            }
            drinfo["卡号"] = basefun.valtag(taginfo, "{卡号}");
            int dkq = 1;

            if (Type == "考勤机")
            {
                if (string.IsNullOrEmpty(basefun.valtag(taginfo, "{卡号}")))
                {
                    drinfo["状态"] = "此卡无效";
                }
                else
                {
                    drinfo["状态"] = "考勤机";
                }
            }
            else
            {
                drinfo["状态"] = msg;
            }
            dkq            = Convert.ToInt32(basefun.valtag(taginfo, "读卡器")) + 1;
            drinfo["门"]    = doorName + "(" + Convert.ToString(dkq) + ")";
            drinfo["设备地址"] = basefun.valtag(taginfo, "{设备地址}");
            dvinfo.Table.Rows.InsertAt(drinfo, 0);
            gridViewInfo.SelectRow(0);
            if (this.gridViewInfo.RowCount > 15)
            {
                this.gridViewInfo.DeleteRow(this.gridViewInfo.RowCount - 1);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// 验证状态信息,对状态对比变化时生成事件记录
        /// </summary>
        /// <param name="item">巡检项</param>
        /// <param name="devid">控制器ID</param>
        /// <param name="taginfo">状态信息tag标记值</param>
        private void validateSate(string taginfo)
        {
            if (string.IsNullOrEmpty(taginfo))
            {
                return;
            }
            Dictionary <string, string[]> dictstate = new Dictionary <string, string[]>();

            string[] alarm = { "4号门报警", "3号门报警", "2号门报警", "1号门报警" };
            dictstate.Add("报警", alarm);
            alarm = new string[] { "火警", "无效刷卡", "联动报警", "非法闯入", "超时", "胁迫" };
            dictstate.Add("警报", alarm);
            alarm = new string[] { "芯片故障", "系统故障4", "时钟故障", "系统故障2", "系统故障1" };
            dictstate.Add("故障", alarm);
            alarm = new string[] { "按钮4状态", "按钮3状态", "按钮2状态", "按钮1状态" };
            dictstate.Add("按钮", alarm);
            alarm = new string[] { "门磁4状态", "门磁3状态", "门磁2状态", "门磁1状态" };
            dictstate.Add("门磁", alarm);
            alarm = new string[] { "继4状态", "继3状态", "继2状态", "继1状态" };
            dictstate.Add("继电器", alarm);

            //检查前后状态改变;alarmmsg报警信息,isalarm当前是否报警改变
            string         msg = "", alarmmsg = "", msgsigal = "";
            bool           isalarm = false;
            NameObjectList psevent = new NameObjectList();

            psevent["控制器"] = this.devid;
            psevent["时间"]  = basefun.valtag(taginfo, "{当前时间}");
            alarm          = new string[] { "警报", "报警", "故障", "按钮", "门磁", "继电器" };
            foreach (string state in alarm)
            {
                //对比状态生成事件
                psevent["事件"] = state;
                string tagorgi   = this.tagInfos[state];
                string tagnews   = "";
                bool   ischanged = false;
                int    inum      = 5;
                foreach (string st in dictstate[state])
                {
                    inum--;
                    string valorg = basefun.valtag(tagorgi, st);
                    if (string.IsNullOrEmpty(valorg))
                    {
                        valorg = "0";
                    }
                    string valnew = basefun.valtag(taginfo, st);
                    tagnews = basefun.setvaltag(tagnews, st, valnew);
                    if ("警报" == state && "1" == valnew)
                    {
                        if (string.IsNullOrEmpty(alarmmsg))
                        {
                            alarmmsg = st;
                        }
                        else
                        {
                            alarmmsg += "," + st;
                        }
                    }
                    if (valorg == valnew && ("报警" != state || !isalarm))
                    {
                        continue;
                    }
                    ischanged = true;
                    if ("警报" == state)
                    {
                        continue;
                    }
                    //处理事件
                    if ("报警" == state || "故障" == state)
                    {
                        if ("报警" == state)
                        {
                            psevent["编号"] = inum.ToString();
                            psevent["内容"] = st + "(" + alarmmsg + ")";
                        }
                        else
                        {
                            psevent.Remove("编号");
                            psevent["内容"] = st;
                        }
                        msg = basefun.setvaltag(msg, st, valnew);
                        if ("1" == valnew)
                        {
                            this.query.ExecuteNonQuery("发生门禁事件", psevent, psevent, psevent);
                        }
                        else
                        {
                            this.query.ExecuteNonQuery("结束门禁事件", psevent, psevent, psevent);
                        }
                    }
                    else
                    {
                        psevent["编号"] = inum.ToString();
                        psevent["内容"] = st + "变位 " + valnew;
                        msgsigal      = basefun.setvaltag(msgsigal, st, valnew);
                        this.query.ExecuteNonQuery("门禁变位事件", psevent, psevent, psevent);
                    }
                }//foreach (string st in dictstate[state])
                this.tagInfos[state] = tagnews;
                if (!ischanged)
                {
                    continue;
                }
                psevent["类别"] = state;
                psevent["内容"] = tagnews;
                this.query.ExecuteNonQuery("门禁巡检状态", psevent, psevent, psevent);
                //报警内容变化时,先结束原警报事件
                if ("警报" == state)
                {
                    isalarm = !string.IsNullOrEmpty(alarmmsg);
                    if (!isalarm)
                    {
                        foreach (string a in dictstate[state])
                        {
                            msg = basefun.setvaltag(msg, a, "0");
                        }
                    }
                    psevent.Remove("编号");
                    this.query.ExecuteNonQuery("结束门禁事件", psevent, psevent, psevent);
                }
            }//foreach (string state in alarm)
            if (string.IsNullOrEmpty(this.Alarm.tag))
            {
                this.Alarm.tag       = taginfo;
                this.Alarm.dtReceive = DateTime.Now;
            }
            if (string.IsNullOrEmpty(this.Signal.tag))
            {
                this.Signal.tag       = taginfo;
                this.Signal.dtReceive = DateTime.Now;
            }
            if (string.IsNullOrEmpty(msg) && string.IsNullOrEmpty(msgsigal))
            {
                return;
            }
            DateTime dt = Convert.ToDateTime(basefun.valtag(taginfo, "{当前时间}"));

            if (!string.IsNullOrEmpty(msg))
            {
                alarm = alarmmsg.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                foreach (string a in alarm)
                {
                    msg = basefun.setvaltag(msg, a, "1");
                }
                this.Alarm.dtReceive = DateTime.Now;
                this.Alarm.tag       = taginfo;
                DvAlarmEventArgs arg = new DvAlarmEventArgs(this.devid, this.station, dt, taginfo);
                arg.TagAlarm = msg;
                this.RaiseAlarm(arg);
            }
            if (!string.IsNullOrEmpty(msgsigal))
            {
                this.Signal.dtReceive = DateTime.Now;
                this.Signal.tag       = taginfo;
                DvSignalEventArgs arg = new DvSignalEventArgs(this.devid, this.station, dt, taginfo);
                arg.TagSignal = msgsigal;
                this.RaiseSignal(arg);
            }
        }