📄 searcheventrecord.cpp
字号:
// SearchEventRecord.cpp : implementation file
//
#include "stdafx.h"
#include "ClientRelationship.h"
#include "SearchEventRecord.h"
#include "EventRecordForm.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CSearchEventRecord dialog
CSearchEventRecord::CSearchEventRecord(CWnd* pParent /*=NULL*/)
: CDialog(CSearchEventRecord::IDD, pParent)
{
//{{AFX_DATA_INIT(CSearchEventRecord)
m_eventDateEnd = COleDateTime::GetCurrentTime();
m_eventCharacter = _T("");
m_recorder = _T("");
m_subject = _T("");
m_eventDateBegin = COleDateTime::GetCurrentTime();
//}}AFX_DATA_INIT
}
void CSearchEventRecord::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CSearchEventRecord)
DDX_Control(pDX, IDC_subject, m_subjectCombo);
DDX_Control(pDX, IDC_recorder, m_recorderCombo);
DDX_Control(pDX, IDC_eventCharacter, m_eventCharacterCombo);
DDX_Control(pDX, IDC_LIST1, m_list);
DDX_DateTimeCtrl(pDX, IDC_eventDateEnd, m_eventDateEnd);
DDX_CBString(pDX, IDC_eventCharacter, m_eventCharacter);
DDX_CBString(pDX, IDC_recorder, m_recorder);
DDX_CBString(pDX, IDC_subject, m_subject);
DDX_DateTimeCtrl(pDX, IDC_eventDateBegin, m_eventDateBegin);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CSearchEventRecord, CDialog)
//{{AFX_MSG_MAP(CSearchEventRecord)
ON_NOTIFY(NM_DBLCLK, IDC_LIST1, OnDblclkList1)
ON_BN_CLICKED(IDC_BUTTON1, OnSearch)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSearchEventRecord message handlers
void CSearchEventRecord::OnDblclkList1(NMHDR* pNMHDR, LRESULT* pResult)
{
CString str;
int flag=0;
POSITION pos = m_list.GetFirstSelectedItemPosition();
if(pos)
{
int nFirstSelItem = m_list.GetNextSelectedItem(pos);
str=m_list.GetItemText(nFirstSelItem,0);
}
CEventRecordForm dlg;
dlg.m_eventRecordID=str;
dlg.is_search=1;
dlg.DoModal();
*pResult = 0;
}
BOOL CSearchEventRecord::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);
CString strSQL;
_RecordsetPtr m_pRecordset;
HRESULT hTRes;
hTRes = m_pRecordset.CreateInstance(_T("ADODB.Recordset"));
strSQL="select distinct eventCharacter from eventRecord";
hTRes = m_pRecordset->Open((LPTSTR)strSQL.GetBuffer(130),
((CClientRelationshipApp*)AfxGetApp())->m_pConn.GetInterfacePtr(),
adOpenDynamic,adLockPessimistic,adCmdText);
int i=0;
while(!(m_pRecordset->adoEOF))
{
m_eventCharacterCombo.InsertString(i,((CClientRelationshipApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("eventCharacter")));
m_pRecordset->MoveNext();
i++;
}
m_pRecordset->Close();
strSQL="select distinct recorder from eventRecord";
hTRes = m_pRecordset->Open((LPTSTR)strSQL.GetBuffer(130),
((CClientRelationshipApp*)AfxGetApp())->m_pConn.GetInterfacePtr(),
adOpenDynamic,adLockPessimistic,adCmdText);
i=0;
while(!(m_pRecordset->adoEOF))
{
m_recorderCombo.InsertString(i,((CClientRelationshipApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("recorder")));
m_pRecordset->MoveNext();
i++;
}
m_pRecordset->Close();
strSQL="select distinct subject from eventRecord";
hTRes = m_pRecordset->Open((LPTSTR)strSQL.GetBuffer(130),
((CClientRelationshipApp*)AfxGetApp())->m_pConn.GetInterfacePtr(),
adOpenDynamic,adLockPessimistic,adCmdText);
i=0;
while(!(m_pRecordset->adoEOF))
{
m_subjectCombo.InsertString(i,((CClientRelationshipApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("subject")));
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
}
void CSearchEventRecord::OnSearch()
{
UpdateData(true);
CString strSQL;
_RecordsetPtr m_pRecordset;
HRESULT hTRes;
hTRes = m_pRecordset.CreateInstance(_T("ADODB.Recordset"));
strSQL="select * from eventRecord";
CString str;
str.Format("%d-%d-%d",m_eventDateBegin.GetYear(),m_eventDateBegin.GetMonth(),m_eventDateBegin.GetDay());
strSQL+=" where eventDate>'"+str+"' ";
str.Format("%d-%d-%d",m_eventDateEnd.GetYear(),m_eventDateEnd.GetMonth(),m_eventDateEnd.GetDay());
strSQL+=" and eventDate<'"+str+"' ";
if(m_eventCharacter!="")
{
strSQL+=" and eventCharacter='"+m_eventCharacter+"' ";
}
if(m_recorder!="")
{
strSQL+=" and recorder='"+m_recorder+"' ";
}
if(m_subject!="")
{
strSQL+=" and subject='"+m_subject+"' ";
}
// AfxMessageBox(strSQL);
hTRes = m_pRecordset->Open((LPTSTR)strSQL.GetBuffer(130),
((CClientRelationshipApp*)AfxGetApp())->m_pConn.GetInterfacePtr(),
adOpenDynamic,adLockPessimistic,adCmdText);
int i=0;
m_list.DeleteAllItems();
while(!(m_pRecordset->adoEOF))
{
m_list.InsertItem(i,((CClientRelationshipApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("eventRecordID")));
COleDateTime eventDate= m_pRecordset->GetCollect("eventDate");
str.Format("%d-%d-%d",eventDate.GetYear(),eventDate.GetMonth(),eventDate.GetDay());
m_list.SetItemText(i,1,str);
m_list.SetItemText(i,2, ((CClientRelationshipApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("eventCharacter")));
m_list.SetItemText(i,3, ((CClientRelationshipApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("recorder")));
m_list.SetItemText(i,4, ((CClientRelationshipApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("subject")));
m_list.SetItemText(i,5, ((CClientRelationshipApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("content")));
m_pRecordset->MoveNext();
i++;
}
m_pRecordset->Close();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -