⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 powsetdialog.cpp

📁 VC+SQL SERVER 2000环境下开发的商品销售管理系统
💻 CPP
📖 第 1 页 / 共 4 页
字号:

					m_pRecordsetPM.CreateInstance (__uuidof(Recordset));
					strSQL.Format ("select * from PowerManagerTable where PowerName = '%s'", PowerNamePN);
                    m_pRecordsetPM->Open (_bstr_t(strSQL),
									    m_pConnection.GetInterfacePtr(),
							            adOpenDynamic,
							            adLockOptimistic,
							            adCmdText);
					CString AllManagerNum;

					var = m_pRecordsetPM->GetCollect ("ManagerPowNum");
					AllManagerNum = (LPCSTR)_bstr_t(var);

					AllManagerNum += PowerNum[0];

					m_pRecordsetPM->PutCollect ("ManagerPowNum", _variant_t(AllManagerNum));
					m_pRecordsetPM->Update();
					m_pRecordsetPM->Close();
					m_pRecordsetPN->Close();
					m_pRecordsetPN = NULL;
					m_pRecordsetPM = NULL;

					m_ManagerPowNameList.InsertString(-1, PowerNamePNY);

				}//if
			}//if
		}//try
		catch(_com_error e)
		{
			AfxMessageBox(e.ErrorMessage());
			return;
		}
	}//if
}

void CPowSetDialog::OnBnClickedUserRecede()
{
	int selPN = m_PowerNameList.GetCurSel();
	if(selPN == LB_ERR)
	{
		AfxMessageBox (_T("没有选择用户权限!"));
		return;
	}
	if( m_ManagerPowNameList.GetCount() == 0)
	{
		AfxMessageBox (_T("该用户没有任何其他管理权限!"));
		return;
	}
	int selPNY = m_ManagerPowNameList.GetCurSel();
	if(selPNY == LB_ERR)
	{
		AfxMessageBox (_T("没有选择已管理用户权限!"));
		return;
	}
	
	CString PowerNamePN, PowerNamePNY;
    m_PowerNameList.GetText (selPN, PowerNamePN);
	m_ManagerPowNameList.GetText (selPNY, PowerNamePNY);
    CString str;
	str.Format ("真是要收回%s%s的管理权限吗?", PowerNamePN, PowerNamePNY);
	if(AfxMessageBox (str, MB_OKCANCEL) == IDOK)
	{
		HRESULT         hrPN;
		_RecordsetPtr   m_pRecordsetPN;

		try{
			m_ManagerPowNameList.DeleteString(selPNY);

			hrPN = m_pRecordsetPN.CreateInstance (__uuidof(Recordset));

			if(FAILED(hrPN))
			{
				AfxMessageBox (_T("创建实例失败!"));
				return;
			}

			CString strSQL;
			strSQL.Format ("select * from PowerNameTable where PowerName = '%s'", PowerNamePNY);
			hrPN = m_pRecordsetPN->Open (_bstr_t(strSQL),
									    m_pConnection.GetInterfacePtr(),
							            adOpenDynamic,
							            adLockOptimistic,
							            adCmdText);
			if(SUCCEEDED(hrPN))
			{
				if(!m_pRecordsetPN->adoEOF)
				{
					CString     PowerNum;
					_variant_t  var;

					var = m_pRecordsetPN->GetCollect ("PowerNum");
					PowerNum = (LPCSTR)_bstr_t(var);

					_RecordsetPtr  m_pRecordsetPM;

					m_pRecordsetPM.CreateInstance (__uuidof(Recordset));
					strSQL.Format ("select * from PowerManagerTable where PowerName = '%s'", PowerNamePN);
                    m_pRecordsetPM->Open(_bstr_t(strSQL),
									    m_pConnection.GetInterfacePtr(),
							            adOpenDynamic,
							            adLockOptimistic,
							            adCmdText);
					CString AllManagerNum;

					var = m_pRecordsetPM->GetCollect ("ManagerPowNum");
					AllManagerNum = (LPCSTR)_bstr_t(var);

					int Count = AllManagerNum.GetLength();
					CString tempAllManagerNum = "";
					for(int index = 0 ; index < Count; index++)
					{
						if(AllManagerNum[index] != PowerNum[0])
							tempAllManagerNum += AllManagerNum[index];
					}

					m_pRecordsetPM->PutCollect ("ManagerPowNum", _variant_t(tempAllManagerNum));
					m_pRecordsetPM->Update();
					m_pRecordsetPM->Close();
					m_pRecordsetPN->Close();
					m_pRecordsetPN = NULL;
					m_pRecordsetPM = NULL;

					m_ManagerPowNotYetList.InsertString(-1, PowerNamePNY);

				}//if
			}//if
		}//try
		catch(_com_error e)
		{
			AfxMessageBox(e.ErrorMessage());
			return;
		}
	}//if
}

void CPowSetDialog::OnBnClickedUserAllgive()
{
	int sel = m_PowerNameList.GetCurSel();
	if(sel == LB_ERR)
	{
		AfxMessageBox (_T("没有选择用户权限!"));
		return;
	}
	if(m_ManagerPowNotYetList.GetCount() == 0)
	{
		AfxMessageBox (_T("已经赋予该用户所有的管理权限!"));
		return;
	}
	CString PowerName;
	CString strValue;
	m_PowerNameList.GetText (sel, PowerName);
	strValue.Format ("真是要赋予%s所有的管理权限吗?", PowerName);

	if(AfxMessageBox (strValue, MB_OKCANCEL) == IDOK)
	{
		int Count = m_ManagerPowNotYetList.GetCount();

		_RecordsetPtr    m_pRecordsetPN;
		_RecordsetPtr    m_pRecordsetPM;
		HRESULT          hrPN;
		HRESULT          hrPM;
	
		try
		{
			hrPN = m_pRecordsetPN.CreateInstance(__uuidof(Recordset));
			hrPM = m_pRecordsetPM.CreateInstance(__uuidof(Recordset));

			if(FAILED(hrPN) || FAILED(hrPM))
			{
				AfxMessageBox(_T("创建实例失败!"));
				return;
			}
			hrPN = m_pRecordsetPN->Open ("select * from PowerNameTable",
										m_pConnection.GetInterfacePtr(),
										adOpenDynamic,
										adLockOptimistic,
										adCmdText);
										
			CString strSQL;
			strSQL.Format("select * from PowerManagerTable where PowerName = '%s'", PowerName);

			hrPM = m_pRecordsetPM->Open (_bstr_t(strSQL),
										m_pConnection.GetInterfacePtr(),
										adOpenDynamic,
										adLockOptimistic,
										adCmdText);

			if(SUCCEEDED(hrPM) && SUCCEEDED(hrPN))
			{
				_variant_t   var;
				CString      AllManagerPowNum;

				if(!m_pRecordsetPM->adoEOF)
				{
					var = m_pRecordsetPM->GetCollect ("ManagerPowNum");
					AllManagerPowNum = (LPCSTR)_bstr_t(var);

					for(int index =0; index< Count; index++)
					{
						CString tempPowerName;
						m_ManagerPowNotYetList.GetText (index, tempPowerName);

						m_pRecordsetPN->MoveFirst();
						while(!m_pRecordsetPN->adoEOF)
						{
							var = m_pRecordsetPN->GetCollect ("PowerName");
							strValue = (LPCSTR)_bstr_t(var);

							if(strValue == tempPowerName)
							{
								m_ManagerPowNameList.InsertString (-1, strValue);

								var = m_pRecordsetPN->GetCollect ("PowerNum");
								strValue = (LPCSTR)_bstr_t(var);
								AllManagerPowNum += strValue[0];
							}
							m_pRecordsetPN->MoveNext();
						}
					}
				}
				for(int index = 0; index < Count; index++)
		             m_ManagerPowNotYetList.DeleteString(0);

				m_pRecordsetPM->PutCollect ("ManagerPowNum", _variant_t(AllManagerPowNum));
				m_pRecordsetPM->Update();

				m_pRecordsetPN->Close();
				m_pRecordsetPM->Close();
				m_pRecordsetPN = NULL;
				m_pRecordsetPM = NULL;
			}
		}//try
		catch(_com_error &e)
		{
			AfxMessageBox(e.ErrorMessage());
			return;
		}
	}
}

void CPowSetDialog::OnBnClickedUserAllrecede()
{
	int sel = m_PowerNameList.GetCurSel();
	if(sel == LB_ERR)
	{
		AfxMessageBox (_T("没有选择用户权限!"));
		return;
	}
	if(m_ManagerPowNameList.GetCount() == 0)
	{
		AfxMessageBox (_T("该用户没有任何其他管理权限!"));
		return;
	}
	CString PowerName;
	CString strValue;
	m_PowerNameList.GetText(sel, PowerName);
	strValue.Format ("真是要收回%s所有的管理权限吗?", PowerName);

	if(AfxMessageBox (strValue, MB_OKCANCEL) == IDOK)
	{
		int Count = m_ManagerPowNameList.GetCount();

		_RecordsetPtr    m_pRecordsetPN;
		_RecordsetPtr    m_pRecordsetPM;
		HRESULT          hrPN;
		HRESULT          hrPM;
	
		try
		{
			hrPN = m_pRecordsetPN.CreateInstance (__uuidof(Recordset));
			hrPM = m_pRecordsetPM.CreateInstance (__uuidof(Recordset));

			if(FAILED(hrPN) || FAILED(hrPM))
			{
				AfxMessageBox(_T("创建实例失败!"));
				return;
			}
			hrPN = m_pRecordsetPN->Open ("select * from PowerNameTable",
										m_pConnection.GetInterfacePtr(),
										adOpenDynamic,
										adLockOptimistic,
										adCmdText);
										
			CString strSQL;
			strSQL.Format("select * from PowerManagerTable where PowerName = '%s'", PowerName);

			hrPM = m_pRecordsetPM->Open (_bstr_t(strSQL),
										m_pConnection.GetInterfacePtr(),
										adOpenDynamic,
										adLockOptimistic,
										adCmdText);

			if(SUCCEEDED(hrPM) && SUCCEEDED(hrPN))
			{
				_variant_t   var;
				CString      AllManagerPowNum;
				CString      tempAllManagerPowNum;

				if(!m_pRecordsetPM->adoEOF)
				{
					var = m_pRecordsetPM->GetCollect ("ManagerPowNum");
					AllManagerPowNum = (LPCSTR)_bstr_t(var);

					for(int index =0; index< Count; index++)
					{
						CString tempPowerName;
						m_ManagerPowNameList.GetText (index, tempPowerName);

						m_pRecordsetPN->MoveFirst();
						while(!m_pRecordsetPN->adoEOF)
						{
							var = m_pRecordsetPN->GetCollect ("PowerName");
							strValue = (LPCSTR)_bstr_t(var);

							if(strValue == tempPowerName)
							{
								m_ManagerPowNotYetList.InsertString (-1, strValue);

								var = m_pRecordsetPN->GetCollect ("PowerNum");
								strValue = (LPCSTR)_bstr_t(var);
								int Count = AllManagerPowNum.GetLength();
								for(int strindex = 0; strindex < Count; strindex++)
								{
									if(AllManagerPowNum[strindex] != strValue[0])
										tempAllManagerPowNum += AllManagerPowNum[strindex];
								}
								AllManagerPowNum = tempAllManagerPowNum;
								tempAllManagerPowNum = "";
							}
							m_pRecordsetPN->MoveNext();
						}//while
					}//for
				}//if
				for(int index = 0; index < Count; index++)
		             m_ManagerPowNameList.DeleteString(0);

				m_pRecordsetPM->PutCollect ("ManagerPowNum", _variant_t(tempAllManagerPowNum));
				m_pRecordsetPM->Update();

				m_pRecordsetPN->Close();
				m_pRecordsetPM->Close();
				m_pRecordsetPN = NULL;
				m_pRecordsetPM = NULL;
			}
		}//try
		catch(_com_error &e)
		{
			AfxMessageBox(e.ErrorMessage());
			return;
		}
	}
}

void CPowSetDialog::OnLbnSelchangeListModule()
{
	// TODO: 在此添加控件通知处理程序代码
}

