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

📄 logindlg.cpp

📁 汽车站售票管理系统,源代码完整无错
💻 CPP
字号:
// LoginDlg.cpp : implementation file
//

#include "stdafx.h"
#include "StationManage.h"
#include "LoginDlg.h"
#include "UserSet.h"
#include "MainFrm.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_password = _T("");
	m_username = _T("");
	//}}AFX_DATA_INIT
}


void CLoginDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CLoginDlg)
	DDX_Control(pDX, IDC_EDIT_USERNAME, m_usernamecontrol);
	DDX_Control(pDX, IDC_EDIT_PASSWORD, m_passwordcontrol);
	DDX_Control(pDX, IDC_COMBO_USERTYPE, m_usertype);
	DDX_Text(pDX, IDC_EDIT_PASSWORD, m_password);
	DDX_Text(pDX, IDC_EDIT_USERNAME, m_username);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CLoginDlg, CDialog)
	//{{AFX_MSG_MAP(CLoginDlg)
	ON_CBN_SELCHANGE(IDC_COMBO_USERTYPE, OnSelchangeComboUsertype)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

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

void CLoginDlg::OnOK() 
{
	// TODO: Add extra validation here
	UpdateData();
	CString str;
	m_usertype.GetWindowText(str);
	if (str!="普通用户"&&str!="售票员"&&str!="管理员")
	{
		MessageBox("请选择用户类型!","警告",MB_OK|MB_ICONEXCLAMATION);
		return;
	}
	if (str=="普通用户")
	{
		CStationManageApp* pt=(CStationManageApp*)AfxGetApp();
		pt->curusername="普通用户";
		CString user="当前用户:身份:"+pt->curusername;
		CMainFrame* pMainFrame = (CMainFrame*)AfxGetMainWnd();
		pMainFrame->m_wndStatusBar.SetPaneText(pMainFrame->m_wndStatusBar.CommandToIndex(ID_CURUSERNAME),user);
		pt->m_changepassword=1;
		pt->m_routesetting=1;
		pt->m_routesettingcontrol=true;

		pt->m_usermanage=1;
		pt->m_usermanagecontrol=true;

		pt->m_seattypesetting=1;
		pt->m_seattypesettingcontrol=true;

		pt->m_pricesetting=1;
		pt->m_pricesettingcontrol=true;

		pt->m_bussetting=1;
		pt->m_bussettingcontrol=true;

		pt->m_driversetting=1;
		pt->m_driversettingcontrol=true;

		pt->m_bustypesetting=1;
		pt->m_bustypesettingcontrol=true;

		pt->m_tickettypesetting=1;
		pt->m_tickettypesettingcontrol=true;

		pt->m_ShouPiaoMingXiViews=1;
		pt->m_ShouPiaoMingXiViewscontrol=true;

		pt->m_ShouPiaoTongJiViews=1;
		pt->m_ShouPiaoTongJiViewscontrol=true;

		pt->m_JieSuanMingXiViews=1;
		pt->m_JieSuanMingXiViewscontrol=true;

		pt->m_JieSuanTongJiViews=1;
		pt->m_JieSuanTongJiViewscontrol=true;

		pt->m_RiBaoBiaoViews=1;
		pt->m_RiBaoBiaoViewscontrol=true;

		pt->m_TuiPiaoXinXiViews=1;
		pt->m_TuiPiaoXinXiViewscontrol=true;

		pt->m_SaleTicketViews = 1;
		pt->m_SaleTicketViewscontrol = true;
		
		pt->m_DispatchViews = 1;
		pt->m_DispatchViewscontrol = true;
		
		pt->m_BackTicketViews = 1;
		pt->m_BackTicketViewscontrol = true;

		CDialog::OnOK();
		return;
	}
	if (str=="售票员"||str=="管理员")
	{
		if (m_password==""||m_username=="")
		{
			MessageBox("用户名或密码不能为空!","警告",MB_OK|MB_ICONEXCLAMATION);
			return;
		}
	}
	CUserSet m_pSet;	
	CString strSQL;	
	if (str=="售票员")
	{
		strSQL.Format("select * from user_pswd where username='%s'and password='%s' and usertype='conductor'",
			m_username,m_password);
		m_pSet.Open(AFX_DB_USE_DEFAULT_TYPE,strSQL);	
		if (m_pSet.GetRecordCount()==0)
		{
			static int count=1;
			if (count<3)
			{
				CString info;
				info.Format("第%d次登录失败,最多只能登录3次",count);
				if (IDOK == MessageBox(info,"警告",MB_OK|MB_ICONEXCLAMATION))
				{
					m_username.Empty();
					m_password.Empty();
					UpdateData(FALSE);
					count++;
					return;
				}				
			}
			else
			{
				if (IDOK == MessageBox("登录次数过多!","警告",MB_OK|MB_ICONEXCLAMATION))
				{
					exit(0);
				}				
			}
		}
		else
		{
			if (IDOK == MessageBox("欢迎您,您是售票员!","登录成功!",MB_OK|MB_ICONINFORMATION))
			{
				m_pSet.Close();
				CStationManageApp* pt=(CStationManageApp*)AfxGetApp();
				m_pSet.m_username.TrimRight();          //去掉后面的空格
				pt->curusername=m_pSet.m_username;
				CString user="当前用户:用户名:"+pt->curusername+" 身份:售票员";
				CMainFrame* pMainFrame = (CMainFrame*)AfxGetMainWnd();
				pMainFrame->m_wndStatusBar.SetPaneText(pMainFrame->m_wndStatusBar.CommandToIndex(ID_CURUSERNAME),user);

				pt->m_changepassword=0;
				pt->m_routesetting=1;
				pt->m_routesettingcontrol=true;
				pt->m_usermanage=1;
				pt->m_usermanagecontrol=true;
				pt->m_seattypesetting=1;
				pt->m_seattypesettingcontrol=true;
				pt->m_pricesetting=1;
				pt->m_pricesettingcontrol=true;
				pt->m_bussetting=1;
				pt->m_bussettingcontrol=true;
				pt->m_driversetting=1;
				pt->m_driversettingcontrol=true;
				pt->m_bustypesetting=1;
				pt->m_bustypesettingcontrol=true;
				pt->m_tickettypesetting=1;
				pt->m_tickettypesettingcontrol=true;
				pt->m_ShouPiaoMingXiViews=1;
				pt->m_ShouPiaoMingXiViewscontrol=true;
				
				pt->m_ShouPiaoTongJiViews=1;
				pt->m_ShouPiaoTongJiViewscontrol=true;
				
				pt->m_JieSuanMingXiViews=1;
				pt->m_JieSuanMingXiViewscontrol=true;
				
				pt->m_JieSuanTongJiViews=1;
				pt->m_JieSuanTongJiViewscontrol=true;
				
				pt->m_RiBaoBiaoViews=1;
				pt->m_RiBaoBiaoViewscontrol=true;
				
				pt->m_TuiPiaoXinXiViews=1;
				pt->m_TuiPiaoXinXiViewscontrol=true;

				pt->m_SaleTicketViews = 0;
				pt->m_SaleTicketViewscontrol = false;
				
				pt->m_DispatchViews = 0;
				pt->m_DispatchViewscontrol = false;
				
				pt->m_BackTicketViews = 0;
				pt->m_BackTicketViewscontrol = false;

				CDialog::OnOK();
				return;
			}
		}
	}

	if (str=="管理员")
	{
		static int count=1;
		strSQL.Format("select * from user_pswd where username='%s'and password='%s' and usertype='admin'",
			m_username,m_password);
		m_pSet.Open(AFX_DB_USE_DEFAULT_TYPE,strSQL);	
		if (m_pSet.GetRecordCount()==0)
		{
			if (count<3)
			{
				CString info;
				info.Format("第%d次登录失败,最多只能登录3次",count);
				if (IDOK == MessageBox(info,"警告",MB_OK|MB_ICONEXCLAMATION))
				{
					m_username.Empty();
					m_password.Empty();
					UpdateData(FALSE);
					count++;
					return;
				}				
			}
			else
			{
				if (IDOK == MessageBox("登录次数过多!","警告",MB_OK|MB_ICONEXCLAMATION))
				{
					exit(0);
				}				
			}
		}
		else
		{
			if (IDOK == MessageBox("欢迎您,您是管理员!","登录成功!",MB_OK|MB_ICONINFORMATION))
			{
				m_pSet.Close();
				CStationManageApp* pt=(CStationManageApp*)AfxGetApp();
				m_pSet.m_username.TrimRight();          //去掉后面的空格
				pt->curusername=m_pSet.m_username;
				CString user="当前用户:用户名:"+pt->curusername+" 身份:管理员";
				CMainFrame* pMainFrame = (CMainFrame*)AfxGetMainWnd();
				pMainFrame->m_wndStatusBar.SetPaneText(pMainFrame->m_wndStatusBar.CommandToIndex(ID_CURUSERNAME),user);
				pt->m_changepassword=0;
				pt->m_routesetting=0;
				pt->m_routesettingcontrol=false;
				pt->m_usermanage=0;
				pt->m_usermanagecontrol=false;
				pt->m_seattypesetting=0;
				pt->m_seattypesettingcontrol=false;
				pt->m_pricesetting=0;
				pt->m_pricesettingcontrol=false;
				pt->m_bussetting=0;
				pt->m_bussettingcontrol=false;
				pt->m_driversetting=0;
				pt->m_driversettingcontrol=false;
				pt->m_bustypesetting=0;
				pt->m_bustypesettingcontrol=false;
				pt->m_tickettypesetting=0;
				pt->m_tickettypesettingcontrol=false;
				pt->m_ShouPiaoMingXiViews=0;
				pt->m_ShouPiaoMingXiViewscontrol=false;				
				pt->m_ShouPiaoTongJiViews=0;
				pt->m_ShouPiaoTongJiViewscontrol=false;				
				pt->m_JieSuanMingXiViews=0;
				pt->m_JieSuanMingXiViewscontrol=false;				
				pt->m_JieSuanTongJiViews=0;
				pt->m_JieSuanTongJiViewscontrol=false;				
				pt->m_RiBaoBiaoViews=0;
				pt->m_RiBaoBiaoViewscontrol=false;				
				pt->m_TuiPiaoXinXiViews=0;
				pt->m_TuiPiaoXinXiViewscontrol=false;

				pt->m_SaleTicketViews = 1;
				pt->m_SaleTicketViewscontrol = true;
				
				pt->m_DispatchViews = 1;
				pt->m_DispatchViewscontrol = true;
				
				pt->m_BackTicketViews = 1;
				pt->m_BackTicketViewscontrol = true;

				CDialog::OnOK();
				return;
			}
		}
	}
	
	CDialog::OnOK();
}

void CLoginDlg::OnCancel() 
{
	// TODO: Add extra cleanup here
	((CStationManageApp*)AfxGetApp())->control=true;
	CDialog::OnCancel();
}
void CLoginDlg::OnSelchangeComboUsertype() 
{
	// TODO: Add your control notification handler code here
	CString str;
	m_usertype.GetWindowText(str);
	if (str=="普通用户")
	{
		m_usernamecontrol.SetReadOnly(true);
		m_passwordcontrol.SetReadOnly(true);
		m_password.Empty();
		m_username.Empty();
		m_username="用户名不用输";
		UpdateData(false);
		return;
	}
	else
	{
		m_password.Empty();
		m_username.Empty();
		m_usernamecontrol.SetReadOnly(false);
		m_passwordcontrol.SetReadOnly(false);
		UpdateData(false);
		return;
	}
}

BOOL CLoginDlg::OnInitDialog() //初始化对话框
{
	CDialog::OnInitDialog();
	m_usertype.SetCurSel(1);
	m_usernamecontrol.SetReadOnly(true);
	m_passwordcontrol.SetReadOnly(true);
	m_password.Empty();
	m_username.Empty();
	m_username="用户名不用输";
	UpdateData(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 + -