ommon files\system\ado\msado15.dll" \
no_namespace \
rename ("EOF", "adoEOF")
并在Myhotel.h中加入:
CDatabase m_DB;
_ConnectionPtr m_pConnection;
此外在myhotel.cpp的初始化函数中加入连接数据库的代码:
ry//连接数据库
{
CString strConnect;
strConnect.Format("DSN=myhotel;");
if(!m_DB.OpenEx(strConnect,CDatabase::useCursorLib))
{
AfxMessageBox("Unable to Connect to the Specified Data Source");
return FALSE ;
}
}
catch(CDBException *pE)//抛出异常
{
pE->ReportError();
pE->Delete();
return FALSE;
}
..........................................
..........................................
// 初始化COM,创建ADO连接等操作
AfxOleInit();
m_pConnection.CreateInstance(__uuidof(Connection));
// 在ADO操作中建议语句中要常用try...catch()来捕获错误信息,
//
try
{
// 打开本地数据库
m_pConnection->Open("Provider=MSDASQL.1;Persist Security Info=False;Data Source=myhotel","","",adModeUnknown);
}
catch(_com_error e)//抛出可能发生的异常
{
AfxMessageBox("数据库连接失败,确认数据库配置正确!");
return FALSE;
}
(2)此主窗口初始化时候要根据登录的操作员的权限来设置登录操作员所有权进行的操作,此功能由函数setuserability来完成,代码为:
void CMyhotelDlg::setuserability()
{
m_pRecordset.CreateInstance(__uuidof(Recordset));
_variant_t var,varIndex;
//loguserid="操作员01";
CString strsqlshow;
strsqlshow.Format("SELECT * FROM setability where 操作员='%s'",loguserid);
try//打开数据库连接
{
m_pRecordset->Open((_variant_t)(strsqlshow), // 查询表中所有字段
theApp.m_pConnection.GetInterfacePtr(),// 获取库接库的IDispatch指针
adOpenDynamic,
adLockOptimistic,
adCmdText);
}
catch(_com_error *e)//捕获异常的发生
{
AfxMessageBox(e->ErrorMessage());
}
///////////////////////////////////////////////
mynenu=AfxGetMainWnd()->GetMenu();//获得主菜单指针
//////////////////////////////////////////////
CString ling="0";
try
{
if(!m_pRecordset->BOF)//判断指针是否在数据集最后
m_pRecordset->MoveFirst();
else
{
AfxMessageBox("表内数据为空");
return;
}
// MessageBox("eeeeeeeeee");
//读取数据表内客房预定字段内容
var = m_pRecordset->GetCollect("客房预定");
if(var.vt != VT_NULL)
{
if((LPCSTR)_bstr_t(var)==ling)//判断是否有权限操作客房预定模块
{ //如果没有权利就使该菜单灰显
EnableMenuItem(mynenu->m_hMenu,ID_MENU_roomprebook,MF_DISABLED|MF_GRAYED);
}
}
//读取数据表内住宿登记字段内容
var = m_pRecordset->GetCollect("住宿登记");
if(var.vt != VT_NULL)
{
if((LPCSTR)_bstr_t(var)==ling)//判断是否有权限操作住宿登记模块
{ //如果没有权利就使该菜单灰显
EnableMenuItem(mynenu->m_hMenu,ID_MENU_checkinreg,MF_DISABLED|MF_GRAYED);
}
}
//读取数据表内追加押金字段内容
var = m_pRecordset->GetCollect("追加押金");
if(var.vt != VT_NULL)
{
if((LPCSTR)_bstr_t(var)==ling)//判断是否有权限操作追加押金模块
{ //如果没有权利就使该菜单灰显
EnableMenuItem(mynenu->m_hMenu,ID_MENU_addmoney,MF_DISABLED|MF_GRAYED);
}
}
//读取数据表内调房登记字段内容
var = m_pRecordset->GetCollect("调房登记");
if(var.vt != VT_NULL)
{
if((LPCSTR)_bstr_t(var)==ling)//判断是否有权限操作调房登记模块
{ //如果没有权利就使该菜单灰显
EnableMenuItem(mynenu->m_hMenu,ID_MENU_changeroomreg,MF_DISABLED|MF_GRAYED);
}
}
//读取数据表内退宿登记字段内容
var = m_pRecordset->GetCollect("退宿登记");
if(var.vt != VT_NULL)
{
if((LPCSTR)_bstr_t(var)==ling)//判断是否有权限操作退宿登记模块
{ //如果没有权利就使该菜单灰显
EnableMenuItem(mynenu->m_hMenu,ID_MENU_checkout,MF_DISABLED|MF_GRAYED);
}
}
//读取数据表内客房管理字段内容
var = m_pRecordset->GetCollect("客房管理");
if(var.vt != VT_NULL)
{
if((LPCSTR)_bstr_t(var)==ling)//判断是否有权限操作客房管理模块
{ //如果没有权利就使该菜单灰显
EnableMenuItem(mynenu->m_hMenu,ID_MENU_roomsetting,MF_DISABLED|MF_GRAYED);
}
}
//读取数据表内客房查询字段内容
var = m_pRecordset->GetCollect("客房查询");
if(var.vt != VT_NULL)
{
if((LPCSTR)_bstr_t(var)==ling)//判断是否有权限操作客房查询模块
{ //如果没有权利就使该菜单灰显
EnableMenuItem(mynenu->m_hMenu,ID_MENU_findroom,MF_DISABLED|MF_GRAYED);
}
}
//读取数据表内房态查看字段内容
var = m_pRecordset->GetCollect("房态查看");
if(var.vt != VT_NULL)
{
if((LPCSTR)_bstr_t(var)==ling)//判断是否有权限操作房态查看模块
{ //如果没有权利就使该菜单灰显
EnableMenuItem(mynenu->m_hMenu,ID_MENU_findroomstate,MF_DISABLED|MF_GRAYE
上一篇:
tts工资管理系统论程序设计VFP_论文
下一篇:
西班牙语童话:El Alimento de Dios