📄 page4.cpp
字号:
// page4.cpp : implementation file
//
#include "stdafx.h"
#include "BusStop.h"
#include "page4.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern CBusStopApp theApp;
extern CListBox m_addline;
/////////////////////////////////////////////////////////////////////////////
// page4 dialog
page4::page4(CWnd* pParent /*=NULL*/)
: CDialog(page4::IDD, pParent)
{
//{{AFX_DATA_INIT(page4)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
void page4::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(page4)
DDX_Control(pDX, IDC_LIST1, m_list);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(page4, CDialog)
//{{AFX_MSG_MAP(page4)
ON_BN_CLICKED(IDC_import, Onimport)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// page4 message handlers
void page4::Onimport()
{
m_list.GetCurSel();
m_list.GetText(m_list.GetCurSel(),theApp.city);
try{
m_pRecordset->MoveFirst();
while(m_pRecordset->adoEOF==VARIANT_FALSE)
{
{
m_pRecordset->Delete(adAffectCurrent);
m_pRecordset->Update();
}
m_pRecordset->MoveNext();
}
}//try
catch (_com_error &e)
{ }
int bus_length1;
int bus_flag=0;
int k1,k2;
CString flag;
CString bus_length;
CString stop_name;
CString bus_number_text;
CString city;
city=theApp.city+".txt";
CStdioFile file;
if(!file.Open(city, CFile::modeRead) )
{
AfxMessageBox("can not open file!");
}
CString strLine;
while(file.ReadString(strLine))
{bus_number_text=strLine;
bus_flag=(bus_flag+1)%2;
flag.Format("%d",bus_flag);
bus_length1=1;
bus_length.Format("%d",bus_length1);
file.ReadString(strLine);
k1=k2=0;
k2=strLine.Find('*',k1+1);
k1++;
do
{
stop_name=strLine.Mid(k1,k2-k1);
try
{
m_pRecordset->AddNew();
m_pRecordset->PutCollect("stop_name",_variant_t(stop_name));
m_pRecordset->PutCollect("stop_number",_variant_t(bus_length));
m_pRecordset->PutCollect("bus_number_text",_variant_t(bus_number_text));
m_pRecordset->PutCollect("flag",_variant_t(flag));
m_pRecordset->Update();
bus_length1++;
bus_length.Format("%d",bus_length1);
}
catch(_com_error *e)
{
AfxMessageBox(e->ErrorMessage());
}
k1=k2+1;
k2=strLine.Find('*',k1);
}while(k2!=-1);
}
file.Close();
CStdioFile file2;
if( !file2.Open(city, CFile::modeRead) )
{
AfxMessageBox("can not open file!");
return ;
}
int num=m_addline.GetCount();
for(int j=0;j<num;j++)
m_addline.DeleteString(0);
CString strLine1;
while(file2.ReadString(strLine1))
{
m_addline.AddString(strLine1);
file2.ReadString(strLine1);
file2.ReadString(strLine1);
file2.ReadString(strLine1);
}
file2.Close();
AfxMessageBox("加载"+theApp.city+"公交车数据库完毕!");
}
BOOL page4::OnInitDialog()
{
CDialog::OnInitDialog();
m_pRecordset.CreateInstance(__uuidof(Recordset));
try
{m_pRecordset->Open("SELECT * FROM bus", // 查询DemoTable表中所有字段
theApp.m_pConnection.GetInterfacePtr(), // 获取库接库的IDispatch指针
adOpenDynamic,
adLockOptimistic,
adCmdText);
}
catch(_com_error *e)
{
AfxMessageBox(e->ErrorMessage());
}
CStdioFile file;
if( !file.Open("1列表.txt", CFile::modeRead) )
{
AfxMessageBox("can not open file!");
return 0;
}
CString strLine;
while(file.ReadString(strLine) )
{
m_list.AddString(strLine);
}
file.Close();
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -