📄 login.cpp
字号:
// Login.cpp : implementation file
//
#include "stdafx.h"
#include "CTSClient.h"
#include "Login.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern SOCKET clientSocket;
extern CString username;
extern CString password;
extern CString workDate;
extern CString workOrders;
/////////////////////////////////////////////////////////////////////////////
extern BOOL socketconnect;
/////////////////////////////////////////////////////////////////////////////
extern char recvbuf2[3072];
/////////////////////////////////////////////////////////////////////////////
// Login dialog
Login::Login(CWnd* pParent /*=NULL*/)
: CDialog(Login::IDD, pParent)
{
//{{AFX_DATA_INIT(Login)
m_username = _T("");
m_password = _T("");
login = false;
//}}AFX_DATA_INIT
}
void Login::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(Login)
DDX_Control(pDX, IDC_DATETIMEPICKER1, m_workDate);
DDX_Control(pDX, IDC_COMBO1, m_workOrders);
DDX_Text(pDX, IDC_USER_NAME, m_username);
DDX_Text(pDX, IDC_PASSWORD, m_password);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(Login, CDialog)
//{{AFX_MSG_MAP(Login)
ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
ON_WM_CANCELMODE()
ON_WM_CREATE()
ON_WM_CAPTURECHANGED()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// Login message handlers
void Login::OnButton2()
{
// TODO: Add your control notification handler code here
/////////////////////////////////////////////////////////////////////////////////////
if (!socketconnect)
{
MessageBox(_T("与服务器连接中断,请检查网络后重新登录该系统!"),_T("出错提示"));
return;
}
/////////////////////////////////////////////////////////////////////////////////////
UpdateData(true);
if(m_username == VT_EMPTY){
MessageBox(_T("请输入用户名称!!!"),_T("出错提示"));
return;
}
if(m_password == VT_EMPTY){
MessageBox(_T("请输入用户密码!!!"),_T("出错提示"));
return;
}
///////////////////////////////////////////////////
int selectIndex = 0;
CString selectText = _T("");
selectIndex = m_workOrders.GetCurSel();
m_workOrders.GetLBText(selectIndex,selectText);
CString workDateAsString = _T("");
m_workDate.GetWindowText(workDateAsString);
////////////////////////////////////////////////////
if(selectText == VT_EMPTY){
MessageBox(_T("请选择作业班次!!!"),_T("出错提示"));
return;
}
CString LSQL = _T("");
LSQL = " select objectId from ctsuser where userId = '"+m_username+"' and password = '"+m_password+"' ";
LSQL=" "+LSQL+'\0';
int iSize = 0,retint = 0;
char* pszMultiByte;
iSize = WideCharToMultiByte(CP_ACP, 0, LSQL, -1, NULL, 0, NULL, NULL);
pszMultiByte = (char*)malloc((iSize+1)*sizeof(char));
WideCharToMultiByte(CP_ACP, 0, LSQL, -1, pszMultiByte, iSize, NULL, NULL);
*pszMultiByte=3;
pszMultiByte++;
*pszMultiByte=iSize/256;
pszMultiByte++;
*pszMultiByte=iSize%256;
pszMultiByte=pszMultiByte-2;
int mint=send(clientSocket,pszMultiByte,iSize,0);
free(pszMultiByte);
delete pszMultiByte;
retint=recv(clientSocket,recvbuf2,sizeof(recvbuf2),0);
if (recvbuf2[0]==8 && retint==1)
{
MessageBox(_T("网络传输出错,请重新点击按钮再试一次!!!"),_T("提示"));
return;
}
if (recvbuf2[0]==27){
MessageBox(_T("该用户不存在或者密码错误,请重新输入!!!"),_T("出错提示"));
login = false;
m_username = _T("");
m_password = _T("");
UpdateData(false);
return;
}else
{
login = true;
username = m_username;
password = m_password;
/////////////////////////////////////////////////
workDate = workDateAsString;
workOrders = selectText;
/////////////////////////////////////////////////
UpdateData(false);
CDialog::OnCancel();
}
}
void Login::OnButton3()
{
// TODO: Add your control notification handler code here
CDialog::OnCancel();
}
BOOL Login::OnInitDialog()
{
CDialog::OnInitDialog();
m_workOrders.SetCurSel(0);
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void Login::OnCancelMode()
{
CDialog::OnCancelMode();
// TODO: Add your message handler code here
}
int Login::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CDialog::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: Add your specialized creation code here
return 0;
}
void Login::OnCaptureChanged(CWnd *pWnd)
{
// TODO: Add your message handler code here
CDialog::OnCaptureChanged(pWnd);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -