📄 finddlg.cpp
字号:
i = 0;
while(!m_pRecordset->adoEOF)
{
var = m_pRecordset->GetCollect("线路");
if(var.vt != VT_NULL)
endline[i++] = (LPCSTR)_bstr_t(var);
m_pRecordset->MoveNext();
}
}
catch(_com_error e)
{
AfxMessageBox(e.Description());
}
///////////////////////////////////////////////////////////////////////
//查找
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)
{
for(int j=0; j<endlinenum; j++)
{
if((LPCSTR)_bstr_t(var) == endline[j])
{//如果能到达终点输出结果
itoa(way, value, 10);
v = value;
m_list.InsertItem(0,"");
m_list.SetItemText(0, 1, "");
m_list.SetItemText(0, 2, "");
m_list.InsertItem(0, v);
m_list.SetItemText(0, 1, endline[j]);
m_list.SetItemText(0, 2, m_start+"--->"+m_end);
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))
//if(!(path[dad].turn > turnout && findout == true) || dad == 0)
{// turnout ++;
try
{
// for(int p=0; p<i; p++)
// TRACE("%s",path[p].name);
//查找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("2");
return;
AfxMessageBox(e.Description());
}
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)
{
for(int j=0; j<endlinenum; j++)
{
if((LPCSTR)_bstr_t(var) == endline[j])
{//如果能到达终点输出结果
way++;
findout = true;
path[i-1].find = true;
path[i-1].go[(path[i-1].g)++] = endline[j];
//AfxMessageBox("find");
}
}
//if(path[i-1].find == false)
//{//如果不能到达终点,标记不能到达的线路
// goneline[l][0] = (LPCSTR)_bstr_t(var);
// goneline[l++][1] = "不能到达";
//}
}
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)
{//如果不能到达终点,标记不能到达的线路
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, path[now].go[k]);
m_list.SetItemText(0, 2, path[now].name +"--->"+m_end);
}
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 []endline;
delete []path;
findout = false;
way = 1;
endlinenum = 0;
turnout = -1;
}
void CFindDlg::OnDblclkResultlist(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
HD_NOTIFY *phdn = (HD_NOTIFY *) pNMHDR;
POSITION pos = m_list.GetFirstSelectedItemPosition();
m_nIndex = m_list.GetNextSelectedItem(pos); // 得到项目索引
CString str, first, second, line, temp;
int i = 0, j = 0, length = 0;
long a = 0, b = 0;
_variant_t var ,n;
bool open = false;
if(m_list.GetItemText(m_nIndex, 2) == "")
return;
line = m_list.GetItemText(m_nIndex, 1);
str = m_list.GetItemText(m_nIndex, 2);
temp = str.Right(6);
if(temp == "(上车)")
{
goto l;
}
length = str.GetLength();
first = str.Left(str.Find("-"));
second = str.Right(length-(str.Find(">")+1));
l: m_detail = "线路名称:" + line + "\r\n";
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("表内数据为空");
return;
}
// 读入库中各字段并加入列表框中
while(!m_pRecordset->adoEOF)
{
var = m_pRecordset->GetCollect("线路");
if(var.vt != VT_NULL)
{
if((LPCSTR)_bstr_t(var) == line)
{
var = m_pRecordset->GetCollect("汽车类型");
m_detail += "汽车类型:";
m_detail += (LPCSTR)_bstr_t(var);
var = m_pRecordset->GetCollect("票价");
m_detail += " 票价:";
m_detail += (LPCSTR)_bstr_t(var);
m_detail += " 元";
var = m_pRecordset->GetCollect("发车时间");
m_detail += "\r\n发车时间:";
m_detail += (LPCSTR)_bstr_t(var);
var = m_pRecordset->GetCollect("结束时间");
m_detail += "\r\n结束时间:";
m_detail += (LPCSTR)_bstr_t(var);
}
}
m_pRecordset->MoveNext();
}
}
catch(_com_error e)
{
AfxMessageBox(e.Description());
}
m_detail += "\r\n乘车线路:";
try
{
m_pRecordset.CreateInstance(__uuidof(Recordset));
m_pRecordset->Open(_variant_t("SELECT * FROM " + line), // 查询站点表中所有字段
theApp.m_pConnection.GetInterfacePtr(), // 获取库接库的IDispatch指针
adOpenDynamic,
adLockOptimistic,
adCmdText);
if(!m_pRecordset->BOF)
m_pRecordset->MoveFirst();
else
{
AfxMessageBox("表内数据为空");
return;
}
// 读入库中各字段并加入列表框中
while(!m_pRecordset->adoEOF)
{
var = m_pRecordset->GetCollect("站点");
if(var.vt != VT_NULL)
{
if(temp == "(上车)")
{
m_detail += (LPCSTR)_bstr_t(var);
m_detail += "-";
}
else
{
if((LPCSTR)_bstr_t(var) == first)
{
n = m_pRecordset->GetCollect("ID");
a = n;
open = true;
///////////////////////////////////////////////
//如果是下行线路
if(b < a && a!=0 && b!=0)
{
while(!m_pRecordset->adoEOF)
{
var = m_pRecordset->GetCollect("站点");
if(var.vt != VT_NULL)
{
if((LPCSTR)_bstr_t(var) != second)
{
i++;
m_detail += (LPCSTR)_bstr_t(var);
m_detail += "-";
}
if((LPCSTR)_bstr_t(var) == second)
{
i++;
m_detail += (LPCSTR)_bstr_t(var);
goto output;
}
}
m_pRecordset->MovePrevious();
}
}
//////////////////////////////////////////////////////////////////
}
if(open == true && (LPCSTR)_bstr_t(var) != second)
{
i++;
m_detail += (LPCSTR)_bstr_t(var);
m_detail += "-";
}
if((LPCSTR)_bstr_t(var) == second)
{
n = m_pRecordset->GetCollect("ID");
b = n;
if(a < b && a!=0 && b!=0)//如果是上行,则可以结束
{
i++;
m_detail += (LPCSTR)_bstr_t(var);
break;
}
}
}
}
m_pRecordset->MoveNext();
}
}
catch(_com_error e)
{
AfxMessageBox(e.Description());
}
if(temp == "(上车)")
{
m_detail = m_detail.Left(m_detail.GetLength() - 2);
}
output: UpdateData(FALSE);
*pResult = 0;
}
void CFindDlg::OnAbout()
{
// TODO: Add your control notification handler code here
CAboutDlg dlg;
dlg.DoModal();
}
void CFindDlg::OnLine()
{
// TODO: Add your control notification handler code here
CLineDlg dlg;
dlg.DoModal();
}
void CFindDlg::OnType()
{
// TODO: Add your control notification handler code here
CFindTypeDlg dlg;
_variant_t var;
if(dlg.DoModal() == IDOK)
{
if(dlg.m_r == 1)//选中 站点-->线路
{
ptol = true;
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)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -