Exemplo n.º 1
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;
            }
        }
Exemplo n.º 2
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");
            }
        }
        //读取事件数据库,判断数据库是否存在该事件,且时间是否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");
            }
        }