📄 studentdlg.cpp
字号:
// StudentDlg.cpp : implementation file
//
#include "stdafx.h"
#include "Student.h"
#include "StudentDlg.h"
#include "oldpass.h"
#include "frmmain.h"
#include "HtmlHelp.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern CStudentApp theApp;
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
//DEL CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
//DEL {
//DEL //{{AFX_DATA_INIT(CAboutDlg)
//DEL //}}AFX_DATA_INIT
//DEL }
//DEL void CAboutDlg::DoDataExchange(CDataExchange* pDX)
//DEL {
//DEL CDialog::DoDataExchange(pDX);
//DEL //{{AFX_DATA_MAP(CAboutDlg)
//DEL //}}AFX_DATA_MAP
//DEL }
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CStudentDlg dialog
CStudentDlg::CStudentDlg(CWnd* pParent /*=NULL*/)
: CDialog(CStudentDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CStudentDlg)
m_sServer = _T("");
m_sUser = _T("");
m_sPassword = _T("");
m_sDbase = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CStudentDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CStudentDlg)
DDX_Control(pDX, IDC_TRUE, m_bTrue);
DDX_Text(pDX, IDC_SERVER, m_sServer);
DDX_Text(pDX, IDC_USER, m_sUser);
DDX_Text(pDX, IDC_PASSWORD, m_sPassword);
DDX_Text(pDX, IDC_DBASE, m_sDbase);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CStudentDlg, CDialog)
//{{AFX_MSG_MAP(CStudentDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_TRUE, OnTrue)
ON_EN_CHANGE(IDC_USER, OnChangeUser)
ON_EN_CHANGE(IDC_SERVER, OnChangeServer)
ON_EN_CHANGE(IDC_PASSWORD, OnChangePassword)
ON_EN_CHANGE(IDC_DBASE, OnChangeDbase)
ON_COMMAND(ID_SETPASSWORD, OnSetpassword)
ON_COMMAND(ID_EXIT, OnExit)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CStudentDlg message handlers
BOOL CStudentDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
m_sServer="bbts_sql";
m_sUser="zhangmin";
m_sPassword="1977";
m_sDbase="study";
UpdateData(FALSE);
//使确定按钮无效
//m_bTrue.EnableWindow(FALSE);
return TRUE; // return TRUE unless you set the focus to a control
}
void CStudentDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
// CAboutDlg dlgAbout;
// dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CStudentDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CStudentDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CStudentDlg::OnTrue()
{
///读取自段值
/*m_pRecordset.CreateInstance("ADODB.Recordset");
m_pRecordset->Open("select * from users",m_sUser,theApp.m_pConnect.GetInterfacePtr(),adOpenStatic,adLockOptimistic,adCmdText);
if(!m_pRecordset->adoEOF)
{
_variant_t User=m_pRecordset->GetCollect("username");
_variant_t Password=m_pRecordset->GetCollect("Password");
m_sUser=(LPCTSTR)(_bstr_t)User;
m_sPassword=(LPCTSTR)(_bstr_t)Password;
UpdateData(FALSE);
}
m_pRecordset->Close();*/
///////
/*_variant_t RecordsAffected;
try
{
theApp.m_pConnect->Execute(("select username from users where username==%s",(_bstr_t)m_sUser),&RecordsAffected,adCmdText);
*/
HRESULT hr;
char buf[100];
try
{
UpdateData(TRUE);
hr=theApp.m_pConnect.CreateInstance("ADODB.Connection");
sprintf(buf,"Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=study;Data Source=%s",m_sServer);
if(SUCCEEDED(hr))
{
hr=theApp.m_pConnect->Open(buf,"","",-1);
}
m_pRecordset.CreateInstance("ADODB.Recordset");
sprintf(buf,"select * from users where Username like \'%s\'",m_sUser);
m_pRecordset->Open(_variant_t(buf),theApp.m_pConnect.GetInterfacePtr(),adOpenStatic,adLockOptimistic,adCmdText);
if(m_pRecordset->adoEOF)
{
MessageBox("用户名不对!");
m_sUser="";
UpdateData(FALSE);
return;
}
m_pRecordset->Close();
sprintf(buf,"select * from users where Password like \'%s\'",m_sPassword);
m_pRecordset->Open(_variant_t(buf),theApp.m_pConnect.GetInterfacePtr(),adOpenStatic,adLockOptimistic,adCmdText);
if(m_pRecordset->adoEOF)
{
MessageBox("密码不对!");
m_sPassword="";
UpdateData(FALSE);
return;
}
m_pRecordset->Close();
theApp.m_sUserName=m_sUser;
//ShowWindow(SW_HIDE);
CStudentDlg::OnOK();
CFrmMain mainDlg;
mainDlg.DoModal();
}
catch(_com_error e)
{
AfxMessageBox(e.ErrorMessage());
}
}
void CStudentDlg::OnChangeUser()
{
//UpdateData(TRUE);
}
void CStudentDlg::EnableTrue()
{
if(!m_sUser.IsEmpty() && !m_sServer.IsEmpty() && !m_sDbase.IsEmpty())
{
m_bTrue.EnableWindow(TRUE);
//m_bTrue.SetFocus();
}
else
{
m_bTrue.EnableWindow(FALSE);
}
}
void CStudentDlg::OnChangeServer()
{
// UpdateData(TRUE);
EnableTrue();
}
void CStudentDlg::OnChangePassword()
{
// UpdateData(TRUE);
EnableTrue();
}
void CStudentDlg::OnChangeDbase()
{
// UpdateData(TRUE);
EnableTrue();
}
void CStudentDlg::WriteRegTable()
{
}
void CStudentDlg::OnSetpassword()
{
COldPass dlg;
dlg.DoModal();
}
void CStudentDlg::OnCancel()
{
// TODO: Add extra cleanup here
CDialog::OnCancel();
}
void CStudentDlg::OnExit()
{
exit(0);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -