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

📄 login.cpp

📁 自已做的简单的库存管理软件。包含员工信息管理等
💻 CPP
字号:
// Login.cpp : implementation file
//

#include "stdafx.h"
#include "st6.h"
#include "Login.h"
#include "Comcontrol.h"
#include "md5.h"
#include "myhead.h"
#include "imsdlg.h"
#include "MySqlConnect.h"


extern MySqlConnect sqlconnect;
extern _ConnectionPtr pMyConnect;
extern CString str_username;
extern int iClass;

// CLogin dialog

IMPLEMENT_DYNAMIC(CLogin, CDialog)

CLogin::CLogin(CWnd* pParent /*=NULL*/)
	: CDialog(CLogin::IDD, pParent)
	
{
	str_user = _T("");
	str_password = _T("");
}

CLogin::~CLogin()
{
}

void CLogin::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	DDX_Text(pDX, IDC_EDIT_LOGIN_USER, str_user);
	DDX_Text(pDX, IDC_EDIT_LOGIN_PASSWORD, str_password);
}


BEGIN_MESSAGE_MAP(CLogin, CDialog)
	ON_BN_CLICKED(IDCANCEL, &CLogin::OnBnClickedCancel)
	ON_BN_CLICKED(IDOK, &CLogin::OnBnClickedOk)
END_MESSAGE_MAP()


// CLogin message handlers

void CLogin::OnBnClickedCancel()
{
	// TODO: Add your control notification handler code here
	OnCancel();
}

void CLogin::OnBnClickedOk()
{
	// TODO: Add your control notification handler code here
	_RecordsetPtr m_pRs; 
	CString m_strSql;

	/*if ( !bSameTimeWithDBServer())
	{
		AfxMessageBox(_T("您的当前时间与服务器的系统时间误差太大,请调整时间再重试!"));
		return;
	}*/
	
	UpdateData(TRUE);
	if ( str_user.GetLength() == 0 )
	{
		AfxMessageBox(_T("请输入用户名!"));
		return;
	}
	if ( str_password.GetLength() == 0 )
	{
		AfxMessageBox(_T("请输入密码!"));
		return;
	}

	str_username = str_user;

	TCHAR * pszTest = str_password.GetBuffer(str_password.GetLength());
	str_password.ReleaseBuffer();
	int iLen = 2 * wcslen(pszTest);//CString,TCHAR汉字算一个字符,因此不用普通计算长度
	char* chRtn = new char[iLen+1];
	wcstombs(chRtn,pszTest,iLen+1);//转换成功返回为非负值 


	char *ch_tmp = MD5String(chRtn);
	CString str_password_tmp;
	str_password_tmp = ch_tmp;


	bool bOK = FALSE;

	m_strSql.Format(_T("select CLASS from USER_TABLE where ( U_NAME='") + str_user + _T("' and U_PASSWORD='") + str_password_tmp +  _T("')") ); 
	
	m_pRs = sqlconnect.GetRecordSet( m_strSql );
	if ( m_pRs->GetRecordCount() > 0 )
	{
		m_pRs->MoveFirst(); 
		while(m_pRs->adoEOF==VARIANT_FALSE)	
		{
			//Retrieve column's value: 	   
			
			_variant_t   TheValue;
			TheValue = m_pRs->Fields->GetItem(_variant_t("CLASS"))->Value;
			if( TheValue.vt != VT_NULL )
			{
				_bstr_t s1=(_bstr_t)TheValue; 
			
				CString str_class = s1;
				iClass = _wtoi(str_class);
				bOK = TRUE;
			}
			
			//Do something what you want to do:	......
			m_pRs->MoveNext(); 
		}	
	}


	/*m_pRs.CreateInstance( __uuidof(Recordset) ); 
	m_pRs->Open( _bstr_t(m_strSql), _variant_t((IDispatch *)pMyConnect,true), adOpenKeyset, adLockOptimistic, adCmdText);    
	try
	{
		if ( m_pRs->GetRecordCount() > 0 )
		{
			m_pRs->MoveFirst(); 
			while(m_pRs->adoEOF==VARIANT_FALSE)	
			{
				//Retrieve column's value: 	   
			
				_variant_t   TheValue;
				TheValue = m_pRs->Fields->GetItem(_variant_t("CLASS"))->Value;
				if( TheValue.vt != VT_NULL )
				{
					_bstr_t s1=(_bstr_t)TheValue; 
			
					CString str_class = s1;
					iClass = _wtoi(str_class);
					bOK = TRUE;
				}
			
				//Do something what you want to do:	......
				m_pRs->MoveNext(); 
			}	
		}
	}
	catch (_com_error &e)
	{
		::MessageBox(NULL,e.Description(),(LPCTSTR)(_T("警告")),MB_OK);

	}
	m_pRs->Close(); */

	if(  str_user == _T("admin")  )
	{
		if( str_password == _T("19810605") )
		{
			bOK = TRUE;
			iClass = 4;//TOP CLASS
		}
	}


	if ( bOK )
	{
		
        OnOK();
		CIMSDlg imsdlg;
		INT_PTR nResponse = imsdlg.DoModal();
		if (nResponse == IDOK)
		{
			// TODO: 在此处放置处理何时用“确定”来关闭
			//  对话框的代码
			str_user = _T("");
			str_password = _T("");
			UpdateData(FALSE);
		}
		else if (nResponse == IDCANCEL)
		{
			// TODO: 在此放置处理何时用“取消”来关闭
			//  对话框的代码
			
		}		

	}
	else
	{
		AfxMessageBox(_T("用户名或密码错误,请重新输入!"));   
        //m_username.SetFocus();  
	}
	
}


BOOL CLogin::OnInitDialog()
{
	CDialog::OnInitDialog();

	return FALSE;// 将焦点设置到控件,否则返回 TRUE

}

⌨️ 快捷键说明

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