📄 placetwoquerydlg.cpp
字号:
// PlaceTwoQueryDlg.cpp : implementation file
//
#include "stdafx.h"
#include "BusQuery.h"
#include "PlaceTwoQueryDlg.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;
/////////////////////////////////////////////////////////////////////////////
// CPlaceTwoQueryDlg dialog
CPlaceTwoQueryDlg::CPlaceTwoQueryDlg(CWnd* pParent /*=NULL*/)
: CDialog(CPlaceTwoQueryDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CPlaceTwoQueryDlg)
m_String_BeginStation = _T("");
m_String_EndStation = _T("");
//}}AFX_DATA_INIT
}
void CPlaceTwoQueryDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CPlaceTwoQueryDlg)
DDX_Control(pDX, IDC_TWO_PLACE_ROUTE_LIST, m_ListBox_Route);
DDX_Control(pDX, IDC_TWO_PLACE_ROUTE_INFOR_LIST, m_ListBox_RouteInfor);
DDX_Control(pDX, IDC_TWO_PLACE_ENDSTATION, m_ComboBox_EndStation);
DDX_Control(pDX, IDC_TWO_PLACE_BEGINSTATION, m_ComboBox_BeginStation);
DDX_CBString(pDX, IDC_TWO_PLACE_BEGINSTATION, m_String_BeginStation);
DDX_CBString(pDX, IDC_TWO_PLACE_ENDSTATION, m_String_EndStation);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CPlaceTwoQueryDlg, CDialog)
//{{AFX_MSG_MAP(CPlaceTwoQueryDlg)
ON_BN_CLICKED(IDC_TWO_PLACE_ENTER, OnTwoPlaceEnter)
ON_LBN_SELCHANGE(IDC_TWO_PLACE_ROUTE_LIST, OnSelchangeTwoPlaceRouteList)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CPlaceTwoQueryDlg message handlers
BOOL CPlaceTwoQueryDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
CRect rc(0, 0, 0, 0);
GetParent()->GetClientRect(&rc);
((CTabCtrl*)GetParent())->AdjustRect(false, &rc);
MoveWindow(&rc);
//////////////////////////////////////////////////////////////////////////
// 初始化站点信息
CPlaceTwoQueryDlg::StationInforQuery();
//////////////////////////////////////////////////////////////////////////
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CPlaceTwoQueryDlg::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_ComboBox_BeginStation.ResetContent();
m_ComboBox_EndStation.ResetContent();
STATION_INFOR *pTemp_staiton;
while( station_infor_head != NULL )
{
pTemp_staiton = station_infor_head;
m_ComboBox_BeginStation.AddString(pTemp_staiton->Station_Name);
m_ComboBox_EndStation.AddString(pTemp_staiton->Station_Name);
station_infor_head = station_infor_head->next;
delete pTemp_staiton;
}
return;
}
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
void CPlaceTwoQueryDlg::OnCancel()
{
// TODO: Add your message handler code here and/or call default
return;
}
void CPlaceTwoQueryDlg::OnOK()
{
// TODO: Add your message handler code here and/or call default
return;
}
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
void CPlaceTwoQueryDlg::OnTwoPlaceEnter()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
if( m_String_BeginStation.IsEmpty() )
{
AfxMessageBox("起始站不能为空!");
return;
}
if( m_String_EndStation.IsEmpty() )
{
AfxMessageBox("终点站不能为空!");
return;
}
if( m_String_BeginStation == m_String_EndStation)
{
AfxMessageBox("起始站与终点站不能相同!");
return;
}
// 调用查询函数
m_ListBox_Route.ResetContent();
m_ListBox_RouteInfor.ResetContent();
TwoPlaceQuery(m_String_BeginStation, m_String_EndStation);
}
//////////////////////////////////////////////////////////////////////////
void CPlaceTwoQueryDlg::TwoPlaceQuery(CString strBeginStation, CString strEndStation)
{
// 查信变量
int rv = 0, i = 0, j = 0, k = 0;
int iSumBusNumber = 0;
int iSumBusStation = 0;
char cBusNumber[8];
char cBeginStation[64];
char cEndStation[64];
char cBeginBusNumber[128];
char cEndBusNumber[128];
CString str;
char cMiddleStation[64];
char cMiddleBusNumber[128];
char cMiddleStation1[64];
char cMiddleBusNumber1[128];
//
BUS_INFOR bus_infor;
BUS_INFOR *bus_infor_head = NULL;
BUS_INFOR *bus_infor_head_next = NULL;
memset(cBusNumber, 0 ,8);
memset(cBeginStation, 0 ,64);
memset(cEndStation, 0 ,64);
memset(cMiddleStation, 0 ,64);
memset(cMiddleBusNumber, 0 ,128);
memset(cMiddleStation1, 0 ,64);
memset(cMiddleBusNumber1, 0 ,128);
memset(cBeginBusNumber, 0 ,128);
memset(cEndBusNumber, 0 ,128);
memset(&bus_infor, 0, sizeof(BUS_INFOR));
strcpy(cBeginStation, strBeginStation);
strcpy(cEndStation, strEndStation);
//////////////////////////////////////////////////////////////////////////
iSumBusStation = m_ComboBox_BeginStation.GetCount();
if (iSumBusStation < 2)
{
return;
}
// 站点信息
rv = DB_STATION_INFOR_Query_BusNumber(hstmt,cBeginStation, cBeginBusNumber);
if( rv != 0)
{
AfxMessageBox("读取站点1信息错误!");
return;
}
rv = DB_STATION_INFOR_Query_BusNumber(hstmt,cEndStation, cEndBusNumber);
if( rv != 0)
{
AfxMessageBox("读取站点2信息错误!");
return;
}
//////////////////////////////////////////////////////////////////////////
for(i = 0; i < 127; i++)
{
if ((cBeginBusNumber[i] == '1') && (cEndBusNumber[i] == '1'))
{
// 显示信息
iSumBusNumber++;
str.Empty();
sprintf((char *)(LPCTSTR)str, "路线 %d: %s<--%d路-->%s", iSumBusNumber, cBeginStation, i+1, cEndStation);
m_ListBox_Route.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("读取路线信息错误!");
delete bus_infor_head;
return;
}
// 显示信息
ShowRouteInfor(bus_infor_head, &m_ListBox_RouteInfor, 60);
str.Empty();
str = " ";
m_ListBox_RouteInfor.AddString(str);
}
}
//////////////////////////////////////////////////////////////////////////
if (iSumBusNumber > 0)
{
return;
}
for (i = 0; i < iSumBusStation; i++)
{
str.Empty();
m_ComboBox_BeginStation.GetLBText(i, str);
memset(cMiddleStation, 0, 64);
strcpy(cMiddleStation, (char *)(LPCTSTR)str);
if(strcmp(cMiddleStation, cBeginStation) == 0)
{
continue;
}
if(strcmp(cMiddleStation, cEndStation) == 0)
{
continue;
}
// 站点信息
rv = DB_STATION_INFOR_Query_BusNumber(hstmt,cMiddleStation, cMiddleBusNumber);
if( rv != 0)
{
AfxMessageBox("读取站点3信息错误!");
return;
}
for(j = 0; j < 127; j++)
{
if ((cBeginBusNumber[j] == '0') || (cMiddleBusNumber[j] == '0'))
{
continue;
}
//
for (k = 0; k < 127; k++)
{
if (( k == j) || (cEndBusNumber[k] == '0') || (cMiddleBusNumber[k] == '0'))
{
continue;
}
// 显示信息
iSumBusNumber++;
str.Empty();
sprintf((char *)(LPCTSTR)str, "路线 %d: %s<--%d路--> %s <--%d路-->%s", iSumBusNumber, cBeginStation, j+1, cMiddleStation, k+1, cEndStation);
m_ListBox_Route.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, j+1);
if( rv != 0 )
{
AfxMessageBox("读取路线信息错误!");
delete bus_infor_head;
return;
}
//----查询信息
bus_infor_head_next = new BUS_INFOR;
memset(&bus_infor, 0, sizeof(BUS_INFOR));
memset(bus_infor_head_next,0, sizeof(BUS_INFOR));
rv = DB_BUS_INFOR_Query_BusNumber(hstmt, &bus_infor, bus_infor_head_next, k+1);
if( rv != 0 )
{
AfxMessageBox("读取路线信息错误!");
delete bus_infor_head_next;
return;
}
bus_infor_head->next = bus_infor_head_next;
// 显示信息
ShowRouteInfor(bus_infor_head, &m_ListBox_RouteInfor, 60);
str = " ";
m_ListBox_RouteInfor.AddString(str);
}// end for
}// end for
}
//////////////////////////////////////////////////////////////////////////
if (iSumBusNumber > 0)
{
return;
}
int n1, n2;
for (n1 = 0; n1 < iSumBusStation; n1++)
{
for (n2 = n1+1; n2 < iSumBusStation; n2++)
{
//////////////////////////////////////////////////////////////////////////
str.Empty();
m_ComboBox_BeginStation.GetLBText(n1, str);
memset(cMiddleStation, 0, 64);
strcpy(cMiddleStation, (char *)(LPCTSTR)str);
str.Empty();
m_ComboBox_BeginStation.GetLBText(n2, str);
memset(cMiddleStation1, 0, 64);
strcpy(cMiddleStation1, (char *)(LPCTSTR)str);
//
if((strcmp(cMiddleStation, cBeginStation) == 0) && (strcmp(cMiddleStation, cEndStation) == 0))
{
continue;
}
if((strcmp(cMiddleStation1, cBeginStation) == 0) && (strcmp(cMiddleStation1, cEndStation) == 0))
{
continue;
}
// 站点信息
rv = DB_STATION_INFOR_Query_BusNumber(hstmt,cMiddleStation, cMiddleBusNumber);
if( rv != 0)
{
AfxMessageBox("读取站点4信息错误!");
return;
}
rv = DB_STATION_INFOR_Query_BusNumber(hstmt,cMiddleStation1, cMiddleBusNumber1);
if( rv != 0)
{
AfxMessageBox("读取站点5信息错误!");
return;
}
//////////////////////////////////////////////////////////////////////////
for (i = 0; i < 127; i++)
{
//
if ((cBeginBusNumber[i] == '0') || (cMiddleBusNumber[i] == '0'))
{
continue;
}
}
} // end if
} // end if
}
//////////////////////////////////////////////////////////////////////////
void CPlaceTwoQueryDlg::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;
int i = 0;
str = "路线 " ;
str = "------------------------------- " + str+ " -----------------------------------";
m_List->AddString(str);
while ( bus_infor_head != NULL )
{
p = bus_infor_head;
//
str.Empty();
itoa(p->Bus_Number, temp, 10);
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;
}
str = " ";
m_List->AddString(str);
//
bus_infor_head = bus_infor_head->next;
delete p;
i++;
}
}
//////////////////////////////////////////////////////////////////////////
void CPlaceTwoQueryDlg::OnSelchangeTwoPlaceRouteList()
{
// TODO: Add your control notification handler code here
}
//////////////////////////////////////////////////////////////////////////
int CPlaceTwoQueryDlg::FindSameStation(char *cBeginBusNumber, char *cMiddleBusNumber, char *cEndBusNumber)
{
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -