// 抓图点击时 开始抓图
        private void cmsZT_Click(object sender, EventArgs e)
        {
            PictureBox pic   = (PictureBox)(cms.SourceControl);
            int        index = int.Parse(pic.Name);

            if (m_lRealHandle[index] >= 0)  // 抓图
            {
                string path = ClassXml.getSetXml("capture");
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }
                //图片名称 年月日 时分秒
                string sBmpPicFileName = System.DateTime.Now.ToString("yyMMddhhmmss");
                sBmpPicFileName = path + "\\" + sBmpPicFileName + ".bmp";
                //BMP抓图 Capture a BMP picture
                if (!CHCNetSDK.NET_DVR_CapturePicture(m_lRealHandle[index], sBmpPicFileName))
                {
                    iLastErr = CHCNetSDK.NET_DVR_GetLastError();
                    toolStripStatusLabel6.Text = "抓图失败,错误代码" + iLastErr.ToString();
                }
                else
                {
                    toolStripStatusLabel6.Text = "抓图成功,保存文件名为" + sBmpPicFileName;
                }
            }
        }
 private void initSet()
 {
     if (panelSet.Visible)
     {
         string[] s = ClassXml.getSetInfo(); // 获得设置信息
         textBox1.Text = s[0];
         textBox2.Text = s[1];
         if (s[2] == "否")
         {
             radioButton2.Checked = true;
             soundonoff           = false;
         }
         else
         {
             radioButton1.Checked = true;
             soundonoff           = true;
         }
         if (s[3] == "否")
         {
             radioButton3.Checked = true;
             radioButton2.Enabled = false;
             radioButton1.Enabled = false;
             motiondetectonoff    = false;
         }
         else
         {
             radioButton4.Checked = true;
             radioButton2.Enabled = true;
             radioButton1.Enabled = true;
             motiondetectonoff    = true;
         }
     }
 }
Example #3
0
 public string devicename, ip;  //设备名
 private void FormDeviceAdd_Load(object sender, EventArgs e)
 {
     if (devicename == "")  //添加设备
     {
         this.Text = "添加设备";
     }
     else
     {
              //修改设备
         this.Text = "修改设备";
         string [] s = ClassXml.getDeviceXml(devicename);
         if (s == null)
         {
             MessageBox.Show("故障!请重新操作!");
             this.Close();
         }
         else
         {
             textBoxName.Text = s[0];
             textBoxIP.Text   = s[1];
             ip = s[1];
             textBoxPort.Text     = s[2];
             textBoxUserName.Text = s[3];
             textBoxPassword.Text = s[4];
             textBoxName.ReadOnly = true;
         }
     }
 }
        private FormRecord[] recordFrm = new FormRecord[9];  //9 个录像界面
        // 录像点击时 开始录像
        private void cmsLX_Click(object sender, EventArgs e)
        {
            PictureBox pic   = (PictureBox)(cms.SourceControl);
            int        index = int.Parse(pic.Name);

            if (index == 0)
            {
                threadRunning = false;      // 线程空运行  只对第一个通道做处理
            }
            if (m_lRealHandle[index] >= 0)  // 如果在预览
            {
                string path = ClassXml.getSetXml("record");
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }
                //图片名称 年月日 时分秒
                string FileName = System.DateTime.Now.ToString("yyMMddhhmmss");
                FileName = path + "\\" + FileName + ".mp4";

                //mp4录像
                if (m_bRecord[index] == false)    //开始录像
                {
                    //强制I帧 Make one key frame
                    int lChannel = iChannelNum[index]; //通道号 Channel number
                    CHCNetSDK.NET_DVR_MakeKeyFrame(m_lUserID, lChannel);

                    //开始录像 Start recording
                    if (!CHCNetSDK.NET_DVR_SaveRealData(m_lRealHandle[index], FileName))
                    {
                        iLastErr = CHCNetSDK.NET_DVR_GetLastError();
                        toolStripStatusLabel6.Text = "录像失败,错误代码" + iLastErr.ToString();
                        return;
                    }
                    else
                    {
                        toolStripStatusLabel6.Text = "开始录像,保存文件名为" + FileName;
                        m_bRecord[index]           = true;
                        recordFrm[index]           = new FormRecord();
                        recordFrm[index].index     = index;
                        recordFrm[index].Owner     = this;
                        recordFrm[index].path      = FileName;
                        recordFrm[index].Show();  // 显示录像界面
                    }
                }
                else  //打开录像界面
                {
                    if (recordFrm[index] != null)
                    {
                        recordFrm[index].WindowState = FormWindowState.Normal;
                    }
                    //停止录像 Stop recording

                    /*CHCNetSDK.NET_DVR_StopSaveRealData(m_lRealHandle[index]);
                     * m_bRecord[index] = false;   */
                }
            }
        }
Example #5
0
 //确定添加设备
 private void button1_Click(object sender, EventArgs e)
 {
     if (textBoxName.Text.Trim() == "")
     {
         MessageBox.Show("别名不能为空");
         return;
     }
     if (textBoxIP.Text.Trim() == "")
     {
         MessageBox.Show("IP不能为空");
         return;
     }
     if (textBoxPort.Text.Trim() == "")
     {
         MessageBox.Show("端口号不能为空");
         return;
     }
     if (textBoxUserName.Text.Trim() == "")
     {
         MessageBox.Show("用户名不能为空");
         return;
     }
     if (textBoxPassword.Text.Trim() == "")
     {
         MessageBox.Show("密码不能为空");
         return;
     }
     if (devicename == "") //添加
     {
         if (ClassXml.findNameXml(textBoxName.Text.Trim()))
         {
             MessageBox.Show("此别名已经存在,请输入新别名!");
             return;
         }
         if (ClassXml.findIpXml(textBoxIP.Text.Trim()))
         {
             MessageBox.Show("此设备IP已经存在,请输入新IP!");
             return;
         }
         ClassXml.AddXml(textBoxName.Text.Trim(), textBoxIP.Text.Trim(), textBoxPort.Text.Trim(), textBoxUserName.Text.Trim(), textBoxPassword.Text.Trim());
         MessageBox.Show("添加成功!");
         this.Close();
     }
     else // 修改
     {
         if (ip != textBoxIP.Text.Trim() && ClassXml.findIpXml(textBoxIP.Text.Trim()))
         {
             MessageBox.Show("此设备IP已经存在,请输入新IP!");
             return;
         }
         ClassXml.deleteXml(textBoxName.Text.Trim());
         ClassXml.AddXml(textBoxName.Text.Trim(), textBoxIP.Text.Trim(), textBoxPort.Text.Trim(), textBoxUserName.Text.Trim(), textBoxPassword.Text.Trim());
         MessageBox.Show("修改成功!");
         this.Close();
     }
 }
 // 是否移动监测
 private void radioButton4_Click(object sender, EventArgs e)
 {
     if (radioButton4.Checked)
     {
         ClassXml.saveSetXml("motiondetect", "是");
     }
     else
     {
         ClassXml.saveSetXml("motiondetect", "否");
     }
     initSet();
 }
 // 是否警报
 private void radioButton1_Click(object sender, EventArgs e)
 {
     if (radioButton1.Checked)
     {
         ClassXml.saveSetXml("sound", "是");
     }
     else
     {
         ClassXml.saveSetXml("sound", "否");
     }
     initSet();
 }
        // 开始录像
        private void startRecord()
        {
            threadRunning = false; // 线程空运行
            if (soundonoff)        // 如果发出警报
            {
                Beep(600, 1000);   // 发出警告声音
            }
            // 开始录像
            if (m_lRealHandle[0] >= 0)  // 如果在预览
            {
                string path = ClassXml.getSetXml("record");
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }
                //图片名称 年月日 时分秒
                string FileName = System.DateTime.Now.ToString("yyMMddhhmmss");
                FileName = path + "\\" + FileName + ".mp4";

                //mp4录像
                if (m_bRecord[0] == false)    //开始录像
                {
                    //强制I帧 Make one key frame
                    int lChannel = iChannelNum[0]; //通道号 Channel number
                    CHCNetSDK.NET_DVR_MakeKeyFrame(m_lUserID, lChannel);

                    //开始录像 Start recording
                    if (!CHCNetSDK.NET_DVR_SaveRealData(m_lRealHandle[0], FileName))
                    {
                        iLastErr = CHCNetSDK.NET_DVR_GetLastError();
                        toolStripStatusLabel6.Text = "录像失败,错误代码" + iLastErr.ToString();
                        return;
                    }
                    else
                    {
                        toolStripStatusLabel6.Text = "开始录像,保存文件名为" + FileName;
                        m_bRecord[0]       = true;
                        recordFrm[0]       = new FormRecord();
                        recordFrm[0].index = 0;
                        recordFrm[0].Owner = this;
                        recordFrm[0].path  = FileName;
                        recordFrm[0].Show();  // 显示录像界面
                    }
                }
                else  //打开录像界面
                {
                    if (recordFrm[0] != null)
                    {
                        recordFrm[0].WindowState = FormWindowState.Normal;
                    }
                }
            }
        }
        // 录像路径保存
        private void button4_Click(object sender, EventArgs e)
        {
            string path = "";
            FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog();

            folderBrowserDialog.Description         = "请选择录像保存路径";
            folderBrowserDialog.ShowNewFolderButton = false;
            if (folderBrowserDialog.ShowDialog() == DialogResult.OK)
            {
                path = folderBrowserDialog.SelectedPath;
                //MessageBox.Show(path);
            }
            ClassXml.saveSetXml("record", path);
            initSet();
        }
 // 删除设备
 private void button1_Click(object sender, EventArgs e)
 {
     if (listView1.SelectedItems.Count > 0)
     {
         string devicename = listView1.SelectedItems[0].Text;
         if (MessageBox.Show("是否确定删除设备" + devicename + "?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
         {
             return;
         }
         ClassXml.deleteXml(devicename);
         devicelistREfresh();  // 刷新
     }
     else
     {
         MessageBox.Show("请选择设备!");
     }
 }
        //选择设备时 打开所有可用通道进行预览  其实这里限制 只预览9个通道
        private void treeView2_AfterSelect(object sender, TreeViewEventArgs e)
        {
            if (treeView2.SelectedNode == null)
            {
                return;
            }
            toolStripStatusLabel4.Text = "监控:" + treeView2.SelectedNode.Text;
            string name = treeView2.SelectedNode.Text.Substring(treeView2.SelectedNode.Text.IndexOf('_') + 1);

            string[] s = ClassXml.getDeviceXml(name); // 获得监控设备的配置信息
            closeDevice();                            //关闭设备
            string DVRIPAddress  = s[1];              //设备IP地址或者域名 Device IP
            Int16  DVRPortNumber = Int16.Parse(s[2]); //设备服务端口号 Device Port
            string DVRUserName   = s[3];              //设备登录用户名 User name to login
            string DVRPassword   = s[4];              //设备登录密码 Password to login

            m_lUserID = CHCNetSDK.NET_DVR_Login_V30(DVRIPAddress, DVRPortNumber, DVRUserName, DVRPassword, ref DeviceInfo);
            if (m_lUserID < 0)
            {
                iLastErr = CHCNetSDK.NET_DVR_GetLastError();
                toolStripStatusLabel6.Text = "登录连接失败,错误代码" + iLastErr.ToString();
            }
            else
            {
                //登录成功
                toolStripStatusLabel6.Text = "登录连接成功";
                dwAChanTotalNum            = (uint)DeviceInfo.byChanNum;                                           // 模拟通道
                dwDChanTotalNum            = (uint)DeviceInfo.byIPChanNum + 256 * (uint)DeviceInfo.byHighDChanNum; // 数字通道
                // 初始化通道
                for (int i = 0; i < 64; i++)
                {
                    iChannelNum[i] = -1;
                }
                if (dwDChanTotalNum > 0)  //数字通道不作处理 没设备呀
                {
                    //InfoIPChannel();
                }
                else
                {
                    for (int i = 0; i < dwAChanTotalNum; i++)
                    {
                        iChannelNum[i] = i + (int)DeviceInfo.byStartChan;
                    }
                    //下面开始预览
                    {
                        for (int i = 0; i < 9; ++i)  // 只能9个
                        {
                            if (box[i].Visible && iChannelNum[i] != -1)
                            {
                                CHCNetSDK.NET_DVR_PREVIEWINFO lpPreviewInfo = new CHCNetSDK.NET_DVR_PREVIEWINFO();
                                lpPreviewInfo.hPlayWnd        = box[i].Handle;  //预览窗口 live view window
                                lpPreviewInfo.lChannel        = iChannelNum[i]; //预览的设备通道 the device channel number
                                lpPreviewInfo.dwStreamType    = 0;              //码流类型:0-主码流,1-子码流,2-码流3,3-码流4,以此类推
                                lpPreviewInfo.dwLinkMode      = 0;              //连接方式:0- TCP方式,1- UDP方式,2- 多播方式,3- RTP方式,4-RTP/RTSP,5-RSTP/HTTP
                                lpPreviewInfo.bBlocked        = true;           //0- 非阻塞取流,1- 阻塞取流
                                lpPreviewInfo.dwDisplayBufNum = 15;             //播放库显示缓冲区最大帧数
                                IntPtr pUser = IntPtr.Zero;                     //用户数据 user data
                                m_lRealHandle[i] = CHCNetSDK.NET_DVR_RealPlay_V40(m_lUserID, ref lpPreviewInfo, null /*RealData*/, pUser);
                                if (m_lRealHandle[i] < 0)
                                {
                                    iLastErr = CHCNetSDK.NET_DVR_GetLastError();
                                    toolStripStatusLabel6.Text = "预览失败,错误代码" + iLastErr.ToString();
                                    return;
                                }
                                else
                                {
                                    //预览成功
                                    toolStripStatusLabel6.Text = "正在预览...";
                                }
                            }
                        }
                    }
                }
            }
        }
 //刷新设备列表
 private void devicelistREfresh()
 {
     closeDevice();
     if (panelDeviceMana.Visible)  // 设备管理
     {
         listView1.Items.Clear();
         string          DVRIPAddress;  //设备IP地址或者域名 Device IP
         Int16           DVRPortNumber; //设备服务端口号 Device Port
         string          DVRUserName;   //设备登录用户名 User name to login
         string          DVRPassword;   //设备登录密码 Password to login
         Int32           m_lUserID;
         string          status = "", xuliehao = "";
         string[]        s;
         List <string[]> list = ClassXml.readXml();
         for (int i = 0; i < list.Count; ++i)
         {
             s = list[i];
             if (s.Length > 0)
             {
                 DVRIPAddress  = s[1];              //设备IP地址或者域名 Device IP
                 DVRPortNumber = Int16.Parse(s[2]); //设备服务端口号 Device Port
                 DVRUserName   = s[3];              //设备登录用户名 User name to login
                 DVRPassword   = s[4];              //设备登录密码 Password to login
                 //登录设备 Login the device
                 m_lUserID = CHCNetSDK.NET_DVR_Login_V30(DVRIPAddress, DVRPortNumber, DVRUserName, DVRPassword, ref DeviceInfo);
                 if (m_lUserID < 0)
                 {
                     status   = "连接无效";
                     xuliehao = "";
                 }
                 else
                 {
                     status   = "连接有效";
                     xuliehao = System.Text.Encoding.Default.GetString(DeviceInfo.sSerialNumber);
                     CHCNetSDK.NET_DVR_Logout(m_lUserID);  // 关闭连接
                 }
                 ListViewItem lvi = new ListViewItem(s[0]);
                 lvi.SubItems.Add(s[1]);
                 lvi.SubItems.Add(xuliehao);
                 lvi.SubItems.Add(status);
                 listView1.Items.Add(lvi);
             }
         }
     }
     else if (panelLiveView.Visible)
     {
         motiondetectonoff = false; soundonoff = false;
         if (ClassXml.getSetXml("motiondetect") == "是")
         {
             motiondetectonoff = true;
         }
         if (ClassXml.getSetXml("sound") == "是")
         {
             soundonoff = true;
         }
         treeView2.Nodes.Clear();
         string[]        s;
         List <string[]> list = ClassXml.readXml();
         for (int i = 0; i < list.Count; ++i)
         {
             s = list[i];
             if (s.Length > 0)
             {
                 treeView2.Nodes.Add("监控点" + (i + 1).ToString() + "_" + s[0]);
             }
         }
         if (treeView2.Nodes.Count > 0) // 启动第一个设备
         {
             treeView2.SelectedNode = treeView2.Nodes[0];
         }
     }
 }