예제 #1
0
        private bool AddDevice()
        {
            string ip        = textNVRIP.Text.Trim();
            int    port      = int.Parse(textNVRPort.Text.Trim());
            string loginName = textLoginName.Text.Trim();
            string password  = textPassword.Text.Trim();

            if (SPlate.SP_InitNVR(ip, port, loginName, password) == 0)
            {
                string sqlString = "insert into videohost (hosttype,hostname,hostip,hostport,loginname,loginpwd,parentid) values (" +
                                   comboDeviceType.SelectedIndex.ToString() + ",'" + textName.Text.Trim() + "','" + ip + "'," + port.ToString() + ",'" + loginName + "','" + password + "',0)";
                Global.LogServer.Add(new LogInfo("ParamSet-Debug", "FormNVR->AddDevice sqlString:" + sqlString, (int)EnumLogLevel.DEBUG));
                Global.mysqlHelper.ExecuteSql(sqlString);
                return(true);
            }
            //switch (comboDeviceType.SelectedIndex)
            //{
            //    case 0: //海康
            //        break;
            //    case 1: //科达
            //        break;
            //    case 2: //大华
            //        break;
            //    default:
            //        break;
            //}
            return(false);
        }
        private void treeMain_DoubleClick(object sender, EventArgs e)
        {
            try
            {
                TreeNode node = treeMain.SelectedNode;
                if (node.Nodes.Count > 0)
                {
                    return;
                }
                foreach (ClsNVRInfo nvr in Global.nvrList)
                {
                    if (node.Text == nvr.nvrName)
                    {
                        try
                        {
                            if (0 == SPlate.SP_InitNVR(nvr.ip, nvr.port, nvr.loginName, nvr.password))
                            {
                                Global.LogServer.Add(new LogInfo("ParamSet-Debug", "SP_InitNVR true", (int)EnumLogLevel.DEBUG));
                                IntPtr ip    = Marshal.AllocHGlobal(Marshal.SizeOf(nvr.config));
                                int    lenth = 0;
                                SPlate.SP_GetNvrCfg(ip, ref lenth);
                                nvr.config = (NET_DVR_IPPARACFG_V40)Marshal.PtrToStructure(ip, typeof(NET_DVR_IPPARACFG_V40));
                                for (int i = 0; i < nvr.config.dwDChanNum; i++)
                                {
                                    Global.LogServer.Add(new LogInfo("ParamSet-Debug", "dwDChanNum:" + i.ToString(), (int)EnumLogLevel.DEBUG));
                                    if (nvr.config.struIPDevInfo[i].byEnable == 1)
                                    {
                                        ClsVideoChannel videoChan = new ClsVideoChannel();
                                        videoChan.ip         = System.Text.Encoding.Default.GetString(nvr.config.struIPDevInfo[i].struIP.sIpV4);
                                        videoChan.channelNo  = i;
                                        videoChan.loginName  = System.Text.Encoding.Default.GetString(nvr.config.struIPDevInfo[i].sUserName);
                                        videoChan.password   = System.Text.Encoding.Default.GetString(nvr.config.struIPDevInfo[i].sPassword);
                                        videoChan.port       = nvr.config.struIPDevInfo[i].wDVRPort;
                                        videoChan.streamType = nvr.config.struStreamMode[i].byGetStreamType;
                                        videoChan.parentID   = nvr.id;

                                        if (!FindVideoChanInList(videoChan.channelNo, videoChan.ip))
                                        {
                                            videoChan.id = Global.mysqlHelper.ExecuteSql(videoChan.getInsertString());
                                            Global.videoList.Add(videoChan);
                                            nvr.videoList.Add(videoChan);
                                        }

                                        TreeNode cNode = new TreeNode();
                                        cNode.Text = "Video" + i.ToString();
                                        node.Nodes.Add(cNode);

                                        Global.LogServer.Add(new LogInfo("ParamSet-Debug", "struIPDevInfo.byEnable true", (int)EnumLogLevel.DEBUG));
                                    }
                                }
                            }
                            Global.sCurSelectedNvrName = nvr.nvrName;
                            break;
                        }
                        catch (System.Exception ex)
                        {
                            Global.LogServer.Add(new LogInfo("ParamSet-Error", "FormMain->treeMain_DoubleClick", (int)EnumLogLevel.ERROR));
                        }

                        if (Global.nVideoRecogType == 1)
                        {
                            InitHKGroupBoard();
                        }
                    }
                    else
                    {
                        for (int i = 0; i < nvr.config.dwDChanNum; i++)
                        {
                            if (node.Text == "Video" + i.ToString())
                            {
                                NET_DVR_PREVIEWINFO previewInfo = new NET_DVR_PREVIEWINFO();
                                previewInfo.hPlayWnd        = videoBox.Handle; //预览窗口
                                previewInfo.lChannel        = nvr.config.dwStartDChan + i;
                                previewInfo.dwStreamType    = 0;               //码流类型:0-主码流,1-子码流,2-码流3,3-码流4,以此类推
                                previewInfo.dwLinkMode      = 0;               //连接方式:0- TCP方式,1- UDP方式,2- 多播方式,3- RTP方式,4-RTP/RTSP,5-RSTP/HTTP
                                previewInfo.bBlocked        = false;           //0- 非阻塞取流,1- 阻塞取流
                                previewInfo.dwDisplayBufNum = 15;
                                int lenth = Marshal.SizeOf(previewInfo);
                                if (lPlayHandle >= 0)
                                {
                                    SPlate.SP_StopPreview(lPlayHandle);
                                    lPlayHandle = -1;
                                }

                                lPlayHandle = SPlate.SP_PreviewInfo(ref previewInfo, lenth);

                                //更新当前被选中的视频线路
                                Global.bVideoInShow          = true;
                                Global.nCurSelectedVideoChan = i;
                                lblCurVideoNo.Text           = "当前视频:Video" + i.ToString();
                                break;
                            }
                        }

                        SwitchVideo();
                    }
                }
            }
            catch (System.Exception ex)
            {
                Global.LogServer.Add(new LogInfo("ParamSet-Error", "FormMain->treeMain_DoubleClick:" + ex.Message, (int)EnumLogLevel.ERROR));
            }
        }