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

📄 stationform.cpp

📁 很优秀的公交查询软件
💻 CPP
字号:
// StationForm.cpp
//
// This file implements the main form for
// your application.

#include "Common.h"
#include "StationForm.h"
#include "BusAllApp.h"
#include "AboutDialog.h"
#include "PrefsDialog.h"
#include "ArrayPopupTrigger.h"
#include "OpenDatabase.h"

// Form open handler
Boolean CStationForm::OnOpen(EventPtr pEvent, Boolean& bHandled)
{
	{
		CBusAllApp* pApp = CBusAllApp::GetInstance();
		CBusDB* pBusDB = pApp->GetDatabase();
		SetTitle((const Char*)pBusDB->GetCityName());

	}
//attach the Swtich PopupTrigger
	m_popupSwitch.Attach(StationSwitchPopupTrigger, StationSwitchList);
	m_popupSwitch.SetItemCount(3);
	m_popupSwitch.SetSelection(0);

	m_gridRouteResult.Init();

	m_popupRouteResult.Attach(StationRouteResultPopupTrigger, StationRouteResultList);
	m_popupRouteResult.Clear();

	SetFocus(StationStationField);

	UInt8	iFound = 0;
	CLabel lbl(StationResultLabel);
	CString lbls;
	lbls.Format("找到%2d: ", iFound);
	lbl.CopyLabel((const Char*)lbls);

	Boolean b;
	OnClear(NULL, b);

//if found that this open method is from go, get the string and clear it	
	CBusAllApp* pApp = CBusAllApp::GetInstance();
	if ("" != pApp->GetGoStation()) {
		CField fldStationStation(StationStationField);
		fldStationStation.Replace(pApp->GetGoStation());
		pApp->SetGoStation("");
		Boolean b;
		OnSearch(NULL, b);
	}
	
	bHandled = false;
	return true;
}

// About command handler
Boolean CStationForm::OnAbout(EventPtr pEvent, Boolean& bHandled)
{
	CAboutDialog frmAbout;
	frmAbout.DoModal();
	return true;
}

// Preferences command handler
Boolean CStationForm::OnPreferences(EventPtr pEvent, Boolean& bHandled)
{
	CPrefsDialog frmPreferences;

	// TODO: add code to set controls in preference form

	if (frmPreferences.DoModal())
	{
		// TODO: add code to read data out of controls
	}
	
	return true;
}

Boolean CStationForm::OnOpenDatabase(EventType* pEvent, Boolean& bHandled)
{
	CForm::GotoForm(OpenDatabaseForm);
	return true;
}


void CStationForm::SetGridRouteResultSelected(UInt8 iSel)
{

	CBusAllApp* pApp = CBusAllApp::GetInstance();
	CBusDB* pBusDB = pApp->GetDatabase();

	CArray<CBusDB::CStationRouteData>* parr = 
		pBusDB->GetStationData(m_popupRouteResult.GetDataInt(iSel));
	m_gridRouteResult.Clear();
	for (int i = 0; i < parr->GetCount(); i++) {
		m_gridRouteResult.Add(
				pBusDB->GetRouteName(parr->GetAt(i).Index),
				parr->GetAt(i).Dir,
				parr->GetAt(i).StationIndex);
	}
	m_gridRouteResult.SetRowCount(parr->GetCount());
}

Boolean CStationForm::OnClear(EventPtr pEvent, Boolean& bHandled)
{
	CField fldStationStation(StationStationField);
	fldStationStation.Replace("");
	
	UInt8	iFound = 0;
	CLabel lbl(StationResultLabel);
	CString lbls;
	lbls.Format("找到%2d: ", iFound);
	lbl.CopyLabel((const Char*)lbls);
	
	m_popupRouteResult.Clear();
	
	m_gridRouteResult.Clear();
	
	return true;	
}

Boolean CStationForm::OnSearch(EventPtr pEvent, Boolean& bHandled)
{
	CField fldStationStation(StationStationField);
	if (0 == fldStationStation.GetTextLength())
		return true;
	CString strForSearch(fldStationStation.GetTextPtr());
	
	CBusAllApp* pApp = CBusAllApp::GetInstance();
	CBusDB* pBusDB = pApp->GetDatabase();

	
	UInt16 iVeryMatch = -1;
	UInt16 iFound = 0;
	

	m_popupRouteResult.Clear();
	CLabel lbl(StationResultLabel);
	CString lbls;
	lbls.Format("找到%2d: ", iFound);
	lbl.CopyLabel((const Char*)lbls);
	m_gridRouteResult.Clear();

	CString s;
	for (int i = 0; i < pBusDB->GetStationCount(); i++) {
		s = pBusDB->GetStationName(i);
		if (-1 != s.FindNoCase((const Char*)strForSearch)) {
			iFound++;
			m_popupRouteResult.Add(s, i);
			if (s.GetLength() == strForSearch.GetLength()) {
				iVeryMatch = iFound - 1;
			}
		}
	}
	
	if (0 != iFound) {
		if (-1 == iVeryMatch)
			iVeryMatch = 0;
		m_popupRouteResult.SetSelection(iVeryMatch);
		SetGridRouteResultSelected(iVeryMatch);
		
		
		CLabel lbl(StationResultLabel);
		CString lbls;
		lbls.Format("找到%2d: ", iFound);
		lbl.CopyLabel((const Char*)lbls);
	}
	return true;	
	
}


Boolean CStationForm::OnSelectItem(CCustomPopupTrigger::EventPtr pEvent, Boolean& bHandled)
{
	switch (pEvent->data.popSelect.listID) {
	case StationSwitchList:
		switch (pEvent->data.popSelect.selection) {
//		case 0:
//			CForm::GotoForm(StationForm);
//			break;
		case 1:
			CForm::GotoForm(RouteForm);
			break;
		case 2:
			CForm::GotoForm(TwoSToLForm);
			break;
		}
		break;
	case StationRouteResultList:
		SetGridRouteResultSelected(pEvent->data.popSelect.selection);
		break;	
	}
/*
	CString strText;
	strText.Format("Selected Item: %d", pEvent->data.popSelect.listID);
	FrmCustomAlert(InfoAlert, strText, "", "");
*/	
	return true;
	
}

Boolean CStationForm::OnGo(EventPtr pEvent, Boolean& bHandled)
{
	if (-1 == m_gridRouteResult.GetSelection()) {
		FrmCustomAlert(WarningAlert, "请先选择一个", "路线", "再转!");
		
		return true;
	}
		
	CBusAllApp* pApp = CBusAllApp::GetInstance();
	
	pApp->SetGoRoute(m_gridRouteResult.GetItemString(m_gridRouteResult.GetSelection()));
	pApp->SetGoRouteDir((CBusDB::DIR_TYPE)m_gridRouteResult.GetItemInt(m_gridRouteResult.GetSelection()));
	CForm::GotoForm(RouteForm);
	
	return true;
}



⌨️ 快捷键说明

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