📄 gs_daoview.cpp
字号:
// GS_DAOView.cpp : implementation of the CGS_DAOView class
//
#include "stdafx.h"
#include "GS_DAO.h"
#include "FindDialog.h"
#include "GS_DAOSet.h"
#include "GS_DAODoc.h"
#include "GS_DAOView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CGS_DAOView
IMPLEMENT_DYNCREATE(CGS_DAOView, CDaoRecordView)
BEGIN_MESSAGE_MAP(CGS_DAOView, CDaoRecordView)
//{{AFX_MSG_MAP(CGS_DAOView)
ON_BN_CLICKED(IDC_ALL, OnAll)
ON_BN_CLICKED(IDC_FIND, OnFind)
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CDaoRecordView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CDaoRecordView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CDaoRecordView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CGS_DAOView construction/destruction
CGS_DAOView::CGS_DAOView()
: CDaoRecordView(CGS_DAOView::IDD)
{
//{{AFX_DATA_INIT(CGS_DAOView)
m_pSet = NULL;
//}}AFX_DATA_INIT
// TODO: add construction code here
}
CGS_DAOView::~CGS_DAOView()
{
}
void CGS_DAOView::DoDataExchange(CDataExchange* pDX)
{
CDaoRecordView::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CGS_DAOView)
DDX_Control(pDX, IDC_HR_LIST, m_list);
DDX_FieldCBString(pDX, IDC_COMPANY_COMBO, m_pSet->m_company, m_pSet);
DDX_FieldText(pDX, IDC_DATA_EDIT, m_pSet->m_indata, m_pSet);
DDX_FieldCBString(pDX, IDC_DEPARTMENT_COMBO, m_pSet->m_department, m_pSet);
DDX_FieldText(pDX, IDC_DUTY_EDIT, m_pSet->m_duty, m_pSet);
DDX_FieldText(pDX, IDC_NAME_EDIT, m_pSet->m_name, m_pSet);
DDX_FieldText(pDX, IDC_OTHER_EDIT, m_pSet->m_detail, m_pSet);
DDX_FieldText(pDX, IDC_WORKERNO_EDIT, m_pSet->m_ID, m_pSet);
//}}AFX_DATA_MAP
}
BOOL CGS_DAOView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CDaoRecordView::PreCreateWindow(cs);
}
void CGS_DAOView::OnInitialUpdate()
{
m_pSet = &GetDocument()->m_gS_DAOSet;
CDaoRecordView::OnInitialUpdate();
GetParentFrame()->RecalcLayout();
ResizeParentToFit();
//CListCtrl*pListCtrl=(CListCtrl*)GetDlgItem(IDC_HR_LIST);
CDC*pDC=GetDC();
TEXTMETRIC tm;
pDC->GetTextMetrics(&tm);
m_list.InsertColumn(0,"公司",0,10*tm.tmAveCharWidth,0);
m_list.InsertColumn(1,"部门",0,10*tm.tmAveCharWidth,1);
m_list.InsertColumn(2,"姓名",0,15*tm.tmAveCharWidth,2);
m_list.InsertColumn(3,"职位",0,15*tm.tmAveCharWidth,3);
m_list.InsertColumn(4,"入厂日期",0,15*tm.tmAveCharWidth,4);
m_list.InsertColumn(5,"工号",0,15*tm.tmAveCharWidth,5);
m_list.InsertColumn(6,"备注",0,50*tm.tmAveCharWidth,6);
}
/////////////////////////////////////////////////////////////////////////////
// CGS_DAOView printing
BOOL CGS_DAOView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CGS_DAOView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CGS_DAOView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CGS_DAOView diagnostics
#ifdef _DEBUG
void CGS_DAOView::AssertValid() const
{
CDaoRecordView::AssertValid();
}
void CGS_DAOView::Dump(CDumpContext& dc) const
{
CDaoRecordView::Dump(dc);
}
CGS_DAODoc* CGS_DAOView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CGS_DAODoc)));
return (CGS_DAODoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CGS_DAOView database support
CDaoRecordset* CGS_DAOView::OnGetRecordset()
{
return m_pSet;
}
/////////////////////////////////////////////////////////////////////////////
// CGS_DAOView message handlers
void CGS_DAOView::InsertRecord()
{
m_list.DeleteAllItems();
int m_iRecCount=0;
for(int i=0;i<1000;i++)
{
m_list.SetTextColor(RGB(255,0,0));
m_list.InsertItem(i,m_pSet->m_company);
m_list.SetItemText(i,1,m_pSet->m_department);
m_list.SetItemText(i,2,m_pSet->m_name);
m_list.SetItemText(i,3,m_pSet->m_duty);
m_list.SetItemText(i,4,m_pSet->m_indata);
m_list.SetItemText(i,5,m_pSet->m_ID);
m_list.SetItemText(i,6,m_pSet->m_detail);
m_iRecCount++;
if(!m_pSet->IsEOF())
m_pSet->MoveNext();
else
{
m_pSet->MoveFirst();
return;
}
}
}
void CGS_DAOView::OnAll()
{
// TODO: Add your control notification handler code here
InsertRecord();
UpdateData(FALSE);
}
void CGS_DAOView::OnFind()
{
// TODO: Add your control notification handler code here
CFindDialog fdlg;
if(fdlg.DoModal()==IDOK)
{
CString str="";
CString and="and";
if(fdlg.m_bDept)
{
CString col="department";
str=col+"='"+fdlg.m_strDept+"'";
m_strFresh=str;
}
if(fdlg.m_bName)
{
if(str=="")
{
CString col="name";
str=col+"='"+fdlg.m_strName+"'";
m_strFresh=str;
}
else
{
CString col="name";
str=str+and+" "+col+"='"+fdlg.m_strName+"'";
m_strFresh=str;
}
}
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);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -