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

📄 pagequerycalc.cpp

📁 一个英国人写的GIS查看/编辑工具。支持标准的shapefile地图文件格式和coverage地图文件格式。同时可以编辑相应的dbf文件。
💻 CPP
📖 第 1 页 / 共 2 页
字号:
//////////////////////////////////////////////////////
//
// 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 "nrdb.h"
#include "sheetquery.h"
#include "PageQueryCalc.h"

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

/////////////////////////////////////////////////////////////////////////////
// CPageQueryCalc property page

IMPLEMENT_DYNCREATE(CPageQueryCalc, CPropertyPage)

CPageQueryCalc::CPageQueryCalc(CQuery* pQuery, CQuery* pQueryPrev, int nType) : CPropertyPage(CPageQueryCalc::IDD)
{
   m_pQuery = pQuery;
   m_pQueryPrev = pQueryPrev;
   m_nType = nType;
   m_bChanged = FALSE; 

	//{{AFX_DATA_INIT(CPageQueryCalc)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}

CPageQueryCalc::CPageQueryCalc()
{
   m_bChanged = FALSE;
}

CPageQueryCalc::~CPageQueryCalc()
{
}

void CPageQueryCalc::DoDataExchange(CDataExchange* pDX)
{
	CPropertyPage::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CPageQueryCalc)
	DDX_Control(pDX, IDC_VALUE1, m_eValue1);
	DDX_Control(pDX, IDC_DECPLACES, m_eDecPlaces);
	DDX_Control(pDX, IDC_STATSNAME, m_eStatsName);
	DDX_Control(pDX, IDC_QUERYSTATS, m_lbQueryStats);
	DDX_Control(pDX, IDC_OPERATOR, m_cbOperator);
	DDX_Control(pDX, IDC_ATTR2, m_cbAttr2);
	DDX_Control(pDX, IDC_ATTR1, m_cbAttr1);
	DDX_Control(pDX, IDC_VALUE2, m_eValue2);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CPageQueryCalc, CPropertyPage)
	//{{AFX_MSG_MAP(CPageQueryCalc)
	ON_LBN_SELCHANGE(IDC_QUERYSTATS, OnSelchangeQuerystats)
	ON_BN_CLICKED(IDC_ADD, OnAdd)
	ON_BN_CLICKED(IDC_DELETE, OnDelete)
	ON_CBN_SELCHANGE(IDC_ATTR1, OnSelchange)
	ON_CBN_SELCHANGE(IDC_ATTR2, OnSelchange)
	ON_CBN_SELCHANGE(IDC_OPERATOR, OnSelchange)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()


///////////////////////////////////////////////////////////////////////////////

BOOL CPageQueryCalc::OnInitDialog() 
{
	CPropertyPage::OnInitDialog();
   
   // Initialise statistics

   OnSelchangeQuerystats();

   OnSelchange();

	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

///////////////////////////////////////////////////////////////////////////////

void CPageQueryCalc::Update()
{
   m_cbAttr1.ResetContent();
   m_cbAttr2.ResetContent();

   m_eDecPlaces.SetValue(0);

      // Initialise controls according to the current feature type

   CString sFType;
   CQueryElement* pElement = m_pQuery;
   while (pElement != NULL)
   {
      if (pElement->GetDataType() == BDFTYPE)
      {
         sFType = CQuery::StripBrackets(pElement->GetDesc());
      }
      if (pElement->GetDataType() == BDNUMBER)
      {
         m_cbAttr1.AddStringX(sFType + " - " + CString(pElement->GetDesc()), 
                              (long)pElement);
         m_cbAttr2.AddStringX(sFType + " - " + CString(pElement->GetDesc()), 
                              (long)pElement);
      }

      pElement = pElement->GetNextQuery();
   }   

   // Add 'value' to attribute lists

   m_cbAttr1.AddStringX(BDString(IDS_VALUE), NULL);
   m_cbAttr2.AddStringX(BDString(IDS_VALUE), NULL);

   // Set default values

   if (m_cbAttr1.GetCurSel() == CB_ERR) m_cbAttr1.SetCurSel(0);
   if (m_cbAttr2.GetCurSel() == CB_ERR) m_cbAttr2.SetCurSel(0);

   // Fill list of defined query statistics
   
   UpdateQueryStats();
}

/////////////////////////////////////////////////////////////////////////////

void CPageQueryCalc::UpdateQueryStats()
{
   m_lbQueryStats.ResetContent();

   // List already defined query stats

   CQueryElement* pElement = m_pQuery;
   while (pElement != NULL)
   {
      if (pElement->GetDataType() == BDQUERYSTATS)
      {         
         int index = m_lbQueryStats.AddString(pElement->GetDesc());
         m_lbQueryStats.SetItemDataPtr(index, pElement);
      }      
      pElement = pElement->GetNextQuery();
   }  
   
   m_lbQueryStats.SetCurSel(0);
   OnSelchangeQuerystats();  
}

/////////////////////////////////////////////////////////////////////////////

void CPageQueryCalc::OnSelchangeQuerystats() 
{
   int index = m_lbQueryStats.GetCurSel();
   if (index != CB_ERR)
   {
      CQueryStats* pStats = (CQueryStats*)m_lbQueryStats.GetItemDataPtr(index);

      // Recover the first attribute

      for (int i = 0; i < m_cbAttr1.GetCount(); i++)
      {         
         CQueryElement* pElement = (CQueryElement*)m_cbAttr1.GetItemDataPtr(i);

         if (pElement != NULL)
         {
            if (pElement->GetAttrId() == pStats->GetAttrId() &&
                pElement->GetFTypeId() == pStats->GetFTypeId())
            {
               m_cbAttr1.SetCurSel(i);
               break;
            }             
         } else
         {
            if (pStats->GetAttrId() == 0)
            {
               m_cbAttr1.SetCurSel(i);
               m_eValue1.SetValue(pStats->GetValue1());
               break;
            }
         }
      }

      // Recover the operator

      for (i = 0; i < m_cbOperator.GetCount(); i++)
      {
         if ((int)m_cbOperator.GetItemData(i) == pStats->GetStatistic())
         {
            m_cbOperator.SetCurSel(i);
            break;
         }
      }

      // Recover the second attribute

      for (i = 0; i < m_cbAttr2.GetCount(); i++)
      {         
         CQueryElement* pElement = (CQueryElement*)m_cbAttr2.GetItemDataPtr(i);

         if (pElement != NULL)
         {
            if (pElement->GetAttrId() == pStats->GetAttrId2() &&
                pElement->GetFTypeId() == pStats->GetFTypeId2())
            {
               m_cbAttr2.SetCurSel(i);
               break;
            }             
         } 
         else
         {
            if (pStats->GetAttrId2() == 0)
            {
               m_cbAttr2.SetCurSel(i);
               m_eValue2.SetValue(pStats->GetValue2());
               break;
            }
         }

      }

      // Recover the name of the statistic

      m_eStatsName.SetWindowText(pStats->GetDesc());

      // Recover the number of decimal places

      m_eDecPlaces.SetValue(pStats->GetDecPlaces());

      // Reset window enabled status

      OnSelchange();
   }
	
}

/////////////////////////////////////////////////////////////////////////////
// CPageQueryCalc message handlers

BOOL CPageQueryCalc::OnSetActive() 
{
   Update();
   UpdateOperators();
	
	return CPropertyPage::OnSetActive();
}

/////////////////////////////////////////////////////////////////////////////

void CPageQueryCalc::OnAdd() 
{
   CQueryStats stats;
   CString sName;

   stats.SetDataType(BDQUERYSTATS);

  // Get First Attribute

   int index = m_cbAttr1.GetCurSel();
   if (index != CB_ERR)
   {
      if (m_cbAttr1.GetItemDataPtr(index) != NULL)
      {
         CQueryElement* pElement = (CQueryElement*)m_cbAttr1.GetItemDataPtr(index);
         stats.SetFTypeId(pElement->GetFTypeId());
         stats.SetAttrId(pElement->GetAttrId());
      } else

⌨️ 快捷键说明

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