void CPowSetDialog::InitManagerModule(CString PowerName)
{
	_RecordsetPtr    m_pRecordsetMM; //ManagerMoudleTable
	_RecordsetPtr    m_pRecordsetM;   //ModuleTable
	HRESULT          hrMM;
	HRESULT          hrM;

	try
	{
		hrMM = m_pRecordsetMM.CreateInstance (__uuidof(Recordset));
		hrM = m_pRecordsetM.CreateInstance (__uuidof(Recordset));
		if(FAILED(hrMM) || FAILED(hrM))
		{
			AfxMessageBox(_T("创建实例失败!"));
			return;
		}
		CString strSQL;
		strSQL.Format ("select * from ManagerModuleTable where PowerName = '%s'", PowerName);

		hrMM = m_pRecordsetMM->Open (_bstr_t(strSQL),
									m_pConnection.GetInterfacePtr(),
									adOpenDynamic,
									adLockOptimistic,
									adCmdText);
        
		hrM = m_pRecordsetM->Open ("select * from ModuleTable",
			                      m_pConnection.GetInterfacePtr(),
								  adOpenDynamic,
								  adLockOptimistic,
								  adCmdText);


		if(SUCCEEDED(hrMM) && SUCCEEDED(hrM))
		{
			_variant_t    var;
			CString       AllManagerModuleNum;

			if(!m_pRecordsetMM->adoEOF)
			{
				var = m_pRecordsetMM->GetCollect ("ManagerModuleNum");
				AllManagerModuleNum = (LPCSTR)_bstr_t(var);
			    
				m_pRecordsetM->MoveFirst();
				while(!m_pRecordsetM->adoEOF)
				{
					var = m_pRecordsetM->GetCollect ("ModuleNum");
					CString ModuleNum = (LPCSTR)_bstr_t(var);

					int Count = AllManagerModuleNum.GetLength();
					for( int index = 0; index < Count; index++)
					{
						if(AllManagerModuleNum[index] == ModuleNum[0])
						{
							var = m_pRecordsetM->GetCollect ("ModuleName");
							CString ModuleName = (LPCSTR)_bstr_t(var);
							m_ListModule.InsertString (-1, ModuleName);
						}
					}
					m_pRecordsetM->MoveNext();
				}//while
			}//if
		}//if
		m_pRecordsetMM->Close();
		m_pRecordsetM->Close();
		m_pRecordsetMM = NULL;
		m_pRecordsetM = NULL;
	}
	catch(_com_error &e)
	{
		AfxMessageBox(e.ErrorMessage());
		return;
	}
}
void CPowSetDialog::OnBnClickedModuleRecede()
{
	int selPN = m_PowerNameList.GetCurSel();//用户权限
	if(selPN == LB_ERR)
	{
		AfxMessageBox (_T("没有选择用户权限!"));
		return;
	}
	if(m_ListModule.GetCount() == 0)
	{
		AfxMessageBox(_T("没有赋予改用户使用任何模块的权限!"));
		return ;
	}
	int selLM =m_ListModule.GetCurSel(); // 已经管理模块
	if(selLM == LB_ERR)
	{
		AfxMessageBox (_T("没有选择已管理模块!"));
		return;
	}

	CString ModuleName, PowerName;
	m_ListModule.GetText (selLM, ModuleName);
	m_PowerNameList.GetText (selPN, PowerName);
   
	if(PowerName == _T("系统管理员"))
	{
		MessageBox (_T("系统管理员是系统自带的权限,不能修改!"), _T("权限设置"), MB_ICONERROR | MB_OK);
		return;
	}

	CString strValue;
	strValue.Format ("真的要回收%s%s的使用权限?", PowerName, ModuleName);
	
	if(AfxMessageBox (strValue, MB_OKCANCEL) == IDOK)
	{
		_RecordsetPtr     m_pRecordsetMM;// ManagerModuleNum
		_RecordsetPtr     m_pRecordsetM; // ManagerTable
		HRESULT           hrMM;
		HRESULT           hrM;
     
		try
		{
			hrMM = m_pRecordsetMM.CreateInstance (__uuidof(Recordset));
			hrM = m_pRecordsetM.CreateInstance (__uuidof(Recordset));
			if(FAILED(hrMM) || FAILED(hrM))
			{
				AfxMessageBox (_T("创建实例失败!"));
				return;
			}

			CString strSQL;
			strSQL.Format ("select * from ManagerModuleTable where PowerName = '%s'", PowerName);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -