/// <summary>
        ///  获取本地DB 广播列表
        ///  用于剔除广播包中郊野等无效包
        /// </summary>
        public void getDbBroadcastDeviceList()
        {
            if (StaticData.g_msBroadcastgDBC.State == System.Data.ConnectionState.Closed)
            {
                StaticData.g_msBroadcastgDBC.Open();
            }
            string          strCMD            = "select device_bianhao,device_name from device_broadcast;";
            MySqlCommand    cmd               = new MySqlCommand(strCMD, StaticData.g_msBroadcastgDBC);
            MySqlDataReader sqlReader         = null;
            string          currentMethodName = System.Reflection.MethodBase.GetCurrentMethod().Name;

            if (StaticUtils.DBReaderOperationException(ref cmd, ref sqlReader, currentClassName, currentMethodName))
            {
                while (sqlReader.Read())
                {
                    //name,password
                    string[] str = { sqlReader.GetString(0), sqlReader.GetString(1) };
                    //添加进字典
                    m_broadcastDeviceList.Add(Int16.Parse(str[0]), str[1]);

                    // 初始化用于判断设备是否故障的dict
                    m_broadcastDeviceOnlineList.Add(Int16.Parse(str[0]), DateTime.Now);
                }
                sqlReader.Close();
            }

            StaticData.g_msBroadcastgDBC.Close();
        }
        /// <summary>
        /// 掉线进行插入表逻辑判断->
        /// 判断如果某个设备不进行广播,则在十分钟后进行进一步逻辑判断->
        /// 1. 如果这个设备record 已经在db_event中& status 为‘未处理’,则不做处理;
        /// 2. 如果这个设备record 已经在db_event中& status 为‘已处理’,则insert;
        /// 3. 如果这个设备record不在db_event中, 则insert.
        /// </summary>
        public void judgeBroadcastDeviceBreakdown(Int16 BroadcastDeviceId)
        {
            if (BroadcastDeviceId != 0)
            {
                m_broadcastDeviceOnlineList[BroadcastDeviceId] = DateTime.Now;
            }

            foreach (var item in m_broadcastDeviceOnlineList)
            {
                DataRow[] dr     = StaticData.g_dtBroadcastDevice.Select("编号='" + (Int32)item.Key + "'");
                string    theone = dr[0]["theone"].ToString();

                // 计算两个dateTime 的时间戳,单位s
                long timeSpan = StaticUtils.GetCurrentTimeUnix(DateTime.Now) - StaticUtils.GetCurrentTimeUnix(item.Value);

                // 未上报时长 > 阈值
                if (timeSpan > StaticData.g_intBroadcastBreakdownTime)
                {
                    if (StaticData.g_msBroadcastgDBC.State == System.Data.ConnectionState.Closed)
                    {
                        StaticData.g_msBroadcastgDBC.Open();
                    }
                    string          strCMD            = "select * from event_assemble where target_theone='" + theone + "';";
                    MySqlCommand    cmd               = new MySqlCommand(strCMD, StaticData.g_msBroadcastgDBC);
                    MySqlDataReader sqlReader         = null;
                    string          currentMethodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
                    if (StaticUtils.DBReaderOperationException(ref cmd, ref sqlReader, currentClassName, currentMethodName))
                    {
                        if (sqlReader.Read())
                        {  // record 在设备表中
                            if (sqlReader["event_status"].ToString().Contains("已读"))
                            {
                                sqlReader.Close();
                                StaticData.g_msBroadcastgDBC.Close();
                                insertBrokenRecordToEventDb(item.Key, theone); // 将record作为新的event record进行插入
                            }
                            else
                            {
                                sqlReader.Close();
                                StaticData.g_msBroadcastgDBC.Close();
                                // record 状态未处理 ,更新DB device_broadcast表 和 界面
                                updateBreakdownInfor(item.Key);
                            }
                        }
                        else
                        {
                            sqlReader.Close();
                            StaticData.g_msBroadcastgDBC.Close();
                            insertBrokenRecordToEventDb(item.Key, theone);
                        }
                    }
                }

                // 未上报时长 <= 阈值时,就算event_assemble中显示未处理,仍更新状态为连接
            }
        }
Example #3
0
        /// <summary>
        /// 掉线进行插入表逻辑判断->
        /// 判断如果某个设备不进行广播,则在x分钟后进行进一步逻辑判断->
        /// 1. 如果这个设备record 已经在db_event中& status 为‘未处理’,则不做处理;
        /// 2. 如果这个设备record 已经在db_event中& status 为‘已处理’,则insert;
        /// 3. 如果这个设备record不在db_event中, 则insert.
        /// </summary>
        public void judgeWifiDeviceBreakdown(string wifiTheone)
        {
            DataRow[] dr = StaticData.g_dtWifi.Select("theone='" + wifiTheone + "'");

            // wifi设备状态 || 在线状态 发生异常时,进行报错并插入数据库
            if (dr[0]["wifi设备状态"].Equals("警告") || dr[0]["wifi设备状态"].Equals("次要") || dr[0]["wifi设备状态"].Equals("重要") || dr[0]["wifi设备状态"].Equals("严重") || dr[0]["在线状态"].Equals("掉线"))
            {
                if (StaticData.g_msWifiDBC.State == System.Data.ConnectionState.Closed)
                {
                    StaticData.g_msWifiDBC.Open();
                }

                // 获取错误详情
                string status = "";
                if (dr[0]["wifi设备状态"].Equals("警告") || dr[0]["wifi设备状态"].Equals("次要") || dr[0]["wifi设备状态"].Equals("重要") || dr[0]["wifi设备状态"].Equals("严重"))
                {
                    status = dr[0]["wifi设备状态"].ToString();
                }
                else
                {
                    status = "";
                }
                if (dr[0]["在线状态"].Equals("掉线"))
                {
                    status += dr[0]["在线状态"];
                }

                string          strCMD            = "select * from event_assemble where target_theone='" + wifiTheone + "';";
                MySqlCommand    cmd               = new MySqlCommand(strCMD, StaticData.g_msWifiDBC);
                MySqlDataReader sqlReader         = null;
                string          currentMethodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
                if (StaticUtils.DBReaderOperationException(ref cmd, ref sqlReader, currentClassName, currentMethodName))
                {
                    if (sqlReader.Read())
                    {  // record 在设备表中
                        if (sqlReader["event_status"].ToString().Contains("已处理"))
                        {
                            sqlReader.Close();
                            StaticData.g_msWifiDBC.Close();
                            insertBrokenRecordToEventDb(wifiTheone, status); // 将record作为新的event record进行插入
                        }
                        else
                        {
                            sqlReader.Close();
                            StaticData.g_msWifiDBC.Close();
                        }
                    }
                    else
                    {
                        sqlReader.Close();
                        StaticData.g_msWifiDBC.Close();
                        insertBrokenRecordToEventDb(wifiTheone, status);
                    }
                }
            }
        }
        /// <summary>
        /// 读取数据库刷新 EventAssemble DataTable
        /// </summary>
        public void refreshEventTable()
        {
            if (StaticData.g_msEventAssembleDBC.State == System.Data.ConnectionState.Closed)
            {
                StaticData.g_msEventAssembleDBC.Open();
            }
            else
            {
                return;
            }
            // 设置降序
            string          strCMD            = "select * from event_assemble where event_type='event_app' and event_status='未读' and start_time> '" + Convert.ToString(last_PollForAppEvent_time) + "'ORDER BY id DESC;";
            MySqlCommand    cmd               = new MySqlCommand(strCMD, StaticData.g_msEventAssembleDBC);
            MySqlDataReader sqlReader         = null;
            string          currentMethodName = System.Reflection.MethodBase.GetCurrentMethod().Name;

            if (StaticUtils.DBReaderOperationException(ref cmd, ref sqlReader, currentClassName, currentMethodName))
            {
                StaticData.g_dtEventAssemble.Clear();
                while (sqlReader.Read())
                {
                    DataRow dr = StaticData.g_dtEventAssemble.NewRow();//表格的行
                    dr["事件名称"]     = sqlReader["event_name"].ToString();
                    dr["事件theone"] = sqlReader["event_theone"].ToString();
                    dr["事件类型"]     = sqlReader["event_type"].ToString();
                    dr["事件状态"]     = sqlReader["event_status"].ToString();
                    dr["时间"]       = sqlReader["end_time"].ToString();
                    StaticData.g_dtEventAssemble.Rows.Add(dr);//添加
                }
                if (StaticData.g_dtEventAssemble.Rows.Count > 0)
                {
                    last_PollForAppEvent_time = Convert.ToDateTime(StaticData.g_dtEventAssemble.Rows[0]["时间"]);
                }

                sqlReader.Close();
            }
            StaticData.g_msEventAssembleDBC.Close();
        }
Example #5
0
        private void Form1_Load(object sender, EventArgs e)
        {
            //从自己的数据库中读取所有的连接第三方系统的参数配置信息
            DBConnect getSystemArgvDBC = new DBConnect();

            try
            {
                if (getSystemArgvDBC.msConn.State == System.Data.ConnectionState.Closed)
                {
                    getSystemArgvDBC.msConn.Open();
                }
                string          strCMD            = "select *  from config_support_platform;";
                MySqlCommand    cmd               = new MySqlCommand(strCMD, getSystemArgvDBC.msConn);
                MySqlDataReader sqlReader         = null;
                string          currentClassName  = System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name;
                string          currentMethodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
                if (StaticUtils.DBReaderOperationException(ref cmd, ref sqlReader, currentClassName, currentMethodName))
                {
                    while (sqlReader.Read())
                    {
                        //根据配置名称,将数据库公共配置表中取到的数据存入全局变量。
                        switch (sqlReader["config_type"].ToString())
                        {
                        case "webSocketIP":
                            StaticData.g_strWebSocketPort = sqlReader["port"].ToString();
                            break;
                        //下面是其他第三方系统

                        //广播相关配置
                        case "broadcast":
                            StaticData.g_strLocalIP             = sqlReader["local_ip"].ToString();
                            StaticData.g_strBroadcastServerIP   = sqlReader["online_ip"].ToString();
                            StaticData.g_strBroadcastServerPort = sqlReader["online_port"].ToString();
                            StaticData.g_strBroadcastListenPort = sqlReader["local_port"].ToString();
                            break;

                        //机房相关配置
                        case "machineRoomConfig":
                            StaticData.g_strMachineRoomUser     = sqlReader["username"].ToString();
                            StaticData.g_strMachineRoomPassword = sqlReader["password"].ToString();
                            StaticData.g_strMachineRoomPort     = sqlReader["port"].ToString();
                            StaticData.g_strMachineRommIP       = sqlReader["nvrip"].ToString();
                            StaticData.g_strMachineRommDBname   = sqlReader["dbname"].ToString();
                            break;

                        //系统轮询时间
                        case "system_poll_freq":
                            StaticData.g_nSystemPollFreq = Convert.ToInt32(sqlReader["value"]);
                            break;

                        //闸机相关配置
                        case "gate":

                            break;

                        //停车场相关配置
                        case "park":

                            break;
                        }
                    }
                    sqlReader.Close();
                }
                /// 根据不同硬件, 读取本地数据库各硬件参数表中各自的参数
                #region
                //机房相关独立配置
                string          strConfigCMD_machineRoom    = "select *  from config_event_computer_room;";
                MySqlCommand    configCmd_machineRoom       = new MySqlCommand(strConfigCMD_machineRoom, getSystemArgvDBC.msConn);
                MySqlDataReader configSqlReader_machineRoom = null;
                if (StaticUtils.DBReaderOperationException(ref configCmd_machineRoom, ref configSqlReader_machineRoom, currentClassName, currentMethodName))
                {
                    StaticData.g_dictMachineRoomConfig = new Dictionary <string, int>();
                    while (configSqlReader_machineRoom.Read())
                    {
                        StaticData.g_dictMachineRoomConfig.Add(configSqlReader_machineRoom["event_definition"].ToString(), Convert.ToInt32(configSqlReader_machineRoom["event_value"]));
                    }
                    configSqlReader_machineRoom.Close();
                    StaticData.g_intMachineRoomWarningIntervalTime = Convert.ToInt32(StaticData.g_dictMachineRoomConfig["warning"]);
                }

                //闸机相关独立配置
                string          strConfigCMD_gate    = "select *  from config_event_gate;";
                MySqlCommand    configCmd_gate       = new MySqlCommand(strConfigCMD_gate, getSystemArgvDBC.msConn);
                MySqlDataReader configSqlReader_gate = null;
                if (StaticUtils.DBReaderOperationException(ref configCmd_gate, ref configSqlReader_gate, currentClassName, currentMethodName))
                {
                    StaticData.g_dictGateConfig = new Dictionary <string, int>();
                    while (configSqlReader_gate.Read())
                    {
                        StaticData.g_dictGateConfig.Add(configSqlReader_gate["event_definition"].ToString(), Convert.ToInt32(configSqlReader_gate["event_value"]));
                    }
                    configSqlReader_gate.Close();
                    StaticData.g_intGateEarlyWarning        = Convert.ToInt32(StaticData.g_dictGateConfig["warning"]);          //闸机人数过多预警
                    StaticData.g_intGateWarning             = Convert.ToInt32(StaticData.g_dictGateConfig["alarm"]);            //闸机人数过多告警
                    StaticData.g_intGateWarningIntervalTime = Convert.ToInt32(StaticData.g_dictGateConfig["warning_interval"]); ////同一闸机相同报警Interval   unit : s
                }
                //停车场相关独立配置
                string          strConfigCMD_park    = "select *  from config_event_park;";
                MySqlCommand    configCmd_park       = new MySqlCommand(strConfigCMD_park, getSystemArgvDBC.msConn);
                MySqlDataReader configSqlReader_park = null;
                if (StaticUtils.DBReaderOperationException(ref configCmd_park, ref configSqlReader_park, currentClassName, currentMethodName))
                {
                    StaticData.g_dictParkConfig = new Dictionary <string, double>();
                    while (configSqlReader_park.Read())
                    {
                        StaticData.g_dictParkConfig.Add(configSqlReader_park["event_definition"].ToString(), Convert.ToDouble(configSqlReader_park["event_value"]));
                    }
                    configSqlReader_park.Close();
                    StaticData.g_intParkWarningIntervalTime = Convert.ToInt32(StaticData.g_dictParkConfig["warning_interval"]); //同一停车场相同报警Interval   unit : s
                    StaticData.g_intParkEarlyWarning        = Convert.ToDouble(StaticData.g_dictParkConfig["warning_rate"]);    //车位使用过多预警  考虑到不同车位的容量不同,此处使用百分比
                    StaticData.g_intParkWarning             = Convert.ToDouble(StaticData.g_dictParkConfig["alarm_rate"]);      //车位使用过多告警
                }
                #endregion

                getSystemArgvDBC.msConn.Close();
                getSystemArgvDBC.msConn = null;
            }
            catch (Exception aaa)
            {
                Console.WriteLine(aaa.ToString());
                MessageBox.Show(DateTime.Now.ToString() + "  Mainform.class-Form1_Load : 数据库检索失败,请检查配置文件");
            }
        }
