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

📄 finddialog.cpp

📁 用C++语言编写得职工信息管理系统
💻 CPP
字号:
// FindDialog.cpp : implementation file
//

#include "stdafx.h"
#include "Worker.h"
#include "FindDialog.h"

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

/////////////////////////////////////////////////////////////////////////////
// CFindDialog dialog


CFindDialog::CFindDialog(CWnd* pParent /*=NULL*/)
	: CDialog(CFindDialog::IDD, pParent)
{
	//{{AFX_DATA_INIT(CFindDialog)
	m_ZhiCheng = _T("");
	m_bMarrige = FALSE;
	m_nMonth = 0;
	m_nYear = 1970;
	//}}AFX_DATA_INIT
}


void CFindDialog::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CFindDialog)
	DDX_Control(pDX, IDC_SHOWALLBTN, m_ShowAllBtn);
	DDX_Control(pDX, IDC_FINDBTN, m_FindBtn);
	DDX_Control(pDX, IDC_LIST1, m_ShowCtrl);
	DDX_CBString(pDX, IDC_COMBO1, m_ZhiCheng);
	DDX_Check(pDX, IDC_CHECKMARRIGE, m_bMarrige);
	DDX_CBIndex(pDX, IDC_COMBO2, m_nMonth);
	DDX_Text(pDX, IDC_EDIT1, m_nYear);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CFindDialog, CDialog)
	//{{AFX_MSG_MAP(CFindDialog)
	ON_BN_CLICKED(IDC_ZHICHENGRADIO, OnZhichengradio)
	ON_BN_CLICKED(IDC_MARRIGERADIO, OnMarrigeradio)
	ON_BN_CLICKED(IDC_AFTERBTDRADIO, OnAfterbtdradio)
	ON_BN_CLICKED(IDC_BEFORBTDRADIO, OnBeforbtdradio)
	ON_BN_CLICKED(IDC_FINDBTN, OnFindBtn)
	ON_BN_CLICKED(IDC_SHOWALLBTN, OnShowAll)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CFindDialog message handlers

BOOL CFindDialog::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	m_ShowCtrl.Init();
	Hide();
	m_bMarrige=FALSE;
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CFindDialog::OnZhichengradio() 
{
	// TODO: Add your control notification handler code here
	Hide();
	GetDlgItem(IDC_FINDSTATIC)->ShowWindow(SW_SHOW);
	GetDlgItem(IDC_COMBO1)->ShowWindow(SW_SHOW);
	GetDlgItem(IDC_COMBO1)->SetFocus();
	GetDlgItem(IDC_FINDSTATIC)->SetWindowText("  职称");
	m_FindBtn.EnableWindow(TRUE);
}

void CFindDialog::OnMarrigeradio() 
{
	// TODO: Add your control notification handler code here
	Hide();
	GetDlgItem(IDC_FINDSTATIC)->ShowWindow(SW_SHOW);
	GetDlgItem(IDC_CHECKMARRIGE)->ShowWindow(SW_SHOW);
	GetDlgItem(IDC_CHECKMARRIGE)->SetFocus();
	GetDlgItem(IDC_FINDSTATIC)->SetWindowText("  婚否");
	m_FindBtn.EnableWindow(TRUE);
}

void CFindDialog::OnAfterbtdradio() 
{
	// TODO: Add your control notification handler code here
	Hide();
	GetDlgItem(IDC_FINDSTATIC)->ShowWindow(SW_SHOW);
	GetDlgItem(IDC_COMBO2)->ShowWindow(SW_SHOW);
	GetDlgItem(IDC_EDIT1)->ShowWindow(SW_SHOW);
	GetDlgItem(IDC_YEARSTATIC)->ShowWindow(SW_SHOW);
	GetDlgItem(IDC_MONTHSTATIC)->ShowWindow(SW_SHOW);
	((CEdit*)GetDlgItem(IDC_EDIT1))->SetWindowText("1970");
	((CEdit*)GetDlgItem(IDC_EDIT1))->SetSel(0,4);
	GetDlgItem(IDC_EDIT1)->SetFocus();
	GetDlgItem(IDC_FINDSTATIC)->SetWindowText("某年月以后出生");
	m_FindBtn.EnableWindow(TRUE);
}

void CFindDialog::OnBeforbtdradio() 
{
	// TODO: Add your control notification handler code here
	Hide();
	GetDlgItem(IDC_FINDSTATIC)->ShowWindow(SW_SHOW);
	GetDlgItem(IDC_COMBO2)->ShowWindow(SW_SHOW);
	GetDlgItem(IDC_EDIT1)->ShowWindow(SW_SHOW);
	GetDlgItem(IDC_YEARSTATIC)->ShowWindow(SW_SHOW);
	GetDlgItem(IDC_MONTHSTATIC)->ShowWindow(SW_SHOW);
	((CEdit*)GetDlgItem(IDC_EDIT1))->SetWindowText("1970");
	((CEdit*)GetDlgItem(IDC_EDIT1))->SetSel(0,4);
	GetDlgItem(IDC_EDIT1)->SetFocus();
	GetDlgItem(IDC_FINDSTATIC)->SetWindowText("某年月以前出生");
	m_FindBtn.EnableWindow(TRUE);
}

void CFindDialog::Hide()
{
	GetDlgItem(IDC_COMBO1)->ShowWindow(SW_HIDE);
	GetDlgItem(IDC_CHECKMARRIGE)->ShowWindow(SW_HIDE);
	GetDlgItem(IDC_FINDSTATIC)->ShowWindow(SW_HIDE);
	GetDlgItem(IDC_COMBO2)->ShowWindow(SW_HIDE);
	GetDlgItem(IDC_EDIT1)->ShowWindow(SW_HIDE);
	GetDlgItem(IDC_YEARSTATIC)->ShowWindow(SW_HIDE);
	GetDlgItem(IDC_MONTHSTATIC)->ShowWindow(SW_HIDE);
	m_FindBtn.EnableWindow(FALSE);
}


void CFindDialog::OnFindBtn() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	if(IsDlgButtonChecked(IDC_ZHICHENGRADIO))
		FindZhiCheng();
	else if(IsDlgButtonChecked(IDC_BEFORBTDRADIO))
		FindBfBth();
	else if(IsDlgButtonChecked(IDC_AFTERBTDRADIO))
		FindAfBth();
	else if(IsDlgButtonChecked(IDC_MARRIGERADIO))
		FindMarrige();
}

void CFindDialog::FindZhiCheng()
{
//查找符合职称要求的职工	
	CMyDataBase database;
	CPerson* person;
	bool finded=false;
	if(!database.Open())
	{
		MessageBox("数据库无法打开!","错误",MB_ICONHAND|MB_ICONSTOP|MB_ICONERROR);
		return;
	}
	m_ShowCtrl.DelAllPerson();
	while((person=database.GetPerson())!=NULL)
	{
		if(person->GetZhiCheng()==m_ZhiCheng)
		{
			m_ShowCtrl.AddPerson(person);
			delete person;
			finded=true;
		}
		else	
			delete person;
	}
	database.Close();
	if(!finded)
		MessageBox("没找到符合该条件的记录。","提示",MB_ICONASTERISK | MB_ICONINFORMATION);
	CString str;
	str.Format("共%d条记录。",m_ShowCtrl.GetItemCount()); 
	GetDlgItem(IDC_TOTALSTATIC)->SetWindowText(str);

}

void CFindDialog::FindBfBth()
{
//查找符合某年前出生要求的职工
	CMyDataBase database;
	CPerson* person;
	bool finded=false;
	if(!database.Open())
	{
		MessageBox("数据库无法打开!","错误",MB_ICONHAND|MB_ICONSTOP|MB_ICONERROR);
		return;
	}
	m_ShowCtrl.DelAllPerson();
	while((person=database.GetPerson())!=NULL)
	{
		if(person->GetBtdYear()<m_nYear||
			(person->GetBtdYear()==m_nYear&&person->GetBtdMonth()<=UINT(m_nMonth+1)))
		{
			m_ShowCtrl.AddPerson(person);
			delete person;
			finded=true;
		}
		else	
			delete person;
	}
	database.Close();
	if(!finded)
		MessageBox("没找到符合该条件的记录。","提示",MB_ICONASTERISK | MB_ICONINFORMATION);
	CString str;
	str.Format("共%d条记录。",m_ShowCtrl.GetItemCount()); 
	GetDlgItem(IDC_TOTALSTATIC)->SetWindowText(str);
}

void CFindDialog::FindAfBth()
{
//查找符合某年后出生要求的职工
	CMyDataBase database;
	CPerson* person;
	bool finded=false;
	if(!database.Open())
	{
		MessageBox("数据库无法打开!","错误",MB_ICONHAND|MB_ICONSTOP|MB_ICONERROR);
		return;
	}
	m_ShowCtrl.DelAllPerson();
	while((person=database.GetPerson())!=NULL)
	{
		if(person->GetBtdYear()>m_nYear||
			(person->GetBtdYear()==m_nYear&&person->GetBtdMonth()>=UINT(m_nMonth+1)))
		{
			m_ShowCtrl.AddPerson(person);
			delete person;
			finded=true;
		}
		else	
			delete person;
	}
	database.Close();
	if(!finded)
		MessageBox("没找到符合该条件的记录。","提示",MB_ICONASTERISK | MB_ICONINFORMATION);
	CString str;
	str.Format("共%d条记录。",m_ShowCtrl.GetItemCount()); 
	GetDlgItem(IDC_TOTALSTATIC)->SetWindowText(str);
}

void CFindDialog::FindMarrige()
{
//查找是否结婚的职工
	CMyDataBase database;
	CPerson* person;
	bool finded=false;
	if(!database.Open())
	{
		MessageBox("数据库无法打开!","错误",MB_ICONHAND|MB_ICONSTOP|MB_ICONERROR);
		return;
	}
	m_ShowCtrl.DelAllPerson();
	while((person=database.GetPerson())!=NULL)
	{
		if((BOOL)(person->IsMarried())==m_bMarrige)
		{
			m_ShowCtrl.AddPerson(person);
			delete person;
			finded=true;
		}
		else	
			delete person;
	}
	database.Close();
	if(!finded)
		MessageBox("没找到符合该条件的记录。","提示",MB_ICONASTERISK | MB_ICONINFORMATION);
	CString str;
	str.Format("共%d条记录。",m_ShowCtrl.GetItemCount()); 
	GetDlgItem(IDC_TOTALSTATIC)->SetWindowText(str);
}


void CFindDialog::OnShowAll() 
{
	// TODO: Add your control notification handler code here
//显示全部职工信息
	int n=0;
	CPerson *person;
	CMyDataBase database;
	if(!database.Open())
	{
		if(MessageBox("数据库无法打开!\n\n是否现在新建?","询问",MB_ICONQUESTION|MB_YESNO)==IDYES)
		{
			database.Build();
		}
		return;
	}
	m_ShowCtrl.DelAllPerson();

	while((person=database.GetPerson())!=NULL)
	{
		m_ShowCtrl.AddPerson(person);
		delete person;
	}

	database.Close();
	CString str;
	str.Format("共%d条记录。",m_ShowCtrl.GetItemCount());
	GetDlgItem(IDC_TOTALSTATIC)->SetWindowText(str);	
}

⌨️ 快捷键说明

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