📄 finddlg.cpp
字号:
AfxMessageBox(e.Description());
return;
}
}
else
{
ptol = false;
m_Combo2.ResetContent();
try
{
m_pRecordset.CreateInstance(__uuidof(Recordset));
m_pRecordset->Open("SELECT * FROM 站点总表", // 查询站点表中所有字段
theApp.m_pConnection.GetInterfacePtr(), // 获取库接库的IDispatch指针
adOpenDynamic,
adLockOptimistic,
adCmdText);
if(!m_pRecordset->BOF)
m_pRecordset->MoveFirst();
else
{
AfxMessageBox("线路总表为空!");
}
// 读入库中各字段并加入列表框中
while(!m_pRecordset->adoEOF)
{
var = m_pRecordset->GetCollect("站点");
if(var.vt != VT_NULL)
{
m_Combo2.AddString((LPCSTR)_bstr_t(var));
}
m_pRecordset->MoveNext();
}
}
catch(_com_error e)
{
AfxMessageBox(e.Description());
return;
}
}
}
}
void CFindDlg::PtoL()
{
int i=0, j=0;
CString v;//用于把way转化成字符
CString nowstation, nowline, L;
long s = 0, l = 0;//记录已经查过的站点,线路数
bool out = false;
bool start = false, end = false;//判断输入的站点是否存在
////////////////////////////////////////////////
//初始化数据
for(i=0; i<5; i++)
value[i] = 0;
CPath *path = new CPath[stationnum];// * stationnum];
goneline = new CString *[linenum];
for(i=0; i<linenum; i++)
goneline[i] = new CString[2];
gonestation = new CString *[stationnum];
for(i=0; i<stationnum; i++)
gonestation[i] = new CString[2];
////////////////////////////////////////////////
//
UpdateData(TRUE);
_variant_t var;
CString now;
if(m_start == "")
{
MessageBox("请输入起点站!", "输入错误!", MB_ICONEXCLAMATION | MB_OK);
return;
}
if(m_end == "")
{
MessageBox("请输入终点线路!", "输入错误!", MB_ICONEXCLAMATION | MB_OK);
return;
}
if(m_start != "" && m_end != "")
{
// 清空列表框
m_list.DeleteAllItems();
L = m_end;
//////////////////////////////////////////////////////////////////
//获得起点的别名
try
{
m_pRecordset.CreateInstance(__uuidof(Recordset));
m_pRecordset->Open("SELECT * FROM 同义站点表", // 查询站点表中所有字段
theApp.m_pConnection.GetInterfacePtr(), // 获取库接库的IDispatch指针
adOpenDynamic,
adLockOptimistic,
adCmdText);
if(!m_pRecordset->BOF)
m_pRecordset->MoveFirst();
else
{
goto loop;
}
// 读入库中各字段并加入列表框中
i = 0;
while(!m_pRecordset->adoEOF)
{
var = m_pRecordset->GetCollect("站点名");
if(var.vt != VT_NULL)
{
if(m_start ==(LPCSTR)_bstr_t(var))
{
start = true;
m_start = (LPCSTR)_bstr_t(m_pRecordset->GetCollect("ID"));
}
}
m_pRecordset->MoveNext();
}
}
catch(_com_error e)
{
AfxMessageBox(e.Description());
return;
}
//////////////////////////////////////////////////////////////////
//查标准名
loop: m_pRecordset.CreateInstance(__uuidof(Recordset));
m_pRecordset->Open("SELECT * FROM 站点总表", // 查询站点表中所有字段
theApp.m_pConnection.GetInterfacePtr(), // 获取库接库的IDispatch指针
adOpenDynamic,
adLockOptimistic,
adCmdText);
////////////////////////////////////////////////////////////////
try
{
if(!m_pRecordset->BOF)
m_pRecordset->MoveFirst();
else
{
AfxMessageBox("线路总表内数据为空");
return;
}
// 读入库中各字段并加入列表框中
i = 0;
while(!m_pRecordset->adoEOF)
{
var = m_pRecordset->GetCollect("站点");
if(var.vt != VT_NULL)
{
if(m_start ==(LPCSTR)_bstr_t(var))
{
start = true;
}
}
m_pRecordset->MoveNext();
}
}
catch(_com_error e)
{
AfxMessageBox(e.Description());
}
////////////////////////////////////////////////////////////////
m_pRecordset.CreateInstance(__uuidof(Recordset));
m_pRecordset->Open("SELECT * FROM 站点总表", // 查询站点表中所有字段
theApp.m_pConnection.GetInterfacePtr(), // 获取库接库的IDispatch指针
adOpenDynamic,
adLockOptimistic,
adCmdText);
try
{
if(!m_pRecordset->BOF)
m_pRecordset->MoveFirst();
else
{
AfxMessageBox("线路总表内数据为空");
return;
}
// 读入库中各字段并加入列表框中
i = 0;
while(!m_pRecordset->adoEOF)
{
var = m_pRecordset->GetCollect("站点");
if(var.vt != VT_NULL)
{
if(m_start ==(LPCSTR)_bstr_t(var))
{
start = true;
}
}
m_pRecordset->MoveNext();
}
}
catch(_com_error e)
{
AfxMessageBox(e.Description());
}
if(start == false)
{
MessageBox("不存在该起点站!");
return;
}
m_pRecordset.CreateInstance(__uuidof(Recordset));
m_pRecordset->Open("SELECT * FROM 线路总表", // 查询站点表中所有字段
theApp.m_pConnection.GetInterfacePtr(), // 获取库接库的IDispatch指针
adOpenDynamic,
adLockOptimistic,
adCmdText);
try
{
if(!m_pRecordset->BOF)
m_pRecordset->MoveFirst();
else
{
AfxMessageBox("线路总表内数据为空");
return;
}
// 读入库中各字段并加入列表框中
i = 0;
while(!m_pRecordset->adoEOF)
{
var = m_pRecordset->GetCollect("线路");
if(var.vt != VT_NULL)
{
if(m_end ==(LPCSTR)_bstr_t(var))
{
end = true;
}
}
m_pRecordset->MoveNext();
}
}
catch(_com_error e)
{
AfxMessageBox(e.Description());
}
if(end == false)
{
MessageBox("不存在该线路!");
return;
}
///////////////////////////////////////////////////////////////////////
//查找
i = 0;
now = m_start;
path[0].name = m_start;//把起点站加入到path中
while(1)
{
if(i == 0)
{
dad = -1;
try
{
m_pRecordset.CreateInstance(__uuidof(Recordset));
m_pRecordset->Open(_variant_t("SELECT * FROM " +m_start), // 查询站点表中所有字段
theApp.m_pConnection.GetInterfacePtr(), // 获取库接库的IDispatch指针
adOpenDynamic,
adLockOptimistic,
adCmdText);
if(!m_pRecordset->BOF)
{
m_pRecordset->MoveFirst();
// 读入库中各字段并加入列表框中
while(!m_pRecordset->adoEOF)
{
var = m_pRecordset->GetCollect("线路");
if(var.vt != VT_NULL)
{
if((LPCSTR)_bstr_t(var) == L)
{//如果能到达终点输出结果
itoa(way, value, 10);
v = value;
int nn=m_list.InsertItem(m_list.GetItemCount(),v);
m_list.SetItemText(nn, 1, L);
m_list.SetItemText(nn, 2, m_start+"(上车)");
nn=m_list.InsertItem(m_list.GetItemCount(),"");
m_list.SetItemText(nn, 1, "");
m_list.SetItemText(nn, 2, "");
way++;
findout = true;
}
if(findout == false)
{//如果不能到达终点,标记不能到达的线路
goneline[l][0] = (LPCSTR)_bstr_t(var);
goneline[l++][1] = "不能到达";
}
}
m_pRecordset->MoveNext();
}
}
}
catch(_com_error e)
{
AfxMessageBox(e.Description());
}
if(findout != true)
{
i++;
turnout++;
gonestation[s][0] = m_start;
gonestation[s++][1] = "不能到达";
}
else
{
break;
}
}
////多转情况
else
{
dad++;
int yy = true;
if(path[dad].turn > turnout)
turnout ++;
//if(!(path[dad].turn <= turnout && findout == true))
if(!(findout == true && path[dad].turn != path[dad - 1].turn))
{
try
{
//查找path[dad]的每条线路nowline;
m_pRecordset.CreateInstance(__uuidof(Recordset));
m_pRecordset->Open(_variant_t("SELECT * FROM " + path[dad].name), // 查询站点表中所有字段
theApp.m_pConnection.GetInterfacePtr(), // 获取库接库的IDispatch指针
adOpenDynamic,
adLockOptimistic,
adCmdText);
}
catch(_com_error e)
{
AfxMessageBox(e.Description());
return;
}
m_pRecordset->MoveFirst();
while(!m_pRecordset->adoEOF)
{
var = m_pRecordset->GetCollect("线路");
if(var.vt != VT_NULL)
{
nowline = (LPCSTR)_bstr_t(var);
for(j=0; j<l; j++)
{
if(nowline == goneline[j][0] && dad != 0)
{
if(goneline[j][1] == "不能到达")
{
goto next;
}
}
}
//查找nowline的每个站点nowstation
try
{
m_pRecordset1.CreateInstance(__uuidof(Recordset));
m_pRecordset1->Open(_variant_t("SELECT * FROM " + nowline), // 查询站点表中所有字段
theApp.m_pConnection.GetInterfacePtr(), // 获取库接库的IDispatch指针
adOpenDynamic,
adLockOptimistic,
adCmdText);
}
catch(_com_error e)
{
AfxMessageBox(e.Description());
}
//out = true;
m_pRecordset1->MoveFirst();
while(!m_pRecordset1->adoEOF)
{
var = m_pRecordset1->GetCollect("站点");
if(var.vt != VT_NULL)
{//查看经过每个站点的线路与终点是否有交集
nowstation = (LPCSTR)_bstr_t(var);
//if(nowstation == path[dad].name)
//out = false;
//if(out == false)
//goto next1;
for(j=0; j<s; j++)//查看该站点是否标记过
{
if(nowstation == gonestation[j][0])
{
if(gonestation[j][1] == "不能到达")
goto next1;
}
}
//添加path节点
path[i].name = nowstation;
path[i].father = dad;
path[i].line = nowline;
path[i++].turn = path[dad].turn + 1;
try
{
m_pRecordset2.CreateInstance(__uuidof(Recordset));
m_pRecordset2->Open(_variant_t("SELECT * FROM " +nowstation), // 查询站点表中所有字段
theApp.m_pConnection.GetInterfacePtr(), // 获取库接库的IDispatch指针
adOpenDynamic,
adLockOptimistic,
adCmdText);
}
catch(_com_error e)
{
AfxMessageBox(e.Description());
}
m_pRecordset2->MoveFirst();
while(!m_pRecordset2->adoEOF)
{
var = m_pRecordset2->GetCollect("线路");
for(j=0; j<l; j++)
{
if((LPCSTR)_bstr_t(var) == goneline[j][0])
{
if(goneline[j][1] == "不能到达")
goto next2;
}
}
if(var.vt != VT_NULL)
{
if((LPCSTR)_bstr_t(var) == L)
{//如果能到达终点输出结果
way++;
findout = true;
path[i-1].find = true;
path[i-1].go[(path[i-1].g)++] = L;
//AfxMessageBox("find");
}
}
next2: m_pRecordset2->MoveNext();
}
if(path[i-1].find == false)
{
gonestation[s][0] = path[i-1].name;
gonestation[s++][1] = "不能到达";
}
}
if(path[i-1].find == false)
{//如果不能到达终点,标记不能到达的线路
bool to = true;
for(j=0; j<l; j++)
{
if(nowline == goneline[j][0])
{
to = false;
break;
}
}
if(to == true)
{
goneline[l][0] = nowline;
goneline[l++][1] = "不能到达";
}
}
next1: m_pRecordset1->MoveNext();
}
}
next:m_pRecordset->MoveNext();
}
}
else
break;
}
}
}
///////////////////////////////////////////////////////////////////////
//在list ctr中输出结果
if(i != 0)//存在转车的情况
{
int k = 0, j = 0, now = 0;
for(j=0; j<5; j++)
value[j] = 0;
way--;
while(way >0)
{
for(j=i-1; j>=0 && path[j].turn >= turnout ; j--)
{
now = j;
for(k=0 ; k<path[j].g ;k++)
{
if(path[now].turn >= turnout )
{
m_list.InsertItem(0, "");
m_list.SetItemText(0, 1, L);
m_list.SetItemText(0, 2, path[now].name + "(上车)");
}
while(path[now].father != 0)
{
m_list.InsertItem(0, "");
m_list.SetItemText(0, 1, path[now].line);
m_list.SetItemText(0, 2, path[path[now].father].name +"--->"+path[now].name);
now = path[now].father;
}
if(path[now].father == 0)
{
itoa(way--, value, 10);
v = value;
m_list.InsertItem(0, v);
m_list.SetItemText(0, 1, path[now].line);
m_list.SetItemText(0, 2, m_start +"--->"+path[now].name);
}
if(way != 0)
{
m_list.InsertItem(0, "");
m_list.SetItemText(0, 1, "");
m_list.SetItemText(0, 2, "");
}
}
}
}
}
///////////////////////////////////////////////////////////////////////
//恢复数据
for(i=0; i<=l; i++)
delete []goneline[i];
delete []goneline;
for(i=0; i<=s; i++)
delete []gonestation[i];
delete []gonestation;
delete []path;
findout = false;
way = 1;
endlinenum = 0;
turnout = -1;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -