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

📄 queryuserinfodlg.cpp

📁 手机话费程序
💻 CPP
字号:
// QueryUserInfoDlg.cpp : implementation file
//

#include "stdafx.h"
#include "mphonequery.h"
#include "QueryUserInfoDlg.h"
#include "MPhoneQueryView.h"
#include "MainFrm.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CQueryUserInfoDlg dialog


CQueryUserInfoDlg::CQueryUserInfoDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CQueryUserInfoDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CQueryUserInfoDlg)
	m_bCheckPhoneNo = FALSE;
	m_bCheckUserNo = FALSE;
	//}}AFX_DATA_INIT
}


void CQueryUserInfoDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CQueryUserInfoDlg)
	DDX_Check(pDX, IDC_CHECK_PHONENO, m_bCheckPhoneNo);
	DDX_Check(pDX, IDC_CHECK_USERNO, m_bCheckUserNo);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CQueryUserInfoDlg, CDialog)
	//{{AFX_MSG_MAP(CQueryUserInfoDlg)
	ON_CBN_SELCHANGE(IDC_COMBO_USERNO, OnSelchangeComboUserno)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CQueryUserInfoDlg message handlers

void CQueryUserInfoDlg::OnOK() 
{
	// TODO: Add extra validation here
	UpdateData(true);
	int iIndex;
	_variant_t strQuery;

	if ( !m_bCheckUserNo && !m_bCheckPhoneNo )
	{
		AfxMessageBox(_T("请选择查询条件!"), MB_ICONEXCLAMATION);
		return;
	}

	if (m_bCheckUserNo)
	{
		iIndex = ((CComboBox*)GetDlgItem(IDC_COMBO_USERNO))->GetCurSel();
		((CComboBox*)GetDlgItem(IDC_COMBO_USERNO))->GetLBText(iIndex,m_strUserNo);

		if (m_strUserNo == _T("无用户纪录"))
		{
			m_strUserNo = "%";
		}
	}
	else
	{
		m_strUserNo = "%";
	}

	if (m_bCheckPhoneNo)
	{
		iIndex = ((CComboBox*)GetDlgItem(IDC_COMBO_PHONENO))->GetCurSel();
		((CComboBox*)GetDlgItem(IDC_COMBO_PHONENO))->GetLBText(iIndex,m_strPhoneNo);
	}
	else
	{
		m_strPhoneNo = "%";
	}

	if ( m_strPhoneNo == "%" )
	{
		strQuery = "select * from phone, customer where phone.cus_id = customer.cus_id \
			and customer.ID_no = '"+m_strUserNo+"'";
	}
	else if ( m_strUserNo == "%" )
	{
		strQuery = "select * from phone where phone_no = '"+m_strPhoneNo+"'";
	}
	else 
	{
		strQuery = "select * from phone, customer where phone_no = '"+m_strPhoneNo+"' \
			and cus_id = '"+m_strUserNo+"'";
	}
	
	CMPhoneQueryView* pView = (CMPhoneQueryView*)(((CMainFrame*)AfxGetMainWnd())->GetActiveView());
	pView->RefreshUser(strQuery, m_strUserNo);
	
	CDialog::OnOK();
}

BOOL CQueryUserInfoDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	_variant_t strQuery, Holder;
	int i = 0;         

	strQuery = "select distinct ID_no from customer";
	theApp.ADOExecute(theApp.m_pADOSet,strQuery);

	int iUserCount = theApp.m_pADOSet->GetRecordCount();
	if( iUserCount > 0 )
	{
		theApp.m_pADOSet->MoveFirst();
		Holder = theApp.m_pADOSet->GetCollect("ID_no");
		CString strUserNo = (char*)(_bstr_t)Holder;
		
		for(; i < iUserCount; i++)
		{
			Holder = theApp.m_pADOSet->GetCollect("ID_no");
			CString strSubUserNo = (char*)(_bstr_t)Holder;
			((CComboBox*)GetDlgItem(IDC_COMBO_USERNO))->InsertString(i, strSubUserNo);
			
			theApp.m_pADOSet->MoveNext();
		}
		((CComboBox*)GetDlgItem(IDC_COMBO_USERNO))->SetCurSel(0);

		strQuery = "select cus_id from customer where ID_no = '"+strUserNo+"'";
		theApp.ADOExecute(theApp.m_pADOSet,strQuery); 
		theApp.m_pADOSet->MoveFirst();
		Holder = theApp.m_pADOSet->GetCollect("cus_id");
		CString strUserId = (char*)(_bstr_t)Holder;

		strQuery = "select phone_no from phone where cus_id ='"+strUserId+"'";
		theApp.ADOExecute(theApp.m_pADOSet,strQuery);

		int iPhoneCount = theApp.m_pADOSet->GetRecordCount();
		if (iPhoneCount > 0)
		{
			theApp.m_pADOSet->MoveFirst();
			for(int j = 0; j < iPhoneCount; j++)
			{
				Holder = theApp.m_pADOSet->GetCollect("phone_no");
				((CComboBox*)GetDlgItem(IDC_COMBO_PHONENO))->InsertString(j, Holder.vt==VT_NULL?"":(char*)(_bstr_t)Holder);
				theApp.m_pADOSet->MoveNext();
			}
			((CComboBox*)GetDlgItem(IDC_COMBO_PHONENO))->SetCurSel(0);
		}
	}

	CString strUserNo = _T("无用户纪录");
	((CComboBox*)GetDlgItem(IDC_COMBO_USERNO))->InsertString(i, strUserNo);

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

void CQueryUserInfoDlg::OnSelchangeComboUserno() 
{
	// TODO: Add your control notification handler code here
	int iIndex;
	CString strText;
	_variant_t strQuery, Holder;

	iIndex = ((CComboBox*)GetDlgItem(IDC_COMBO_USERNO))->GetCurSel();
	if(iIndex != CB_ERR)
	{
		((CComboBox*)GetDlgItem(IDC_COMBO_USERNO))->GetLBText(iIndex,strText);
		int iCount = ((CComboBox*)GetDlgItem(IDC_COMBO_PHONENO))->GetCount();
		for(int i = 0 ; i < iCount; i++)
		{
			((CComboBox*)GetDlgItem(IDC_COMBO_PHONENO))->DeleteString(0);
		}

		if ( strText == _T("无用户纪录"))
		{
			strQuery = "select * from phone where cus_id is NULL";
			theApp.ADOExecute(theApp.m_pADOSet,strQuery);
			iCount = theApp.m_pADOSet->GetRecordCount();

			if (iCount == 0)
			{
				return;
			}

			theApp.m_pADOSet->MoveFirst();
			for(i = 0; i < iCount; i++)
			{
				Holder  = theApp.m_pADOSet->GetCollect("phone_no");
				CString strPhoneNo = (char*)(_bstr_t)Holder;
				((CComboBox*)GetDlgItem(IDC_COMBO_PHONENO))->InsertString(i, strPhoneNo);
				theApp.m_pADOSet->MoveNext();
			}
			((CComboBox*)GetDlgItem(IDC_COMBO_PHONENO))->SetCurSel(0);
		}
		else
		{
			strQuery = "select cus_id from customer where ID_no = '"+strText+"'";
			theApp.ADOExecute(theApp.m_pADOSet,strQuery); 
			theApp.m_pADOSet->MoveFirst();
			Holder = theApp.m_pADOSet->GetCollect("cus_id");
			CString strUserId = (char*)(_bstr_t)Holder;

			strQuery = "select * from phone where cus_id = '"+strUserId+"'";
			theApp.ADOExecute(theApp.m_pADOSet,strQuery);
			iCount = theApp.m_pADOSet->GetRecordCount();

			if (iCount > 0)
			{
				theApp.m_pADOSet->MoveFirst();
				for(i = 0; i < iCount; i++)
				{
					Holder  = theApp.m_pADOSet->GetCollect("phone_no");
					CString strPhoneNo = (char*)(_bstr_t)Holder;
					((CComboBox*)GetDlgItem(IDC_COMBO_PHONENO))->InsertString(i, strPhoneNo);
					theApp.m_pADOSet->MoveNext();
				}
				((CComboBox*)GetDlgItem(IDC_COMBO_PHONENO))->SetCurSel(0);
			}
		}
	}
	
	return;
}

⌨️ 快捷键说明

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