// SetChildMsg.cpp : implementation file // #include "stdafx.h" #include "ylgl.h" #include "SetChildMsg.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // SetChildMsg dialog SetChildMsg::SetChildMsg(CWnd* pParent /*=NULL*/) : CDialog(SetChildMsg::IDD, pParent) { m_check1 = FALSE; m_days = _T(""); m_content = _T(""); m_mode = 0; } void SetChildMsg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); DDX_Control(pDX, IDC_COMBO1, m_combo1); DDX_Control(pDX, IDC_LIST1, m_List1); DDX_Check(pDX, IDC_CHECK1, m_check1); DDX_CBString(pDX, IDC_COMBO1, m_days); DDX_Text(pDX, IDC_EDIT1, m_content); } BEGIN_MESSAGE_MAP(SetChildMsg, CDialog) ON_LBN_SELCHANGE(IDC_LIST1, OnSelchangeList1) ON_BN_CLICKED(IDC_BUTadd, OnBUTadd) ON_BN_CLICKED(IDC_BUTdel, OnBUTdel) ON_EN_CHANGE(IDC_EDIT1, OnChangeEdit1) END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // SetChildMsg message handlers BOOL SetChildMsg::OnInitDialog() { CDialog::OnInitDialog(); if (m_mode == 1 || m_mode == 0) { SetWindowText("宝宝成长跟踪短信"); m_combo1.AddString("一周"); m_combo1.AddString("两周"); m_combo1.AddString("三周"); m_combo1.AddString("满月"); m_combo1.AddString("两个月"); m_combo1.AddString("三个月"); m_combo1.AddString("六个月"); m_combo1.AddString("一岁"); m_combo1.AddString("两岁"); m_combo1.AddString("三岁"); } else if (m_mode == 2) { SetWindowText("怀孕周期提醒短信"); GetDlgItem(IDC_STATIC2)->SetWindowText("怀孕满(x天):"); m_combo1.AddString("一周"); m_combo1.AddString("两周"); m_combo1.AddString("三周"); m_combo1.AddString("一个月"); m_combo1.AddString("两个月"); m_combo1.AddString("三个月"); m_combo1.AddString("六个月"); m_combo1.AddString("七个月"); m_combo1.AddString("八个月"); m_combo1.AddString("九个月"); } GetData(); return TRUE; } void SetChildMsg::OnSelchangeList1() { int pos = m_List1.GetCurSel(); if (pos == -1) { m_olddays = ""; return; } m_days = daysarray.ElementAt(pos); m_olddays = m_days; m_content = contentarray.ElementAt(pos); m_check1 = checkarray.ElementAt(pos); UpdateData(false); } void SetChildMsg::OnBUTadd() { UpdateData(); m_days.TrimLeft(); m_days.TrimRight(); if (m_days.IsEmpty()) { AfxMessageBox("天数不能为空!", MB_ICONINFORMATION); return; } if (m_content.IsEmpty()) { AfxMessageBox("内容不能为空!", MB_ICONINFORMATION); return; } CString sql; if (m_days != m_olddays) { if (::FindArray(&daysarray, m_days) != -1) { AfxMessageBox("已有此天数的记录!", MB_ICONINFORMATION); return; } sql.Format("insert into [childmsg]([check],[days],[content],[mode])values('%d','%s','%s','%d')", m_check1, m_days, m_content, m_mode); } else { sql.Format("update [childmsg] set [check]='%d',[content]='%s' where [days]='%s' and [mode]='%d'", m_check1, m_content, m_days, m_mode); } g_sendhead.bsql = 1; g_pMainWnd->ProcessChatMessageRequest2(sql); if (g_bSendOK == 0)return; GetData(); } void SetChildMsg::OnBUTdel() { int pos = m_List1.GetCurSel(); if (pos == -1) { AfxMessageBox("请选中您要删除的项目!", MB_ICONINFORMATION); return; } if (AfxMessageBox("确认删除吗?", MB_ICONINFORMATION | MB_YESNO) != IDYES)return; CString sql; CString days = daysarray.ElementAt(pos); sql.Format("delete from [childmsg] where [days]='%s' and [mode]='%d'", days, m_mode); g_sendhead.bsql = 1; g_pMainWnd->ProcessChatMessageRequest2(sql); if (g_bSendOK == 0)return; m_List1.DeleteString(pos); daysarray.RemoveAt(pos); contentarray.RemoveAt(pos); checkarray.RemoveAt(pos); } void SetChildMsg::OnChangeEdit1() { UpdateData(); m_content.Replace("'", "'"); m_content.Replace("(", "("); m_content.Replace(")", ")"); UpdateData(false); CString str; int count = 0; int leng = GetLengthEx(m_content) + 7; count += (leng / MSG_LENGTH); if (leng%MSG_LENGTH) count += 1; str.Format("内容:%d字/条,现%d字,共%d条)", MSG_LENGTH, leng, count); GetDlgItem(IDC_STATIC1)->SetWindowText(str); } BOOL SetChildMsg::HasDay(CString days) { CString str; for (int i = 0; i < m_combo1.GetCount(); i++) { m_combo1.GetLBText(i, str); if (days == str)return 0; } return 1; } void SetChildMsg::GetData() { g_sendhead.bsql = 0; g_sendhead.code[0] = 177; g_sendhead.tabcount = 1; CString filter; filter.Format("mode='%d'", m_mode); g_pMainWnd->ProcessChatMessageRequest2(filter); if (g_bSendOK == 0) { CDialog::OnCancel(); return; } DataToArray(&g_List1array); CenterWindow(); checkarray.RemoveAll(); daysarray.RemoveAll(); contentarray.RemoveAll(); m_List1.ResetContent(); for (int i = 0; i < g_List1array.GetSize(); i++) { checkarray.Add(atoi(g_List1array.ElementAt(i).ElementAt(0))); daysarray.Add(g_List1array.ElementAt(i).ElementAt(1)); contentarray.Add(g_List1array.ElementAt(i).ElementAt(2)); CString str; if (atoi(g_List1array.ElementAt(i).ElementAt(0))) str.Format(_T("自动发送-宝宝满%s"), g_List1array.ElementAt(i).ElementAt(1)); else str.Format(_T("未开启-宝宝满%s"), g_List1array.ElementAt(i).ElementAt(1)); if (m_mode == 2) { if (atoi(g_List1array.ElementAt(i).ElementAt(0))) str.Format(_T("自动发送-怀孕满%s"), g_List1array.ElementAt(i).ElementAt(1)); else str.Format(_T("未开启-怀孕满%s"), g_List1array.ElementAt(i).ElementAt(1)); } if (HasDay(g_List1array.ElementAt(i).ElementAt(1))) str += "天短信"; else str += "短信"; m_List1.AddString(str); } }