SetChildMsg.cpp 6.2 KB

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