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

📄 myformview.cpp

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

#include "stdafx.h"
#include "notesendsystem.h"
#include "MyFormView.h"
#include "MainFrm.h"
#include "MyListView.h"

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

/////////////////////////////////////////////////////////////////////////////
// CMyFormView

IMPLEMENT_DYNCREATE(CMyFormView, CFormView)

CMyFormView::CMyFormView()
	: CFormView(CMyFormView::IDD)
{
	//{{AFX_DATA_INIT(CMyFormView)
	m_msg = _T("");
	m_no = _T("");
	m_sendrecvmsg = _T("");
	//}}AFX_DATA_INIT
}

CMyFormView::~CMyFormView()
{
}

void CMyFormView::DoDataExchange(CDataExchange* pDX)
{
	CFormView::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CMyFormView)
	DDX_Text(pDX, IDC_MSG, m_msg);
	DDX_Text(pDX, IDC_PHONENO, m_no);
	DDX_Text(pDX, IDC_SEND_RECV_MSGBOX, m_sendrecvmsg);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CMyFormView, CFormView)
	//{{AFX_MSG_MAP(CMyFormView)
	ON_BN_CLICKED(IDC_SEND, OnSend)
	ON_BN_CLICKED(IDM_SEND, OnSend)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMyFormView diagnostics

#ifdef _DEBUG
void CMyFormView::AssertValid() const
{
	CFormView::AssertValid();
}

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

/////////////////////////////////////////////////////////////////////////////
// CMyFormView message handlers

void CMyFormView::OnSend() 
{
	CMainFrame * pMainFrame = (CMainFrame *)AfxGetMainWnd();
	//当前是否连接到串口
	if (pMainFrame->connect_state == 0)
	{
		MessageBox("还未连接到串口,不能发送", "提示");
		m_no.Empty();
		m_msg.Empty();
		UpdateData(FALSE);
		return;
	}

	UpdateData();
	if (m_msg.GetLength() == 0)
	{
		MessageBox("信息不能为空", "提示");
		return;
	}
	//对号码进行验证
	if (m_no.GetLength() == 0)
	{
		MessageBox("号码不能为空", "提示");
		return;
	}
	if (m_no.GetLength() != 11)
	{
		MessageBox("请输入正确的号码", "提示");
		m_no.Empty();
		UpdateData(FALSE);
		return;
	}

	//进行发送操作
	SM_PARAM    SmParam;
	CString		strSmsc;
	CString		strNumber;
	CString		strContent;
	int			len		= m_msg.GetLength();
	int			send_state;
	char*		msg		= new char[1024];

	memset(&SmParam, 0, sizeof(SM_PARAM));	
	strcpy(msg, (LPCTSTR)m_msg);
	CNoteSendSystemApp *pApp = (CNoteSendSystemApp *)AfxGetApp();
	strSmsc		 = pApp->CulPhone;
	strNumber	 = m_no;
	strContent	 = m_msg;

	if(strSmsc[0] == '+')  strSmsc = strSmsc.Mid(1);
	if(strNumber[0] == '+')  strNumber = strNumber.Mid(1);
	if(strSmsc.Left(2) != "86")  strSmsc = "86" + strSmsc;
	if(strNumber.Left(2) != "86")  strNumber = "86" + strNumber;
	
	strcpy(SmParam.SCA, strSmsc);
	strcpy(SmParam.TPA, strNumber);
	strcpy(SmParam.TP_UD, strContent);
	SmParam.TP_PID = 0;
	SmParam.TP_DCS = GSM_UCS2;

	//发送消息
	if (!gsmSendMessage(&SmParam, pMainFrame))
	{
		MessageBox("发送失败", "提示");
		send_state	=  0;
	}
	else
	{
		MessageBox("发送成功", "提示");	
		send_state = 1;
		int			 orderId = 9999;
		COleDateTime time;
		CString		 timestr;
		time = COleDateTime::GetCurrentTime();
		timestr = time.Format("%Y-%m-%d %H:%M:%S");	
		
		//写入发送日志 
		//orderId为9999表示是单条发送的

		if (!pApp->m_pConnection.SaveSendMsg(orderId, timestr, send_state, strContent, m_no))
		{
			MessageBox("写入数据库失败,单条发送","提示");
		}
		//在列表控件中显示发送的信息
		CMyListView *myListView = (CMyListView *)pMainFrame->m_sp2_wnd.GetPane(0, 0);
		CListCtrl& ListCtrl = myListView->GetListCtrl();

		int nItemCount = ListCtrl.GetItemCount();
		if(nItemCount >= 200)
		{
			ListCtrl.DeleteItem(0);
			nItemCount--;
		}		
		// 插入新消息
		ListCtrl.InsertItem(nItemCount, m_no);
		ListCtrl.SetItemText(nItemCount, 1, timestr);
		ListCtrl.SetItemText(nItemCount, 2, strContent);
		ListCtrl.SetItemText(nItemCount, 3, "发送成功");

		m_no.Empty();
		m_msg.Empty();
		UpdateData(FALSE);
	}	
}

⌨️ 快捷键说明

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