addindent.cpp

来自「短信猫: 1确认短信Modem未连接电源」· C++ 代码 · 共 247 行

CPP
247
字号
// AddIndent.cpp : implementation file
//

#include "stdafx.h"
#include "短信群发.h"
#include "AddIndent.h"
#include "into.h"
#include "IndentDialog.h"

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

/////////////////////////////////////////////////////////////////////////////
// CAddIndent dialog


CAddIndent::CAddIndent(CWnd* pParent /*=NULL*/)
	: CDialog(CAddIndent::IDD, pParent)
{
	//{{AFX_DATA_INIT(CAddIndent)
	m_startTime = COleDateTime::GetCurrentTime();
	m_startDay = COleDateTime::GetCurrentTime();
	m_endDay = COleDateTime::GetCurrentTime();
	m_endTime = COleDateTime::GetCurrentTime();
	m_strMessage = _T("");
	m_id=0;
	m_strArr.RemoveAll();
	//}}AFX_DATA_INIT
}


void CAddIndent::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAddIndent)
	DDX_DateTimeCtrl(pDX, IDC_STARTTIME, m_startTime);
	DDX_DateTimeCtrl(pDX, IDC_STARTDAY, m_startDay);
	DDX_DateTimeCtrl(pDX, IDC_ENDDAY, m_endDay);
	DDX_DateTimeCtrl(pDX, IDC_ENDTIME, m_endTime);
	DDX_Text(pDX, IDC_MESSAGE_EDIT, m_strMessage);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CAddIndent, CDialog)
	//{{AFX_MSG_MAP(CAddIndent)
	ON_BN_CLICKED(IDC_ADD_INDENT, OnAddIndent)
	ON_BN_CLICKED(IDC_INTRODUCEPHONE, OnIntroducephone)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CAddIndent message handlers

void CAddIndent::OnAddIndent() 
{
	BOOL ret;
	CADORecordset record1,record2;
	int id;
	CString strBeginDay  = _T("");
	CString strBeginTime = _T("");
	CString strEndDay    = _T("");
	CString strEndTime   = _T("");
	CString strStartTime = _T("");
	CString strOverTime  = _T("");
	CString strSql       = _T("");

	UpdateData(TRUE);
	ret=pub.LengthCheck2(m_strMessage,140);
	if(!ret)
	{
		AfxMessageBox("短信的长度最大为140 !");
		return;
	}
	if(m_strMessage.IsEmpty())
	{
		AfxMessageBox("信息内容是空!");
		return;
	}
	ret=pub.TimeCheck(m_startDay,m_endDay);
	if(ret)
	{
		if (m_endDay==m_startDay)
		{
			ret=pub.TimeCheck(m_startTime,m_endTime);
			if (!ret)
			{
				return;
			}
		}
	}
	else
	{
		return;
	}
	if (!m_strArr.GetSize())
	{
		AfxMessageBox("号码没有被导入!");
		return;
	}

	strBeginDay  = m_startDay.Format("%Y-%m-%d");
	strBeginTime = m_startTime.Format("%H:%M");
	strEndDay    = m_endDay.Format("%Y-%m-%d");
	strEndTime   = m_endTime.Format("%H:%M");

	strStartTime.Format("'%s %s' , 'yyyy-mm-dd hh24:mi:ss' ",strBeginDay,strBeginTime);
	strOverTime.Format("'%s %s' , 'yyyy-mm-dd hh24:mi:ss' ",strEndDay,strEndTime);
	
	m_id=pub.GetMaxID("ORDERS")+1;

	strSql.Format("insert into ORDERS (ID, ORDERSTART, ORDEREND, CONTENT) values (%d, to_date(%s), to_date(%s), '%s' )",m_id,strStartTime,strOverTime,m_strMessage);

	ret=record1.Open(db.m_pConnection,strSql,0);
	if(ret)
	{
		m_strMessage.Empty();
		UpdateData(FALSE);
		CIndentDialog * theIndent=(CIndentDialog *) GetParent()->GetParent();
		theIndent->printList();
	}
	else
	{
		AfxMessageBox("更新数据失败!");
		m_strArr.RemoveAll();
		return;
	}
	record1.Close();

	id=pub.GetMaxID("PHONENUMBER")+1;
	ret=record2.Open(db.m_pConnection,"PHONENUMBER",CADORecordset::openTable);
	if (ret)
	{
		for(int i=0;i<m_strArr.GetSize();i++)
		{
			record2.AddNew();
			record2.SetFieldValue("ID",id);
			record2.SetFieldValue("ORDERID",m_id);
			record2.SetFieldValue("V_NUMBER",m_strArr.GetAt(i));
			id++;
			ret=record2.Update();
		}
		if (!ret)
		{
			int id1;
			AfxMessageBox("更新数据失败!");
			if(record1.Open(db.m_pConnection,"ORDERS",CADORecordset::openTable));
			{
				while(!record1.IsEof())
				{
					record1.GetFieldValue("ID",id1);
					if(id1==m_id)
					{
						record1.Delete();
						record1.Update();
						break;
					}
					record1.MoveNext();
				}
			}
			record1.Close();
			record2.Close();
			return;
		}

	}
	record2.Close();
	AfxMessageBox("添加订单成功!");
	m_strArr.RemoveAll();

}


void CAddIndent::OnIntroducephone() 
{
	        CFile fp;
			  int count1=0;
	          int count2=0;
			  int ID;
 	         BOOL ret;
	CADORecordset record;
	
	m_strArr.RemoveAll();
	CFileDialog inputDLG(TRUE);
	inputDLG.m_ofn.lpstrDefExt ="*.txt"; 
	inputDLG.m_ofn.lpstrTitle = "导入电话号码";
	inputDLG.m_ofn.lpstrFilter = "*.txt\0*.txt\0\0";
	if (IDOK==inputDLG.DoModal())
	{
		CString filename = inputDLG.GetPathName();
		
		if(!fp.Open(filename,CFile::modeRead))
		{
			AfxMessageBox("打开文件失败!");
			return ;
		}
		int fsize = fp.GetLength()+1;
		CString strText,strTaken;
		strText.GetBufferSetLength(fsize);
		fp.Read(strText.GetBuffer(0),fsize);
		fp.Close();
		strTaken = (CString)(strtok(strText.GetBuffer(0),"\r\n"));
		strTaken.TrimLeft(" ");
		strTaken.TrimRight(" ");
		CString str("input phone number");
		if(strncmp(strTaken ,str, str.GetLength())!=0)
		{
			AfxMessageBox("导入的号码文件有误");
			return;
		}

		while(1)
		{
			strTaken = CString(strtok(NULL,"\r\n"));
			strTaken.TrimLeft(" ");
			strTaken.TrimRight(" ");
			if(strTaken!="end of input phone number")
			{
				if (strTaken.IsEmpty())
				{
					continue;
				}
				else
				{
					count1++;
					if(pub.PhoneCheck1(strTaken))
					{
						m_strArr.Add(strTaken);
						count2++;
					}
				}
			}
			else
			{
				break;
			}
		}
		CString str1;
		str1.Format("查找%d个记录,其中有效电话号码是%d个,导入电话号码%d个 ",count1,count2,count2);
		AfxMessageBox(str1);
		
	}
}

⌨️ 快捷键说明

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