search.cpp
上传用户:hbzqs18
上传日期:2021-03-04
资源大小:46k
文件大小:5k
- // search.cpp : implementation file
- //
- #include "stdafx.h"
- #include "学生家庭经济情况调查系统.h"
- #include "search.h"
- #include <fstream.h>
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // search dialog
- search::search(CWnd* pParent /*=NULL*/)
- : CDialog(search::IDD, pParent)
- {
- //{{AFX_DATA_INIT(search)
- m_editJiGuan = _T("");
- //}}AFX_DATA_INIT
- }
- void search::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(search)
- DDX_Control(pDX, IDC_LIST_RESULTS, m_listResults);
- DDX_Control(pDX, IDC_COMBO3, m_comboIn);
- DDX_Text(pDX, IDC_EDIT_JIGUAN, m_editJiGuan);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(search, CDialog)
- //{{AFX_MSG_MAP(search)
- ON_BN_CLICKED(IDC_BTN_QUERY, OnBtnQuery)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // search message handlers
- BOOL search::OnInitDialog()
- {
- CDialog::OnInitDialog();
-
- // TODO: Add extra initialization here
- int nIndex = m_comboIn.AddString(">=500");
- m_comboIn.AddString("<500");
- m_listResults.InsertColumn(0,"学号");
- m_listResults.InsertColumn(1,"籍贯");
- m_listResults.InsertColumn(1,"家庭月收入");
- m_listResults.InsertColumn(3,"家庭成员数");
- m_listResults.SetColumnWidth(0,100);
- m_listResults.SetColumnWidth(1,100);
- m_listResults.SetColumnWidth(2,50);
- m_listResults.SetColumnWidth(3,100);
- return TRUE; // return TRUE unless you set the focus to a control
- // EXCEPTION: OCX Property Pages should return FALSE
- }
- void search::OnBtnQuery()
- {
- // TODO: Add your control notification handler code here
- UpdateData();
- CString pattern;
- int nIndex = GetCheckedRadioButton(IDC_RADIO1,IDC_RADIO3);
- GetDlgItemText(nIndex,pattern);
- if(!pattern.Compare("全体学生家庭经济情况"))
- {
- ShowAll();
- }else if(!pattern.Compare("籍贯"))
- {
- ShowAccordingJiGuan();
- }else if(!pattern.Compare("家庭人均月收入"))
- {
- ShowAccordingIncome();
- }else MessageBox("不知名的错误,请重新启动程序!");
- }
- void search::ShowAll()
- {
- m_listResults.DeleteAllItems();
- ifstream inf;
- inf.open("student.dat",ios::nocreate|ios::in);
- char buf[MAX_PATH];
- char stunum[10];
- char jiguan[20];
- int income;
- int members;
- int i=0;
- while(true){
- inf.get(stunum,10,' ');
- stunum[9]=0;
- inf.seekg(1,ios::cur);
- inf>>jiguan;
- inf.seekg(1,ios::cur);
- inf>>income;
- inf.seekg(1,ios::cur);
- inf>>members;
- if(inf.eof())break;
- inf.seekg(2,ios::cur);
- m_listResults.InsertItem(i,"");
- m_listResults.SetItemText(i,0,stunum);
- m_listResults.SetItemText(i,1,jiguan);
- sprintf(buf,"%d",income);
- m_listResults.SetItemText(i,2,buf);
- sprintf(buf,"%d",members);
- m_listResults.SetItemText(i,3,buf);
-
- i++;
- }
- inf.close();
- }
- void search::ShowAccordingJiGuan()
- {
- UpdateData();
- m_listResults.DeleteAllItems();
- ifstream inf;
- inf.open("student.dat",ios::nocreate|ios::in);
- char buf[MAX_PATH];
- char stunum[10];
- char jiguan[20];
- int income;
- int members;
- int i=0;
- BOOL find = FALSE;
- while(true){
- inf.get(stunum,10,' ');
- stunum[9]=0;
- inf.seekg(1,ios::cur);
- inf>>jiguan;
- if(!strcmp(jiguan,m_editJiGuan.GetBuffer(20)))
- find = TRUE;
- inf.seekg(1,ios::cur);
- inf>>income;
- inf.seekg(1,ios::cur);
- inf>>members;
- if(inf.eof())break;
- inf.seekg(2,ios::cur);
- if(find){
- m_listResults.InsertItem(i,"");
- m_listResults.SetItemText(i,0,stunum);
- m_listResults.SetItemText(i,1,jiguan);
- sprintf(buf,"%d",income);
- m_listResults.SetItemText(i,2,buf);
- sprintf(buf,"%d",members);
- m_listResults.SetItemText(i,3,buf);
-
- i++;
- }
- find = FALSE;
- }
- inf.close();
- }
- void search::ShowAccordingIncome()
- {
- CString str;
- m_comboIn.GetLBText(m_comboIn.GetCurSel(),str);
- m_listResults.DeleteAllItems();
- int pattern = 0;
- if(!str.Compare(">=500"))
- pattern = 1;
- else
- pattern =0;
- ifstream inf;
- inf.open("student.dat",ios::nocreate|ios::in);
- char buf[MAX_PATH];
- char stunum[10];
- char jiguan[20];
- int income;
- int members;
- int i=0;
- BOOL find = FALSE;
- while(true){
- inf.get(stunum,10,' ');
- stunum[9]=0;
- inf.seekg(1,ios::cur);
- inf>>jiguan;
- inf.seekg(1,ios::cur);
- inf>>income;
- if(pattern == 1)
- {
- if(income >= 500)
- find = TRUE;
- }else
- {
- if(income < 500)
- find = TRUE;
- }
- inf.seekg(1,ios::cur);
- inf>>members;
- if(inf.eof())break;
- inf.seekg(2,ios::cur);
- if(find){
- m_listResults.InsertItem(i,"");
- m_listResults.SetItemText(i,0,stunum);
- m_listResults.SetItemText(i,1,jiguan);
- sprintf(buf,"%d",income);
- m_listResults.SetItemText(i,2,buf);
- sprintf(buf,"%d",members);
- m_listResults.SetItemText(i,3,buf);
-
- i++;
- }
- find = FALSE;
- }
- inf.close();
- }