querydlg.cpp

来自「用VC+SuperMap开发的校园GIS系统」· C++ 代码 · 共 129 行

CPP
129
字号
// QueryDlg.cpp : implementation file
//

#include "stdafx.h"
#include "CampusGis.h"
#include "QueryDlg.h"
#include "solayers.h"
#include "solayer.h"
#include "sodataset.h"
#include "soDatasetVector.h"
#include "sorecordset.h"
#include "soselection.h"

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

/////////////////////////////////////////////////////////////////////////////
// CQueryDlg dialog


CQueryDlg::CQueryDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CQueryDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CQueryDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}


void CQueryDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CQueryDlg)
	DDX_Control(pDX, IDOK, m_Ok);
	DDX_Control(pDX, IDCANCEL, m_Cancel);
	DDX_Control(pDX, IDC_LAYERNAME, m_LayerName);
	DDX_Control(pDX, IDC_EDIT, m_txtQuery);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CQueryDlg, CDialog)
	//{{AFX_MSG_MAP(CQueryDlg)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()




void CQueryDlg::OnOK() 
{
	//从图层名称和查询条件查找地图中相应的集合
	//对象,并在地图窗口中显示出来
	CString strQueryText,strLayerName;
	IDispatch *ar = NULL;
	char *temp = NULL;

	GetDlgItemText(IDC_EDIT,strQueryText);
	GetDlgItemText(IDC_LAYERNAME,strLayerName);	
	//取得相应图层的数据集并进行查询
	CsoLayers layers=m_pSupermap->GetLayers();
	if(!layers.GetCount())
	{
		AfxMessageBox("地图窗口中不存在图层,不能进行查询!",MB_ICONINFORMATION);
		return;
	}
	CsoLayer layer=layers.GetItem(COleVariant(strLayerName));
	CsoDataset dataset=layer.GetDataset();
	if(!dataset.GetVector())
	{
		AfxMessageBox("该图层不是矢量图层,不能进行查询!",MB_ICONINFORMATION);
		return;
	}
	//取矢量数据集,第二个参数为false,防止objDt 被释放
	CsoDatasetVector datasetVector;
	datasetVector.AttachDispatch(dataset,false);
	
	CsoRecordset recordset=datasetVector.Query(strQueryText,FALSE,ar,temp);
	if(recordset.IsEmpty())
	{
		AfxMessageBox("查找不到满足条件的记录!",MB_ICONINFORMATION);
		return;
	}
	//把查到的数据加入到选择集中(使其呈被选中状态)
	m_pSupermap->GetSelection ().FromRecordset(recordset);
	//刷新地图窗口并关闭Recordset
	recordset.Close();
	m_pSupermap->Refresh();
	//将焦点移到查询条件文本框
	m_txtQuery.SetFocus();

	return;
}

void CQueryDlg::OnCancel() 
{
	// TODO: Add extra cleanup here
	
	CDialog::ShowWindow(SW_HIDE);
}

void CQueryDlg::SetParentSupermap(CSuperMap *pSupermap)
{
	m_pSupermap=pSupermap;
}

void CQueryDlg::RefreshContent()
{
	CsoLayer layer;
	if(!m_pSupermap)
		return;
	CsoLayers layers=m_pSupermap->GetLayers();
	long lLayercount=layers.GetCount();
	if(!lLayercount)
		return;
	//将地图窗口的图层名称添加到列表中
	m_LayerName.Clear();

	for(long i=1; i<=lLayercount; i++)
	{
		layer=layers.GetItem(COleVariant(i));
		m_LayerName.AddString(layer.GetName());
	}
	m_txtQuery.SetFocus();
}

⌨️ 快捷键说明

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