Пример #1
0
 /// <summary>
 /// 摄像头预览方法
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void kButtonView_Click(object sender, EventArgs e)
 {
     if (StaticData.g_CameraSelectChannel > 0)
     {
         Hikvision previewFun = HikvisionPreviewFun.GetInstance();
         //根据选中的摄像头通道号跟IP地址进行预览
         string    srtSql = "IP地址= '" + StaticData.g_CameraSelectNVRIP + "'";
         DataRow[] dr     = StaticData.g_dtNVR.Select(srtSql);
         if (dr.Length > 0)
         {
             previewFun.PreviewFun(Convert.ToInt32(dr[0]["userid"]), StaticData.g_CameraSelectChannel);
         }
     }
     else
     {
         MessageBox.Show("请点击摄像头名称选择要预览的摄像头画面");
     }
 }
Пример #2
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;
            }
        }