SendMsg.cpp 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541
  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. }
  151. void SendMsg::OnChangeEdtSms()
  152. {
  153. // TODO: If this is a RICHEDIT control, the control will not
  154. // send this notification unless you override the MyFormView::OnInitDialog()
  155. // function and call CRichEditCtrl().SetEventMask()
  156. // with the ENM_CHANGE flag ORed into the mask.
  157. UpdateData();
  158. m_strSendSms.Replace ("'", "'");
  159. m_strSendSms.Replace ("(", "(");
  160. m_strSendSms.Replace (")", ")");
  161. UpdateData(false);
  162. CString str;
  163. int count=0;
  164. int leng=GetLengthEx(m_strSendSms);
  165. if(m_nMobile)
  166. {
  167. count+=m_nMobile*(leng/MSG_LENGTH);
  168. if(leng%MSG_LENGTH)
  169. count+=m_nMobile;
  170. }
  171. if(m_nPhone)
  172. {
  173. count+=m_nPhone*(leng/56);
  174. if(leng%56)
  175. count+=m_nPhone;
  176. }
  177. m_count=count;
  178. str.Format ("短信内容(手机%d字/条,小灵通56字/条)(现%d字,共%d条短信)", MSG_LENGTH,leng,count);
  179. GetDlgItem(IDC_STATIC2)->SetWindowText(str);
  180. CRect rc;
  181. GetDlgItem(IDC_STATIC2)->GetWindowRect (rc);
  182. ScreenToClient(rc);
  183. InvalidateRect(rc);
  184. // TODO: Add your control notification handler code here
  185. }
  186. void SendMsg::OnButton2()
  187. {
  188. // TODO: Add your control notification handler code here
  189. CStringArray array;
  190. GetPhone dlg;
  191. dlg.m_pArray=&array;
  192. dlg.m_pArray2=&m_selitemarray;
  193. m_selitemarray.RemoveAll ();
  194. if(dlg.DoModal ()!=IDOK)return;
  195. CString str,temp;
  196. BOOL exist;int pos;
  197. for(int i=0; i<array.GetSize (); i+=2)
  198. {
  199. str=array.ElementAt (i);
  200. str+="\r\n";
  201. str+=array.ElementAt (i+1);
  202. if(array.ElementAt (i+1).IsEmpty ())continue;
  203. if(array.ElementAt (i+1).Left (1)!="1")continue;
  204. /* exist=0;
  205. for(int a=0; a<m_List1.GetCount (); a++)
  206. {
  207. m_List1.GetText (a, temp);
  208. pos=temp.Find ("\r\n");
  209. if(array.ElementAt (i+1)==temp.Right (temp.GetLength ()-pos-2))
  210. {
  211. exist=1;
  212. break;
  213. }
  214. }
  215. if(exist)continue;*/
  216. if(m_List1.GetCount()%2)
  217. m_List1.AddEntry( str , g_gridcol1, m_List1.GetCount());
  218. else
  219. m_List1.AddEntry( str , g_gridcol2, m_List1.GetCount());
  220. }
  221. m_List1.Invalidate ();
  222. }
  223. void SendMsg::OnButton5()
  224. {
  225. // TODO: Add your control notification handler code here
  226. m_selitemarray.RemoveAll ();
  227. m_List1.ResetContent ();
  228. }
  229. void SendMsg::OnSelAll()
  230. {
  231. // TODO: Add your control notification handler code here
  232. for(int i=0; i<m_List1.GetCount (); i++)
  233. m_List1.SetSel (i, 1);
  234. OnSelchangeList1();
  235. }
  236. void SendMsg::OnReset()
  237. {
  238. // TODO: Add your control notification handler code here
  239. for(int i=0; i<m_List1.GetCount (); i++)
  240. m_List1.SetSel (i, 0);
  241. OnSelchangeList1();
  242. }
  243. void SendMsg::OnSelchangeList1()
  244. {
  245. // TODO: Add your control notification handler code here
  246. UpdateData();
  247. int count= m_List1.GetSelCount() ;
  248. if(count==0)return;
  249. int *pIndex=new int[count];
  250. m_List1.GetSelItems(count, pIndex);
  251. m_strRecvMobi = _T("");
  252. m_mobicount = 0;
  253. CString str,temp;
  254. int pos;
  255. m_nMobile=0;
  256. m_nPhone=0;
  257. BOOL bExist=0;
  258. for(int i=0; i<count; i++)
  259. {
  260. if(0)//m_nMobile>2999)
  261. {
  262. AfxMessageBox("一次最多能发送3000个手机, 部分选中的手机未生效, 请重新选择!", MB_ICONSTOP);
  263. break;
  264. }
  265. m_List1.GetText (pIndex[i], str);
  266. pos=str.Find ("\r\n");
  267. if(pos==-1)continue;
  268. temp=str.Right (str.GetLength ()-pos-2);
  269. if(m_strRecvMobi.Find (temp)!=-1)
  270. {
  271. bExist=1;
  272. continue;
  273. }
  274. if(CheckPhoneType(temp)==0 || CheckPhoneType(temp)==1 || CheckPhoneType(temp)==2)
  275. m_nMobile++;
  276. else if(CheckPhoneType(temp)==3)
  277. m_nPhone++;
  278. else
  279. {
  280. AfxMessageBox("号码"+temp+"不是正确的电话号码!", MB_ICONSTOP);
  281. continue;
  282. }
  283. m_strRecvMobi+=temp;
  284. m_strRecvMobi+=",";
  285. m_mobicount++;
  286. }
  287. if(bExist)AfxMessageBox("选中的号码中有重复的号码, 重复的号码已被忽略!");
  288. m_strRecvMobi.TrimRight (",");
  289. UpdateData(false);
  290. delete []pIndex;
  291. OnChangeEdtSms();
  292. CRect rc;
  293. GetDlgItem(IDC_EDT_RECV_MOBI)->GetWindowRect(rc);
  294. ScreenToClient(rc);
  295. InvalidateRect(rc);
  296. }
  297. void SendMsg::OnBtnSel()
  298. {
  299. SelMsgContent dlg;
  300. if(dlg.DoModal ()!=IDOK)return;
  301. SetDlgItemText(IDC_EDT_SMS, dlg.m_content);
  302. OnChangeEdtSms();
  303. }
  304. void SendMsg::OnBtnSend() // 短信群发 - 发送消息按钮
  305. {
  306. // TODO: Add your control notification handler code here
  307. if(!(IsHasRights2new(38) || IsHasRights2new(49)))return;
  308. UpdateData();
  309. if(CheckBadWords(m_strSendSms)==0 || CheckBadWords2(m_strSendSms)==0)
  310. {
  311. AfxMessageBox("信息服务商禁止的非法字符:("+g_temp+")希望您谅解!");
  312. return;
  313. }
  314. if(m_mobicount==0)
  315. {
  316. AfxMessageBox("手机号码不能为空, 请在联系人中选择, 按Ctrl或Shift键多选!");
  317. return;
  318. }
  319. if(m_strSendSms.IsEmpty ())
  320. {
  321. AfxMessageBox("信息不能为空!");
  322. return;
  323. }
  324. CString str, timestamp;
  325. timestamp = "msgtimestamp";
  326. //if(CheckExist(m_strSendSms,m_strRecvMobi))
  327. {
  328. CString sql = "select count(*) as cot from sendreg where [content]='" + m_strSendSms + "' and [phones]='" + m_strRecvMobi + "'";
  329. g_sendhead.bsql = 1;
  330. g_pMainWnd->ProcessChatMessageRequest2(sql); if (g_bSendOK == 0)return;
  331. if (g_ncount)
  332. if (AfxMessageBox("提醒:相似的信息已发送, 重复发送将再次收取短信费用, 继续吗?", MB_YESNO | MB_ICONINFORMATION) != IDYES)return;
  333. }
  334. CString scount;
  335. scount.Format("%d", m_count);
  336. if (atoi(g_cominfoarray.ElementAt(0).ElementAt(30)) < m_count && m_count > 1)
  337. {
  338. if (AfxMessageBox("提醒:您的余额可能不足, 继续发送吗?", MB_YESNO | MB_ICONINFORMATION) != IDYES)return;
  339. }
  340. #if JEFF_TEST_ON
  341. // 需要对手机串进行分组插入数据库,每组数量100;
  342. INT_PTR nLen = 0;
  343. INT nPos = 0;
  344. INT nCount = 0;
  345. CString strPhones = m_strRecvMobi;
  346. CString strSend = _T("");
  347. CString strTempTime = _T("");
  348. CString strTempPhone = _T("");
  349. nLen = (strPhones.GetLength() + 1) / 12; // 计算出电话号码个数;
  350. CString strSQL = _T("");
  351. if (nLen <= 100)
  352. {
  353. strSend.Format(INSERT_SENDREG, _T("0"), m_strRecvMobi, m_strSendSms, timestamp, scount, _T("0"), _T("0"), _T("0"), g_user.name);
  354. strSQL = strSend;
  355. if (m_selitemarray.GetSize() == 4)
  356. {
  357. 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);
  358. strSQL += _T("***") + strSend;
  359. }
  360. }
  361. else
  362. {
  363. int nIndex = 0;
  364. do
  365. {
  366. nPos = strPhones.Find(',');
  367. if (nPos != -1)
  368. {
  369. strTempPhone += strPhones.Left(nPos) + _T(",");
  370. strPhones.Delete(0, nPos + 1);
  371. if (++nCount == 100)
  372. {
  373. nCount = 0;
  374. strTempPhone.TrimRight(_T(","));
  375. strSend.Format(INSERT_SENDREG,_T("0"), strTempPhone, m_strSendSms, timestamp, scount, _T("0"), _T("0"), _T("0"), g_user.name);
  376. if (strSQL.IsEmpty())
  377. strSQL += strSend;
  378. else
  379. strSQL += _T("***") + strSend;
  380. if (m_selitemarray.GetSize() == 4)
  381. {
  382. 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);
  383. strSQL += _T("***") + strSend;
  384. }
  385. strTempPhone = _T("");
  386. }
  387. }
  388. else
  389. {
  390. nCount = 0;
  391. strTempPhone += strPhones;
  392. strSend.Format(INSERT_SENDREG, _T("0"),strTempPhone, m_strSendSms, timestamp, scount, _T("0"), _T("0"), _T("0"), g_user.name);
  393. strSQL += _T("***") + strSend;
  394. if (m_selitemarray.GetSize() == 4)
  395. {
  396. 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);
  397. strSQL += _T("***") + strSend;
  398. }
  399. break;
  400. }
  401. } while (1);
  402. }
  403. //WriteClientLog(strSQL);
  404. g_sendhead.bsql = 1;
  405. g_pMainWnd->ProcessChatMessageRequest2(strSQL);
  406. #else
  407. 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 + "')";
  408. if (m_selitemarray.GetSize() == 4)
  409. 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 + "')";
  410. g_sendhead.bsql = 1;
  411. g_pMainWnd->ProcessChatMessageRequest2(sql);
  412. #endif
  413. if (g_bSendOK == 0)return;
  414. AfxMessageBox("发送成功! 请具体发送情况请查询发送记录!", MB_ICONINFORMATION);
  415. }
  416. void SendMsg::OnButton1()
  417. {
  418. // TODO: Add your control notification handler code here
  419. InputPhones dlg;
  420. if (dlg.DoModal() == IDOK)
  421. {
  422. CStringArray array;
  423. CString str = dlg.m_phones;
  424. str.Replace(" ", "");
  425. str.Replace(" ", "");
  426. str.Replace("\r\n", ",");
  427. str.Replace("\r", ",");
  428. str.Replace("\n", ",");
  429. str.Replace(";", ",");
  430. str.Replace(";", ",");
  431. str.Replace(",", ",");
  432. int pos = str.Find(",");
  433. CString temp;
  434. while (pos != -1)
  435. {
  436. temp = str.Left(pos);
  437. array.Add(temp);
  438. str = str.Right(str.GetLength() - pos - 1);
  439. pos = str.Find(",");
  440. }
  441. array.Add(str);
  442. CStringArray *m_pArray = &array;
  443. m_strRecvMobi = _T("");
  444. m_mobicount = 0;
  445. m_nMobile = 0;
  446. m_nPhone = 0;
  447. BOOL bExist = 0;
  448. for (int i = 0; i < m_pArray->GetSize(); i++)
  449. {
  450. temp = m_pArray->ElementAt(i);
  451. if (m_strRecvMobi.Find(temp) != -1)
  452. {
  453. bExist = 1;
  454. continue;
  455. }
  456. if (CheckPhoneType(temp) == 0 || CheckPhoneType(temp) == 1 || CheckPhoneType(temp) == 2)
  457. m_nMobile++;
  458. else if (CheckPhoneType(temp) == 3)
  459. m_nPhone++;
  460. else
  461. {
  462. AfxMessageBox("号码" + temp + "不是正确的电话号码!", MB_ICONSTOP);
  463. continue;
  464. }
  465. m_strRecvMobi += temp;
  466. m_strRecvMobi += ",";
  467. m_mobicount++;
  468. }
  469. if (bExist)AfxMessageBox("选中的号码中有重复的号码, 重复的号码已被忽略!");
  470. m_strRecvMobi.TrimRight(",");
  471. UpdateData(false);
  472. OnChangeEdtSms();
  473. }
  474. }
  475. void SendMsg::OnButton6()
  476. {
  477. // TODO: Add your control notification handler code here
  478. CStringArray array;
  479. GetPhoneAge dlg;
  480. dlg.m_pArray=&array;
  481. dlg.m_pArray2=&m_selitemarray;
  482. m_selitemarray.RemoveAll ();
  483. if(dlg.DoModal ()!=IDOK)return;
  484. CString str,temp;
  485. BOOL exist;int pos;
  486. for(int i=0; i<array.GetSize (); i+=2)
  487. {
  488. str=array.ElementAt (i);
  489. str+="\r\n";
  490. str+=array.ElementAt (i+1);
  491. if(array.ElementAt (i+1).IsEmpty ())continue;
  492. if(array.ElementAt (i+1).Left (1)!="1")continue;
  493. if(m_List1.GetCount()%2)
  494. m_List1.AddEntry( str , g_gridcol1, m_List1.GetCount());
  495. else
  496. m_List1.AddEntry( str , g_gridcol2, m_List1.GetCount());
  497. }
  498. m_List1.Invalidate ();
  499. }