/// <summary>
        /// 方法用于轮询时的状态拼接Json处理
        /// </summary>
        /// <param name="strDeviceName">设备类型</param>
        /// <param name="strIP">IP数组</param>
        /// <param name="strState">状态数组</param>
        /// <returns></returns>
        public string QueryJson(string strDeviceName, string[] strIP, string[] strState)
        {
            JsonObject js = new JsonObject();

            js.Add("responseType", strDeviceName);
            JsonObject jsArr = new JsonObject();

            try
            {
                for (int i = 0; i < strIP.Length; i++)
                {
                    jsArr.Add(strIP[i], strState[i]);
                }
                jsArr.Add("type", "Query");
                jsArr.Add("status", "1");
            }
            catch (Exception e)
            {
                jsArr.Add("type", "Query");
                jsArr.Add("status", "0");
                StaticUtils.ShowEventMsg("MyJsonCtrl.class-QueryJson : 轮询时的状态拼接Json处理出现异常!!\n");
            }
            js.Add("responDetail", jsArr);
            string strReturnResult = js.ToString();

            strReturnResult = Encoding.UTF8.GetString(Encoding.UTF8.GetBytes(strReturnResult));
            return(strReturnResult);
        }
예제 #2
0
        public void SkyinforVideoServer()
        {
            //显示视频转码路数
            CrossThreadOperationControl CrossDele_VideoCount = delegate()
            {
                Mainform.form1.textBoxVideo.Text = StaticData.g_dtCamera.Rows.Count + "路";
            };

            Mainform.form1.textBoxVideo.Invoke(CrossDele_VideoCount);
            List <string> rtspList = new List <string>();
            List <string> idList   = new List <string>();

            //遍历一下所有的摄像头rtsp流,传入rtsp流地址,通道号,就能实现转换了
            for (int i = 0; i < StaticData.g_dtCamera.Rows.Count; i++)
            {
                rtspList.Add(StaticData.g_dtCamera.Rows[i]["RTSP地址"].ToString());
                idList.Add(StaticData.g_dtCamera.Rows[i]["通道号"].ToString());
            }
            try
            {
                skyinforVideoShare(rtspList.ToArray(), idList.ToArray(), StaticData.g_dtCamera.Rows.Count);
            }
            catch (Exception)
            {
                //自己写的代码,肯定有异常,先不管了。。。测试能用了再说
                StaticUtils.ShowEventMsg("SkyinforHikvision.class-SkyinforVideoServer : SkyinforVideoServer出现异常!!\n");
                return;
            }
        }
 /// <summary>
 /// 报警回调函数
 /// </summary>
 /// <param name="userID"></param>
 /// <param name="channel"></param>
 public override void AlarmCallBackFun(int userID, int channel)
 {
     try
     {
         IntPtr pUser = IntPtr.Zero;
         m_falarmData = new CHCNetSDK.MSGCallBack(MsgCallback);                        //注册回调函数
         bool test = CHCNetSDK.NET_DVR_SetDVRMessageCallBack_V30(m_falarmData, pUser); //海康回调SDK
         GC.KeepAlive(m_falarmData);
         GC.KeepAlive(test);
         if (!test)
         {
             iLastErr = CHCNetSDK.NET_DVR_GetLastError();
             MessageBox.Show("Error" + iLastErr);
         }
         else
         {
             //Console.WriteLine("启动报警成功");
         }
         CHCNetSDK.NET_DVR_SETUPALARM_PARAM struAlarmParam = new CHCNetSDK.NET_DVR_SETUPALARM_PARAM(); //设置布防SDK
         struAlarmParam.dwSize  = (uint)Marshal.SizeOf(struAlarmParam);
         struAlarmParam.byLevel = 1;                                                                   //0- 一级布防,1- 二级布防
         CHCNetSDK.NET_DVR_SetupAlarmChan_V41(userID, ref struAlarmParam);
     }
     catch (Exception e)
     {
         StaticUtils.ShowEventMsg("HikvisionAlarmCallBackFun.class-AlarmCallBackFun : 报警回调函数出现异常!\n");
         Console.WriteLine(e);
     }
 }
예제 #4
0
        /// <summary>
        /// 遍历CameraData table的数据,并写入数据库   /*  UpdateDB耗时操作应放到子线程中 */
        ///
        /// </summary>
        public void UpdateDB()
        {
            //遍历datatable
            DBConnect upCameraDBC = new DBConnect();
            DataTable dt          = StaticData.g_dtCamera;

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                string strNVVRIP  = dt.Rows[i]["NVRIP地址"].ToString();
                string strChannel = dt.Rows[i]["通道号"].ToString();
                string strStatus  = dt.Rows[i]["摄像头状态"].ToString();
                string strCMD     = "UPDATE device_camera SET device_status='" + strStatus + "'  WHERE device_nvrip='" + strNVVRIP + "' AND device_channel='" + strChannel + "';";

                if (upCameraDBC.msConn.State == System.Data.ConnectionState.Closed)
                {
                    upCameraDBC.msConn.Open();
                }

                try
                {
                    MySqlCommand cmd = new MySqlCommand(strCMD, upCameraDBC.msConn);
                    string       currentMethodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
                    StaticUtils.DBNonQueryOperationException(ref cmd, currentClassName, currentMethodName);
                }
                catch (Exception)
                {
                    StaticUtils.ShowEventMsg("SkyinforHikvision.class-UpdateDB : 遍历CameraData table数据出现异常!!\n");
                    //throw;
                }
            }
        }
예제 #5
0
        /// <summary>
        /// 用于摄像头列表的选取
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void kdtGrid_CameraList_CellContentClick(object sender, DataGridViewCellEventArgs e)  //单击DataView中的单元格内容时发生
        {
            //string strCameraName= (kdtGrid_CameraList.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString());
            //DataRow[] dr = StaticData.g_dtCamera.Select("摄像头名称='" + strCameraName + "'");
            //if (dr.Length>=1)
            //{
            //    //StaticData.g_CameraSelectChannel = Int32.Parse(dr[e.RowIndex]["通道号"].ToString());//将获取到的通道号存入g_CameraChannel;
            //}
            //else
            //{
            //    return;
            //}
            try
            {
                //得到选中行的索引
                int intRow = kdtGrid_CameraList.SelectedCells[0].RowIndex;

                //得到列的索引
                int    intColumn = kdtGrid_CameraList.SelectedCells[0].ColumnIndex;
                string strLine   = kdtGrid_CameraList.Rows[intRow].Cells["通道号"].Value.ToString();

                StaticData.g_CameraSelectChannel = Int32.Parse(strLine);                                              //将获取到的通道号存入g_CameraChannel;
                StaticData.g_CameraSelectNVRIP   = kdtGrid_CameraList.Rows[intRow].Cells["NVRIP地址"].Value.ToString(); //将获取到的通道号存入g_CameraChannel;
            }
            catch (Exception ex)
            {
                StaticUtils.ShowEventMsg("Mainform.class-kdtGrid_CameraList_CellContentClick : 摄像头列表的选取出现异常!!\n");
                return;
            }
        }
        /// <summary>
        /// 向web 上报事件
        /// </summary>
        public void sendMsgToWebSocketClients(string strEventTheOne, string msg)
        {
            //发送数据Json格式
            string strSendMSG = jscontrol.EventJson(strEventTheOne);

            Mainform.form1.SendMsgToWebSocketClients(strSendMSG);
            //更新UI界面
            StaticUtils.ShowEventMsg(msg);
            //计数加一
            StaticData.g_inAlarmNum++;
        }
        private void StartListen()
        {
            Socket clientSocket = default(Socket);
            string strClientIP;

            while (true)
            {
                try
                {
                    clientSocket = m_listener.Accept();//这个方法返回一个通信套接字,并用这个套接字进行通信,错误时返回-1并设置全局错误变量
                }
                catch (Exception e)
                {
                    StaticUtils.ShowEventMsg("MgJsonCtrl.class-StartListen : 监听Json出现异常!");
                    Console.WriteLine(e);
                }
                Byte[] bytesForm = new byte[1024 * 1024];
                if (clientSocket != null && clientSocket.Connected)
                {
                    try
                    {
                        int length = clientSocket.Receive(bytesForm);
                        clientSocket.Send(PackHandShakeData(GetSecKeyAccept(bytesForm, length)));
                        strClientIP = clientSocket.RemoteEndPoint.ToString(); //得到客户端IP
                                                                              //      Console.WriteLine(strClientIP );
                        if (m_listClient.ContainsKey(strClientIP))
                        {
                            m_listClient[strClientIP] = clientSocket;
                        }
                        else
                        {
                            m_listClient.Add(strClientIP, clientSocket);
                            CrossThreadOperationControl CrossDele = delegate()
                            {
                                Mainform.form1.listViewIPClient.Items.Add(strClientIP);
                            };
                            Mainform.form1.listViewIPClient.Invoke(CrossDele);
                        }
                        //创建一个通信线程
                        ParameterizedThreadStart pts = new ParameterizedThreadStart(recv);
                        Thread thread = new Thread(pts);
                        thread.IsBackground = true;
                        thread.Start(clientSocket);
                        dictThread.Add(clientSocket.RemoteEndPoint.ToString(), thread);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e);
                        StaticUtils.ShowEventMsg("MgJsonCtrl.class-StartListen : 监听Json出现异常!\n");
                    }
                }
            }
        }
 /// <summary>
 /// 发送数据到客户端
 /// </summary>
 /// <param name="sc"></param>
 /// <param name="str"></param>
 public void SendMessage(Socket sc, string str)
 {
     try
     {
         sc.Send(PackData(str));
     }
     catch (Exception e)
     {
         StaticUtils.ShowEventMsg("MgJsonCtrl.class-SendMessage : 发送数据到客户端出现异常!\n");
         Console.WriteLine(e);
     }
 }
 //数据库更新插入异常判断
 public static bool DBNonQueryOperationException(ref MySqlCommand cmd, string currentClassName, string currentMethodName)
 {
     try
     {
         cmd.ExecuteNonQuery();
         return(true);
     }
     catch
     {
         StaticUtils.ShowEventMsg("时间:" + DateTime.Now.ToString() + "  " + currentClassName + ".class-" + currentMethodName + " : 执行数据库nonQuery语句失败!\n");
         return(false);
     }
 }
        /// <summary>
        /// 接收数据
        /// </summary>
        /// <param name="socketclientpara"></param>
        public void recv(object socketclientpara)
        {
            Socket socketClient = socketclientpara as Socket;

            myJson = new MyJsonCtrl();
            while (true)
            {
                //创建一个内存缓冲区,其大小为1024*1024字节  即1M
                byte[] arrServerRecMsg = new byte[1024 * 1024];
                //将接收到的信息存入到内存缓冲区,并返回其字节数组的长度
                try
                {
                    int length = socketClient.Receive(arrServerRecMsg);
                    //处理收到的数据
                    string strSRecMsg = AnalyticData(arrServerRecMsg, length);
                    //   Console.WriteLine(strSRecMsg);

                    ///
                    ///zzt重要,这里是解析每个web客户端发过来命令的地方
                    ///
                    string strReturn = myJson.ReceiceJson(strSRecMsg);
                    SendMessage(socketClient, strReturn);
                    //  Console.WriteLine(strReturn);
                }
                catch (SocketException ex)
                {
                    StaticUtils.ShowEventMsg("MgJsonCtrl.class-recv : 接收数据出现异常!\n");
                    Console.WriteLine("异常抛出" + ex + ",RemoteEnd=" + socketClient.RemoteEndPoint.ToString());
                    //从通信套接字集合中删除被中断连接的通信套接字
                    m_listClient.Remove(socketClient.RemoteEndPoint.ToString());//删除异常的端口和IP
                    Thread stopThread = dictThread[socketClient.RemoteEndPoint.ToString()];
                    //从通信线程中删除被中断的连接通信线程对象
                    dictThread.Remove(socketClient.RemoteEndPoint.ToString());//删除异常的线程
                    CrossThreadOperationControl CrossDele = delegate()
                    {
                        for (int j = 0; j < Mainform.form1.listViewIPClient.Items.Count; j++)
                        {
                            if (Mainform.form1.listViewIPClient.Items[j].Text.Equals(socketClient.RemoteEndPoint.ToString()))
                            {
                                Mainform.form1.listViewIPClient.Items.Remove(Mainform.form1.listViewIPClient.Items[j]);
                                j--;
                            }
                        }
                    };
                    Mainform.form1.listViewIPClient.Invoke(CrossDele);
                    stopThread.Abort();
                    return;
                }
            }
        }
 //数据库读取异常判断
 public static bool DBReaderOperationException(ref MySqlCommand cmd, ref MySqlDataReader sqlReader, string currentClassName, string currentMethodName)
 {
     try
     {
         sqlReader = cmd.ExecuteReader();
         return(true);
     }
     catch
     {
         StaticUtils.ShowEventMsg("时间:" + DateTime.Now.ToString() + "  " + currentClassName + ".class-" + currentMethodName + " : 执行数据库查询语句失败!\n");
         if (!sqlReader.IsClosed)
         {
             sqlReader.Close();
         }
         return(false);
     }
 }
        /// <summary>
        /// 轮询获取 DB 中App端上报的event
        /// </summary>
        public void PollForAppEvent()
        {
            /// Design:服务器维护一个关于Event_assemble的DataTable
            /// 每次轮询更新DataTable ,find a new record and then send a message to clients by websocket;
            /// Point : if there are many new records found, consist them and the split is signal ','.
            InitEventTable();
            MyJsonCtrl jscontrol = new MyJsonCtrl();

            while (true)
            {
                refreshEventTable();
                string        theones     = "";
                List <string> warning_msg = new List <string>();
                //StaticUtils.ShowEventMsg(Convert.ToString(last_PollForAppEvent_time)  +"    "+ StaticData.g_dtEventAssemble.Rows.Count+"\n");
                if (StaticData.g_dtEventAssemble.Rows.Count > 0)
                {
                    for (int i = 0; i < StaticData.g_dtEventAssemble.Rows.Count; i++)
                    {
                        if (i == StaticData.g_dtEventAssemble.Rows.Count - 1)
                        {
                            theones += StaticData.g_dtEventAssemble.Rows[i]["事件theone"];
                        }
                        else
                        {
                            theones += StaticData.g_dtEventAssemble.Rows[i]["事件theone"] + ",";
                        }
                        warning_msg.Add("报警时间:" + StaticData.g_dtEventAssemble.Rows[i]["时间"] + "  事件类型:App故障事件上报  事件名称:" + StaticData.g_dtEventAssemble.Rows[i]["事件名称"] + "\n");
                    }
                    if (!"".Equals(theones))
                    {
                        //发送数据Json格式
                        string strSendMSG = jscontrol.EventJson(theones);
                        Mainform.form1.SendMsgToWebSocketClients(strSendMSG);
                        foreach (var item in warning_msg)
                        {
                            //更新UI界面
                            StaticUtils.ShowEventMsg(item);
                            //计数加一
                            StaticData.g_inAlarmNum++;
                        }
                    }
                }
                Thread.Sleep(5 * 1000);    //   APP轮询
            }
        }
 public WebSocket()
 {
     try
     {
         m_listClient = new Dictionary <string, Socket>();
         dictThread   = new Dictionary <string, Thread>();
         GetIP();
         m_listener.Bind(localEP);
         m_listener.Listen(50);
         //   Console.WriteLine("等待客户端连接");
         //开启客户端监听线程
         theStartListne = new Thread(StartListen);
         theStartListne.IsBackground = true;
         theStartListne.Start();
     }
     catch (Exception)
     {
         StaticUtils.ShowEventMsg("MgJsonCtrl.class-ReceiceJson : 数据格式错误,请输入标准Json格式或产生异常!\n");
         //  throw;
     }
 }
예제 #14
0
        public void SkyinforVideoServer()
        {
            List <string> rtspList = new List <string>();
            List <string> idList   = new List <string>();
            int           k        = 0;

            //遍历一下所有的摄像头rtsp流,传入rtsp流地址,通道号,就能实现转换了,不是判断摄像头online,判断device_transcoding_flag,然后传入rtsp地址
            for (int i = 0; i < StaticData.g_dtCamera.Rows.Count; i++)
            {
                //  if (StaticData.g_dtCamera.Rows[i]["摄像头状态"].ToString()=="online")
                if (Convert.ToInt32(StaticData.g_dtCamera.Rows[i]["转码标识"]) == 1)
                {
                    rtspList.Add(StaticData.g_dtCamera.Rows[i]["RTSP地址"].ToString());
                    idList.Add(k.ToString());
                    k++;
                }
            }


            //显示视频转码路数
            CrossThreadOperationControl CrossDele_VideoCount = delegate()
            {
                Mainform.form1.textBoxVideo.Text = rtspList.Count + "路";
            };

            Mainform.form1.textBoxVideo.Invoke(CrossDele_VideoCount);
            try
            {
                skyinforVideoShare(rtspList.ToArray(), idList.ToArray(), rtspList.Count);//该处暂时写死了------------
            }
            catch (Exception)
            {
                //自己写的代码,肯定有异常,先不管了。。。测试能用了再说
                StaticUtils.ShowEventMsg("SkyinforVideoTransform.class-SkyinforVideoServer : 出现异常!!\n");
                return;
            }
        }
예제 #15
0
 /// <summary>
 /// 该方法用于发送消息给客户端
 /// webSocket发送消息
 /// </summary>
 public void SendMsgToWebSocketClients(string strMsg)
 {
     //发送消息给各个客户端
     if (WebSocket.m_listClient != null)
     {
         foreach (Socket clientSocket in WebSocket.m_listClient.Values)
         {
             try
             {
                 //发送摄像头状态信息给每一个客户端
                 // string msg = ProcessMsgQuery();
                 if (strMsg != null)
                 {
                     websocket.SendMessage(clientSocket, strMsg);
                 }
             }
             catch (Exception ex)
             {
                 StaticUtils.ShowEventMsg("Mainform.class-SendMsgToWebSocketClients : 轮询发送数据出现异常!!\n");
                 Console.WriteLine("轮询发送数据出错" + ex);
             }
         }
     }
 }
예제 #16
0
        public void WifiList_Get()
        {
            while (true)
            {
                string msg = "";
                // out  格式类似于C 中的 pointer
                string responseString = DigestAuthClient.Request(StaticData.g_strWifiUrl, "GET", out msg);
                if ("".Equals(responseString))
                {
                    StaticUtils.ShowEventMsg("Wifi数据获取失败: " + msg + "\n");
                }
                else
                {
                    JObject jo  = (JObject)JsonConvert.DeserializeObject(responseString);
                    JArray  jar = JArray.Parse(jo["apBasicInfo"].ToString());
                    for (var i = 0; i < jar.Count; i++)
                    {
                        JObject j = JObject.Parse(jar[i].ToString());

                        //发现问题, 管理中心中设备的名称会不定期发生变化;故此处查询条件选用设备唯一 SN
                        string    serialId = j["serialId"].ToString();
                        DataRow[] dr       = StaticData.g_dtWifi.Select("SN='" + serialId + "'");//表格的行

                        // 根据get得到的json 刷新界面
                        //  onlineStatus	:对于Fit AP,0表示不在线,1表示在线。整数(Integer)类型。
                        //  status:设备状态 -1:未管理,0:未知,1:正常,2:警告,3:次要,4:重要,5:严重 。  整数(Integer)类型。
                        if (dr.Length > 0)
                        {
                            switch (Convert.ToInt32(j["onlineStatus"].ToString()))
                            {
                            case 0:
                                dr[0]["在线状态"] = "掉线";
                                break;

                            case 1:
                                dr[0]["在线状态"] = "在线";
                                break;

                            default:
                                dr[0]["在线状态"] = "掉线";
                                break;
                            }
                            switch (Convert.ToInt32(j["status"].ToString()))
                            {
                            case -1:
                                dr[0]["wifi设备状态"] = "未管理";
                                break;

                            case 0:
                                dr[0]["wifi设备状态"] = "未知";
                                break;

                            case 1:
                                dr[0]["wifi设备状态"] = "正常";
                                break;

                            case 2:
                                dr[0]["wifi设备状态"] = "警告";
                                break;

                            case 3:
                                dr[0]["wifi设备状态"] = "次要";
                                break;

                            case 4:
                                dr[0]["wifi设备状态"] = "重要";
                                break;

                            case 5:
                                dr[0]["wifi设备状态"] = "严重";
                                break;

                            default:
                                dr[0]["wifi设备状态"] = "未管理";
                                break;
                            }
                            dr[0]["接入人数"] = j["onlineClientCount"].ToString();
                            dr[0]["时间"]   = DateTime.Now.ToString();

                            //根据GET到的数据更新DB device_wifi
                            updateDbWifi(serialId, dr[0]["在线状态"].ToString(), dr[0]["wifi设备状态"].ToString(), dr[0]["接入人数"].ToString(), dr[0]["时间"].ToString());

                            // 判断wifi 设备是否故障 报警
                            judgeWifiDeviceBreakdown(dr[0]["theone"].ToString());
                        }
                    }
                }
                Thread.Sleep(20 * 1000); // 30s Sleep Time
            }
        }
예제 #17
0
        /// <summary>
        /// 将异常record作为新的event record插入event_assemble & event_park
        /// 判断数据库是否存在该事件,且时间是否x seconds以上才再次触发,存在且是的话插入新事件
        /// x为StaticData中的全局变量
        /// </summary>
        /// <param name="parkName"> 闸机名称 </param>
        /// <param name="strLevel"> 事件等级判断 </param>
        public string insertRecordToEventDb(string parkName, string strLevel)
        {
            if (StaticData.g_msParkingDBC.State == System.Data.ConnectionState.Closed)
            {
                StaticData.g_msParkingDBC.Open();
            }

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

            DataRow[] dr              = StaticData.g_dtParking.Select("停车场名称='" + parkName + "'");
            string    theone          = dr[0]["theone"].ToString();
            string    strParkPosition = 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;

            try
            {
                sqlReader = cmd.ExecuteReader();
            }
            catch
            {
                StaticUtils.ShowEventMsg("SkyinforParking.class-insertRecordToEventDb : 执行数据库查询语句失败!\n");
                return("");
            }
            if (sqlReader.Read())
            {
                // 计算两个dateTime 的时间戳,单位s
                long timeSpan = StaticUtils.GetCurrentTimeUnix(DateTime.Now) - StaticUtils.GetCurrentTimeUnix(Convert.ToDateTime(sqlReader["end_time"]));
                if (timeSpan < StaticData.g_intParkWarningIntervalTime)
                {
                    sqlReader.Close();
                    // 返回\"\"代表无需后续步骤,eg step: web端上传
                    return("");
                }
                else if (sqlReader["event_status"].ToString().Equals("已读"))
                {
                    sqlReader.Close();
                    // 返回\"\"代表无需后续步骤,eg step: web端上传
                    return("");
                }
            }

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

            string strInsert_assemble = "";
            string strInsert_park     = "";

            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_park','" + DateTime.Now.ToString().Replace('/', '-') + "','" + DateTime.Now.ToString().Replace('/', '-') + "','未读','" +
                                     strParkPosition + "','" + strLevel + "','" + theone + "');";
                strInsert_park = "INSERT INTO event_park (event_theone,device_event_type,device_theone) values" +
                                 "('" + strEventTheOne + "','" + event_name + "','" + theone + "');";
            }
            else
            {
                // 数据库存储按照等级进行存储, 级别越低,id越低
                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_park','" + DateTime.Now.ToString().Replace('/', '-') + "','" + DateTime.Now.ToString().Replace('/', '-') + "','未读','" +
                                     strParkPosition + "','" + strLevel + "','" + theone + "');";
                strInsert_park = "INSERT INTO event_park (event_theone,device_event_type,device_theone) values" +
                                 "('" + strEventTheOne + "','" + event_name + "','" + theone + "');";
            }
            MySqlCommand insertAssembleCmd = new MySqlCommand(strInsert_assemble, StaticData.g_msParkingDBC);
            MySqlCommand insertParkCmd     = new MySqlCommand(strInsert_park, StaticData.g_msParkingDBC);
            string       currentMethodName = System.Reflection.MethodBase.GetCurrentMethod().Name;

            StaticUtils.DBNonQueryOperationException(ref insertAssembleCmd, currentClassName, currentMethodName);
            StaticUtils.DBNonQueryOperationException(ref insertParkCmd, currentClassName, currentMethodName);
            return(strEventTheOne);
        }
예제 #18
0
        /// <summary>
        /// 第三方系统初始化函数
        /// </summary>
        private void InitDevices()
        {
            ///
            ///初始化摄像头
            ///
            #region
            //初始化安防NVR与IPC
            //首先初始化数据库连接
            DBConnect getVideoCBDBC = new DBConnect();
            try
            {
                if (getVideoCBDBC.msConn.State == System.Data.ConnectionState.Closed)
                {
                    getVideoCBDBC.msConn.Open();
                }
                StaticData.g_msVideCallBackConn = getVideoCBDBC.msConn;//将数据库连接指向静态全局,保持开放为事件回调写入提供
            }
            catch
            {
                StaticUtils.ShowEventMsg("Mainform.class-InitDevices : 初始化摄像头数据库连接出现异常 !!\n");
            }

            DBConnect dbcVideoQueryDBC = new DBConnect();
            try
            {
                if (dbcVideoQueryDBC.msConn.State == System.Data.ConnectionState.Closed)
                {
                    dbcVideoQueryDBC.msConn.Open();
                }
                StaticData.g_msVideQueryConn = dbcVideoQueryDBC.msConn;//将数据库连接指向静态全局,保持开放为事件回调写入提供
            }
            catch
            {
                StaticUtils.ShowEventMsg("Mainform.class-InitDevices : 初始化摄像头数据库连接出现异常 !!\n");
            }
            #endregion

            ///
            ///初始化广播,建立广播相关的数据库连接
            ///
            #region
            //将获取到的数据库信息存入到datatable
            DBConnect getBroadcastDBC = new DBConnect();
            try
            {
                if (getBroadcastDBC.msConn.State == System.Data.ConnectionState.Closed)
                {
                    getBroadcastDBC.msConn.Open();
                }
                StaticData.g_msBroadcastgDBC = getBroadcastDBC.msConn; //将数据库连接指向静态全局,保持开放为事件回调写入提供
                                                                       //然后把远程数据库的数据存入到datatable
                string          strCMD             = "select * from device_broadcast;";
                MySqlCommand    cmd                = new MySqlCommand(strCMD, StaticData.g_msBroadcastgDBC);
                MySqlDataReader sqlReaderBroadcast = cmd.ExecuteReader();
                while (sqlReaderBroadcast.Read())
                {
                    DataRow dr = StaticData.g_dtBroadcastDevice.NewRow();//表格的行
                    dr["编号"]     = Convert.ToInt32(sqlReaderBroadcast["device_bianhao"]);
                    dr["名称"]     = sqlReaderBroadcast["device_name"].ToString();
                    dr["类型"]     = sqlReaderBroadcast["device_type"].ToString();
                    dr["IP"]     = sqlReaderBroadcast["device_ip"].ToString();
                    dr["连通"]     = sqlReaderBroadcast["device_liantong"].ToString();
                    dr["状态"]     = sqlReaderBroadcast["device_status"].ToString();
                    dr["频道"]     = sqlReaderBroadcast["device_channel"].ToString();
                    dr["theone"] = sqlReaderBroadcast["device_theone"].ToString();
                    dr["音量"]     = sqlReaderBroadcast["device_volume"].ToString();
                    if (sqlReaderBroadcast["device_time"].ToString() == null || "".Equals(sqlReaderBroadcast["device_time"].ToString()))
                    {
                        dr["时间"] = "";
                    }
                    else
                    {
                        dr["时间"] = Convert.ToDateTime(sqlReaderBroadcast["device_time"].ToString());
                    }
                    dr["坐标"] = sqlReaderBroadcast["device_position"].ToString();
                    StaticData.g_dtBroadcastDevice.Rows.Add(dr); //添加
                }
                sqlReaderBroadcast.Close();                      // 写入操作关闭, 数据库连接保持开放
                StaticData.g_msBroadcastgDBC.Close();
            }
            catch
            {
                //  throw;
                StaticUtils.ShowEventMsg("Mainform.class-InitDevices : 初始化广播,建立广播相关的数据库连接出现异常 !!\n");
            }
            #endregion

            ///
            ///初始化停车场
            ///
            #region
            DBConnect getParkingDBC = new DBConnect();
            try
            {
                if (getParkingDBC.msConn.State == System.Data.ConnectionState.Closed)
                {
                    getParkingDBC.msConn.Open();
                }
                StaticData.g_msParkingDBC = getParkingDBC.msConn;//将数据库连接指向静态全局,保持开放为事件回调写入提供

                string          strCMD           = "select * from device_park;";
                MySqlCommand    cmd              = new MySqlCommand(strCMD, StaticData.g_msParkingDBC);
                MySqlDataReader sqlReaderParking = cmd.ExecuteReader();
                while (sqlReaderParking.Read())
                {
                    DataRow dr = StaticData.g_dtParking.NewRow();//表格的行
                    dr["停车场名称"]  = sqlReaderParking["device_name"].ToString();
                    dr["总车位数"]   = Convert.ToInt32(sqlReaderParking["device_all_park"]);
                    dr["未使用车位"]  = Convert.ToInt32(sqlReaderParking["device_rest_park"]);
                    dr["已使用车位"]  = Convert.ToInt32(sqlReaderParking["device_all_park"]) - Convert.ToInt32(sqlReaderParking["device_rest_park"]);
                    dr["时间"]     = sqlReaderParking["device_time"].ToString();
                    dr["地址"]     = sqlReaderParking["device_address"].ToString();
                    dr["类别"]     = sqlReaderParking["device_park_id"].ToString();
                    dr["theone"] = sqlReaderParking["device_theone"].ToString();
                    dr["坐标"]     = sqlReaderParking["device_position"].ToString();
                    StaticData.g_dtParking.Rows.Add(dr); //添加
                }
                sqlReaderParking.Close();                // 写入操作关闭, 数据库连接保持开放
                StaticData.g_msParkingDBC.Close();
            }
            catch
            {
                //  throw;
                StaticUtils.ShowEventMsg("Mainform.class-InitDevices : 初始化停车场出现异常 !!\n");
            }
            #endregion

            ///
            ///初始化闸机系统
            ///
            #region
            DBConnect getGateDBC = new DBConnect();
            try
            {
                if (getGateDBC.msConn.State == System.Data.ConnectionState.Closed)
                {
                    getGateDBC.msConn.Open();
                }
                StaticData.g_msGateDBC = getGateDBC.msConn;

                string          strCMD        = "select device_name,device_time,concat_ws(',',ST_X(device_point),ST_Y(device_point),device_height) as device_position,device_address,device_theone  from device_gate;";
                MySqlCommand    cmd           = new MySqlCommand(strCMD, StaticData.g_msGateDBC);
                MySqlDataReader sqlReaderGate = cmd.ExecuteReader();
                while (sqlReaderGate.Read())
                {
                    DataRow dr = StaticData.g_dtGate.NewRow();//表格的行
                    dr["闸机名称"]    = sqlReaderGate["device_name"].ToString();
                    dr["此闸机入园人数"] = 0;
                    dr["此闸机出园人数"] = 0;
                    dr["时间"]      = sqlReaderGate["device_time"].ToString();
                    dr["坐标"]      = sqlReaderGate["device_position"].ToString();
                    dr["地址"]      = sqlReaderGate["device_address"].ToString();
                    dr["theone"]  = sqlReaderGate["device_theone"].ToString();
                    StaticData.g_dtGate.Rows.Add(dr); //添加
                }
                sqlReaderGate.Close();                // 写入操作关闭, 数据库连接保持开放
                StaticData.g_msGateDBC.Close();
            }
            catch
            {
                StaticUtils.ShowEventMsg("Mainform.class-InitDevices : 初始化停车场 !!\n");
            }
            #endregion

            ///
            ///初始化机房环控
            ///
            #region
            DBConnect getMachineRoom = new DBConnect();
            //机房设备数据实时写入到远端数据库中, 故需轮询远端数据库
            MachineRoomRemoteDBConnect getRemoteMachineRoom = new MachineRoomRemoteDBConnect();  // 开启机房远程数据库连接
            try
            {
                if (getMachineRoom.msConn.State == System.Data.ConnectionState.Closed)
                {
                    getMachineRoom.msConn.Open();
                }
                StaticData.g_msMachineRoomDBC = getMachineRoom.msConn;

                if (getRemoteMachineRoom.msConn.State == System.Data.ConnectionState.Closed)
                {
                    getRemoteMachineRoom.msConn.Open();
                }
                StaticData.g_msMachineRoomRemoteDBC = getRemoteMachineRoom.msConn;

                string          strCMD = "select * from device_computer_room;";
                MySqlCommand    cmd    = new MySqlCommand(strCMD, StaticData.g_msMachineRoomDBC);
                MySqlDataReader sqlReaderMachineRoom = cmd.ExecuteReader();
                while (sqlReaderMachineRoom.Read())
                {
                    DataRow dr = StaticData.g_dtMachineRoom.NewRow();//表格的行
                    dr["机房名称"]   = sqlReaderMachineRoom["device_name"].ToString();
                    dr["坐标"]     = sqlReaderMachineRoom["device_position"].ToString();
                    dr["theone"] = sqlReaderMachineRoom["device_theone"].ToString();
                    dr["地址"]     = sqlReaderMachineRoom["device_address"].ToString();
                    StaticData.g_dtMachineRoom.Rows.Add(dr);//添加
                }
                sqlReaderMachineRoom.Close();
                StaticData.g_msMachineRoomDBC.Close();
            }
            catch
            {
                StaticUtils.ShowEventMsg("Mainform.class-InitDevices : 初始化机房环控出现异常 !!\n");
            }
            #endregion
            ///
            ///初始化Wifi数据库连接
            ///
            #region
            DBConnect getDeviceWifi = new DBConnect();
            try
            {
                if (getDeviceWifi.msConn.State == System.Data.ConnectionState.Closed)
                {
                    getDeviceWifi.msConn.Open();
                }
                StaticData.g_msWifiDBC = getDeviceWifi.msConn;

                string          strCMD        = "select * from device_wifi;";
                MySqlCommand    cmd           = new MySqlCommand(strCMD, StaticData.g_msWifiDBC);
                MySqlDataReader sqlReaderGate = cmd.ExecuteReader();
                while (sqlReaderGate.Read())
                {
                    DataRow dr = StaticData.g_dtWifi.NewRow();//表格的行
                    dr["Ap名称"]     = sqlReaderGate["device_name"].ToString();
                    dr["Ap中文名称"]   = sqlReaderGate["device_ap_chinesename"].ToString();
                    dr["Ap型号"]     = sqlReaderGate["device_ap_model"].ToString();
                    dr["wifi设备状态"] = sqlReaderGate["device_status"].ToString();
                    dr["在线状态"]     = sqlReaderGate["device_onlinestatus"].ToString();
                    dr["接入人数"]     = sqlReaderGate["device_person_online"].ToString();
                    dr["Ap安装位置"]   = sqlReaderGate["device_address"].ToString();
                    dr["时间"]       = sqlReaderGate["device_time"].ToString();
                    dr["安装方式"]     = sqlReaderGate["device_install_type"].ToString();
                    dr["Ap标志"]     = sqlReaderGate["device_ap_tag"].ToString();
                    dr["WIFI坐标"]   = sqlReaderGate["device_position"].ToString();
                    dr["theone"]   = sqlReaderGate["device_theone"].ToString();
                    dr["SN"]       = sqlReaderGate["device_ap_sn"].ToString();
                    StaticData.g_dtWifi.Rows.Add(dr);//添加
                }

                sqlReaderGate.Close(); // 写入操作关闭
                StaticData.g_msWifiDBC.Close();
            }
            catch
            {
                StaticUtils.ShowEventMsg("Mainform.class-InitDevices : 初始化Wifi数据库连接出现异常 !!\n");
            }
            #endregion

            ///
            ///初始化异常事件数据库连接  &&  异常信息DataTable 初始化
            ///
            #region
            DBConnect getEventAssemble = new DBConnect();
            try
            {
                if (getEventAssemble.msConn.State == System.Data.ConnectionState.Closed)
                {
                    getEventAssemble.msConn.Open();
                }
                StaticData.g_msEventAssembleDBC = getEventAssemble.msConn;

                string          strCMD = "select * from event_type;";
                MySqlCommand    cmd    = new MySqlCommand(strCMD, StaticData.g_msEventAssembleDBC);
                MySqlDataReader sqlReaderAbnormalInfor = cmd.ExecuteReader();
                while (sqlReaderAbnormalInfor.Read())
                {
                    DataRow dr = StaticData.g_dtAbnormalInfor.NewRow();//表格的行
                    dr["ID"]     = sqlReaderAbnormalInfor["id"].ToString();
                    dr["故障父类名称"] = sqlReaderAbnormalInfor["event_type"].ToString();
                    dr["故障子类名称"] = sqlReaderAbnormalInfor["event_type_name"].ToString();
                    dr["父ID"]    = sqlReaderAbnormalInfor["parent_id"].ToString();
                    StaticData.g_dtAbnormalInfor.Rows.Add(dr);//添加
                }

                sqlReaderAbnormalInfor.Close(); // 写入操作关闭
                StaticData.g_msEventAssembleDBC.Close();
            }
            catch
            {
                StaticUtils.ShowEventMsg("Mainform.class-InitDevices : 初始化异常事件数据库连接出现异常 !!\n");
            }
            StaticData.g_msEventAssembleDBC.Close();
            #endregion
        }
예제 #19
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");
            }
        }
예제 #20
0
        /// <summary>
        /// 用于更新UI中的在线数、掉线数、报警数等信息
        /// </summary>
        public void UpdateForm()
        {
            DataRow[] dtrCamera_Online     = null; //获取摄像头在线的行数
            DataRow[] dtrCamera_Offline    = null; //获取摄像头掉线的行数
            DataRow[] dtrBroadcast_Online  = null; //获取广播在线的行数
            DataRow[] dtrBroadcast_Offline = null; //获取广播离线的行数
            while (true)
            {
                Thread.Sleep(5000);
                try
                {
                    dtrCamera_Online  = StaticData.g_dtCamera.Select("摄像头状态='正常'"); //获取摄像头在线的行数
                    dtrCamera_Offline = StaticData.g_dtCamera.Select("摄像头状态='掉线'"); //获取摄像头掉线的行数
                }
                catch (Exception)
                {
                    StaticUtils.ShowEventMsg("Mainform.class-UpdateForm : 获取摄像头在线数据出现异常!!\n");
                }
                try
                {
                    dtrBroadcast_Online  = StaticData.g_dtBroadcastDevice.Select("连通='连通'");   //获取广播在线的行数
                    dtrBroadcast_Offline = StaticData.g_dtBroadcastDevice.Select("连通 <>'连通'"); //获取广播离线的行数
                }
                catch (Exception)
                {
                    StaticUtils.ShowEventMsg("Mainform.class-UpdateForm : 获取广播在线数据出现异常!!\n");
                }

                #region 跨线程更新UI界面

                if (dtrCamera_Online != null)
                {
                    CrossThreadOperationControl CrossDele_CamOnline = delegate()
                    {
                        Mainform.form1.textBoxCameraOnline.Text = dtrCamera_Online.Length.ToString();
                    };
                    Mainform.form1.textBoxCameraOnline.Invoke(CrossDele_CamOnline);
                    CrossThreadOperationControl CrossDele_CamOffline = delegate()
                    {
                        Mainform.form1.textBoxCameraOffline.Text = dtrCamera_Offline.Length.ToString();
                    };
                    Mainform.form1.textBoxCameraOffline.Invoke(CrossDele_CamOffline);
                    CrossThreadOperationControl CrossDele_AlarmNum = delegate()
                    {
                        Mainform.form1.textBoxCameraAlarm.Text = StaticData.g_inAlarmNum.ToString();
                    };
                    Mainform.form1.textBoxCameraAlarm.Invoke(CrossDele_AlarmNum);
                }

                if (dtrBroadcast_Online != null)
                {
                    CrossThreadOperationControl CrossDele_BroadOnline = delegate()
                    {
                        Mainform.form1.textBoxBroadcastOnline.Text = dtrBroadcast_Online.Length.ToString();
                    };
                    Mainform.form1.textBoxBroadcastOnline.Invoke(CrossDele_BroadOnline);
                    CrossThreadOperationControl CrossDele_BroadOffline = delegate()
                    {
                        Mainform.form1.textBoxBroadcastOffline.Text = dtrBroadcast_Offline.Length.ToString();
                    };
                    Mainform.form1.textBoxBroadcastOffline.Invoke(CrossDele_BroadOffline);
                }
                #endregion
            }
        }
        /// <summary>
        /// 越界侦测用的报警
        /// </summary>
        /// <param name="pAlarmer"></param>
        /// <param name="pAlarmInfo"></param>
        /// <param name="dwBufLen"></param>
        /// <param name="pUser"></param>
        private void ProcessCommAlarm_RULE(ref CHCNetSDK.NET_DVR_ALARMER pAlarmer, IntPtr pAlarmInfo, uint dwBufLen, IntPtr pUser)
        {
            string strNvrIp = pAlarmer.sDeviceIP;//报警nvrIp地址

            CHCNetSDK.NET_VCA_RULE_ALARM struRuleAlarmInfo = new CHCNetSDK.NET_VCA_RULE_ALARM();
            //看下报警信息里面有没有通道号,
            struRuleAlarmInfo = (CHCNetSDK.NET_VCA_RULE_ALARM)Marshal.PtrToStructure(pAlarmInfo, typeof(CHCNetSDK.NET_VCA_RULE_ALARM));
            byte channel = struRuleAlarmInfo.struDevInfo.byChannel;
            //报警设备IP地址
            string strIP = struRuleAlarmInfo.struDevInfo.struDevIP.sIpV4;
            //报警信息
            string stringAlarm = "";
            uint   dwSize      = (uint)Marshal.SizeOf(struRuleAlarmInfo.struRuleInfo.uEventParam);

            switch (struRuleAlarmInfo.struRuleInfo.wEventTypeEx)
            {
            case (ushort)CHCNetSDK.VCA_RULE_EVENT_TYPE_EX.ENUM_VCA_EVENT_TRAVERSE_PLANE:
                IntPtr ptrTraverseInfo = Marshal.AllocHGlobal((Int32)dwSize);
                Marshal.StructureToPtr(struRuleAlarmInfo.struRuleInfo.uEventParam, ptrTraverseInfo, false);
                CHCNetSDK.NET_VCA_TRAVERSE_PLANE m_struTraversePlane = (CHCNetSDK.NET_VCA_TRAVERSE_PLANE)Marshal.PtrToStructure(ptrTraverseInfo, typeof(CHCNetSDK.NET_VCA_TRAVERSE_PLANE));
                stringAlarm = "穿越警戒面,目标ID:" + struRuleAlarmInfo.struTargetInfo.dwID;
                //警戒面边线起点坐标: (m_struTraversePlane.struPlaneBottom.struStart.fX, m_struTraversePlane.struPlaneBottom.struStart.fY)
                //警戒面边线终点坐标: (m_struTraversePlane.struPlaneBottom.struEnd.fX, m_struTraversePlane.struPlaneBottom.struEnd.fY)
                break;

            case (ushort)CHCNetSDK.VCA_RULE_EVENT_TYPE_EX.ENUM_VCA_EVENT_ENTER_AREA:
                IntPtr ptrEnterInfo = Marshal.AllocHGlobal((Int32)dwSize);
                Marshal.StructureToPtr(struRuleAlarmInfo.struRuleInfo.uEventParam, ptrEnterInfo, false);
                CHCNetSDK.NET_VCA_AREA m_struVcaArea = (CHCNetSDK.NET_VCA_AREA)Marshal.PtrToStructure(ptrEnterInfo, typeof(CHCNetSDK.NET_VCA_AREA));
                stringAlarm = "目标进入区域,目标ID:" + struRuleAlarmInfo.struTargetInfo.dwID;
                //m_struVcaArea.struRegion 多边形区域坐标
                break;

            case (ushort)CHCNetSDK.VCA_RULE_EVENT_TYPE_EX.ENUM_VCA_EVENT_EXIT_AREA:
                IntPtr ptrExitInfo = Marshal.AllocHGlobal((Int32)dwSize);
                Marshal.StructureToPtr(struRuleAlarmInfo.struRuleInfo.uEventParam, ptrExitInfo, false);
                m_struVcaArea = (CHCNetSDK.NET_VCA_AREA)Marshal.PtrToStructure(ptrExitInfo, typeof(CHCNetSDK.NET_VCA_AREA));
                stringAlarm   = "目标离开区域,目标ID:" + struRuleAlarmInfo.struTargetInfo.dwID;
                //m_struVcaArea.struRegion 多边形区域坐标
                break;

            case (ushort)CHCNetSDK.VCA_RULE_EVENT_TYPE_EX.ENUM_VCA_EVENT_INTRUSION:
                IntPtr ptrIntrusionInfo = Marshal.AllocHGlobal((Int32)dwSize);
                Marshal.StructureToPtr(struRuleAlarmInfo.struRuleInfo.uEventParam, ptrIntrusionInfo, false);
                CHCNetSDK.NET_VCA_INTRUSION m_struIntrusion = (CHCNetSDK.NET_VCA_INTRUSION)Marshal.PtrToStructure(ptrIntrusionInfo, typeof(CHCNetSDK.NET_VCA_INTRUSION));
                stringAlarm = "周界入侵,目标ID:" + struRuleAlarmInfo.struTargetInfo.dwID;
                //m_struIntrusion.struRegion 多边形区域坐标
                break;

            default:
                stringAlarm = "其他行为分析报警,目标ID:" + struRuleAlarmInfo.struTargetInfo.dwID;
                break;
            }


            //报警图片保存
            if (struRuleAlarmInfo.dwPicDataLen > 0)
            {
                FileStream fs   = new FileStream("行为分析报警抓图.jpg", FileMode.Create);
                int        iLen = (int)struRuleAlarmInfo.dwPicDataLen;
                byte[]     by   = new byte[iLen];
                Marshal.Copy(struRuleAlarmInfo.pImage, by, 0, iLen);
                fs.Write(by, 0, iLen);
                fs.Close();
            }

            //报警时间:年月日时分秒
            string time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");

            string theone   = "0";
            string name     = "";
            string position = "";

            try
            {
                //根据数据库找到theone、摄像头名称等内容
                //找到了目前这个函数通道所在的NVR,
                //然后根据通道号跟NVRip地址,找到摄像头
                string    srtSql = "IP地址 ='" + strIP + "'";
                DataRow[] dr     = StaticData.g_dtCamera.Select(srtSql);
                if (dr.Length > 0)
                {
                    theone   = dr[0]["theone"].ToString();
                    name     = dr[0]["摄像头名称"].ToString();
                    position = dr[0]["坐标"].ToString();
                }
                else
                {
                    // 处理获取非指定camaras错误回调后所产生的数据为空的异常情况
                    // 异常eg:  发现了非列表中的未知nvrip = “10.1.12.51”的设备
                    return;
                }
            }
            catch (Exception)
            {
                StaticUtils.ShowEventMsg("HikvisionAlarmCallBackFun.class-ProcessCommAlarm_RULE : 报警回调函数出现异常!\n");
                //throw;
            }

            //读取事件数据库,判断数据库是否存在该事件,且时间是否2分钟以上差别,存在且是的话插入新事件
            //不是的话更新endtime字段为当前时间
            //不存在的话直接插入数据,还需要插入个摄像头的位置,名称
            string[] paras = new string[2]
            {
                time, strNvrIp
            };
            string str_channel = Convert.ToString(channel);

            CheckEvent(name, theone, stringAlarm, DateTime.Now.ToString().Replace('/', '-'), position, name, paras, str_channel);
        }
        private void ProcessCommAlarm_V30(ref CHCNetSDK.NET_DVR_ALARMER pAlarmer, IntPtr pAlarmInfo, uint dwBufLen, IntPtr pUser)
        {
            CHCNetSDK.NET_DVR_ALARMINFO_V30 struAlarmInfoV30 = new CHCNetSDK.NET_DVR_ALARMINFO_V30();

            struAlarmInfoV30 = (CHCNetSDK.NET_DVR_ALARMINFO_V30)Marshal.PtrToStructure(pAlarmInfo, typeof(CHCNetSDK.NET_DVR_ALARMINFO_V30));

            string strIP       = pAlarmer.sDeviceIP;
            string stringAlarm = "";
            int    i;

            switch (struAlarmInfoV30.dwAlarmType)
            {
            case 0:
                stringAlarm = "信号量报警,报警报警输入口:" + struAlarmInfoV30.dwAlarmInputNumber + ",触发录像通道:";
                for (i = 0; i < CHCNetSDK.MAX_CHANNUM_V30; i++)
                {
                    if (struAlarmInfoV30.byAlarmRelateChannel[i] == 1)
                    {
                        stringAlarm += (i + 1 - 32) + ",";
                    }
                }
                break;

            case 1:
                stringAlarm = "硬盘满,";
                for (i = 0; i < CHCNetSDK.MAX_DISKNUM_V30; i++)
                {
                    if (struAlarmInfoV30.byDiskNumber[i] == 1)
                    {
                        stringAlarm += (i + 1 - 32) + ",";
                    }
                }
                break;

            case 2:
                stringAlarm = "信号丢失,";
                for (i = 0; i < CHCNetSDK.MAX_CHANNUM_V30; i++)
                {
                    if (struAlarmInfoV30.byChannel[i] == 1)
                    {
                        stringAlarm += (i + 1 - 32) + ",";
                    }
                }
                break;

            case 3:
                stringAlarm = "移动侦测,";
                for (i = 0; i < CHCNetSDK.MAX_CHANNUM_V30; i++)       //MAX_CHANNUM_V30
                {
                    if (struAlarmInfoV30.byChannel[i] == 1)
                    {
                        stringAlarm += (i + 1 - 32) + ",";
                    }
                }
                break;

            case 4:
                stringAlarm = "硬盘未格式化,";
                for (i = 0; i < CHCNetSDK.MAX_DISKNUM_V30; i++)
                {
                    if (struAlarmInfoV30.byDiskNumber[i] == 1)
                    {
                        stringAlarm += (i + 1 - 32) + ",";
                    }
                }
                break;

            case 5:
                stringAlarm = "读写硬盘出错,";
                for (i = 0; i < CHCNetSDK.MAX_DISKNUM_V30; i++)
                {
                    if (struAlarmInfoV30.byDiskNumber[i] == 1)
                    {
                        stringAlarm += (i + 1 - 32) + ",";
                    }
                }
                break;

            case 6:
                stringAlarm = "遮挡报警,";
                for (i = 0; i < CHCNetSDK.MAX_CHANNUM_V30; i++)
                {
                    if (struAlarmInfoV30.byChannel[i] == 1)
                    {
                        stringAlarm += (i + 1 - 32) + ",";
                    }
                }
                break;

            case 7:
                stringAlarm = "制式不匹配,";
                for (i = 0; i < CHCNetSDK.MAX_CHANNUM_V30; i++)
                {
                    if (struAlarmInfoV30.byChannel[i] == 1)
                    {
                        stringAlarm += (i + 1 - 32) + ",";
                    }
                }
                break;

            case 8:
                stringAlarm = "非法访问,";
                break;

            case 9:
                stringAlarm = "视频信号异常,";
                for (i = 0; i < CHCNetSDK.MAX_CHANNUM_V30; i++)
                {
                    if (struAlarmInfoV30.byChannel[i] == 1)
                    {
                        stringAlarm += (i + 1 - 32) + ",";
                    }
                }
                break;

            case 10:
                stringAlarm = "录像/抓图异常,";
                for (i = 0; i < CHCNetSDK.MAX_CHANNUM_V30; i++)
                {
                    if (struAlarmInfoV30.byChannel[i] == 1)
                    {
                        stringAlarm += (i + 1 - 32) + ",";
                    }
                }
                break;

            case 11:
                stringAlarm = "智能场景变化,";
                for (i = 0; i < CHCNetSDK.MAX_CHANNUM_V30; i++)
                {
                    if (struAlarmInfoV30.byChannel[i] == 1)
                    {
                        stringAlarm += (i + 1 - 32) + ",";
                    }
                }
                break;

            case 12:
                stringAlarm = "阵列异常,";
                break;

            case 13:
                stringAlarm = "前端/录像分辨率不匹配,";
                for (i = 0; i < CHCNetSDK.MAX_CHANNUM_V30; i++)
                {
                    if (struAlarmInfoV30.byChannel[i] == 1)
                    {
                        stringAlarm += (i + 1 - 32) + ",";
                    }
                }
                break;

            case 15:
                stringAlarm = "智能侦测,";
                for (i = 0; i < CHCNetSDK.MAX_CHANNUM_V30; i++)
                {
                    if (struAlarmInfoV30.byChannel[i] == 1)
                    {
                        stringAlarm += (i + 1 - 32) + ",";
                    }
                }
                break;

            default:
                stringAlarm = "其他未知报警信息,";
                break;
            }
            //在这里为报警信息
            if (true)
            {
                string[] paras = new string[3];
                paras[0] = DateTime.Now.ToString();      //当前PC系统时间
                paras[1] = strIP;                        //nvrip地址
                paras[2] = stringAlarm;
                string[] alarmMsg = paras[2].Split(','); //报警类型和通道号
                //            Console.WriteLine(paras[0] + "," + paras[1] + "," + paras[2] + "\n");
                //根据数据库找到theone、摄像头名称等内容
                string theone   = "0";
                string name     = "";
                string position = "";
                try
                {
                    //根据数据库找到theone、摄像头名称等内容
                    //找到了目前这个函数通道所在的NVR,
                    //然后根据通道号跟NVRip地址,找到摄像头
                    string    srtSql = "NVRIP地址= '" + paras[1] + "'" + " and  通道号 ='" + alarmMsg[1] + "'";
                    DataRow[] dr     = StaticData.g_dtCamera.Select(srtSql);
                    if (dr.Length > 0)
                    {
                        theone   = dr[0]["theone"].ToString();
                        name     = dr[0]["摄像头名称"].ToString();
                        position = dr[0]["坐标"].ToString();
                    }
                    else
                    {
                        // 处理获取非指定camaras错误回调后所产生的数据为空的异常情况
                        // 异常eg:  发现了非列表中的未知nvrip = “10.1.12.51”的设备
                        return;
                    }
                }
                catch (Exception)
                {
                    StaticUtils.ShowEventMsg("HikvisionAlarmCallBackFun.class-ProcessCommAlarm_V30 : 报警回调函数出现异常!\n");
                    //throw;
                }

                //读取事件数据库,判断数据库是否存在该事件,且时间是否2分钟以上差别,存在且是的话插入新事件
                //不是的话更新endtime字段为当前时间
                //不存在的话直接插入数据,还需要插入个摄像头的位置,名称

                CheckEvent(name, theone, alarmMsg[0], DateTime.Now.ToString().Replace('/', '-'), position, name, paras, alarmMsg[1]);
            }
            else
            {
                //创建该控件的主线程直接更新信息列表
                //  UpdateClientList(DateTime.Now.ToString(), strIP, stringAlarm);
            }
        }
예제 #23
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;
            }
        }
예제 #24
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();
            }
        }
        //读取事件数据库,判断数据库是否存在该事件,且时间是否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");
            }
        }
        /// <summary>
        /// 命令解析函数
        /// </summary>
        /// <param name="strJson"></param>
        /// <returns></returns>
        public string ReceiceJson(string strJson)
        {
            try
            {
                JsonObject joWebCmd      = (JsonObject)JsonValue.Parse(strJson);
                string     strResult     = "null";
                string     strResult2    = "null";
                string     strStatusCode = "0";
                string     strCmd        = "";
                #region 摄像头云台控制命令
                if (joWebCmd["requestType"] == "Camera")
                {
                    string strCameraNVRip   = joWebCmd["requestDetail"]["nvrip"];
                    string strCameraChannel = joWebCmd["requestDetail"]["channel"];
                    string strCameraCmd     = joWebCmd["requestDetail"]["command"];
                    //执行命令
                    HikvisionPTZControl hkPtzCtl = new HikvisionPTZControl();
                    //根据选中的摄像头通道号跟IP地址进行预览
                    //zzt补充,这里加个界面日志,告诉别人收到了什么命令,时间跟
                    DataRow[] dr;
                    switch (strCameraCmd)
                    {
                    case "left":
                        dr = StaticData.g_dtNVR.Select("IP地址= '" + strCameraNVRip + "'");
                        if (dr.Length > 0)
                        {
                            hkPtzCtl.PTZleft(Convert.ToInt32(dr[0]["userid"]), Convert.ToInt32(strCameraChannel));
                        }
                        break;

                    case "right":
                        dr = StaticData.g_dtNVR.Select("IP地址= '" + strCameraNVRip + "'");
                        if (dr.Length > 0)
                        {
                            hkPtzCtl.PTZright(Convert.ToInt32(dr[0]["userid"]), Convert.ToInt32(strCameraChannel));
                        }
                        break;

                    case "up":
                        dr = StaticData.g_dtNVR.Select("IP地址= '" + strCameraNVRip + "'");
                        if (dr.Length > 0)
                        {
                            hkPtzCtl.PTZup(Convert.ToInt32(dr[0]["userid"]), Convert.ToInt32(strCameraChannel));
                        }
                        break;

                    case "down":
                        dr = StaticData.g_dtNVR.Select("IP地址= '" + strCameraNVRip + "'");
                        if (dr.Length > 0)
                        {
                            hkPtzCtl.PTZdown(Convert.ToInt32(dr[0]["userid"]), Convert.ToInt32(strCameraChannel));
                        }
                        break;

                    case "upleft":
                        dr = StaticData.g_dtNVR.Select("IP地址= '" + strCameraNVRip + "'");
                        if (dr.Length > 0)
                        {
                            hkPtzCtl.PTZupleft(Convert.ToInt32(dr[0]["userid"]), Convert.ToInt32(strCameraChannel));
                        }
                        break;

                    case "upright":
                        dr = StaticData.g_dtNVR.Select("IP地址= '" + strCameraNVRip + "'");
                        if (dr.Length > 0)
                        {
                            hkPtzCtl.PTZright(Convert.ToInt32(dr[0]["userid"]), Convert.ToInt32(strCameraChannel));
                        }
                        break;

                    case "downleft":
                        dr = StaticData.g_dtNVR.Select("IP地址= '" + strCameraNVRip + "'");
                        if (dr.Length > 0)
                        {
                            hkPtzCtl.PTZdownleft(Convert.ToInt32(dr[0]["userid"]), Convert.ToInt32(strCameraChannel));
                        }
                        break;

                    case "downright":
                        dr = StaticData.g_dtNVR.Select("IP地址= '" + strCameraNVRip + "'");
                        if (dr.Length > 0)
                        {
                            hkPtzCtl.PTZdownright(Convert.ToInt32(dr[0]["userid"]), Convert.ToInt32(strCameraChannel));
                        }
                        break;

                    case "zoom_out":
                        dr = StaticData.g_dtNVR.Select("IP地址= '" + strCameraNVRip + "'");
                        if (dr.Length > 0)
                        {
                            hkPtzCtl.PTZzoomout(Convert.ToInt32(dr[0]["userid"]), Convert.ToInt32(strCameraChannel));
                        }
                        break;

                    case "zoom_in":
                        dr = StaticData.g_dtNVR.Select("IP地址= '" + strCameraNVRip + "'");
                        if (dr.Length > 0)
                        {
                            hkPtzCtl.PTZzoomin(Convert.ToInt32(dr[0]["userid"]), Convert.ToInt32(strCameraChannel));
                        }
                        break;
                    }

                    //更新下界面
                    StaticUtils.ShowCMDMsg("接收时间:" + DateTime.Now.ToString() + "  摄像头云台控制命令!\n" + "控制nvrip为:" + strCameraNVRip + "   通道号为:" + strCameraChannel + "   命令为:" + strCameraCmd + "\n");

                    //得到状态,下一步封装成json传回去
                    JsonObject returnJS        = SendJson("Camera", strStatusCode, m_lCameraIP, m_lChannel, strCmd, strResult, strResult2);
                    string     strReturnResult = returnJS.ToString();
                    strReturnResult = Encoding.UTF8.GetString(Encoding.UTF8.GetBytes(strReturnResult));
                    return(strReturnResult);
                }
                #endregion


                #region 广播控制命令
                if (joWebCmd["requestType"] == "Broadcast")
                {
                    string strBroadcastDeviceId    = joWebCmd["requestDetail"]["deviceid"];
                    string strBroadcastChannel     = joWebCmd["requestDetail"]["channel"];
                    string strBroadcastDeviceIp    = joWebCmd["requestDetail"]["deviceip"];
                    string strBroadcastVolumeValue = joWebCmd["requestDetail"]["volumeValue"];
                    string strBroadcastCmd         = joWebCmd["requestDetail"]["command"];

                    //执行命令
                    BroadcastUDP broadcastUDP = new BroadcastUDP();
                    //根据选中的摄像头通道号跟IP地址进行预览
                    //zzt补充,这里加个界面日志,告诉别人收到了什么命令,时间跟
                    switch (strBroadcastCmd)
                    {
                    case "volume":
                        //此命令为修改设备音量,需要设备id,设备ip地址,音量值。
                        Byte volumeArray = (Byte)Convert.ToInt32(strBroadcastVolumeValue);     // 将获取到的string转化为 byte
                        broadcastUDP.setBroadcastDeviceVolume(strBroadcastDeviceIp, short.Parse(strBroadcastDeviceId), volumeArray);
                        break;

                    case "stop":
                        //此命令为 强制关闭设备,需要设备id,设备ip地址,音量值。
                        Byte nMode = (Byte)Convert.ToInt32("1");     // 输入默认值 ;强制关闭类型: 1 表示强制关闭
                        broadcastUDP.closeBroadcastDevice(strBroadcastDeviceIp, short.Parse(strBroadcastDeviceId), nMode);
                        break;

                    case "channel":
                        //此命令为 切换设备频道,需要设备id,设备ip地址,频道。
                        Byte nChannel = (Byte)Convert.ToInt32(strBroadcastChannel);
                        broadcastUDP.changeBroadcastDeviceChannel(strBroadcastDeviceIp, short.Parse(strBroadcastDeviceId), nChannel);
                        break;
                    }

                    //更新下界面
                    StaticUtils.ShowCMDMsg("接收时间:" + DateTime.Now.ToString() + "  广播云台控制命令!\n" + "控制广播设备编号为:" + strBroadcastDeviceId + "   命令为:" + strBroadcastCmd + "   广播设备IP为:" + strBroadcastDeviceIp + "\n");
                }
                #endregion

                return(strResult);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                StaticUtils.ShowEventMsg("MgJsonCtrl.class-ReceiceJson : 数据格式错误,请输入标准Json格式或产生异常\n");
                return("数据格式错误,请输入标准Json格式或产生异常");
            }
        }
예제 #27
0
        public void ParkingWebRequest_Get()
        {
            ParkingWebRequest parks = new ParkingWebRequest();

            while (true)
            {
                if (StaticData.g_msParkingDBC.State == System.Data.ConnectionState.Closed)
                {
                    try
                    {
                        StaticData.g_msParkingDBC.Open();
                    }
                    catch
                    {
                        StaticUtils.ShowEventMsg("时间:" + DateTime.Now.ToString() + "SkyinforParking.class- ParkingWebRequest_Get  : 开启数据库查询失败!\n");
                        //sleep,间隔事件轮询
                        Thread.Sleep(StaticData.g_nSystemPollFreq * 1000);
                        continue;
                    }
                }

                //获取停车场数据
                string[] num1 = parks.Post("T1");
                string[] num2 = parks.Post("T2");
                string[] num4 = parks.Post("T4");
                string   time = DateTime.Now.ToString();

                if (num1 == null || num2 == null || num4 == null || num1.Length == 0 || num2.Length == 0 || num4.Length == 0)
                {
                    Thread.Sleep(StaticData.g_nSystemPollFreq * 1000);
                    continue;
                }

                // 更新界面UI
                DataRow[] dr1 = StaticData.g_dtParking.Select("停车场名称='" + num1[2] + "'"); //表格的行
                DataRow[] dr2 = StaticData.g_dtParking.Select("停车场名称='" + num2[2] + "'"); //表格的行
                DataRow[] dr4 = StaticData.g_dtParking.Select("停车场名称='" + num4[2] + "'"); //表格的行
                if (dr1.Length > 0 && dr2.Length > 0 && dr4.Length > 0)
                {
                    dr1[0]["总车位数"]  = num1[3];
                    dr1[0]["已使用车位"] = int.Parse(num1[3]) - int.Parse(num1[0]);
                    dr1[0]["未使用车位"] = num1[0];
                    dr1[0]["时间"]    = time;

                    dr2[0]["总车位数"]  = num2[3];
                    dr2[0]["已使用车位"] = int.Parse(num2[3]) - int.Parse(num2[0]);
                    dr2[0]["未使用车位"] = num2[0];
                    dr2[0]["时间"]    = time;

                    dr4[0]["总车位数"]  = num4[3];
                    dr4[0]["已使用车位"] = int.Parse(num4[3]) - int.Parse(num4[0]);
                    dr4[0]["未使用车位"] = num4[0];
                    dr4[0]["时间"]    = time;

                    //获取到的数据插入到DB:park_number中进行记录
                    insertToDbParkNumber(num1, num2, num4, time);
                    //根据GET到的数据更新DB park
                    updateDbPark(num1[2], int.Parse(num1[3]), int.Parse(num1[0]), num2[2], int.Parse(num2[3]), int.Parse(num2[0]), num4[2], int.Parse(num4[3]), int.Parse(num4[0]));
                    // 判断车辆已使用车位是否过多报警
                    string[] park_name = new string[3] {
                        num1[2], num2[2], num4[2]
                    };
                    int[] park_num = new int[3] {
                        Convert.ToInt32(dr1[0]["已使用车位"]), Convert.ToInt32(dr2[0]["已使用车位"]), Convert.ToInt32(dr4[0]["已使用车位"])
                    };
                    int[] park_total_num = new int[3] {
                        Convert.ToInt32(dr1[0]["总车位数"]), Convert.ToInt32(dr2[0]["总车位数"]), Convert.ToInt32(dr4[0]["总车位数"])
                    };
                    judgeWarning(park_name, park_num, park_total_num);
                }
                ;
                StaticData.g_msParkingDBC.Close();
                //sleep,间隔事件轮询
                Thread.Sleep(StaticData.g_nSystemPollFreq * 1000);
            }
        }