/// <summary> /// 显示组信息 /// </summary> /// <param name="groupInfo">组信息</param> /// <param name="blnShowRights">是否显示权限信息</param> private void ShowGroupInfo(USER_GROUP_INFO groupInfo, bool blnShowRights) { ActiveGroupID = groupInfo.dwID; txtGroupdemo.Text = DHClient.DHByteArrayToString(groupInfo.memo); txtGroupdemo.ReadOnly = true; txtGroupName.ReadOnly = true; txtGroupName.Text = DHClient.DHByteArrayToString(groupInfo.name); if (blnShowRights == true) { ShowRights(groupInfo.rights, groupInfo.dwRightNum); } }
/// <summary> /// 修改用户组 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnEditGroup_Click(object sender, EventArgs e) { if (ActiveGroupID == 0) { MessageBox.Show("请选择用户组!", pMsgTitle); return; } switch (btnEditGroup.Text) { case "修改组": txtGroupName.ReadOnly = false; txtGroupdemo.ReadOnly = false; btnEditGroup.Text = "保存组"; btnEditGroup.BackColor = Color.Yellow; break; case "保存组": bool blnAddGroup = false; USER_GROUP_INFO groupInfo = new USER_GROUP_INFO("无用参数"); groupInfo.dwID = userManageInfo.groupList[ActiveGroupIndex].dwID; DHClient.DHStringToByteArry(txtGroupName.Text, ref groupInfo.name); DHClient.DHStringToByteArry(txtGroupdemo.Text, ref groupInfo.memo); uint rightsNum = 0; for (int i = 0; i < chkRightList.Items.Count; i++) { if (chkRightList.GetItemChecked(i) == true) { groupInfo.rights[rightsNum] = rightListArray[i].keyID; rightsNum += 1; } } groupInfo.dwRightNum = rightsNum; blnAddGroup = DHClient.DHOperateUserInfo(pLoginID, USER_OPERATE.DH_GROUP_EDIT, groupInfo, userManageInfo.groupList[ActiveGroupIndex], 3000); if (blnAddGroup == false) { MessageBox.Show("修改组失败!\n" + DHClient.LastOperationInfo.ToString(pErrInfoFormatStyle), pMsgTitle); } btnEditGroup.Text = "修改组"; btnEditGroup.BackColor = Color.Transparent; ActiveUserID = 0; GetUserInfo(pLoginID, ref userManageInfo, 3000); break; } }
/// <summary> /// 修改用户组 /// </summary> /// <param name="iLogin"></param> /// <param name="grpInfo"></param> /// <param name="waitTime"></param> /// <returns></returns> public static bool DHOperateUserInfo(int iLogin, USER_OPERATE operate, USER_GROUP_INFO grpNewInfo, USER_GROUP_INFO grpOldInfo, int waitTime) { bool retValue = false; IntPtr pBoxInfo = IntPtr.Zero; IntPtr pBoxInfo1 = IntPtr.Zero; try { pBoxInfo = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(USER_GROUP_INFO)));//分配固定的指定大小的内存空间 pBoxInfo1 = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(USER_GROUP_INFO)));//分配固定的指定大小的内存空间 if (pBoxInfo != IntPtr.Zero && pBoxInfo1!=IntPtr.Zero) { Marshal.StructureToPtr(grpNewInfo, pBoxInfo, true); Marshal.StructureToPtr(grpOldInfo, pBoxInfo1, true); retValue = CLIENT_OperateUserInfo(iLogin, (int)operate, pBoxInfo, pBoxInfo1, waitTime); } DHThrowLastError(retValue); } catch (Exception e) { DHThrowLastError(e); retValue= false; } finally { Marshal.FreeHGlobal(pBoxInfo);//释放固定内存分配 pBoxInfo = IntPtr.Zero; Marshal.FreeHGlobal(pBoxInfo1);//释放固定内存分配 pBoxInfo = IntPtr.Zero; } return retValue; }