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

📄 twostolform.cpp

📁 很优秀的公交查询软件
💻 CPP
字号:
#include "Common.h"
#include "TwoSToLForm.h"
#include "BusAllApp.h"
#include "AboutDialog.h"
#include "PrefsDialog.h"
#include "ArrayPopupTrigger.h"
#include "OpenDatabase.h"

// Form open handler
Boolean CTwoSToLForm::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(TwoSToLSwitchPopupTrigger, TwoSToLSwitchList);
	m_popupSwitch.SetItemCount(3);
	m_popupSwitch.SetSelection(2);

	m_gridTwoSToLResult.Init();
	SetFocus(TwoSToLStationSField);


	Boolean b;
	OnClear(NULL, b);

	bHandled = false;
	return true;
}

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

// Preferences command handler
Boolean CTwoSToLForm::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 CTwoSToLForm::OnOpenDatabase(EventType* pEvent, Boolean& bHandled)
{
	CForm::GotoForm(OpenDatabaseForm);
	return true;
}


Boolean CTwoSToLForm::OnSelectItem(CCustomPopupTrigger::EventPtr pEvent, Boolean& bHandled)
{
	switch (pEvent->data.popSelect.listID) {
	case TwoSToLSwitchList:
		switch (pEvent->data.popSelect.selection) {
		case 0:
			CForm::GotoForm(StationForm);
			break;
		case 1:
			CForm::GotoForm(RouteForm);
			break;
//		case 2:
//			CForm::GotoForm(TwoSToLForm);
//			break;
		}
		break;
	}
	return true;
	
}

Boolean CTwoSToLForm::OnClear(EventPtr pEvent, Boolean& bHandled)
{
	CField fldTwoSToLStationS(TwoSToLStationSField);
	fldTwoSToLStationS.Replace("");
	CField fldTwoSToLStationE(TwoSToLStationEField);
	fldTwoSToLStationE.Replace("");
	
	m_gridTwoSToLResult.Clear();
	
	return true;	
}

Boolean CTwoSToLForm::OnGoS(EventPtr pEvent, Boolean& bHandled)
{
	if (-1 == m_gridTwoSToLResult.GetSelection()) {
		FrmCustomAlert(WarningAlert, "请先选择一个", "起始站", "再转!");
		
		return true;
	}
		
	CBusAllApp* pApp = CBusAllApp::GetInstance();
	pApp->SetGoStation(
		m_gridTwoSToLResult.GetItemStationS(m_gridTwoSToLResult.GetSelection()));
	CForm::GotoForm(StationForm);
	
	return true;
}

Boolean CTwoSToLForm::OnGoE(EventPtr pEvent, Boolean& bHandled)
{
	if (-1 == m_gridTwoSToLResult.GetSelection()) {
		FrmCustomAlert(WarningAlert, "请先选择一个", "将到站", "再转!");
		
		return true;
	}
		
	CBusAllApp* pApp = CBusAllApp::GetInstance();
	pApp->SetGoStation(
		m_gridTwoSToLResult.GetItemStationE(m_gridTwoSToLResult.GetSelection()));
	CForm::GotoForm(StationForm);
	
	return true;
}

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

Boolean CTwoSToLForm::OnSearch(EventPtr pEvent, Boolean& bHandled)
{
//get the start station search str
	CField fldTwoSToLStationS(TwoSToLStationSField);
	if (0 == fldTwoSToLStationS.GetTextLength())
		return true;
	CString strForSearchS(fldTwoSToLStationS.GetTextPtr());
	
//get the end station search str	
	CField fldTwoSToLStationE(TwoSToLStationEField);
	if (0 == fldTwoSToLStationE.GetTextLength())
		return true;
	CString strForSearchE(fldTwoSToLStationE.GetTextPtr());
	
//get database	
	CBusAllApp* pApp = CBusAllApp::GetInstance();
	CBusDB* pBusDB = pApp->GetDatabase();

	CString s;
//found the station name match the start search str
//put it in a array
	UInt16 aStationResultS[STATIONRESULTLIMIT + 1];	
	UInt16 iFoundS = 0;
	for (int i = 0; i < pBusDB->GetStationCount(); i++) {
		s = pBusDB->GetStationName(i);
		if (-1 != s.FindNoCase((const Char*)strForSearchS)) {
			aStationResultS[iFoundS] = i;
			iFoundS++;
			if (STATIONRESULTLIMIT == iFoundS) {
				FrmCustomAlert(WarningAlert, "开始站点查询结果超出,请增加关键字长度", "", "");
				return true;				
			}
		}
	}

//found the end station
	UInt16 aStationResultE[STATIONRESULTLIMIT + 1];	
	UInt16 iFoundE = 0;
	for (int i = 0; i < pBusDB->GetStationCount(); i++) {
		s = pBusDB->GetStationName(i);
		if (-1 != s.FindNoCase((const Char*)strForSearchE)) {
			aStationResultE[iFoundE] = i;
			iFoundE++;
			if (STATIONRESULTLIMIT == iFoundE) {
				FrmCustomAlert(WarningAlert, "结束站点查询结果超出,请增加关键字长度", "", "");
				return true;				
			}
		}
	}

//now they are store in aStationResultS and aStationResultE
//check out the route go through the aStationResult, and find the same

	UInt16 iS, iE, iSa, iEa;
	CArray<CBusDB::CStationRouteData>* parr;
	CArray<CBusDB::CStationRouteData> arrS;
	CArray<CBusDB::CStationRouteData> arrE;
	CBusDB::CStationRouteData arrRDS;
	CBusDB::CStationRouteData arrRDE;

//clear the display
	m_gridTwoSToLResult.Clear();
	for (iS = 0; iS < iFoundS; iS++) {
		for (iE = 0; iE < iFoundE; iE++) {
			//for all start station, get the route go through them
			//store then
			//the parr is point, so copy it out
			//clear the array
			arrS.DeleteAll();
			parr = pBusDB->GetStationData(aStationResultS[iS]);
			for (int i = 0; i < parr->GetCount(); i++) {
				CBusDB::CStationRouteData& srd = arrS.Add();
				srd = parr->GetAt(i);
			}
			
			//clear the array
			arrE.DeleteAll();
			parr = pBusDB->GetStationData(aStationResultE[iE]);
			for (int i = 0; i < parr->GetCount(); i++) {
				CBusDB::CStationRouteData& srd = arrE.Add();
				srd = parr->GetAt(i);
			}

			parr = pBusDB->GetStationData(aStationResultE[iE]);
			for (iSa = 0; iSa < arrS.GetCount(); iSa++) {
				for (iEa = 0; iEa < arrE.GetCount(); iEa++) {
					arrRDS = arrS.GetAt(iSa);
					arrRDE = arrE.GetAt(iEa);
					if ((arrRDS.Index == arrRDE.Index) 
						&& (arrRDS.Dir == arrRDE.Dir)
						&& (arrRDS.StationIndex < arrRDE.StationIndex)) { 
						//we found the route which go through 2 station
						//store it
//						iS, iE, parrRDS->Index, parrRDS.StationIndex, parrRDS.StationIndex

						m_gridTwoSToLResult.Add(
									(const Char*)pBusDB->GetStationName(aStationResultS[iS]),
									(const Char*)pBusDB->GetStationName(aStationResultE[iE]),
									(const Char*)pBusDB->GetRouteName(arrRDS.Index), 
									arrRDS.Dir, 
									arrRDE.StationIndex - arrRDS.StationIndex);
									
					}		
				}			
			}
		}
	}	
	m_gridTwoSToLResult.SyncRowCount();
	return true;	
	
}


⌨️ 快捷键说明

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