UserSet.cpp
上传用户:yffx2008
上传日期:2014-10-12
资源大小:12414k
文件大小:3k
- // UserSet.cpp : implementation file
- //
- #include "stdafx.h"
- #include "gpssc.h"
- #include "UserSet.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CUserSet
- extern CGpsSCApp theApp;
- IMPLEMENT_DYNAMIC(CUserSet, CRecordset)
- CUserSet::CUserSet(CDatabase* pdb)
- : CRecordset(pdb)
- {
- //{{AFX_FIELD_INIT(CUserSet)
- m_user = _T("");
- m_Password = _T("");
- m_UserType = _T("");
- m_nFields = 3;
- //}}AFX_FIELD_INIT
- m_nDefaultType = snapshot;
- }
- CString CUserSet::GetDefaultConnect()
- {
- return _T("ODBC;DSN=CenterDataBase");
- }
- CString CUserSet::GetDefaultSQL()
- {
- return _T("[_User]");
- }
- void CUserSet::DoFieldExchange(CFieldExchange* pFX)
- {
- //{{AFX_FIELD_MAP(CUserSet)
- pFX->SetFieldType(CFieldExchange::outputColumn);
- RFX_Text(pFX, _T("[user]"), m_user);
- RFX_Text(pFX, _T("[Password]"), m_Password);
- RFX_Text(pFX, _T("[UserType]"), m_UserType);
- //}}AFX_FIELD_MAP
- }
- /////////////////////////////////////////////////////////////////////////////
- // CUserSet diagnostics
- #ifdef _DEBUG
- void CUserSet::AssertValid() const
- {
- CRecordset::AssertValid();
- }
- void CUserSet::Dump(CDumpContext& dc) const
- {
- CRecordset::Dump(dc);
- }
- #endif //_DEBUG
- void CUserSet::EditPassword(CString strUser,CString strPassword)
- {
- try
- {
- CString _SQL = "SELECT * FROM _User WHERE UserName='"+strUser+"'";
- if(!IsOpen())
- Open(AFX_DB_USE_DEFAULT_TYPE,_SQL);
- if(!IsEOF())
- {
- Edit();
- m_Password = strPassword;
- Update();
- }
- Close();
- }
- catch(CDBException *Exp)
- {
- Close();
- AfxMessageBox(Exp->m_strError);
- }
- }
- BOOL CUserSet::CheckLogin(CString strUser,CString strPassWord)
- {
- try
- {
- if(strUser=="来宾")
- {
- theApp.m_bUserType = false;
- return TRUE;
- }
- CString _SQL = "SELECT * FROM _User WHERE UserName='"+strUser+"' And Password='"+strPassWord+"'";
- if(!IsOpen())
- Open(AFX_DB_USE_DEFAULT_TYPE,_SQL);
- if(!IsEOF())
- {
- theApp.m_bUserType = true;
- return TRUE;
- }
- Close();
- }
- catch(CDBException *Exp)
- {
- Close();
- AfxMessageBox(Exp->m_strError);
- }
- return FALSE;
- }
- BOOL CUserSet::CheckOldPassword(CString strUser,CString strPassword)
- {
- try
- {
- CString _SQL = "SELECT * FROM _User WHERE UserName='"+strUser+"' And Password='"+strPassword+"'";
- if(!IsOpen())
- Open(AFX_DB_USE_DEFAULT_TYPE,_SQL);
- if(!IsEOF())
- {
- return TRUE;
- }
- Close();
- }
- catch(CDBException *Exp)
- {
- Close();
- AfxMessageBox(Exp->m_strError);
- }
- return FALSE;
- }
- void CUserSet::LoadUser(CTreeCtrl &m_CtrlTree,HTREEITEM hTreeItem)
- {
- try
- {
- CString _SQL("SELECT * FROM _User ORDER BY UserType");
- if (!IsOpen())
- {
- Open(AFX_DB_USE_DEFAULT_TYPE,_SQL);
- }
- if (!IsEOF())
- {
- MoveFirst();
- }
- while (!IsEOF())
- {
- m_CtrlTree.InsertItem(m_user,hTreeItem);
- MoveNext();
- }
- Close();
- }
- catch(CDBException *Exp)
- {
- Close();
- AfxMessageBox(Exp->m_strError);
- }
- }