SendMsg.cpp 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545
  1. // SendMsg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "ylgl.h"
  5. #include "SendMsg.h"
  6. #include "MyMdi.H"
  7. #include "GetPhone.h"
  8. #include "GetPhoneAge.h"
  9. #include "SelMsgContent.h"
  10. #include "InputPhones.h"
  11. #ifdef _DEBUG
  12. #define new DEBUG_NEW
  13. #undef THIS_FILE
  14. static char THIS_FILE[] = __FILE__;
  15. #endif
  16. /////////////////////////////////////////////////////////////////////////////
  17. // SendMsg IDC_LIST1
  18. IMPLEMENT_DYNCREATE(SendMsg, MyFormView)
  19. SendMsg::SendMsg()
  20. : MyFormView(SendMsg::IDD)
  21. {
  22. //{{AFX_DATA_INIT(SendMsg)
  23. m_strRecvMobi = _T("");
  24. m_strSendSms = _T("");
  25. m_mobicount = 0;
  26. m_nMobile=0;
  27. m_nPhone=0;
  28. m_count = 0;
  29. //}}AFX_DATA_INIT
  30. g_nYearposTemp=g_nYearpos;
  31. }
  32. SendMsg::~SendMsg()
  33. {
  34. g_nYearpos=g_nYearposTemp;
  35. }
  36. void SendMsg::DoDataExchange(CDataExchange* pDX)
  37. {
  38. MyFormView::DoDataExchange(pDX);
  39. //{{AFX_DATA_MAP(SendMsg)
  40. DDX_Control(pDX, IDC_LIST1, m_List1);
  41. DDX_Control(pDX, IDC_STATIC1, m_static1);
  42. DDX_Text(pDX, IDC_EDT_RECV_MOBI, m_strRecvMobi);
  43. DDX_Text(pDX, IDC_EDT_SMS, m_strSendSms);
  44. DDX_Text(pDX, IDC_EDT_NUM, m_mobicount);
  45. //}}AFX_DATA_MAP
  46. }
  47. // DDV_MaxChars(pDX, m_strSendSms, 2000);
  48. BEGIN_MESSAGE_MAP(SendMsg, MyFormView)
  49. //{{AFX_MSG_MAP(SendMsg)
  50. ON_BN_CLICKED(IDC_BUTclose, OnBUTclose)
  51. ON_BN_CLICKED(IDC_BTN_SEND, OnBtnSend)
  52. ON_BN_CLICKED(IDC_BTN_Sel, OnBtnSel)
  53. ON_EN_CHANGE(IDC_EDT_SMS, OnChangeEdtSms)
  54. ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
  55. ON_BN_CLICKED(IDC_BUTTON5, OnButton5)
  56. ON_BN_CLICKED(IDC_BUTTON3, OnSelAll)
  57. ON_BN_CLICKED(IDC_BUTTON4, OnReset)
  58. ON_LBN_SELCHANGE(IDC_LIST1, OnSelchangeList1)
  59. ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
  60. ON_BN_CLICKED(IDC_BUTTON6, OnButton6)
  61. //}}AFX_MSG_MAP
  62. END_MESSAGE_MAP()
  63. /////////////////////////////////////////////////////////////////////////////
  64. // SendMsg diagnostics
  65. #ifdef _DEBUG
  66. void SendMsg::AssertValid() const
  67. {
  68. MyFormView::AssertValid();
  69. }
  70. void SendMsg::Dump(CDumpContext& dc) const
  71. {
  72. MyFormView::Dump(dc);
  73. }
  74. #endif //_DEBUG
  75. /////////////////////////////////////////////////////////////////////////////
  76. // SendMsg message handlers
  77. void SendMsg::OnInitialUpdate()
  78. {
  79. MyFormView::OnInitialUpdate();
  80. // TODO: Add your specialized code here and/or call the base class
  81. CMyMdi Mdi;
  82. Mdi.SetSubView((CWnd*)GetParent(), (CWnd*)this);
  83. // Here we create the outbar control using the splitter as its parent
  84. // and setting its id to the first pane.
  85. CRect rc2;
  86. GetWindowRect(rc2);
  87. ::MoveWindow(m_hWnd,g_rc.left,g_rc.top,g_rc.Width(),g_rc.Height(),TRUE);
  88. EnumChildWindows(m_hWnd,(WNDENUMPROC)EnumChildProc,0);
  89. m_static1.SetFont (&g_titlefont);
  90. if(IsHasRights2new(38) || IsHasRights2new(49))
  91. {
  92. GetDlgItem(IDC_BTN_SEND)->EnableWindow(1);
  93. }
  94. else
  95. GetDlgItem(IDC_BTN_SEND)->EnableWindow(0);
  96. #ifndef CHILD_VERSION
  97. GetDlgItem(IDC_BUTTON6)->ShowWindow(0);
  98. #endif
  99. }
  100. void SendMsg::OnBUTclose()
  101. {
  102. // TODO: Add your control notification handler code here
  103. GetParent()->SendMessage(WM_CLOSE);
  104. }
  105. BOOL SendMsg::PreTranslateMessage(MSG* pMsg)
  106. {
  107. // TODO: Add your specialized code here and/or call the base class
  108. try
  109. {
  110. if(pMsg->message==WM_KEYDOWN)
  111. {
  112. switch (pMsg->wParam)
  113. {
  114. case 0x43: // copy
  115. if ( ( GetKeyState( VK_CONTROL ) & 0x80 ) )
  116. {
  117. GetFocus()->SendMessage(WM_COPY);
  118. return TRUE;
  119. }
  120. break;
  121. case 0x56: //Ctrl + V:
  122. if ( ( GetKeyState( VK_CONTROL ) & 0x80 ) )
  123. {
  124. GetFocus()->SendMessage(WM_PASTE);
  125. return TRUE;
  126. }
  127. break;
  128. case 0x58: // cut
  129. if ( ( GetKeyState( VK_CONTROL ) & 0x80 ) )
  130. {
  131. GetFocus()->SendMessage(WM_CUT);
  132. return TRUE;
  133. }
  134. break;
  135. case 0x5A: //undo
  136. case 0x59: //redo
  137. if ( ( GetKeyState( VK_CONTROL ) & 0x80 ) )
  138. {
  139. GetFocus()->SendMessage(WM_UNDO);
  140. return TRUE;
  141. }
  142. break;
  143. }
  144. }
  145. return MyFormView::PreTranslateMessage(pMsg);
  146. }
  147. catch(...)
  148. {
  149. }
  150. return TRUE;
  151. }
  152. void SendMsg::OnChangeEdtSms()
  153. {
  154. // TODO: If this is a RICHEDIT control, the control will not
  155. // send this notification unless you override the MyFormView::OnInitDialog()
  156. // function and call CRichEditCtrl().SetEventMask()
  157. // with the ENM_CHANGE flag ORed into the mask.
  158. UpdateData();
  159. m_strSendSms.Replace ("'", "'");
  160. m_strSendSms.Replace ("(", "(");
  161. m_strSendSms.Replace (")", ")");
  162. UpdateData(false);
  163. CString str;
  164. int count=0;
  165. int leng=GetLengthEx(m_strSendSms);
  166. if(m_nMobile)
  167. {
  168. count+=m_nMobile*(leng/MSG_LENGTH);
  169. if(leng%MSG_LENGTH)
  170. count+=m_nMobile;
  171. }
  172. if(m_nPhone)
  173. {
  174. count+=m_nPhone*(leng/56);
  175. if(leng%56)
  176. count+=m_nPhone;
  177. }
  178. m_count=count;
  179. str.Format ("短信内容(手机%d字/条,小灵通56字/条)(现%d字,共%d条短信)", MSG_LENGTH,leng,count);
  180. GetDlgItem(IDC_STATIC2)->SetWindowText(str);
  181. CRect rc;
  182. GetDlgItem(IDC_STATIC2)->GetWindowRect (rc);
  183. ScreenToClient(rc);
  184. InvalidateRect(rc);
  185. // TODO: Add your control notification handler code here
  186. }
  187. void SendMsg::OnButton2() // 筛选按钮;
  188. {
  189. // TODO: Add your control notification handler code here
  190. CStringArray array;
  191. GetPhone dlg;
  192. dlg.m_pArray=&array;
  193. dlg.m_pArray2=&m_selitemarray;
  194. m_selitemarray.RemoveAll();
  195. if(dlg.DoModal()!=IDOK)
  196. return;
  197. CString str,temp;
  198. BOOL exist;
  199. int pos;
  200. for(int i=0; i<array.GetSize (); i+=2)
  201. {
  202. str=array.ElementAt (i);
  203. str+="\r\n";
  204. str+=array.ElementAt (i+1);
  205. if(array.ElementAt (i+1).IsEmpty ())continue;
  206. if(array.ElementAt (i+1).Left (1)!="1")continue;
  207. /* exist=0;
  208. for(int a=0; a<m_List1.GetCount (); a++)
  209. {
  210. m_List1.GetText (a, temp);
  211. pos=temp.Find ("\r\n");
  212. if(array.ElementAt (i+1)==temp.Right (temp.GetLength ()-pos-2))
  213. {
  214. exist=1;
  215. break;
  216. }
  217. }
  218. if(exist)continue;*/
  219. if(m_List1.GetCount()%2)
  220. m_List1.AddEntry( str , g_gridcol1, m_List1.GetCount());
  221. else
  222. m_List1.AddEntry( str , g_gridcol2, m_List1.GetCount());
  223. }
  224. m_List1.Invalidate ();
  225. }
  226. void SendMsg::OnButton5()
  227. {
  228. // TODO: Add your control notification handler code here
  229. m_selitemarray.RemoveAll ();
  230. m_List1.ResetContent ();
  231. }
  232. void SendMsg::OnSelAll() // 全选按钮;
  233. {
  234. // TODO: Add your control notification handler code here
  235. for(int i=0; i<m_List1.GetCount (); i++)
  236. m_List1.SetSel (i, 1);
  237. OnSelchangeList1();
  238. }
  239. void SendMsg::OnReset()
  240. {
  241. // TODO: Add your control notification handler code here
  242. for(int i=0; i<m_List1.GetCount (); i++)
  243. m_List1.SetSel (i, 0);
  244. OnSelchangeList1();
  245. }
  246. void SendMsg::OnSelchangeList1()
  247. {
  248. // TODO: Add your control notification handler code here
  249. UpdateData();
  250. int count= m_List1.GetSelCount() ;
  251. if(count==0)return;
  252. int *pIndex=new int[count];
  253. m_List1.GetSelItems(count, pIndex);
  254. m_strRecvMobi = _T("");
  255. m_mobicount = 0;
  256. CString str,temp;
  257. int pos;
  258. m_nMobile=0;
  259. m_nPhone=0;
  260. BOOL bExist=0;
  261. for(int i=0; i<count; i++)
  262. {
  263. if(0)//m_nMobile>2999)
  264. {
  265. AfxMessageBox("一次最多能发送3000个手机, 部分选中的手机未生效, 请重新选择!", MB_ICONSTOP);
  266. break;
  267. }
  268. m_List1.GetText (pIndex[i], str);
  269. pos=str.Find ("\r\n");
  270. if(pos==-1)continue;
  271. temp=str.Right (str.GetLength ()-pos-2);
  272. if(m_strRecvMobi.Find (temp)!=-1)
  273. {
  274. bExist=1;
  275. continue;
  276. }
  277. if(CheckPhoneType(temp)==0 || CheckPhoneType(temp)==1 || CheckPhoneType(temp)==2)
  278. m_nMobile++;
  279. else if(CheckPhoneType(temp)==3)
  280. m_nPhone++;
  281. else
  282. {
  283. AfxMessageBox("号码"+temp+"不是正确的电话号码!", MB_ICONSTOP);
  284. continue;
  285. }
  286. m_strRecvMobi+=temp;
  287. m_strRecvMobi+=",";
  288. m_mobicount++;
  289. }
  290. if(bExist)AfxMessageBox("选中的号码中有重复的号码, 重复的号码已被忽略!");
  291. m_strRecvMobi.TrimRight (",");
  292. UpdateData(false);
  293. delete []pIndex;
  294. OnChangeEdtSms();
  295. CRect rc;
  296. GetDlgItem(IDC_EDT_RECV_MOBI)->GetWindowRect(rc);
  297. ScreenToClient(rc);
  298. InvalidateRect(rc);
  299. }
  300. void SendMsg::OnBtnSel()
  301. {
  302. SelMsgContent dlg;
  303. if(dlg.DoModal ()!=IDOK)return;
  304. SetDlgItemText(IDC_EDT_SMS, dlg.m_content);
  305. OnChangeEdtSms();
  306. }
  307. void SendMsg::OnBtnSend() // 短信群发 - 发送消息按钮
  308. {
  309. // TODO: Add your control notification handler code here
  310. if(!(IsHasRights2new(38) || IsHasRights2new(49)))return;
  311. UpdateData();
  312. if(CheckBadWords(m_strSendSms)==0 || CheckBadWords2(m_strSendSms)==0)
  313. {
  314. AfxMessageBox("信息服务商禁止的非法字符:("+g_temp+")希望您谅解!");
  315. return;
  316. }
  317. if(m_mobicount==0)
  318. {
  319. AfxMessageBox("手机号码不能为空, 请在联系人中选择, 按Ctrl或Shift键多选!");
  320. return;
  321. }
  322. if(m_strSendSms.IsEmpty ())
  323. {
  324. AfxMessageBox("信息不能为空!");
  325. return;
  326. }
  327. CString str, timestamp;
  328. timestamp = "msgtimestamp";
  329. //if(CheckExist(m_strSendSms,m_strRecvMobi))
  330. {
  331. CString sql = "select count(*) as cot from sendreg where [content]='" + m_strSendSms + "' and [phones]='" + m_strRecvMobi + "'";
  332. g_sendhead.bsql = 1;
  333. g_pMainWnd->ProcessChatMessageRequest2(sql); if (g_bSendOK == 0)return;
  334. if (g_ncount)
  335. if (AfxMessageBox("提醒:相似的信息已发送, 重复发送将再次收取短信费用, 继续吗?", MB_YESNO | MB_ICONINFORMATION) != IDYES)return;
  336. }
  337. CString scount;
  338. scount.Format("%d", m_count);
  339. if (atoi(g_cominfoarray.ElementAt(0).ElementAt(30)) < m_count && m_count > 1)
  340. {
  341. if (AfxMessageBox("提醒:您的余额可能不足, 继续发送吗?", MB_YESNO | MB_ICONINFORMATION) != IDYES)return;
  342. }
  343. #if JEFF_TEST_ON
  344. // 需要对手机串进行分组插入数据库,每组数量100;
  345. INT_PTR nLen = 0;
  346. INT nPos = 0;
  347. INT nCount = 0;
  348. CString strPhones = m_strRecvMobi;
  349. CString strSend = _T("");
  350. CString strTempTime = _T("");
  351. CString strTempPhone = _T("");
  352. nLen = (strPhones.GetLength() + 1) / 12; // 计算出电话号码个数;
  353. CString strSQL = _T("");
  354. if (nLen <= 100)
  355. {
  356. strSend.Format(INSERT_SENDREG, _T("0"), m_strRecvMobi, m_strSendSms, timestamp, scount, _T("0"), _T("0"), _T("0"), g_user.name);
  357. strSQL = strSend;
  358. if (m_selitemarray.GetSize() == 4)
  359. {
  360. strSend.Format(INSERT_SENDREG2, m_strRecvMobi, m_strSendSms, m_selitemarray.ElementAt(0), m_selitemarray.ElementAt(1), m_selitemarray.ElementAt(2), m_selitemarray.ElementAt(3), timestamp, g_user.name);
  361. strSQL += _T("***") + strSend;
  362. }
  363. }
  364. else
  365. {
  366. int nIndex = 0;
  367. do
  368. {
  369. nPos = strPhones.Find(',');
  370. if (nPos != -1)
  371. {
  372. strTempPhone += strPhones.Left(nPos) + _T(",");
  373. strPhones.Delete(0, nPos + 1);
  374. if (++nCount == 100)
  375. {
  376. nCount = 0;
  377. strTempPhone.TrimRight(_T(","));
  378. strSend.Format(INSERT_SENDREG,_T("0"), strTempPhone, m_strSendSms, timestamp, scount, _T("0"), _T("0"), _T("0"), g_user.name);
  379. if (strSQL.IsEmpty())
  380. strSQL += strSend;
  381. else
  382. strSQL += _T("***") + strSend;
  383. if (m_selitemarray.GetSize() == 4)
  384. {
  385. strSend.Format(INSERT_SENDREG2, strTempPhone, m_strSendSms, m_selitemarray.ElementAt(0), m_selitemarray.ElementAt(1), m_selitemarray.ElementAt(2), m_selitemarray.ElementAt(3), timestamp, g_user.name);
  386. strSQL += _T("***") + strSend;
  387. }
  388. strTempPhone = _T("");
  389. }
  390. }
  391. else
  392. {
  393. nCount = 0;
  394. strTempPhone += strPhones;
  395. strSend.Format(INSERT_SENDREG, _T("0"),strTempPhone, m_strSendSms, timestamp, scount, _T("0"), _T("0"), _T("0"), g_user.name);
  396. strSQL += _T("***") + strSend;
  397. if (m_selitemarray.GetSize() == 4)
  398. {
  399. strSend.Format(INSERT_SENDREG2, strTempPhone, m_strSendSms, m_selitemarray.ElementAt(0), m_selitemarray.ElementAt(1), m_selitemarray.ElementAt(2), m_selitemarray.ElementAt(3), timestamp, g_user.name);
  400. strSQL += _T("***") + strSend;
  401. }
  402. break;
  403. }
  404. } while (1);
  405. }
  406. //WriteTextLog(strSQL);
  407. g_sendhead.bsql = 1;
  408. g_pMainWnd->ProcessChatMessageRequest2(strSQL);
  409. #else
  410. 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 + "')";
  411. if (m_selitemarray.GetSize() == 4)
  412. sql += "***insert into [sendreg2]([phones],[content],[price],[yytime],[client],[type],[date],[ren])values('" + m_strRecvMobi + "','" + m_strSendSms + "','" + m_selitemarray.ElementAt(0) + "','" + m_selitemarray.ElementAt(1) + "','" + m_selitemarray.ElementAt(2) + "','" + m_selitemarray.ElementAt(3) + "','" + timestamp + "','" + g_user.name + "')";
  413. g_sendhead.bsql = 1;
  414. g_pMainWnd->ProcessChatMessageRequest2(sql);
  415. #endif
  416. if (g_bSendOK == 0)return;
  417. AfxMessageBox("发送成功! 请具体发送情况请查询发送记录!", MB_ICONINFORMATION);
  418. }
  419. void SendMsg::OnButton1()
  420. {
  421. // TODO: Add your control notification handler code here
  422. InputPhones dlg;
  423. if (dlg.DoModal() == IDOK)
  424. {
  425. CStringArray array;
  426. CString str = dlg.m_phones;
  427. str.Replace(" ", "");
  428. str.Replace(" ", "");
  429. str.Replace("\r\n", ",");
  430. str.Replace("\r", ",");
  431. str.Replace("\n", ",");
  432. str.Replace(";", ",");
  433. str.Replace(";", ",");
  434. str.Replace(",", ",");
  435. int pos = str.Find(",");
  436. CString temp;
  437. while (pos != -1)
  438. {
  439. temp = str.Left(pos);
  440. array.Add(temp);
  441. str = str.Right(str.GetLength() - pos - 1);
  442. pos = str.Find(",");
  443. }
  444. array.Add(str);
  445. CStringArray *m_pArray = &array;
  446. m_strRecvMobi = _T("");
  447. m_mobicount = 0;
  448. m_nMobile = 0;
  449. m_nPhone = 0;
  450. BOOL bExist = 0;
  451. for (int i = 0; i < m_pArray->GetSize(); i++)
  452. {
  453. temp = m_pArray->ElementAt(i);
  454. if (m_strRecvMobi.Find(temp) != -1)
  455. {
  456. bExist = 1;
  457. continue;
  458. }
  459. if (CheckPhoneType(temp) == 0 || CheckPhoneType(temp) == 1 || CheckPhoneType(temp) == 2)
  460. m_nMobile++;
  461. else if (CheckPhoneType(temp) == 3)
  462. m_nPhone++;
  463. else
  464. {
  465. AfxMessageBox("号码" + temp + "不是正确的电话号码!", MB_ICONSTOP);
  466. continue;
  467. }
  468. m_strRecvMobi += temp;
  469. m_strRecvMobi += ",";
  470. m_mobicount++;
  471. }
  472. if (bExist)AfxMessageBox("选中的号码中有重复的号码, 重复的号码已被忽略!");
  473. m_strRecvMobi.TrimRight(",");
  474. UpdateData(false);
  475. OnChangeEdtSms();
  476. }
  477. }
  478. void SendMsg::OnButton6()
  479. {
  480. // TODO: Add your control notification handler code here
  481. CStringArray array;
  482. GetPhoneAge dlg;
  483. dlg.m_pArray=&array;
  484. dlg.m_pArray2=&m_selitemarray;
  485. m_selitemarray.RemoveAll ();
  486. if(dlg.DoModal ()!=IDOK)return;
  487. CString str,temp;
  488. BOOL exist;int pos;
  489. for(int i=0; i<array.GetSize (); i+=2)
  490. {
  491. str=array.ElementAt (i);
  492. str+="\r\n";
  493. str+=array.ElementAt (i+1);
  494. if(array.ElementAt (i+1).IsEmpty ())continue;
  495. if(array.ElementAt (i+1).Left (1)!="1")continue;
  496. if(m_List1.GetCount()%2)
  497. m_List1.AddEntry( str , g_gridcol1, m_List1.GetCount());
  498. else
  499. m_List1.AddEntry( str , g_gridcol2, m_List1.GetCount());
  500. }
  501. m_List1.Invalidate ();
  502. }