SendMsgDlg.cpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444
  1. // SendMsgDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "ylgl.h"
  5. #include "SendMsgDlg.h"
  6. #include "SelMsgContent.h"
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #undef THIS_FILE
  10. static char THIS_FILE[] = __FILE__;
  11. #endif
  12. /////////////////////////////////////////////////////////////////////////////
  13. // SendMsgDlg dialog IDC_EDT_RECV_MOBI
  14. SendMsgDlg::SendMsgDlg(CWnd* pParent /*=NULL*/)
  15. : CDialog(SendMsgDlg::IDD, pParent)
  16. {
  17. //{{AFX_DATA_INIT(SendMsgDlg)
  18. m_strRecvMobi = _T("");
  19. m_strSendSms = _T("");
  20. m_mobicount = 0;
  21. m_nMobile=0;
  22. m_nPhone=0;
  23. m_count = 0;
  24. m_radio = 0;
  25. m_mode=0;
  26. m_sendmode=0;
  27. m_pIdArray=NULL;
  28. //}}AFX_DATA_INIT
  29. }
  30. void SendMsgDlg::DoDataExchange(CDataExchange* pDX)
  31. {
  32. CDialog::DoDataExchange(pDX);
  33. //{{AFX_DATA_MAP(SendMsgDlg)
  34. DDX_Radio(pDX, IDC_RADIO1, m_radio);
  35. DDX_Text(pDX, IDC_EDT_RECV_MOBI, m_strRecvMobi);
  36. DDX_Text(pDX, IDC_EDT_SMS, m_strSendSms);
  37. DDX_Text(pDX, IDC_EDT_NUM, m_mobicount);
  38. DDV_MaxChars(pDX, m_strSendSms, 2000);
  39. //}}AFX_DATA_MAP
  40. }
  41. BEGIN_MESSAGE_MAP(SendMsgDlg, CDialog)
  42. //{{AFX_MSG_MAP(SendMsgDlg)
  43. ON_EN_CHANGE(IDC_EDT_SMS, OnChangeEdtSms)
  44. ON_BN_CLICKED(IDC_RADIO1, OnRadio1)
  45. ON_BN_CLICKED(IDC_RADIO2, OnRadio2)
  46. ON_BN_CLICKED(IDC_RADIO9, OnRadio9)
  47. ON_BN_CLICKED(IDC_BUTclose, OnBUTclose)
  48. ON_BN_CLICKED(IDC_BTN_SEND, OnBtnSend)
  49. ON_BN_CLICKED(IDC_BTN_Sel, OnBtnSel)
  50. //}}AFX_MSG_MAP
  51. END_MESSAGE_MAP()
  52. /////////////////////////////////////////////////////////////////////////////
  53. // SendMsgDlg message handlers
  54. BOOL SendMsgDlg::OnInitDialog()
  55. {
  56. CDialog::OnInitDialog();
  57. #ifdef CHILD_VERSION
  58. GetDlgItem(IDC_RADIO1)->ShowWindow(SW_HIDE);
  59. GetDlgItem(IDC_RADIO2)->ShowWindow(SW_HIDE);
  60. GetDlgItem(IDC_RADIO9)->ShowWindow(SW_HIDE);
  61. #endif
  62. if(IsHasRights2new(38) || IsHasRights2new(49))
  63. {
  64. GetDlgItem(IDC_BTN_SEND)->EnableWindow(1);
  65. }
  66. else
  67. GetDlgItem(IDC_BTN_SEND)->EnableWindow(0);
  68. // TODO: Add extra initialization here
  69. if(m_mode==1 || m_mode==2)
  70. {
  71. if(m_mode==1)
  72. SetWindowText("短信发送");
  73. else
  74. SetWindowText("意向客户短信发送");
  75. GetDlgItem(IDC_RADIO1)->ShowWindow(SW_HIDE);
  76. GetDlgItem(IDC_RADIO2)->ShowWindow(SW_HIDE);
  77. GetDlgItem(IDC_RADIO9)->ShowWindow(SW_HIDE);
  78. m_strRecvMobi = _T("");
  79. m_mobicount = 0;
  80. CString str,temp;
  81. int pos;
  82. m_nMobile=0;
  83. m_nPhone=0;
  84. BOOL bExist=0;
  85. for(int i=0; i<m_pArray->GetSize (); i++)
  86. {
  87. temp=m_pArray->ElementAt (i);
  88. if(m_strRecvMobi.Find (temp)!=-1)
  89. {
  90. bExist=1;
  91. continue;
  92. }
  93. if(CheckPhoneType(temp)==0 || CheckPhoneType(temp)==1 || CheckPhoneType(temp)==2)
  94. m_nMobile++;
  95. else if(CheckPhoneType(temp)==3)
  96. m_nPhone++;
  97. else
  98. {
  99. #ifndef CHILD_VERSION
  100. AfxMessageBox("号码"+temp+"不是正确的电话号码!", MB_ICONSTOP);
  101. #endif
  102. continue;
  103. }
  104. m_strRecvMobi+=temp;
  105. m_strRecvMobi+=",";
  106. m_mobicount++;
  107. }
  108. if(bExist)AfxMessageBox("选中的号码中有重复的号码, 重复的号码已被忽略!");
  109. m_strRecvMobi.TrimRight (",");
  110. UpdateData(false);
  111. OnChangeEdtSms();
  112. }
  113. else
  114. OnRadio1();
  115. return TRUE; // return TRUE unless you set the focus to a control
  116. // EXCEPTION: OCX Property Pages should return FALSE
  117. }
  118. void SendMsgDlg::OnChangeEdtSms()
  119. {
  120. // TODO: If this is a RICHEDIT control, the control will not
  121. // send this notification unless you override the CDialog::OnInitDialog()
  122. // function and call CRichEditCtrl().SetEventMask()
  123. // with the ENM_CHANGE flag ORed into the mask.
  124. UpdateData();
  125. m_strSendSms.Replace ("'", "'");
  126. m_strSendSms.Replace ("(", "(");
  127. m_strSendSms.Replace (")", ")");
  128. UpdateData(false);
  129. CString str;
  130. int count=0;
  131. int leng=GetLengthEx(m_strSendSms);
  132. if(m_nMobile)
  133. {
  134. count+=m_nMobile*(leng/MSG_LENGTH);
  135. if(leng%MSG_LENGTH)
  136. count+=m_nMobile;
  137. }
  138. if(m_nPhone)
  139. {
  140. count+=m_nPhone*(leng/56);
  141. if(leng%56)
  142. count+=m_nPhone;
  143. }
  144. m_count=count;
  145. str.Format ("短信内容(手机%d字/条,小灵通56字/条)(现%d字,共%d条短信)", MSG_LENGTH, leng,count);
  146. GetDlgItem(IDC_STATIC2)->SetWindowText(str);
  147. CRect rc;
  148. GetDlgItem(IDC_STATIC2)->GetWindowRect (rc);
  149. ScreenToClient(rc);
  150. InvalidateRect(rc);
  151. // TODO: Add your control notification handler code hereds
  152. }
  153. void SendMsgDlg::OnRadio1()
  154. {
  155. // TODO: Add your control notification handler code here
  156. UpdateData();
  157. m_strRecvMobi = _T("");
  158. m_mobicount = 0;
  159. CString str,temp;
  160. int pos;
  161. m_nMobile=0;
  162. m_nPhone=0;
  163. BOOL bExist=0;
  164. for(int i=0; i<m_pArray->GetSize (); i++)
  165. {
  166. temp=m_pArray->ElementAt (i);
  167. if(temp.IsEmpty ())continue;
  168. if(m_strRecvMobi.Find (temp)!=-1)
  169. {
  170. bExist=1;
  171. continue;
  172. }
  173. if(CheckPhoneType(temp)==0 || CheckPhoneType(temp)==1 || CheckPhoneType(temp)==2)
  174. m_nMobile++;
  175. else if(CheckPhoneType(temp)==3)
  176. m_nPhone++;
  177. else
  178. {
  179. #ifndef CHILD_VERSION
  180. AfxMessageBox("号码"+temp+"不是正确的电话号码!", MB_ICONSTOP);
  181. #endif
  182. continue;
  183. }
  184. if(m_radio==1 && i%2==0)continue;
  185. if(m_radio==2 && i%2 )continue;
  186. m_strRecvMobi+=temp;
  187. m_strRecvMobi+=",";
  188. m_mobicount++;
  189. }
  190. if(bExist)AfxMessageBox("选中的号码中有重复的号码, 重复的号码已被忽略!");
  191. m_strRecvMobi.TrimRight (",");
  192. UpdateData(false);
  193. OnChangeEdtSms();
  194. /* UpdateData();
  195. m_strRecvMobi = _T("");
  196. m_mobicount = 0;
  197. CString str,temp;
  198. int pos;
  199. m_nMobile=0;
  200. m_nPhone=0;
  201. BOOL bExist=0;
  202. CStringArray phonearray;
  203. if(m_radio==0)
  204. {
  205. if(!m_phone1.IsEmpty ())phonearray.Add (m_phone1);
  206. if(!m_phone2.IsEmpty ())phonearray.Add (m_phone2);
  207. }
  208. else if(m_radio==1)
  209. {
  210. if(!m_phone2.IsEmpty ())phonearray.Add (m_phone2);
  211. }
  212. else if(m_radio==2)
  213. {
  214. if(!m_phone1.IsEmpty ())phonearray.Add (m_phone1);
  215. }
  216. for(int i=0; i<phonearray.GetSize (); i++)
  217. {
  218. temp=phonearray.ElementAt (i);
  219. if(m_strRecvMobi.Find (temp)!=-1)
  220. {
  221. bExist=1;
  222. continue;
  223. }
  224. if(CheckPhoneType(temp)==0 || CheckPhoneType(temp)==1 || CheckPhoneType(temp)==2)
  225. m_nMobile++;
  226. else if(CheckPhoneType(temp)==3)
  227. m_nPhone++;
  228. else
  229. {
  230. AfxMessageBox("号码"+temp+"不是正确的电话号码!", MB_ICONSTOP);
  231. continue;
  232. }
  233. m_strRecvMobi+=temp;
  234. m_strRecvMobi+=",";
  235. m_mobicount++;
  236. }
  237. if(bExist)AfxMessageBox("选中的号码中有重复的号码, 重复的号码已被忽略!");
  238. m_strRecvMobi.TrimRight (",");
  239. UpdateData(false);
  240. OnChangeEdtSms();*/
  241. }
  242. void SendMsgDlg::OnRadio2()
  243. {
  244. // TODO: Add your control notification handler code here
  245. OnRadio1();
  246. }
  247. void SendMsgDlg::OnRadio9()
  248. {
  249. // TODO: Add your control notification handler code here
  250. OnRadio1();
  251. }
  252. void SendMsgDlg::OnBUTclose()
  253. {
  254. // TODO: Add your control notification handler code here
  255. CDialog::OnCancel ();
  256. }
  257. void SendMsgDlg::OnBtnSend() // 发送消息 按钮;
  258. {
  259. // TODO: Add your control notification handler code here
  260. if(!(IsHasRights2new(38) || IsHasRights2new(49)))return;
  261. UpdateData();
  262. if(CheckBadWords(m_strSendSms)==0 || CheckBadWords2(m_strSendSms)==0)
  263. {
  264. AfxMessageBox("信息服务商禁止的非法字符:("+g_temp+")希望您谅解!");
  265. return;
  266. }
  267. if(m_mobicount==0)
  268. {
  269. AfxMessageBox("手机号码不能为空!");
  270. return;
  271. }
  272. if(m_strSendSms.IsEmpty ())
  273. {
  274. AfxMessageBox("信息不能为空!");
  275. return;
  276. }
  277. #if JEFF_TEST_ON
  278. // 查询sendreg表是否存在该记录;
  279. #define SELECT_SENDREG _T("select count(*) as cot from sendreg where [content]='%s' and [phones] like '%%%s%%'")
  280. //#define INSERT_SENDREG _T("insert into sendreg([phones],[content],[timestamp],[msgcount],[status],[issended],[isautosend],[ren]) values ('%s','%s','%s','%s','%s','%s','%s','%s')")
  281. CString strSQL;
  282. CString timestamp = _T("msgtimestamp");
  283. INT_PTR nLen = 0;
  284. INT nPos = 0;
  285. INT nCount = 0;
  286. CString strPhones = m_strRecvMobi;
  287. // 1.短信内容+手机串 判断是否存在记录;
  288. // 无法逐个查询是否存在发送;只查询一个.
  289. strSQL.Format(SELECT_SENDREG, m_strSendSms,strPhones.Left(11));
  290. g_sendhead.bsql = 1;
  291. g_pMainWnd->ProcessChatMessageRequest2(strSQL);
  292. if (g_bSendOK == 0)return;
  293. if (g_ncount)
  294. if (AfxMessageBox("提醒:相似的信息已发送, 重复发送将再次收取短信费用, 继续吗?", MB_YESNO | MB_ICONINFORMATION) != IDYES)
  295. return;
  296. strSQL = _T("");
  297. // 2.再按每组100个写入数据库;
  298. CString strSend = _T("");
  299. CString strTempTime = _T("");
  300. CString strTempPhone = _T("");
  301. nLen = (strPhones.GetLength() + 1) / 12; // 计算出电话号码个数;
  302. CString strCount;
  303. strCount.Format("%d", m_count / nLen);
  304. if (nLen <= 100)
  305. {
  306. strSend.Format(INSERT_SENDREG, _T("0"),m_strRecvMobi, m_strSendSms, timestamp, strCount, _T("0"), _T("0"), _T("0"), g_user.name);
  307. strSQL = strSend;
  308. }
  309. else
  310. {
  311. int nIndex = 0;
  312. do
  313. {
  314. nPos = strPhones.Find(',');
  315. if (nPos != -1)
  316. {
  317. strTempPhone += strPhones.Left(nPos) + _T(",");
  318. strPhones.Delete(0, nPos + 1);
  319. if (++nCount == 100)
  320. {
  321. nCount = 0;
  322. strTempPhone.TrimRight(_T(","));
  323. strSend.Format(INSERT_SENDREG, _T("0"), strTempPhone, m_strSendSms, timestamp, strCount, _T("0"), _T("0"), _T("0"), g_user.name);
  324. if (strSQL.IsEmpty())
  325. strSQL += strSend;
  326. else
  327. strSQL += _T("***") + strSend;
  328. strTempPhone = _T("");
  329. }
  330. }
  331. else
  332. {
  333. nCount = 0;
  334. strTempPhone += strPhones;
  335. strSend.Format(INSERT_SENDREG,_T("0"), strTempPhone, m_strSendSms, timestamp, strCount, _T("0"), _T("0"), _T("0"), g_user.name);
  336. strSQL += _T("***") + strSend;
  337. break;
  338. }
  339. } while (1);
  340. }
  341. if (m_pIdArray && m_sendmode)
  342. {
  343. CString temp;
  344. if (m_sendmode == 1)
  345. strSQL += "***update dindan set [send1]='1' where ";
  346. else if (m_sendmode == 2)
  347. strSQL += "***update dindan set [send2]='1' where ";
  348. else if (m_sendmode == 3)
  349. strSQL += "***update dindan set [send3]='1' where ";
  350. else if (m_sendmode == 4)
  351. strSQL += "***update dindan set [send4]=1 where ";
  352. else if (m_sendmode == 5)
  353. strSQL += "***update dindan set [send5]=1 where ";
  354. for (int i = 0; i < m_pIdArray->GetSize(); i++)
  355. {
  356. temp.Format("[id]='%s' or ", m_pIdArray->ElementAt(i));
  357. strSQL += temp;
  358. }
  359. strSQL.TrimRight(" or ");
  360. }
  361. g_sendhead.bsql = 1;
  362. g_pMainWnd->ProcessChatMessageRequest2(strSQL);
  363. if (g_bSendOK == 0)return;
  364. #else
  365. // 以短信内容+手机串判断是否存在记录;
  366. CString str, timestamp;
  367. timestamp = "msgtimestamp";//CTime::GetCurrentTime ().Format ("%Y%m%d%H%M%S"); msgxxtimestamp
  368. //if(CheckExist(m_strSendSms,m_strRecvMobi))
  369. {
  370. CString sql = "select count(*) as cot from sendreg where [content]='" + m_strSendSms + "' and [phones]='" + m_strRecvMobi + "'";
  371. g_sendhead.bsql = 1;
  372. g_pMainWnd->ProcessChatMessageRequest2(sql);
  373. if (g_bSendOK == 0)return;
  374. if (g_ncount)
  375. if (AfxMessageBox("提醒:相似的信息已发送, 重复发送将再次收取短信费用, 继续吗?", MB_YESNO | MB_ICONINFORMATION) != IDYES)return;
  376. }
  377. CString scount;
  378. scount.Format("%d", m_count);
  379. 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 + "')";
  380. if (m_pIdArray && m_sendmode)
  381. {
  382. CString temp;
  383. if (m_sendmode == 1)
  384. sql += "***update dindan set [send1]='1' where ";
  385. else if (m_sendmode == 2)
  386. sql += "***update dindan set [send2]='1' where ";
  387. else if (m_sendmode == 3)
  388. sql += "***update dindan set [send3]='1' where ";
  389. else if (m_sendmode == 4)
  390. sql += "***update dindan set [send4]=1 where ";
  391. else if (m_sendmode == 5)
  392. sql += "***update dindan set [send5]=1 where ";
  393. for (int i = 0; i < m_pIdArray->GetSize(); i++)
  394. {
  395. temp.Format("[id]='%s' or ", m_pIdArray->ElementAt(i));
  396. sql += temp;
  397. }
  398. sql.TrimRight(" or ");
  399. }
  400. g_sendhead.bsql = 1;
  401. g_pMainWnd->ProcessChatMessageRequest2(sql);
  402. if (g_bSendOK == 0)return;
  403. #endif
  404. AfxMessageBox("发送成功! 请具体发送情况请查询发送记录!", MB_ICONINFORMATION);
  405. }
  406. void SendMsgDlg::OnBtnSel()
  407. {
  408. SelMsgContent dlg;
  409. if(dlg.DoModal ()!=IDOK)return;
  410. SetDlgItemText(IDC_EDT_SMS, dlg.m_content);
  411. OnChangeEdtSms();
  412. }