www.gusucode.com > VC++编写的SQL服务端和客户端源码程序 > VC++编写的SQL服务端和客户端源码程序\code\Server\LogDlg.cpp
// LogDlg.cpp : implementation file // Download by http://www.NewXing.com #include "stdafx.h" #include "miniSQL.h" #include "LogDlg.h" #include "UserDoc.h" #include "Error.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif extern CMiniSQLApp theApp; ///////////////////////////////////////////////////////////////////////////// // CLogDlg dialog CLogDlg::CLogDlg(CWnd* pParent /*=NULL*/) : CDialog(CLogDlg::IDD, pParent) { //{{AFX_DATA_INIT(CLogDlg) m_code = _T(""); m_user = _T(""); //}}AFX_DATA_INIT } void CLogDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CLogDlg) DDX_Text(pDX, IDC_EDIT_CODE, m_code); DDV_MaxChars(pDX, m_code, 16); DDX_Text(pDX, IDC_EDIT_USER, m_user); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CLogDlg, CDialog) //{{AFX_MSG_MAP(CLogDlg) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CLogDlg message handlers DWORD CLogDlg::GetType() { if( m_user == _T("admin") && m_code == _T("admin") ) { NoUserData(); return LOG_ADMIN; } else if( m_user == _T("superuser") && m_code == _T("superuser") ) { NoUserData(); return LOG_SUPERUSER; } else if( m_user == _T("user") && m_code == _T("user") ) { NoUserData(); return LOG_USER; } else { CFileStatus status; CString path( theApp.dir ); path += "\\user.dat"; if( CFile::GetStatus( path, status ) ) { CFile File( path, CFile::modeRead ); CArchive ar( &File, CArchive::load ); int length = 0; ar>>length; for( int i = 0; i < length; i++ ) { CUser user; user.Serialize( ar ); if( m_user == user.m_user && m_code == user.m_code ) return user.m_type; } return 0; } else { CFile File( path, CFile::modeCreate | CFile::modeWrite ); CArchive ar( &File, CArchive::store ); int length = 0; ar<<length<<'\0'; return 0; } } } void CLogDlg::EndDialog( int nResult ) { CDialog::EndDialog( nResult ); UpdateData(); } void CLogDlg::NoUserData() { CFileStatus status; CString path( theApp.dir ); path += "\\user.dat"; if( !CFile::GetStatus( path, status ) ) { CFile File( path, CFile::modeCreate | CFile::modeWrite ); CArchive ar( &File, CArchive::store ); int length = 0; ar<<length<<'\0'; } }