SearchPersonDlg.cpp
上传用户:tyjx315
上传日期:2015-01-18
资源大小:1685k
文件大小:4k
- // SearchPersonDlg.cpp : implementation file
- //
- #include "stdafx.h"
- #include "SuperMarket.h"
- #include "SearchPersonDlg.h"
- #include "afxdb.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CSearchPersonDlg dialog
- CSearchPersonDlg::CSearchPersonDlg(CWnd* pParent /*=NULL*/)
- : CDialog(CSearchPersonDlg::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CSearchPersonDlg)
- m_number = _T("");
- m_name = _T("");
- m_age = _T("");
- //}}AFX_DATA_INIT
- }
- void CSearchPersonDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CSearchPersonDlg)
- DDX_Control(pDX, IDC_LIST1, m_list);
- DDX_Control(pDX, IDC_COMBOBOXEX2, m_department);
- DDX_Control(pDX, IDC_COMBOBOXEX1, m_sex);
- DDX_Text(pDX, IDC_EDIT1, m_number);
- DDX_Text(pDX, IDC_EDIT2, m_name);
- DDX_Text(pDX, IDC_EDIT3, m_age);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CSearchPersonDlg, CDialog)
- //{{AFX_MSG_MAP(CSearchPersonDlg)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CSearchPersonDlg message handlers
- void CSearchPersonDlg::OnOK()
- {
- // TODO: Add extra validation here
- CDatabase dbTemp;
- CRecordset rs( &dbTemp);
- UpdateData();
- CString strSQL,tempnumber,tempname,tempage,tempsex,tempdepartment,str1,str2;
- bool flag=false,found_flag=false;
- int w = 0;
- dbTemp.OpenEx("Driver={Microsoft Access Driver (*.mdb)};DBQ=超市管理数据库.mdb;");
- rs.Open(AFX_DB_USE_DEFAULT_TYPE,"select * From 员工信息");
- m_list.DeleteAllItems();
- while(!rs.IsEOF())
- {
- rs.GetFieldValue((short)0,tempnumber);
- rs.GetFieldValue((short)1,tempname);
- rs.GetFieldValue((short)2,tempage);
- rs.GetFieldValue((short)3,tempsex);
- rs.GetFieldValue((short)4,tempdepartment);
- if(m_number != "")
- {
- if(tempnumber == m_number)
- flag=true;
- else
- flag=false;
- }
- else
- flag=true;
- if(m_name != "" && flag == true)
- {
- if(tempname == m_name)
- flag=true;
- else
- flag=false;
- }
- if(m_age != "" && flag == true)
- {
- if(tempage == m_age)
- flag=true;
- else
- flag=false;
- }
- m_sex.GetWindowText(str1);
- if(str1 != "" && flag == true)
- {
- if(tempsex == str1)
- flag=true;
- else
- flag=false;
- }
- m_department.GetWindowText(str2);
- if(str2 != "" && flag == true)
- {
- if(tempdepartment == str2)
- flag=true;
- else
- flag=false;
- }
- if(flag == true)
- {
-
- m_list.InsertItem (w,tempnumber);//写第一列;
-
- m_list.SetItemText (w,1,tempname);//第二列;
- m_list.SetItemText (w,2,tempage);//第三列;
- m_list.SetItemText (w,3,tempsex);//第四列;
- m_list.SetItemText (w,4,tempdepartment);//第四列;
- w = w + 1;
- found_flag=true;
- UpdateData(false);
- }
- rs.MoveNext();
- }
- if(found_flag != true)
- MessageBox("没有找到相应内容!");
- rs.Close();
- dbTemp.Close();
- // CDialog::OnOK();
- }
- BOOL CSearchPersonDlg::OnInitDialog()
- {
- CDialog::OnInitDialog();
-
- // TODO: Add extra initialization here
- m_list.SetExtendedStyle(LVS_EX_GRIDLINES|LVS_EX_FULLROWSELECT|LVS_EX_ONECLICKACTIVATE);
- m_list.InsertColumn(0,"编号",LVCFMT_LEFT,115);
- m_list.InsertColumn(1,"姓名",LVCFMT_LEFT,115);
- m_list.InsertColumn(2,"年龄",LVCFMT_LEFT,110);
- m_list.InsertColumn(3,"性别",LVCFMT_LEFT,110);
- m_list.InsertColumn(3,"部门",LVCFMT_LEFT,130);
-
-
- return TRUE; // return TRUE unless you set the focus to a control
- // EXCEPTION: OCX Property Pages should return FALSE
- }