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

📄 dbasequery.cpp

📁 一个有关人事系统的所有代码和有关文件包括里面小量数据库。
💻 CPP
字号:
// DBaseQuery.cpp : implementation file
//

#include "stdafx.h"
#include "Rsglxt.h"
#include "DBaseQuery.h"

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

/////////////////////////////////////////////////////////////////////////////
// CDBaseQuery dialog
extern CRsglxtApp theApp;
extern CString Lever;

CDBaseQuery::CDBaseQuery(CWnd* pParent /*=NULL*/)
	: CDialog(CDBaseQuery::IDD, pParent)
{
	//{{AFX_DATA_INIT(CDBaseQuery)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}


void CDBaseQuery::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDBaseQuery)
	DDX_Control(pDX, IDC_Group1, m_Group1);
	DDX_Control(pDX, IDC_Group, m_Group);
	DDX_Control(pDX, IDC_BUT_QUERY, m_ButQuery);
	DDX_Control(pDX, IDC_BUT_Print, m_ButPrint);
	DDX_Control(pDX, IDC_BASEQUERY_GRID, m_Grid);
	DDX_Control(pDX, IDC_BASEQUERY_EDTCONDITION, m_EdtCondition);
	DDX_Control(pDX, IDC_BASEQUERY_COMFIELD, m_ComField);
	DDX_Control(pDX, IDC_BASEQUERY_COMEMBLEM, m_ComEmblem);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CDBaseQuery, CDialog)
	//{{AFX_MSG_MAP(CDBaseQuery)
	ON_BN_CLICKED(IDC_BUT_QUERY, OnButQuery)
	ON_BN_CLICKED(IDC_BUT_Print, OnBUTPrint)
	ON_NOTIFY(NM_DBLCLK, IDC_BASEQUERY_GRID, OnDblclkBasequeryGrid)
	ON_WM_CTLCOLOR()
	ON_WM_PAINT()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDBaseQuery message handlers
 bool CDBaseQuery::Show(CString sCaption, CString sDateBaseName, CDialog *NextWnd,PrintStruct pr)
 {
 	m_Caption=sCaption;//窗口名
 	m_DateBaseName=sDateBaseName;//数据库名
 	m_pWnd=NextWnd;//窗口
 	m_ps =pr;
	//m_Grid.SetDateBase(sDateBaseName);
 	return true;
 }

void CDBaseQuery::OnButQuery() 
{
	// TODO: Add your control notification handler code here
	CString sSQL,sField,sEmblem,sCondition;
	this->m_ComField.GetWindowText(sField);
	this->m_ComEmblem.GetWindowText(sEmblem);
	this->m_EdtCondition.GetWindowText(sCondition);
	//判断查询字段的类型  
	if(m_ComField.m_CurrentFieldType=="数值型")
		sSQL.Format("SELECT * FROM %s WHERE %s %s %s",this->m_DateBaseName,sField,sEmblem,sCondition);	
	else
		if(m_ComField.m_CurrentFieldType=="字符型")
		{
			if(sEmblem!="LIKE")
				sSQL.Format("SELECT * FROM %s WHERE %s %s '%s'",this->m_DateBaseName,sField,sEmblem,sCondition);	
			else
				sSQL.Format("SELECT * FROM %s WHERE %s %s '%%%s%%'",this->m_DateBaseName,sField,sEmblem,sCondition);	
		}
		else//日期
		{
			if(sEmblem!="LIKE")
				sSQL.Format("SELECT * FROM %s WHERE %s %s '%s'",this->m_DateBaseName,sField,sEmblem,sCondition);
			else
				sSQL.Format("SELECT * FROM %s WHERE %s %s '%%%s%%'",this->m_DateBaseName,sField,sEmblem,sCondition);	
		
		}
		if(m_ComField.m_CurrentFieldType=="备注型")
			sSQL.Format("SELECT * FROM %s WHERE %s LIKE '%%%s%%'",this->m_DateBaseName,sField,sCondition);	

	rst.Open(sSQL,adCmdText);
	m_Grid.AddCellValue(rst);
}

void CDBaseQuery::OnBUTPrint() 
{
	// TODO: Add your control notification handler code here
	CString sCount;
	sCount.Format("%d",rst.GetRecordCount());
	m_ps.TotalNumber=1;
	m_ps.Totals[0]="共计 "+sCount+" 条记录";
	m_ps.Totals[1]="";
	m_ps.Grid=&m_Grid;
	theApp.Print();	
}

BOOL CDBaseQuery::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	this->SetWindowText(m_Caption);
	rst.Open(m_DateBaseName);
	this->m_ComField.SetFieldset(rst);
	m_Grid.ReadOnly(true);
	this->m_ComEmblem.SetCurSel(0);
	this->m_ComField.SetCurSel(0);
	this->m_ButPrint.EnableWindow(CanPrint);
	m_Grid.SetDataBase(m_DateBaseName,adCmdTable);
	this->m_ComField.m_CurrentFieldType="字符型";

	m_ButQuery.LoadPic(IDB_BIT_Query,IDB_BIT_Query,IDB_BIT_Query);
	m_ButPrint.LoadPic(IDB_BIT_Print,IDB_BIT_Print,IDB_BIT_Print);

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

void CDBaseQuery::OnDblclkBasequeryGrid(NMHDR* pNMHDR, LRESULT* pResult) 
{
	// TODO: Add your control notification handler code here
	CString s="超级管理员";
	if(Lever!=s)//进行权限匹配
	{
		MessageBox("你无权进行编辑,请与系统管理员联系!","系统提示",MB_OK|MB_ICONSTOP);
		return;
	}
	if(m_Grid.GetItemCount()>0)	
	{
		if(m_Grid.GetHotItem()!=-1)
		{
			m_CurrentRow=m_Grid.GetHotItem();		
			m_pWnd->DoModal();
			this->m_ComField.SetCurSel(0);
			this->m_ComEmblem.SetCurSel(0);
			this->m_EdtCondition.SetWindowText("");
			this->OnButQuery();
		}
	}
	else
	{
			m_pWnd->DoModal();
			this->m_ComField.SetCurSel(0);
			this->m_ComEmblem.SetCurSel(0);
			this->m_EdtCondition.SetWindowText("");
			this->OnButQuery();

	}
	*pResult = 0;
}

HBRUSH CDBaseQuery::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
{
	HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
	
	// TODO: Change any attributes of the DC here
	if(nCtlColor==CTLCOLOR_STATIC)
	{
		pDC->SetBkColor(RGB(255,255,255));
		pDC->SetTextColor(RGB(0,0,0));

	}
	// TODO: Return a different brush if the default is not desired
	return hbr;
}

void CDBaseQuery::OnPaint() 
{
	CPaintDC dc(this); // device context for painting
	
	// TODO: Add your message handler code here
	    CRect rect;
		CBitmap bit;
		CDC memDC;
		this->GetClientRect(&rect);
		bit.LoadBitmap(IDB_BIT_BJ);
		memDC.CreateCompatibleDC(&dc);
		memDC.SelectObject(&bit);
		dc.BitBlt(0,0,rect.Width(),rect.Height(),&memDC,0,0,SRCCOPY);
		memDC.DeleteDC();
		::DeleteObject(&bit);	
		CDialog::OnPaint();
	// Do not call CDialog::OnPaint() for painting messages
}

⌨️ 快捷键说明

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