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

📄 role.cpp

📁 一个电视台专用的信息管理软件源代码
💻 CPP
字号:
// Role.cpp: implementation of the CRole class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"

#include "Role.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CRole::CRole()
{

}

CRole::~CRole()
{

}

int CRole::GetUID()
{
	return UID;
}

void CRole::SetUID(int iUID)
{
	UID=iUID;
}

int CRole::GetRoleID()
{
	return RoleID;
}

void CRole::SetRoleID(int iRoleID)
{
	RoleID=iRoleID;
}

CString CRole::GetName()
{
	return Name;
}

void CRole::SetName(CString cName)
{
	Name = cName;
}


CString CRole::GetDesc()
{
	return Desc;
}

void CRole::SetDesc(CString cDesc)
{
	Desc = cDesc;
}


//数据库操作

	
void CRole::sql_insert(CString cName,CString cDesc)
{	
	//设置INSERT语句
	vSQL = "INSERT INTO Role VALUES('" + cName + "','" +cDesc + "')";

	//执行INSERT语句
	ExecuteSQL(vSQL);	
}

void CRole::sql_update(long iUID,CString cName,CString cDesc,long& iFlg,CString& cMessage)
{

	try
	{
		m_pCommand.CreateInstance(__uuidof(Command));
		m_pCommand->ActiveConnection=m_pConnection;
		m_pCommand->CommandType=adCmdStoredProc;
		m_pCommand->CommandText=_bstr_t("edt_Role");
		
		_variant_t vvar1,vvar2,vvar3,vvar4,vvar5;
	
		vvar1=_variant_t(_bstr_t(cName));
		vvar2=_variant_t(_bstr_t(cDesc));
		vvar3=_variant_t(iUID);
		vvar4=_variant_t(iFlg);
		vvar5=_variant_t(_bstr_t(cMessage));

		_ParameterPtr mp_var1,mp_var2,mp_var3,mp_var4,mp_var5;
		mp_var1.CreateInstance(__uuidof(Parameter));
		mp_var2.CreateInstance(__uuidof(Parameter));
		mp_var3.CreateInstance(__uuidof(Parameter));
		mp_var4.CreateInstance(__uuidof(Parameter));
		mp_var5.CreateInstance(__uuidof(Parameter));
	
		mp_var1=m_pCommand->CreateParameter
		(
		_bstr_t("var1"),
		adVarChar,
		adParamInput,
		50,
		vvar1
		);
		m_pCommand->Parameters->Append(mp_var1); 

		mp_var2=m_pCommand->CreateParameter
		(
		_bstr_t("var2"),
		adVarChar,
		adParamInput,
		2000,
		vvar2
		);
		m_pCommand->Parameters->Append(mp_var2); 
		

		mp_var3=m_pCommand->CreateParameter
		(
		_bstr_t("var3"),
		adBigInt,
		adParamInput,
		5,
		vvar3
		);
		m_pCommand->Parameters->Append(mp_var3); 
	
		mp_var4=m_pCommand->CreateParameter
		(
		_bstr_t("var4"),
		adBigInt,
		adParamOutput,
		5,
		vvar4
		);
		m_pCommand->Parameters->Append(mp_var4); 

		mp_var5=m_pCommand->CreateParameter
		(
		_bstr_t("var5"),
		adVarChar,
		adParamOutput,
		200,
		vvar5
		);
		m_pCommand->Parameters->Append(mp_var5); 


		_variant_t vNull;
		vNull.vt=VT_ERROR;
		vNull.scode=DISP_E_PARAMNOTFOUND;
		m_pCommand->Execute(&vNull,&vNull,adCmdStoredProc);

		iFlg=mp_var4->Value;
		cMessage=mp_var5->Value.bstrVal;
		}
		catch(_com_error &error)
		{
			AfxMessageBox(error.ErrorMessage(),MB_OK,0);
			AfxMessageBox(error.Description(),MB_OK,0);
			AfxMessageBox("ADO错误!",MB_OK,0);
		}
	
}

void CRole::sql_delete(int iUID)
{

	//设置DELETE语句
	vSQL = "DELETE FROM Role WHERE UID=" + iUID;
	//执行DELETE语句
	ExecuteSQL(vSQL);	
}
	


//根据角色编号读取所有字段值
void CRole::GetData(int UID)
{

	//设置SELECT语句
	CString strUID;
	strUID.Format("%d",UID);
	vSQL = "SELECT * FROM Role WHERE UID=" + strUID;
	//执行SELETE语句
	m_pRecordset = GetRecordSet(vSQL);

	//返回各列的值
	if (m_pRecordset->adoEOF)
		CRole();
	else
	{
		Name = (LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("Name");
		Desc = (LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("Description");
	}
}

//PASS
void CRole::GetAllRole(CStringArray& allRoles,int num)
{
	//设置SELECT语句
	CString strNum;
	strNum.Format("%d",num);
	vSQL = "SELECT Name FROM Role WHERE IsDelete='0' AND ROLEID >"+ strNum;

	//执行SELETE语句
	m_pRecordset = GetRecordSet(vSQL);

	while(!m_pRecordset->adoEOF)
	{
		allRoles.Add((_bstr_t)m_pRecordset->GetCollect("Name"));

		m_pRecordset->MoveNext();
	}
}

//PASS
int CRole::getRoleIDByRoleName(CString roleName)
{
	//设置SELECT语句
	_bstr_t vSQL;
	
	vSQL = "SELECT RoleID FROM Role WHERE Name='"+roleName+"'";
	//执行SELETE语句

	m_pRecordset = GetRecordSet(vSQL);
	
	if (m_pRecordset->adoEOF)
	{
		CRole();
	}
	else
	{
		
		RoleID = atoi((LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("RoleID"));
		
	}
	return RoleID;
}
int CRole::GetIDByName(CString cName)
{
	int iUID=-1;
	vSQL = "SELECT UID FROM Role WHERE Name='" + cName+"'";
	//执行SELETE语句
	m_pRecordset = GetRecordSet(vSQL);
	//返回各列的值
	if (m_pRecordset->adoEOF)
		CRole();
	else
	{
		
		iUID = atoi((LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("UID"));
	
	}
	
	return iUID;

}
void CRole::ShowList(CListCtrl& listctrl)
{
	int i=0;
    LV_ITEM lvitem;
	lvitem.mask=LVIF_TEXT | LVIF_IMAGE | LVIF_STATE;
	lvitem.state=0;
	lvitem.stateMask=0;

	CString strUID,strDescription,strName;

	CString strSQL = "";
	m_pCommand.CreateInstance(__uuidof(Command));
	m_pCommand->ActiveConnection=m_pConnection;
	m_pCommand->CommandText="QryRole";    
	m_pCommand->CommandType=adCmdStoredProc;
	m_pCommand->Parameters->Refresh(); 

	m_pCommand->Parameters->GetItem((short)1)->Value=(_bstr_t)strSQL;


	m_pRecordset = m_pCommand->Execute(NULL,NULL,adCmdStoredProc);

	listctrl.DeleteAllItems();
    	
	 while(!m_pRecordset->adoEOF)
	{   
		lvitem.iItem=i;
		lvitem.iSubItem=0;
		strUID=(LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("UID");
		lvitem.pszText=(LPTSTR)(LPCTSTR)strUID;  
		listctrl.InsertItem(&lvitem);

		strName =(LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("Name");
		listctrl.SetItemText(i,1,strName);

		strDescription =(LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("Description");
		listctrl.SetItemText(i,2,strDescription);

		i++;
		m_pRecordset->MoveNext();
	}

}
void CRole::GetAllRole(CStringArray& allRoles)
{
	//设置SELECT语句
	vSQL = "SELECT Name FROM Role";
	//执行SELETE语句
	m_pRecordset = GetRecordSet(vSQL);
	while(!m_pRecordset->adoEOF)
	{
		allRoles.Add(_T((_bstr_t)m_pRecordset->GetCollect("Name")));
		m_pRecordset->MoveNext();
	}

}

⌨️ 快捷键说明

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