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

📄 pagesendlog.cpp

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

#include "stdafx.h"
#include "notesendsystem.h"
#include "PageSendLog.h"
#include "AdoRecordSet.h"
#include "LogManager.h"

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

/////////////////////////////////////////////////////////////////////////////
// CPageSendLog dialog


CPageSendLog::CPageSendLog(CWnd* pParent /*=NULL*/)
	: CDialog(CPageSendLog::IDD, pParent)
{
	//{{AFX_DATA_INIT(CPageSendLog)
	m_enddate = COleDateTime::GetCurrentTime();
	m_orderid = _T("");
	m_phoneno = _T("");
	m_startdate = COleDateTime::GetCurrentTime();
	//}}AFX_DATA_INIT
	culSel = 1;
}


void CPageSendLog::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CPageSendLog)
	DDX_Control(pDX, IDC_SEND_LIST, m_list);
	DDX_Control(pDX, IDC_RADIO_ORDERID, m_radio);
	DDX_Control(pDX, IDC_STARTDATE, m_ctrl_startdate);
	DDX_Control(pDX, IDC_PHONENO, m_ctrl_phoneno);
	DDX_Control(pDX, IDC_ORDERID, m_ctrl_orderid);
	DDX_Control(pDX, IDC_ENDDATE, m_ctrl_enddate);
	DDX_Control(pDX, IDC_COMBO, m_combo);
	DDX_DateTimeCtrl(pDX, IDC_ENDDATE, m_enddate);
	DDX_Text(pDX, IDC_ORDERID, m_orderid);
	DDX_Text(pDX, IDC_PHONENO, m_phoneno);
	DDX_DateTimeCtrl(pDX, IDC_STARTDATE, m_startdate);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CPageSendLog, CDialog)
	//{{AFX_MSG_MAP(CPageSendLog)
	ON_BN_CLICKED(IDC_SEARCH, OnSearch)
	ON_BN_CLICKED(IDC_RADIO_ORDERID, OnRadioOrderid)
	ON_BN_CLICKED(IDC_RADIO_SENDTIME, OnRadioSendtime)
	ON_BN_CLICKED(IDC_RADIO_PHONENO, OnRadioPhoneno)
	ON_BN_CLICKED(IDC_RADIO_SENDSTATE, OnRadioSendstate)
	ON_BN_CLICKED(IDC_EXPORT, OnExport)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CPageSendLog message handlers

void CPageSendLog::OnSearch() 
{
	UpdateData();
	CString			command;
	CString			Send_State;
	CAdoRecordSet	record;

	CNoteSendSystemApp *pApp = (CNoteSendSystemApp *)AfxGetApp();

	if (culSel == 1)
	{
		if (m_orderid.GetLength() == 0)
		{
			MessageBox("订单号不能为空", "提示");
			return;
		}
		command.Format("select * from SendLog where OrderID='%s'", m_orderid);
	}
	else if (culSel == 2)
	{	
		if (m_startdate > m_enddate)
		{
			MessageBox("开始日期不能大于结束日期", "提示");
			return;
		}
		CString		starttime;
		CString     endtime;
		starttime = m_startdate.Format("%Y-%m-%d");
		endtime = m_enddate.Format("%Y-%m-%d");
		command.Format("select * from SendLog where SendTime between '%s' and '%s'", starttime, endtime);	
	}
	else if (culSel == 3)
	{
		if (m_phoneno.GetLength() == 0)
		{
			MessageBox("电话号码不能为空", "提示");
			return;
		}
		if (m_phoneno.GetLength() != 11)
		{
			MessageBox("电话号码必须为11位", "提示");
			m_phoneno.Empty();
			UpdateData(FALSE);
			return;
		}
		command.Format("select * from SendLog where PhoneNo='%s'", m_phoneno);
	}
	else if (culSel == 4)
	{
		//1表示成功 0表示失败	
		int state;
		int	index = m_combo.GetCurSel();
		CString		str;
		m_combo.GetLBText(index, str);
		if (str == "成功")
		{
			state = 1;
		}
		else
		{
			state = 0;
		}
		command.Format("select * from SendLog where State='%d'", state);
	}
	pApp->m_pConnection.GetRecordSet(command, record);
	if (record.IsEof())
	{	if (m_list.m_hWnd)
		{
			m_list.DeleteAllItems();
		}
		MessageBox("没有数据", "提示");
	
		m_orderid.Empty();
		m_phoneno.Empty();
		UpdateData(FALSE);
		return;
	}

	SendList			list;
	while (!record.IsEof())
	{
		record.GetValue("ID", list.send_id);
		record.GetValue("OrderID", list.order_id);
		record.GetValue("SendTime", list.send_time);
		record.GetValue("State", list.send_state);
		record.GetValue("Content", list.content);
		record.GetValue("PhoneNo", list.no);
		pApp->SendListVect.push_back(list);
		record.MoveNext();
	}
	ShowList();
}

void CPageSendLog::OnRadioOrderid() 
{
	culSel = 1;
	m_ctrl_orderid.EnableWindow(TRUE);
	m_ctrl_startdate.EnableWindow(FALSE);
	m_ctrl_enddate.EnableWindow(FALSE);
	m_combo.EnableWindow(FALSE);
	m_ctrl_phoneno.EnableWindow(FALSE);
}

void CPageSendLog::OnRadioSendtime() 
{
	culSel = 2;
	m_ctrl_orderid.EnableWindow(FALSE);
	m_ctrl_startdate.EnableWindow(TRUE);
	m_ctrl_enddate.EnableWindow(TRUE);
	m_combo.EnableWindow(FALSE);
	m_ctrl_phoneno.EnableWindow(FALSE);
}

void CPageSendLog::OnRadioPhoneno() 
{
	culSel = 3;
	m_ctrl_orderid.EnableWindow(FALSE);
	m_ctrl_startdate.EnableWindow(FALSE);
	m_ctrl_enddate.EnableWindow(FALSE);
	m_combo.EnableWindow(FALSE);
	m_ctrl_phoneno.EnableWindow(TRUE);
}

void CPageSendLog::OnRadioSendstate() 
{
	culSel = 4;
	m_ctrl_orderid.EnableWindow(FALSE);
	m_ctrl_startdate.EnableWindow(FALSE);
	m_ctrl_enddate.EnableWindow(FALSE);
	m_combo.EnableWindow(TRUE);
	m_ctrl_phoneno.EnableWindow(FALSE);	
}

BOOL CPageSendLog::OnInitDialog() 
{
	CDialog::OnInitDialog();
	m_combo.AddString("成功");
	m_combo.AddString("失败");
	m_combo.SetCurSel(0);
	m_radio.SetCheck(1);
	m_ctrl_orderid.EnableWindow(TRUE);
	m_ctrl_startdate.EnableWindow(FALSE);
	m_ctrl_enddate.EnableWindow(FALSE);
	m_combo.EnableWindow(FALSE);
	m_ctrl_phoneno.EnableWindow(FALSE);

	m_list.ModifyStyle(0, LVS_REPORT);
	
	CString	str[6] = {"发送日志ID", "订单号", "发送时间", "发送状态", "内容", "电话号码"};
	int		i;
	for (i = 0; i < 6; i++)
	{
		m_list.InsertColumn(i, str[i], LVCFMT_LEFT, 75);
	}
	//设置列表控件初始化属性
	m_list.SetExtendedStyle(m_list.GetExtendedStyle() | LVS_EX_GRIDLINES | LVS_EX_FULLROWSELECT);	
 
	return TRUE; 
}

void CPageSendLog::SaveToVect()
{

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

	int len = pApp->SendListVect.size();

	for (int i=0; i<len; i++)
	{
		str.Format("%d", pApp->SendListVect[i].send_id);
		m_list.InsertItem(i, str);
		str.Empty();

		str.Format("%d", pApp->SendListVect[i].order_id);
		m_list.SetItemText(i, 1, str);
		str.Empty();

		str = pApp->SendListVect[i].send_time.Format("%Y-%m-%d %H:%M:%S");
		m_list.SetItemText(i, 2, str);
		str.Empty();
		
		if (pApp->SendListVect[i].send_state == 1)
		{
			str = "发送成功";
		}
		else
		{
			str = "发送失败";
		}
		m_list.SetItemText(i, 3, str);
		str.Empty();		

		str.Format("%s", pApp->SendListVect[i].content);
		m_list.SetItemText(i, 4, str);
		str.Empty();

		str.Format("%s", pApp->SendListVect[i].no);
		m_list.SetItemText(i, 5, str);
		str.Empty();
	}
	pApp->SendListVect.clear();
}
void CPageSendLog::OnExport() 
{
	CString			command;
	CAdoRecordSet	record;
	
	CNoteSendSystemApp *pApp = (CNoteSendSystemApp *)AfxGetApp();
	
	command.Format("select * from SendLog");
	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();
		ExportSendLog(record);
		MessageBox("保存发送日志成功", "提示");
	}
}

int CPageSendLog::ExportSendLog(CAdoRecordSet	&record)
{
	CNoteSendSystemApp *pApp = (CNoteSendSystemApp *)AfxGetApp();
	SendList			sendlist;
	while(!record.IsEof())
	{
		record.GetValue("ID", sendlist.send_id);
		record.GetValue("OrderID", sendlist.order_id);
		record.GetValue("SendTime", sendlist.send_time);
		record.GetValue("State", sendlist.send_state);
		record.GetValue("Content", sendlist.content);
		record.GetValue("PhoneNo", sendlist.no);
		pApp->SendListVect.push_back(sendlist);
		record.MoveNext();
	}
	
	CStdioFile   stdFile;
	CString		 strBuf;
	CString		 strTime;
	int			 len;
	len = pApp->SendListVect.size();
	if (!stdFile.Open(m_FilePathName, CFile::modeCreate | CFile::modeWrite))
	{
		MessageBox("保存时创建文件失败", "提示");
		pApp->SendListVect.clear();
		return 0;
	}
	stdFile.WriteString("发送日志\r\n\r\n");
	stdFile.WriteString("发送日志ID  订单ID  发送时间            发送状态  发送内容				号码\r\n\r\n");
	for(int i=0; i<len; i++)
	{
		sendlist = pApp->SendListVect[i];
		strTime = sendlist.send_time.Format("%Y-%m-%d %H:%M:%S");
		strBuf.Format("%-12d%-8d%-20s%-10d%-38s%-11s",\
		sendlist.send_id, sendlist.order_id, strTime,  sendlist.send_state, sendlist.content, sendlist.no);
		stdFile.WriteString(strBuf);
		stdFile.WriteString("\r\n\r\n");
		strTime.Empty();
	}
	pApp->SendListVect.clear();
	stdFile.Close();
	return 1;
}

⌨️ 快捷键说明

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