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

📄 logon.cpp

📁 出差管理系统,是利用VC开发一个简单的,管理出差记录及出差发票报销记录的程序,目的是避免人工烦琐的管理工作.
💻 CPP
字号:
// Logon.cpp : implementation file
//

#include "stdafx.h"
#include "cc.h"
#include "Logon.h"

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

/////////////////////////////////////////////////////////////////////////////
// CLogon dialog
extern CCcApp theApp;

CLogon::CLogon(CWnd* pParent /*=NULL*/)
	: CDialog(CLogon::IDD, pParent)
{
	//{{AFX_DATA_INIT(CLogon)
	m_user = _T("");
	m_pwd = _T("");
	//}}AFX_DATA_INIT
}


void CLogon::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CLogon)
	DDX_Control(pDX, IDC_COMBO1, m_1);
	DDX_CBString(pDX, IDC_COMBO1, m_user);
	DDX_Text(pDX, IDC_EDIT1, m_pwd);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CLogon, CDialog)
	//{{AFX_MSG_MAP(CLogon)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CLogon message handlers

void CLogon::OnOK() 
{
	// TODO: Add extra validation here
	UpdateData();
	//如果用户名和密码不为空则执行以下操作
	if(!m_user.IsEmpty()&&!m_pwd.IsEmpty())
	{
		//成生sql语句
		m_pwd=theApp.addpwd(m_pwd,true);
		CString sql="SELECT * FROM alluser where name='"+m_user+"' and pwd='"+m_pwd+"'";
		try
		{
			//查询数据库,看是否有此用户和密码
			m_pRecordset.CreateInstance("ADODB.Recordset");
			m_pRecordset->Open((_variant_t)sql,_variant_t((IDispatch*)theApp.m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText);
			//如果没有此用户和密码,再查询是否有此用户
			if(m_pRecordset->adoEOF)
			{
				m_pRecordset->Close();
				sql="select name from alluser where name='"+m_user+"'";
				try
				{
					m_pRecordset.CreateInstance("ADODB.Recordset");
					m_pRecordset->Open((_variant_t)sql,_variant_t((IDispatch*)theApp.m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText);
					//如果没有此用户,则提示叫用户建立此用户。
					if(m_pRecordset->adoEOF)
					{
						if(AfxMessageBox("用户名或密码错误!你想新建此用户吗?",MB_YESNO)==IDYES)
						{
							m_pRecordset->Close();
							sql="insert into alluser (name,pwd) values('"+m_user+"','"+m_pwd+"')";
							_variant_t RecordsAffected;
							theApp.m_pConnection->Execute((_bstr_t)sql,&RecordsAffected,adCmdText);
							AfxMessageBox("新用户成功建立!请记住:\n\n用户名:"+m_user+"\n密  码:"+theApp.addpwd(m_pwd,false));
							theApp.name=m_user;
							theApp.pwd=m_pwd;
							CDialog::OnOK();						
						}
						else
							return;
					}
					//如果有,提示错误信息。
					else
					{
						AfxMessageBox("用户名或密码错误!");
						return;
					}
				}
				catch(_com_error e)///捕捉异常
				{
					CString temp;
					temp.Format("连接数据库错误信息:%s",e.ErrorMessage());
					AfxMessageBox(temp);
					return;
				}
			}
			//用户名和密码存在,登录成功
			else
			{
				theApp.name=m_user;
				theApp.pwd=m_pwd;
				CDialog::OnOK();
				return;
			}
		}
		catch(_com_error e)///捕捉异常
		{
			CString temp;
			temp.Format("连接数据库错误信息:%s",e.ErrorMessage());
			AfxMessageBox(temp);
			return;
		}
	}
	//反之则
	else
		AfxMessageBox("请输入用户名和密码!");
}

void CLogon::OnCancel() 
{
	// TODO: Add extra cleanup here
	
	CDialog::OnCancel();
}

BOOL CLogon::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here

	//读出数据库中的用户名,显示在控件中。
	int numline=0;
	CString sql="select name from alluser order by name";
	try
	{
		m_pRecordset.CreateInstance("ADODB.Recordset");
		m_pRecordset->Open((_variant_t)sql,_variant_t((IDispatch*)theApp.m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText);
		if(m_pRecordset->adoEOF)
		{
			;//AfxMessageBox("你的数据库中还没有出差记录信息!");
		}
		else
		{
			while(!m_pRecordset->adoEOF)
			{
				m_1.InsertString(0,(LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("name"));
				sql=(LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("name");
				m_pRecordset->MoveNext();
			}
			SetDlgItemText(IDC_COMBO1,sql);
		}
		m_pRecordset->Close();
	}
	catch(_com_error e)///捕捉异常
	{
		CString temp;
		temp.Format("连接数据库错误信息:%s",e.ErrorMessage());
		AfxMessageBox(temp);
		return false;
	}
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

⌨️ 快捷键说明

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