?? logonfileserverdlg.cpp
字號:
// LogonFileServerDlg.cpp : 實現文件
//
#include "stdafx.h"
#include "NCSimulaSys.h"
#include "NCMessage.h"
#include "LogonFileServerDlg.h"
// CLogonFileServerDlg 對話框
IMPLEMENT_DYNAMIC(CLogonFileServerDlg, CDialog)
CLogonFileServerDlg::CLogonFileServerDlg(CWnd* pParent /*=NULL*/)
: CDialog(CLogonFileServerDlg::IDD, pParent)
, m_dwordIP(0)
, m_uintPort(0)
, m_strUserID(_T(""))
, m_strPass(_T(""))
, m_strIP(_T(""))
, m_strInfo(_T(""))
{
m_strIP = _T("127.0.0.1");
m_uintPort = 2000;
m_pMainFrame = (CMainFrame*)pParent;
}
CLogonFileServerDlg::~CLogonFileServerDlg()
{
}
void CLogonFileServerDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Text(pDX, IDC_EDIT_FILE_PORT, m_uintPort);
DDX_Text(pDX, IDC_EDIT_FILE_USERID, m_strUserID);
DDX_Text(pDX, IDC_EDIT_FILE_PASS, m_strPass);
DDX_Text(pDX, IDC_EDIT_FILE_IP, m_strIP);
DDX_Text(pDX, IDC_STATIC_FILE_INFO, m_strInfo);
}
BEGIN_MESSAGE_MAP(CLogonFileServerDlg, CDialog)
ON_BN_CLICKED(IDOK, CLogonFileServerDlg::OnBnClickedOk)
END_MESSAGE_MAP()
// CLogonFileServerDlg 消息處理程序
BOOL CLogonFileServerDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: 在此添加額外的初始化
if(theApp.m_Socket_SynSimula != NULL)
{
m_strUserID = theApp.m_strNCClientUserID;
m_strPass = theApp.m_strNCClientPass;
GetDlgItem(IDC_EDIT_FILE_USERID)->EnableWindow(false);
GetDlgItem(IDC_EDIT_FILE_PASS)->EnableWindow(false);
UpdateData(false);
}
return TRUE; // return TRUE unless you set the focus to a control
// 異常: OCX 屬性頁應返回 FALSE
}
void CLogonFileServerDlg::OnBnClickedOk()
{
// TODO: 在此添加控件通知處理程序代碼
UpdateData(true);
if(inet_addr(m_strIP) == INADDR_NONE)
{
AfxMessageBox(_T("無效的IP地址."));
return;
}
if(!(m_uintPort>1024 && m_uintPort<=65535))
{
AfxMessageBox(_T("端口范圍應>1024且<=65535"));
return;
}
if(m_strUserID=="" || m_strPass=="")
{
AfxMessageBox(_T("用戶名和密碼不能為空."));
return;
}
BOOL bSuccessful = false;
theApp.m_Socket_File = new CNCFileSocket();
bSuccessful = theApp.m_Socket_File->Create(0,SOCK_STREAM);
if(!bSuccessful)
{
m_strInfo = _T("套接字創建不成功.");
theApp.m_Socket_File = NULL;
UpdateData(false);
}
theApp.m_Socket_File->Init(this);
// 設置要連接的服務器IP和端口. 轉換為network format.
sockaddr_in addr;
addr.sin_family = AF_INET;
addr.sin_addr.S_un.S_addr = inet_addr(m_strIP);
addr.sin_port = htons(m_uintPort);
// 連接服務器.
if(!theApp.m_Socket_File->Connect((sockaddr*)&addr, sizeof(addr)))
{
theApp.m_Socket_File->CloseSocket();
theApp.m_Socket_File = NULL;
return;
}
// 發送用戶名和密碼信息.
CString strInfo = _T("USER-") + m_strUserID + _T("|") + _T("PASS-") + m_strPass;
CNCMessage msg;
msg.m_strMessage = strInfo;
theApp.m_Socket_File->SendNetMessage(msg);
}
void CLogonFileServerDlg::OnReceive(CNCFileSocket* pSocket, CNCMessage& msg)
{
CString strInfo;
strInfo = msg.m_strMessage;
if(strInfo == _T("FILESERVER-LOGON-SUCCESSFUL"))
{
theApp.m_strNCClientUserID = m_strUserID;
theApp.m_strNCClientPass = m_strPass;
CDialog::OnOK();
}
if(strInfo == _T("FILESERVER-LOGON-FAILED-UPERROR"))
{
theApp.m_Socket_File->CloseSocket();
delete theApp.m_Socket_File;
theApp.m_Socket_File = NULL;
m_strInfo = _T("用戶名或密碼錯誤.");
UpdateData(false);
}
if(strInfo == _T("FILESERVER-LOGON-FAILED-HAVELOGON"))
{
theApp.m_Socket_File->CloseSocket();
delete theApp.m_Socket_File;
theApp.m_Socket_File = NULL;
m_strInfo = _T("該用戶已在其它客戶端登錄.");
UpdateData(false);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -