-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAFewNames.cpp
More file actions
110 lines (82 loc) · 2.28 KB
/
AFewNames.cpp
File metadata and controls
110 lines (82 loc) · 2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// AFewNames.cpp: 实现文件
//
#include "pch.h"
#include "WorkerManager.h"
#include "afxdialogex.h"
#include "AFewNames.h"
// AFewNames 对话框
IMPLEMENT_DYNAMIC(AFewNames, CDialogEx)
AFewNames::AFewNames(CWnd* pParent /*=nullptr*/)
: CDialogEx(IDD_AFewNames, pParent)
{
}
AFewNames::~AFewNames()
{
}
void AFewNames::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
DDX_Control(pDX, IDC_LIST2, m_list);
}
BEGIN_MESSAGE_MAP(AFewNames, CDialogEx)
ON_BN_CLICKED(IDOK2, &AFewNames::OnBnClickedOk2)
END_MESSAGE_MAP()
// AFewNames 消息处理程序
BOOL AFewNames::OnInitDialog()
{
CDialogEx::OnInitDialog();
// TODO: 在此添加额外的初始化
// 设置扩展风格
//LVS_EX_FULLROWSELECT选中整行,LVS_EX_GRIDLINES网格
m_list.SetExtendedStyle(m_list.GetExtendedStyle() | LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES);
// 初始化表头
CString field[] = { _T("职工编号"), _T("职工姓名"), _T("职工级别"), _T("职工薪水") };
for (int i = 0; i < sizeof(field) / sizeof(field[0]); ++i)
{
m_list.InsertColumn(i, field[i], LVCFMT_CENTER, 105);
}
ifstream ifs(FILENAME);//打开文件
char buf[1024] = { 0 };//初始化数组
ifs.getline(buf, sizeof(buf));//取出表头
while (!ifs.eof())//未读取完毕
{
msg tmp;
ifs.getline(buf, sizeof(buf));//读取一行
char* sst = strtok(buf, "|");//用“|”分隔
if (sst != NULL)
{
tmp.id = atoi(sst);//职工编号
}
else
{
break;
}
sst = strtok(NULL, "|");
tmp.name = sst;//职工姓名
sst = strtok(NULL, "|");
tmp.job = sst;//职工职位
sst = strtok(NULL, "|");
tmp.wage = atoi(sst);//职工薪水
CStringA str;
str = worker->m_name;
if (tmp.name == str.GetBuffer())
{
CString str1, str2, str3, str4;
str1.Format(_T("%d"), tmp.id);
m_list.InsertItem(0, str1);
int column = 1;
m_list.SetItemText(0, column++, (CString)tmp.name.c_str());
m_list.SetItemText(0, column++, (CString)tmp.job.c_str());
str4.Format(_T("%d"), tmp.wage);
m_list.SetItemText(0, column++, str4);
}
}
ifs.close();//关闭文件
return TRUE; // return TRUE unless you set the focus to a control
// 异常: OCX 属性页应返回 FALSE
}
void AFewNames::OnBnClickedOk2()
{
OnOK();
// TODO: 在此添加控件通知处理程序代码
}