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

📄 querypage.cpp

📁 数据库管理软件,具有很多功能,应用DBS数据库
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// QueryPage.cpp : implementation file
//

#include "stdafx.h"
#include "resource.h"
#include "QueryPage.h"
#include "QuerySheet.h"
#include "demo2005Dlg.h"
#include "demoCommon.h"

#ifdef _DEBUG
#undef THIS_FILE
static char BASED_CODE THIS_FILE[] = __FILE__;
#endif

IMPLEMENT_DYNCREATE(CSelectPage1, CPropertyPage)
IMPLEMENT_DYNCREATE(CWherePage2, CPropertyPage)
IMPLEMENT_DYNCREATE(CExecutePage3, CPropertyPage)
IMPLEMENT_DYNCREATE(CResultPage4, CPropertyPage)


/////////////////////////////////////////////////////////////////////////////
// CSelectPage1 property page

CSelectPage1::CSelectPage1() : CPropertyPage(CSelectPage1::IDD)
{
	//{{AFX_DATA_INIT(CSelectPage1)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}

CSelectPage1::~CSelectPage1()
{
}

void CSelectPage1::DoDataExchange(CDataExchange* pDX)
{
	CPropertyPage::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CSelectPage1)
	DDX_Control(pDX, IDC_SELECTED_FIELD_LIST, m_selectedList);
	DDX_Control(pDX, IDC_FIELD_LIST, m_fieldList);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CSelectPage1, CPropertyPage)
	//{{AFX_MSG_MAP(CSelectPage1)
	ON_BN_CLICKED(IDC_SELECT_BUTTON, OnSelectButton)
	ON_BN_CLICKED(IDC_UNSELECT_BUTTON, OnUnselectButton)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()


/////////////////////////////////////////////////////////////////////////////
// CWherePage2 property page

CWherePage2::CWherePage2() : CPropertyPage(CWherePage2::IDD)
{
	//{{AFX_DATA_INIT(CWherePage2)
	m_op = _T("");
	m_val = _T("");
	m_fName = _T("");
	//}}AFX_DATA_INIT

	bSaved = TRUE;
}

CWherePage2::~CWherePage2()
{
}

void CWherePage2::DoDataExchange(CDataExchange* pDX)
{
	CPropertyPage::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CWherePage2)
	DDX_Control(pDX, IDC_VALUE_CAPTION, m_staValCaption);
	DDX_Control(pDX, IDC_OPERATER_COMBO, m_cmbOp);
	DDX_Control(pDX, IDC_FIELD_VALUE_EDIT, m_edVal);
	DDX_Control(pDX, IDC_FIELD_NAME_COMBO, m_cmbFName);
	DDX_CBString(pDX, IDC_OPERATER_COMBO, m_op);
	DDX_Text(pDX, IDC_FIELD_VALUE_EDIT, m_val);
	DDX_CBString(pDX, IDC_FIELD_NAME_COMBO, m_fName);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CWherePage2, CPropertyPage)
	//{{AFX_MSG_MAP(CWherePage2)
	ON_BN_CLICKED(IDC_AND_BUTTON, OnAndButton)
	ON_BN_CLICKED(IDC_OR_BUTTON, OnOrButton)
	ON_CBN_SELCHANGE(IDC_FIELD_NAME_COMBO, OnSelchangeFieldNameCombo)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()


/////////////////////////////////////////////////////////////////////////////
// CExecutePage3 property page

CExecutePage3::CExecutePage3() : CPropertyPage(CExecutePage3::IDD)
{
	//{{AFX_DATA_INIT(CExecutePage3)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}

CExecutePage3::~CExecutePage3()
{
}

void CExecutePage3::DoDataExchange(CDataExchange* pDX)
{
	CPropertyPage::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CExecutePage3)
	DDX_Control(pDX, IDC_SELECT_SENTENCE_EDIT, m_SelSentence);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CExecutePage3, CPropertyPage)
	//{{AFX_MSG_MAP(CExecutePage3)
	ON_WM_PAINT()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()


/////////////////////////////////////////////////////////////////////////////
// CResultPage4 property page

CResultPage4::CResultPage4() : CPropertyPage(CResultPage4::IDD)
{
	//{{AFX_DATA_INIT(CResultPage4)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}

CResultPage4::~CResultPage4()
{
}

void CResultPage4::DoDataExchange(CDataExchange* pDX)
{
	CPropertyPage::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CResultPage4)
	DDX_Control(pDX, IDC_VIEW_LIST, m_viewList);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CResultPage4, CPropertyPage)
	//{{AFX_MSG_MAP(CResultPage4)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()


/////////////////////////////////////////////////////////////////////////////


// 修改各页的按钮
BOOL CSelectPage1::OnSetActive() 
{
	CQuerySheet *pParent = (CQuerySheet*)GetParent();
	pParent->SetWizardButtons( PSWIZB_NEXT );	

	return CPropertyPage::OnSetActive();
}

BOOL CWherePage2::OnSetActive() 
{
	CQuerySheet *pParent = (CQuerySheet*)GetParent();
	pParent->SetWizardButtons( PSWIZB_BACK | PSWIZB_NEXT );	
	
	return CPropertyPage::OnSetActive();
}

BOOL CExecutePage3::OnSetActive() 
{
	CQuerySheet *pParent = (CQuerySheet*)GetParent();
	pParent->SetWizardButtons( PSWIZB_BACK | PSWIZB_NEXT );	
	
	return CPropertyPage::OnSetActive();
}

BOOL CResultPage4::OnSetActive() 
{
	CQuerySheet *pParent = (CQuerySheet*)GetParent();
	pParent->SetWizardButtons( PSWIZB_BACK | PSWIZB_FINISH );	
	pParent->SetFinishText("保存");	

	return CPropertyPage::OnSetActive();
}


/******************************
 ** 对"选择字段"对话框的操作 **
 ******************************/

BOOL CSelectPage1::OnInitDialog() 
{
	CPropertyPage::OnInitDialog();
	
	// show fields-name in m_fieldList
	CQuerySheet *pParent = (CQuerySheet*)GetParent();
	CDemo2005Dlg *pDemo = (CDemo2005Dlg*)pParent->GetParent();
	for(int i=0; i<pDemo->fcnt; i++)
		m_fieldList.AddString((LPCTSTR)pDemo->pFieldDsc[i].fName);

	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CSelectPage1::OnSelectButton() 
{
/*	CQuerySheet *pParent = (CQuerySheet*)GetParent();
	int nMaxItems = pParent->fcnt;
	int *rgIndex = (int*)malloc( sizeof(int)*nMaxItems );
*/
	int nMaxItems, i;
	int *rgIndex;

	UpdateData(TRUE);
	
	// Get selected items
	nMaxItems = m_fieldList.GetSelCount();
	if( nMaxItems<=0 ) // select nothing
		return;

	rgIndex = (int*)malloc( sizeof(int)*nMaxItems );
	m_fieldList.GetSelItems( nMaxItems, rgIndex );

	// put selected items to m_selectedList
	for( i=0; i<nMaxItems; i++ )
	{
		CString sztmp;
		m_fieldList.GetText( rgIndex[i], sztmp );
		m_selectedList.AddString((LPCTSTR)sztmp);
	}

	// delete selected items from m_fieldList
	for( i=nMaxItems-1; i>=0; i-- )
		m_fieldList.DeleteString( rgIndex[i] );

}

void CSelectPage1::OnUnselectButton() 
{
	int nMaxItems, i;
	int *rgIndex;

	UpdateData(TRUE);
	
	// Get selected items
	nMaxItems = m_selectedList.GetSelCount();
	if( nMaxItems<=0 ) // select nothing
		return;

	rgIndex = (int*)malloc( sizeof(int)*nMaxItems );
	m_selectedList.GetSelItems( nMaxItems, rgIndex );

	// put selected items to m_selectedList
	for( i=0; i<nMaxItems; i++ )
	{
		CString sztmp;
		m_selectedList.GetText( rgIndex[i], sztmp );
		m_fieldList.AddString((LPCTSTR)sztmp);
	}

	// delete selected items from m_fieldList
	for( i=nMaxItems-1; i>=0; i-- )
		m_selectedList.DeleteString( rgIndex[i] );
	
}

LRESULT CSelectPage1::OnWizardNext() 
{
	int n;

	UpdateData(TRUE);
	
	// Get fields of view
	n = m_selectedList.GetCount();
	if( n<=0 )// no fields
	{
		AfxMessageBox("Should select fields for view first!", MB_OK|MB_ICONERROR);
		return -1;
	}

	// Get Parents
	CQuerySheet *pParent = (CQuerySheet*)GetParent();
	CDemo2005Dlg *pDemo = (CDemo2005Dlg*)pParent->GetParent();

	// save field description for query view
	pParent->rsltFcnt = n;
	pParent->prsltFieldDsc = (fieldDesc *)malloc( sizeof(fieldDesc)*n );

	n = 0;
	for(int  i=0; i<pParent->rsltFcnt; i++ )
	{
		CString sztmp;
		m_selectedList.GetText( i, sztmp );
		for(int j=0; j<pDemo->fcnt; j++)
		{
			if( !strcmp( (LPCTSTR)sztmp,pDemo->pFieldDsc[j].fName  ) )
			{
				// copy origin field description
				memcpy( (void*)&pParent->prsltFieldDsc[i],
						(void*)&pDemo->pFieldDsc[j],
						sizeof(fieldDesc) );
				// modify offset
				if( i==0 )
					pParent->prsltFieldDsc[i].offset = 0;
				else
					pParent->prsltFieldDsc[i].offset = pParent->prsltFieldDsc[i-1].offset
													 + pParent->prsltFieldDsc[i-1].fLen ;

				// remember origin field nth
				pParent->originFth[i] = j;

				// calculate record length
				n += pDemo->pFieldDsc[j].fLen;
			}
		}
	}

	pParent->rsltRlen = n; // query result record length
		
	
	return CPropertyPage::OnWizardNext();
}


/******************************
 ** 对"查询条件"对话框的操作 **
 ******************************/

BOOL CWherePage2::OnInitDialog() 
{
	CPropertyPage::OnInitDialog();
	
	// show fields-name in m_fieldCombo
	CQuerySheet *pParent = (CQuerySheet*)GetParent();
	CDemo2005Dlg *pDemo = (CDemo2005Dlg*)pParent->GetParent();
	for(int i=0; i<pDemo->fcnt; i++)
		m_cmbFName.AddString((LPCTSTR)pDemo->pFieldDsc[i].fName);
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

//AND button
void CWherePage2::OnAndButton() 
{
	// save a AND instruction
	if( !bSaved && SaveCondition() )
		bSaved = TRUE; // current condition saved
}

//OR button
void CWherePage2::OnOrButton() 
{
	// add last AND instruction first
	if( !bSaved && SaveCondition() )
	{
		// save index of OR in queryInst
		CQuerySheet *pParent = (CQuerySheet*)GetParent();
		pParent->qcond.orIndex[++pParent->qcond.ornumth] = pParent->qcond.icnt; // or index

		// current condition saved
		bSaved = TRUE;
	}
}

LRESULT CWherePage2::OnWizardNext() 
{
	CQuerySheet *pParent = (CQuerySheet*)GetParent();

	// add last AND instruction first
	if( !bSaved )
	{
		if( !SaveCondition() )
			return -1;
		bSaved = TRUE; // current condition saved
	}

	// save index of OR in queryInst
	if( pParent->qcond.orIndex[pParent->qcond.ornumth] != pParent->qcond.icnt )
		pParent->qcond.orIndex[++pParent->qcond.ornumth] = pParent->qcond.icnt;

	return CPropertyPage::OnWizardNext();

⌨️ 快捷键说明

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