SendReg.cpp 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. // SendReg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "AutoRun.h"
  5. #include "SendReg.h"
  6. #include "mysqldata.h"
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #undef THIS_FILE
  10. static char THIS_FILE[] = __FILE__;
  11. #endif
  12. extern DWORD g_nSendCode;
  13. /////////////////////////////////////////////////////////////////////////////
  14. // SendReg dialog
  15. SendReg::SendReg(CWnd* pParent /*=NULL*/)
  16. : CDialog(SendReg::IDD, pParent)
  17. {
  18. //{{AFX_DATA_INIT(SendReg)
  19. // NOTE: the ClassWizard will add member initialization here
  20. //}}AFX_DATA_INIT
  21. m_times=0;
  22. }
  23. void SendReg::DoDataExchange(CDataExchange* pDX)
  24. {
  25. CDialog::DoDataExchange(pDX);
  26. //{{AFX_DATA_MAP(SendReg)
  27. DDX_Control(pDX, IDC_LIST1, m_List1);
  28. //}}AFX_DATA_MAP
  29. }
  30. BEGIN_MESSAGE_MAP(SendReg, CDialog)
  31. //{{AFX_MSG_MAP(SendReg)
  32. ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
  33. ON_WM_TIMER()
  34. //}}AFX_MSG_MAP
  35. END_MESSAGE_MAP()
  36. /////////////////////////////////////////////////////////////////////////////
  37. // SendReg message handlers
  38. BOOL SendReg::OnInitDialog()
  39. {
  40. CDialog::OnInitDialog();
  41. // TODO: Add extra initialization here
  42. m_List1.SetHeadings("账号,100;号码,100;内容,100;时间,100;费用,100;报告,100" );
  43. m_List1.LoadColumnInfo (119);
  44. OnButton1();
  45. return TRUE; // return TRUE unless you set the focus to a control
  46. // EXCEPTION: OCX Property Pages should return FALSE
  47. }
  48. void SendReg::OnButton1()
  49. {
  50. // TODO: Add your control notification handler code here
  51. GetDlgItem(IDC_BUTTON1)->EnableWindow(0);
  52. m_times=0;
  53. SetTimer(1, 1000, NULL);
  54. Refresh();
  55. CRecordset myset(&g_db);
  56. CString sql="select count(*) as cot from sendreg";
  57. myset.Open (CRecordset::forwardOnly, sql);
  58. myset.GetFieldValue ("cot", sql);
  59. myset.Close();
  60. m_List1array.SetSize(atol(sql) , 1 );
  61. RstSendReg rsSt;
  62. rsSt.Open();
  63. DWORD ii=0;
  64. while(!rsSt.IsEOF())
  65. {
  66. m_List1array.ElementAt (ii).RemoveAll ();
  67. m_List1array.ElementAt (ii).Add(rsSt.m_account) ;
  68. m_List1array.ElementAt (ii).Add(rsSt.m_phones) ;
  69. m_List1array.ElementAt (ii).Add(rsSt.m_content) ;
  70. m_List1array.ElementAt (ii).Add(rsSt.m_timestamp) ;
  71. m_List1array.ElementAt (ii).Add(rsSt.m_msgcount) ;
  72. m_List1array.ElementAt (ii).Add("发送:"+rsSt.m_log) ;
  73. ii++;
  74. rsSt.MoveNext();if(m_List1array.GetSize ()<=ii)break;
  75. }
  76. rsSt.Close();m_List1array.SetSize(ii , 1 );
  77. FillGrid();
  78. }
  79. void SendReg::FillGrid()
  80. {
  81. m_List1.DeleteAllItems2 ();
  82. int ii=0;
  83. m_List1.m_arLabels.SetSize( m_List1array.GetSize (), 1 );
  84. int count=0;
  85. for(ii=0; ii<m_List1.m_arLabels.GetSize (); ii++)
  86. {
  87. m_List1.m_arLabels.ElementAt (count++).Copy (m_List1array.ElementAt (ii));
  88. }
  89. m_List1.m_arLabels.SetSize(count, 1);
  90. ii=count;
  91. m_List1.m_LabelCount=ii;
  92. m_List1.SetItemCountEx (ii);
  93. }
  94. void SendReg::Refresh()
  95. {
  96. RstSendReg rsSt;
  97. rsSt.m_strFilter ="[status]<>'OK'";
  98. rsSt.Open();
  99. DWORD ii=0;
  100. CString timestamp="";
  101. CStringArray idarray;
  102. while(!rsSt.IsEOF())
  103. {
  104. timestamp+=rsSt.m_timestamp ;
  105. idarray.Add (rsSt.m_id);
  106. ii++;
  107. if(ii>9)break;
  108. rsSt.MoveNext();
  109. }
  110. rsSt.Close();
  111. if(timestamp.IsEmpty ())return;
  112. CString str;
  113. str=m_strLoginID;
  114. str+="\r\n";
  115. str+=m_strLoginPwd;
  116. str+="\r\n";
  117. str+=timestamp;
  118. BYTE *pData=new BYTE[str.GetLength ()];
  119. memcpy(pData, str.GetBuffer (0), str.GetLength ());
  120. str.ReleaseBuffer ();
  121. EncryptFile2(pData, str.GetLength (), "888666333");
  122. g_nSendCode=4;
  123. g_pMainWnd->ProcessChatMessageRequest2(pData, str.GetLength ());
  124. g_nSendCode=0;
  125. delete []pData;
  126. if(g_bSendOK==0)return;
  127. if(g_str.GetLength ())
  128. {
  129. CStringArray strarray;
  130. int pos=g_str.Find (",");
  131. if(pos!=-1)
  132. {
  133. strarray.Add(g_str.Left (pos));
  134. g_str=g_str.Right (g_str.GetLength ()-pos-1);
  135. pos=g_str.Find (",");
  136. while(pos!=-1)
  137. {
  138. strarray.Add (g_str.Left (pos));
  139. g_str=g_str.Right (g_str.GetLength ()-pos-1);
  140. pos=g_str.Find (",");
  141. }
  142. strarray.Add (g_str);
  143. }
  144. else
  145. strarray.Add (g_str);
  146. if(strarray.GetSize ()!=idarray.GetSize ())return;
  147. CString sql,sok;
  148. for(int i=0; i<strarray.GetSize (); i++)
  149. {
  150. str=strarray.ElementAt (i);
  151. pos=str.Find ('/');
  152. if(pos==-1)continue;
  153. if(str.Left (pos)==str.Right (str.GetLength ()-pos-1) && atoi(str.Left (pos))!=0)
  154. sok="OK";
  155. else
  156. sok="0";
  157. sql.Format("update sendreg set [log]='"+str+"',[status]='"+sok+"' where [autoid]=%d", atol(idarray.ElementAt (i)));
  158. g_db.ExecuteSQL (sql);
  159. }
  160. }
  161. }
  162. void SendReg::OnTimer(UINT nIDEvent)
  163. {
  164. // TODO: Add your message handler code here and/or call default
  165. m_times++;
  166. if(m_times>10)
  167. {
  168. KillTimer(nIDEvent);
  169. GetDlgItem(IDC_BUTTON1)->EnableWindow(1);
  170. GetDlgItem(IDC_BUTTON1)->SetWindowText("刷新");
  171. return;
  172. }
  173. CString str;
  174. str.Format ("刷新(%d)", 11-m_times);
  175. GetDlgItem(IDC_BUTTON1)->SetWindowText(str);
  176. }