the edit text.
}
else
return;
m_pRecordset->Update();
}
catch(_com_error e)///捕捉异常
{
CString temp;
temp.Format("删除用户出错:%s",e.ErrorMessage());
AfxMessageBox(temp);
return;
}
}
}
void CUserDlg::OnButtonUsave()
{
CString sql="select * from USERS";
CString temp,snewid,spower;
CString name,sdiscount;
_RecordsetPtr m_pRecordset;
UpdateData();
//检查数据完整性
if(m_username.IsEmpty()||m_logname.IsEmpty()||m_upwd.IsEmpty())
{
AfxMessageBox("请输入、登录名称和密码!");
return;
}
m_oUsername.GetWindowText(name);//Get the current text in edit.
if(AfxMessageBox("保存修改吗?",MB_YESNO)==IDYES)
{
int sex=m_oSex.GetCurSel();
if(sex==0) m_sex="0";
if(sex==1) m_sex="1";
m_oDiscount.GetWindowText(sdiscount);
if(m_oCheck1.GetCheck()==1)
spower="[Basedoc]";
if(m_oCheck2.GetCheck()==1)
spower=spower+"[Stat]";
if(m_oCheck3.GetCheck()==1)
spower=spower+"[Sysmain]";
if(m_oCheck4.GetCheck()==1)
spower=spower+"[RF]";
if(m_oCheck5.GetCheck()==1)
spower=spower+"[DelBill]";
if(m_oCheck6.GetCheck()==1)
spower=spower+"[CallBill]";
if(m_oCheck7.GetCheck()==1)
spower=spower+"[Deldata]";
if(m_oCheck8.GetCheck()==1)
spower=spower+"[Hang]";
if(m_oCheck9.GetCheck()==1)
spower=spower+"[Recheck]";
if(lNewID>atol(suserid))
{
snewid.Format("%d",lNewID);
if(bRepeat(name)==TRUE)
{
AfxMessageBox("用户名重复,请重新输入!");
return;
}
try
{
m_pRecordset.CreateInstance("ADODB.Recordset");
m_pRecordset->Open((_variant_t)
sql,_variant_t((IDispatch*)theApp.m_pConnection,true),adOpenStatic,adLockOpti
mistic,adCmdText);
m_pRecordset->AddNew();//insert the current into database.
m_pRecordset->PutCollect("ID",_variant_t(snewid));
m_pRecordset->PutCollect("NAME",_variant_t(m_username));
m_pRecordset->PutCollect("LOGINID",_variant_t(m_logname));
m_pRecordset->PutCollect("PSD",_variant_t(m_upwd));
m_pRecordset->PutCollect("TITLE",_variant_t(m_duty));
m_pRecordset->PutCollect("SEX",_variant_t(m_sex));
m_pRecordset->PutCollect("DATEBIRTH",_variant_t(m_datebirth));
m_pRecordset->PutCollect("HOME",_variant_t(m_jiguan));
m_pRecordset->PutCollect("EMPLOYNUMBER",_variant_t(m_number));
m_pRecordset->PutCollect("DISCOUNT",_variant_t(sdiscount));
m_pRecordset->PutCollect("POWER",_variant_t(spower));
m_pRecordset->Update();//保存到库中
m_oListuser.AddString(m_username);
m_oListuser.SelectString(-1,m_username);
m_pRecordset->Close();
UpdateData(FALSE);
}
catch(_com_error e)///捕捉异常
{
CString temp;
temp.Format("保存用户资料出错:%s",e.ErrorMessage());
AfxMessageBox(temp);
return;
}
}
else
{
_variant_t RecordsAffected;
if(sdiscount=="")
sdiscount="0";
sql="Update USERS set NAME='"+m_username+
"',LOGINID='"+m_logname+
"',PSD='"+m_upwd+
"',TITLE='"+m_duty+
"',SEX='"+m_sex+
"',DATEBIRTH='"+m_datebirth+
"',HOME='"+m_jiguan+
"',EMPLOYNUMBER='"+m_number+
"',DISCOUNT="+sdiscount+
",POWER='"+spower+"' where ID="+suserid+"";
try
{
theApp.m_pConnection->Execute((_bstr_t)sql,&RecordsAffected,adCmdText);
ReadToListbox();
UpdateData(FALSE);
}
catch(_com_error e)///捕捉异常
{
CString temp;
temp.Format("修改用户资料出错:%s",e.ErrorMessage());
AfxMessageBox(temp);
return;
}
}
}
}
void CUserDlg::OnSelchangeListUser() //Read selected user info into controls.
{
CString stemp,sql,sex,spower;
int iOption;
_RecordsetPtr m_pRecordset;
m_oCheck1.SetCheck(0);
m_oCheck2.SetCheck(0);
m_oCheck3.SetCheck(0);
m_oCheck4.SetCheck(0);
m_oCheck5.SetCheck(0);
m_oCheck6.SetCheck(0);
m_oCheck7.SetCheck(0);
m_oCheck8.SetCheck(0);
m_oCheck9.SetCheck(0);
iOption = m_oListuser.GetCurSel();
m_oListuser.GetText(iOption, stemp);//得到选中项的文本
sql="select * from USERS where NAME='"+