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

📄 hrview.cpp

📁 本程序实现了vc++访问DAO数据库的功能,对于操作数据库有很大的启发的.
💻 CPP
📖 第 1 页 / 共 2 页
字号:
	m_pSet->Open();
	}
	else
	InsertRecord();
	UpdateData(FALSE);
	// TODO: Add your control notification handler code here
	
}

BOOL CHrView::OnMove(UINT nIDMoveCommand) 
{
	// TODO: Add your specialized code here and/or call the base class
	if(m_bAdd)
	{
	m_bAdd=FALSE;
	UpdateData(TRUE);
	if(m_pSet->CanUpdate())
	{
	m_pSet->Update();
	}
	if(!m_pSet->IsEOF())
	{
	m_pSet->MoveLast();
	}
	m_pSet->Requery();
	UpdateData(FALSE);
	return TRUE;
	}
	else
	{
	switch(nIDMoveCommand)
	{
	case ID_RECORD_PREV:
		m_pSet->MovePrev();
		if(!m_pSet->IsBOF())
			break;
	case ID_RECORD_FIRST:
		m_pSet->MoveFirst();
		break;
	case ID_RECORD_NEXT:
		m_pSet->MoveNext();
		if(!m_pSet->IsEOF())
		break;
		if(!m_pSet->CanScroll())
		{
		m_pSet->SetFieldNull(NULL);
		break;
		}
	case ID_RECORD_LAST:
		m_pSet->MoveLast();
		break;
	default:
		ASSERT(FALSE);
	}
	UpdateData(FALSE);
	return TRUE;
	}

	//return CDaoRecordView::OnMove(nIDMoveCommand);
}

void CHrView::OnUpdateRecordNext(CCmdUI* pCmdUI) 
{
	pCmdUI->Enable(!m_pSet->IsBOF());
	// TODO: Add your command update UI handler code here
	
}

void CHrView::OnUpdateRecordPrev(CCmdUI* pCmdUI) 
{
		pCmdUI->Enable(!m_pSet->IsEOF());
	// TODO: Add your command update UI handler code here
	
}

void CHrView::OnAddButton() 
{
	m_pSet->AddNew();
	CEdit*pCtrl=(CEdit*)GetDlgItem(IDC_NAME_EDIT);
	pCtrl->SetReadOnly(FALSE);
	pCtrl=(CEdit*)GetDlgItem(IDC_DUTY_EDIT);
	pCtrl->SetReadOnly(FALSE);
	pCtrl=(CEdit*)GetDlgItem(IDC_DATA_EDIT);
	pCtrl->SetReadOnly(FALSE);
	pCtrl=(CEdit*)GetDlgItem(IDC_WORKERNO_EDIT);
	pCtrl->SetReadOnly(FALSE);
	pCtrl=(CEdit*)GetDlgItem(IDC_OTHER_EDIT);
	pCtrl->SetReadOnly(FALSE);
	CButton*pButton=(CButton*)GetDlgItem(IDC_SAVE_BUTTON);
	pButton->EnableWindow(TRUE);
	pButton=(CButton*)GetDlgItem(IDC_DELETE_BUTTON);
	pButton->EnableWindow(FALSE);
	pButton=(CButton*)GetDlgItem(IDC_MODIFY_BUTTON);
	pButton->EnableWindow(FALSE);
	pButton=(CButton*)GetDlgItem(IDC_ADD_BUTTON);
	pButton->EnableWindow(FALSE);
    m_bAdd=TRUE;
    UpdateData(FALSE);
	// TODO: Add your control notification handler code here
	
}


void CHrView::OnModifyButton() 
{
	CEdit*pCtrl=(CEdit*)GetDlgItem(IDC_NAME_EDIT);
	pCtrl->SetReadOnly(FALSE);
	pCtrl=(CEdit*)GetDlgItem(IDC_DUTY_EDIT);
	pCtrl->SetReadOnly(FALSE);
	pCtrl=(CEdit*)GetDlgItem(IDC_DATA_EDIT);
	pCtrl->SetReadOnly(FALSE);
	pCtrl=(CEdit*)GetDlgItem(IDC_WORKERNO_EDIT);
	pCtrl->SetReadOnly(FALSE);
	pCtrl=(CEdit*)GetDlgItem(IDC_OTHER_EDIT);
	pCtrl->SetReadOnly(FALSE);
	CButton*pButton=(CButton*)GetDlgItem(IDC_SAVE_BUTTON);
	pButton->EnableWindow(TRUE);
	pButton=(CButton*)GetDlgItem(IDC_DELETE_BUTTON);
	pButton->EnableWindow(FALSE);
	pButton=(CButton*)GetDlgItem(IDC_MODIFY_BUTTON);
	pButton->EnableWindow(FALSE);
	pButton=(CButton*)GetDlgItem(IDC_ADD_BUTTON);
	pButton->EnableWindow(FALSE);
	if(m_pSet->m_ID=="")
	{
	m_pSet->AddNew();
	m_bAdd=TRUE;
	UpdateData(FALSE);
	}
	else
	{
    m_bModify=TRUE;
	}
	// TODO: Add your control notification handler code here
	
}

void CHrView::OnFindButton() 
{
	// TODO: Add your control notification handler code here
	CFindDlg fdlg;
	if(fdlg.DoModal()==IDOK)
	{
		CString str="";
		CString and="and";
	if(fdlg.m_bDepartment)
	{
		CString col="department";
		str=col+"='"+fdlg.m_strDepartment+"'";
		m_strFresh=str;
		m_bFresh=TRUE;
	}
    if(fdlg.m_bDate)
	{
		if(str=="")
		{
		CString col="indata";    
		str=col+"='"+fdlg.m_strName+"'";
		m_strFresh=str;
		m_bFresh=TRUE;
		}
		else
		{
		CString col="indata";    
		str=str+and+" "+col+"='"+fdlg.m_strName+"'";
		m_strFresh=str;
		m_bFresh=TRUE;
		}
	}
	if(fdlg.m_bDuty)
	{
		if(str=="")
		{
		CString col="duty";    
		str=col+"='"+fdlg.m_strDuty+"'";
		m_strFresh=str;
		m_bFresh=TRUE;
		}
		else
		{
		CString col="duty";    
		str=str+and+" "+col+"='"+fdlg.m_strDuty+"'";
		m_strFresh=str;
		m_bFresh=TRUE;
		}
	}
		if(fdlg.m_bName)
	{
		if(str=="")
		{
		CString col="name";    
		str=col+"='"+fdlg.m_strName+"'";
		m_strFresh=str;
		m_bFresh=TRUE;
		}
		else
		{
		CString col="name";    
		str=str+and+" "+col+"='"+fdlg.m_strName+"'";
		m_strFresh=str;
		m_bFresh=TRUE;
		}
	}
	m_pSet->Close();
	m_pSet->m_strFilter=str;
	m_pSet->Open();
	int recCount=m_pSet->GetRecordCount();
	if(recCount==0)
	{
	MessageBox("No Record!");
	m_pSet->Close();
	m_pSet->m_strFilter="";
	m_pSet->Open();

	}
	else
	InsertRecord();

	UpdateData(FALSE);
	}
}

void CHrView::InsertRecord()
{
int recCount=m_pSet->GetRecordCount();
CListCtrl*pListCtrl=(CListCtrl*)GetDlgItem(IDC_HR_LIST);
pListCtrl->DeleteAllItems();
m_iRecCount=0;
pListCtrl->SendMessage(LVM_SETITEMCOUNT,(WPARAM)recCount,(LPARAM)LVSICF_NOINVALIDATEALL);
for(int i=0;i<1000;i++)
{
pListCtrl->SetTextColor(RGB(255,0,0));
pListCtrl->InsertItem(i,m_pSet->m_company);
pListCtrl->SetItemText(i,1,m_pSet->m_department);
pListCtrl->SetItemText(i,2,m_pSet->m_name);
pListCtrl->SetItemText(i,3,m_pSet->m_duty);
pListCtrl->SetItemText(i,4,m_pSet->m_indata);
pListCtrl->SetItemText(i,5,m_pSet->m_ID);
pListCtrl->SetItemText(i,6,m_pSet->m_detail);
m_iRecCount++;
if(!m_pSet->IsEOF())
m_pSet->MoveNext();

else
{
m_pSet->MoveFirst();
return;
}
}
}

void CHrView::OnPrint(CDC* pDC, CPrintInfo* pInfo) 
{
	// TODO: Add your specialized code here and/or call the base class
	pDC->SetMapMode(MM_TWIPS);
	CFont font;
	font.CreateFont(-280,0,0,0,400,FALSE,FALSE,0,
		ANSI_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,
		DEFAULT_PITCH|FF_MODERN,"Arial");
	CFont*pOldFont=(CFont*)(pDC->SelectObject(&font));
	PrintHrHeader(pDC,pInfo);
	
	CPoint point(720,-1440);
	for(int i=0;i<m_iRecCount;i++)
	{
	CString str("");
	str=m_pSet->m_company;
	int y=-1000-i*400;
	pDC->TextOut(300,y,str);
	str=m_pSet->m_department;
	pDC->TextOut(1400,y,str);
	str=m_pSet->m_name;
	pDC->TextOut(2300,y,str);
	str=m_pSet->m_duty;
	pDC->TextOut(3600,y,str);
	str=m_pSet->m_indata;
	pDC->TextOut(5400,y,str);
	str=m_pSet->m_ID;
	pDC->TextOut(7400,y,str);
	str=m_pSet->m_detail;
	pDC->TextOut(9000,y,str);
	if(!m_pSet->IsEOF())
	{
	m_pSet->MoveNext();
	}
	else
	{
	m_pSet->MoveFirst();	
	}
	}	
	CDaoRecordView::OnPrint(pDC, pInfo);
}

void CHrView::PrintHrHeader(CDC* pDC, CPrintInfo* pInfo)
{

CString str("");
CPoint point(3800,0);
pDC->TextOut(point.x,point.y,"The Report of "+m_pSet->m_department);
TEXTMETRIC textMetric;
pDC->GetTextMetrics(&textMetric);
int y=-350-2*textMetric.tmHeight;
int x=-300-textMetric.tmHeight;
pDC->MoveTo(0,y);
pDC->LineTo(14400,y);
str=CString("公司");
pDC->TextOut(300,x,str);
str=CString("部门");
pDC->TextOut(1300,x,str);
str=CString("姓名");
pDC->TextOut(2300,x,str);
str=CString("职  位");
pDC->TextOut(3700,x,str);
str=CString("入厂日期");
pDC->TextOut(5400,x,str);
str=CString("工  号");
pDC->TextOut(7400,x,str);
str=CString("备注");
pDC->TextOut(9000,x,str);
}

void CHrView::OnPrepareDC(CDC* pDC, CPrintInfo* pInfo) 
{
	// TODO: Add your specialized code here and/or call the base class
	//pDC->SetMapMode(MM_LOENGLISH);
	CDaoRecordView::OnPrepareDC(pDC, pInfo);
}

void CHrView::OnDraw(CDC* pDC) 
{
	// TODO: Add your specialized code here and/or call the base class

	
}

⌨️ 快捷键说明

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