コード例 #1
0
ファイル: frm_Main.cs プロジェクト: doksec/bykom_dahuaDotNet
        /// <summary>
        /// 获取用户信息
        /// </summary>
        /// <param name="loginId">登录ID</param>
        /// <param name="usrInfo">用户信息</param>
        /// <param name="waitTime">超时限制</param>
        private void GetUserInfo(int loginId,ref USER_MANAGE_INFO usrInfo,int waitTime)
        {
             bool blnGetUserInfo = false;
             ActiveUserID = 0;
             ActiveGroupID = 0;
             ActiveGroupIndex = 0;
             ActiveUserIndex = 0;
            //读取用户信息
            blnGetUserInfo = DHClient.DHQueryUserInfo(loginId, ref  usrInfo, waitTime);
            if (blnGetUserInfo == true)
            {
                trvUserManageList.Nodes.Clear();
                chkRightList.Items.Clear();
                //用户组添加
                foreach (USER_GROUP_INFO gp in userManageInfo.groupList)
                {
                    if (gp.dwID != 0)
                    {
                        trvUserManageList.Nodes.Add(gp.dwID.ToString(), DHClient.DHByteArrayToString(gp.name));
                    }

                }
                //将用户添加到用户组的Node中
                userIDListArray = new uint[200];//最大200用户
                uint userIndex = 0;
                foreach (USER_INFO user in userManageInfo.userList)
                {
                    if (user.dwGroupID != 0 && user.dwID != 0)
                    {
                        userIDListArray[userIndex] = user.dwID;
                        trvUserManageList.Nodes[user.dwGroupID.ToString()].Nodes.Add(userIndex.ToString(), DHClient.DHByteArrayToString(user.name));
                        userIndex += 1;
                    }
                }
                //权限列表[没有选择组或用户时,显示所有可用的权限]
                chkRightList.Items.Clear();//清空所有权限列表
                rightListArray = new LISTITEM[userManageInfo.dwRightNum];
                for (uint i = 0; i < userManageInfo.dwRightNum; i++)
                {
                    rightListArray[i].index = i;//保存权限列表项的索引
                    rightListArray[i].keyID = userManageInfo.rightList[i].dwID;//保存权限列表项的Key值
                    chkRightList.Items.Add(DHClient.DHByteArrayToString(userManageInfo.rightList[i].name), CheckState.Checked);
                }
            }
            else
            {
                MessageBox.Show("获取用户信息失败!", pMsgTitle);
            }
        }
コード例 #2
0
ファイル: frm_Main.cs プロジェクト: dalinhuang/demodemo
        /// <summary>
        /// 设备用户登录/注销处理
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnUserLogin_Click(object sender, EventArgs e)
        {
            switch (btnUserLogin.Text)
            {
                case "设备用户登录":
                    frm_AddDevice fLogin = new frm_AddDevice();
                    fLogin.ShowDialog();
                    if (fLogin.blnOKEnter == true)
                    {
                        //设备用户信息获得
                        NET_DEVICEINFO deviceInfo = new NET_DEVICEINFO();

                        int error = 0;
                        //设备用户登录
                        pLoginID = DHClient.DHLogin(fLogin.cmbDevIP.Text.ToString(), ushort.Parse(fLogin.txtDevProt.Text.ToString()), fLogin.txtName.Text.ToString(), fLogin.txtPassword.Text.ToString(), out deviceInfo, out error);
                        if (pLoginID != 0)
                        {
                            btnUserLogin.BackColor = Color.Yellow;
                            btnUserLogin.Text = "设备用户注销";
                            grpMain.Enabled = true;
                            //读取用户信息
                            GetUserInfo(pLoginID, ref userManageInfo, 3000);
                            //设置消息回调函数
                            DHClient.DHSetDVRMessCallBack(msgCallBack, IntPtr.Zero);
                            //开始侦听
                            if (DHClient.DHStartListen(pLoginID) == true)
                            {
                                timeDisplayAlarmInfo.Enabled = true;
                            }
                            else
                            {
                                timeDisplayAlarmInfo.Enabled = false;
                            }
                        }
                    }
                    break;
                case "设备用户注销":
                    bool result = DHClient.DHLogout(pLoginID);
                    if (result == false)
                    {
                        //报最后一次操作的错误信息
                        MessageBox.Show(DHClient.LastOperationInfo.ToString(pErrInfoFormatStyle), pMsgTitle);
                    }

                    //画面初期化
                    timeDisplayAlarmInfo.Enabled = false;
                    this.Controls.Clear();
                    InitializeComponent();
                    pLoginID = 0;
                    userManageInfo = new USER_MANAGE_INFO();
                    clientState = new NET_CLIENT_STATE();
                    AlarmAudio = new byte[16];
                    AlarmDiskErr = new byte[32];//DVR最大可挂32块硬盘,每一位表示一个硬盘的状态,0:硬盘状态正常;1:硬盘出错
                    AlarmDiskFull = false;
                    AlarmShelter = new byte[16];
                    ActiveUserID = 0;
                    ActiveGroupID = 0;
                    ActiveGroupIndex = 0;
                    ActiveUserIndex = 0;
                    btnUserLogin.BackColor = Color.Transparent;
                    btnUserLogin.Text = "设备用户登录";
                    grpMain.Enabled = false;
                    this.WindowState = FormWindowState.Normal;
                    break;
            }
        }
