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

📄 ctsclient.cpp

📁 码头手持机项目,用于统计集装箱,轮船的情况,手持机采用S3C2440处理器,数据传输采用2.4G无线,上位机用VC编写
💻 CPP
字号:
// CTSClient.cpp : Defines the class behaviors for the application.
//

#include "stdafx.h"
#include "CTSClient.h"

#include "MainFrm.h"
#include "CTSClientDoc.h"
#include "CTSClientView.h"
#include "Login.h"
//#include "Init.h"

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

/////////////////////////////////////////////////////////////////////////////
// CCTSClientApp

BEGIN_MESSAGE_MAP(CCTSClientApp, CWinApp)
//{{AFX_MSG_MAP(CCTSClientApp)
ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
// NOTE - the ClassWizard will add and remove mapping macros here.
//    DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG_MAP
// Standard file based document commands
ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CCTSClientApp construction
CCTSClientApp::CCTSClientApp(LPCTSTR lpszHelpName)
: CWinApp(lpszHelpName)
{
	// TODO: add construction code here,
	// Place all significant initialization in InitInstance
}

/////////////////////////////////////////////////////////////////////////////
// The one and only CCTSClientApp object
CCTSClientApp theApp(_T("CTSClient.htp"));
SOCKET clientSocket;

/////////////////////////////////////////////////////////////////////////////
SOCKET testSocket;
BOOL socketconnect;
/////////////////////////////////////////////////////////////////////////////
int currentRow;
CString deliveryOrdischarge;

CString username;
CString password;
/////////////////////////////////////////////////////////////////////////////
CString workDate;
CString workOrders;
/////////////////////////////////////////////////////////////////////////////
CString loadTallyListItemObjectId;
CString loadContainerNo;
CString loadSealNo;
CString voyageNoQuery;
/////////////////////////////////////////////////////////////////////////////

//add@2007-1-25
char recvbuf[10240];
char recvbuf2[3072];
char rectemp[50];
//add end
// CCTSClientApp initialization

BOOL CCTSClientApp::InitInstance()
{
	if (!AfxSocketInit())
	{
		AfxMessageBox(IDP_SOCKETS_INIT_FAILED);
		return FALSE;
	}
	
	AfxEnableControlContainer();
	
    //////////////////////////////////////////////////////////////////////////////////////////
	//Init * initdlg = new Init;
	//initdlg->Create(IDD_INIT,NULL);
	//initdlg->ShowWindow(SW_SHOW);
	//////////////////////////////////////////////////////////////////////////////////////////
	if (!Init_net(ServerPort))
		return false;
	
	status = connect(clientSocket, (LPSOCKADDR)&clientSockAddr, sizeof(clientSockAddr));
	if (status == SOCKET_ERROR)
	{
		status = closesocket(clientSocket);
		status=WSACleanup();
		Init_net(ServerPort);
		socketconnect=false;
	}
	else
		socketconnect=true;
	if (!socketconnect)
	{	
		status = connect(clientSocket, (LPSOCKADDR)&clientSockAddr, sizeof(clientSockAddr));
		if (status == SOCKET_ERROR)
		{
			AfxMessageBox(_T("网络连接不成功!"));
			status = WSACleanup();
			socketconnect=false;
		}
		else
		{
			socketconnect=true;
			status = connect(testSocket, (LPSOCKADDR)&clientSockAddr, sizeof(clientSockAddr));
		}
	}
	else
	{
		socketconnect=true;
		status = connect(testSocket, (LPSOCKADDR)&clientSockAddr, sizeof(clientSockAddr));
	}
	////////////////////////////////////////////////////////////////////////////////////////////
	//initdlg->DestroyWindow();
	////////////////////////////////////////////////////////////////////////////////////////////
	
	SetRegistryKey(_T("Local AppWizard-Generated Applications"));
	
	LoadStdProfileSettings();  // Load standard INI file options (including MRU)
	
	
	// Register the application's document templates.  Document templates
	//  serve as the connection between documents, frame windows and views.
	
	CSingleDocTemplate* pDocTemplate;
	pDocTemplate = new CSingleDocTemplate(
		IDR_MAINFRAME,
		RUNTIME_CLASS(CCTSClientDoc),
		RUNTIME_CLASS(CMainFrame),       // main SDI frame window
		RUNTIME_CLASS(CCTSClientView));
	AddDocTemplate(pDocTemplate);
	
	// Parse command line for standard shell commands, DDE, file open
	CCommandLineInfo cmdInfo;
	ParseCommandLine(cmdInfo);
	
	// Dispatch commands specified on the command line
	if (!ProcessShellCommand(cmdInfo))
		return FALSE;
	
	// The one and only window has been initialized, so show and update it.
	m_pMainWnd->SetWindowText(_T("集装箱理货管理系统"));
	m_pMainWnd->ShowWindow(SW_MAXIMIZE);
	m_pMainWnd->UpdateWindow();
	
	Login login;
	login.DoModal();
    if(login.login != true)
	{
		closesocket(clientSocket);
		closesocket(testSocket);
		WSACleanup();
		return FALSE;
	}
	
	return TRUE;
}



/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();
	
	// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA
	
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL
	
	// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	virtual BOOL OnInitDialog();		// Added for WCE apps
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

// App command to run the dialog
void CCTSClientApp::OnAppAbout()
{
	CAboutDlg aboutDlg;
	aboutDlg.DoModal();
}

/////////////////////////////////////////////////////////////////////////////
// CCTSClientApp commands
// Added for WCE apps

BOOL CAboutDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	CenterWindow();
	
	return TRUE;  // return TRUE unless you set the focus to a control
	// EXCEPTION: OCX Property Pages should return FALSE
}

BOOL CCTSClientApp::Init_net(u_short PORT)
{
	status=WSAStartup(MAKEWORD(1, 1), &Data);
	if (status != 0)
	{
		AfxMessageBox(_T("网络环境错误!"));
		return  false;
	}
	memset(&clientSockAddr, 0, sizeof(clientSockAddr));
    clientSockAddr.sin_port=htons(PORT);
    clientSockAddr.sin_family=AF_INET;
	//clientSockAddr.sin_addr.S_un.S_addr=inet_addr("219.129.44.201");
	clientSockAddr.sin_addr.S_un.S_addr=inet_addr("10.1.138.3");
	//clientSockAddr.sin_addr.S_un.S_addr=inet_addr("10.1.8.137");
	//clientSockAddr.sin_addr.S_un.S_addr=inet_addr("192.168.1.105");
    clientSocket=socket(AF_INET, SOCK_STREAM, 0);
	testSocket=socket(AF_INET, SOCK_STREAM, 0);
	//////////////////////////////////////////////////////////////////////
    if (clientSocket == INVALID_SOCKET)
	{
		AfxMessageBox(_T("网络初始化错误!"));
		status=WSACleanup();
		if (status == SOCKET_ERROR)
			AfxMessageBox(_T("ERROR: WSACleanup unsuccessful!")); 
		return false;
	}

	if (testSocket == INVALID_SOCKET)
	{
		AfxMessageBox(_T("网络初始化错误!"));
		status=WSACleanup();
		if (status == SOCKET_ERROR)
			AfxMessageBox(_T("ERROR: WSACleanup unsuccessful!")); 
		return false;
	}

    return TRUE;
}

⌨️ 快捷键说明

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