Skip to content

Commit

Permalink
final
Browse files Browse the repository at this point in the history
  • Loading branch information
SparkChen927 committed Mar 29, 2022
1 parent 1770f16 commit ba34885
Show file tree
Hide file tree
Showing 87 changed files with 5,117 additions and 935 deletions.
110 changes: 110 additions & 0 deletions AFewNames.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,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: 在此添加控件通知处理程序代码
}
31 changes: 31 additions & 0 deletions AFewNames.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#pragma once
#include "afxdialogex.h"
#include "DeleteWorker.h"

// AFewNames 对话框

class AFewNames : public CDialogEx
{
DECLARE_DYNAMIC(AFewNames)
friend class DeleteWorker;

public:
AFewNames(CWnd* pParent = nullptr); // 标准构造函数
virtual ~AFewNames();

// 对话框数据
#ifdef AFX_DESIGN_TIME
enum { IDD = IDD_AFewNames };
#endif

protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持

DECLARE_MESSAGE_MAP()
private:
CListCtrl m_list;
DeleteWorker* worker;
public:
virtual BOOL OnInitDialog();
afx_msg void OnBnClickedOk2();
};
120 changes: 120 additions & 0 deletions AddWorker.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
// AddWorker.cpp: 实现文件
//

#include "pch.h"
#include "WorkerManager.h"
#include "AddWorker.h"


// AddWorker

IMPLEMENT_DYNCREATE(AddWorker, CFormView)

AddWorker::AddWorker()
: CFormView(IDD_AddWorker)
, m_wage(0)
, m_name(_T(""))
{

}

AddWorker::~AddWorker()
{
}

void AddWorker::DoDataExchange(CDataExchange* pDX)
{
CFormView::DoDataExchange(pDX);
DDX_Control(pDX, IDC_COMBO1, m_job);
DDX_Text(pDX, IDC_EDIT4, m_wage);
DDX_Text(pDX, IDC_EDIT1, m_name);
}

BEGIN_MESSAGE_MAP(AddWorker, CFormView)
ON_BN_CLICKED(IDC_BUTTON1, &AddWorker::OnBnClickedButton1)
ON_BN_CLICKED(IDC_BUTTON2, &AddWorker::OnBnClickedButton2)
ON_EN_CHANGE(IDC_EDIT4, &AddWorker::OnEnChangeEdit4)
END_MESSAGE_MAP()


// AddWorker 诊断

#ifdef _DEBUG
void AddWorker::AssertValid() const
{
CFormView::AssertValid();
}

#ifndef _WIN32_WCE
void AddWorker::Dump(CDumpContext& dc) const
{
CFormView::Dump(dc);
}
#endif
#endif //_DEBUG


// AddWorker 消息处理程序



void AddWorker::OnBnClickedButton1()
{
//拿到最新的数据
UpdateData(TRUE);

// TODO: 在此添加控件通知处理程序代码

//验证数据的有效性
if (m_name.IsEmpty())
{
MessageBox(TEXT("输入信息有误"));
return;
}

WorkerManager file;
file.Read();
//获取职位名称
int index = m_job.GetCurSel();
//根据索引获取到具体内容
CString job;
m_job.GetLBText(index, job);
file.Add(m_name, job, m_wage);
file.Write();
MessageBox(TEXT("添加职工成功"));

//清空添加的新数据
m_name.Empty();
m_job.Clear();
m_wage = 0;
UpdateData(FALSE);
}

void AddWorker::OnBnClickedButton2()
{
// TODO: 在此添加控件通知处理程序代码
m_name.Empty();
m_job.Clear();
m_wage = 0;
UpdateData(FALSE);
}


void AddWorker::OnEnChangeEdit4()
{
// TODO: 如果该控件是 RICHEDIT 控件,它将不
// 发送此通知,除非重写 CFormView::OnInitDialog()
// 函数并调用 CRichEditCtrl().SetEventMask(),
// 同时将 ENM_CHANGE 标志“或”运算到掩码中。

// TODO: 在此添加控件通知处理程序代码
}


void AddWorker::OnInitialUpdate()
{
CFormView::OnInitialUpdate();

// TODO: 在此添加专用代码和/或调用基类
void InitData();//防止修改数据文件中的编号导致错误
}
42 changes: 42 additions & 0 deletions AddWorker.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#pragma once



// AddWorker 窗体视图

class AddWorker : public CFormView
{
DECLARE_DYNCREATE(AddWorker)

protected:
AddWorker(); // 动态创建所使用的受保护的构造函数
virtual ~AddWorker();

public:
#ifdef AFX_DESIGN_TIME
enum { IDD = IDD_AddWorker };
#endif
#ifdef _DEBUG
virtual void AssertValid() const;
#ifndef _WIN32_WCE
virtual void Dump(CDumpContext& dc) const;
#endif
#endif

protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持

DECLARE_MESSAGE_MAP()
private:
int m_id;
CString m_name;
CComboBox m_job;
int m_wage;
public:
afx_msg void OnBnClickedButton1();
afx_msg void OnBnClickedButton2();
afx_msg void OnEnChangeEdit4();
virtual void OnInitialUpdate();
};


12 changes: 0 additions & 12 deletions Boss.h

This file was deleted.

49 changes: 49 additions & 0 deletions CDisplayView.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// CDisplayView.cpp: 实现文件
//

#include "pch.h"
#include "WorkerManager.h"
#include "CDisplayView.h"


// CDisplayView

IMPLEMENT_DYNCREATE(CDisplayView, CFormView)

CDisplayView::CDisplayView()
: CFormView(IDD_CDisplayView1)
{

}

CDisplayView::~CDisplayView()
{
}

void CDisplayView::DoDataExchange(CDataExchange* pDX)
{
CFormView::DoDataExchange(pDX);
}

BEGIN_MESSAGE_MAP(CDisplayView, CFormView)
END_MESSAGE_MAP()


// CDisplayView 诊断

#ifdef _DEBUG
void CDisplayView::AssertValid() const
{
CFormView::AssertValid();
}

#ifndef _WIN32_WCE
void CDisplayView::Dump(CDumpContext& dc) const
{
CFormView::Dump(dc);
}
#endif
#endif //_DEBUG


// CDisplayView 消息处理程序
Loading

0 comments on commit ba34885

Please sign in to comment.