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

📄 logindlg.cpp

📁 通讯录
💻 CPP
字号:
// LoginDlg.cpp : implementation file
//

#include "stdafx.h"
#include "AddressList.h"
#include "LoginDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CLoginDlg dialog


CLoginDlg::CLoginDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CLoginDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CLoginDlg)
	m_name = _T("");
	m_pwd = _T("");
	m_repwd = _T("");
	m_purview = -1;
	//}}AFX_DATA_INIT
}


void CLoginDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CLoginDlg)
	DDX_Control(pDX, IDC_RADIO_purview0, m_ctrpur);
	DDX_Control(pDX, IDC_STATIC_purview, m_ctrSPur);
	DDX_Text(pDX, IDC_EDIT_NAME, m_name);
	DDX_Text(pDX, IDC_EDIT_PWD, m_pwd);
	DDX_Text(pDX, IDC_EDIT_REPWD, m_repwd);
	DDX_Radio(pDX, IDC_RADIO_purview0, m_purview);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CLoginDlg, CDialog)
	//{{AFX_MSG_MAP(CLoginDlg)
	ON_BN_CLICKED(IDC_BUTTON_OK, OnButtonOk)
	ON_BN_CLICKED(IDC_BUTTON_LOOK, OnButtonLook)
	ON_BN_CLICKED(IDC_BUTTON_CANCEL, OnButtonCancel)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CLoginDlg message handlers

BOOL CLoginDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	
	if(m_purview == 0)
	{
	
		m_ctrSPur.ShowWindow(1);
	}
	else
	{
		CButton *bt;
		bt=(CButton *)GetDlgItem(IDC_RADIO_purview0);
		bt->ShowWindow(1);
		//bt->set
		bt=(CButton *)GetDlgItem(IDC_RADIO_purview1);
		bt->ShowWindow(1);
	}

	m_pCon.CreateInstance(__uuidof(Connection));
	m_pCon->Open("driver={SQL Server};Server=192.168.1.13;DATABASE=AddressList","sa","sa",adModeUnknown);
	m_pCon->CursorLocation = adUseClient;
	m_pSet.CreateInstance(__uuidof(Recordset));
	m_pSet->Open("AL_User",m_pCon.GetInterfacePtr(),adOpenDynamic,adLockOptimistic,adCmdTable);
	
	s = true;
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CLoginDlg::OnButtonOk() 
{
	// TODO: Add your control notification handler code here
	UpdateData(true);

	//检查输入的规范
	if(m_name == "")
	{
		MessageBox("用户名不能为空!");
		return;
	}
	if(!m_pwd == m_repwd)
	{
		MessageBox("密码不一致!");
		return;
	}
	//在数据库中查重
	s = false;
	if(OnButtonLook())
	{
		return;
	}
	//写入数据库中
	CString strSQL;
	strSQL.Format("insert into AL_User values('%s','%s','%i')",m_name,m_pwd,m_purview);
	m_pCon->Execute((_bstr_t)strSQL,0,adCmdText);
	CDialog::OnOK();
}

bool CLoginDlg::OnButtonLook() 
{
	// TODO: Add your control notification handler code here
	UpdateData(true);

		if(m_name == "")
	{
		MessageBox("用户名不能为空!");
		return true;
	}
		m_pSet->MoveFirst();
		CString strPwd;
		CString strUs;
		while(!m_pSet->adoEOF)
		{
			strUs = (LPCTSTR)(_bstr_t)m_pSet->GetCollect("user");

			if(m_name == strUs) 
			{
				MessageBox("用户名已存在!");
				return true;//true为存在
			}
			m_pSet->MoveNext();
			
		}
		if(s)
		MessageBox("此用户名不存在!可以申请");
		return false;//不存在

		//m_pSet->Find((_bstr_t)("us=" + m_name),0,adSearchForward);

	
}

void CLoginDlg::OnButtonCancel() 
{
	// TODO: Add your control notification handler code here
	CDialog::OnCancel();
}

⌨️ 快捷键说明

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