123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444 |
- // SendMsgDlg.cpp : implementation file
- //
- #include "stdafx.h"
- #include "ylgl.h"
- #include "SendMsgDlg.h"
- #include "SelMsgContent.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // SendMsgDlg dialog IDC_EDT_RECV_MOBI
- SendMsgDlg::SendMsgDlg(CWnd* pParent /*=NULL*/)
- : CDialog(SendMsgDlg::IDD, pParent)
- {
- //{{AFX_DATA_INIT(SendMsgDlg)
- m_strRecvMobi = _T("");
- m_strSendSms = _T("");
- m_mobicount = 0;
- m_nMobile=0;
- m_nPhone=0;
- m_count = 0;
- m_radio = 0;
- m_mode=0;
- m_sendmode=0;
- m_pIdArray=NULL;
- //}}AFX_DATA_INIT
- }
- void SendMsgDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(SendMsgDlg)
- DDX_Radio(pDX, IDC_RADIO1, m_radio);
- DDX_Text(pDX, IDC_EDT_RECV_MOBI, m_strRecvMobi);
- DDX_Text(pDX, IDC_EDT_SMS, m_strSendSms);
- DDX_Text(pDX, IDC_EDT_NUM, m_mobicount);
- DDV_MaxChars(pDX, m_strSendSms, 2000);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(SendMsgDlg, CDialog)
- //{{AFX_MSG_MAP(SendMsgDlg)
- ON_EN_CHANGE(IDC_EDT_SMS, OnChangeEdtSms)
- ON_BN_CLICKED(IDC_RADIO1, OnRadio1)
- ON_BN_CLICKED(IDC_RADIO2, OnRadio2)
- ON_BN_CLICKED(IDC_RADIO9, OnRadio9)
- ON_BN_CLICKED(IDC_BUTclose, OnBUTclose)
- ON_BN_CLICKED(IDC_BTN_SEND, OnBtnSend)
- ON_BN_CLICKED(IDC_BTN_Sel, OnBtnSel)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // SendMsgDlg message handlers
- BOOL SendMsgDlg::OnInitDialog()
- {
- CDialog::OnInitDialog();
- #ifdef CHILD_VERSION
- GetDlgItem(IDC_RADIO1)->ShowWindow(SW_HIDE);
- GetDlgItem(IDC_RADIO2)->ShowWindow(SW_HIDE);
- GetDlgItem(IDC_RADIO9)->ShowWindow(SW_HIDE);
- #endif
- if(IsHasRights2new(38) || IsHasRights2new(49))
- {
- GetDlgItem(IDC_BTN_SEND)->EnableWindow(1);
- }
- else
- GetDlgItem(IDC_BTN_SEND)->EnableWindow(0);
- // TODO: Add extra initialization here
- if(m_mode==1 || m_mode==2)
- {
- if(m_mode==1)
- SetWindowText("短信发送");
- else
- SetWindowText("意向客户短信发送");
- GetDlgItem(IDC_RADIO1)->ShowWindow(SW_HIDE);
- GetDlgItem(IDC_RADIO2)->ShowWindow(SW_HIDE);
- GetDlgItem(IDC_RADIO9)->ShowWindow(SW_HIDE);
- m_strRecvMobi = _T("");
- m_mobicount = 0;
- CString str,temp;
- int pos;
- m_nMobile=0;
- m_nPhone=0;
- BOOL bExist=0;
- for(int i=0; i<m_pArray->GetSize (); i++)
- {
- temp=m_pArray->ElementAt (i);
- if(m_strRecvMobi.Find (temp)!=-1)
- {
- bExist=1;
- continue;
- }
- if(CheckPhoneType(temp)==0 || CheckPhoneType(temp)==1 || CheckPhoneType(temp)==2)
- m_nMobile++;
- else if(CheckPhoneType(temp)==3)
- m_nPhone++;
- else
- {
- #ifndef CHILD_VERSION
- AfxMessageBox("号码"+temp+"不是正确的电话号码!", MB_ICONSTOP);
- #endif
- continue;
- }
- m_strRecvMobi+=temp;
- m_strRecvMobi+=",";
- m_mobicount++;
- }
- if(bExist)AfxMessageBox("选中的号码中有重复的号码, 重复的号码已被忽略!");
- m_strRecvMobi.TrimRight (",");
- UpdateData(false);
- OnChangeEdtSms();
- }
- else
- OnRadio1();
- return TRUE; // return TRUE unless you set the focus to a control
- // EXCEPTION: OCX Property Pages should return FALSE
- }
- void SendMsgDlg::OnChangeEdtSms()
- {
- // TODO: If this is a RICHEDIT control, the control will not
- // send this notification unless you override the CDialog::OnInitDialog()
- // function and call CRichEditCtrl().SetEventMask()
- // with the ENM_CHANGE flag ORed into the mask.
- UpdateData();
- m_strSendSms.Replace ("'", "'");
- m_strSendSms.Replace ("(", "(");
- m_strSendSms.Replace (")", ")");
- UpdateData(false);
- CString str;
- int count=0;
- int leng=GetLengthEx(m_strSendSms);
- if(m_nMobile)
- {
- count+=m_nMobile*(leng/MSG_LENGTH);
- if(leng%MSG_LENGTH)
- count+=m_nMobile;
- }
- if(m_nPhone)
- {
- count+=m_nPhone*(leng/56);
- if(leng%56)
- count+=m_nPhone;
- }
- m_count=count;
- str.Format ("短信内容(手机%d字/条,小灵通56字/条)(现%d字,共%d条短信)", MSG_LENGTH, leng,count);
- GetDlgItem(IDC_STATIC2)->SetWindowText(str);
- CRect rc;
- GetDlgItem(IDC_STATIC2)->GetWindowRect (rc);
- ScreenToClient(rc);
- InvalidateRect(rc);
- // TODO: Add your control notification handler code hereds
- }
- void SendMsgDlg::OnRadio1()
- {
- // TODO: Add your control notification handler code here
- UpdateData();
- m_strRecvMobi = _T("");
- m_mobicount = 0;
- CString str,temp;
- int pos;
- m_nMobile=0;
- m_nPhone=0;
- BOOL bExist=0;
- for(int i=0; i<m_pArray->GetSize (); i++)
- {
- temp=m_pArray->ElementAt (i);
- if(temp.IsEmpty ())continue;
- if(m_strRecvMobi.Find (temp)!=-1)
- {
- bExist=1;
- continue;
- }
- if(CheckPhoneType(temp)==0 || CheckPhoneType(temp)==1 || CheckPhoneType(temp)==2)
- m_nMobile++;
- else if(CheckPhoneType(temp)==3)
- m_nPhone++;
- else
- {
- #ifndef CHILD_VERSION
- AfxMessageBox("号码"+temp+"不是正确的电话号码!", MB_ICONSTOP);
- #endif
- continue;
- }
- if(m_radio==1 && i%2==0)continue;
- if(m_radio==2 && i%2 )continue;
- m_strRecvMobi+=temp;
- m_strRecvMobi+=",";
- m_mobicount++;
- }
- if(bExist)AfxMessageBox("选中的号码中有重复的号码, 重复的号码已被忽略!");
- m_strRecvMobi.TrimRight (",");
- UpdateData(false);
- OnChangeEdtSms();
- /* UpdateData();
- m_strRecvMobi = _T("");
- m_mobicount = 0;
- CString str,temp;
- int pos;
- m_nMobile=0;
- m_nPhone=0;
- BOOL bExist=0;
- CStringArray phonearray;
- if(m_radio==0)
- {
- if(!m_phone1.IsEmpty ())phonearray.Add (m_phone1);
- if(!m_phone2.IsEmpty ())phonearray.Add (m_phone2);
- }
- else if(m_radio==1)
- {
- if(!m_phone2.IsEmpty ())phonearray.Add (m_phone2);
- }
- else if(m_radio==2)
- {
- if(!m_phone1.IsEmpty ())phonearray.Add (m_phone1);
- }
- for(int i=0; i<phonearray.GetSize (); i++)
- {
- temp=phonearray.ElementAt (i);
- if(m_strRecvMobi.Find (temp)!=-1)
- {
- bExist=1;
- continue;
- }
- if(CheckPhoneType(temp)==0 || CheckPhoneType(temp)==1 || CheckPhoneType(temp)==2)
- m_nMobile++;
- else if(CheckPhoneType(temp)==3)
- m_nPhone++;
- else
- {
- AfxMessageBox("号码"+temp+"不是正确的电话号码!", MB_ICONSTOP);
- continue;
- }
- m_strRecvMobi+=temp;
- m_strRecvMobi+=",";
- m_mobicount++;
- }
- if(bExist)AfxMessageBox("选中的号码中有重复的号码, 重复的号码已被忽略!");
- m_strRecvMobi.TrimRight (",");
- UpdateData(false);
- OnChangeEdtSms();*/
- }
- void SendMsgDlg::OnRadio2()
- {
- // TODO: Add your control notification handler code here
- OnRadio1();
- }
- void SendMsgDlg::OnRadio9()
- {
- // TODO: Add your control notification handler code here
- OnRadio1();
- }
- void SendMsgDlg::OnBUTclose()
- {
- // TODO: Add your control notification handler code here
- CDialog::OnCancel ();
- }
- void SendMsgDlg::OnBtnSend() // 发送消息 按钮;
- {
- // TODO: Add your control notification handler code here
- if(!(IsHasRights2new(38) || IsHasRights2new(49)))return;
- UpdateData();
- if(CheckBadWords(m_strSendSms)==0 || CheckBadWords2(m_strSendSms)==0)
- {
- AfxMessageBox("信息服务商禁止的非法字符:("+g_temp+")希望您谅解!");
- return;
- }
- if(m_mobicount==0)
- {
- AfxMessageBox("手机号码不能为空!");
- return;
- }
- if(m_strSendSms.IsEmpty ())
- {
- AfxMessageBox("信息不能为空!");
- return;
- }
- #if JEFF_TEST_ON
- // 查询sendreg表是否存在该记录;
- #define SELECT_SENDREG _T("select count(*) as cot from sendreg where [content]='%s' and [phones] like '%%%s%%'")
- //#define INSERT_SENDREG _T("insert into sendreg([phones],[content],[timestamp],[msgcount],[status],[issended],[isautosend],[ren]) values ('%s','%s','%s','%s','%s','%s','%s','%s')")
- CString strSQL;
- CString timestamp = _T("msgtimestamp");
- INT_PTR nLen = 0;
- INT nPos = 0;
- INT nCount = 0;
- CString strPhones = m_strRecvMobi;
- // 1.短信内容+手机串 判断是否存在记录;
- // 无法逐个查询是否存在发送;只查询一个.
- strSQL.Format(SELECT_SENDREG, m_strSendSms,strPhones.Left(11));
- g_sendhead.bsql = 1;
- g_pMainWnd->ProcessChatMessageRequest2(strSQL);
- if (g_bSendOK == 0)return;
- if (g_ncount)
- if (AfxMessageBox("提醒:相似的信息已发送, 重复发送将再次收取短信费用, 继续吗?", MB_YESNO | MB_ICONINFORMATION) != IDYES)
- return;
- strSQL = _T("");
- // 2.再按每组100个写入数据库;
- CString strSend = _T("");
- CString strTempTime = _T("");
- CString strTempPhone = _T("");
- nLen = (strPhones.GetLength() + 1) / 12; // 计算出电话号码个数;
- CString strCount;
- strCount.Format("%d", m_count / nLen);
- if (nLen <= 100)
- {
- strSend.Format(INSERT_SENDREG, _T("0"),m_strRecvMobi, m_strSendSms, timestamp, strCount, _T("0"), _T("0"), _T("0"), g_user.name);
- strSQL = strSend;
- }
- else
- {
- int nIndex = 0;
- do
- {
- nPos = strPhones.Find(',');
- if (nPos != -1)
- {
- strTempPhone += strPhones.Left(nPos) + _T(",");
- strPhones.Delete(0, nPos + 1);
- if (++nCount == 100)
- {
- nCount = 0;
- strTempPhone.TrimRight(_T(","));
- strSend.Format(INSERT_SENDREG, _T("0"), strTempPhone, m_strSendSms, timestamp, strCount, _T("0"), _T("0"), _T("0"), g_user.name);
- if (strSQL.IsEmpty())
- strSQL += strSend;
- else
- strSQL += _T("***") + strSend;
- strTempPhone = _T("");
- }
- }
- else
- {
- nCount = 0;
- strTempPhone += strPhones;
- strSend.Format(INSERT_SENDREG,_T("0"), strTempPhone, m_strSendSms, timestamp, strCount, _T("0"), _T("0"), _T("0"), g_user.name);
- strSQL += _T("***") + strSend;
- break;
- }
- } while (1);
- }
- if (m_pIdArray && m_sendmode)
- {
- CString temp;
- if (m_sendmode == 1)
- strSQL += "***update dindan set [send1]='1' where ";
- else if (m_sendmode == 2)
- strSQL += "***update dindan set [send2]='1' where ";
- else if (m_sendmode == 3)
- strSQL += "***update dindan set [send3]='1' where ";
- else if (m_sendmode == 4)
- strSQL += "***update dindan set [send4]=1 where ";
- else if (m_sendmode == 5)
- strSQL += "***update dindan set [send5]=1 where ";
- for (int i = 0; i < m_pIdArray->GetSize(); i++)
- {
- temp.Format("[id]='%s' or ", m_pIdArray->ElementAt(i));
- strSQL += temp;
- }
- strSQL.TrimRight(" or ");
- }
- g_sendhead.bsql = 1;
- g_pMainWnd->ProcessChatMessageRequest2(strSQL);
- if (g_bSendOK == 0)return;
- #else
- // 以短信内容+手机串判断是否存在记录;
- CString str, timestamp;
- timestamp = "msgtimestamp";//CTime::GetCurrentTime ().Format ("%Y%m%d%H%M%S"); msgxxtimestamp
- //if(CheckExist(m_strSendSms,m_strRecvMobi))
- {
- CString sql = "select count(*) as cot from sendreg where [content]='" + m_strSendSms + "' and [phones]='" + m_strRecvMobi + "'";
- g_sendhead.bsql = 1;
- g_pMainWnd->ProcessChatMessageRequest2(sql);
- if (g_bSendOK == 0)return;
- if (g_ncount)
- if (AfxMessageBox("提醒:相似的信息已发送, 重复发送将再次收取短信费用, 继续吗?", MB_YESNO | MB_ICONINFORMATION) != IDYES)return;
- }
- CString scount;
- scount.Format("%d", m_count);
- CString sql = "insert into sendreg([phones],[content],[timestamp],[msgcount],[status],[issended],[isautosend],[ren]) values('" + m_strRecvMobi + "','" + m_strSendSms + "','" + timestamp + "','" + scount + "','0','0','0','" + g_user.name + "')";
- if (m_pIdArray && m_sendmode)
- {
- CString temp;
- if (m_sendmode == 1)
- sql += "***update dindan set [send1]='1' where ";
- else if (m_sendmode == 2)
- sql += "***update dindan set [send2]='1' where ";
- else if (m_sendmode == 3)
- sql += "***update dindan set [send3]='1' where ";
- else if (m_sendmode == 4)
- sql += "***update dindan set [send4]=1 where ";
- else if (m_sendmode == 5)
- sql += "***update dindan set [send5]=1 where ";
- for (int i = 0; i < m_pIdArray->GetSize(); i++)
- {
- temp.Format("[id]='%s' or ", m_pIdArray->ElementAt(i));
- sql += temp;
- }
- sql.TrimRight(" or ");
- }
- g_sendhead.bsql = 1;
- g_pMainWnd->ProcessChatMessageRequest2(sql);
- if (g_bSendOK == 0)return;
- #endif
- AfxMessageBox("发送成功! 请具体发送情况请查询发送记录!", MB_ICONINFORMATION);
- }
- void SendMsgDlg::OnBtnSel()
- {
- SelMsgContent dlg;
- if(dlg.DoModal ()!=IDOK)return;
- SetDlgItemText(IDC_EDT_SMS, dlg.m_content);
- OnChangeEdtSms();
- }
|