📄 nrdbpro.cpp
字号:
//////////////////////////////////////////////////////
//
// NRDB Pro - Spatial database and mapping application
//
// Copyright (c) 1989-2004 Richard D. Alexander
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//
// NRDB Pro is part of the Natural Resources Database Project
//
// Homepage: http://www.nrdb.co.uk/
// Users' Forum: http://nrdb.mypalawan.info/
//
#include "stdafx.h"
#include <initguid.h>
#include <odbcinst.h>
#include <direct.h>
#include <io.h>
#include "nrdbpro.h"
#include "MainFrm.h"
#include "docmap.h"
#include "viewmap.h"
#include "framemap.h"
#include "docgraph.h"
#include "viewgraph.h"
#include "docbdreport.h"
#include "importodbc.h"
#include "importmaplines.h"
#include "bdhtmlview.h"
#include "framereport.h"
#include "dlgseldictionary.h"
#include "ComboBoxFType.h"
#include "dlglogin.h"
#include "docsummary.h"
#include "doctsgraph.h"
#include "viewtsgraph.h"
#include "dlgprojection.h"
#include "viewmap.h"
#include "sheetreportsettings.h"
#include "bdimportexport.h"
#include "dlgabout.h"
#include "importtextfile.h"
#include "shapefile.h"
#include "dlgaddlayer.h"
#include "dochtmlhelp.h"
#include "dlgnew.h"
#include "docpiechart.h"
#include "viewpiechart.h"
#include "doctsreport.h"
#include "comboboxsymbol.h"
#include "dlgftype.h"
#include "dlgfeatures.h"
#include "viewmaplayout.h"
#include "docmaplayout.h"
#include "framemaplayout.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
///////////////////////////////////////////////////////////////////////////////
#define HELP_DBSETUP 0x10000
#define LAYOUTFILE "layout.xml"
///////////////////////////////////////////////////////////////////////////////
unsigned long CRC32(unsigned long current, BOOL init, void *buffer, unsigned long size);
///////////////////////////////////////////////////////////////////////////////
extern "C"
{
extern int _stdcall compress(BYTE *dest, ULONG *destLen, const BYTE *source, ULONG sourceLen);
extern int _stdcall uncompress (BYTE *dest, ULONG *destLen, const BYTE *source, ULONG sourceLen);
};
int _stdcall compressZ(BYTE *dest, ULONG *destLen, const BYTE *source, ULONG sourceLen)
{
return compress(dest, destLen, source, sourceLen);
}
int _stdcall uncompressZ (BYTE *dest, ULONG *destLen, const BYTE *source, ULONG sourceLen)
{
return uncompress(dest, destLen, source, sourceLen);
}
///////////////////////////////////////////////////////////////////////////////
CNRDBApp* BDGetApp();
BDHANDLE BDHandle() {return BDGetApp()->GetDBHandle();}
BDHANDLE& BDHandleRef() {return BDGetApp()->GetDBHandle();}
CNRDBApp* BDGetApp() {return (CNRDBApp*)AfxGetApp();}
CString BDString(int nId) {return BDGetApp()->LoadString(nId);};
CProjection* BDProjection() {return BDGetApp()->GetProjection();};
CDocMap* BDGetDocMap() {return BDGetApp()->GetDocMap();}
void BDSetProgressBar(CBDProgressBar* p) {BDGetApp()->SetProgressBar(p);}
CBDProgressBar* BDGetProgressBar() {return BDGetApp()->GetProgressBar();}
void BDSetProgressText(CStatic* pEdit) {BDGetApp()->SetProgressText(pEdit);}
CStatic* BDGetProgressText() {return BDGetApp()->GetProgressText();}
CBDMain& BDGetSettings() {return BDGetApp()->GetSettings();};
LPCSTR BDGetDataSource() {return BDGetApp()->GetDataSource();}
void BDGetPrinterInfo(DEVMODE* pDevMode) {BDGetApp()->GetPrinterInfo(pDevMode);}
CMultiDocTemplate* BDGetDocTemplate(LPCSTR pDocName) {return BDGetApp()->GetDocTemplate(pDocName);}
BDOnHelpNrdbhomepage() {BDGetApp()->OnHelpNrdbhomepage(); return 0;}
long BDFTypeSel() {return BDGetApp()->GetFTypeSel();}
void BDFTypeSel(long lFType) {BDGetApp()->SetFTypeSel(lFType);}
LPCSTR BDGetHtmlHelp() {return BDGetApp()->GetHtmlHelp();}
void BDSetHtmlHelp(LPCSTR s, BOOL bTemp) {BDGetApp()->SetHtmlHelp(s, bTemp);}
int BDGetPreviousReport() {return BDGetApp()->GetPreviousReport();}
void BDSetPreviousReport(int nType) {BDGetApp()->SetPreviousReport(nType);}
long& BDCRCRegKey() {return BDGetApp()->m_lCRCRegKey;}
void BDOnReportSummary() {BDGetApp()->OnReportSummary();}
HWND& BDHwndDialog() {return BDGetApp()->m_hwndDialog;}
CToolTipCtrl*& BDToolTip() {return BDGetApp()->m_gpToolTip;}
CString BDGetAppPath() {return BDGetApp()->GetAppPath();}
CFeatureArray& BDFeatureSel() {return BDGetApp()->GetFeatureSel();}
CFTypeAttrArray& BDAttrSel() {return BDGetApp()->GetAttrSel();}
BOOL BDIsAttrSel(long lFType, long lAttr)
{
for (int i = 0; i < BDAttrSel().GetSize(); i++)
{
if (BDAttrSel().GetAt(i).GetFTypeId() == lFType &&
BDAttrSel().GetAt(i).GetAttrId() == lAttr) return TRUE;
}
return FALSE;
}
BOOL BDIsFeatureSel(long lFType, long lFeature)
{
for (int i = 0; i < BDFeatureSel().GetSize(); i++)
{
if (BDFeatureSel().GetAt(i).m_lId == lFeature &&
BDFeatureSel().GetAt(i).m_lFeatureTypeId == lFType) return TRUE;
}
return FALSE;
}
/////////////////////////////////////////////////////////////////////////////
#define MENU_REPORT 4
#define MENU_MAP 3
#define MENU_FILE 0
#define MENU_ITEMS 7
/////////////////////////////////////////////////////////////////////////////
typedef CArray <CFTypeAttr, CFTypeAttr> CFTypeAttrArray;
/////////////////////////////////////////////////////////////////////////////
CString CNRDBApp::m_sLoadString;
/////////////////////////////////////////////////////////////////////////////
// CNRDBApp
BEGIN_MESSAGE_MAP(CNRDBApp, CWinApp)
//{{AFX_MSG_MAP(CNRDBApp)
ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
ON_COMMAND(ID_APP_EXIT, OnAppExit)
ON_COMMAND(ID_REPORT_GRAPH, OnReportGraph)
ON_COMMAND(ID_REPORT_TABLE, OnReportTable)
ON_COMMAND(ID_IMPORT_ODBC, OnImportODBC)
ON_COMMAND(ID_REPORT_SUMMARY, OnReportSummary)
ON_COMMAND(ID_REPORT_TSGRAPH, OnReportTsgraph)
ON_COMMAND(ID_REPORT_PIECHART, OnReportPieChart)
ON_COMMAND(ID_REPORT_TIMESERIES, OnReportTSReport)
ON_COMMAND(ID_TOOLS_SETTINGS, OnToolsSettings)
ON_COMMAND(ID_REPORT_WIZARD, OnReportWizard)
ON_COMMAND(ID_REPORT_WIZARD_SETUP, OnReportWizardSetup)
ON_COMMAND(ID_VIEW_LAYERS, OnViewLayers)
ON_COMMAND(ID_IMPORT_FILE, OnImportFile)
ON_COMMAND(ID_IMPORT_SHAPEFILE, OnImportShapefile)
ON_COMMAND(ID_CONVERT_SHAPEFILE, OnConvertShapefile)
ON_COMMAND(ID_EXPORT_SHAPEFILE, OnExportShapefile)
ON_COMMAND(ID_FILE_LOGOUT, OnFileLogout)
ON_COMMAND(ID_REPORT_PREVIOUS, OnReportPrevious)
ON_UPDATE_COMMAND_UI(ID_EXPORT_SHAPEFILE, OnUpdateExportShapefile)
ON_COMMAND(ID_HELP_NRDBHOMEPAGE, OnHelpNrdbhomepage)
ON_COMMAND(ID_HELP_SUPPORT, OnHelpSupport)
ON_COMMAND(ID_HELP_NRDBTUTORIAL, OnHelpTutorial)
ON_COMMAND(ID_FILE_NEW, OnFileNew)
ON_COMMAND(ID_FILE_SETUP_FEATURETYPES, OnFileSetupFeatureTypes)
ON_COMMAND(ID_FILE_SETUP_FEATURES, OnFileSetupFeatures)
ON_UPDATE_COMMAND_UI(ID_IMPORT_ODBC, OnUpdateFTypesExist)
ON_UPDATE_COMMAND_UI(ID_REPORT_WIZARD, OnUpdateFTypesExist)
ON_UPDATE_COMMAND_UI(ID_REPORT_WIZARD_SETUP, OnUpdateFTypesExist)
ON_UPDATE_COMMAND_UI(ID_IMPORT_SHAPEFILE, OnUpdateFTypesExist)
ON_UPDATE_COMMAND_UI(ID_FILE_SETUP_FEATURES, OnUpdateFTypesExist)
ON_UPDATE_COMMAND_UI(ID_REPORT_GRAPH, OnUpdateFTypesExist)
ON_UPDATE_COMMAND_UI(ID_REPORT_SUMMARY, OnUpdateFTypesExist)
ON_UPDATE_COMMAND_UI(ID_REPORT_TABLE, OnUpdateFTypesExist)
ON_UPDATE_COMMAND_UI(ID_REPORT_TIMESERIES, OnUpdateFTypesExist)
ON_UPDATE_COMMAND_UI(ID_REPORT_TSGRAPH, OnUpdateFTypesExist)
ON_UPDATE_COMMAND_UI(ID_FILE_OPEN, OnUpdateFTypesExist)
ON_UPDATE_COMMAND_UI(ID_REPORT_PREVIOUS, OnUpdateReportPrevious)
//}}AFX_MSG_MAP
// Standard file based document commands
ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
// Standard print setup command
ON_COMMAND(ID_FILE_PRINT_SETUP, CWinApp::OnFilePrintSetup)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// CNRDBApp construction
CNRDBApp::CNRDBApp()
{
m_pProgressBar = NULL;
m_pProgessText = NULL;
m_hwndDialog = NULL;
m_gpToolTip = NULL;
m_hConnect = (BDHANDLE)-1;
m_bFType = TRUE;
m_nPreviousReport = -1;
}
/////////////////////////////////////////////////////////////////////////////
CNRDBApp::~CNRDBApp()
{
//if (m_pDialogExplorer != NULL) delete m_pDialogExplorer;
}
/////////////////////////////////////////////////////////////////////////////
// The one and only CNRDBApp object
CNRDBApp theApp;
/////////////////////////////////////////////////////////////////////////////
// CNRDBApp initialization
BOOL CNRDBApp::InitInstance()
{
CFeatureType ftype;
// Allow the user of active-x controls
AfxEnableControlContainer();
// 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
SetRegistryKey(_T("Natural Resources Database"));
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.
CMultiDocTemplate* pDocTemplate;
pDocTemplate = new CMultiDocTemplate(
IDR_MAPTYPE,
RUNTIME_CLASS(CDocMap),
RUNTIME_CLASS(CFrameMap), // custom MDI child frame
RUNTIME_CLASS(CViewMap));
AddDocTemplate(pDocTemplate);
// Register the template
pDocTemplate = new CMultiDocTemplate(
IDR_GRAPHTYPE,
RUNTIME_CLASS(CDocGraph),
RUNTIME_CLASS(CMDIChildWnd),
RUNTIME_CLASS(CViewGraph));
AddDocTemplate(pDocTemplate);
pDocTemplate = new CMultiDocTemplate(
IDR_TSGRAPHTYPE,
RUNTIME_CLASS(CDocTSGraph),
RUNTIME_CLASS(CMDIChildWnd),
RUNTIME_CLASS(CViewTSGraph));
AddDocTemplate(pDocTemplate);
pDocTemplate = new CMultiDocTemplate(
IDR_PIECHART,
RUNTIME_CLASS(CDocPieChart),
RUNTIME_CLASS(CMDIChildWnd),
RUNTIME_CLASS(CViewPieChart));
AddDocTemplate(pDocTemplate);
pDocTemplate = new CMultiDocTemplate(
IDR_TSREPORT,
RUNTIME_CLASS(CDocTSReport),
RUNTIME_CLASS(CFrameReport),
RUNTIME_CLASS(CBDHtmlView));
AddDocTemplate(pDocTemplate);
pDocTemplate = new CMultiDocTemplate(
IDR_HTMLREPORT,
RUNTIME_CLASS(CDocBDReport),
RUNTIME_CLASS(CFrameReport),
RUNTIME_CLASS(CBDHtmlView));
AddDocTemplate(pDocTemplate);
pDocTemplate = new CMultiDocTemplate(
IDR_HTMLREPORT,
RUNTIME_CLASS(CDocBDReport),
RUNTIME_CLASS(CFrameReport),
RUNTIME_CLASS(CBDHtmlView));
AddDocTemplate(pDocTemplate);
pDocTemplate = new CMultiDocTemplate(
IDR_SUMMARYREPORT,
RUNTIME_CLASS(CDocSummary),
RUNTIME_CLASS(CFrameReport),
RUNTIME_CLASS(CBDHtmlView));
AddDocTemplate(pDocTemplate);
pDocTemplate = new CMultiDocTemplate(
IDR_HTMLHELP,
RUNTIME_CLASS(CDocHtmlHelp),
RUNTIME_CLASS(CFrameReport),
RUNTIME_CLASS(CBDHtmlView));
AddDocTemplate(pDocTemplate);
pDocTemplate = new CMultiDocTemplate(
IDR_MAPLAYOUT,
RUNTIME_CLASS(CDocMapLayout),
RUNTIME_CLASS(CFrameMapLayout),
RUNTIME_CLASS(CViewMapLayout));
AddDocTemplate(pDocTemplate);
// create main MDI Frame window
CMainFrame* pMainFrame = new CMainFrame;
if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
return FALSE;
m_pMainWnd = pMainFrame;
pMainFrame->ShowWindow(m_nCmdShow);
pMainFrame->UpdateWindow();
// Display about box
CDlgAbout dlg(TRUE);
dlg.DoModal();
// Login
if (!Login())
{
return FALSE;
}
// Retrieve settings
BDMain(BDHandle(), &m_BDMain, BDGETINIT);
BDEnd(BDHandle());
// Load custom symbols
CComboBoxSymbol::InitCustomSym();
// Set the printer to landscape
SetLandscape();
// Open explorer (to ensure there is a window for default map!)
// Open the file specified on the command line
CDocMap* pDocMap = GetDocMap();
if (m_lpCmdLine[0] != '\0' && pDocMap != NULL)
{
GetDocMap()->Open(m_lpCmdLine);
// Reset command line
m_lpCmdLine[0] = '\0';
}
BDEnd(BDHandle());
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
BOOL CNRDBApp::Login()
{
BOOL bOK = TRUE;
// Retrieve the default data source name
CString sDataSource = DefaultDataSource();
// Connect to the database
do
{
TRY
{
bOK = TRUE;
CDlgLogin dlg(sDataSource);
if (dlg.DoModal() != IDOK) return FALSE;
BeginWaitCursor();
int nRet = BDConnect(dlg.GetDataSource(), &m_hConnect);
EndWaitCursor();
if (nRet == -1)
{
if (AfxMessageBox(BDString(IDS_INVALIDNRDB) + "\r\nWould you like to create the necessary NRDB tables?", MB_YESNO) == IDYES)
{
// Create tables
BDInitialise(dlg.GetDataSource());
}
bOK = FALSE;
} else
{
bOK = nRet == TRUE;
};
m_sDataSource = dlg.GetDataSource();
// Trap database errors
}
CATCH (CDBException, pEx)
{
AfxMessageBox(pEx->m_strError);
bOK = FALSE;
}
END_CATCH
} while (!bOK);
BDEnd(BDHandle());
// Determine the projection
m_projection.InitialiseProjection();
// Retrieve layout
LoadLayout();
// Open the map
BeginWaitCursor();
CDocMap* pDoc;
CMultiDocTemplate* pTemplate = GetDocTemplate("Map");
pDoc = (CDocMap*)pTemplate->OpenDocumentFile(NULL);
EndWaitCursor();
// Retrieve default feature type
m_lFTypeSel = GetProfileInt(m_sDataSource, "FTypeId", 0);
// Reset default colour
CDlgAddLayer::Reset();
return bOK;
}
///////////////////////////////////////////////////////////////////////////////
void CNRDBApp::OnFileLogout()
{
CFeatureType ftype;
// Logff
Logout();
// Re-login
if (Login())
{
// Reset sectors
CComboBoxFType::InitDictionary(TRUE);
} else
{
OnAppExit();
}
}
/////////////////////////////////////////////////////////////////////////////
void CNRDBApp::Logout()
{
// Disconnect from the database
if ((int)m_hConnect >= 0)
{
if (BDGetTransLevel(BDHandle()) > 0) BDCommit(BDHandle());
ASSERT(BDGetTransLevel(BDHandle()) == 0);
BeginWaitCursor();
BDDisconnect(m_hConnect);
EndWaitCursor();
m_hConnect = (BDHANDLE)-1;
// Write the default feature for the database
WriteProfileInt(m_sDataSource, "FTypeId", m_lFTypeSel);
// Write the default colour
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -