www.pudn.com > Library.rar > QueryBasicDlg.cpp, change:2009-04-11,size:4221b


// QueryBasicDlg.cpp : implementation file 
// 
 
#include "stdafx.h" 
#include "Library.h" 
#include "QueryBasicDlg.h" 
#include "BookDataSet.h" 
#include "QueryAdvancedDlg.h" 
 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
 
///////////////////////////////////////////////////////////////////////////// 
// CQueryBasicDlg dialog 
 
 
CQueryBasicDlg::CQueryBasicDlg(CWnd* pParent /*=NULL*/) 
	: CDialog(CQueryBasicDlg::IDD, pParent) 
{ 
	//{{AFX_DATA_INIT(CQueryBasicDlg) 
	m_strKeyWord = _T(""); 
	//}}AFX_DATA_INIT 
} 
 
 
void CQueryBasicDlg::DoDataExchange(CDataExchange* pDX) 
{ 
	CDialog::DoDataExchange(pDX); 
	//{{AFX_DATA_MAP(CQueryBasicDlg) 
	DDX_Control(pDX, IDC_LIST_RESULT, m_listResult); 
	DDX_Control(pDX, IDC_LIST_DETAIL, m_listDetail); 
	DDX_Text(pDX, IDC_KEY_WORD, m_strKeyWord); 
	//}}AFX_DATA_MAP 
} 
 
 
BEGIN_MESSAGE_MAP(CQueryBasicDlg, CDialog) 
	//{{AFX_MSG_MAP(CQueryBasicDlg) 
	ON_BN_CLICKED(IDC_QUERY, OnQuery) 
	ON_LBN_SELCHANGE(IDC_LIST_RESULT, OnSelchangeListResult) 
	ON_BN_CLICKED(IDC_ADVANCED_QUERY, OnAdvancedQuery) 
	//}}AFX_MSG_MAP 
END_MESSAGE_MAP() 
 
///////////////////////////////////////////////////////////////////////////// 
// CQueryBasicDlg message handlers 
 
void CQueryBasicDlg::OnQuery()  
{ 
    UpdateData(); 
	m_listResult.ResetContent(); 
	if(!m_rsBookDataSet.IsOpen()){ 
		m_rsBookDataSet.Open(); 
	} 
	m_rsBookDataSet.m_strFilter="BOOK_NAME like '%"+m_strKeyWord+"%'"; 
	m_rsBookDataSet.Requery(); 
 
	if(m_rsBookDataSet.IsEOF()){ 
		AfxMessageBox("查无此书"); 
		return; 
	} 
	while(!m_rsBookDataSet.IsEOF()){ 
		m_listResult.AddString(m_rsBookDataSet.m_BOOK_NAME); 
		m_rsBookDataSet.MoveNext(); 
	}	 
} 
 
void CQueryBasicDlg::OnSelchangeListResult()  
{ 
    CString aColCaption[6]; 
	aColCaption[0]="书号:    "; 
	aColCaption[1]="书名:    "; 
	aColCaption[2]="作者:    "; 
	aColCaption[3]="出版社:    "; 
	aColCaption[4]="出版日期:    "; 
	aColCaption[5]="是否能借出:    "; 
 
	m_listDetail.ResetContent(); 
	int curSel; 
	CString strDetail; 
	CString strLine; 
	curSel=m_listResult.GetCurSel(); 
	m_rsBookDataSet.SetAbsolutePosition(curSel+1); 
	for(int i=0;i<m_rsBookDataSet.m_nFields;i++){ 
		m_rsBookDataSet.GetFieldValue(i,strDetail); 
		strLine.Empty(); 
		strLine+=aColCaption[i]; 
		strLine+=strDetail; 
		m_listDetail.AddString(strLine); 
	}	 
} 
 
void CQueryBasicDlg::OnAdvancedQuery()  
{ 
	int i; 
	CQueryAdvancedDlg advancedQuery; 
	advancedQuery.DoModal(); 
	CString str; 
	CString strFilter; 
	CString * astrKeyWord[5]; 
    CString astrColumnCaption[5]; 
	CString * astrColumnVal[5]; 
	CString * aAndOr[5]; 
	aAndOr[1]=&advancedQuery.m_andOr1; 
	aAndOr[2]=&advancedQuery.m_andOr2; 
	aAndOr[3]=&advancedQuery.m_andOr3; 
	aAndOr[4]=&advancedQuery.m_andOr4; 
	astrColumnVal[1]=&advancedQuery.m_condition1; 
    astrColumnVal[2]=&advancedQuery.m_condition2; 
	astrColumnVal[3]=&advancedQuery.m_condition3; 
	astrColumnVal[4]=&advancedQuery.m_condition4; 
 
	for(i=1;i<5;i++){ 
		if(!astrColumnVal[i]->Compare("书号")){ 
			astrColumnCaption[i]="BOOK_ID"; 
			continue; 
		} 
		if(!astrColumnVal[i]->Compare("书名")){ 
			astrColumnCaption[i]="BOOK_NAME"; 
			continue; 
		} 
		if(!astrColumnVal[i]->Compare("作者")){ 
			astrColumnCaption[i]="AUTHOR"; 
			continue; 
		} 
		if(!astrColumnVal[i]->Compare("出版社")){ 
			astrColumnCaption[i]="PRESS"; 
			continue; 
		} 
	} 
	astrKeyWord[1]=&advancedQuery.m_keyword1; 
	astrKeyWord[2]=&advancedQuery.m_keyword2; 
	astrKeyWord[3]=&advancedQuery.m_keyword3; 
	astrKeyWord[4]=&advancedQuery.m_keyword4; 
	i=1; 
	while(!astrKeyWord[i]->IsEmpty()&&i<5){ 
		if(i!=1){ 
			strFilter+=" "; 
			strFilter+=*aAndOr[i-1]; 
			strFilter+=" "; 
		} 
		str.Format("%s='%s'",astrColumnCaption[i],*astrKeyWord[i]); 
		strFilter+=str; 
		i++; 
	} 
	m_rsBookDataSet.m_strFilter=strFilter; 
	if(!m_rsBookDataSet.IsOpen()){ 
		m_rsBookDataSet.Open(); 
	} 
	m_rsBookDataSet.Requery(); 
	m_listResult.ResetContent(); 
	m_listDetail.ResetContent(); 
	if(m_rsBookDataSet.IsEOF()){ 
		AfxMessageBox("查无此书"); 
		return; 
	} 
	while(!m_rsBookDataSet.IsEOF()){ 
		m_listResult.AddString(m_rsBookDataSet.m_BOOK_NAME); 
		m_rsBookDataSet.MoveNext(); 
	} 
	 
}