SendMsg.cpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472
  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. 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+"')";
  341. if(m_selitemarray.GetSize ()==4)
  342. 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+"')";
  343. g_sendhead.bsql=1;
  344. g_pMainWnd->ProcessChatMessageRequest2(sql);if(g_bSendOK==0)return;
  345. AfxMessageBox("发送成功! 请具体发送情况请查询发送记录!", MB_ICONINFORMATION);
  346. }
  347. void SendMsg::OnButton1()
  348. {
  349. // TODO: Add your control notification handler code here
  350. InputPhones dlg;
  351. if(dlg.DoModal ()==IDOK)
  352. {
  353. CStringArray array;
  354. CString str=dlg.m_phones;
  355. str.Replace (" ", "");
  356. str.Replace (" ", "");
  357. str.Replace ("\r\n", ",");
  358. str.Replace ("\r", ",");
  359. str.Replace ("\n", ",");
  360. str.Replace (";", ",");
  361. str.Replace (";", ",");
  362. str.Replace (",", ",");
  363. int pos=str.Find (",");
  364. CString temp;
  365. while(pos!=-1)
  366. {
  367. temp=str.Left (pos);
  368. array.Add (temp);
  369. str=str.Right (str.GetLength ()-pos-1);
  370. pos=str.Find (",");
  371. }
  372. array.Add (str);
  373. CStringArray *m_pArray=&array;
  374. m_strRecvMobi = _T("");
  375. m_mobicount = 0;
  376. m_nMobile=0;
  377. m_nPhone=0;
  378. BOOL bExist=0;
  379. for(int i=0; i<m_pArray->GetSize (); i++)
  380. {
  381. temp=m_pArray->ElementAt (i);
  382. if(m_strRecvMobi.Find (temp)!=-1)
  383. {
  384. bExist=1;
  385. continue;
  386. }
  387. if(CheckPhoneType(temp)==0 || CheckPhoneType(temp)==1 || CheckPhoneType(temp)==2)
  388. m_nMobile++;
  389. else if(CheckPhoneType(temp)==3)
  390. m_nPhone++;
  391. else
  392. {
  393. AfxMessageBox("号码"+temp+"不是正确的电话号码!", MB_ICONSTOP);
  394. continue;
  395. }
  396. m_strRecvMobi+=temp;
  397. m_strRecvMobi+=",";
  398. m_mobicount++;
  399. }
  400. if(bExist)AfxMessageBox("选中的号码中有重复的号码, 重复的号码已被忽略!");
  401. m_strRecvMobi.TrimRight (",");
  402. UpdateData(false);
  403. OnChangeEdtSms();
  404. }
  405. }
  406. void SendMsg::OnButton6()
  407. {
  408. // TODO: Add your control notification handler code here
  409. CStringArray array;
  410. GetPhoneAge dlg;
  411. dlg.m_pArray=&array;
  412. dlg.m_pArray2=&m_selitemarray;
  413. m_selitemarray.RemoveAll ();
  414. if(dlg.DoModal ()!=IDOK)return;
  415. CString str,temp;
  416. BOOL exist;int pos;
  417. for(int i=0; i<array.GetSize (); i+=2)
  418. {
  419. str=array.ElementAt (i);
  420. str+="\r\n";
  421. str+=array.ElementAt (i+1);
  422. if(array.ElementAt (i+1).IsEmpty ())continue;
  423. if(array.ElementAt (i+1).Left (1)!="1")continue;
  424. if(m_List1.GetCount()%2)
  425. m_List1.AddEntry( str , g_gridcol1, m_List1.GetCount());
  426. else
  427. m_List1.AddEntry( str , g_gridcol2, m_List1.GetCount());
  428. }
  429. m_List1.Invalidate ();
  430. }