?? role.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;
}
//數(shù)據(jù)庫操作
void CRole::sql_insert(CString cName,CString cDesc)
{
//設(shè)置INSERT語句
vSQL = "INSERT INTO Role VALUES('" + cName + "','" +cDesc + "')";
//執(zhí)行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)
{
//設(shè)置DELETE語句
vSQL = "DELETE FROM Role WHERE UID=" + iUID;
//執(zhí)行DELETE語句
ExecuteSQL(vSQL);
}
//根據(jù)角色編號讀取所有字段值
void CRole::GetData(int UID)
{
//設(shè)置SELECT語句
CString strUID;
strUID.Format("%d",UID);
vSQL = "SELECT * FROM Role WHERE UID=" + strUID;
//執(zhí)行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)
{
//設(shè)置SELECT語句
CString strNum;
strNum.Format("%d",num);
vSQL = "SELECT Name FROM Role WHERE IsDelete='0' AND ROLEID >"+ strNum;
//執(zhí)行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)
{
//設(shè)置SELECT語句
_bstr_t vSQL;
vSQL = "SELECT RoleID FROM Role WHERE Name='"+roleName+"'";
//執(zhí)行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+"'";
//執(zhí)行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)
{
//設(shè)置SELECT語句
vSQL = "SELECT Name FROM Role";
//執(zhí)行SELETE語句
m_pRecordset = GetRecordSet(vSQL);
while(!m_pRecordset->adoEOF)
{
allRoles.Add(_T((_bstr_t)m_pRecordset->GetCollect("Name")));
m_pRecordset->MoveNext();
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -