📄 show.cpp
字号:
// show.cpp : implementation file
//
#include "stdafx.h"
#include "salsary.h"
#include "show.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// show dialog
show::show(CWnd* pParent /*=NULL*/)
: CDialog(show::IDD, pParent)
{
//{{AFX_DATA_INIT(show)
m_get = _T("");
//}}AFX_DATA_INIT
}
void show::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(show)
DDX_Control(pDX, IDC_LIST1, m_list);
DDX_Text(pDX, IDC_STATIC1, m_get);
DDV_MaxChars(pDX, m_get, 10);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(show, CDialog)
//{{AFX_MSG_MAP(show)
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
ON_NOTIFY(NM_CLICK, IDC_LIST1, OnClickList1)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// show message handlers
#include"wh.h"
BOOL show::OnInitDialog()
{
CDialog::OnInitDialog();
((CComboBox*)GetDlgItem(IDC_COMBO2))->AddString("用户数量");
((CComboBox*)GetDlgItem(IDC_COMBO2))->AddString("最大年龄");
((CComboBox*)GetDlgItem(IDC_COMBO2))->AddString("最小年龄");
((CComboBox*)GetDlgItem(IDC_COMBO2))->AddString("平均年龄");
((CComboBox*)GetDlgItem(IDC_COMBO2))->AddString("最高工资");
((CComboBox*)GetDlgItem(IDC_COMBO2))->AddString("最低工资");
((CComboBox*)GetDlgItem(IDC_COMBO2))->AddString("平均工资");
((CComboBox*)GetDlgItem(IDC_COMBO2))->SetCurSel(0);
m_list.SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES|LVS_EX_HEADERDRAGDROP|
LVS_EX_ONECLICKACTIVATE|LVS_EX_FLATSB);
m_list.InsertColumn(0,"用户名",LVCFMT_LEFT,65);
m_list.InsertColumn(1,"姓名",LVCFMT_LEFT,65);
m_list.InsertColumn(2,"年龄",LVCFMT_LEFT,65);
m_list.InsertColumn(3,"工资",LVCFMT_LEFT,65);
//初始化列表框
fstream iof("C:\\user.dat",ios::binary|ios::in|ios::out);
if(!iof)
{cerr<<"文件不能打开"<<endl;
return FALSE;
}
user_data user;
CString User,Name,Age,Salary;
iof.seekp(0,ios::end);
long posEnd=iof.tellp();
int i=0;//i用来确定输入数据的位置
m_list.DeleteAllItems();
iof.seekp(0,ios::beg);
do
{iof.read((char*)&user,sizeof(user_data));
User=user.user;Name=user.name;Age.Format("%d",user.age);
Salary.Format("%d",user.salary);
{m_list.InsertItem(i,User,1);
m_list.SetItemText(i,1,Name);
m_list.SetItemText(i,2,Age);
m_list.SetItemText(i,3,Salary);
}
if(i==0)
i++;
}while(iof.tellp()!=posEnd);
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
#include"wh.h"
void show::OnButton1()
{
int index; // TODO: Add your control notification handler code here
index=((CComboBox*)GetDlgItem(IDC_COMBO2))->GetCurSel();
((CComboBox*)GetDlgItem(IDC_COMBO2))->GetLBText(index,m_choose);
//进行数据统计
int number=0;int oldAge=0;int youngAge;double aveAge=0;int highSal=0;
int lowSal;double aveSal=0;
fstream iof("C:\\user.dat",ios::binary|ios::in|ios::out);
if(!iof)
{cerr<<"文件不能打开"<<endl;
return ;
}
iof.seekp(0,ios::end);
long posEnd=iof.tellp();
user_data user;
iof.seekp(0,ios::beg);
do{iof.read((char*)&user,sizeof(user_data));
if(user.age>oldAge){oldAge=user.age;}
if(user.age<youngAge||number==0){youngAge=user.age;}
aveAge+=user.age;
if(user.salary>highSal){highSal=user.salary;}
if(user.salary<lowSal||number==0){lowSal=user.salary;}
aveSal+=user.salary;
number++;
}while(iof.tellp()!=posEnd);
aveSal/=number;
aveAge/=number;
CString cNumber,cOldAge,cYoungAge,cAveAge,cHighSal,cLowSal,cAveSal;
cNumber.Format("%d",number);
cOldAge.Format("%d",oldAge);
cYoungAge.Format("%d",youngAge);
cAveAge.Format("%f",aveAge);
cHighSal.Format("%d",highSal);
cLowSal.Format("%d",lowSal);
cAveSal.Format("%f",aveSal);
switch(index)
{case 0:m_get=cNumber;break;
case 1:m_get=cOldAge;break;
case 2:m_get=cYoungAge;break;
case 3:m_get=cAveAge;break;
case 4:m_get=cHighSal;break;
case 5:m_get=cLowSal;break;
case 6:m_get=cAveSal;break;}
UpdateData(FALSE);
}
void show::OnButton2()
{
EndDialog(1); // TODO: Add your control notification handler code here
}
void show::OnClickList1(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
*pResult = 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -