SendMsg.cpp 14 KB

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