FindMessageDlg.cpp
上传用户:yffx2008
上传日期:2014-10-12
资源大小:12414k
文件大小:6k
源码类别:

交通/航空行业

开发平台:

Visual C++

  1. // FindMessageDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "GpsSC.h"
  5. #include "FindMessageDlg.h"
  6. #include "ClientinfoSet.h"
  7. #include "VehicleMessageSet.h"
  8. #ifdef _DEBUG
  9. #define new DEBUG_NEW
  10. #undef THIS_FILE
  11. static char THIS_FILE[] = __FILE__;
  12. #endif
  13. /////////////////////////////////////////////////////////////////////////////
  14. // CFindMessageDlg dialog
  15. CFindMessageDlg::CFindMessageDlg(CWnd* pParent /*=NULL*/)
  16. : CDialog(CFindMessageDlg::IDD, pParent)
  17. {
  18. //{{AFX_DATA_INIT(CFindMessageDlg)
  19. m_findHour = _T("");
  20. m_findDay = _T("");
  21. m_findMonth = _T("");
  22. m_findYear = _T("");
  23. m_findCarPhone = _T("");
  24. //}}AFX_DATA_INIT
  25. m_strTime="";
  26. }
  27. void CFindMessageDlg::DoDataExchange(CDataExchange* pDX)
  28. {
  29. CDialog::DoDataExchange(pDX);
  30. //{{AFX_DATA_MAP(CFindMessageDlg)
  31. DDX_Control(pDX, IDC_FIND_MONTH, m_ControlMonth);
  32. DDX_Control(pDX, IDC_MESSAGELIST, m_listctrl);
  33. DDX_CBString(pDX, IDC_FIND_HOUR, m_findHour);
  34. DDX_CBString(pDX, IDC_FIND_DAY, m_findDay);
  35. DDX_CBString(pDX, IDC_FIND_MONTH, m_findMonth);
  36. DDX_CBString(pDX, IDC_FIND_YEAR, m_findYear);
  37. DDX_Text(pDX, IDC_FIND_CARPHONE, m_findCarPhone);
  38. //}}AFX_DATA_MAP
  39. }
  40. BEGIN_MESSAGE_MAP(CFindMessageDlg, CDialog)
  41. //{{AFX_MSG_MAP(CFindMessageDlg)
  42. ON_BN_CLICKED(IDC_FINDMESSAGE, OnFindmessage)
  43. ON_WM_LBUTTONDOWN()
  44. ON_WM_CLOSE()
  45. ON_CBN_EDITCHANGE(IDC_FIND_YEAR, OnEditchangeFindYear)
  46. ON_BN_CLICKED(IDC_DELETEMESSAGE, OnDeletemessage)
  47. //}}AFX_MSG_MAP
  48. END_MESSAGE_MAP()
  49. /////////////////////////////////////////////////////////////////////////////
  50. // CFindMessageDlg message handlers
  51. BOOL CFindMessageDlg::OnInitDialog() 
  52. {
  53. CDialog::OnInitDialog();
  54. // TODO: Add extra initialization here
  55. m_listctrl.SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES|LVS_OWNERDATA);
  56. m_listctrl.InsertColumn(0,"司机", LVCFMT_CENTER,50);
  57. m_listctrl.InsertColumn(1,"车牌号码", LVCFMT_CENTER,80);
  58. m_listctrl.InsertColumn(2,"车载电话", LVCFMT_CENTER,80);
  59. m_listctrl.InsertColumn(3,"收到消息时间", LVCFMT_CENTER,100);
  60. m_listctrl.InsertColumn(4,"汽车状态", LVCFMT_CENTER,80);
  61. m_listctrl.InsertColumn(5,"汽车位置", LVCFMT_CENTER,80);
  62. m_listctrl.InsertColumn(6,"速度", LVCFMT_CENTER,80);
  63. m_listctrl.InsertColumn(7,"纬度", LVCFMT_CENTER,80);
  64. m_listctrl.InsertColumn(8,"经度", LVCFMT_CENTER,80);
  65. return TRUE;  // return TRUE unless you set the focus to a control
  66.               // EXCEPTION: OCX Property Pages should return FALSE
  67. }
  68. void CFindMessageDlg::OnFindmessage() 
  69. {
  70. // TODO: Add your control notification handler code here
  71. CVehicleMessageSet messageSet;
  72. CClientinfoSet clientinfoSet;
  73. CString str_ClientName,str_CarNumber;
  74. BOOL opinion1,opinion2;
  75. UpdateData(TRUE);
  76. m_strFindYear = m_findYear;
  77. m_strFindMonth = m_findMonth;
  78. m_strFindDay = m_findDay;
  79. m_strFindHour = m_findHour;
  80. m_strFindCarPhone = m_findCarPhone;
  81. if(m_findYear!="")
  82. m_strTime=m_findYear.Right(2)+'/';
  83. if(m_findMonth!="")
  84. m_strTime+=m_findMonth+'/';
  85. if(m_findDay!="")
  86. m_strTime+=m_findDay+',';
  87. if(m_findHour!="")
  88. m_strTime+=m_findHour;
  89. //判断条件
  90. opinion1=opinion2=FALSE;
  91. m_listctrl.DeleteAllItems();
  92. int length=m_strTime.GetLength();
  93. try
  94. {
  95. if(!messageSet.IsOpen())
  96. messageSet.Open();
  97. if(!messageSet.IsEOF())
  98. messageSet.MoveFirst();
  99. while(!messageSet.IsEOF())
  100. {
  101. int m_nItemCount = m_listctrl.GetItemCount();
  102. //判断条件,编辑框为空默认为符合条件
  103. //车载电话
  104. if((m_findCarPhone=="")||(m_findCarPhone.Right(11)==messageSet.m_CarPhone.Right(11)))
  105. opinion1=TRUE;
  106. //只判断有选择的日期
  107. if((m_strTime=="")||(m_strTime==messageSet.m_Time.Left(length)))
  108. opinion2=TRUE;
  109. if((opinion1)&&(opinion2))
  110. {
  111. //客户姓名、车牌号码
  112. clientinfoSet.FindClientinfo(messageSet.m_CarPhone.Right(11),str_ClientName,str_CarNumber);
  113. m_listctrl.InsertItem(m_nItemCount, str_ClientName);
  114. m_listctrl.SetItemText(m_nItemCount,1, str_CarNumber);
  115. m_listctrl.SetItemText(m_nItemCount,2, messageSet.m_CarPhone);
  116. m_listctrl.SetItemText(m_nItemCount,3, messageSet.m_Time);
  117. m_listctrl.SetItemText(m_nItemCount,4, messageSet.m_CarEstate);
  118. m_listctrl.SetItemText(m_nItemCount,5, messageSet.m_CarPlace);
  119. m_listctrl.SetItemText(m_nItemCount,6, messageSet.m_Speed);
  120. m_listctrl.SetItemText(m_nItemCount,7, messageSet.m_Longitude);
  121. m_listctrl.SetItemText(m_nItemCount,8, messageSet.m_Latitude);
  122. }
  123. opinion1=opinion2=FALSE;
  124. str_ClientName=str_CarNumber="";
  125. messageSet.MoveNext();
  126. }
  127. }
  128. catch(CDBException *Exp)
  129. {
  130. AfxMessageBox(Exp->m_strError);
  131. }
  132. }
  133. void CFindMessageDlg::OnLButtonDown(UINT nFlags, CPoint point) 
  134. {
  135. // TODO: Add your message handler code here and/or call default
  136. CDialog::OnLButtonDown(nFlags, point);
  137. }
  138. void CFindMessageDlg::OnClose() 
  139. {
  140. // TODO: Add your message handler code here and/or call default
  141. CDialog::OnClose();
  142. }
  143. void CFindMessageDlg::OnEditchangeFindYear() 
  144. {
  145. // TODO: Add your control notification handler code here
  146. }
  147. void CFindMessageDlg::OnDeletemessage() 
  148. {
  149. // TODO: Add your control notification handler code here
  150. CVehicleMessageSet messageSet;
  151. int nItemCount = m_listctrl.GetItemCount();
  152. if(nItemCount<0)
  153. {
  154. AfxMessageBox("请选择要删除的记录");
  155. return;
  156. }
  157. BOOL opinion1,opinion2;
  158. UpdateData(TRUE);
  159. m_strFindYear = m_findYear;
  160. m_strFindMonth = m_findMonth;
  161. m_strFindDay = m_findDay;
  162. m_strFindHour = m_findHour;
  163. m_strFindCarPhone = m_findCarPhone;
  164. if(m_strFindYear!="")
  165. m_strTime=m_findYear.Right(2)+'/';
  166. if(m_strFindMonth!="")
  167. m_strTime+=m_findMonth+'/';
  168. if(m_strFindDay!="")
  169. m_strTime+=m_findDay+',';
  170. if(m_strFindHour!="")
  171. m_strTime+=m_findHour;
  172. //判断条件
  173. opinion1=opinion2=FALSE;
  174. int length=m_strTime.GetLength();
  175. try
  176. {
  177. if(!messageSet.IsOpen())
  178. messageSet.Open();
  179. if(!messageSet.IsEOF())
  180. messageSet.MoveFirst();
  181. while(!messageSet.IsEOF())
  182. {
  183. //判断条件,编辑框为空默认为符合条件
  184. //车载电话
  185. if((m_findCarPhone=="")||(m_findCarPhone.Right(11)==messageSet.m_CarPhone.Right(11)))
  186. opinion1=TRUE;
  187. //只判断有选择的日期
  188. if((m_strTime=="")||(m_strTime==messageSet.m_Time.Left(length)))
  189. opinion2=TRUE;
  190. if((opinion1)&&(opinion2))
  191. {
  192. messageSet.Delete();
  193. }
  194. opinion1=opinion2=FALSE;
  195. messageSet.MoveNext();
  196. }
  197. }
  198. catch(CDBException *Exp)
  199. {
  200. AfxMessageBox(Exp->m_strError);
  201. }
  202. m_listctrl.DeleteAllItems();
  203. AfxMessageBox("删除记录成功!");
  204. }