ShowAllClientDlg.cpp
上传用户:yffx2008
上传日期:2014-10-12
资源大小:12414k
文件大小:12k
源码类别:
交通/航空行业
开发平台:
Visual C++
- // ShowAllClientDlg.cpp : implementation file
- //
- #include "stdafx.h"
- #include "GpsSC.h"
- #include "ShowAllClientDlg.h"
- #include "ClientinfoSet.h"
- #include "EditclientinfoDlg.h"
- #include "MainFrm.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- //extern CGpsSCApp theApp; // 在此引用应用类中的theApp来获取库连接指针
- /////////////////////////////////////////////////////////////////////////////
- // CShowAllClientDlg dialog
- CShowAllClientDlg::CShowAllClientDlg(CWnd* pParent /*=NULL*/)
- : CDialog(CShowAllClientDlg::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CShowAllClientDlg)
- // NOTE: the ClassWizard will add member initialization here
- //}}AFX_DATA_INIT
- showallinfo = FALSE;
- }
- void CShowAllClientDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CShowAllClientDlg)
- DDX_Control(pDX, IDC_LIST1, m_listctrl);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CShowAllClientDlg, CDialog)
- //{{AFX_MSG_MAP(CShowAllClientDlg)
- ON_BN_CLICKED(IDC_DELETECLIENT, OnDeleteclient)
- ON_BN_CLICKED(IDC_EDITCLIENT, OnEditclient)
- ON_WM_LBUTTONDBLCLK()
- ON_NOTIFY(NM_DBLCLK, IDC_LIST1, OnDblclkList1)
- ON_WM_CLOSE()
- ON_BN_CLICKED(IDC_SHOWALLINFO, OnShowinfo)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CShowAllClientDlg message handlers
- BOOL CShowAllClientDlg::OnInitDialog()
- {
- CDialog::OnInitDialog();
- // TODO: Add extra initialization here
- m_listctrl.SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES);
- OnShowpartInfo();
- return TRUE; // return TRUE unless you set the focus to a control
- // EXCEPTION: OCX Property Pages should return FALSE
- }
- void CShowAllClientDlg::OnDeleteclient()
- {
- // TODO: Add your control notification handler code here
- CClientinfoSet clientinfoSet;
- int nItemIndex = -1;
- nItemIndex = m_listctrl . GetNextItem ( nItemIndex, LVNI_SELECTED ) ;
- if((m_listctrl.GetNextItem ( -1, LVNI_SELECTED ) ) != -1)
- {
- if(AfxMessageBox("确定要删除这条记录吗?",1,NULL)==IDOK)
- {
- try
- {
- if(!clientinfoSet.IsOpen())
- clientinfoSet.Open();
- if(!clientinfoSet.IsEOF())
- clientinfoSet.MoveFirst();
- while(!clientinfoSet.IsEOF())
- {
- if(clientinfoSet.m_CarPhone==m_listctrl.GetItemText(nItemIndex,0))
- {
- //更新树状信息
- CMainFrame* mainfrm=(CMainFrame*)AfxGetApp()->m_pMainWnd;
- mainfrm->DeleteTreeItem(clientinfoSet.m_CarNumber);
- clientinfoSet.Delete();
- m_listctrl.DeleteItem(nItemIndex);
- AfxMessageBox("删除记录成功!");
- break;
- }
- clientinfoSet.MoveNext();
- }
- }
- catch(CDBException* pEx)
- {
- AfxMessageBox(pEx->m_strError);
- }
- }
- }
- else
- {
- AfxMessageBox("请选择一条记录");
- return;
- }
- }
- void CShowAllClientDlg::OnEditclient()
- {
- // TODO: Add your control notification handler code here
- CClientinfoSet clientinfoSet;
- int i,nItemIndex = -1;
- i=0;
- nItemIndex = m_listctrl . GetNextItem ( nItemIndex, LVNI_SELECTED ) ;
- if((m_listctrl.GetNextItem ( -1, LVNI_SELECTED ) ) != -1)
- {
- CEditclientinfoDlg *dlg;
- dlg =new CEditclientinfoDlg();
- try{
- if(!clientinfoSet.IsOpen())
- clientinfoSet.Open();
- if(!clientinfoSet.IsEOF())
- clientinfoSet.MoveFirst();
- while(!clientinfoSet.IsEOF())
- {
- if(clientinfoSet.m_CarPhone==m_listctrl.GetItemText(nItemIndex,0))
- {
- dlg->m_ClientName = clientinfoSet.m_ClientName;
- dlg->m_ClientAge = clientinfoSet.m_ClientAge;
- dlg->m_ClientUnits = clientinfoSet.m_ClientUnits;
- dlg->m_ClientDuty = clientinfoSet.m_ClientDuty;
- dlg->m_ClientIDcard = clientinfoSet.m_ClientIDcard;
- dlg->m_ClientDrivelicence = clientinfoSet.m_ClientDrivelicence;
- dlg->m_ClientPhone = clientinfoSet.m_ClientPhone;
- dlg->m_ClientPassword = clientinfoSet.m_ClientPassword;
- dlg->m_CarNumber = clientinfoSet.m_CarNumber;
- dlg->m_CarType = clientinfoSet.m_CarType;
- dlg->m_CarColor = clientinfoSet.m_CarColor;
- dlg->m_CarEngine = clientinfoSet.m_CarEngine;
- dlg->m_BatholithNo = clientinfoSet.m_BatholithNo;
- dlg->m_CarPhone = clientinfoSet.m_CarPhone;
- break;
- }
- i++;
- clientinfoSet.MoveNext();
- }
- }
- catch(CDBException *Exp)
- {
- AfxMessageBox(Exp->m_strError);
- }
- if(dlg->DoModal()==IDOK)
- {
- try
- {
- if(!clientinfoSet.IsOpen())
- clientinfoSet.Open();
- //判断是否车载电话重复(车载电话是关键字)
- if(dlg->m_CarPhone!=m_listctrl.GetItemText(nItemIndex,0))
- {
- if(!clientinfoSet.IsEOF())
- clientinfoSet.MoveFirst();
- while(!clientinfoSet.IsEOF())
- {
- if(clientinfoSet.m_CarPhone==dlg->m_CarPhone)
- {
- AfxMessageBox ( "已存在此车载电话号码!修改失败!" );
- return;
- }
- clientinfoSet.MoveNext();
- }
- clientinfoSet.MoveFirst();
- for(int j=0;j<i;j++)
- clientinfoSet.MoveNext();
- clientinfoSet.Edit();
- clientinfoSet.m_ClientName =dlg->m_ClientName;
- clientinfoSet.m_ClientAge =dlg->m_ClientAge;
- clientinfoSet.m_ClientUnits =dlg->m_ClientUnits;
- clientinfoSet.m_ClientDuty =dlg->m_ClientDuty;
- clientinfoSet.m_ClientIDcard =dlg->m_ClientIDcard;
- clientinfoSet.m_ClientDrivelicence=dlg->m_ClientDrivelicence;
- clientinfoSet.m_ClientPhone =dlg->m_ClientPhone;
- clientinfoSet.m_ClientPassword =dlg->m_ClientPassword;
- clientinfoSet.m_CarNumber =dlg->m_CarNumber;
- clientinfoSet.m_CarType =dlg->m_CarType;
- clientinfoSet.m_CarColor =dlg->m_CarColor;
- clientinfoSet.m_CarEngine =dlg->m_CarEngine;
- clientinfoSet.m_BatholithNo =dlg->m_BatholithNo;
- clientinfoSet.m_CarPhone =dlg->m_CarPhone;
- clientinfoSet.Update();
- AfxMessageBox ( "修改成功!" );
- //更新树状信息
- CMainFrame* mainfrm=(CMainFrame*)AfxGetApp()->m_pMainWnd;
- mainfrm->InsertTreeItem();
- }
- else
- {
- clientinfoSet.Edit();
- clientinfoSet.m_ClientName =dlg->m_ClientName;
- clientinfoSet.m_ClientAge =dlg->m_ClientAge;
- clientinfoSet.m_ClientUnits =dlg->m_ClientUnits;
- clientinfoSet.m_ClientDuty =dlg->m_ClientDuty;
- clientinfoSet.m_ClientIDcard =dlg->m_ClientIDcard;
- clientinfoSet.m_ClientDrivelicence=dlg->m_ClientDrivelicence;
- clientinfoSet.m_ClientPhone =dlg->m_ClientPhone;
- clientinfoSet.m_ClientPassword =dlg->m_ClientPassword;
- clientinfoSet.m_CarNumber =dlg->m_CarNumber;
- clientinfoSet.m_CarType =dlg->m_CarType;
- clientinfoSet.m_CarColor =dlg->m_CarColor;
- clientinfoSet.m_CarEngine =dlg->m_CarEngine;
- clientinfoSet.m_BatholithNo =dlg->m_BatholithNo;
- clientinfoSet.m_CarPhone =dlg->m_CarPhone;
- clientinfoSet.Update();
- AfxMessageBox ( "修改成功!" );
- //更新树状信息
- CMainFrame* mainfrm=(CMainFrame*)AfxGetApp()->m_pMainWnd;
- mainfrm->InsertTreeItem();
- }
- }
- catch(CDBException* pEx)
- {
- AfxMessageBox(pEx->m_strError);
- }
- }
- delete dlg;
- }
- else
- {
- AfxMessageBox("请选择一条记录!");
- return;
- }
- if(showallinfo)
- OnLoadallinfo();
- else
- OnLoadinfo();
- }
- void CShowAllClientDlg::OnLoadallinfo()
- {
- CClientinfoSet clientinfoSet;
- m_listctrl.DeleteAllItems();
- try
- {
- if(!clientinfoSet.IsOpen())
- clientinfoSet.Open();
- if(!clientinfoSet.IsEOF())
- clientinfoSet.MoveFirst();
- //显示所有信息
- while(!clientinfoSet.IsEOF())
- {
- int m_nItemCount = m_listctrl.GetItemCount();
- m_listctrl.InsertItem (m_nItemCount, clientinfoSet .m_CarPhone);
- m_listctrl.SetItemText(m_nItemCount,1, clientinfoSet .m_ClientName);
- m_listctrl.SetItemText(m_nItemCount,2, clientinfoSet .m_ClientAge);
- m_listctrl.SetItemText(m_nItemCount,3, clientinfoSet .m_ClientUnits);
- m_listctrl.SetItemText(m_nItemCount,4, clientinfoSet .m_ClientDuty);
- m_listctrl.SetItemText(m_nItemCount,5, clientinfoSet .m_ClientIDcard);
- m_listctrl.SetItemText(m_nItemCount,6, clientinfoSet .m_ClientDrivelicence);
- m_listctrl.SetItemText(m_nItemCount,7, clientinfoSet .m_ClientPhone);
- m_listctrl.SetItemText(m_nItemCount,8, clientinfoSet .m_ClientPassword);
- m_listctrl.SetItemText(m_nItemCount,9, clientinfoSet .m_CarNumber);
- m_listctrl.SetItemText(m_nItemCount,10, clientinfoSet .m_CarType);
- m_listctrl.SetItemText(m_nItemCount,11, clientinfoSet .m_CarColor);
- m_listctrl.SetItemText(m_nItemCount,12, clientinfoSet .m_CarEngine);
- m_listctrl.SetItemText(m_nItemCount,13, clientinfoSet .m_BatholithNo);
- clientinfoSet.MoveNext();
- }
- }
- catch(CDBException* pEx)
- {
- AfxMessageBox(pEx->m_strError);
- }
- }
- void CShowAllClientDlg::OnLButtonDblClk(UINT nFlags, CPoint point)
- {
- // TODO: Add your message handler code here and/or call default
- CDialog::OnLButtonDblClk(nFlags, point);
- }
- void CShowAllClientDlg::OnDblclkList1(NMHDR* pNMHDR, LRESULT* pResult)
- {
- // TODO: Add your control notification handler code here
- OnEditclient();
- *pResult = 0;
- }
- void CShowAllClientDlg::OnShowallinfo()
- {
- // TODO: Add your control notification handler code here
- m_listctrl.DeleteAllItems();
- while(m_listctrl.DeleteColumn(0));
- m_listctrl.InsertColumn(0,"车载电话号码", LVCFMT_CENTER,100);
- m_listctrl.InsertColumn(1," 客户姓名", LVCFMT_CENTER,80);
- m_listctrl.InsertColumn(2,"年龄", LVCFMT_CENTER,50);
- m_listctrl.InsertColumn(3,"单位", LVCFMT_CENTER,150);
- m_listctrl.InsertColumn(4,"职务", LVCFMT_CENTER,100);
- m_listctrl.InsertColumn(5,"身份证号码", LVCFMT_CENTER,150);
- m_listctrl.InsertColumn(6,"驾驶证号码", LVCFMT_CENTER,120);
- m_listctrl.InsertColumn(7,"客户联系电话", LVCFMT_CENTER,100);
- m_listctrl.InsertColumn(8,"客户密码", LVCFMT_CENTER,70);
- m_listctrl.InsertColumn(9,"车牌号码", LVCFMT_CENTER,80);
- m_listctrl.InsertColumn(10,"车辆型号", LVCFMT_CENTER,100);
- m_listctrl.InsertColumn(11,"车辆颜色", LVCFMT_CENTER,70);
- m_listctrl.InsertColumn(12,"发动机编号", LVCFMT_CENTER,100);
- m_listctrl.InsertColumn(13,"底盘编号", LVCFMT_CENTER,100);
- OnLoadallinfo();
- }
- void CShowAllClientDlg::OnLoadinfo()
- {
- CClientinfoSet clientinfoset;
- m_listctrl.DeleteAllItems();
- try
- {
- if(!clientinfoset.IsOpen())
- clientinfoset.Open();
- if(!clientinfoset.IsEOF())
- clientinfoset.MoveFirst();
- //隐藏部分信息
- while(!clientinfoset.IsEOF())
- {
- int m_nItemCount = m_listctrl.GetItemCount();
- m_listctrl.InsertItem (m_nItemCount, clientinfoset.m_CarPhone);
- m_listctrl.SetItemText (m_nItemCount,1,clientinfoset.m_ClientName);
- m_listctrl.SetItemText (m_nItemCount,2,clientinfoset.m_ClientPhone);
- m_listctrl.SetItemText (m_nItemCount,3,clientinfoset.m_CarNumber);
- clientinfoset.MoveNext();
- }
- }
- catch(CDBException* pEx)
- {
- AfxMessageBox(pEx->m_strError);
- }
- }
- void CShowAllClientDlg::OnShowpartInfo()
- {
- m_listctrl.DeleteAllItems();
- while(m_listctrl.DeleteColumn(0));
- m_listctrl.InsertColumn(0,"车载电话号码",LVCFMT_CENTER,100);
- m_listctrl.InsertColumn(1," 客户姓名",LVCFMT_CENTER,80);
- m_listctrl.InsertColumn(2,"客户联系电话",LVCFMT_CENTER,100);
- m_listctrl.InsertColumn(3,"车牌号码",LVCFMT_CENTER,80);
- OnLoadinfo();
- }
- void CShowAllClientDlg::OnShowinfo()
- {
- if(showallinfo==FALSE)
- {
- OnShowallinfo();
- showallinfo = TRUE;
- }
- else
- {
- OnShowpartInfo();
- showallinfo= FALSE;
- }
- }
- void CShowAllClientDlg::OnClose()
- {
- // TODO: Add your message handler code here and/or call default
- /* CClientinfoSet clientinfoset;
- clientinfoset.Close();*/
- CDialog::OnClose();
- }