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

📄 powsetdialog.cpp

📁 VC+SQL SERVER 2000环境下开发的商品销售管理系统
💻 CPP
📖 第 1 页 / 共 4 页
字号:
			hrMM = m_pRecordsetMM->Open (_bstr_t(strSQL),
										m_pConnection.GetInterfacePtr(),
										adOpenDynamic,
										adLockOptimistic,
										adCmdText);

			strSQL.Format ("select * from ModuleTable where ModuleName = '%s'", ModuleName);
			hrM = m_pRecordsetM->Open (_bstr_t(strSQL),
										m_pConnection.GetInterfacePtr(),
										adOpenDynamic,
										adLockOptimistic,
										adCmdText);

			if(SUCCEEDED(hrMM) && SUCCEEDED(hrM))
			{
				if(!m_pRecordsetMM->adoEOF)
				{                  
					m_ListModule.DeleteString(selLM);

					_variant_t  var = m_pRecordsetMM->GetCollect ("ManagerModuleNum");
					CString    AllModuleNum = (LPCSTR)_bstr_t(var);

					var = m_pRecordsetM->GetCollect ("ModuleNum");
					CString ModuleNum = (LPCSTR)_bstr_t(var);

					int Count = AllModuleNum.GetLength();
					CString tempAllModuleNum = "";
					for( int index = 0; index< Count; index++)
					{
						if(AllModuleNum[index] != ModuleNum[0])
							tempAllModuleNum += AllModuleNum[index];
					}
					m_pRecordsetMM->PutCollect ("ManagerModuleNum", _variant_t(tempAllModuleNum));
					m_pRecordsetMM->Update();
				}
				m_ListNoModule.InsertString (-1, ModuleName);

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

void CPowSetDialog::InitManagerNotYetModule(CString PowerName)
{
	_RecordsetPtr    m_pRecordsetMM; // ManagerModuleTable
	_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))
		{
		  if(!m_pRecordsetMM->adoEOF)
		  {
			_variant_t var = m_pRecordsetMM->GetCollect ("ManagerModuleNum");
			CString AllModuleNum = (LPCSTR)_bstr_t(var);

			struct FlagModule{
				CString ModuleNum;
				CString ModuleName;
				BOOL    flag;
			};

			int size = 0;
			while(!m_pRecordsetM->adoEOF)
			{
				size++;
				m_pRecordsetM->MoveNext();
			}

			FlagModule *pFlagModule = new FlagModule[size];

			m_pRecordsetM->MoveFirst();
			int modindex = 0;
			while(!m_pRecordsetM->adoEOF)
			{
				var = m_pRecordsetM->GetCollect ("ModuleNum");
				pFlagModule[modindex].ModuleNum = (LPCSTR)_bstr_t(var);
				var = m_pRecordsetM->GetCollect ("ModuleName");
				pFlagModule[modindex].ModuleName = (LPCSTR)_bstr_t(var);
				pFlagModule[modindex].flag = FALSE;
				
				modindex++;
				m_pRecordsetM->MoveNext();
			}


			int Count = AllModuleNum.GetLength();
			for(int index = 0; index< Count; index++)
			{
				for(modindex = 0; modindex < size; modindex++)
				{
					if(AllModuleNum[index] == pFlagModule[modindex].ModuleNum)
					{
						pFlagModule[modindex].flag = TRUE;
						break;
					}
				}

			}//for

			for(modindex = 0; modindex < size; modindex++)
			{
				if(pFlagModule[modindex].flag == FALSE)
					m_ListNoModule.InsertString(-1, pFlagModule[modindex].ModuleName);
			}

			m_pRecordsetMM->Close();
			m_pRecordsetM->Close();
			m_pRecordsetMM = NULL;
			m_pRecordsetM = NULL;
			delete [] pFlagModule;
		  }//if
		}
	}
	catch(_com_error &e)
	{
		AfxMessageBox(e.ErrorMessage());
		return;
	}
}

