📄 busstationquerydlg.cpp
字号:
// BusStationQueryDlg.cpp : implementation file
//
#include "stdafx.h"
#include "BusQuery.h"
#include "BusStationQueryDlg.h"
#include "DB_Func.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern SQLHENV henv;
extern SQLHDBC hdbc;
extern SQLHSTMT hstmt;
/////////////////////////////////////////////////////////////////////////////
// CBusStationQueryDlg dialog
CBusStationQueryDlg::CBusStationQueryDlg(CWnd* pParent /*=NULL*/)
: CDialog(CBusStationQueryDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CBusStationQueryDlg)
m_String_StationName = _T("");
m_String_StationType = _T("");
//}}AFX_DATA_INIT
}
void CBusStationQueryDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CBusStationQueryDlg)
DDX_Control(pDX, IDC_STATION_QUERY_COMBO_STATIOM, m_ComboBox_StationType);
DDX_Control(pDX, IDC_STATION_QUERY_LISTBOX_ROUTE_INF, m_ListBox_RouteInfor);
DDX_Control(pDX, IDC_STATION_QUERY_LISTBOX_ROUTE_INFOR, m_ListBox_RouteAllInfor);
DDX_Control(pDX, IDC_STATION_QUERY_LISTBOX_STATION, m_ListBox_Station);
DDX_Control(pDX, IDC_STATION_QUERY_LISTBOX_ROUTE_NAME, m_ListBox_BusName);
DDX_Text(pDX, IDC_STATION_QUERY_STATIONNAME, m_String_StationName);
DDX_CBString(pDX, IDC_STATION_QUERY_COMBO_STATIOM, m_String_StationType);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CBusStationQueryDlg, CDialog)
//{{AFX_MSG_MAP(CBusStationQueryDlg)
ON_LBN_SELCHANGE(IDC_STATION_QUERY_LISTBOX_STATION, OnSelchangeStationQueryListboxStation)
ON_LBN_SELCHANGE(IDC_STATION_QUERY_LISTBOX_ROUTE_NAME, OnSelchangeStationQueryListboxRouteName)
ON_BN_CLICKED(IDC_STATION_QUERY_QUERY_ENTER, OnStationQueryQueryEnter)
ON_CBN_SELCHANGE(IDC_STATION_QUERY_COMBO_STATIOM, OnSelchangeStationQueryComboStatiom)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CBusStationQueryDlg message handlers
BOOL CBusStationQueryDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
CRect rc(0, 0, 0, 0);
GetParent()->GetClientRect(&rc);
((CTabCtrl*)GetParent())->AdjustRect(false, &rc);
MoveWindow(&rc);
//////////////////////////////////////////////////////////////////////////
m_station_hanghao = 0;
m_route_hanghao = 0;
// 初始化站点列表
CBusStationQueryDlg::StationInforQuery();
// 初始化站点类型
CBusStationQueryDlg::StationTypeQuery();
m_String_StationType = "站点类型";
UpdateData(FALSE);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CBusStationQueryDlg::OnCancel()
{
// TODO: Add your message handler code here and/or call default
return;
}
void CBusStationQueryDlg::OnOK()
{
// TODO: Add your message handler code here and/or call default
return;
}
//////////////////////////////////////////////////////////////////////////
void CBusStationQueryDlg::StationInforQuery()
{
// TODO: Add your message handler code here and/or call default
//---------------- 查询站点信息 ----------------//
//初始化变量
STATION_INFOR station_infor;
STATION_INFOR *station_infor_head;
station_infor_head = new STATION_INFOR;
memset(&station_infor, 0, sizeof(STATION_INFOR));
memset(station_infor_head,0, sizeof(STATION_INFOR));
//查询信息
int rv;
rv = DB_STATION_INFOR_Query(hstmt,&station_infor,station_infor_head);
if( rv != 0 )
{
AfxMessageBox("数据库中无信息,请添加信息!");
delete station_infor_head;
return ;
}
// 列表显示
m_ListBox_Station.ResetContent();
STATION_INFOR *pTemp_staiton;
while( station_infor_head != NULL )
{
pTemp_staiton = station_infor_head;
m_ListBox_Station.AddString(pTemp_staiton->Station_Name);
station_infor_head = station_infor_head->next;
delete pTemp_staiton;
}
return;
}
void CBusStationQueryDlg::StationTypeQuery()
{
CString str;
m_ComboBox_StationType.ResetContent();
str = "全部";
m_ComboBox_StationType.AddString(str);
//************* 查询所有站点类型 *************//
// 初始化变量
STATION_TYPE staiton_type;
STATION_TYPE *staiton_type_head;
staiton_type_head = new STATION_TYPE;
memset(&staiton_type, 0, sizeof(STATION_TYPE));
memset(staiton_type_head, 0, sizeof(STATION_TYPE));
// 查询
int rv;
rv = DB_STATION_TYPE_Query(hstmt, &staiton_type, staiton_type_head);
if( rv != 0 )
{
delete staiton_type_head;
return ;
}
// 列表显示
STATION_TYPE *pTemp_staiton;
while( staiton_type_head != NULL )
{
pTemp_staiton = staiton_type_head;
str = pTemp_staiton->Station_Type_Name;
m_ComboBox_StationType.AddString(str);
staiton_type_head = staiton_type_head->next;
delete pTemp_staiton;
}
}
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
void CBusStationQueryDlg::OnSelchangeStationQueryListboxStation()
{
// TODO: Add your control notification handler code here
m_station_hanghao = m_ListBox_Station.GetCurSel();
m_ListBox_Station.GetText(m_station_hanghao,m_String_StationName);
UpdateData(FALSE);
}
void CBusStationQueryDlg::OnSelchangeStationQueryListboxRouteName()
{
// TODO: Add your control notification handler code here
m_route_hanghao = m_ListBox_BusName.GetCurSel();
CString strBusNumber;
m_ListBox_BusName.GetText(m_route_hanghao,strBusNumber);
ShowOnRouteList(strBusNumber);
}
void CBusStationQueryDlg::OnSelchangeStationQueryComboStatiom()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
int num = m_ComboBox_StationType.GetCurSel();
if( num < 0 )
{
AfxMessageBox("请先选定站点类型!");
return;
}
m_ComboBox_StationType.GetLBText(num, m_String_StationType);
UpdateData(FALSE);
if(m_String_StationType=="全部")
{
CBusStationQueryDlg::StationTypeQuery();
return;
}
//---------------- 查询站点信息 ----------------//
// 获取查询条件
char station_type[24];
memset(station_type, 0, 24);
strcpy(station_type, m_String_StationType);
//初始化变量
STATION_INFOR station_infor;
STATION_INFOR *station_infor_head;
station_infor_head = new STATION_INFOR;
memset(&station_infor, 0, sizeof(STATION_INFOR));
memset(station_infor_head,0, sizeof(STATION_INFOR));
//查询信息
int rv;
rv = DB_STATION_INFOR_Query_StationName(hstmt,&station_infor,station_infor_head, station_type);
if( rv != 0 )
{
AfxMessageBox("数据库中无此类信息!");
delete station_infor_head;
return ;
}
// 列表显示
m_ListBox_Station.ResetContent();
STATION_INFOR *pTemp_staiton;
while( station_infor_head != NULL )
{
pTemp_staiton = station_infor_head;
m_ListBox_Station.AddString(pTemp_staiton->Station_Name);
station_infor_head = station_infor_head->next;
delete pTemp_staiton;
}
return;
}
//
//////////////////////////////////////////////////////////////////////////
void CBusStationQueryDlg::OnStationQueryQueryEnter()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
if(m_String_StationName.GetLength() == 0)
{
AfxMessageBox("站点名称不能为空");
return;
}
ShowStionInforInList(m_String_StationName);
}
//////////////////////////////////////////////////////////////////////////
void CBusStationQueryDlg::ShowStionInforInList(CString strStationName)
{
m_ListBox_BusName.ResetContent();
// 查信变量
char station_name[24];
memset(station_name, 0 ,24);
strcpy(station_name, strStationName);
// 站点信息
char bus_number[128];
CString str;
char temp[8];
memset(bus_number, 0, 128);
m_ListBox_RouteAllInfor.ResetContent();
int rv;
rv = DB_STATION_INFOR_Query_BusNumber(hstmt,station_name, bus_number); // 读取原站点信息
if( rv != 0)
{
AfxMessageBox("读取原站点信息错误!");
return;
}
// 显示信息
BUS_INFOR bus_infor;
BUS_INFOR *bus_infor_head;
int k=0;
for(int i=0; i<128; i++)
{
if(bus_number[i] == '1')
{
k=1;
itoa(i+1, temp, 10);
str = temp;
m_ListBox_BusName.AddString(str);
//初始化变量
bus_infor_head = new BUS_INFOR;
memset(&bus_infor, 0, sizeof(BUS_INFOR));
memset(bus_infor_head,0, sizeof(BUS_INFOR));
//----查询信息
rv = DB_BUS_INFOR_Query_BusNumber(hstmt, &bus_infor, bus_infor_head, i+1);
if( rv != 0 )
{
AfxMessageBox("读取路线信息错误!");
return;
}
// 显示信息
ShowRouteInfor(bus_infor_head, &m_ListBox_RouteAllInfor, 60);
str = " ";
m_ListBox_RouteAllInfor.AddString(str);
}
}
if(i==0)
{
AfxMessageBox("此站点无车次信息!");
}
}
void CBusStationQueryDlg::ShowOnRouteList(CString strBusNumber)
{
m_ListBox_RouteInfor.ResetContent();
//
//---获取查询条件
int bus_number;
char temp[8];
memset(temp, 0, 8);
strcpy(temp, strBusNumber);
bus_number = atoi(temp);
//初始化变量
BUS_INFOR bus_infor;
BUS_INFOR *bus_infor_head;
bus_infor_head = new BUS_INFOR;
memset(&bus_infor, 0, sizeof(BUS_INFOR));
memset(bus_infor_head,0, sizeof(BUS_INFOR));
//----查询信息
int rv;
rv = DB_BUS_INFOR_Query_BusNumber(hstmt, &bus_infor, bus_infor_head,bus_number);
if( rv != 0 )
{
AfxMessageBox("无此线路公交车,请确认!");
return;
}
// 显示信息
m_ListBox_RouteInfor.ResetContent();
ShowRouteInfor(bus_infor_head, &m_ListBox_RouteInfor, 72);
}
void CBusStationQueryDlg::ShowRouteInfor(BUS_INFOR *bus_infor_head, CListBox *m_List, int listLen)
{
BUS_INFOR *p;
CString str,strR;
char temp[8];
char tempRoute[80];
int nSign,routeLen;
while ( bus_infor_head != NULL )
{
p = bus_infor_head;
//
itoa(p->Bus_Number, temp, 10);
str = temp;
str = "-------------------------- "+str+"路"+" ------------------------------";
m_List->AddString(str);
str = temp;
str = str+"路:";
strR = p->Bus_Type_Name;
str = str+strR;
if( p->Bus_Ticket == 0 )
{
strR = ",有月票";
}
else
{
strR = ",无月票";
}
str = str+strR;
strR = p->Bus_Remark;
str = str+","+strR;
m_List->AddString(str);
nSign = 0;
routeLen = strlen(p->Bus_Route);
while( (routeLen-nSign) > 0 )
{
memset(tempRoute, 0 ,listLen);
if( (routeLen-listLen) >= 0)
{
strncpy(tempRoute, &p->Bus_Route[nSign], listLen);
tempRoute[listLen] = '\0';
}
else
{
strncpy(tempRoute, &p->Bus_Route[nSign], routeLen-nSign);
tempRoute[listLen] = '\0';
}
//
str = tempRoute;
str = " "+str;
m_List->AddString(str);
//
nSign = nSign+listLen;
}
//
bus_infor_head = bus_infor_head->next;
delete p;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -