首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VC/MFC >

急救,救!该怎么处理

2012-05-24 
急救,急救!!!本人按照书上做了一个试题库系统,其它模块运转正常,但用户管理模块彻底进不去了分为两段代码:

急救,急救!!!
本人按照书上做了一个试题库系统,其它模块运转正常,但用户管理模块彻底进不去了
分为两段代码:
  进入用户管理模块代码:
  if(m_tree.GetItemText(hselItem)=="用户管理")
{
if(userright==0)
{

USERDLG mydlg;
mydlg.DoModal();
return;
}
else
{
AfxMessageBox("您是录入员,没有此权限!");
return;
}
}
USERDLG 的全部代码:
// USERDLG.cpp : implementation file
//

#include "stdafx.h"
#include "TBManager.h"
#include "USERDLG.h"

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

/////////////////////////////////////////////////////////////////////////////
// USERDLG dialog


USERDLG::USERDLG(CWnd* pParent /*=NULL*/)
: CDialog(USERDLG::IDD, pParent)
{
//{{AFX_DATA_INIT(USERDLG)
m_name = _T("");
m_newpass = _T("");
m_nnewpass = _T("");
m_oldpass = _T("");
m_pass1 = _T("");
m_pass2 = _T("");
//}}AFX_DATA_INIT
}


void USERDLG::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(USERDLG)
DDX_Control(pDX, IDC_LIST2, m_list);
DDX_Control(pDX, IDC_COMBO1, m_combo);
DDX_Text(pDX, IDC_NAME, m_name);
DDX_Text(pDX, IDC_NEWPASS, m_newpass);
DDX_Text(pDX, IDC_NNEWPASS, m_nnewpass);
DDX_Text(pDX, IDC_OLDPASS, m_oldpass);
DDX_Text(pDX, IDC_PASS1, m_pass1);
DDX_Text(pDX, IDC_PASS2, m_pass2);
//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(USERDLG, CDialog)
//{{AFX_MSG_MAP(USERDLG)
ON_BN_CLICKED(IDC_MODIFY, OnModify)
ON_BN_CLICKED(IDC_ADDUSER, OnAdduser)
ON_BN_CLICKED(IDC_DELUSER, OnDeluser)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// USERDLG message handlers

void USERDLG::OnModify() //修改密码
{
UpdateData();
if(m_oldpass=="")
{
  MessageBox("请选择用户!");
GetDlgItem(IDC_OLDPASS)->SetFocus();
//return ;
}
if(m_oldpass!=e_mima)
{
MessageBox("密码与原密码不符,请重新输入!");
GetDlgItem(IDC_OLDPASS)->SetFocus();
m_oldpass=m_newpass=m_nnewpass="";
UpdateData(false);
//return ;
}
if(m_newpass!=m_nnewpass)
{
MessageBox("密码不符!");
GetDlgItem(IDC_OLDPASS)->SetFocus();
m_oldpass=m_newpass=m_nnewpass="";
UpdateData(false);
//return ;
}
else
{
_variant_t ra;
CString str;
str.Format("update password set password='%s' where name='%s'",m_newpass,e_user);
m_pConnection->Execute(str.AllocSysString(),&ra,adCmdText);
MessageBox("密码修改成功!");
m_oldpass=m_newpass=m_nnewpass="";
UpdateData(false);
//return ;
}

}

void USERDLG::OnAdduser() 
{
UpdateData();
//CString temp;
if(m_name=="")
{
MessageBox("您好,用户名不能为空!");
GetDlgItem(IDC_NAME)->SetFocus();
}
else if(m_pass1!=m_pass2)
{  
MessageBox("两次密码输入不一致,请重新输入!");
GetDlgItem(IDC_PASS1)->SetFocus();
m_pass1=m_pass2="";
UpdateData(false);
}
else 
{
CString str,temp;
_variant_t ra;
int k=m_combo.GetCurSel();//得到下拉列表中选中该项的位置
m_combo.GetLBText(k,temp);//得到对应位置的内容保存在temp中
int temp1 = atoi(temp);
str.Format("insert into password values('%s','%s','%d')",m_name,m_pass1,temp1);
//m_pConnection->Execute(str.AllocSysString(),&ra,adCmdText);
m_pConnection->Execute(_bstr_t(str),&ra,adCmdText);
showdata();
MessageBox("用戶添加成功!");


m_name=m_pass1=m_pass2="";
UpdateData(false);
//return ;
}
}

void USERDLG::OnDeluser() 
{
UpdateData();
if(MessageBox("确定删除?","注意",MB_YESNO)==IDYES)
{
if(m_list.GetCurSel()==-1)
{
MessageBox("请选择用户!");
GetDlgItem(IDC_OLDPASS)->SetFocus();
return ;
}
CString temp,temp1;
_variant_t ra;
int k=m_list.GetCurSel();
m_list.GetText(k,temp);
int mmm;
mmm=temp.GetLength();
temp1=temp.Left(mmm-8);
CString str;
str.Format("delete from password where name='%s'",temp1);
//str.Format("delete from password where name='%s'",m_name);
//m_pConnection->Execute(str.AllocSysString(),&ra,adCmdText);
m_pConnection->Execute(str.AllocSysString(),&ra,adCmdText);
//m_pConnection->Execute(_bstr_t(str),&ra,adCmdText);
MessageBox("删除成功!");
showdata();
}

}

BOOL USERDLG::OnInitDialog() 
{
CDialog::OnInitDialog();

m_combo.InsertString(0,"管理员");
m_combo.InsertString(1,"录入员");
m_combo.SetCurSel(0);
try
{
HRESULT hr = m_pConnection.CreateInstance("ADODB.Connection");//创建Connection对象
if(SUCCEEDED(hr))
{
hr = m_pConnection->Open("driver={SQL Server};Server=.;DATABASE=abao;UID=sa;PWD=","","",adModeUnknown);
}
}
catch (_com_error e) //COM错误取得,当执行COM功能的时候,如果出错,可以捕捉到_com_error的异常
{  
CString strComError;
strComError.Format("错误编号: %08lx\n错误信息: %s\n错误源: %s\n错误描述: %s",
e.Error(), // 错误编号
e.ErrorMessage(), // 错误信息
(LPCSTR) e.Source(), // 错误源
(LPCSTR) e.Description()); // 错误描述  

::MessageBox(NULL,strComError,"错误",MB_ICONEXCLAMATION);
}

showdata();
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSErty Pages should return FALSE
}


void USERDLG::showdata()
{
m_list.ResetContent();
CString user,password,power,temp;
m_pRecordset.CreateInstance("ADODB.Recordset");
  m_pRecordset->Open("SELECT * FROM password",_variant_t((IDispatch*)m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText);  
int k=0;
while(!m_pRecordset->adoEOF)
{
user=m_pRecordset->GetCollect("name").bstrVal;
password=m_pRecordset->GetCollect("password").bstrVal;
power=m_pRecordset->GetCollect("userright").bstrVal;
temp=user+"["+power+"]";
m_list.InsertString(k,temp);
m_pRecordset->MoveNext();
k++;
}
}


[解决办法]
自己调试,找出运行异常行号再来问
[解决办法]
是不是用户的权限不对啊?
你调一下这段代码:
if(m_tree.GetItemText(hselItem)=="用户管理")
{
if(userright==0)
{

USERDLG mydlg;
mydlg.DoModal();
return;
}
else
{
AfxMessageBox("您是录入员,没有此权限!");
return;
}
}

看看问题是不是出在这儿

热点排行