void CPowSetDialog::OnBnClickedModuleGive()
{
	int selPN = m_PowerNameList.GetCurSel();//用户权限
	if(selPN == LB_ERR)
	{
		AfxMessageBox (_T("没有选择用户权限!"));
		return;
	}
	if(m_ListNoModule.GetCount() == 0)
	{
		AfxMessageBox(_T("该用户已经拥有了系统所有模块使用权限!"));
		return;
	}
	int selLM =m_ListNoModule.GetCurSel(); // 未已经管理模块
	if(selLM == LB_ERR)
	{
		AfxMessageBox (_T("没有选择未管理模块!"));
		return;
	}

	CString ModuleName, PowerName;
	m_ListNoModule.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);
			hrMM = m_pRecordsetMM->Open (_bstr_t(strSQL),
										m_pConnection.GetInterfacePtr(),
										adOpenDynamic,
										adLockOptimistic,
										adCmdText);

			strSQL.Format ("select * from ModuleTable where ModuleName = '%s'", ModuleName);
			hrM = m_pRecordsetM->Open (_bstr_t(strSQL),
										m_pConnection.GetInterfacePtr(),
										adOpenDynamic,
										adLockOptimistic,
										adCmdText);

			if(SUCCEEDED(hrMM) && SUCCEEDED(hrM))
			{
				if(!m_pRecordsetMM->adoEOF)
				{                  
					m_ListNoModule.DeleteString(selLM);

					_variant_t  var = m_pRecordsetMM->GetCollect ("ManagerModuleNum");
					CString    AllModuleNum = (LPCSTR)_bstr_t(var);

					var = m_pRecordsetM->GetCollect ("ModuleNum");
					CString ModuleNum = (LPCSTR)_bstr_t(var);

					AllModuleNum += ModuleNum[0];

					m_pRecordsetMM->PutCollect ("ManagerModuleNum", _variant_t(AllModuleNum));
					m_pRecordsetMM->Update();
				}
				m_ListModule.InsertString (-1, ModuleName);

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

void CPowSetDialog::OnBnClickedModuleAllgive()
{
	int selPN = m_PowerNameList.GetCurSel();//用户权限
	if(selPN == LB_ERR)
	{
		AfxMessageBox (_T("没有选择用户权限!"));
		return;
	}
	if(m_ListNoModule.GetCount() == 0)
	{
		AfxMessageBox(_T("该用户已经拥有了系统所有模块使用权限!"));
		return;
	}
    CString PowerName;
	m_PowerNameList.GetText (selPN, PowerName);

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

	CString strValue;
	strValue.Format ("真的要赋予%s所有模块的使用权限?", PowerName);
	
	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);
			hrMM = m_pRecordsetMM->Open (_bstr_t(strSQL),
										m_pConnection.GetInterfacePtr(),
										adOpenDynamic,
										adLockOptimistic,
										adCmdText);

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

			if(SUCCEEDED(hrMM) && SUCCEEDED(hrM))
			{
				if(!m_pRecordsetMM->adoEOF)
				{                  
					int Count = m_ListNoModule.GetCount();
					_variant_t var = m_pRecordsetMM->GetCollect("ManagerModuleNum");
					CString AllManagerModule = (LPCSTR)_bstr_t(var);
					CString strValue;

					for(int index = 0; index < Count; index++)
					{
						m_ListNoModule.GetText(index, strValue);
						
						m_pRecordsetM->MoveFirst();
						while(!m_pRecordsetM->adoEOF)
						{
							var = m_pRecordsetM->GetCollect("ModuleName");
							CString ModuleName = (LPCSTR)_bstr_t(var);
							if(ModuleName == strValue)
							{
								var = m_pRecordsetM->GetCollect("ModuleNum");
								CString ModuleNum = (LPCSTR)_bstr_t(var);
								m_ListModule.InsertString(-1, ModuleName);

								AllManagerModule += ModuleNum[0];
							}
							m_pRecordsetM->MoveNext();
						}//while
					}//for
					m_pRecordsetMM->PutCollect("ManagerModuleNum", _variant_t(AllManagerModule));
					m_pRecordsetMM->Update();

					for(int index = 0 ; index< Count; index++)
						m_ListNoModule.DeleteString(0);
				}//if

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

void CPowSetDialog::OnBnClickedModuleAllrecede()
{
    int selPN = m_PowerNameList.GetCurSel();//用户权限
	if(selPN == LB_ERR)
	{
		AfxMessageBox (_T("没有选择用户权限!"));
		return;
	}
	if(m_ListModule.GetCount() == 0)
	{
		AfxMessageBox(_T("没有赋予改用户使用任何模块的权限!"));
		return ;
	}

	CString  PowerName;
	m_PowerNameList.GetText (selPN, PowerName);

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

	CString strValue;
	strValue.Format ("真的要回收%s的所有模块使用权限?", PowerName);
	
	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);
			hrMM = m_pRecordsetMM->Open (_bstr_t(strSQL),
										m_pConnection.GetInterfacePtr(),
										adOpenDynamic,
										adLockOptimistic,
										adCmdText);

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

			if(SUCCEEDED(hrMM) && SUCCEEDED(hrM))
			{
				if(!m_pRecordsetMM->adoEOF)
				{                  

					_variant_t  var = m_pRecordsetMM->GetCollect ("ManagerModuleNum");
					CString    AllModuleNum = (LPCSTR)_bstr_t(var);

					var = m_pRecordsetM->GetCollect ("ModuleNum");
					CString ModuleNum = (LPCSTR)_bstr_t(var);

					int Count = m_ListModule.GetCount();
					CString tempAllModuleNum = "";
					CString tempPowerName;

					for(int index = 0; index < Count; index++)
					{
						m_ListModule.GetText (index, tempPowerName);
						m_pRecordsetM->MoveFirst();
						
						while(!m_pRecordsetM->adoEOF)
						{
						   var = m_pRecordsetM->GetCollect ("ModuleName");
						   CString strValue = (LPCSTR)_bstr_t(var);
						   
						   if(strValue == tempPowerName)
						   {   
							   m_ListNoModule.InsertString(-1, strValue);
							   var = m_pRecordsetM->GetCollect ("ModuleNum");
							   CString ModuleNum = (LPCSTR)_bstr_t(var);
							   int Count = AllModuleNum.GetLength();

							   for(int modindex = 0; modindex < Count; modindex++)
							   {
								   if(AllModuleNum[modindex] != ModuleNum[0])
									   tempAllModuleNum += AllModuleNum[modindex];
							   }

							   AllModuleNum = tempAllModuleNum;
							   tempAllModuleNum = "";
						   }
						   m_pRecordsetM->MoveNext();
						}//while
					}//for
                    Count = m_ListModule.GetCount();
					for(int modindex = 0; modindex < Count; modindex++)
						m_ListModule.DeleteString(0);
				
					m_pRecordsetMM->PutCollect ("ManagerModuleNum", _variant_t(tempAllModuleNum));
					m_pRecordsetMM->Update();
				}
				m_pRecordsetMM->Close();
				m_pRecordsetM->Close();
				m_pRecordsetMM = NULL;
				m_pRecordsetM = NULL;
			}
		}//try
		catch(_com_error &e)
		{
			AfxMessageBox(e.ErrorMessage());
			return;
		}
	}//if
}

⌨️ 快捷键说明

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