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

📄 pdtsearch.cpp

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

#include "stdafx.h"
#include "ManageSystem.h"
#include "PdtSearch.h"

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

#define RESULT_SHOW	0
#define RESULT_HIDE	1
/////////////////////////////////////////////////////////////////////////////
// CPdtSearch dialog
IMPLEMENT_DYNCREATE(CPdtSearch, CDialog)

CPdtSearch::CPdtSearch(CWnd* pParent /*=NULL*/)
	: CDialog(CPdtSearch::IDD, pParent)
{
	//{{AFX_DATA_INIT(CPdtSearch)
	m_Company = _T("");
	m_Linkman = _T("");
	m_Telephone = _T("");
	m_ProductArea = _T("");
	m_Keyword = _T("");
	m_Name = _T("");
	m_ProviceArea = _T("");
	//}}AFX_DATA_INIT
}


void CPdtSearch::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CPdtSearch)
	DDX_Control(pDX, IDC_SEARCH4, m_btnSearch2);
	DDX_Control(pDX, IDC_SEARCH3, m_btnSearch1);
	DDX_Text(pDX, IDC_COMANYNAME, m_Company);
	DDX_Text(pDX, IDC_LINKMAN, m_Linkman);
	DDX_Text(pDX, IDC_LINKTELEPHONE, m_Telephone);
	DDX_Text(pDX, IDC_PDTAREA, m_ProductArea);
	DDX_Text(pDX, IDC_P_KEYWORD, m_Keyword);
	DDX_Text(pDX, IDC_PDTNAME, m_Name);
	DDX_Text(pDX, IDC_PROVICEAREA, m_ProviceArea);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CPdtSearch, CDialog)
	//{{AFX_MSG_MAP(CPdtSearch)
	ON_BN_CLICKED(IDC_SEARCH3, OnSearchByClass)
	ON_BN_CLICKED(IDC_SEARCH4, OnSearchByDark)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CPdtSearch message handlers

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

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

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

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

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

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

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

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

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

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

	if(!m_Telephone.IsEmpty())
	{
		if(bIsNUll==false)
			temp=" AND comp_telephone LIKE '%";
		else
			temp=" comp_telephone LIKE '%";
		temp+=m_Telephone;
		temp+="%'";
		sqlComm+=temp;
		bIsNUll=false;
	}
	//==========================================
	if(bIsNUll==true)
	{
		AfxMessageBox("请输入关键信息.");
		return;
	}
	//==========================================
	try
	{
		g_pSet->Open(CRecordset::snapshot,sqlComm);
		g_isPLocked=true;
		::SendMessage(::AfxGetMainWnd()->m_hWnd,WM_SHOW_PRO_RESULT_SIMP,0,RESULT_SHOW);

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

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

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

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

	temp=" company_name LIKE '%";
	temp+=m_Keyword;
	temp+="%'";
	sqlComm+=temp;

	temp=" OR linkman LIKE '%";
	temp+=m_Keyword;
	temp+="%'";
	sqlComm+=temp;


	temp=" OR prodt_name LIKE '%";
	temp+=m_Keyword;
	temp+="%'";
	sqlComm+=temp;

	temp=" OR producing_area LIKE '%";
	temp+=m_Keyword;
	temp+="%'";
	sqlComm+=temp;

	temp=" OR provide_area LIKE '%";
	temp+=m_Keyword;
	temp+="%'";
	sqlComm+=temp;

	temp=" OR comp_telephone LIKE '%";
	temp+=m_Keyword;
	temp+="%'";
	sqlComm+=temp;

	temp=" OR prodt_resume LIKE '%";
	temp+=m_Keyword;
	temp+="%'";
	sqlComm+=temp;
	
	//==========================================
	try
	{
		g_pSet->Open(CRecordset::snapshot,sqlComm);
		g_isPLocked=true;
		::SendMessage(::AfxGetMainWnd()->m_hWnd,WM_SHOW_PRO_RESULT_SIMP,0,RESULT_SHOW);

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

BOOL CPdtSearch::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	m_btnSearch1.SetShade(CShadeButtonST::SHS_HSHADE,8,20,5,RGB(55,55,255));
	m_btnSearch2.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 + -