⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 finddlg.cpp

📁 公交查询生成系统 Find.exe可以查询指定站点间的转站方案(可实现无限转)
💻 CPP
📖 第 1 页 / 共 3 页
字号:
// findDlg.cpp : implementation file
//

#include "stdafx.h"
#include "find.h"
#include "findDlg.h"
#include "path.h"
#include "linedlg.h"
#include "FindTypeDlg.h "

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

extern CFindApp theApp;  // 在此引用应用类中的theApp来获取库连接指针
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

	// 定义ADO连接、命令、记录集变量指针
	_ConnectionPtr	m_pConnection;
	_CommandPtr		m_pCommand;
	_RecordsetPtr	m_pRecordset;
	
// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CFindDlg dialog

CFindDlg::CFindDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CFindDlg::IDD, pParent)
{
	findout = false;
	ptol = false;
	way = 1;
	endlinenum = 0;
	turnout = -1;
	fangan = "方案";
	m_nIndex = 0;
	//{{AFX_DATA_INIT(CFindDlg)
	m_start = _T("");
	m_end = _T("");
	m_detail = _T("");
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CFindDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CFindDlg)
	DDX_Control(pDX, IDC_END, m_Combo2);
	DDX_Control(pDX, IDC_START, m_Combo1);
	DDX_Control(pDX, IDC_DETAIL, m_edit);
	DDX_Control(pDX, IDC_RESULTLIST, m_list);
	DDX_Control(pDX, IDC_FIND, m_find);
	DDX_Text(pDX, IDC_START, m_start);
	DDX_Text(pDX, IDC_END, m_end);
	DDX_Text(pDX, IDC_DETAIL, m_detail);
	//}}AFX_DATA_MAP

}

BEGIN_MESSAGE_MAP(CFindDlg, CDialog)
	//{{AFX_MSG_MAP(CFindDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_FIND, OnFind)
	ON_NOTIFY(NM_DBLCLK, IDC_RESULTLIST, OnDblclkResultlist)
	ON_BN_CLICKED(IDC_ABOUT, OnAbout)
	ON_BN_CLICKED(IDC_LINE, OnLine)
	ON_WM_CTLCOLOR()
	ON_BN_CLICKED(IDC_TYPE, OnType)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CFindDlg message handlers

BOOL CFindDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon

//	m_find.OffsetColor(CButtonST::BTNST_COLOR_BK_IN, 30);
//	m_find.SetBkColor(RGB(162,189,252));
//	m_find.SetTooltipText(_T("读取全部记录"));
//	m_find.SetRounded(TRUE);
////////////////////////////////////////////////////////////////////////////////	
//	m_imagelist.Create(16,16,TRUE,2,2);
//	m_imagelist.Add(AfxGetApp()->LoadIcon(IDI_ICON2));
//	m_list.SetImageList(&m_imagelist,LVSIL_SMALL);

	m_pConnection.CreateInstance(__uuidof(Connection));

	// 在ADO操作中建议语句中要常用try...catch()来捕获错误信息,
	// 因为它有时会经常出现一些想不到的错误。
	try                 
	{	
		// 打开本地Access库Demo.mdb
		m_pConnection->Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=公交查询.mdb","","",adModeUnknown);
		
	}
	catch(_com_error e)
	{
		AfxMessageBox("数据库连接失败,确认数据库公交查询.mdb是否在当前路径下!");
		return FALSE;
	} 


	m_font.CreateFont(14, 0,0,0,FW_NORMAL, 0,0,0,
		DEFAULT_CHARSET, OUT_CHARACTER_PRECIS, CLIP_CHARACTER_PRECIS,
		DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, "Arial");
	m_list.SetFont(&m_font);

	// TODO: Add extra initialization here
/////////////////////////////////////////////////////////////////////////////////	

	m_list.SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES);
//	m_list.SetExtendedStyle(LVS_EX_FULLROWSELECT);//行有效
//	m_list.SetExtendedStyle(LVS_EX_GRIDLINES);//方格
//	m_list.SetBkColor(RGB(247,247,255));
	m_list.SetTextColor(RGB(0,0,255));
	m_list.SetTextBkColor(RGB(247,247,255));
	m_list.InsertColumn(0, "方案", LVCFMT_CENTER, 68);
	m_list.InsertColumn(1, "线路名称", LVCFMT_CENTER, 110);
	m_list.InsertColumn(2, "乘车线路", LVCFMT_CENTER, 160);
	m_list.InsertColumn(3, "站数", LVCFMT_CENTER, 78);
	// TODO: Add extra initialization here




////////////////////////////////////////////////////////////////////////////////
//获取线路和站点数目
	m_pRecordset.CreateInstance(__uuidof(Recordset));
	m_pRecordset->Open(_variant_t("SELECT * FROM 总数" ),                // 查询站点表中所有字段
								theApp.m_pConnection.GetInterfacePtr(),	 // 获取库接库的IDispatch指针
								adOpenDynamic,
								adLockOptimistic,
								adCmdText);	
	
		_variant_t var;
		try
		{
			if(!m_pRecordset->BOF)
				m_pRecordset->MoveFirst();
			else
			{
				AfxMessageBox("总数表内数据为空");
				return false;
			}
			// 读入库中各字段并加入列表框中
			while(!m_pRecordset->adoEOF)
			{
				var = m_pRecordset->GetCollect("站点数");
				if(var.vt != VT_NULL)
					stationnum = var;
				var = m_pRecordset->GetCollect("线路数");
				if(var.vt != VT_NULL)
					linenum = var;
				m_pRecordset->MoveNext();
			}
			// 默认列表指向第一项,同时移动记录指针并显示
		}
		catch(_com_error *e)
		{
			AfxMessageBox(e->ErrorMessage());
		}
	int i=0;
	station  = new CString[stationnum];
	line = new CString[linenum];
////////////////////////////////////////////////////////////////////////////////
//导出线路数据
/*	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 false;
			}
			// 读入库中各字段并加入列表框中
			while(!m_pRecordset->adoEOF)
			{
				var = m_pRecordset->GetCollect("线路");
				if(var.vt != VT_NULL)
					line[i++] = (LPCSTR)_bstr_t(var);
				m_pRecordset->MoveNext();
			}
		}
		catch(_com_error *e)
		{
			AfxMessageBox(e->ErrorMessage());
		}
		*/
////////////////////////////////////////////////////////////////////////////////
//导出站点数据
    i = 0;//初始化
	m_pRecordset.CreateInstance(__uuidof(Recordset));
	m_pRecordset->Open(_variant_t("SELECT * FROM 站点总表"),                // 查询站点表中所有字段
						theApp.m_pConnection.GetInterfacePtr(),	 // 获取库接库的IDispatch指针
						adOpenDynamic,
						adLockOptimistic,
						adCmdText);		
		try
		{
			if(!m_pRecordset->BOF)
				m_pRecordset->MoveFirst();
			else
			{
				AfxMessageBox("表内数据为空");
				return false;
			}

			// 读入库中各字段并加入列表框中
			while(!m_pRecordset->adoEOF)
			{
				var = m_pRecordset->GetCollect("站点");
				if(var.vt != VT_NULL)
				{
					m_Combo1.AddString((LPCSTR)_bstr_t(var));
					m_Combo2.AddString((LPCSTR)_bstr_t(var));
					station[i++] = (LPCSTR)_bstr_t(var);
				}
				m_pRecordset->MoveNext();
			}
		}
		catch(_com_error *e)
		{
			AfxMessageBox(e->ErrorMessage());
		}

////////////////////////////////////////////////////////////////////////////////
			return TRUE;  // return TRUE  unless you set the focus to a control
}

void CFindDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CFindDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CFindDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CFindDlg::OnFind() 
{
	if(ptol == true)//如果是查询 站点-->线路,则运行PtoL()
	{
		PtoL();
		return;
	}
	int i=0, j=0;
	CString v;//用于把way转化成字符
	CString nowstation, nowline;
	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();
//////////////////////////////////////////////////////////////////
//获得起点和终点的标准名称
		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"));
					}
					if(m_end ==(LPCSTR)_bstr_t(var))
					{
						end = true;
						m_end = (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;						
					}
					if(m_end ==(LPCSTR)_bstr_t(var))
					{
						end = true;						
					}
					if(m_end == (LPCSTR)_bstr_t(var))
					{
						var = m_pRecordset->GetCollect("通过线路数");
						if(var.vt != VT_NULL)
						{
							endlinenum = var;
							endline = new CString[endlinenum];
						}
					}
				}
				m_pRecordset->MoveNext();
			}
		}
		catch(_com_error e)
		{
			AfxMessageBox(e.Description());
		}
		if(start == false)
		{
			MessageBox("不存在该起点站!");
			return;
		}
		if(end == false)
		{
			MessageBox("不存在该终点站!");
			return;
		}
	////////////////////////////////////////////////////////////////
		m_pRecordset.CreateInstance(__uuidof(Recordset));
		m_pRecordset->Open(_variant_t("SELECT * FROM " +m_end),                // 查询站点表中所有字段
								theApp.m_pConnection.GetInterfacePtr(),	 // 获取库接库的IDispatch指针
								adOpenDynamic,
								adLockOptimistic,
								adCmdText);
	////////////////////////////////////////////////////////////////		
		try
		{
			if(!m_pRecordset->BOF)
				m_pRecordset->MoveFirst();
			else
			{
				AfxMessageBox(m_end+"表内数据为空");
				return;
			}
			// 读入库中各字段并加入列表框中

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -