15,978
社区成员
发帖
与我相关
我的任务
分享BOOL CNewsqlApp::InitInstance()
{
AfxEnableControlContainer();
// 初始化COM,创建ADO连接等操作
AfxOleInit();
m_pConnection.CreateInstance(__uuidof(Connection));
// 在ADO操作中建议语句中要常用try...catch()来捕获错误信息,
// 因为它有时会经常出现一些想不到的错误。jingzhou xu
try
{
// 打开本地Access库Demo.mdb
m_pConnection->Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=bs.mdb","","",adModeUnknown);
}
catch(_com_error& e)
{
//调用在CAdoRWAccessDlg中打印错误信息的静态函数
CNewsqlDlg::dump_com_error(e);
return FALSE;
}
// Standard initialization
// If you are not using these features and wish to reduce the size
// of your final executable, you should remove from the following
// the specific initialization routines you do not need.
#ifdef _AFXDLL
Enable3dControls(); // Call this when using MFC in a shared DLL
#else
Enable3dControlsStatic(); // Call this when linking to MFC statically
#endif
login login1;
// m_pMainWnd = &login1;
int ifok =login1.DoModal();
if (ifok==IDOK)
{
}
else if (ifok==IDCANCEL)
{
}
/* CNewsqlDlg dlg;
m_pMainWnd = &dlg;
int nResponse = dlg.DoModal();
if (nResponse == IDOK)
{
// TODO: Place code here to handle when the dialog is
// dismissed with OK
}
else if (nResponse == IDCANCEL)
{
// TODO: Place code here to handle when the dialog is
// dismissed with Cancel
}*/
// Since the dialog has been closed, return FALSE so that we exit the
// application, rather than start the application's message pump.
return FALSE;
}BOOL CNewsqlApp::InitInstance()
{
AfxEnableControlContainer();
// 初始化COM,创建ADO连接等操作
AfxOleInit();
m_pConnection.CreateInstance(__uuidof(Connection));
// 在ADO操作中建议语句中要常用try...catch()来捕获错误信息,
// 因为它有时会经常出现一些想不到的错误。jingzhou xu
try
{
// 打开本地Access库Demo.mdb
m_pConnection->Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=bs.mdb","","",adModeUnknown);
}
catch(_com_error& e)
{
//调用在CAdoRWAccessDlg中打印错误信息的静态函数
CNewsqlDlg::dump_com_error(e);
return FALSE;
}
// Standard initialization
// If you are not using these features and wish to reduce the size
// of your final executable, you should remove from the following
// the specific initialization routines you do not need.
#ifdef _AFXDLL
Enable3dControls(); // Call this when using MFC in a shared DLL
#else
Enable3dControlsStatic(); // Call this when linking to MFC statically
#endif
login login1;
m_pMainWnd = &login1;
int ifok =login1.DoModal();
if (ifok==IDOK)
{
login::OnOK();
}
else if (ifok==IDCANCEL)
{
}
/* CNewsqlDlg dlg;
m_pMainWnd = &dlg;
int nResponse = dlg.DoModal();
if (nResponse == IDOK)
{
// TODO: Place code here to handle when the dialog is
// dismissed with OK
}
else if (nResponse == IDCANCEL)
{
// TODO: Place code here to handle when the dialog is
// dismissed with Cancel
}*/
// Since the dialog has been closed, return FALSE so that we exit the
// application, rather than start the application's message pump.
return FALSE;
}void login::OnOK()
{
// TODO: Add extra validation here
_variant_t var1,var2,var3,var4,var5,var6,var7;
CDialog::OnOK();
// AfxMessageBox(m_user);
// AfxMessageBox(m_password);
if (allcanused::ifuser==1)
{try
{m_pRecordset.CreateInstance(__uuidof(Recordset));
m_pRecordset->Open("SELECT * FROM owner",
theApp.m_pConnection.GetInterfacePtr(), // 获取库接库的IDispatch指针
adOpenDynamic,
adLockOptimistic,
adCmdText);
}
catch(_com_error& e)
{
dump_com_error(e);
}
m_pRecordset->MoveFirst();
while(!m_pRecordset->adoEOF)
{
var6=m_pRecordset->GetCollect ("TEL");
if(var6.vt != VT_NULL)
allcanused::OTEL =(LPCSTR) _bstr_t(var6);
if (allcanused::OTEL==m_user)
break;
m_pRecordset->MoveNext();
}
if (m_pRecordset->adoEOF)
{
AfxMessageBox("用户不在数据表中,请联系管理员注册账号") ;
login login1;
login1.DoModal();
}
else
{
var7=m_pRecordset->GetCollect ("password");
if(var7.vt != VT_NULL)
allcanused::Opassword =(LPCSTR) _bstr_t(var7);
if (allcanused::Opassword ==m_password)
{
AfxMessageBox("尊敬的车主您好,为了更好的方便管理,除了密码,您的其他的资料信息无法修改,如发现资料不符可以带相关证明找管理员修改");
var1=m_pRecordset->GetCollect ("name");
if(var1.vt != VT_NULL)
allcanused::Oname =(LPCSTR) _bstr_t(var1);
var4=m_pRecordset->GetCollect ("ID");
if(var4.vt != VT_NULL)
allcanused::OID= (LPCSTR)_bstr_t(var4);
var5=m_pRecordset->GetCollect ("DID");
if(var5.vt != VT_NULL)
allcanused::ODID= (LPCSTR)_bstr_t(var5);
var6=m_pRecordset->GetCollect ("TEL");
if(var6.vt != VT_NULL)
allcanused::OTEL= (LPCSTR)_bstr_t(var6);
userdlg *userdlg1;
userdlg1=new userdlg(this);
userdlg1->Create(IDD_USERDLG);
userdlg1->SetDlgItemText(IDC_EDIT1,allcanused::Oname);
userdlg1->SetDlgItemText(IDC_EDIT3,allcanused::OID);
userdlg1->SetDlgItemText(IDC_EDIT2,allcanused::ODID);
userdlg1->SetDlgItemText(IDC_EDIT4,allcanused::OTEL);
userdlg1->ShowWindow(SW_RESTORE);
}
else
{
AfxMessageBox("密码用户错误");
login login1;
login1.DoModal();
}
}
}
else if(allcanused::ifuser==0)
{
try
{m_pRecordset.CreateInstance(__uuidof(Recordset));
m_pRecordset->Open("SELECT * FROM Administrator",
theApp.m_pConnection.GetInterfacePtr(), // 获取库接库的IDispatch指针
adOpenDynamic,
adLockOptimistic,
adCmdText);
}
catch(_com_error& e)
{
dump_com_error(e);
}
m_pRecordset->MoveFirst();
while(!m_pRecordset->adoEOF)
{
var6=m_pRecordset->GetCollect ("account");
if(var6.vt != VT_NULL)
allcanused::Aaccount =(LPCSTR) _bstr_t(var6);
if (allcanused::Aaccount==m_user)
break;
m_pRecordset->MoveNext();
}
if (m_pRecordset->adoEOF)
{
AfxMessageBox("用户不在数据表中,确定您是管理员?") ;
login login1;
login1.DoModal();
}
else
{
var7=m_pRecordset->GetCollect ("password");
if(var7.vt != VT_NULL)
allcanused::Apassword =(LPCSTR) _bstr_t(var7);
if (allcanused::Apassword ==m_password)
{
CNewsqlDlg dlg;
// m_pMainWnd = &dlg;
int nResponse = dlg.DoModal();
}
else
AfxMessageBox("密码用户错误");
}
}
}