?? condition.cpp
字號:
// Condition.cpp : implementation file
//
#include "stdafx.h"
#include "The Time Of Day.h"
#include "The Time Of DayDlg.h"
#include "Condition.h"
#include "ShowData.h"
#include <atlconv.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
static CString m_AddStart1;
static CString m_AddEnd1;
static CString m_Week1;
static CString m_Company1;
/////////////////////////////////////////////////////////////////////////////
// CCondition property page
IMPLEMENT_DYNCREATE(CCondition, CPropertyPage)
CCondition::CCondition() : CPropertyPage(CCondition::IDD)
{
//{{AFX_DATA_INIT(CCondition)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
CCondition::~CCondition()
{
}
void CCondition::DoDataExchange(CDataExchange* pDX)
{
CPropertyPage::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CCondition)
DDX_Control(pDX, IDC_COMBO_Company, m_Company);
DDX_Control(pDX, IDC_DATETIM_Start, m_DataCtr);
DDX_Control(pDX, IDC_COMBO_End, m_AddEnd);
DDX_Control(pDX, IDC_COMBO_Start, m_AddStart);
DDX_Control(pDX,IDC_RADIO_Train,m_Train);
DDX_Control(pDX,IDC_RADIO_Airplane,m_Airplane);
DDX_Control(pDX,IDC_STATIC_Strat,m_StaticAddStart);
DDX_Control(pDX,IDC_STATIC_end,m_StaticAddEnd);
DDX_Control(pDX,IDC_STATIC_Data,m_StaticData);
DDX_Control(pDX,IDC_STATIC_Company,m_StaticCompany);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CCondition, CPropertyPage)
//{{AFX_MSG_MAP(CCondition)
ON_CBN_DROPDOWN(IDC_COMBO_Start, OnDropdownCOMBOStart)
ON_CBN_DROPDOWN(IDC_COMBO_End, OnDropdownCOMBOEnd)
ON_CBN_EDITCHANGE(IDC_COMBO_Start, OnEditchangeCOMBOStart)
ON_CBN_CLOSEUP(IDC_COMBO_Start, OnCloseupCOMBOStart)
ON_CBN_CLOSEUP(IDC_COMBO_End, OnCloseupCOMBOEnd)
ON_CBN_EDITCHANGE(IDC_COMBO_End, OnEditchangeCOMBOEnd)
ON_CBN_EDITCHANGE(IDC_COMBO_Company, OnEditchangeCOMBOCompany)
ON_CBN_CLOSEUP(IDC_COMBO_Company, OnCloseupCOMBOCompany)
ON_NOTIFY(DTN_DATETIMECHANGE, IDC_DATETIM_Start, OnDatetimechangeDATETIMStart)
ON_WM_PAINT()
ON_WM_SIZE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCondition message handlers
//初始話對話框
BOOL CCondition::OnInitDialog()
{
CPropertyPage::OnInitDialog();
// TODO: Add extra initialization here
m_Airplane.SetCheck(1);
OpenSqlite();
//獲取表中所有信息
USES_CONVERSION;
char **tableResult;
int nRow, nColumn;
char *errmsg = NULL;
//獲取航班公司表中的航班公司名稱
CString strSql = L"select CompanyName from tbAronefCompany";
char *sql = (char*)W2A((LPCTSTR)strSql);
sqlite3_get_table( db, sql, &tableResult, &nRow, &nColumn, &errmsg);
//插入數據(航班公司)
m_Company.AddString(L"所有航空公司");
if(nRow != 0 && nColumn !=0)
{
CString strValue;
for (int i = 0; i < nRow; i++)
{
strValue = tableResult[i+1];
m_Company.AddString(strValue);
}
}
m_Company.SetWindowText(L"所有航空公司");
sqlite3_close(db);
sqlite3_free_table(tableResult);
//初始化
CTime temptime;
m_DataCtr.GetTime(temptime);
int tempweek = 0;
tempweek = temptime.GetDayOfWeek();
if(tempweek == 1)
tempweek = 7;
else
tempweek-=1;
m_Week1.Format(L"%d",tempweek);
m_AddStart1 = L"";
m_AddEnd1 = L"";
m_Company1 = L"所有航空公司";
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
//出發地組合框列表打開觸發
void CCondition::OnDropdownCOMBOStart()
{
// TODO: Add your control notification handler code here
if(m_Airplane.GetCheck())
{
USES_CONVERSION;
//限制條件起始地
OpenSqlite();
CString strAdd;
m_AddStart.GetWindowText(strAdd);
m_AddStart.ResetContent();
if(strAdd.Find(L" ") != -1)// 顯示到列表框的是...
{
strAdd = strAdd.Left(strAdd.Find(L" "));
}
CString strSql;
//判斷輸入是否是中文
const char *trmpAdd = T2A(strAdd);
if(*trmpAdd & 0x80 && trmpAdd[1] & 0x80)//是
strSql = L"select Locus,LocusID from tbLocus where Locus like '" + strAdd + "%' ORDER BY LocusID";
else //否
strSql = L"select Locus,LocusID from tbLocus where LocusID like '" + strAdd + "%' ORDER BY LocusID";
char **tableResult;
int nRow, nColumn;
char *errmsg = NULL;
char *sql = (char*)W2A((LPCTSTR)strSql);
sqlite3_get_table( db, sql, &tableResult, &nRow, &nColumn, &errmsg);
sql = NULL;
//插入數據(城市)
if(nRow != 0 && nColumn !=0)
{
CString strValue;
int number = nColumn;
for (int i = 0; i < nRow; i++)
{
strValue = "";
for(int j = 0; j < nColumn; j++)
{
strValue += tableResult[number];
strValue +=" ";
number++;
}
strValue = strValue.Left(strValue.GetLength()-1);
int index = strValue.Find(L" ");
CString tempValue = strValue.Left(index);
while(tempValue.GetLength() < 4)
{
tempValue.Insert(index,L" ");
}
strValue = strValue.Right(strValue.GetLength()-index);
strValue = tempValue + strValue;
m_AddStart.AddString(strValue);
}
}
/* for(int j = 0; j < nColumn; j++)
{
strValue += tableResult[number];
strValue +=" ";
number++;
}
strValue = strValue.Left(strValue.GetLength()-1);
int index = strValue.Find(L" ");
CString tempValue = strValue.Left(index);
while(GetByteValue(tempValue) < 10)
{
tempValue.Insert(index,L" ");
}
strValue = strValue.Right(strValue.GetLength()-index);
strValue = tempValue + strValue;
m_AddStart.AddString(strValue);*/
sqlite3_close(db);
sqlite3_free_table(tableResult);
}
}
//目的地組合框列表打開觸發
void CCondition::OnDropdownCOMBOEnd()
{
// TODO: Add your control notification handler code here
if(m_Airplane.GetCheck())
{
USES_CONVERSION;
//限制條件起始地
OpenSqlite();
CString strAdd;
m_AddEnd.GetWindowText(strAdd);
m_AddEnd.ResetContent();
if(strAdd.Find(L" ") != -1)// 顯示到列表框的是...
strAdd = strAdd.Left(strAdd.Find(L" "));
CString strSql;
//判斷輸入是否中文
const char *trmpAdd = T2A(strAdd);
if(*trmpAdd & 0x80 && trmpAdd[1] & 0x80)//是
strSql = L"select Locus,LocusID from tbLocus where Locus like '" + strAdd + "%' ORDER BY LocusID";
else //否
strSql = L"select Locus,LocusID from tbLocus where LocusID like '" + strAdd + "%' ORDER BY LocusID";
char **tableResult;
int nRow, nColumn;
char *errmsg = NULL;
char *sql = (char*)W2A((LPCTSTR)strSql);
sqlite3_get_table( db, sql, &tableResult, &nRow, &nColumn, &errmsg);
sql = NULL;
//插入數據(城市)
if(nRow != 0 && nColumn !=0)
{
CString strValue;
int number = nColumn;
for (int i = 0; i < nRow; i++)
{
strValue = "";
for(int j = 0; j < nColumn; j++)
{
strValue += tableResult[number];
strValue += " ";
number++;
}
strValue = strValue.Left(strValue.GetLength()-1);
int index = strValue.Find(L" ");
CString tempValue = strValue.Left(index);
while(tempValue.GetLength() < 4)
{
tempValue.Insert(index,L" ");
}
strValue = strValue.Right(strValue.GetLength()-index);
strValue = tempValue + strValue;
m_AddEnd.AddString(strValue);
}
}
sqlite3_close(db);
sqlite3_free_table(tableResult);
}
}
//創建打開sqlite數據庫
void CCondition::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;
}
//獲取字符串的字節數
int CCondition::GetByteValue(CString value)
{
USES_CONVERSION;
int ByteValue = 0;
int templength = value.GetLength();
for(int i = 1; i <= templength; i++)
{
const char *trmpAdd = T2A(value.Left(i));
value = value.Right(value.GetLength()-1);
if(*trmpAdd & 0x80 && trmpAdd[1] & 0x80)
ByteValue += 2;
else
ByteValue++;
}
return ByteValue;
}
//獲取起始地
CString CCondition::GetAddStart()
{
return m_AddStart1;
}
//獲取目的地
CString CCondition::GetAddEnd()
{
return m_AddEnd1;
}
//獲取星期
CString CCondition::GetAddWeek()
{
return m_Week1;
}
//獲取航空公司
CString CCondition::GetAddCompany()
{
return m_Company1;
}
//用戶改變起始地組合框中編輯框內容
void CCondition::OnEditchangeCOMBOStart()
{
// TODO: Add your control notification handler code here
m_AddStart.GetWindowText(m_AddStart1);
if(m_AddStart1.Find(L" ") != -1)
{
m_AddStart1 = m_AddStart1.Right(m_AddStart1.GetLength()-m_AddStart1.Find(L" "));
m_AddStart1.TrimLeft();
}
}
//關閉起始地列表框
void CCondition::OnCloseupCOMBOStart()
{
// TODO: Add your control notification handler code here
int Index = m_AddStart.GetCurSel();
if(Index >= 0)
m_AddStart.GetLBText(Index,m_AddStart1);
else
m_AddStart.GetWindowText(m_AddStart1);
if(m_AddStart1.Find(L" ") != -1)
{
m_AddStart1 = m_AddStart1.Right(m_AddStart1.GetLength()-m_AddStart1.Find(L" "));
m_AddStart1.TrimLeft();
}
}
//關閉目的地列表框
void CCondition::OnCloseupCOMBOEnd()
{
// TODO: Add your control notification handler code here
int Index = m_AddEnd.GetCurSel();
if(Index >= 0)
m_AddEnd.GetLBText(Index,m_AddEnd1);
else
m_AddEnd.GetWindowText(m_AddEnd1);
if(m_AddEnd1.Find(L" ") != -1)
{
m_AddEnd1 = m_AddEnd1.Right(m_AddEnd1.GetLength()-m_AddEnd1.Find(L" "));
m_AddEnd1.TrimLeft();
}
}
//用戶改變目的地組合框中編輯框內容
void CCondition::OnEditchangeCOMBOEnd()
{
m_AddEnd.GetWindowText(m_AddEnd1);
if(m_AddEnd1.Find(L" ") != -1)
{
m_AddEnd1 = m_AddEnd1.Right(m_AddEnd1.GetLength()-m_AddEnd1.Find(L" "));
m_AddEnd1.TrimLeft();
}
}
//用戶改變航班公司組合框中編輯框內容
void CCondition::OnEditchangeCOMBOCompany()
{
m_Company.GetWindowText(m_Company1);
}
//關閉航班公司列表框
void CCondition::OnCloseupCOMBOCompany()
{
int Index = m_Company.GetCurSel();
if(Index >= 0)
m_Company.GetLBText(Index,m_Company1);
else
m_Company.GetWindowText(m_Company1);
}
//日期控件的編輯框改變時
void CCondition::OnDatetimechangeDATETIMStart(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
CTime temptime;
m_DataCtr.GetTime(temptime);
int tempweek = 0;
tempweek = temptime.GetDayOfWeek();
if(tempweek == 1)
tempweek = 7;
else
tempweek-=1;
m_Week1.Format(L"%d",tempweek);
*pResult = 0;
}
void CCondition::OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: Add your message handler code here
CRect tabRect,tempRect;
GetClientRect(&tabRect);
//航班時刻單選
tempRect.left=tabRect.left +20;
tempRect.top=(tabRect.bottom)/6*1/6;
tempRect.right=tabRect.right-20;
tempRect.bottom=(tabRect.bottom)/6*1;
m_Airplane.MoveWindow(&tempRect);
//火車時刻單選
tempRect.left=tabRect.left +20;
tempRect.top +=(tabRect.bottom)/6*1;
tempRect.right=tabRect.right-20;
tempRect.bottom=(tabRect.bottom)/6*2;
m_Train.MoveWindow(&tempRect);
//----------------------------------------------------------------
//起始地靜態文本框
tempRect.left=tabRect.left +20;
tempRect.top +=(tabRect.bottom)/6*1;
tempRect.right=(tabRect.right-40)/3+20;
tempRect.bottom=(tabRect.bottom)/6*3;
m_StaticAddStart.MoveWindow(&tempRect);
//起始地組合框
tempRect.left=(tabRect.right-40)/3+20+2;
tempRect.bottom=(tabRect.bottom)/6*3 - 20;
tempRect.right=tabRect.right-20;
m_AddStart.MoveWindow(&tempRect);
//----------------------------------------------------------------
//目的地地靜態文本框
tempRect.left=tabRect.left +20;
tempRect.top +=(tabRect.bottom)/6*1;
tempRect.right=(tabRect.right-40)/3+20;
tempRect.bottom=(tabRect.bottom)/6*4;
m_StaticAddEnd.MoveWindow(&tempRect);
//目的地組合框
tempRect.left=(tabRect.right-40)/3+20+2;
tempRect.right=tabRect.right-20;
tempRect.bottom=(tabRect.bottom)/6*4 - 20;
m_AddEnd.MoveWindow(&tempRect);
//--------------------------------------------------------------------
//起始日期靜態文本框
tempRect.left=tabRect.left +20;
tempRect.top +=(tabRect.bottom)/6*1;
tempRect.right=(tabRect.right-40)/3+20;
tempRect.bottom=(tabRect.bottom)/6*5;
m_StaticData.MoveWindow(&tempRect);
//日期控件
tempRect.left=(tabRect.right-40)/3+20+2;
tempRect.right=tabRect.right-20;
tempRect.bottom=(tabRect.bottom)/6*5 - 20;
m_DataCtr.MoveWindow(&tempRect);
//--------------------------------------------------------------
//公司名稱靜態文本框
tempRect.left=tabRect.left +20;
tempRect.top +=(tabRect.bottom)/6*1;;
tempRect.right=(tabRect.right-40)/3+20;
tempRect.bottom=(tabRect.bottom)/6*6;
m_StaticCompany.MoveWindow(&tempRect);
//公司名組合框
tempRect.left=(tabRect.right-40)/3+20+2;
tempRect.right=tabRect.right-20;
tempRect.bottom=(tabRect.bottom)/6*6 - 20;
m_Company.MoveWindow(&tempRect);
// Do not call CPropertyPage::OnPaint() for painting messages
}
void CCondition::OnSize(UINT nType, int cx, int cy)
{
CPropertyPage::OnSize(nType, cx, cy);
// TODO: Add your message handler code here
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -