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

交通/航空行业

开发平台:

Visual C++

  1. // ShowAllClientDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "GpsSC.h"
  5. #include "ShowAllClientDlg.h"
  6. #include "ClientinfoSet.h"
  7. #include "EditclientinfoDlg.h"
  8. #include "MainFrm.h"
  9. #ifdef _DEBUG
  10. #define new DEBUG_NEW
  11. #undef THIS_FILE
  12. static char THIS_FILE[] = __FILE__;
  13. #endif
  14. //extern CGpsSCApp theApp;       // 在此引用应用类中的theApp来获取库连接指针
  15. /////////////////////////////////////////////////////////////////////////////
  16. // CShowAllClientDlg dialog
  17. CShowAllClientDlg::CShowAllClientDlg(CWnd* pParent /*=NULL*/)
  18. : CDialog(CShowAllClientDlg::IDD, pParent)
  19. {
  20. //{{AFX_DATA_INIT(CShowAllClientDlg)
  21. // NOTE: the ClassWizard will add member initialization here
  22. //}}AFX_DATA_INIT
  23. showallinfo = FALSE;
  24. }
  25. void CShowAllClientDlg::DoDataExchange(CDataExchange* pDX)
  26. {
  27. CDialog::DoDataExchange(pDX);
  28. //{{AFX_DATA_MAP(CShowAllClientDlg)
  29. DDX_Control(pDX, IDC_LIST1, m_listctrl);
  30. //}}AFX_DATA_MAP
  31. }
  32. BEGIN_MESSAGE_MAP(CShowAllClientDlg, CDialog)
  33. //{{AFX_MSG_MAP(CShowAllClientDlg)
  34. ON_BN_CLICKED(IDC_DELETECLIENT, OnDeleteclient)
  35. ON_BN_CLICKED(IDC_EDITCLIENT, OnEditclient)
  36. ON_WM_LBUTTONDBLCLK()
  37. ON_NOTIFY(NM_DBLCLK, IDC_LIST1, OnDblclkList1)
  38. ON_WM_CLOSE()
  39. ON_BN_CLICKED(IDC_SHOWALLINFO, OnShowinfo)
  40. //}}AFX_MSG_MAP
  41. END_MESSAGE_MAP()
  42. /////////////////////////////////////////////////////////////////////////////
  43. // CShowAllClientDlg message handlers
  44. BOOL CShowAllClientDlg::OnInitDialog() 
  45. {
  46. CDialog::OnInitDialog();
  47. // TODO: Add extra initialization here
  48. m_listctrl.SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES);
  49. OnShowpartInfo();
  50. return TRUE;  // return TRUE unless you set the focus to a control
  51.               // EXCEPTION: OCX Property Pages should return FALSE
  52. }
  53. void CShowAllClientDlg::OnDeleteclient() 
  54. {
  55. // TODO: Add your control notification handler code here
  56. CClientinfoSet clientinfoSet;
  57. int nItemIndex = -1;
  58. nItemIndex = m_listctrl . GetNextItem ( nItemIndex, LVNI_SELECTED ) ;
  59. if((m_listctrl.GetNextItem ( -1, LVNI_SELECTED ) ) != -1)
  60. {
  61. if(AfxMessageBox("确定要删除这条记录吗?",1,NULL)==IDOK)
  62. {
  63. try
  64. {
  65. if(!clientinfoSet.IsOpen())
  66. clientinfoSet.Open();
  67. if(!clientinfoSet.IsEOF())
  68. clientinfoSet.MoveFirst();
  69. while(!clientinfoSet.IsEOF())
  70. {
  71. if(clientinfoSet.m_CarPhone==m_listctrl.GetItemText(nItemIndex,0))
  72. {
  73. //更新树状信息
  74. CMainFrame*  mainfrm=(CMainFrame*)AfxGetApp()->m_pMainWnd;
  75. mainfrm->DeleteTreeItem(clientinfoSet.m_CarNumber);
  76. clientinfoSet.Delete();
  77. m_listctrl.DeleteItem(nItemIndex);
  78. AfxMessageBox("删除记录成功!");
  79. break;
  80. }
  81. clientinfoSet.MoveNext();
  82. }
  83. }
  84. catch(CDBException* pEx)
  85. {
  86.          AfxMessageBox(pEx->m_strError);
  87. }
  88. }
  89. }
  90. else
  91. {
  92. AfxMessageBox("请选择一条记录");
  93. return;
  94. }
  95. }
  96. void CShowAllClientDlg::OnEditclient() 
  97. {
  98. // TODO: Add your control notification handler code here
  99. CClientinfoSet clientinfoSet;
  100. int i,nItemIndex = -1;
  101. i=0;
  102. nItemIndex = m_listctrl . GetNextItem ( nItemIndex, LVNI_SELECTED ) ;
  103. if((m_listctrl.GetNextItem ( -1, LVNI_SELECTED ) ) != -1)
  104. {
  105. CEditclientinfoDlg *dlg;
  106. dlg =new CEditclientinfoDlg();
  107. try{
  108. if(!clientinfoSet.IsOpen())
  109. clientinfoSet.Open();
  110. if(!clientinfoSet.IsEOF())
  111. clientinfoSet.MoveFirst();
  112. while(!clientinfoSet.IsEOF())
  113. {
  114. if(clientinfoSet.m_CarPhone==m_listctrl.GetItemText(nItemIndex,0))
  115. {
  116. dlg->m_ClientName         = clientinfoSet.m_ClientName;
  117. dlg->m_ClientAge          = clientinfoSet.m_ClientAge;
  118. dlg->m_ClientUnits        = clientinfoSet.m_ClientUnits;
  119. dlg->m_ClientDuty         = clientinfoSet.m_ClientDuty;
  120. dlg->m_ClientIDcard       = clientinfoSet.m_ClientIDcard;
  121. dlg->m_ClientDrivelicence = clientinfoSet.m_ClientDrivelicence;
  122. dlg->m_ClientPhone        = clientinfoSet.m_ClientPhone;
  123. dlg->m_ClientPassword     = clientinfoSet.m_ClientPassword;
  124. dlg->m_CarNumber          = clientinfoSet.m_CarNumber;
  125. dlg->m_CarType            = clientinfoSet.m_CarType;
  126. dlg->m_CarColor           = clientinfoSet.m_CarColor;
  127. dlg->m_CarEngine          = clientinfoSet.m_CarEngine;
  128. dlg->m_BatholithNo        = clientinfoSet.m_BatholithNo;
  129. dlg->m_CarPhone           = clientinfoSet.m_CarPhone;
  130. break;
  131. }
  132. i++;
  133. clientinfoSet.MoveNext();
  134. }
  135. }
  136. catch(CDBException *Exp)
  137. {
  138. AfxMessageBox(Exp->m_strError);
  139. }
  140. if(dlg->DoModal()==IDOK)
  141. {
  142. try
  143. {
  144. if(!clientinfoSet.IsOpen())
  145. clientinfoSet.Open();
  146. //判断是否车载电话重复(车载电话是关键字)
  147. if(dlg->m_CarPhone!=m_listctrl.GetItemText(nItemIndex,0))
  148. {
  149. if(!clientinfoSet.IsEOF())
  150. clientinfoSet.MoveFirst();
  151. while(!clientinfoSet.IsEOF())
  152. {
  153. if(clientinfoSet.m_CarPhone==dlg->m_CarPhone)
  154. {
  155. AfxMessageBox ( "已存在此车载电话号码!修改失败!" );
  156. return;
  157. }
  158. clientinfoSet.MoveNext();
  159. }
  160. clientinfoSet.MoveFirst();
  161. for(int j=0;j<i;j++)
  162. clientinfoSet.MoveNext();
  163. clientinfoSet.Edit();
  164. clientinfoSet.m_ClientName        =dlg->m_ClientName;
  165. clientinfoSet.m_ClientAge         =dlg->m_ClientAge;
  166. clientinfoSet.m_ClientUnits   =dlg->m_ClientUnits;
  167. clientinfoSet.m_ClientDuty   =dlg->m_ClientDuty;
  168. clientinfoSet.m_ClientIDcard      =dlg->m_ClientIDcard;
  169. clientinfoSet.m_ClientDrivelicence=dlg->m_ClientDrivelicence;
  170. clientinfoSet.m_ClientPhone   =dlg->m_ClientPhone;
  171. clientinfoSet.m_ClientPassword    =dlg->m_ClientPassword;
  172. clientinfoSet.m_CarNumber         =dlg->m_CarNumber;
  173. clientinfoSet.m_CarType   =dlg->m_CarType;
  174. clientinfoSet.m_CarColor   =dlg->m_CarColor;
  175. clientinfoSet.m_CarEngine   =dlg->m_CarEngine;
  176. clientinfoSet.m_BatholithNo   =dlg->m_BatholithNo;
  177. clientinfoSet.m_CarPhone   =dlg->m_CarPhone;
  178. clientinfoSet.Update();
  179. AfxMessageBox ( "修改成功!" );
  180. //更新树状信息
  181. CMainFrame*  mainfrm=(CMainFrame*)AfxGetApp()->m_pMainWnd;
  182. mainfrm->InsertTreeItem();
  183. }
  184. else
  185. {
  186. clientinfoSet.Edit();
  187. clientinfoSet.m_ClientName        =dlg->m_ClientName;
  188. clientinfoSet.m_ClientAge         =dlg->m_ClientAge;
  189. clientinfoSet.m_ClientUnits   =dlg->m_ClientUnits;
  190. clientinfoSet.m_ClientDuty   =dlg->m_ClientDuty;
  191. clientinfoSet.m_ClientIDcard      =dlg->m_ClientIDcard;
  192. clientinfoSet.m_ClientDrivelicence=dlg->m_ClientDrivelicence;
  193. clientinfoSet.m_ClientPhone   =dlg->m_ClientPhone;
  194. clientinfoSet.m_ClientPassword    =dlg->m_ClientPassword;
  195. clientinfoSet.m_CarNumber         =dlg->m_CarNumber;
  196. clientinfoSet.m_CarType   =dlg->m_CarType;
  197. clientinfoSet.m_CarColor   =dlg->m_CarColor;
  198. clientinfoSet.m_CarEngine   =dlg->m_CarEngine;
  199. clientinfoSet.m_BatholithNo   =dlg->m_BatholithNo;
  200. clientinfoSet.m_CarPhone   =dlg->m_CarPhone;
  201. clientinfoSet.Update();
  202. AfxMessageBox ( "修改成功!" );
  203. //更新树状信息
  204. CMainFrame*  mainfrm=(CMainFrame*)AfxGetApp()->m_pMainWnd;
  205. mainfrm->InsertTreeItem();
  206. }
  207. }
  208. catch(CDBException* pEx)
  209. {
  210.          AfxMessageBox(pEx->m_strError);
  211. }
  212. }
  213. delete dlg;
  214. }
  215. else
  216. {
  217. AfxMessageBox("请选择一条记录!");
  218. return;
  219. }
  220. if(showallinfo)
  221.     OnLoadallinfo();
  222. else
  223. OnLoadinfo();
  224. }
  225. void CShowAllClientDlg::OnLoadallinfo()
  226. {
  227. CClientinfoSet clientinfoSet;
  228. m_listctrl.DeleteAllItems();
  229. try
  230. {
  231. if(!clientinfoSet.IsOpen())
  232. clientinfoSet.Open();
  233. if(!clientinfoSet.IsEOF())
  234. clientinfoSet.MoveFirst();
  235. //显示所有信息
  236. while(!clientinfoSet.IsEOF())
  237. {
  238. int m_nItemCount = m_listctrl.GetItemCount();
  239. m_listctrl.InsertItem (m_nItemCount, clientinfoSet .m_CarPhone);
  240. m_listctrl.SetItemText(m_nItemCount,1, clientinfoSet .m_ClientName);
  241.           m_listctrl.SetItemText(m_nItemCount,2, clientinfoSet .m_ClientAge);
  242.          m_listctrl.SetItemText(m_nItemCount,3, clientinfoSet .m_ClientUnits);
  243.          m_listctrl.SetItemText(m_nItemCount,4, clientinfoSet .m_ClientDuty);
  244.           m_listctrl.SetItemText(m_nItemCount,5, clientinfoSet .m_ClientIDcard);
  245.          m_listctrl.SetItemText(m_nItemCount,6, clientinfoSet .m_ClientDrivelicence);
  246.          m_listctrl.SetItemText(m_nItemCount,7, clientinfoSet .m_ClientPhone);
  247.          m_listctrl.SetItemText(m_nItemCount,8, clientinfoSet .m_ClientPassword);
  248.          m_listctrl.SetItemText(m_nItemCount,9, clientinfoSet .m_CarNumber);
  249.          m_listctrl.SetItemText(m_nItemCount,10, clientinfoSet .m_CarType);
  250.          m_listctrl.SetItemText(m_nItemCount,11, clientinfoSet .m_CarColor);
  251.          m_listctrl.SetItemText(m_nItemCount,12, clientinfoSet .m_CarEngine);
  252.         m_listctrl.SetItemText(m_nItemCount,13, clientinfoSet .m_BatholithNo);
  253. clientinfoSet.MoveNext();
  254. }
  255. }
  256. catch(CDBException* pEx)
  257. {
  258. AfxMessageBox(pEx->m_strError);
  259. }
  260. }
  261. void CShowAllClientDlg::OnLButtonDblClk(UINT nFlags, CPoint point) 
  262. {
  263. // TODO: Add your message handler code here and/or call default
  264. CDialog::OnLButtonDblClk(nFlags, point);
  265. }
  266. void CShowAllClientDlg::OnDblclkList1(NMHDR* pNMHDR, LRESULT* pResult) 
  267. {
  268. // TODO: Add your control notification handler code here
  269. OnEditclient();
  270. *pResult = 0;
  271. }
  272. void CShowAllClientDlg::OnShowallinfo() 
  273. {
  274. // TODO: Add your control notification handler code here
  275. m_listctrl.DeleteAllItems();
  276. while(m_listctrl.DeleteColumn(0));
  277. m_listctrl.InsertColumn(0,"车载电话号码", LVCFMT_CENTER,100);
  278. m_listctrl.InsertColumn(1," 客户姓名", LVCFMT_CENTER,80);
  279. m_listctrl.InsertColumn(2,"年龄", LVCFMT_CENTER,50);
  280. m_listctrl.InsertColumn(3,"单位", LVCFMT_CENTER,150);
  281. m_listctrl.InsertColumn(4,"职务", LVCFMT_CENTER,100);
  282. m_listctrl.InsertColumn(5,"身份证号码", LVCFMT_CENTER,150);
  283. m_listctrl.InsertColumn(6,"驾驶证号码", LVCFMT_CENTER,120);
  284. m_listctrl.InsertColumn(7,"客户联系电话", LVCFMT_CENTER,100);
  285. m_listctrl.InsertColumn(8,"客户密码", LVCFMT_CENTER,70);
  286. m_listctrl.InsertColumn(9,"车牌号码", LVCFMT_CENTER,80);
  287. m_listctrl.InsertColumn(10,"车辆型号", LVCFMT_CENTER,100);
  288. m_listctrl.InsertColumn(11,"车辆颜色", LVCFMT_CENTER,70);
  289. m_listctrl.InsertColumn(12,"发动机编号", LVCFMT_CENTER,100);
  290. m_listctrl.InsertColumn(13,"底盘编号", LVCFMT_CENTER,100);
  291. OnLoadallinfo();
  292. }
  293. void CShowAllClientDlg::OnLoadinfo()
  294. {
  295. CClientinfoSet clientinfoset;
  296. m_listctrl.DeleteAllItems();
  297. try
  298. {
  299. if(!clientinfoset.IsOpen())
  300. clientinfoset.Open();
  301. if(!clientinfoset.IsEOF())
  302. clientinfoset.MoveFirst();
  303. //隐藏部分信息
  304. while(!clientinfoset.IsEOF())
  305. {
  306. int m_nItemCount = m_listctrl.GetItemCount();
  307. m_listctrl.InsertItem (m_nItemCount, clientinfoset.m_CarPhone);
  308. m_listctrl.SetItemText (m_nItemCount,1,clientinfoset.m_ClientName);
  309.          m_listctrl.SetItemText (m_nItemCount,2,clientinfoset.m_ClientPhone);
  310.          m_listctrl.SetItemText (m_nItemCount,3,clientinfoset.m_CarNumber);
  311. clientinfoset.MoveNext();
  312. }
  313. }
  314. catch(CDBException* pEx)
  315. {
  316. AfxMessageBox(pEx->m_strError);
  317. }
  318. }
  319. void CShowAllClientDlg::OnShowpartInfo()
  320. {
  321. m_listctrl.DeleteAllItems();
  322. while(m_listctrl.DeleteColumn(0));
  323. m_listctrl.InsertColumn(0,"车载电话号码",LVCFMT_CENTER,100);
  324. m_listctrl.InsertColumn(1," 客户姓名",LVCFMT_CENTER,80);
  325. m_listctrl.InsertColumn(2,"客户联系电话",LVCFMT_CENTER,100);
  326. m_listctrl.InsertColumn(3,"车牌号码",LVCFMT_CENTER,80);
  327. OnLoadinfo();
  328. }
  329. void CShowAllClientDlg::OnShowinfo()
  330. {
  331. if(showallinfo==FALSE)
  332. {
  333. OnShowallinfo();
  334. showallinfo = TRUE;
  335. }
  336. else
  337. {
  338. OnShowpartInfo();
  339. showallinfo= FALSE;
  340. }
  341. }
  342. void CShowAllClientDlg::OnClose() 
  343. {
  344. // TODO: Add your message handler code here and/or call default
  345. /* CClientinfoSet clientinfoset;
  346. clientinfoset.Close();*/
  347. CDialog::OnClose();
  348. }