SendMsgDlg.cpp 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  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. CString str,timestamp;
  278. timestamp="msgtimestamp";//CTime::GetCurrentTime ().Format ("%Y%m%d%H%M%S"); msgxxtimestamp
  279. //if(CheckExist(m_strSendSms,m_strRecvMobi))
  280. {
  281. CString sql="select count(*) as cot from sendreg where [content]='"+m_strSendSms+"' and [phones]='"+m_strRecvMobi+"'";
  282. g_sendhead.bsql=1;
  283. g_pMainWnd->ProcessChatMessageRequest2(sql);if(g_bSendOK==0)return;
  284. if(g_ncount)
  285. if(AfxMessageBox("提醒:相似的信息已发送, 重复发送将再次收取短信费用, 继续吗?", MB_YESNO|MB_ICONINFORMATION)!=IDYES)return;
  286. }
  287. CString scount;
  288. scount.Format ("%d", m_count);
  289. 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+"')";
  290. if(m_pIdArray && m_sendmode)
  291. {
  292. CString temp;
  293. if(m_sendmode==1)
  294. sql+="***update dindan set [send1]='1' where ";
  295. else if(m_sendmode==2)
  296. sql+="***update dindan set [send2]='1' where ";
  297. else if(m_sendmode==3)
  298. sql+="***update dindan set [send3]='1' where ";
  299. else if(m_sendmode==4)
  300. sql+="***update dindan set [send4]=1 where ";
  301. else if(m_sendmode==5)
  302. sql+="***update dindan set [send5]=1 where ";
  303. for(int i=0; i<m_pIdArray->GetSize (); i++)
  304. {
  305. temp.Format ("[id]='%s' or ", m_pIdArray->ElementAt (i));
  306. sql+=temp;
  307. }
  308. sql.TrimRight (" or ");
  309. }
  310. g_sendhead.bsql=1;
  311. g_pMainWnd->ProcessChatMessageRequest2(sql);if(g_bSendOK==0)return;
  312. AfxMessageBox("发送成功! 请具体发送情况请查询发送记录!", MB_ICONINFORMATION);
  313. }
  314. void SendMsgDlg::OnBtnSel()
  315. {
  316. SelMsgContent dlg;
  317. if(dlg.DoModal ()!=IDOK)return;
  318. SetDlgItemText(IDC_EDT_SMS, dlg.m_content);
  319. OnChangeEdtSms();
  320. }