ReCharge.cpp 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. // ReCharge.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "LYFZSendMsg.h"
  5. #include "ReCharge.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #undef THIS_FILE
  9. static char THIS_FILE[] = __FILE__;
  10. #endif
  11. /////////////////////////////////////////////////////////////////////////////
  12. // ReCharge dialog
  13. ReCharge::ReCharge(CWnd* pParent /*=NULL*/)
  14. : CDialog(ReCharge::IDD, pParent)
  15. {
  16. //{{AFX_DATA_INIT(ReCharge)
  17. m_account = _T("");
  18. m_name = _T("");
  19. m_money = _T("");
  20. m_count = _T("");
  21. m_price = _T("");
  22. //}}AFX_DATA_INIT
  23. }
  24. void ReCharge::DoDataExchange(CDataExchange* pDX)
  25. {
  26. CDialog::DoDataExchange(pDX);
  27. //{{AFX_DATA_MAP(ReCharge)
  28. DDX_Control(pDX, IDC_EDITcount, m_editnum2);
  29. DDX_Control(pDX, IDC_EDITmoney, m_editnum1);
  30. DDX_Text(pDX, IDC_EDITaccount, m_account);
  31. DDX_Text(pDX, IDC_EDITname, m_name);
  32. DDX_Text(pDX, IDC_EDITmoney, m_money);
  33. DDX_Text(pDX, IDC_EDITcount, m_count);
  34. DDX_Text(pDX, IDC_EDITprice, m_price);
  35. //}}AFX_DATA_MAP
  36. }
  37. BEGIN_MESSAGE_MAP(ReCharge, CDialog)
  38. //{{AFX_MSG_MAP(ReCharge)
  39. ON_EN_CHANGE(IDC_EDITmoney, OnChangeEDITmoney)
  40. ON_EN_CHANGE(IDC_EDITcount, OnChangeEDITcount)
  41. //}}AFX_MSG_MAP
  42. END_MESSAGE_MAP()
  43. /////////////////////////////////////////////////////////////////////////////
  44. // ReCharge message handlers
  45. BOOL ReCharge::OnInitDialog()
  46. {
  47. CDialog::OnInitDialog();
  48. // TODO: Add extra initialization here
  49. /* CRecordset myset(&g_db);
  50. CString sql="select ReCharge from ReCharge";
  51. myset.Open (CRecordset::forwardOnly, sql);
  52. myset.GetFieldValue ("ReCharge", m_oldReCharge);
  53. myset.Close();
  54. this->CenterWindow (g_pMainWnd);*/
  55. return TRUE; // return TRUE unless you set the focus to a control
  56. // EXCEPTION: OCX Property Pages should return FALSE
  57. }
  58. void ReCharge::OnChangeEDITmoney()
  59. {
  60. // TODO: If this is a RICHEDIT control, the control will not
  61. // send this notification unless you override the CDialog::OnInitDialog()
  62. // function and call CRichEditCtrl().SetEventMask()
  63. // with the ENM_CHANGE flag ORed into the mask.
  64. UpdateData();
  65. if(atof(m_count))
  66. {
  67. m_price.Format ("%0.4f", atof(m_money)/atof(m_count));
  68. }
  69. else
  70. m_price="0";
  71. UpdateData(false);
  72. // TODO: Add your control notification handler code here
  73. }
  74. void ReCharge::OnChangeEDITcount()
  75. {
  76. // TODO: If this is a RICHEDIT control, the control will not
  77. // send this notification unless you override the CDialog::OnInitDialog()
  78. // function and call CRichEditCtrl().SetEventMask()
  79. // with the ENM_CHANGE flag ORed into the mask.
  80. OnChangeEDITmoney();
  81. // TODO: Add your control notification handler code here
  82. }
  83. void ReCalAccount(CString account)
  84. {
  85. CString sql;
  86. if(1)
  87. {
  88. MyLock lock("xiaoaccessdbmsg");
  89. CRecordset myset(&g_db);
  90. CString count1,count2,count3;
  91. #ifdef SQLSERVER_VERSION
  92. sql="select sum(cast([count] as float)) as cot from recharge where account='"+account+"'";
  93. #else
  94. sql="select sum([count]) as cot from recharge where account='"+account+"'";
  95. #endif
  96. myset.Open (CRecordset::forwardOnly, sql);
  97. if(!myset.IsEOF())
  98. myset.GetFieldValue ("cot", count1);
  99. myset.Close();
  100. #ifdef SQLSERVER_VERSION
  101. sql="select sum(cast([msgcount] as float)) as cot from sendreg where account='"+account+"'";
  102. #else
  103. sql="select sum([msgcount]) as cot from sendreg where account='"+account+"'";
  104. #endif
  105. myset.Open (CRecordset::forwardOnly, sql);
  106. if(!myset.IsEOF())
  107. myset.GetFieldValue ("cot", count2);
  108. myset.Close();
  109. #ifdef SQLSERVER_VERSION
  110. sql="select sum(cast([msgcount2] as float)) as cot from sendreg where account='"+account+"'";
  111. #else
  112. sql="select sum([msgcount2]) as cot from sendreg where account='"+account+"'";
  113. #endif
  114. myset.Open (CRecordset::forwardOnly, sql);
  115. if(!myset.IsEOF())
  116. myset.GetFieldValue ("cot", count3);
  117. myset.Close();
  118. // sql.Format ("update clientinfo set balance='%d' where account='%s'", atoi(count1)-min(atoi(count2),atoi(count3)), account);
  119. sql.Format ("update clientinfo set balance='%d' where account='%s'", atoi(count1)-atoi(count2), account);
  120. }
  121. MyExecuteSQL(&g_db, sql);
  122. }
  123. void ReCharge::OnOK()
  124. {
  125. // TODO: Add extra validation here
  126. UpdateData();
  127. m_count.TrimLeft ();
  128. m_count.TrimRight ();
  129. m_money.TrimLeft ();
  130. m_money.TrimRight ();
  131. if(atoi(m_count)==0)
  132. {
  133. AfxMessageBox("短信条数不能为0!", MB_ICONINFORMATION);
  134. return;
  135. }
  136. CString timestamp=CTime::GetCurrentTime ().Format ("%Y-%m-%d");
  137. CString sql;
  138. sql="insert into recharge([account],[money],[count],[timestamp]) values('"+m_account+"','"+m_money+"','"+m_count+"','"+timestamp+"')";
  139. // MyLock lock("msgaccessdb");
  140. MyExecuteSQL(&g_db, sql);
  141. ReCalAccount(m_account);
  142. AfxMessageBox("充值成功!", MB_ICONINFORMATION);
  143. sql="delete from nullbalance where [account]='"+m_account+"'";
  144. MyExecuteSQL(&g_db, sql);
  145. CDialog::OnOK();
  146. }