📄 inqu.cpp
字号:
// INQU.cpp : implementation file
//
#include "stdafx.h"
#include "SMS.h"
#include "INQU.h"
#include "CSpreadSheet.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CINQU dialog
CINQU::CINQU(CWnd* pParent /*=NULL*/)
: CDialog(CINQU::IDD, pParent)
{
//{{AFX_DATA_INIT(CINQU)
m_personlist = _T("");
m_gzrn = _T("");
m_begintime = COleDateTime::GetCurrentTime();
m_endtime = COleDateTime::GetCurrentTime();
//}}AFX_DATA_INIT
m_count = _T("找到0条记录");
}
void CINQU::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CINQU)
DDX_Control(pDX, IDC_LIST1, m_clist);
DDX_CBString(pDX, IDC_COMBO1, m_personlist);
DDX_Text(pDX, IDC_EDIT1, m_gzrn);
DDX_DateTimeCtrl(pDX, IDC_DATETIMEPICKER1, m_begintime);
DDX_DateTimeCtrl(pDX, IDC_DATETIMEPICKER2, m_endtime);
DDX_Text(pDX, IDC_COUNT, m_count);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CINQU, CDialog)
//{{AFX_MSG_MAP(CINQU)
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
ON_NOTIFY(NM_CLICK, IDC_LIST1, OnClickList1)
ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CINQU message handlers
void CINQU::OnButton1()
{
findperson();
// TODO: Add your control notification handler code here
}
BOOL CINQU::OnInitDialog()
{
CDialog::OnInitDialog();
int nColumnCount = m_clist.GetHeaderCtrl()->GetItemCount();
m_clist.SetExtendedStyle( LVS_EX_GRIDLINES | LVS_EX_FULLROWSELECT );
CComboBox* pComb=(CComboBox*)this->GetDlgItem(IDC_COMBO1);
CString strText;
_variant_t Holder, strQuery;
strQuery = "select distinct name from information ";
theApp.ADOExecute(theApp.m_pADOSet, strQuery);
int iCount = theApp.m_pADOSet->GetRecordCount();
theApp.m_pADOSet->MoveFirst();
pComb->AddString("All");
for (int i=0;i<iCount;i++)
{Holder=theApp.m_pADOSet->GetCollect("name");
strText=(Holder.vt==VT_NULL?"":(char*)(_bstr_t)Holder);
pComb->AddString(strText);
theApp.m_pADOSet->MoveNext();
}
pComb->SetCurSel(0);
//索引
for ( i=0;i < nColumnCount;i++)
{
m_clist.DeleteColumn(0);
}
m_clist.DeleteAllItems();
char *title[] =
{
"发送人",
"发送时间",
"短信内容",
"发送对象"
};
int nWidth[4] = { 80, 120, 380,120};
for(i = 0; i < 4; i++ )
{
m_clist.InsertColumn( i, title[i], LVCFMT_LEFT, nWidth[i], 0 );
}
return true;
}
void CINQU::findperson()
{
UpdateData();
CString begin=m_begintime.Format("%Y-%m-%d");
CString end=m_endtime.Format("%Y-%m-%d");
begin=begin+" "+"00"+":"+"01";
end=end+" "+"23"+":"+"59";
CTimeSpan spn=m_endtime-m_begintime;
if (spn<0)
{ AfxMessageBox(_T("中止时间不能小于开始时间"), MB_ICONEXCLAMATION);
return;}
CString strText,username;
CComboBox* pCombobox=(CComboBox*) this->GetDlgItem(IDC_COMBO1);
pCombobox->GetWindowText(username);
_variant_t Holder, strQuery;
if (username=="All")
{strQuery = "select * from information where sbdate between '"+begin+"' and '"+end+"' ";
}
else
{strQuery = "select * from information where name='"+username+"' and sbdate between '"+begin+"' and '"+end+"' ";
}
theApp.ADOExecute(theApp.m_pADOSet, strQuery);
int iCount = theApp.m_pADOSet->GetRecordCount();
m_clist.DeleteAllItems();
if (iCount>0)
{
theApp.m_pADOSet->MoveFirst();
for (int i=0;i<iCount;i++)
{Holder=theApp.m_pADOSet->GetCollect("name");
strText=(Holder.vt==VT_NULL?"":(char*)(_bstr_t)Holder);
m_clist.InsertItem( i, strText );
Holder=theApp.m_pADOSet->GetCollect("sbdate");
strText=(Holder.vt==VT_NULL?"":(char*)(_bstr_t)Holder);
m_clist.SetItemText( i, 1, strText );
Holder=theApp.m_pADOSet->GetCollect("content");
strText=(Holder.vt==VT_NULL?"":(char*)(_bstr_t)Holder);
m_clist.SetItemText( i, 2, strText );
Holder=theApp.m_pADOSet->GetCollect("sbperosn");
strText=(Holder.vt==VT_NULL?"":(char*)(_bstr_t)Holder);
m_clist.SetItemText( i, 3, strText );
theApp.m_pADOSet->MoveNext();
}
m_count.Format( "找到%d条记录", m_clist.GetItemCount());
UpdateData(false);
}
else {m_count.Format( "找到%d条记录", m_clist.GetItemCount());
UpdateData(false);
return;}
}
void CINQU::finddate()
{
}
void CINQU::OnClickList1(NMHDR* pNMHDR, LRESULT* pResult)
{ CString value;
POSITION pos;
pos = m_clist.GetFirstSelectedItemPosition();
IndexInFieldList = m_clist.GetNextSelectedItem(pos);
value = m_clist.GetItemText(IndexInFieldList, 2);
m_gzrn=value;
UpdateData(false);
// TODO: Add your control notification handler code here
*pResult = 0;
}
void CINQU::OnButton2()
{
int count=m_clist.GetItemCount();
CString value;
CString strDestName;
CFileDialog dlg(FALSE);
char cFilter[]="Microsoft Excel 文件\0*.xls\0\0";
dlg.m_ofn.lpstrFilter=cFilter;
if (dlg.DoModal()==IDOK)
{
//获得下载文件在本地机上存储的路径和名称
strDestName=dlg.GetPathName();
if(strDestName=="")
{ AfxMessageBox("请写入文件名!",MB_OK|MB_ICONSTOP);
return;}
//调用函数下载文件
}
else
{
return;
}
CSpreadSheet SS(strDestName+".xls", "短信查询信息汇总");
CStringArray sampleArray, testRow;
SS.BeginTransaction();
// 加入标题
sampleArray.RemoveAll();
sampleArray.Add("上报人");
sampleArray.Add("上报时间");
sampleArray.Add("短信内容");
sampleArray.Add("发送对象");
SS.AddHeaders(sampleArray);
// 加入数据
for(int i = 0; i <= count; i++)
{ sampleArray.RemoveAll();
for (int j=0;j<4;j++)
{
value = m_clist.GetItemText(i, j);
sampleArray.Add(value);
}
SS.AddRow(sampleArray);
}
SS.Commit();
MessageBox("导出成功");
// TODO: Add your control notification handler code here
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -