📄 showdata.cpp
字号:
// ShowData.cpp : implementation file
//
#include "stdafx.h"
#include "The Time Of Day.h"
#include "The Time Of DayDlg.h"
#include "ShowData.h"
#include <atlconv.h>
#include "Condition.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
static int m_inumber;
/////////////////////////////////////////////////////////////////////////////
// CShowData property page
IMPLEMENT_DYNCREATE(CShowData, CPropertyPage)
CShowData::CShowData() : CPropertyPage(CShowData::IDD)
{
m_IsAirplane = true;
m_inumber = 0;
//{{AFX_DATA_INIT(CShowData)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
CShowData::~CShowData()
{
}
void CShowData::DoDataExchange(CDataExchange* pDX)
{
CPropertyPage::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CShowData)
DDX_Control(pDX, IDC_LIST_info, m_DataInfo);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CShowData, CPropertyPage)
//{{AFX_MSG_MAP(CShowData)
ON_WM_PAINT()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CShowData message handlers
void CShowData::OnPaint()
{
const CPaintDC dc(this); // device context for painting
//使的控件和对话框相当大
/* CRect tabRect;
GetClientRect(&tabRect);
m_DataInfo.MoveWindow(&tabRect);*/
// TODO: Add your message handler code here
if(m_IsAirplane)
{
OpenSqlite();
USES_CONVERSION;
CCondition *m_Condition = new CCondition();
//拼接字符串
CString strSql = "select AronefTimeID,ArodromeStart,b.ArodromeName as ArodromeEnd,";
strSql += "TimeStart,TimeEnd,AronefType,Stop,Periods,a.CompanyName as CompanyName ";
strSql += "from(select AronefTimeID,ArodromeName as ArodromeStart,ArodromeEnd,";
strSql += "TimeStart,TimeEnd,AronefType,Stop,Periods,CompanyID ";
strSql += "from tbAronefTime a ,tbArodrome b where a.ArodromeStart=b.ArodromeID ";
//限制条件起始地
CString Values = m_Condition->GetAddStart();
if(Values != L"")
strSql += "and arodromeStart in (select ArodromeID from tbArodrome where Locus like '" + Values +"')" ;
//限制条件目的地
Values = m_Condition->GetAddEnd();
if(Values != L"")
strSql += "and ArodromeEnd in (select ArodromeID from tbArodrome where Locus like '" + Values + "') ";
//限制条件时间
Values = m_Condition->GetAddWeek();
if(Values != L"")
strSql += "and Periods like '%" + Values + "%' ";
//限制条件航空公司
Values = m_Condition->GetAddCompany();
if(Values != L"所有航空公司")
strSql += "and a.CompanyID =(select CompanyID from tbAronefCompany where CompanyName = '" + Values + "') ";
strSql += "ORDER BY TimeStart) as c,tbArodrome as b,tbAronefCompany as a ";
strSql += "where ArodromeEnd = ArodromeID and a.CompanyID = c.CompanyID ";
//获取表中信息
char *errmsg = NULL;
char *sql = (char*)W2A((LPCTSTR)strSql);
sqlite3_get_table( db, sql, &m_tableResult, &m_nRow, &m_nColumn, &errmsg);
sqlite3_close(db);
delete m_Condition;
m_Condition = NULL;
}
//火车
else
{
//
//
}
//判断是否存在数据
if(m_nRow != 0 && m_nColumn !=0)
{
//删除
m_DataInfo.DeleteAllItems();
int num = 0;
while(num < 4)
{
for (int j = 0; j < m_inumber; j++)
{
m_DataInfo.DeleteColumn(j);
}
num++;
}
m_inumber = m_nColumn;
//插入字段名
CString strValue;
for (int i = 0; i <m_nColumn; i++)
{
strValue = m_tableResult[i];
m_DataInfo.InsertColumn(i,strValue);
m_DataInfo.SetColumnWidth(i,strlen(m_tableResult[i])+100);
}
//插入数据
int number = m_nColumn;
for (int k = 0; k < m_nRow; k++)
{
m_DataInfo.InsertItem(k,L"");
for(int j = 0; j < m_nColumn; j++)
{
strValue = m_tableResult[number];
m_DataInfo.SetItemText(k, j, strValue);
number++;
}
}
}
// Do not call CPropertyPage::OnPaint() for painting messages
}
//创建打开sqlite数据库
void CShowData::OpenSqlite()
{
sqlite3 *sdb;
CString szPath;
wchar_t pBuf[256];
GetModuleFileName(NULL,pBuf,sizeof(pBuf)/sizeof(wchar_t));
szPath=pBuf;
szPath = szPath.Left(szPath.ReverseFind('\\')+1);
szPath += "\\time.db";
if(szPath.Find('\\') == 0)
szPath.Delete(0,2);
USES_CONVERSION;
char *buffer = (char*)W2A((LPCTSTR)szPath);
if(SQLITE_OK!=sqlite3_open(buffer,&sdb))
{ CString errmsg = sqlite3_errmsg(sdb);
MessageBox(errmsg,NULL,MB_OK | MB_ICONERROR);
sqlite3_close(sdb);
return;
}
db = sdb;
}
BOOL CShowData::OnInitDialog()
{
CPropertyPage::OnInitDialog();
// TODO: Add extra initialization here
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 + -