mylistview.cpp

来自「短信群发系统」· C++ 代码 · 共 173 行

CPP
173
字号
// MyListView.cpp : implementation file
//

#include "stdafx.h"
#include "notesendsystem.h"
#include "MyListView.h"
#include "AdoRecordSet.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CMyListView

IMPLEMENT_DYNCREATE(CMyListView, CListView)

CMyListView::CMyListView()
{
}

CMyListView::~CMyListView()
{
}

BEGIN_MESSAGE_MAP(CMyListView, CListView)
	//{{AFX_MSG_MAP(CMyListView)
		// NOTE - the ClassWizard will add and remove mapping macros here.
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMyListView drawing

void CMyListView::OnDraw(CDC* pDC)
{
	CDocument* pDoc = GetDocument();
	// TODO: add draw code here
}

/////////////////////////////////////////////////////////////////////////////
// CMyListView diagnostics

#ifdef _DEBUG
void CMyListView::AssertValid() const
{
	CListView::AssertValid();
}

void CMyListView::Dump(CDumpContext& dc) const
{
	CListView::Dump(dc);
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CMyListView message handlers

void CMyListView::OnInitialUpdate() 
{
	CListView::OnInitialUpdate();
	CListCtrl& ListCtrl = GetListCtrl();
	
	DWORD dwStytle = ::GetWindowLong(m_hWnd, GWL_STYLE); 
	dwStytle |= LVS_REPORT;
	::SetWindowLong(m_hWnd, GWL_STYLE, dwStytle);
	ListCtrl.SetExtendedStyle(ListCtrl.GetExtendedStyle() | LVS_EX_GRIDLINES | LVS_EX_FULLROWSELECT);
	
	ListCtrl.InsertColumn(0, "号码", LVCFMT_LEFT, 100);
	ListCtrl.InsertColumn(1, "时间", LVCFMT_LEFT, 140);
	ListCtrl.InsertColumn(2, "消息内容", LVCFMT_LEFT, 285);
	ListCtrl.InsertColumn(3, "状态", LVCFMT_LEFT, 100);
//	UpdateListView();
}

void CMyListView::UpdateListView()
{
	CListCtrl& m_list = GetListCtrl();

	if (m_list.m_hWnd)
	{
		m_list.DeleteAllItems();
	}
	int					i;
	CString				str;
	CString				command;
	CString				timebuf;
	COleDateTime		time;
	CAdoRecordSet		record;
	RecvList			recvlist;
	SendList			sendlist;

	command.Format("select * from ReceivedLog");
	CNoteSendSystemApp *pApp =(CNoteSendSystemApp *)AfxGetApp();
	pApp->m_pConnection.GetRecordSet(command, record);
	//读取接收日志
	while (!record.IsEof())
	{
		record.GetValue("ID", recvlist.recv_id);
		record.GetValue("PeerNumber", recvlist.no);
		record.GetValue("ReplyContent", recvlist.content);
		record.GetValue("ReplyTime", recvlist.recv_time);		
		pApp->RecvListVect.push_back(recvlist);
		record.MoveNext();
	}
	//显示接收日志
	int recvlen = pApp->RecvListVect.size();
	for (i=0; i<recvlen; i++)
	{
		str.Format("%s", pApp->RecvListVect[i].no);
		m_list.InsertItem(i, str);
		str.Empty();
		
		timebuf = pApp->RecvListVect[i].recv_time.Format("%Y-%m-%d %H:%M:%S");
		str.Format("%s", timebuf);
		m_list.SetItemText(i, 1, str);			
		str.Empty();
		timebuf.Empty();

		str.Format("%s", pApp->RecvListVect[i].content);
		m_list.SetItemText(i, 2, str);			
		str.Empty();
		
		str.Format("接收");
		m_list.SetItemText(i, 3, str);			
		str.Empty();	
	}

	CAdoRecordSet		recvrecord;
	command.Empty();
	command.Format("select * from SendLog");
	pApp->m_pConnection.GetRecordSet(command, recvrecord);

	//读取发送日志
	while (!recvrecord.IsEof())
	{
		recvrecord.GetValue("ID", sendlist.send_id);
		recvrecord.GetValue("PhoneNo", sendlist.no);
		recvrecord.GetValue("Content", sendlist.content);
		recvrecord.GetValue("SendTime", sendlist.send_time);		
		pApp->SendListVect.push_back(sendlist);
		recvrecord.MoveNext();
	}

	//显示发送日志
	int sendlen = pApp->RecvListVect.size();
	for (i=0; i<sendlen; i++)
	{
		str.Format("%s", pApp->SendListVect[i].no);
		m_list.InsertItem(i+recvlen, str);
		str.Empty();
		
		timebuf = pApp->SendListVect[i].send_time.Format("%Y-%m-%d %H:%M:%S");
		str.Format("%s", timebuf);
		m_list.SetItemText(i+recvlen, 1, str);			
		str.Empty();
		timebuf.Empty();
		
		str.Format("%s", pApp->RecvListVect[i].content);
		m_list.SetItemText(i+recvlen, 2, str);			
		str.Empty();
		
		str.Format("发送");
		m_list.SetItemText(i+recvlen, 3, str);			
		str.Empty();	
	}
	
	pApp->SendListVect.clear();
	pApp->RecvListVect.clear();
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?