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

📄 memsearch.cpp

📁 使用vc进行数据库编程的好例子
💻 CPP
字号:
// MemSearch.cpp : implementation file
//

#include "stdafx.h"
#include "ManageSystem.h"
#include "MemSearch.h"

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

#define RESULT_SHOW	0
#define RESULT_HIDE	1

/////////////////////////////////////////////////////////////////////////////
// CMemSearch dialog
IMPLEMENT_DYNCREATE(CMemSearch, CDialog)

CMemSearch::CMemSearch(CWnd* pParent /*=NULL*/)
	: CDialog(CMemSearch::IDD, pParent)
{
	//{{AFX_DATA_INIT(CMemSearch)
	m_City = _T("");
	m_Company = _T("");
	m_KeyWork = _T("");
	m_Name = _T("");
	m_Province = _T("");
	m_UserName = _T("");
	//}}AFX_DATA_INIT
}


void CMemSearch::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CMemSearch)
	DDX_Control(pDX, IDC_SEARCH2, m_btnSeach2);
	DDX_Control(pDX, IDC_SEARCH1, m_btnSeach1);
	DDX_Text(pDX, IDC_CITY, m_City);
	DDX_Text(pDX, IDC_COMPANY, m_Company);
	DDX_Text(pDX, IDC_M_KEYWORD, m_KeyWork);
	DDX_Text(pDX, IDC_NAME, m_Name);
	DDX_Text(pDX, IDC_PROVINCE, m_Province);
	DDX_Text(pDX, IDC_USERNAME, m_UserName);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CMemSearch, CDialog)
	//{{AFX_MSG_MAP(CMemSearch)
	ON_BN_CLICKED(IDC_SEARCH1, OnSearchByClass)
	ON_BN_CLICKED(IDC_SEARCH2, OnSearchByDark)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMemSearch message handlers

void CMemSearch::OnOK() 
{
	// TODO: Add extra validation here
}

void CMemSearch::OnCancel() 
{
	// TODO: Add extra cleanup here
}

void CMemSearch::OnSearchByClass() 
{
	// TODO: Add your control notification handler code here
	UpdateData(true);
	bool bIsNUll=true;

	if(g_isMlocked==false)
	{
		if(g_mSet->IsOpen())
			g_mSet->Close();
	}
	else
	{
		AfxMessageBox("locked,try again");
		return;
	}

	///===========================================
	CString sqlComm,temp;
	sqlComm="SELECT * FROM memberinfo WHERE";

	if(!m_City.IsEmpty())
	{
		temp=" city LIKE '%";
		temp+=m_City;
		temp+="%'";
		sqlComm+=temp;
		bIsNUll=false;
	}

	if(!m_Company.IsEmpty())
	{
		if(bIsNUll==false)
			temp=" AND mem_company LIKE '%";
		else
			temp=" mem_company LIKE '%";
		temp+=m_Company;
		temp+="%'";
		sqlComm+=temp;
		bIsNUll=false;
	}

	if(!m_Name.IsEmpty())
	{
		if(bIsNUll==false)
			temp=" AND mem_name LIKE '%";
		else
			temp=" mem_name LIKE '%";
		temp+=m_Name;
		temp+="%'";
		sqlComm+=temp;
		bIsNUll=false;
	}

	if(!m_Province.IsEmpty())
	{
		if(bIsNUll==false)
			temp=" AND province LIKE '%";
		else
			temp=" province LIKE '%";
		temp+=m_Province;
		temp+="%'";
		sqlComm+=temp;
		bIsNUll=false;
	}

	if(!m_UserName.IsEmpty())
	{
		if(bIsNUll==false)
			temp=" AND user_name LIKE '%";
		else
			temp=" user_name LIKE '%";

		temp+=m_UserName;
		temp+="%'";
		sqlComm+=temp;
		bIsNUll=false;
	}
	
	//==================================================
	if(bIsNUll==true)
	{
		AfxMessageBox("请输入关键信息");
		return;
	}
	///================================================
	
	try
	{
		g_mSet->Open(CRecordset::snapshot,sqlComm);
		g_isMlocked=true;
		::SendMessage(::AfxGetMainWnd()->m_hWnd,WM_SHOW_MEM_RESULT_SIMP,0,RESULT_SHOW);

	}
	catch(CDBException* pe)
	{
		AfxMessageBox("用户信息数据搜索错误:\n"+pe->m_strError);
		if(g_mSet)
		{
			if(g_mSet->IsOpen())
				g_mSet->Close();
			delete g_mSet;
		}
		pe->Delete();
	}	
}

void CMemSearch::OnSearchByDark() 
{
	// TODO: Add your control notification handler code here
	UpdateData(true);

	if(g_isMlocked==false)
	{
		if(g_mSet->IsOpen())
			g_mSet->Close();
	}
	else
	{
		AfxMessageBox("locked,try again");
		return;
	}

	if(m_KeyWork.IsEmpty())
	{
		AfxMessageBox("请输入关键字。");
		return;
	}
	///===========================================
	CString sqlComm,temp;
	sqlComm="SELECT * FROM memberinfo WHERE";

	temp=" city LIKE '%";
	temp+=m_KeyWork;
	temp+="%'";
	sqlComm+=temp;

	temp=" OR mem_company LIKE '%";
	temp+=m_KeyWork;
	temp+="%'";
	sqlComm+=temp;

	temp=" OR mem_name LIKE '%";
	temp+=m_KeyWork;
	temp+="%'";
	sqlComm+=temp;

	temp=" OR province LIKE '%";
	temp+=m_KeyWork;
	temp+="%'";
	sqlComm+=temp;

	temp=" OR user_name LIKE '%";
	temp+=m_KeyWork;
	temp+="%'";
	sqlComm+=temp;

	temp=" OR mem_telephone LIKE '%";
	temp+=m_KeyWork;
	temp+="%'";
	sqlComm+=temp;

	///================================================
	
	try
	{
		g_mSet->Open(CRecordset::snapshot,sqlComm);
		g_isMlocked=true;
		::SendMessage(::AfxGetMainWnd()->m_hWnd,WM_SHOW_MEM_RESULT_SIMP,0,RESULT_SHOW);

	}
	catch(CDBException* pe)
	{
		AfxMessageBox("用户信息数据搜索错误:\n"+pe->m_strError);
		if(g_mSet)
		{
			if(g_mSet->IsOpen())
				g_mSet->Close();
			delete g_mSet;
		}
		pe->Delete();
	}		
}

BOOL CMemSearch::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	m_btnSeach1.SetShade(CShadeButtonST::SHS_HSHADE,8,20,5,RGB(55,55,255));
	m_btnSeach2.SetShade(CShadeButtonST::SHS_HSHADE,8,20,5,RGB(55,55,255));
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

⌨️ 快捷键说明

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