📄 searchletter.cpp
字号:
// SearchLetter.cpp : implementation file
//
#include "stdafx.h"
#include "Office.h"
#include "SearchLetter.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CSearchLetter dialog
CSearchLetter::CSearchLetter(CWnd* pParent /*=NULL*/)
: CDialog(CSearchLetter::IDD, pParent)
{
//{{AFX_DATA_INIT(CSearchLetter)
m_beginDate = COleDateTime::GetCurrentTime();
m_endDate = COleDateTime::GetCurrentTime();
m_subject = _T("");
m_letterType = _T("");
m_letterCharacter = _T("");
m_sendor = _T("");
m_receiver = _T("");
//}}AFX_DATA_INIT
}
void CSearchLetter::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CSearchLetter)
DDX_Control(pDX, IDC_RECEIVER, m_receiverCombo);
DDX_Control(pDX, IDC_SENDOR, m_sendorCombo);
DDX_Control(pDX, IDC_LETTERCHARACTER1, m_letterCharacterCombo);
DDX_Control(pDX, IDC_LETTERTYPE, m_letterTypeCombo);
DDX_Control(pDX, IDC_SUBJECT, m_subjectCombo);
DDX_Control(pDX, IDC_LIST, m_list);
DDX_DateTimeCtrl(pDX, IDC_BEGINDATE, m_beginDate);
DDX_DateTimeCtrl(pDX, IDC_ENDDATE, m_endDate);
DDX_CBString(pDX, IDC_SUBJECT, m_subject);
DDX_CBString(pDX, IDC_LETTERTYPE, m_letterType);
DDX_CBString(pDX, IDC_LETTERCHARACTER1, m_letterCharacter);
DDX_CBString(pDX, IDC_SENDOR, m_sendor);
DDX_CBString(pDX, IDC_RECEIVER, m_receiver);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CSearchLetter, CDialog)
//{{AFX_MSG_MAP(CSearchLetter)
ON_BN_CLICKED(IDC_SEARCH, OnSearch)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSearchLetter message handlers
void CSearchLetter::OnSearch()
{
UpdateData(true);
CString strSQL;
_RecordsetPtr m_pRecordset; //记录集
HRESULT hTRes;
hTRes = m_pRecordset.CreateInstance(_T("ADODB.Recordset"));//创建实例
strSQL="select * from letterRecord";//查询语句
CString str;
str.Format("%d-%d-%d",m_beginDate.GetYear(),m_beginDate.GetMonth(),m_beginDate.GetDay());
strSQL+=" where letterDate>'"+str+"' ";//将开始日期作为条件
str.Format("%d-%d-%d",m_endDate.GetYear(),m_endDate.GetMonth(),m_endDate.GetDay());
strSQL+=" and letterDate<'"+str+"' "; //将结束日期作为条件
if(m_subject!="")
{
strSQL+=" and subject='"+m_subject+"' ";//将主题作为条件
}
if(m_letterType!="")
{
strSQL+=" and letterType='"+m_letterType+"' "; //将信函类别作为条件
}
if(m_letterCharacter!="")
{
strSQL+=" and letterCharacter='"+m_letterCharacter+"' "; //将信函性质作为条件
}
if(m_sendor!="")
{
strSQL+=" and sendor='"+m_sendor+"' "; //将发件人作为条件
}
if(m_receiver!="")
{
strSQL+=" and receiver='"+m_receiver+"' ";//将收件人作为条件
}
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("letterCharacter")));//信函性质
COleDateTime eventDate= m_pRecordset->GetCollect("letterDate");//信函日期
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("sendor")));//发件人
m_list.SetItemText(i,3, ((COfficeApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("letterType")));//信函类别
m_list.SetItemText(i,4, ((COfficeApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("receiver")));//接收人
m_list.SetItemText(i,5, ((COfficeApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("subject")));//主题
m_list.SetItemText(i,6, ((COfficeApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("content")));//内容
m_list.SetItemText(i,7, ((COfficeApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("remark"))); //备注
m_pRecordset->MoveNext();//记录集指针向后移动
i++;
}
m_pRecordset->Close();//关闭记录集
}
BOOL CSearchLetter::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);
m_list.InsertColumn(7,"备注",LVCFMT_LEFT,100);
CString strSQL;
_RecordsetPtr m_pRecordset;
HRESULT hTRes;
hTRes = m_pRecordset.CreateInstance(_T("ADODB.Recordset"));
strSQL="select distinct letterType from letterRecord";
hTRes = m_pRecordset->Open((LPTSTR)strSQL.GetBuffer(130),
((COfficeApp*)AfxGetApp())->m_pConn.GetInterfacePtr(),
adOpenDynamic,adLockPessimistic,adCmdText);
int i=0;
while(!(m_pRecordset->adoEOF))
{
m_letterTypeCombo.InsertString(i,((COfficeApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("letterType")));
m_pRecordset->MoveNext();
i++;
}
m_pRecordset->Close();
strSQL="select distinct subject from letterRecord";
hTRes = m_pRecordset->Open((LPTSTR)strSQL.GetBuffer(130),
((COfficeApp*)AfxGetApp())->m_pConn.GetInterfacePtr(),
adOpenDynamic,adLockPessimistic,adCmdText);
i=0;
while(!(m_pRecordset->adoEOF))
{
m_subjectCombo.InsertString(i,((COfficeApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("subject")));
m_pRecordset->MoveNext();
i++;
}
m_pRecordset->Close();
strSQL="select distinct letterCharacter from letterRecord";
hTRes = m_pRecordset->Open((LPTSTR)strSQL.GetBuffer(130),
((COfficeApp*)AfxGetApp())->m_pConn.GetInterfacePtr(),
adOpenDynamic,adLockPessimistic,adCmdText);
i=0;
while(!(m_pRecordset->adoEOF))
{
m_letterCharacterCombo.InsertString(i,((COfficeApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("letterCharacter")));
m_pRecordset->MoveNext();
i++;
}
m_pRecordset->Close();
strSQL="select distinct sendor from letterRecord";
hTRes = m_pRecordset->Open((LPTSTR)strSQL.GetBuffer(130),
((COfficeApp*)AfxGetApp())->m_pConn.GetInterfacePtr(),
adOpenDynamic,adLockPessimistic,adCmdText);
i=0;
while(!(m_pRecordset->adoEOF))
{
m_sendorCombo.InsertString(i,((COfficeApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("sendor")));
m_pRecordset->MoveNext();
i++;
}
m_pRecordset->Close();
strSQL="select distinct receiver from letterRecord";
hTRes = m_pRecordset->Open((LPTSTR)strSQL.GetBuffer(130),
((COfficeApp*)AfxGetApp())->m_pConn.GetInterfacePtr(),
adOpenDynamic,adLockPessimistic,adCmdText);
i=0;
while(!(m_pRecordset->adoEOF))
{
m_receiverCombo.InsertString(i,((COfficeApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("receiver")));
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 + -