⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 userdlg.cpp

📁 (1)学生信息的输入
💻 CPP
字号:
// USERDLG.cpp : implementation file
//

#include "stdafx.h"
#include "lxy.h"
#include "USERDLG.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern CString users,powers,pass;
/////////////////////////////////////////////////////////////////////////////
// USERDLG dialog


USERDLG::USERDLG(CWnd* pParent /*=NULL*/)
	: CDialog(USERDLG::IDD, pParent)
{
	//{{AFX_DATA_INIT(USERDLG)
	m_users = _T("");
	m_pass1 = _T("");
	m_pass2 = _T("");
	m_oldpass = _T("");
	m_newpass1 = _T("");
	m_newpass2 = _T("");
	//}}AFX_DATA_INIT
}


void USERDLG::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(USERDLG)
	DDX_Control(pDX, IDC_LIST1, m_list);
	DDX_Control(pDX, IDC_COMBO1, m_combo);
	DDX_Text(pDX, IDC_EDIT1, m_users);
	DDX_Text(pDX, IDC_EDIT3, m_pass1);
	DDX_Text(pDX, IDC_EDIT4, m_pass2);
	DDX_Text(pDX, IDC_EDIT5, m_oldpass);
	DDX_Text(pDX, IDC_EDIT6, m_newpass1);
	DDX_Text(pDX, IDC_EDIT7, m_newpass2);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(USERDLG, CDialog)
	//{{AFX_MSG_MAP(USERDLG)
	ON_BN_CLICKED(IDC_AD, OnAd)
	ON_BN_CLICKED(IDC_DE, OnDe)
	ON_BN_CLICKED(IDC_modofi, Onmodofi)
	ON_BN_CLICKED(IDC_help, Onhelp)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

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

BOOL USERDLG::OnInitDialog() 
{  
	CDialog::OnInitDialog();
/////////////////////////////////////////////////////////////////////////////	
    m_combo.InsertString(0,"管理员");
    m_combo.InsertString(1,"录入员");
	m_combo.SetCurSel(0);
	pdb=new CDatabase;
	m_pSet=new PASSSet(pdb);
	m_pSet->Open();
	sbstr.Format("select  * from  pass");
	if(powers=="录入员")
		{ GetDlgItem(IDC_AD)->EnableWindow(false);  
			GetDlgItem(IDC_DE)->EnableWindow(false); 
		}	
	show();
/////////////////////////////////////////////////////////////////////////////	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}
void USERDLG::show()
{ 	m_list.ResetContent();
	/////////////////////////////////////////////////////////
    if(m_pSet->IsOpen())
		m_pSet->Close();
    m_pSet->Open(AFX_DB_USE_DEFAULT_TYPE,sbstr);
	int i=0;
	while(!m_pSet->IsEOF())
	{
		CString str;
		str.Format("%s[%s]",m_pSet->m_users,m_pSet->m_powers);
		m_list.InsertString(i,str);
		i++;
		m_pSet->MoveNext();
		
	}
	m_list.SetCurSel(0);
}

void USERDLG::OnAd() 
{	UpdateData();
CString str,temp;
   if(m_users.IsEmpty()||m_pass1.IsEmpty()||m_pass2.IsEmpty())
		   AfxMessageBox("用户信息不完整,请重新填写!");		 
	else		 if(m_pass1==m_pass2) 
				  {
					int k=m_combo.GetCurSel();
					m_combo.GetLBText(k,temp);
					str.Format("insert into pass values ('%s','%s','%s')",m_users,m_pass1,temp);
						pdb->ExecuteSQL(str);
						m_pSet->Requery();
						m_pSet->MoveLast();
						show();
						AfxMessageBox("添加成功!");


				  }
			  else 	AfxMessageBox("两次密码不一致,添加失败!");
					
    m_users=m_pass1=m_pass2="";
	UpdateData(false);
  }

void USERDLG::OnDe() 
{
	int k,m;
	CString temp,temp1,str;
	k=m_list.GetCurSel();
	m_list.GetText(k,temp);
	m=temp.GetLength();
	m=m-18;
	temp1=temp.Left(m);
	
	   if(AfxMessageBox("是否删除?",MB_YESNO) == IDYES)
	   {
		   str.Format("delete from pass where users='%s'",temp1);
		   pdb->ExecuteSQL(str);
		   m_pSet->Requery();
		   AfxMessageBox("删除成功!");
		   show();
	   }
}

void USERDLG::Onmodofi() 
{UpdateData();
		int k,m;
	CString temp,temp1,str,sbs,sbc;
	k=m_list.GetCurSel();
	m_list.GetText(k,temp);
	m=temp.GetLength();
	m=m-18;
	temp1=temp.Left(m);		
	 if(m_pSet->IsOpen())
		m_pSet->Close();
    m_pSet->Open(AFX_DB_USE_DEFAULT_TYPE,sbstr);
	while(!m_pSet->IsEOF())
		{if(m_pSet->m_users==temp1)
			{	sbs=m_pSet->m_pass;break;}	
		 m_pSet->MoveNext();
		}
   m_oldpass.TrimRight();
	sbs.TrimRight();
	if(sbs!=m_oldpass)
			AfxMessageBox("初始密码错误");
		else if(m_newpass1!=m_newpass2)
				AfxMessageBox("密码不一致");
			else
			{
				str.Format("update pass set pass='%s'  where users='%s'",m_newpass1,temp1);
				pdb->ExecuteSQL(str);
		        m_pSet->Requery();
				AfxMessageBox("修改成功");
			}
	m_oldpass=m_newpass1=m_newpass2="";
	UpdateData(false);
}

void USERDLG::Onhelp() 
{
	CString sPath ;
	int nPos;
	GetModuleFileName(NULL,sPath.GetBufferSetLength (MAX_PATH+1),MAX_PATH);
	nPos=sPath.ReverseFind('\\');
	sPath=sPath.Left(nPos);
nPos=sPath.ReverseFind('\\');
	sPath=sPath.Left(nPos);
	ShellExecute(NULL,NULL,_T("help.doc"),NULL,_T(sPath),NULL);	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -