📄 searchachievement.cpp
字号:
// SearchAchievement.cpp : implementation file
//
#include "stdafx.h"
#include "Office.h"
#include "SearchAchievement.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CSearchAchievement dialog
CSearchAchievement::CSearchAchievement(CWnd* pParent /*=NULL*/)
: CDialog(CSearchAchievement::IDD, pParent)
{
//{{AFX_DATA_INIT(CSearchAchievement)
m_beginDate = COleDateTime::GetCurrentTime();
m_endDate = COleDateTime::GetCurrentTime();
m_name = _T("");
m_department = _T("");
m_project = _T("");
//}}AFX_DATA_INIT
}
void CSearchAchievement::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CSearchAchievement)
DDX_Control(pDX, IDC_LIST, m_list);
DDX_Control(pDX, IDC_PROJECT, m_projectCombo);
DDX_Control(pDX, IDC_DEPARTMENT, m_departmentCombo);
DDX_Control(pDX, IDC_NAME, m_nameCombo);
DDX_DateTimeCtrl(pDX, IDC_BEGINDATE, m_beginDate);
DDX_DateTimeCtrl(pDX, IDC_ENDDATE, m_endDate);
DDX_CBString(pDX, IDC_NAME, m_name);
DDX_CBString(pDX, IDC_DEPARTMENT, m_department);
DDX_CBString(pDX, IDC_PROJECT, m_project);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CSearchAchievement, CDialog)
//{{AFX_MSG_MAP(CSearchAchievement)
ON_BN_CLICKED(IDC_SEARCH, OnSearch)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSearchAchievement message handlers
void CSearchAchievement::OnSearch()
{
UpdateData(true);
CString strSQL;
_RecordsetPtr m_pRecordset;
HRESULT hTRes;
hTRes = m_pRecordset.CreateInstance(_T("ADODB.Recordset"));
strSQL="select * from achievementRecord";
CString str;
str.Format("%d-%d-%d",m_beginDate.GetYear(),m_beginDate.GetMonth(),m_beginDate.GetDay());
strSQL+=" where achievementDate>'"+str+"' ";
str.Format("%d-%d-%d",m_endDate.GetYear(),m_endDate.GetMonth(),m_endDate.GetDay());
strSQL+=" and achievementDate<'"+str+"' ";
if(m_name!="")
{
strSQL+=" and name='"+m_name+"' ";
}
if(m_department!="")
{
strSQL+=" and department='"+m_department+"' ";
}
if(m_project!="")
{
strSQL+=" and project='"+m_project+"' ";
}
// AfxMessageBox(strSQL);
hTRes = m_pRecordset->Open((LPTSTR)strSQL.GetBuffer(130),
((COfficeApp*)AfxGetApp())->m_pConn.GetInterfacePtr(),
adOpenDynamic,adLockPessimistic,adCmdText);
int i=0;
m_list.DeleteAllItems();
while(!(m_pRecordset->adoEOF))
{
m_list.InsertItem(i,((COfficeApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("name")));
COleDateTime eventDate= m_pRecordset->GetCollect("achievementDate");
str.Format("%d-%d-%d",eventDate.GetYear(),eventDate.GetMonth(),eventDate.GetDay());
m_list.SetItemText(i,1,str);
m_list.SetItemText(i,2, ((COfficeApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("id")));
m_list.SetItemText(i,3, ((COfficeApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("department")));
m_list.SetItemText(i,4, ((COfficeApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("project")));
m_list.SetItemText(i,5, ((COfficeApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("achievement")));
m_list.SetItemText(i,6, ((COfficeApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("remark")));
m_pRecordset->MoveNext();
i++;
}
m_pRecordset->Close();
}
BOOL CSearchAchievement::OnInitDialog()
{
CDialog::OnInitDialog();
DWORD style;
style=m_list.GetExStyle();
style=(style|LVS_EX_GRIDLINES|LVS_EX_FULLROWSELECT)&(~LVS_EX_CHECKBOXES) ;
m_list.SetExtendedStyle(style);
m_list.InsertColumn(0,"姓名",LVCFMT_LEFT,100);
m_list.InsertColumn(1,"发生日期",LVCFMT_LEFT,100);
m_list.InsertColumn(2,"人员编号",LVCFMT_LEFT,100);
m_list.InsertColumn(3,"所属部门",LVCFMT_LEFT,100);
m_list.InsertColumn(4,"项目",LVCFMT_LEFT,100);
m_list.InsertColumn(5,"业绩",LVCFMT_LEFT,100);
m_list.InsertColumn(6,"备注",LVCFMT_LEFT,100);
CString strSQL;
_RecordsetPtr m_pRecordset;
HRESULT hTRes;
hTRes = m_pRecordset.CreateInstance(_T("ADODB.Recordset"));
strSQL="select distinct name from achievementRecord";
hTRes = m_pRecordset->Open((LPTSTR)strSQL.GetBuffer(130),
((COfficeApp*)AfxGetApp())->m_pConn.GetInterfacePtr(),
adOpenDynamic,adLockPessimistic,adCmdText);
int i=0;
while(!(m_pRecordset->adoEOF))
{
m_nameCombo.InsertString(i,((COfficeApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("name")));
m_pRecordset->MoveNext();
i++;
}
m_pRecordset->Close();
strSQL="select distinct department from achievementRecord";
hTRes = m_pRecordset->Open((LPTSTR)strSQL.GetBuffer(130),
((COfficeApp*)AfxGetApp())->m_pConn.GetInterfacePtr(),
adOpenDynamic,adLockPessimistic,adCmdText);
i=0;
while(!(m_pRecordset->adoEOF))
{
m_departmentCombo.InsertString(i,((COfficeApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("department")));
m_pRecordset->MoveNext();
i++;
}
m_pRecordset->Close();
strSQL="select distinct project from achievementRecord";
hTRes = m_pRecordset->Open((LPTSTR)strSQL.GetBuffer(130),
((COfficeApp*)AfxGetApp())->m_pConn.GetInterfacePtr(),
adOpenDynamic,adLockPessimistic,adCmdText);
i=0;
while(!(m_pRecordset->adoEOF))
{
m_projectCombo.InsertString(i,((COfficeApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("project")));
m_pRecordset->MoveNext();
i++;
}
m_pRecordset->Close();
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 + -