AutoRun3Dlg2.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773
  1. // AutoRun3Dlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "AutoRun3.h"
  5. #include "AutoRun3Dlg2.h"
  6. #include <afxsock.h>//<Winsock2.h>
  7. #include "ConnectDlg.h"
  8. #include "SendDataDlg.h"
  9. #include "AddContact.h"
  10. #include "SendReg.h"
  11. #ifdef _DEBUG
  12. #define new DEBUG_NEW
  13. #undef THIS_FILE
  14. static char THIS_FILE[] = __FILE__;
  15. #endif
  16. extern DWORD g_nSendCode;
  17. extern BOOL g_bReturned2;
  18. /////////////////////////////////////////////////////////////////////////////
  19. extern HWND g_hSendWnd;
  20. extern HWND g_hConnectWnd;
  21. #define DISCONNECT_TIMER (WM_USER + 101)
  22. #define LOGINFAILED_TIMER (WM_USER + 102)
  23. /////////////////////////////////////////////////////////////////////////////
  24. static void HandleClientNetEvent2(IN SOCKET hSocket, IN ETransportEvent eEvent,
  25. IN void *pDataBuf, IN unsigned long nDataLen,
  26. IN int nError, IN void *pContext)
  27. {
  28. if( nError != TRANSPORT_OK ) return;
  29. CAutoRun3Dlg2 *pDlg = (CAutoRun3Dlg2 *)pContext;
  30. if( NULL == pDlg ) return;
  31. pDlg->ProcessNetEvent(eEvent, pDataBuf, nDataLen);
  32. }
  33. CAutoRun3Dlg2::CAutoRun3Dlg2(CWnd* pParent /*=NULL*/)
  34. : CDialog(CAutoRun3Dlg2::IDD, pParent)
  35. {
  36. //{{AFX_DATA_INIT(CAutoRun3Dlg2)
  37. m_strSendSms = _T("");
  38. m_strLoginID = _T("");
  39. m_strLoginPwd = _T("");
  40. m_strRecvMobi = _T("");
  41. m_strNewPwd = _T("");
  42. m_mobicount = 0;
  43. m_check1 = FALSE;
  44. m_count = 0;
  45. //}}AFX_DATA_INIT
  46. // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
  47. m_nMobile=0;
  48. m_nPhone=0;
  49. CString version = _T ("Version 1.0");
  50. m_strLoginID=AfxGetApp()->GetProfileString (version, "account", "");
  51. m_strLoginPwd=AfxGetApp()->GetProfileString (version, "psw", "");
  52. if(!m_strLoginPwd.IsEmpty())m_check1=1;
  53. }
  54. void CAutoRun3Dlg2::DoDataExchange(CDataExchange* pDX)
  55. {
  56. CDialog::DoDataExchange(pDX);
  57. //{{AFX_DATA_MAP(CAutoRun3Dlg2)
  58. DDX_Control(pDX, IDC_LIST2, m_List1);
  59. DDX_Control(pDX, IDC_BTN_SEND, m_btnSend);
  60. DDX_Control(pDX, IDC_LST_SMS, m_listCtrl);
  61. DDX_Text(pDX, IDC_EDT_SMS, m_strSendSms);
  62. DDV_MaxChars(pDX, m_strSendSms, 2000);
  63. DDX_Text(pDX, IDC_EDT_LOGIN_ID, m_strLoginID);
  64. DDV_MaxChars(pDX, m_strLoginID, 11);
  65. DDX_Text(pDX, IDC_EDT_LOGIN_PWD, m_strLoginPwd);
  66. DDX_Text(pDX, IDC_EDT_RECV_MOBI, m_strRecvMobi);
  67. DDX_Text(pDX, IDC_EDT_NEW_PWD, m_strNewPwd);
  68. DDX_Text(pDX, IDC_EDT_NUM, m_mobicount);
  69. DDX_Check(pDX, IDC_CHECK1, m_check1);
  70. //}}AFX_DATA_MAP
  71. }
  72. BEGIN_MESSAGE_MAP(CAutoRun3Dlg2, CDialog)
  73. //{{AFX_MSG_MAP(CAutoRun3Dlg2)
  74. ON_WM_DESTROY()
  75. ON_BN_CLICKED(IDC_BTN_SEND, OnBtnSend)
  76. ON_BN_CLICKED(IDC_BTN_QUERY, OnBtnQuery)
  77. ON_BN_CLICKED(IDC_BTN_Query2, OnBTNQuery2)
  78. ON_BN_CLICKED(IDC_BTN_CHANGE_PWD, OnBtnChangePwd)
  79. ON_BN_CLICKED(IDC_BTN_GET_STATUS, OnBtnGetStatus)
  80. ON_WM_TIMER()
  81. ON_BN_CLICKED(IDC_BUTadd, OnBUTadd)
  82. ON_BN_CLICKED(IDC_BUTdel, OnBUTdel)
  83. ON_LBN_SELCHANGE(IDC_LIST2, OnSelchangeList2)
  84. ON_EN_CHANGE(IDC_EDT_SMS, OnChangeEdtSms)
  85. ON_EN_CHANGE(IDC_EDT_RECV_MOBI, OnChangeEdtRecvMobi)
  86. ON_BN_CLICKED(IDC_CHECK1, OnCheck1)
  87. ON_BN_CLICKED(IDC_BTN_REG, OnBtnReg)
  88. //}}AFX_MSG_MAP
  89. END_MESSAGE_MAP()
  90. /////////////////////////////////////////////////////////////////////////////
  91. BOOL CAutoRun3Dlg2::OnInitDialog()
  92. {
  93. CDialog::OnInitDialog();
  94. // Set the icon for this dialog. The framework does this automatically
  95. // when the application's main window is not a dialog
  96. // g_pMainWnd=this;
  97. /////////////////////////////////
  98. // TODO: Add extra initialization here
  99. return TRUE; // return TRUE unless you set the focus to a control
  100. }
  101. DWORD CAutoRun3Dlg2::GetConnectionID()
  102. {
  103. return m_dwConnectionID;
  104. }
  105. void CAutoRun3Dlg2::SetConnectionID(DWORD dwConnection)
  106. {
  107. m_dwConnectionID = dwConnection;
  108. }
  109. void CAutoRun3Dlg2::ProcessChatMessageRequest2(CString sql)
  110. {
  111. const char *szDataBuf = sql.GetBuffer(0);
  112. sql.ReleaseBuffer();
  113. ProcessChatMessageRequest((void*)szDataBuf, strlen(szDataBuf) + 1);
  114. }
  115. void CAutoRun3Dlg2::ProcessChatMessageRequest2(BYTE code)
  116. {
  117. ProcessChatMessageRequest(&code, sizeof(BYTE));
  118. }
  119. void CAutoRun3Dlg2::ProcessChatMessageRequest2(BYTE *pData, int length)
  120. {
  121. ProcessChatMessageRequest((void*)pData, length);
  122. }
  123. BOOL CAutoRun3Dlg2::ProcessChatMessageRequest(void *szDataBuf, int nDataLen)
  124. {
  125. g_bReturned2=0;
  126. DWORD dwFromUserID = GetConnectionID();
  127. WORD wMessageId = MSG_CHATMESSAGE_REQ;
  128. DWORD dwDataLen = sizeof(TCHAT_MESSAGE_STRU) + nDataLen;
  129. BYTE *pSendData = new BYTE[dwDataLen];
  130. TCHAT_MESSAGE_STRU *pChatMessage=(TCHAT_MESSAGE_STRU*)pSendData;
  131. memset(pChatMessage, 0x00, dwDataLen);
  132. g_sendhead.length[98]=987123768;
  133. memcpy(pSendData, &g_sendhead, sizeof(g_sendhead));
  134. pChatMessage->tCommonMsg.dwConnectionID = GetConnectionID();
  135. pChatMessage->tCommonMsg.wMessageId = wMessageId;
  136. pChatMessage->dwFromUserID = dwFromUserID;
  137. pChatMessage->dwToUserID = 15;
  138. pChatMessage->wMessageLen = nDataLen;
  139. memcpy(pChatMessage->byFileContent, szDataBuf, nDataLen);
  140. TMessageHeader tHeader = {0};
  141. tHeader.wMessageId = wMessageId;
  142. tHeader.dwDataLen = dwDataLen;
  143. BOOL bRet=0;
  144. unsigned long ulSendLen = m_tClientTunnel.net_Send(&tHeader, (void *)pChatMessage, dwDataLen);
  145. if( ulSendLen != SOCKET_ERROR )
  146. {
  147. bRet=1;
  148. }
  149. delete [] pSendData;
  150. return bRet;
  151. }
  152. BOOL CAutoRun3Dlg2::OnConnect()
  153. {
  154. CString strServerAddress = g_server2;
  155. char *szServerAddress = strServerAddress.GetBuffer(0);
  156. strServerAddress.ReleaseBuffer();
  157. /*for Client, IP and Port can be 0,
  158. and for Server, IP is LocalIP, and Port is Listening Port*/
  159. int nResult = m_tClientTunnel.net_OpenSocket(Transport_Client,
  160. 0,
  161. HandleClientNetEvent2,
  162. this);
  163. if( TRANSPORT_OK != nResult )
  164. {
  165. return 0;
  166. }
  167. DWORD dwRemoteIPValue = inet_addr(szServerAddress);
  168. WORD wPort = 5678;
  169. nResult = m_tClientTunnel.net_Connect(dwRemoteIPValue, wPort);
  170. if( TRANSPORT_OK != nResult )
  171. {
  172. m_tClientTunnel.net_CloseSocket();
  173. return 0;
  174. }
  175. return ProcessLoginRequest();
  176. }
  177. void CAutoRun3Dlg2::ProcessNetEvent(int nEventType, void *pRecvMsg, DWORD dwDataLen)
  178. {
  179. if( Transport_ReadEv == nEventType )
  180. {
  181. if( NULL == pRecvMsg ) return;
  182. TMessageHeader* pHeader = (TMessageHeader *)pRecvMsg;
  183. char *pDataBuf = (char *)pRecvMsg + MESSAGE_HEADER_LEN;
  184. WORD dwMessageID = pHeader->wMessageId;
  185. switch(dwMessageID)
  186. {
  187. case MSG_LOGIN_RESP:
  188. {
  189. LOGIN_RESULT_STRU tLoginResult = {0};
  190. memcpy(&tLoginResult, pDataBuf, sizeof(LOGIN_RESULT_STRU));
  191. ProcessLoginResponse(&tLoginResult);
  192. break;
  193. }
  194. case MSG_USERINFO_RESP:
  195. {
  196. TUSERLIST_INFO_STRU tUserListInfo = {0};
  197. memcpy(&tUserListInfo, pDataBuf, sizeof(TUSERLIST_INFO_STRU));
  198. // ProcessUserListInfoResponse(&tUserListInfo);
  199. break;
  200. }
  201. case MSG_LOGOUT_RESP:
  202. {
  203. TUSERLIST_INFO_STRU tUserListInfo = {0};
  204. memcpy(&tUserListInfo, pDataBuf, sizeof(TUSERLIST_INFO_STRU));
  205. // ProcessLogoutResponse(&tUserListInfo);
  206. break;
  207. }
  208. case MSG_CHATMESSAGE_RESP:
  209. {
  210. TCHAT_MESSAGE_STRU *pChatMessage = (TCHAT_MESSAGE_STRU *)pDataBuf;
  211. ProcessChatMessageResponse((void *)pChatMessage);
  212. break;
  213. }
  214. default:
  215. {
  216. break;
  217. }
  218. }
  219. }
  220. else if( Transport_CloseEv == nEventType )
  221. {
  222. SetTimer(DISCONNECT_TIMER, 0, NULL);
  223. }
  224. ///////
  225. }
  226. void CAutoRun3Dlg2::OnDisconnect()
  227. {
  228. m_tClientTunnel.net_CloseSocket();
  229. SetConnectionID(INVALID_SOCKET);
  230. }
  231. void CAutoRun3Dlg2::ProcessLoginResponse(void *pLoginResult)
  232. {
  233. if( NULL == pLoginResult ) return;
  234. LOGIN_RESULT_STRU *ptLoginResult = (LOGIN_RESULT_STRU *)pLoginResult;
  235. DWORD dwConnectionID = ptLoginResult->tCommonMsg.dwConnectionID;
  236. SetConnectionID(dwConnectionID);
  237. BYTE byResult = ptLoginResult->byResult;
  238. if(LOGIN_RESULT_SUC == byResult)
  239. {
  240. }
  241. else
  242. {
  243. SetTimer(LOGINFAILED_TIMER, 0, NULL);
  244. }
  245. CString strCommentInfo("");
  246. strCommentInfo.Format("%s. 用户代号: %ld",
  247. ((LOGIN_RESULT_SUC == byResult) ? "登录成功" :
  248. (LOGIN_RESULT_MULTI == byResult) ? "重复登录" :
  249. (LOGIN_RESULT_NAMERROR == byResult) ? "名字不存在" :
  250. (LOGIN_RESULT_PWERROR == byResult) ? "密码错误" : "登录失败"),
  251. dwConnectionID);
  252. // MessageBox((CString)strCommentInfo);
  253. }
  254. extern void MyGetIPByName(CString &name);
  255. extern CString g_localip;
  256. BOOL CAutoRun3Dlg2::ProcessLoginRequest()
  257. {
  258. WORD wMessageId = MSG_LOGIN_REQ;
  259. TLOGIN_STRU tLogonInfo = {0};
  260. tLogonInfo.tCommonMsg.dwConnectionID = GetConnectionID();
  261. tLogonInfo.tCommonMsg.wMessageId = wMessageId;
  262. if(g_localip.IsEmpty ())
  263. {
  264. char path[MAX_PATH];
  265. ::memset (path, 0, MAX_PATH);
  266. DWORD leng=50;
  267. ::GetComputerName (path, &leng);
  268. g_localip=path;
  269. MyGetIPByName(g_localip);
  270. return 0;
  271. }
  272. CString strUserName = "rtghj3wsdfg"+g_localip;
  273. strUserName.TrimLeft();
  274. strUserName.TrimRight();
  275. strcpy(tLogonInfo.tUserInfo.szUserName, strUserName);
  276. DWORD dwDataLen = sizeof(TLOGIN_STRU);
  277. TMessageHeader tHeader = {0};
  278. tHeader.wMessageId = wMessageId;
  279. tHeader.dwDataLen = dwDataLen;
  280. unsigned long ulSendLen = m_tClientTunnel.net_Send(&tHeader, (void *)&tLogonInfo, dwDataLen);
  281. if( ulSendLen == SOCKET_ERROR )
  282. {
  283. return 0;
  284. }
  285. return 1;
  286. }
  287. //---------------------------------------------------------------------------
  288. void CAutoRun3Dlg2::OnDestroy()
  289. {
  290. CDialog::OnDestroy();
  291. OnDisconnect();
  292. }
  293. void CAutoRun3Dlg2::OnTimer(UINT nIDEvent)
  294. {
  295. // TODO: Add your message handler code here and/or call default
  296. if( DISCONNECT_TIMER == nIDEvent )
  297. {
  298. KillTimer(nIDEvent);
  299. OnDisconnect();
  300. }
  301. else if( LOGINFAILED_TIMER == nIDEvent )
  302. {
  303. KillTimer(nIDEvent);
  304. OnDisconnect();
  305. }
  306. }
  307. void CAutoRun3Dlg2::OnBUTadd()
  308. {
  309. // TODO: Add your control notification handler code here
  310. AddContact dlg;
  311. if(dlg.DoModal ()!=IDOK)return;
  312. CString str;
  313. int pos;
  314. for(int i=0; i<m_List1.GetCount (); i++)
  315. {
  316. m_List1.GetText (i, str);
  317. pos=str.Find ("\r\n");
  318. if(dlg.m_phone==str.Right (str.GetLength ()-pos-2))
  319. {
  320. AfxMessageBox("已有此电话的记录!");
  321. return;
  322. }
  323. }
  324. CString sql;
  325. sql= "insert into contact([name],[phone]) values(\
  326. '"+dlg.m_name+"',\
  327. '"+dlg.m_phone+"')";
  328. g_db.ExecuteSQL (sql);
  329. if(m_List1.GetCount()%2)
  330. m_List1.AddEntry( dlg.m_name+"\r\n"+dlg.m_phone , RGB(240,247,255), m_List1.GetCount());
  331. else
  332. m_List1.AddEntry( dlg.m_name+"\r\n"+dlg.m_phone , RGB(255,248,240), m_List1.GetCount());
  333. }
  334. void CAutoRun3Dlg2::OnBUTdel()
  335. {
  336. // TODO: Add your control notification handler code here
  337. int listpos=m_List1.GetCurSel ();
  338. if(listpos==-1)
  339. {
  340. AfxMessageBox("请先选中您要删除的联系人!");
  341. return;
  342. }
  343. if(AfxMessageBox("警告:删除后将不可恢复, 继续吗?", MB_YESNO|MB_ICONSTOP)!=IDYES)return;
  344. CString str;
  345. m_List1.GetText (listpos, str);
  346. int pos=str.Find ("\r\n");
  347. CString name=str.Left (pos);
  348. CString phone=str.Right (str.GetLength ()-pos-2);
  349. CString sql;
  350. sql= "delete from contact where [name]='"+name+"' and [phone]='"+phone+"'";
  351. g_db.ExecuteSQL (sql);
  352. m_List1.DeleteString(listpos);
  353. }
  354. void CAutoRun3Dlg2::OnSelchangeList2()
  355. {
  356. // TODO: Add your control notification handler code here
  357. UpdateData();
  358. int count= m_List1.GetSelCount() ;
  359. if(count==0)return;
  360. int *pIndex=new int[count];
  361. m_List1.GetSelItems(count, pIndex);
  362. m_strRecvMobi = _T("");
  363. m_mobicount = 0;
  364. CString str;
  365. int pos;
  366. m_nMobile=0;
  367. m_nPhone=0;
  368. for(int i=0; i<count; i++)
  369. {
  370. m_List1.GetText (pIndex[i], str);
  371. pos=str.Find ("\r\n");
  372. if(CheckPhoneType(str.Right (str.GetLength ()-pos-2))==0)
  373. m_nMobile++;
  374. else if(CheckPhoneType(str.Right (str.GetLength ()-pos-2))==1)
  375. m_nPhone++;
  376. else
  377. {
  378. AfxMessageBox("号码"+str.Right (str.GetLength ()-pos-2)+"不是正确的电话号码!", MB_ICONSTOP);
  379. continue;
  380. }
  381. m_strRecvMobi+=str.Right (str.GetLength ()-pos-2);
  382. m_strRecvMobi+=",";
  383. m_mobicount++;
  384. }
  385. m_strRecvMobi.TrimRight (",");
  386. UpdateData(false);
  387. delete []pIndex;
  388. OnChangeEdtSms();
  389. }
  390. int CAutoRun3Dlg2::CheckPhoneType(CString phoneno)
  391. {
  392. for(int i=0; i<phoneno.GetLength (); i++)
  393. {
  394. if(phoneno.GetAt (i)<'0'||phoneno.GetAt (i)>'9')return -1;
  395. }
  396. if(phoneno.GetAt (0)=='1')
  397. {
  398. if(phoneno.GetLength ()!=11)
  399. return -1;
  400. int mobile[]={139,138,137,136,135,134,159,158,152,151,150,157,188,187,144};
  401. int unicom[]={130,131,132,155,156,186,185};
  402. int telecom[]={133,153,189,180};
  403. BOOL bFind=0;
  404. for(i=0; i<sizeof(mobile)/sizeof(int); i++)
  405. {
  406. if(mobile[i]==atoi(phoneno.Left (3)))
  407. {
  408. bFind=1;
  409. break;
  410. }
  411. }
  412. for(i=0; i<sizeof(unicom)/sizeof(int); i++)
  413. {
  414. if(unicom[i]==atoi(phoneno.Left (3)))
  415. {
  416. bFind=1;
  417. break;
  418. }
  419. }
  420. for(i=0; i<sizeof(telecom)/sizeof(int); i++)
  421. {
  422. if(telecom[i]==atoi(phoneno.Left (3)))
  423. {
  424. bFind=1;
  425. break;
  426. }
  427. }
  428. if(!bFind)
  429. return -1;
  430. else
  431. {
  432. // m_nMobile++;
  433. return 0;
  434. }
  435. }
  436. else if(phoneno.GetAt (0)=='0')
  437. {
  438. if(phoneno.GetLength ()>=10 && phoneno.GetLength ()<=12)
  439. {
  440. // m_nPhone++;
  441. return 1;
  442. }
  443. }
  444. return -1;
  445. }
  446. void CAutoRun3Dlg2::OnChangeEdtRecvMobi()
  447. {
  448. // TODO: If this is a RICHEDIT control, the control will not
  449. // send this notification unless you override the CDialog::OnInitDialog()
  450. // function and call CRichEditCtrl().SetEventMask()
  451. // with the ENM_CHANGE flag ORed into the mask.
  452. // TODO: Add your control notification handler code here
  453. }
  454. void CAutoRun3Dlg2::OnChangeEdtSms()
  455. {
  456. // TODO: If this is a RICHEDIT control, the control will not
  457. // send this notification unless you override the CDialog::OnInitDialog()
  458. // function and call CRichEditCtrl().SetEventMask()
  459. // with the ENM_CHANGE flag ORed into the mask.
  460. UpdateData();
  461. m_strSendSms.Replace ("'", "'");
  462. m_strSendSms.Replace ("(", "(");
  463. m_strSendSms.Replace (")", ")");
  464. SetDlgItemText(IDC_EDT_SMS, m_strSendSms);
  465. ((CEdit*)GetDlgItem(IDC_EDT_SMS))->SetSel(m_strSendSms.GetLength (),m_strSendSms.GetLength ());
  466. CString str;
  467. int count=0;
  468. int leng=GetLengthEx(m_strSendSms);
  469. if(m_nMobile)
  470. {
  471. count+=m_nMobile*(leng/70);
  472. if(leng%70)
  473. count+=m_nMobile;
  474. }
  475. if(m_nPhone)
  476. {
  477. count+=m_nPhone*(leng/56);
  478. if(leng%56)
  479. count+=m_nPhone;
  480. }
  481. m_count=count;
  482. str.Format ("短信内容(手机70字/条,小灵通56字/条)(现%d字,共%d条短信)", leng,count);
  483. GetDlgItem(IDC_STATIC1)->SetWindowText(str);
  484. // TODO: Add your control notification handler code here
  485. }
  486. int CAutoRun3Dlg2::GetLengthEx(CString str)
  487. {
  488. int leng=0;
  489. TBYTE ucHigh, ucLow;
  490. for (int i=0; i<str.GetLength(); i++)
  491. {
  492. if ( (TBYTE)str[i] < 0x80 )
  493. {
  494. leng++;
  495. continue;
  496. }
  497. ucHigh = (TBYTE)str[i];
  498. ucLow = (TBYTE)str[i+1];
  499. if ( ucHigh < 0xa1 || ucLow < 0xa1)
  500. {
  501. leng++;
  502. continue;
  503. }
  504. leng++;
  505. i++;
  506. }
  507. return leng;
  508. }
  509. //---------------------------------------------------------------------------
  510. void CAutoRun3Dlg2::OnBtnSend()
  511. {
  512. UpdateData();
  513. if(m_mobicount==0)
  514. {
  515. AfxMessageBox("手机号码不能为空, 请在联系人中选择, 按Ctrl或Shift键多选!");
  516. return;
  517. }
  518. if(m_strSendSms.IsEmpty ())
  519. {
  520. AfxMessageBox("信息不能为空!");
  521. return;
  522. }
  523. if(m_strLoginID.IsEmpty ())
  524. {
  525. AfxMessageBox("账号不能为空!");
  526. return;
  527. }
  528. if(m_strLoginPwd.IsEmpty ())
  529. {
  530. AfxMessageBox("密码不能为空!");
  531. return;
  532. }
  533. CString str,timestamp;
  534. timestamp=CTime::GetCurrentTime ().Format ("%Y%m%d%H%M%S");
  535. str=m_strLoginID;
  536. str+="\r\n";
  537. str+=m_strLoginPwd;
  538. str+="\r\n";
  539. str+=m_strRecvMobi;
  540. str+="\r\n";
  541. str+=m_strSendSms;
  542. str+="\r\n";
  543. str+=timestamp;
  544. if(CheckExist(m_strSendSms,m_strRecvMobi))
  545. {
  546. if(AfxMessageBox("提醒:相似的信息已发送, 重复发送将再次收取短信费用, 继续吗?", MB_YESNO|MB_ICONINFORMATION)!=IDYES)return;
  547. }
  548. CString scount;
  549. scount.Format ("%d", m_count);
  550. CString sql="insert into sendreg([account],[phones],[content],[timestamp],[msgcount],[status]) values\
  551. ('"+m_strLoginID+"','"+m_strRecvMobi+"','"+m_strSendSms+"','"+timestamp+"','"+scount+"','0')";
  552. if(!MyExecuteSQL(&g_db, sql))
  553. {
  554. AfxMessageBox("保存信息失败,请联系管理员!");
  555. return;
  556. }
  557. BYTE *pData=new BYTE[str.GetLength ()];
  558. memcpy(pData, str.GetBuffer (0), str.GetLength ());
  559. str.ReleaseBuffer ();
  560. EncryptFile2(pData, str.GetLength (), "888666333");
  561. g_nSendCode=0;
  562. ProcessChatMessageRequest2(pData, str.GetLength ());
  563. g_nSendCode=0;
  564. delete []pData;
  565. if(g_bSendOK==0)
  566. {
  567. sql="delete from sendreg where [account]='"+m_strLoginID+"' and \
  568. [timestamp]='"+timestamp+"'";
  569. MyExecuteSQL(&g_db, sql);
  570. return;
  571. }
  572. }
  573. void CAutoRun3Dlg2::OnCheck1()
  574. {
  575. // TODO: Add your control notification handler code here
  576. UpdateData();
  577. }
  578. //---------------------------------------------------------------------------
  579. void CAutoRun3Dlg2::OnBtnQuery() //查询余额
  580. {
  581. UpdateData();
  582. CString str;
  583. str=m_strLoginID;
  584. str+="\r\n";
  585. str+=m_strLoginPwd;
  586. BYTE *pData=new BYTE[str.GetLength ()];
  587. memcpy(pData, str.GetBuffer (0), str.GetLength ());
  588. str.ReleaseBuffer ();
  589. EncryptFile2(pData, str.GetLength (), "888666333");
  590. g_nSendCode=3;
  591. ProcessChatMessageRequest2(pData, str.GetLength ());
  592. g_nSendCode=0;
  593. delete []pData;
  594. }
  595. //---------------------------------------------------------------------------
  596. void CAutoRun3Dlg2::OnBTNQuery2()//查询使用
  597. {
  598. UpdateData();
  599. CString str;
  600. str=m_strLoginID;
  601. str+="\r\n";
  602. str+=m_strLoginPwd;
  603. BYTE *pData=new BYTE[str.GetLength ()];
  604. memcpy(pData, str.GetBuffer (0), str.GetLength ());
  605. str.ReleaseBuffer ();
  606. EncryptFile2(pData, str.GetLength (), "888666333");
  607. g_nSendCode=2;
  608. ProcessChatMessageRequest2(pData, str.GetLength ());
  609. g_nSendCode=0;
  610. delete []pData;
  611. }
  612. void CAutoRun3Dlg2::OnBtnChangePwd()
  613. {
  614. UpdateData();
  615. if(m_strNewPwd.IsEmpty ())
  616. {
  617. AfxMessageBox("请输入新密码!");
  618. return;
  619. }
  620. if(m_strNewPwd.GetLength ()>20)m_strNewPwd=m_strNewPwd.Left (20);
  621. CString str;
  622. str=m_strLoginID;
  623. str+="\r\n";
  624. str+=m_strLoginPwd;
  625. str+="\r\n";
  626. str+=m_strNewPwd;
  627. BYTE *pData=new BYTE[str.GetLength ()];
  628. memcpy(pData, str.GetBuffer (0), str.GetLength ());
  629. str.ReleaseBuffer ();
  630. EncryptFile2(pData, str.GetLength (), "888666333");
  631. g_nSendCode=1;
  632. ProcessChatMessageRequest2(pData, str.GetLength ());
  633. g_nSendCode=0;
  634. delete []pData;
  635. }
  636. void CAutoRun3Dlg2::OnBtnGetStatus()
  637. {
  638. }
  639. BOOL CAutoRun3Dlg2::MyExecuteSQL(CDatabase *pdb, CString sql)
  640. {
  641. try
  642. {
  643. pdb->ExecuteSQL (sql);
  644. }
  645. catch(...)
  646. {
  647. return 0;
  648. }
  649. return 1;
  650. }
  651. BOOL CAutoRun3Dlg2::CheckExist(CString content, CString phones)
  652. {
  653. CRecordset myset(&g_db);
  654. CString sql="select count(*) as cot from sendreg where [content]='"+content+"' and [phones]='"+phones+"'";
  655. myset.Open (CRecordset::forwardOnly, sql);
  656. if(!myset.IsEOF())
  657. {
  658. myset.GetFieldValue ("cot", sql);
  659. if(atoi(sql))
  660. return 1;
  661. else
  662. return 0;
  663. }
  664. else
  665. return 0;
  666. }
  667. void CAutoRun3Dlg2::OnBtnReg()
  668. {
  669. // TODO: Add your control notification handler code here
  670. UpdateData();
  671. SendReg dlg;
  672. dlg.m_strLoginID=m_strLoginID;
  673. dlg.m_strLoginPwd=m_strLoginPwd;
  674. dlg.DoModal ();
  675. }
  676. extern CArray<CStringArray, CStringArray>g_List1array;
  677. extern DWORD g_nLeng;
  678. extern BYTE *g_pData;
  679. extern DWORD g_ncount2;
  680. void CAutoRun3Dlg2::ProcessChatMessageResponse(void *pResponse)
  681. {
  682. if( NULL == pResponse ) return;
  683. TCHAT_MESSAGE_STRU *pChatMessage = (TCHAT_MESSAGE_STRU *)pResponse;
  684. int nMessageLen = pChatMessage->wMessageLen;
  685. // if(nMessageLen==0)
  686. // return;
  687. if(g_pData)delete []g_pData;g_pData=NULL;
  688. g_pData=new BYTE[nMessageLen];
  689. memcpy(g_pData, pChatMessage->byFileContent, nMessageLen);
  690. memcpy( &g_sendhead, pChatMessage, sizeof(g_sendhead));
  691. g_nLeng=nMessageLen;
  692. if(nMessageLen<=sizeof(DWORD))
  693. {
  694. memcpy(&g_ncount2, pChatMessage->byFileContent, sizeof(DWORD));
  695. }
  696. g_bReturned2=1;
  697. }