【VC开源代码栏目提醒】:网学会员在VC开源代码频道为大家收集整理了DialogUsers.cpp提供大家参考,希望对大家有所帮助!
// DialogUsers.cpp : implementation file
//
#include "stdafx.h"
#include "a1.h"
#include "DialogUsers.h"
#include "myfunction.h"
#include "Crypt.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CDialogUsers dialog
CDialogUsers::CDialogUsers(CWnd* pParent /*=NULL*/)
: CDialog(CDialogUsers::IDD, pParent)
{
//{{AFX_DATA_INIT(CDialogUsers)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
void CDialogUsers::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDialogUsers)
DDX_Control(pDX, IDC_EDIT3, m_editMM2);
DDX_Control(pDX, IDC_EDIT2, m_editMM1);
DDX_Control(pDX, IDC_EDIT1, m_editName);
DDX_Control(pDX, IDC_COMBO1, m_comboPurview);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDialogUsers, CDialog)
//{{AFX_MSG_MAP(CDialogUsers)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDialogUsers message handlers
BOOL CDialogUsers::OnInitDialog()
{
CDialog::OnInitDialog();
LRunSql m_runsql;
CString sql;
_variant_t value;
/* int i=0;
sql.Format("select * from tabpurview");
if(!m_runsql.CheckSQLResult(sql))
{
this->EndDialog(0);
return false;
}
while(!m_runsql.m_recordset->adoEOF)
{
value=m_recordset->GetCollect("admi_purview");
this->m_comboPureview.InsertString(i,(char*)(_bstr_t)value);
m_runsql.m_recordset->MoveNext();
i++;
}*/
this->m_comboPurview.InsertString(0,"超级用户");
this->m_comboPurview.InsertString(1,"管理员");
this->m_comboPurview.InsertString(2,"标准用户");
this->m_comboPurview.InsertString(3,"一般用户");
this->m_comboPurview.SetCurSel(3);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CDialogUsers::OnOK()
{
HWND hwnd=this->GetFocus()->GetSafeHwnd();
if(hwnd==this->m_editName.GetSafeHwnd())
{
this->m_editMM1.SetFocus();
return;
}
else if(hwnd==this->m_editMM1.GetSafeHwnd())
{
this->m_editMM2.SetFocus();
return;
}
else if(hwnd==this->m_editMM2.GetSafeHwnd())
{
this->m_comboPurview.SetFocus();
return;
}
CString m_sNewPW1,m_sNewPW2;
this->m_editMM1.GetWindowText(m_sNewPW1);
this->m_editMM2.GetWindowText(m_sNewPW2);
LRunSql m_runsql;
CString sql;
CString name;
int purview=m_comboPurview.GetCurSel();
this->m_editName.GetWindowText(name);
if(name=="")
{
MessageBox("用户名不可为空");
m_editName.SetFocus();
return;
}
if(m_sNewPW1!=m_sNewPW2)
{
MessageBox("请确认密码相同");
m_editMM2.SetFocus();
return;
}
else
{
try{
sql.Format("select * from tabpurview where admi_name = '%s'"
,name);
if(m_runsql.CheckSQLResult(sql))
{
MessageBox("请换一个用户名,该用户名已被注册");
return;
}
CString s_password=CCrypt::Encrypt(m_sNewPW2);
sql.Format("insert into tabpurview(admi_name,admi_password,admi_purview) values('%s','%s',%d)"
,name,s_password,purview);
m_runsql.RunSQL(sql);
}
catch(_com_error& e)
{
AfxMessageBox(e.ErrorMessage());
return ;
}
MessageBox("成功添加新用户!","医药管理系统");
this->m_strName=name;
this->m_comboPurview.GetWindowText(m_strPurview);
}
CDialog::OnOK();
}