コード例 #3
0
ファイル: frm_Main.cs プロジェクト: doksec/bykom_dahuaDotNet
        /// <summary>
        /// 设备用户登录/注销处理
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnUserLogin_Click(object sender, EventArgs e)
        {
            string strLogin  = StringUtil.ConvertString("设备用户登录");
            string strLogout = StringUtil.ConvertString("设备用户注销");

            if (btnUserLogin.Text.Equals(strLogin))
            {
                frm_AddDevice fLogin = new frm_AddDevice();
                fLogin.ShowDialog();
                if (fLogin.blnOKEnter == true)
                {
                    //设备用户信息获得
                    NET_DEVICEINFO deviceInfo = new NET_DEVICEINFO();

                    int error = 0;
                    //设备用户登录
                    pLoginID = DHClient.DHLogin(fLogin.cmbDevIP.Text.ToString(), ushort.Parse(fLogin.txtDevProt.Text.ToString()), fLogin.txtName.Text.ToString(), fLogin.txtPassword.Text.ToString(), out deviceInfo, out error);
                    if (pLoginID != 0)
                    {
                        btnUserLogin.BackColor = Color.Yellow;
                        btnUserLogin.Text = strLogout;
                        grpMain.Enabled = true;
                        //读取用户信息
                        GetUserInfo(pLoginID, ref userManageInfo, 3000);
                        //设置消息回调函数
                        DHClient.DHSetDVRMessCallBack(msgCallBack, IntPtr.Zero);
                        IntPtr pVer = new IntPtr();
                        pVer = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(int)));
                        int nRet = 0;
                        int nVer = 0;
                        bool bRet = DHClient.DHQueryDevState((int)pLoginID, (int)DHClient.DH_DEVSTATE_PROTOCAL_VER, pVer, 4, ref nRet, 2000);
                        if (bRet)
                        {
                             nVer = (int)Marshal.PtrToStructure((IntPtr)((UInt32)pVer), typeof(int));

                             //开始侦听
                             if (nVer >= 5)
                             {
                                 if (DHClient.DHStartListenEx(pLoginID) == true)
                                 {
                                     timeDisplayAlarmInfo.Enabled = true;
                                 }
                                 else
                                 {
                                     timeDisplayAlarmInfo.Enabled = false;
                                 }
                             }
                             else
                             {
                                 if (DHClient.DHStartListen(pLoginID) == true)
                                 {
                                     timeDisplayAlarmInfo.Enabled = true;
                                 }
                                 else
                                 {
                                     timeDisplayAlarmInfo.Enabled = false;
                                 }
                             }
                        }
                        
                    }
                }
            }
            else
            {
                bool result = DHClient.DHLogout(pLoginID);
                if (result == false)
                {
                    //报最后一次操作的错误信息
                    MessageBox.Show(DHClient.LastOperationInfo.ToString(pErrInfoFormatStyle), pMsgTitle);
                }


                //画面初期化
                timeDisplayAlarmInfo.Enabled = false;
                this.Controls.Clear();
                InitializeComponent();
                StringUtil.InitControlText(this);
                pLoginID = 0;
                userManageInfo = new USER_MANAGE_INFO();
                clientState = new NET_CLIENT_STATE();
                AlarmAudio = new byte[16];
                AlarmDiskErr = new byte[32];//DVR最大可挂32块硬盘,每一位表示一个硬盘的状态,0:硬盘状态正常;1:硬盘出错
                AlarmDiskFull = false;
                AlarmShelter = new byte[16];
                AlarmExternal = new byte[16];
                ActiveUserID = 0;
                ActiveGroupID = 0;
                ActiveGroupIndex = 0;
                ActiveUserIndex = 0;
                btnUserLogin.BackColor = Color.Transparent;
                btnUserLogin.Text = strLogin;
                grpMain.Enabled = false;
                this.WindowState = FormWindowState.Normal;
            }

        }
コード例 #4
0
 /// <summary>
 /// 查询用户信息
 /// </summary>
 /// <param name="iLogin">DHLogin的返回值</param>
 /// <param name="userInfo">USER_MANAGE_INFO结构</param>
 /// <param name="waitTime">等待时间</param>
 /// <returns>true:成功;false:失败</returns>
 public static bool DHQueryUserInfo(int iLogin,ref USER_MANAGE_INFO userInfo,int waitTime)
 {
     bool retValue = false;
     IntPtr pBoxInfo = IntPtr.Zero;
     try
     {
         pBoxInfo = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(USER_MANAGE_INFO)));//分配固定的指定大小的内存空间
         if (pBoxInfo != IntPtr.Zero)
         {
             retValue = CLIENT_QueryUserInfo(iLogin, pBoxInfo, waitTime);
             if (retValue == true)
             {
                 userInfo = (USER_MANAGE_INFO)Marshal.PtrToStructure((IntPtr)((UInt32)pBoxInfo), typeof(USER_MANAGE_INFO));
             }
         }
         DHThrowLastError(retValue);                
     }
     catch (Exception e)
     {
         DHThrowLastError(e);
         retValue = false;
     }
     finally
     {
         Marshal.FreeHGlobal(pBoxInfo);//释放固定内存分配
         pBoxInfo = IntPtr.Zero;
     } 
     return retValue;
                    
 }