⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pagereceivelog.cpp

📁 短信群发系统
💻 CPP
字号:
// PageReceiveLog.cpp : implementation file
//

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

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

/////////////////////////////////////////////////////////////////////////////
// CPageReceiveLog dialog


CPageReceiveLog::CPageReceiveLog(CWnd* pParent /*=NULL*/)
	: CDialog(CPageReceiveLog::IDD, pParent)
{
	//{{AFX_DATA_INIT(CPageReceiveLog)
	m_content = _T("");
	m_end_time = COleDateTime::GetCurrentTime();
	m_no = _T("");
	m_recvid = _T("");
	m_start_time = COleDateTime::GetCurrentTime();
	CulSel = 0;
	//}}AFX_DATA_INIT
}


void CPageReceiveLog::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CPageReceiveLog)
	DDX_Control(pDX, IDC_RECV_LIST, m_list);
	DDX_Control(pDX, IDC_START_TIME, m_ctrl_starttime);
	DDX_Control(pDX, IDC_RECV_ID, m_ctrl_id);
	DDX_Control(pDX, IDC_RADIO, m_radio);
	DDX_Control(pDX, IDC_RECVNO, m_ctrl_no);
	DDX_Control(pDX, IDC_END_TIME, m_ctrl_endtime);
	DDX_Control(pDX, IDC_CONTENT, m_ctrl_content);
	DDX_Text(pDX, IDC_CONTENT, m_content);
	DDX_DateTimeCtrl(pDX, IDC_END_TIME, m_end_time);
	DDX_Text(pDX, IDC_RECVNO, m_no);
	DDX_Text(pDX, IDC_RECV_ID, m_recvid);
	DDX_DateTimeCtrl(pDX, IDC_START_TIME, m_start_time);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CPageReceiveLog, CDialog)
	//{{AFX_MSG_MAP(CPageReceiveLog)
	ON_BN_CLICKED(IDC_SEARCH, OnSearch)
	ON_BN_CLICKED(IDC_REPORT, OnReport)
	ON_BN_CLICKED(IDC_RADIO, OnRadio)
	ON_BN_CLICKED(IDC_RADIO_TIME, OnRadioTime)
	ON_BN_CLICKED(IDC_RADIO_NO, OnRadioNo)
	ON_BN_CLICKED(IDC_RADIO_CONTENT, OnRadioContent)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CPageReceiveLog message handlers

void CPageReceiveLog::OnSearch() 
{
	UpdateData();
	CString			command;

	if (CulSel == 1)
	{
		if (m_recvid.GetLength() == 0)
		{
			MessageBox("接收ID不能为空", "提示");
			return;
		}
		command.Format("select * from ReceivedLog where ID='%s'", m_recvid);
	}
	else if (CulSel == 2)
	{
		if (m_start_time > m_end_time)
		{
			MessageBox("开始时间不能大于结束时间", "提示");
			return;
		}
		CString			strStartTime;
		CString			strEndTime;

		strStartTime = m_start_time.Format("%Y-%m-%d");
		strEndTime	 = m_end_time.Format("%Y-%m-%d");
		command.Format("select * from ReceivedLog where ReplyTime between '%s' and '%s'", strStartTime, strEndTime);
	}
	else if (CulSel == 3)
	{
		if (m_no.GetLength() == 0)
		{
			MessageBox("号码不能为空", "提示");
			return;
		}
		command.Format("select * from ReceivedLog where PeerNumber='%s'", m_no);
	}
	else if (CulSel == 4)
	{
		if (m_content.GetLength() == 0)
		{
			MessageBox("内容不能为空", "提示");
			return;
		}
		command.Format("select * from ReceivedLog where ReplyContent='%s'", m_content);
	}
	CNoteSendSystemApp *pApp =(CNoteSendSystemApp *)AfxGetApp();
	CAdoRecordSet		record;
	pApp->m_pConnection.GetRecordSet(command, record);
	if (record.IsEof())
	{
		MessageBox("没有数据", "提示");
		m_no.Empty();
		m_content.Empty();
		m_recvid.Empty();
		UpdateData(FALSE);
		return;
	}
	RecvList			recvlist;
	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();
	}
	ShowList();
}

void CPageReceiveLog::OnReport() 
{
	CString			command;
	CAdoRecordSet	record;
	
	CNoteSendSystemApp *pApp = (CNoteSendSystemApp *)AfxGetApp();
	
	command.Format("select * from ReceivedLog");
	pApp->m_pConnection.GetRecordSet(command, record);
	
	if (record.IsEof())
	{
		MessageBox("没有接收日志,不能导出", "提示");
		return;
	}
		
	CString szFilterFDlg = "文本文件 (*.txt)|*.txt||"; 
	CFileDialog myFileDlg(FALSE, "txt", NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, szFilterFDlg, NULL);
	myFileDlg.m_ofn.lpstrTitle= _T("请选择保存路径:");
	if ( myFileDlg.DoModal() !=IDOK )
	{
		return;
	}
	else
	{
		m_FilePathName = myFileDlg.GetFileName();
		if (!ExportRecvLog(record))
		{
			return;
		}
		MessageBox("保存接收日志成功", "提示");
	}
}

void CPageReceiveLog::OnOK() 
{
	// TODO: Add extra validation here
	
//	CDialog::OnOK();
}

void CPageReceiveLog::OnCancel() 
{
	// TODO: Add extra cleanup here
	
//	CDialog::OnCancel();
}

void CPageReceiveLog::OnRadio() 
{
	m_ctrl_id.EnableWindow(TRUE);
	m_ctrl_content.EnableWindow(FALSE);
	m_ctrl_endtime.EnableWindow(FALSE);
	m_ctrl_starttime.EnableWindow(FALSE);
	m_ctrl_no.EnableWindow(FALSE);
	CulSel = 1;
}

void CPageReceiveLog::OnRadioTime() 
{
	m_ctrl_id.EnableWindow(FALSE);
	m_ctrl_content.EnableWindow(FALSE);
	m_ctrl_endtime.EnableWindow(TRUE);
	m_ctrl_starttime.EnableWindow(TRUE);
	m_ctrl_no.EnableWindow(FALSE);
	CulSel =2;
}

void CPageReceiveLog::OnRadioNo() 
{
	m_ctrl_id.EnableWindow(FALSE);
	m_ctrl_content.EnableWindow(FALSE);
	m_ctrl_endtime.EnableWindow(FALSE);
	m_ctrl_starttime.EnableWindow(FALSE);
	m_ctrl_no.EnableWindow(TRUE);
	CulSel = 3;
}

void CPageReceiveLog::OnRadioContent() 
{
	m_ctrl_id.EnableWindow(FALSE);
	m_ctrl_content.EnableWindow(TRUE);
	m_ctrl_endtime.EnableWindow(FALSE);
	m_ctrl_starttime.EnableWindow(FALSE);
	m_ctrl_no.EnableWindow(FALSE);	
	CulSel = 4;
}

BOOL CPageReceiveLog::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	m_radio.SetCheck(1);
	m_ctrl_id.EnableWindow(TRUE);
	m_ctrl_content.EnableWindow(FALSE);
	m_ctrl_endtime.EnableWindow(FALSE);
	m_ctrl_starttime.EnableWindow(FALSE);
	m_ctrl_no.EnableWindow(FALSE);
	
	CulSel = 1;

	//初始化列表控件
	m_list.ModifyStyle(0, LVS_REPORT);
	
	CString	str[4] = {"接收日志ID", "接收号码", "接收内容", "接收时间"};
	int		i;
	for (i = 0; i < 4; i++)
	{
		m_list.InsertColumn(i, str[i], LVCFMT_LEFT, 100);
	}
	//设置列表控件初始化属性
	m_list.SetExtendedStyle(m_list.GetExtendedStyle() | LVS_EX_GRIDLINES | LVS_EX_FULLROWSELECT);	
 
	return TRUE;  // return TRUE unless you set the focus to a cointrol
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CPageReceiveLog::ShowList()
{
	if (m_list.m_hWnd)
	{
		m_list.DeleteAllItems();
	}
	CNoteSendSystemApp *pApp = (CNoteSendSystemApp *)AfxGetApp();
	CString		str;

	int len = pApp->RecvListVect.size();
	
	for (int i=0; i<len; i++)
	{
		str.Format("%d", pApp->RecvListVect[i].recv_id);
		m_list.InsertItem(i, str);
		str.Empty();	
		
		str.Format("%s", pApp->RecvListVect[i].no);
		m_list.SetItemText(i, 1, str);
		str.Empty();

		str.Format("%s", pApp->RecvListVect[i].content);
		m_list.SetItemText(i, 2, str);
		str.Empty();
		
		str = pApp->RecvListVect[i].recv_time.Format("%Y-%m-%d %H:%M:%S");
		m_list.SetItemText(i, 3, str);
		str.Empty();
	}
	pApp->RecvListVect.clear();
}

int CPageReceiveLog::ExportRecvLog(CAdoRecordSet &record)
{
	CNoteSendSystemApp *pApp = (CNoteSendSystemApp *)AfxGetApp();
	RecvList		recv;
	while(!record.IsEof())
	{
		record.GetValue("ID", recv.recv_id);
		record.GetValue("PeerNumber", recv.no);
		record.GetValue("ReplyContent", recv.content);
		record.GetValue("ReplyTime", recv.recv_time);
		pApp->RecvListVect.push_back(recv);
		record.MoveNext();
	}
	CString		strBuf;
	CString		strTime;
	CStdioFile	stdFile;
	int			len;

	len = pApp->RecvListVect.size();
	if (!stdFile.Open(m_FilePathName, CFile::modeCreate | CFile::modeWrite))
	{
		MessageBox("保存接收日志时创建文件失败", "提示");
		pApp->RecvListVect.clear();
		return 0;
	}
	stdFile.WriteString("接收日志\r\n\r\n");
	stdFile.WriteString("接收日志ID    号码	      内容					    时间\r\n\r\n");
	
	for (int i=0; i<len; i++)
	{
		recv = pApp->RecvListVect[i];
		strTime = recv.recv_time.Format("%Y-%m-%d %H:%M:%S");
		strBuf.Format("%-14d%-16s%-46s%-20s\r\n\r\n", recv.recv_id, recv.no, recv.content, strTime);
		stdFile.WriteString(strBuf);
		strTime.Empty();
	}
	pApp->RecvListVect.clear();
	return 1;
}

⌨️ 快捷键说明

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