void CNCUView::OnLogout() {
//退出按钮 int i=MessageBox(\您确定要退出么?\提示消息\ if (i==IDOK) { AfxGetMainWnd()->SendMessage(WM_CLOSE); return; } }
void CNCUView::OnFileSave() { // TODO: Add your command handler code here OnFile(); }
void CNCUView::OnFileOpen() {
//重新连接数据源 if(m_database.IsOpen()) m_database.Close(); m_database.Open(_T(\ m_recordSet.Close(); m_recordSet.m_pDatabase=&m_database; }
void CNCUView::OnFileSaveAs() {
//恢复数据库文件
CString filter,strSQL; CString path;
filter=\数据库文件(*.mdb)|*.mdb||\ CFileDialog
file(true,NULL,NULL,OFN_OVERWRITEPROMPT,filter,this); int i=file.DoModal(); if (i==IDOK) { path=file.GetPathName(); m_database.Close(); CopyFile(path,cPath,FALSE); OpenDB(); }
MessageBox(\成功恢复数据库文件!\}
return;
26
void CNCUView::OnDataBackup() { // TODO: Add your command handler code here
if(AfxMessageBox(\确定要备份数据库?\ { return; } CTime time=time.GetCurrentTime(); int iYear=time.GetYear(); int iMonth=time.GetMonth(); int iDay=time.GetDay(); CString sFileName; sFileName.Format(\ if(CopyFile(cPath,\
AfxMessageBox(\数据库已成功备份到当前databack中!\else
AfxMessageBox(\数据库备份失败!\}
void CNCUView::OnHlp() { // TODO: Add your control notification handler code here ShellExecute(NULL,\WMAXIMIZED);}
void CNCUView::OnBack() { // TODO: Add your control notification handler code here DestoryTab(); m_pic=(CStatic*)GetDlgItem(IDC_STATIC); m_pic->ModifyStyle(NULL,WS_VISIBLE); this->RedrawWindow(); }
Login.cpp
//用户登录界面
void CLogin::OnOK() { // TODO: Add extra validation here CString username,password; m_name.GetWindowText(username);
//////判断用户名是否为空//////////// if(username.IsEmpty()) {
27
MessageBox(\用户名不能为空!\错误\ m_name.SetFocus(); return; }
//////判断密码是否为空///////////// m_password.GetWindowText(password); if(password.IsEmpty()) { MessageBox(\密码不能为空!\错误\ m_password.SetFocus(); return; } OpenDB(); CString strSQL;
/////////////判断有无用户//////// strSQL.Format(\ m_recordSet.Open(CRecordset::forwardOnly,strSQL); if(m_recordSet.GetRecordCount()==0) { MessageBox(\现在系统里和还没有用户,来注册一个吧~~\提示\ m_recordSet.Close(); m_name.SetWindowText(\
m_password.SetWindowText(\清空密码文本框 m_name.SetFocus(); OnNew(); return; }
m_recordSet.Close();
////////验证用户名和密码////// strSQL.Format(\Password='%s'\ m_recordSet.Open(CRecordset::forwardOnly,strSQL);
if(m_recordSet.GetRecordCount()==0)//如果找不到记录 {
MessageBox(\用户名或密码错误,请重新输入\错误\提示密码错误 m_password.SetWindowText(\清空密码文本框 m_password.SetFocus();//设置用户名文本框为当前的焦点 m_recordSet.Close();
28
}
else//如果找到记录 {
m_recordSet.GetFieldValue(\则将用户ID值赋给theUser m_recordSet.Close(); CDialog::OnOK(); } }
New.cpp
//用户注册页面
void CNew::OnOK() { // TODO: Add extra validation here CString
aver,limit,balance,password,username,intype,outtype,temp; m_username.GetWindowText(username); if(username.GetLength()<3) { MessageBox(\用户名太短,至少要多于3个字节。\错误\ m_username.SetFocus(); return; }
////////////////检测用户名是否重复////// OpenDB(); CRecordset rs; rs.m_pDatabase=&m_database; CString strSQL; strSQL.Format(\Name='%s'\
rs.Open(CRecordset::forwardOnly,strSQL); if (rs.GetRecordCount()!=0) {
MessageBox(\貌似你的用户名已经有人用啦,那就换一个吧 -_-\错误\ m_username.SetWindowText(\ m_username.SetFocus(); rs.Close(); return; } rs.Close();
29
/////////////////////////////////////// m_password.GetWindowText(password); if(password.GetLength()<6) {
MessageBox(\为了您的安全,请将密码设为6位以上。\错误\ m_password.SetFocus(); return; }
///////判断密码长度///////////// m_balance.GetWindowText(balance); if(balance.IsEmpty()) {
MessageBox(\为了使系统能够正常工作,请填写帐户初始余额。\提示\ m_balance.SetFocus(); return; } m_aver.GetWindowText(aver); m_limit.GetWindowText(limit); CStringArray ary;
//////////提取InType的所有ID值以便插入新建用户的数据表中//////// strSQL.Format(\ rs.Open(CRecordset::forwardOnly,strSQL); for(int i=0;i 30