SetChildMsg.cpp 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. // SetChildMsg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "ylgl.h"
  5. #include "SetChildMsg.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #undef THIS_FILE
  9. static char THIS_FILE[] = __FILE__;
  10. #endif
  11. /////////////////////////////////////////////////////////////////////////////
  12. // SetChildMsg dialog
  13. SetChildMsg::SetChildMsg(CWnd* pParent /*=NULL*/) : CDialog(SetChildMsg::IDD, pParent)
  14. {
  15. m_check1 = FALSE;
  16. m_days = _T("");
  17. m_content = _T("");
  18. m_mode = 0;
  19. }
  20. void SetChildMsg::DoDataExchange(CDataExchange* pDX)
  21. {
  22. CDialog::DoDataExchange(pDX);
  23. DDX_Control(pDX, IDC_COMBO1, m_combo1);
  24. DDX_Control(pDX, IDC_LIST1, m_List1);
  25. DDX_Check(pDX, IDC_CHECK1, m_check1);
  26. DDX_CBString(pDX, IDC_COMBO1, m_days);
  27. DDX_Text(pDX, IDC_EDIT1, m_content);
  28. }
  29. BEGIN_MESSAGE_MAP(SetChildMsg, CDialog)
  30. ON_LBN_SELCHANGE(IDC_LIST1, OnSelchangeList1)
  31. ON_BN_CLICKED(IDC_BUTadd, OnBUTadd)
  32. ON_BN_CLICKED(IDC_BUTdel, OnBUTdel)
  33. ON_EN_CHANGE(IDC_EDIT1, OnChangeEdit1)
  34. END_MESSAGE_MAP()
  35. /////////////////////////////////////////////////////////////////////////////
  36. // SetChildMsg message handlers
  37. BOOL SetChildMsg::OnInitDialog()
  38. {
  39. CDialog::OnInitDialog();
  40. if (m_mode == 1 || m_mode == 0)
  41. {
  42. SetWindowText("宝宝成长跟踪短信");
  43. m_combo1.AddString("一周");
  44. m_combo1.AddString("两周");
  45. m_combo1.AddString("三周");
  46. m_combo1.AddString("满月");
  47. m_combo1.AddString("两个月");
  48. m_combo1.AddString("三个月");
  49. m_combo1.AddString("六个月");
  50. m_combo1.AddString("一岁");
  51. m_combo1.AddString("两岁");
  52. m_combo1.AddString("三岁");
  53. }
  54. else if (m_mode == 2)
  55. {
  56. SetWindowText("怀孕周期提醒短信");
  57. GetDlgItem(IDC_STATIC2)->SetWindowText("怀孕满(x天):");
  58. m_combo1.AddString("一周");
  59. m_combo1.AddString("两周");
  60. m_combo1.AddString("三周");
  61. m_combo1.AddString("一个月");
  62. m_combo1.AddString("两个月");
  63. m_combo1.AddString("三个月");
  64. m_combo1.AddString("六个月");
  65. m_combo1.AddString("七个月");
  66. m_combo1.AddString("八个月");
  67. m_combo1.AddString("九个月");
  68. }
  69. GetData();
  70. return TRUE;
  71. }
  72. void SetChildMsg::OnSelchangeList1()
  73. {
  74. int pos = m_List1.GetCurSel();
  75. if (pos == -1)
  76. {
  77. m_olddays = "";
  78. return;
  79. }
  80. m_days = daysarray.ElementAt(pos);
  81. m_olddays = m_days;
  82. m_content = contentarray.ElementAt(pos);
  83. m_check1 = checkarray.ElementAt(pos);
  84. UpdateData(false);
  85. }
  86. void SetChildMsg::OnBUTadd()
  87. {
  88. UpdateData();
  89. m_days.TrimLeft();
  90. m_days.TrimRight();
  91. if (m_days.IsEmpty())
  92. {
  93. AfxMessageBox("天数不能为空!", MB_ICONINFORMATION);
  94. return;
  95. }
  96. if (m_content.IsEmpty())
  97. {
  98. AfxMessageBox("内容不能为空!", MB_ICONINFORMATION);
  99. return;
  100. }
  101. CString sql;
  102. if (m_days != m_olddays)
  103. {
  104. if (::FindArray(&daysarray, m_days) != -1)
  105. {
  106. AfxMessageBox("已有此天数的记录!", MB_ICONINFORMATION);
  107. return;
  108. }
  109. sql.Format("insert into [childmsg]([check],[days],[content],[mode])values('%d','%s','%s','%d')", m_check1, m_days, m_content, m_mode);
  110. }
  111. else
  112. {
  113. sql.Format("update [childmsg] set [check]='%d',[content]='%s' where [days]='%s' and [mode]='%d'", m_check1, m_content, m_days, m_mode);
  114. }
  115. g_sendhead.bsql = 1;
  116. g_pMainWnd->ProcessChatMessageRequest2(sql); if (g_bSendOK == 0)return;
  117. GetData();
  118. }
  119. void SetChildMsg::OnBUTdel()
  120. {
  121. int pos = m_List1.GetCurSel();
  122. if (pos == -1)
  123. {
  124. AfxMessageBox("请选中您要删除的项目!", MB_ICONINFORMATION);
  125. return;
  126. }
  127. if (AfxMessageBox("确认删除吗?", MB_ICONINFORMATION | MB_YESNO) != IDYES)return;
  128. CString sql;
  129. CString days = daysarray.ElementAt(pos);
  130. sql.Format("delete from [childmsg] where [days]='%s' and [mode]='%d'", days, m_mode);
  131. g_sendhead.bsql = 1;
  132. g_pMainWnd->ProcessChatMessageRequest2(sql); if (g_bSendOK == 0)return;
  133. m_List1.DeleteString(pos);
  134. daysarray.RemoveAt(pos);
  135. contentarray.RemoveAt(pos);
  136. checkarray.RemoveAt(pos);
  137. }
  138. void SetChildMsg::OnChangeEdit1()
  139. {
  140. UpdateData();
  141. m_content.Replace("'", "'");
  142. m_content.Replace("(", "(");
  143. m_content.Replace(")", ")");
  144. UpdateData(false);
  145. CString str;
  146. int count = 0;
  147. int leng = GetLengthEx(m_content) + 7;
  148. count += (leng / MSG_LENGTH);
  149. if (leng%MSG_LENGTH)
  150. count += 1;
  151. str.Format("内容:%d字/条,现%d字,共%d条)", MSG_LENGTH, leng, count);
  152. GetDlgItem(IDC_STATIC1)->SetWindowText(str);
  153. }
  154. BOOL SetChildMsg::HasDay(CString days)
  155. {
  156. CString str;
  157. for (int i = 0; i < m_combo1.GetCount(); i++)
  158. {
  159. m_combo1.GetLBText(i, str);
  160. if (days == str)return 0;
  161. }
  162. return 1;
  163. }
  164. void SetChildMsg::GetData()
  165. {
  166. g_sendhead.bsql = 0;
  167. g_sendhead.code[0] = 177;
  168. g_sendhead.tabcount = 1;
  169. CString filter;
  170. filter.Format("mode='%d'", m_mode);
  171. g_pMainWnd->ProcessChatMessageRequest2(filter);
  172. if (g_bSendOK == 0)
  173. {
  174. CDialog::OnCancel();
  175. return;
  176. }
  177. DataToArray(&g_List1array);
  178. CenterWindow();
  179. checkarray.RemoveAll();
  180. daysarray.RemoveAll();
  181. contentarray.RemoveAll();
  182. m_List1.ResetContent();
  183. for (int i = 0; i < g_List1array.GetSize(); i++)
  184. {
  185. checkarray.Add(atoi(g_List1array.ElementAt(i).ElementAt(0)));
  186. daysarray.Add(g_List1array.ElementAt(i).ElementAt(1));
  187. contentarray.Add(g_List1array.ElementAt(i).ElementAt(2));
  188. CString str;
  189. if (atoi(g_List1array.ElementAt(i).ElementAt(0)))
  190. str.Format(_T("自动发送-宝宝满%s"), g_List1array.ElementAt(i).ElementAt(1));
  191. else
  192. str.Format(_T("未开启-宝宝满%s"), g_List1array.ElementAt(i).ElementAt(1));
  193. if (m_mode == 2)
  194. {
  195. if (atoi(g_List1array.ElementAt(i).ElementAt(0)))
  196. str.Format(_T("自动发送-怀孕满%s"), g_List1array.ElementAt(i).ElementAt(1));
  197. else
  198. str.Format(_T("未开启-怀孕满%s"), g_List1array.ElementAt(i).ElementAt(1));
  199. }
  200. if (HasDay(g_List1array.ElementAt(i).ElementAt(1)))
  201. str += "天短信";
  202. else
  203. str += "短信";
  204. m_List1.AddString(str);
  205. }
  206. }