Example #6
0
        /// <summary>
        /// 根据数据库对海康摄像头进行遍历
        /// </summary>
        public void InitHKCamera()
        {
            StaticData.g_dtCamera.Columns.Add("序号", typeof(int));
            StaticData.g_dtCamera.Columns.Add("编号", typeof(string));
            StaticData.g_dtCamera.Columns.Add("摄像头名称", typeof(string));
            StaticData.g_dtCamera.Columns.Add("摄像头状态", typeof(string));
            StaticData.g_dtCamera.Columns.Add("IP地址", typeof(string));
            StaticData.g_dtCamera.Columns.Add("用户名", typeof(string));
            StaticData.g_dtCamera.Columns.Add("密码", typeof(string));
            StaticData.g_dtCamera.Columns.Add("端口", typeof(int));
            StaticData.g_dtCamera.Columns.Add("NVRIP地址", typeof(string));
            StaticData.g_dtCamera.Columns.Add("通道号", typeof(string));
            StaticData.g_dtCamera.Columns.Add("RTSP地址", typeof(string));
            StaticData.g_dtCamera.Columns.Add("转码标识", typeof(int));
            StaticData.g_dtCamera.Columns.Add("theone", typeof(string));
            StaticData.g_dtCamera.Columns.Add("坐标", typeof(string));
            StaticData.g_dtCamera.Columns.Add("RTMP地址", typeof(string));
            StaticData.g_dtCamera.Columns.Add("HLS地址", typeof(string));
            StaticData.g_dtCamera.Columns.Add("摄像头型号", typeof(string));
            StaticData.g_dtCamera.Columns.Add("摄像头型类型", typeof(string));
            StaticData.g_dtCamera.Columns.Add("摄像头型区域", typeof(string));
            StaticData.g_dtCamera.Columns.Add("流ID", typeof(string));
            //下面是转码配置,先不管
            string strConfigPath = AppDomain.CurrentDomain.BaseDirectory + "config.ini";

            m_hlsPort = OperateIniFile.ReadIniData("Login", "hlsPort", null, strConfigPath);//读取hls流使用的端口号

            /*--------------------------------------------------------------------------------
             *  读取camera表,获取IP、名称、channel、line等
             *  进行摄像头状态获取及流转换处理
             *  之后更新Form中的数据
             *  ---------------------------------------------------------------------------------*/
            DBConnect getCameraDBC = new DBConnect();

            try
            {
                if (getCameraDBC.msConn.State == System.Data.ConnectionState.Closed)
                {
                    getCameraDBC.msConn.Open();
                }
                string          strCMD            = "select device_paper_number,device_name,device_ip,device_type,device_area,device_nvrip,device_channel,device_theone,concat_ws(',',ST_X(device_point),ST_Y(device_point),device_height) as device_position,device_rtsp,device_transcoding_flag from device_camera;";
                MySqlCommand    cmd               = new MySqlCommand(strCMD, getCameraDBC.msConn);
                MySqlDataReader sqlReaderCamera   = null;
                string          currentMethodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
                if (StaticUtils.DBReaderOperationException(ref cmd, ref sqlReaderCamera, currentClassName, currentMethodName))
                {
                    int i = 0;
                    while (sqlReaderCamera.Read())
                    {
                        DataRow dr = StaticData.g_dtCamera.NewRow();//表格的行
                        dr["序号"]      = i;
                        dr["编号"]      = sqlReaderCamera["device_paper_number"].ToString();
                        dr["摄像头名称"]   = sqlReaderCamera["device_name"].ToString();
                        dr["IP地址"]    = sqlReaderCamera["device_ip"].ToString();
                        dr["摄像头型类型"]  = sqlReaderCamera["device_type"].ToString();
                        dr["摄像头型区域"]  = sqlReaderCamera["device_area"].ToString();
                        dr["NVRIP地址"] = sqlReaderCamera["device_nvrip"].ToString();
                        dr["通道号"]     = sqlReaderCamera["device_channel"].ToString();
                        dr["theone"]  = sqlReaderCamera["device_theone"].ToString();
                        dr["坐标"]      = sqlReaderCamera["device_position"].ToString();
                        dr["RTSP地址"]  = sqlReaderCamera["device_rtsp"].ToString();

                        // 针对转码标识为空无法直转int 作条件判断
                        if (sqlReaderCamera["device_transcoding_flag"] is System.DBNull || "".Equals(sqlReaderCamera["device_transcoding_flag"]))
                        {
                            dr["转码标识"] = 0;
                        }
                        else
                        {
                            dr["转码标识"] = Convert.ToInt32(sqlReaderCamera["device_transcoding_flag"]);
                        }

                        dr["IP地址"] = sqlReaderCamera["device_ip"].ToString();
                        dr["用户名"]  = "admin";
                        dr["密码"]   = "admin123456";
                        dr["端口"]   = 8000;
                        StaticData.g_dtCamera.Rows.Add(dr);//添加
                        i++;
                    }


                    //读取完所有摄像头后,遍历一遍状态
                    //遍历一遍NVR,将NVR中各个通道的状态与摄像头列表进行管线,进行整体状态维护,其中根据NVRIP 与通道号进行关联
                    for (int k = 0; k < StaticData.g_dtNVR.Rows.Count; k++)
                    {
                        Hikvision hikivisionList = new HikIPListFun();
                        hikivisionList.IPListFun(Convert.ToInt32(StaticData.g_dtNVR.Rows[k]["userid"]));  //调用IPList方法,将状态写入到dicIPList字典中
                    }

                    sqlReaderCamera.Close();
                }
                getCameraDBC.msConn.Close();
                getCameraDBC.msConn = null;
            }
            catch
            {
                StaticUtils.ShowEventMsg("HikvisionAlarmCallBackFun.class-InitHKCamera : 利用DB初始化摄像头出现异常!!\n");
            }
        }
Example #7
0
        /// <summary>
        /// 根据数据库对海康NVR进行初始化
        /// </summary>
        public void InitNVR()
        {
            try
            {
                /*
                 * 读取nvr表,并根据反射进行摄像头SDK注册
                 */
                StaticData.g_dtNVR.Columns.Add("序号", typeof(int));
                StaticData.g_dtNVR.Columns.Add("IP地址", typeof(string));
                StaticData.g_dtNVR.Columns.Add("用户名", typeof(string));
                StaticData.g_dtNVR.Columns.Add("密码", typeof(string));
                StaticData.g_dtNVR.Columns.Add("端口", typeof(int));
                StaticData.g_dtNVR.Columns.Add("userid", typeof(int));

                DBConnect getNvrDBC = new DBConnect();
                try
                {
                    if (getNvrDBC.msConn.State == System.Data.ConnectionState.Closed)
                    {
                        getNvrDBC.msConn.Open();
                    }
                    string          strCMD            = "select username,password,nvrip  from config_support_platform where config_type='nvr';";
                    MySqlCommand    cmd               = new MySqlCommand(strCMD, getNvrDBC.msConn);
                    MySqlDataReader sqlReader         = null;
                    string          currentMethodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
                    if (StaticUtils.DBReaderOperationException(ref cmd, ref sqlReader, currentClassName, currentMethodName))
                    {
                        int i = 0;
                        while (sqlReader.Read())
                        {
                            //得到了NVR数据库
                            //IP,name,password
                            string[]  str       = { sqlReader["nvrip"].ToString(), sqlReader["username"].ToString(), sqlReader["password"].ToString() };
                            Hikvision hikCamera = CameraNVR.CreateCamera("Hikvision");
                            hikCamera.CameraInit(str[0], 8000, str[1], str[2]); //海康SDK注册
                            DataRow dr = StaticData.g_dtNVR.NewRow();           //表格的行
                            dr["序号"]   = i;
                            dr["IP地址"] = str[0];
                            dr["用户名"]  = str[1];
                            dr["密码"]   = str[2];
                            dr["端口"]   = 8000;//以后也可以做成可以配置的

                            dr["userid"] = Hikvision.m_iUserID;
                            StaticData.g_dtNVR.Rows.Add(dr);//添加
                            i++;
                        }
                        sqlReader.Close();
                    }
                    getNvrDBC.msConn.Close();
                    getNvrDBC.msConn = null;
                }
                catch
                {
                    throw;
                }
            }
            catch (Exception)
            {
                StaticUtils.ShowEventMsg("SkyinforHikvision.class-InitNVR : 海康NVR进行初始化出现异常!!\n");
                //throw;
            }
        }
Example #8
0
        /// <summary>
        /// 用于轮询时刷新摄像头状态,轮询状态意义不大。不用轮询
        /// </summary>
        public void QueryCameras()
        {
            /*------------------------------------------------------------------------
            *  读取camera表,获取IP、名称、channel、line等
            *  进行摄像头状态获取及流转换处理
            *  之后更新Form中的数据
            *  ------------------------------------------------------------------------*/
            string strCMD = "select * from device_camera;";

            if (StaticData.g_msVideQueryConn.State == System.Data.ConnectionState.Closed)
            {
                StaticData.g_msVideQueryConn.Open();
            }
            MySqlCommand    cmd               = new MySqlCommand(strCMD, StaticData.g_msVideQueryConn);
            MySqlDataReader sqlReader         = null;
            string          currentMethodName = System.Reflection.MethodBase.GetCurrentMethod().Name;

            if (StaticUtils.DBReaderOperationException(ref cmd, ref sqlReader, currentClassName, currentMethodName))
            {
                int i = 0;
                while (sqlReader.Read())
                {
                    /*----------------------------------------------------------------------------------------------------------------------------------------
                     * 下面读取到camera表的所有字段,依次为
                     * id(0)   name(1)    position(2)   ip(3)   type(4) username(5) password(6) theon(7)    time(8) line(9) nvrip(10)   rtspstreamid(11)
                     * ------------------------------------------------------------------------------------------------------------------------------------------*/
                    //string[] strCamera = { sqlReader.GetString(0), sqlReader.GetString(1), sqlReader.GetString(2), sqlReader.GetString(3), sqlReader.GetString(4), sqlReader.GetString(5), sqlReader.GetString(6)
                    //, sqlReader.GetString(7), sqlReader.GetString(8), sqlReader.GetString(9), sqlReader.GetString(10), sqlReader.GetString(11)};
                    DataRow dt = StaticData.g_dtCamera.NewRow();//表格的行
                    dt["序号"] = i;
                    dt["编号"] = sqlReader["device_paper_number"].ToString();

                    dt["摄像头名称"]   = sqlReader["device_name"].ToString();
                    dt["IP地址"]    = sqlReader["device_ip"].ToString();
                    dt["摄像头型类型"]  = sqlReader["device_type"].ToString();
                    dt["摄像头型区域"]  = sqlReader["device_area"].ToString();
                    dt["NVRIP地址"] = sqlReader["device_nvrip"].ToString();
                    dt["通道号"]     = sqlReader["device_channel"].ToString();
                    dt["用户名"]     = "admin";
                    dt["密码"]      = "admin123456";

                    dt["RTSP地址"] = "rtsp://";

                    dt["端口"] = 8000;
                    string strCameraState = "";
                    try
                    {
                        Hikvision hikivisionList = new HikIPListFun();
                        hikivisionList.IPListFun(Hikvision.m_iUserID);                                     //调用IPList方法,将状态写入到dicIPList字典中
                        strCameraState = hikivisionList.dicIPList[sqlReader["device_channel"].ToString()]; //从字典中读取到该摄像头的状态
                    }
                    catch (Exception)
                    {
                        strCameraState = "ERROR";
                        StaticUtils.ShowEventMsg("SkyinforHikvision.class-QueryCameras : 轮询刷新摄像头状态出现异常!!\n");
                    }

                    //dt.Rows[i]["摄像头状态"] = strCameraState;
                    //dt.Rows[i]["用户名"] = strCamera[5];//这个要查询数据库的,我先放着了,你继续完善
                    //dt.Rows[i]["密码"] = strCamera[6];//这个要查询数据库的,我先放着了,你继续完善
                    //dt.Rows[i]["NVR IP地址"] = strCamera[10];//这个要查询数据库的,我先放着了,你继续完善

                    //dt.Rows[i]["RTSP地址"] = "rtsp://" + dt.Rows[i]["用户名"] + ":" + dt.Rows[i]["密码"] + "@" + dt.Rows[i]["NVR IP地址"] + ":554/Streaming/Channels/" + dt.Rows[i]["流ID"];
                    //dt.Rows[i]["RTMP地址"] = "rtmp://" + StaticData.g_strLocalIP + "/live/" + dt.Rows[i]["通道号"];
                    //dt.Rows[i]["HLS地址"] = "http://" + StaticData.g_strLocalIP +":"+m_hlsPort+ "/live/" + dt.Rows[i]["通道号"] + "/hls.m3u8";
                    i++;
                    if (i > StaticData.g_dtCamera.Rows.Count - 1)
                    {
                        i = StaticData.g_dtCamera.Rows.Count - 1;
                    }
                }
                sqlReader.Close();
            }
        }
        /// <summary>
        /// 将异常record作为新的event record插入event_assemble & event_gate
        /// 判断数据库是否存在该事件,且时间是否x seconds以上才再次触发,存在且是的话插入新事件
        /// x为StaticData中的全局变量
        /// </summary>
        /// <param name="gateName"> 闸机名称 </param>
        /// <param name="strLevel"> 事件等级判断 </param>
        ///
        public string insertPersonTooMuchRecordToEventDb(string gateName, string strLevel)
        {
            if (StaticData.g_msGateDBC.State == System.Data.ConnectionState.Closed)
            {
                StaticData.g_msGateDBC.Open();
            }

            //生成eventtheon
            string strEventTheOne = Guid.NewGuid().ToString();

            DataRow[] dr              = StaticData.g_dtGate.Select("闸机名称='" + gateName + "'");
            string    theone          = dr[0]["theone"].ToString();
            string    strGatePosition = dr[0]["坐标"].ToString();


            string strCMD = "select *  from event_assemble where target_theone='" + theone + "' ORDER BY id DESC LIMIT 1;";

            if (StaticData.g_msEventAssembleDBC.State == System.Data.ConnectionState.Closed)
            {
                StaticData.g_msEventAssembleDBC.Open();
            }
            MySqlCommand    cmd               = new MySqlCommand(strCMD, StaticData.g_msEventAssembleDBC);
            MySqlDataReader sqlReader         = null;
            string          currentMethodName = System.Reflection.MethodBase.GetCurrentMethod().Name;

            if (StaticUtils.DBReaderOperationException(ref cmd, ref sqlReader, currentClassName, currentMethodName))
            {
                if (sqlReader.Read())
                {
                    // 计算两个dateTime 的时间戳,单位s
                    long timeSpan = StaticUtils.GetCurrentTimeUnix(DateTime.Now) - StaticUtils.GetCurrentTimeUnix(Convert.ToDateTime(sqlReader["end_time"]));
                    if (timeSpan < StaticData.g_intGateWarningIntervalTime)
                    {
                        sqlReader.Close();
                        return("");  // 返回\"\"代表无需后续步骤,eg step: web端上传
                    }
                    else if (sqlReader["event_status"].ToString().Equals("已读"))
                    {
                        sqlReader.Close();
                        return("");  // 返回\"\"代表无需后续步骤,eg step: web端上传
                    }
                }

                sqlReader.Close();
            }
            else
            {
                return("");
            }

            // 将record作为新的event record进行插入
            DataRow[] dr_abnormal_super = StaticData.g_dtAbnormalInfor.Select("故障父类名称='event_gate'");
            DataRow[] dr_abnormal_sub   = StaticData.g_dtAbnormalInfor.Select("父ID='" + dr_abnormal_super[0]["ID"] + "'");
            string    event_name        = ""; //故障二级名称

            string strInsert_assemble = "";
            string strInsert_gate     = "";

            if (strLevel.Equals("一般情况"))
            {
                // 数据库存储按照等级进行存储, 级别越低,id越低
                event_name = dr_abnormal_sub[0]["故障子类名称"].ToString();

                strInsert_assemble = "INSERT INTO event_assemble (event_name,event_theone,event_type,start_time,end_time,event_status,position,event_level,target_theone) values" +
                                     "('" + event_name + "','" + strEventTheOne + "','event_gate','" + DateTime.Now.ToString().Replace('/', '-') + "','" + DateTime.Now.ToString().Replace('/', '-') + "','未读','" +
                                     strGatePosition + "','" + strLevel + "','" + theone + "');";
                strInsert_gate = "INSERT INTO event_gate (event_theone,device_event_type,device_theone) values" +
                                 "('" + strEventTheOne + "','" + event_name + "','" + theone + "');";
            }
            else
            {
                event_name = dr_abnormal_sub[1]["故障子类名称"].ToString();

                strInsert_assemble = "INSERT INTO event_assemble (event_name,event_theone,event_type,start_time,end_time,event_status,position,event_level,target_theone) values" +
                                     "('" + event_name + "','" + strEventTheOne + "','event_gate','" + DateTime.Now.ToString().Replace('/', '-') + "','" + DateTime.Now.ToString().Replace('/', '-') + "','未读','" +
                                     strGatePosition + "','" + strLevel + "','" + theone + "');";
                strInsert_gate = "INSERT INTO event_gate (event_theone,device_event_type,device_theone) values" +
                                 "('" + strEventTheOne + "','" + event_name + "','" + theone + "');";
            }
            MySqlCommand insertAssembleCmd = new MySqlCommand(strInsert_assemble, StaticData.g_msGateDBC);
            MySqlCommand insertGateCmd     = new MySqlCommand(strInsert_gate, StaticData.g_msGateDBC);

            StaticUtils.DBNonQueryOperationException(ref insertAssembleCmd, currentClassName, currentMethodName);
            StaticUtils.DBNonQueryOperationException(ref insertGateCmd, currentClassName, currentMethodName);
            return(strEventTheOne);
        }
        //读取事件数据库,判断数据库是否存在该事件,且时间是否2分钟以上才再次触发,存在且是的话插入新事件
        //不是的话更新endtime字段为当前时间
        //不存在的话直接插入数据
        private void CheckEvent(string strDevice, string strTarget_theone, string strEvent, string strTime, string strPosition, string srtCameraName, string[] paras, string channelName)
        {
            //事件比较特殊,可有可能同时都会调用,所以这里每次调用的时候,都新建一个数据库的conn
            DBConnect dbCheck   = new DBConnect();
            DBConnect dbInsORUp = new DBConnect();

            string[] strReadDB = new string[] { };
            try
            {
                //判断数据库状态并打开数据库连接
                if (dbCheck.msConn.State == System.Data.ConnectionState.Closed)
                {
                    dbCheck.msConn.Open();
                }
                if (dbInsORUp.msConn.State == System.Data.ConnectionState.Closed)
                {
                    dbInsORUp.msConn.Open();
                }
                // string strCMD = "select theone,event,endtime  from event;";
                string strCMD = "select end_time from event_assemble where target_theone='" + strTarget_theone + "' ORDER BY id DESC LIMIT 1;";

                MySqlCommand    cmd               = new MySqlCommand(strCMD, dbCheck.msConn);
                MySqlDataReader sqlReader         = null;
                string          currentMethodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
                if (StaticUtils.DBReaderOperationException(ref cmd, ref sqlReader, currentClassName, currentMethodName))
                {
                    while (sqlReader.Read())
                    {
                        strReadDB = new string[] { sqlReader.GetString(0) };
                        //逐条数据判断
                        //判断数据库中是否存在数据
                        if (strReadDB != null)
                        {
                            //比较endtime的时间和当前时间
                            //传入时间
                            DateTime data_create = Convert.ToDateTime(strTime);
                            DateTime data_db     = Convert.ToDateTime(strReadDB[0]);

                            // 相同报警间隔time   unit: s
                            long time_interval = StaticUtils.GetCurrentTimeUnix(data_create) - StaticUtils.GetCurrentTimeUnix(data_db);

                            if (time_interval < 120)
                            {
                                string       strUpdate = "UPDATE event_assemble SET end_time='" + strTime + "'  WHERE target_theone='" + strTarget_theone + "' AND end_time='" + strReadDB[0] + "';";
                                MySqlCommand cmdUpdate = new MySqlCommand(strUpdate, dbInsORUp.msConn);
                                StaticUtils.DBNonQueryOperationException(ref cmd, currentClassName, currentMethodName);
                                //跳出
                                goto here;
                            }
                        }
                    }
                }
                string event_name = "";   //故障二级名称

                //事件等级判断
                string strLevel = "";
                if (strEvent.Contains("信号丢失"))
                {
                    strLevel   = "一般情况";
                    event_name = "监控设备掉线";
                }
                else if (strEvent.Contains("移动侦测"))
                {
                    strLevel   = "一般情况";
                    event_name = "监控移动侦测";
                }
                else if (strEvent.Contains("穿越警戒面"))
                {
                    strLevel   = "重要情况";
                    event_name = "监控越界侦测";
                }


                //生成eventtheon
                string strEventTheOne = Guid.NewGuid().ToString();

                //插入数据
                //往总表跟字表里面都插入数据
                DataRow[] dr_abnormal_super = StaticData.g_dtAbnormalInfor.Select("故障父类名称='event_camera'");
                DataRow[] dr_abnormal_sub   = StaticData.g_dtAbnormalInfor.Select("父ID='" + dr_abnormal_super[0]["ID"] + "'");

                string strInsert1 = "INSERT INTO event_assemble (event_name,event_theone,event_type,start_time,end_time,event_status,position,event_level,target_theone) values" +
                                    "('" + event_name + "','" + strEventTheOne + "','event_camera','" + DateTime.Now.ToString().Replace('/', '-') + "','" + DateTime.Now.ToString().Replace('/', '-') + "','未读','" +
                                    strPosition + "','" + strLevel + "','" + strTarget_theone + "');";
                string strInsert2 = "INSERT INTO event_camera (event_theone,device_event_type,device_theone) values" +
                                    "('" + strEventTheOne + "','" + event_name + "','" + strTarget_theone + "');";
                MySqlCommand cmdInsert = new MySqlCommand(strInsert1, dbInsORUp.msConn);
                StaticUtils.DBNonQueryOperationException(ref cmdInsert, currentClassName, currentMethodName);
                MySqlCommand cmdInsert2 = new MySqlCommand(strInsert2, dbInsORUp.msConn);
                StaticUtils.DBNonQueryOperationException(ref cmdInsert2, currentClassName, currentMethodName);

                //向web上报事件
                string strSendMSG = jscontrol.EventJson(strEventTheOne);
                Mainform.form1.SendMsgToWebSocketClients(strSendMSG);
                //更新UI界面
                StaticUtils.ShowEventMsg("报警时间:" + paras[0] + "  NVRIP:" + paras[1] + "  事件类型:" + event_name + "  通道号:" + channelName + "  摄像机名称:" + strDevice + "\n");
                //计数加一
                StaticData.g_inAlarmNum++;

here:
                dbInsORUp.msConn.Close();
                sqlReader.Close();
                dbCheck.msConn.Close();
            }
            catch (Exception e)
            {
                StaticUtils.ShowEventMsg("HikvisionAlarmCallBackFun.class-CheckEvent : 插入摄像头报警事件出现异常!!\n");
            }
        }