📄 routeform.cpp
字号:
#include "Common.h"
#include "RouteForm.h"
#include "BusAllApp.h"
#include "AboutDialog.h"
#include "PrefsDialog.h"
#include "ArrayPopupTrigger.h"
// Form open handler
Boolean CRouteForm::OnOpen(EventPtr pEvent, Boolean& bHandled)
{
{
CBusAllApp* pApp = CBusAllApp::GetInstance();
CBusDB* pBusDB = pApp->GetDatabase();
SetTitle((const Char*)pBusDB->GetCityName());
}
m_bCompact = false;
if (m_bCompact) {
CPushButton pb1(RouteCompactPushButton);
pb1.SetValue(1);
} else {
CPushButton pb1(RouteListPushButton);
pb1.SetValue(1);
}
//attach the Swtich PopupTrigger
m_popupSwitch.Attach(RouteSwitchPopupTrigger, RouteSwitchList);
m_popupSwitch.SetItemCount(3);
m_popupSwitch.SetSelection(1);
m_gridStationResult.Attach(RouteStationResultTable, RouteStationResultVScrollBar);
m_gridStationResult.SetGridMode(CGrid::GM_FULLROWSELECT);
m_gridStationResult.SetDrawStyle(CGrid::DS_ALL | CGrid::DS_GRAYLINES);
m_gridStationResult.SetIgnoreFocus(true);
m_gridStationResult.DeleteAllRows();
m_meoStationResult.Attach(RouteStationResultField, RouteStationResult2VScrollBar);
m_meoStationResult.Replace("");
/*
CString strText1, strText2;
for (int i = 0; i < -1; i++) {
strText1.Format("%d", i + 1);
strText2.Format("%s", "station names");
m_gridStationResult.AddRowE(-1, (const Char*)strText1, (const Char*)strText2);
}
*/
m_popupRouteResult.Attach(RouteRouteResultPopupTrigger, RouteRouteResultList);
m_popupRouteResult.Clear();
SetFocus(RouteRouteField);
Boolean b;
OnClear(NULL, b);
AdjustListAndCompact();
//if found that this open method is from go, get the string and clear it
CBusAllApp* pApp = CBusAllApp::GetInstance();
m_DirType = CBusDB::DIR_UP;
if ("" != pApp->GetGoRoute())
m_DirType = pApp->GetGoRouteDir();
if (CBusDB::DIR_UP == m_DirType) {
CPushButton pb1(RouteUpDirPushButton);
pb1.SetValue(1);
} else {
CPushButton pb1(RouteDownDirPushButton);
pb1.SetValue(1);
}
if ("" != pApp->GetGoRoute()) {
CField fldRouteRoute(RouteRouteField);
fldRouteRoute.Replace(pApp->GetGoRoute());
pApp->SetGoRoute("");
Boolean b;
OnSearch(NULL, b);
}
bHandled = false;
return true;
}
void CRouteForm::AdjustListAndCompact()
{
if (m_bCompact) {
m_gridStationResult.HideGrid();
m_meoStationResult.ShowMemo();
} else {
m_meoStationResult.HideMemo();
m_gridStationResult.ShowGrid();
}
}
// About command handler
Boolean CRouteForm::OnAbout(EventPtr pEvent, Boolean& bHandled)
{
CAboutDialog frmAbout;
frmAbout.DoModal();
return true;
}
// Preferences command handler
Boolean CRouteForm::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 CRouteForm::OnClear(EventPtr pEvent, Boolean& bHandled)
{
CField fldRouteRoute(RouteRouteField);
fldRouteRoute.Replace("");
CString lbls;
lbls.Format("%2d: ", 0);
CLabel lbl(RouteResultLabel);
lbl.CopyLabel(lbls);
m_gridStationResult.DeleteAllRows();
m_meoStationResult.Replace("");
m_popupRouteResult.Clear();
return true;
}
void CRouteForm::SetGridRouteResultSelected(Int8 iSel)
{
CBusAllApp* pApp = CBusAllApp::GetInstance();
CBusDB* pBusDB = pApp->GetDatabase();
CArray<UInt16>* parr =
pBusDB->GetRouteData(m_popupRouteResult.GetDataInt(iSel) + ((CBusDB::DIR_UP == m_DirType)? 0: 1));
m_gridStationResult.DeleteAllRows();
CString strText1;
// CString strText2;
CString strMemo;
UInt16 iCount = parr->GetCount();
for (int i = 0; i < iCount; i++) {
strText1.Format("%d", i + 1);
// strText2.Format("%d", parr->GetAt(i));
m_gridStationResult.AddRowE(-1,
(const Char*)strText1,
(const Char*)pBusDB->GetStationName(parr->GetAt(i)));
// (const Char*)strText2);
strMemo = strMemo + pBusDB->GetStationName(parr->GetAt(i));
if (i != (iCount - 1))
strMemo = strMemo + "*";
}
m_meoStationResult.Replace((const Char*)strMemo);
}
Boolean CRouteForm::OnSelectItem(CCustomPopupTrigger::EventPtr pEvent, Boolean& bHandled)
{
switch (pEvent->data.popSelect.listID) {
case RouteSwitchList:
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 RouteRouteResultList:
SetGridRouteResultSelected(pEvent->data.popSelect.selection);
break;
}
return true;
}
Boolean CRouteForm::OnSearch(EventPtr pEvent, Boolean& bHandled)
{
CField fldRouteRoute(RouteRouteField);
CString strForSearch(fldRouteRoute.GetTextPtr());
CBusAllApp* pApp = CBusAllApp::GetInstance();
CBusDB* pBusDB = pApp->GetDatabase();
CString lbls;
lbls.Format("%2d: ", 0);
CLabel lbl(RouteResultLabel);
lbl.CopyLabel(lbls);
m_popupRouteResult.Clear();
m_gridStationResult.DeleteAllRows();
m_meoStationResult.Replace("");
UInt16 iVeryMatch = -1;
UInt16 iFound = 0;
//Up and Down only show one
CString s;
for (int i = 0; i < pBusDB->GetRouteCount(); i++) {
s = pBusDB->GetRouteName(i);
if (CBusDB::DIR_UP != pBusDB->GetRouteDir(i))
continue;
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);
CString lbls;
lbls.Format("%2d: ", iFound);
CLabel lbl(RouteResultLabel);
lbl.CopyLabel(lbls);
}
return true;
}
Boolean CRouteForm::OnGo(EventPtr pEvent, Boolean& bHandled)
{
CString strForGo;
if (m_bCompact) {
CField fld(RouteStationResultField);
strForGo = fld.GetTextPtr();
UInt16 iS, iE;
fld.GetSelection(iS, iE);
if (iE == iS) {
FrmCustomAlert(WarningAlert, "请先选择一个", "站点", "再转!");
return true;
}
strForGo = strForGo.Mid(iS, iE - iS);
} else {
if (-1 == m_gridStationResult.GetSelection()) {
FrmCustomAlert(WarningAlert, "请先选择一个", "站点", "再转!");
return true;
}
strForGo = m_gridStationResult.GetItemText(m_gridStationResult.GetSelection(), 1);
}
CBusAllApp* pApp = CBusAllApp::GetInstance();
pApp->SetGoStation(strForGo);
CForm::GotoForm(StationForm);
return true;
}
Boolean CRouteForm::OnUpDir(EventPtr pEvent, Boolean& bHandled)
{
m_DirType = CBusDB::DIR_UP;
if (-1 != m_popupRouteResult.GetSelection())
SetGridRouteResultSelected(m_popupRouteResult.GetSelection());
return true;
}
Boolean CRouteForm::OnDownDir(EventPtr pEvent, Boolean& bHandled)
{
m_DirType = CBusDB::DIR_DOWN;
if (-1 != m_popupRouteResult.GetSelection())
SetGridRouteResultSelected(m_popupRouteResult.GetSelection());
return true;
}
Boolean CRouteForm::OnCompact(EventPtr pEvent, Boolean& bHandled)
{
m_bCompact = true;
AdjustListAndCompact();
return true;
}
Boolean CRouteForm::OnList(EventPtr pEvent, Boolean& bHandled)
{
m_bCompact = false;
AdjustListAndCompact();
return true;
}
Boolean CRouteForm::OnOpenDatabase(EventType* pEvent, Boolean& bHandled)
{
CForm::GotoForm(OpenDatabaseForm);
return true;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -