// UDPServ.cpp : Defines the class behaviors for the application.
//
//  Version 1.2:
//		1. Modify the Vehicle.dbf file to append records instead of replacing
//		2. Change Vehicle.dbf (CCurrLoc) to use VehicleID as an Int. rather than Char.
//
//	Version 1.3:
//		1.  Change Time field in Vehicle.dbf to echo time style string
//		2.  Change Velocity to KPH (from incoming MPH)
//		3.  Do conversion from incoming time in Seconds to Time string.
//
//	Version 1.4:
//		1.  Add outgoing UDP support to send data to Mapping Prog.
//			Data format: VehicleID|Time|Date|Velocity|Latitude|Longitude|Status
//		2.  Add .INI file support
//
//	Version 1.5:
//		1.	Add support for Map Skew correction.
//		2.  Two new .INI entries [Map]LongCorr and [Map]LatCorr
//
//	Version 1.6:
//		1.  Add support for TCP Map updates
//		2.  Turn off VEHICLE.DBF updates when TCP map updates on
//
//	Version 1.6b:
//		1.  Added code to delete the top 100 characters if the number of
//			lines is greater than 50.  This should stop the unexpected crashes
//			due to the edit buffer overflowing. (code in CServView)
//
//	Version 1.7:
//		1.	Added check support to ensure that incoming latitude and
//			longitude are within valid parameters.  
//		2.	Added 3 new .INI entries - LatMean, LongMean, and LatLongDev.
//		3.  Added new entries in the Setup Dialog to support the 
//			parameter checking.
//		4.  Fixed bug where Server Port number would reset to default (4099)
//			whenever setup dialog was opened.
//
//	Version 1.7a:
//		1.  Added a check box in the Setup Dialog to allow the choice to
//			save data to the backup database (datalink.mdb).  When this
//			is disabled, and TCP map updates are enabled, ODBC is not
//			used.
//		2.	Related note:  Added new .ini entry [Host]BackupEnabled
//			to save this data.
//
//	Version 1.7b:
//		1.  Fixed Bug where code would crash when an update came in.
//			(bug was due to the program trying to update a database
//			 that wasn't open)
//		2.  Moved all record updates to backup database (CUDPRecSet)
//			out of ParseDataIn() and put into DataToDB() function.
//		3.  Modified RxDataIn() to call ParseDataIn() and UpdateDBCurrent()
//			if m_bBackupEnabled was not true. (i.e. the backup database 
//			is not being used)
//
//	Version 1.8:
//			Add GMT time difference correction for summer time.
/////////////
// Sept. 5, 97, Redirect IP takes only 11 digits. Fixed.

#include "stdafx.h"
#include "UDPServ.h"

#include "MainFrm.h"
#include "UDPServDoc.h"
#include "UDPServView.h"

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

/////////////////////////////////////////////////////////////////////////////
// CUDPApp

BEGIN_MESSAGE_MAP(CUDPApp, CWinApp)
	//{{AFX_MSG_MAP(CUDPApp)
	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()

/////////////////////////////////////////////////////////////////////////////
// CUDPApp construction

CUDPApp::CUDPApp()
{
	// TODO: add construction code here,
	// Place all significant initialization in InitInstance
}

/////////////////////////////////////////////////////////////////////////////
// The one and only CUDPApp object

CUDPApp theApp;

/////////////////////////////////////////////////////////////////////////////
// CUDPApp initialization

BOOL CUDPApp::InitInstance()
{
	if (!AfxSocketInit())
	{
		AfxMessageBox(IDP_SOCKETS_INIT_FAILED);
		return FALSE;
	}

	// Standard initialization
	// If you are not using these features and wish to reduce the size
	//  of your final executable, you should remove from the following
	//  the specific initialization routines you do not need.

#ifdef _AFXDLL
	Enable3dControls();			// Call this when using MFC in a shared DLL
#else
	Enable3dControlsStatic();	// Call this when linking to MFC statically
#endif

	LoadStdProfileSettings(0);  // 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(CUDPDoc),
		RUNTIME_CLASS(CMainFrame),       // main SDI frame window
		RUNTIME_CLASS(CUDPView));
	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;

	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)
		// No message handlers
	//}}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 CUDPApp::OnAppAbout()
{
	CAboutDlg aboutDlg;
	aboutDlg.DoModal();
}

/////////////////////////////////////////////////////////////////////////////
// CUDPApp commands
