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

📄 condition.cpp

📁 本程序是基于winCE开发应用sqlite数据库 数据库在程序当中附有 可以在虚拟机以及设别上查看功能!WinCE编译通过
💻 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 + -