diff --git a/AFewNames.cpp b/AFewNames.cpp new file mode 100644 index 0000000..280078d --- /dev/null +++ b/AFewNames.cpp @@ -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: 在此添加控件通知处理程序代码 +} diff --git a/AFewNames.h b/AFewNames.h new file mode 100644 index 0000000..1675859 --- /dev/null +++ b/AFewNames.h @@ -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(); +}; diff --git a/AddWorker.cpp b/AddWorker.cpp new file mode 100644 index 0000000..bff639a --- /dev/null +++ b/AddWorker.cpp @@ -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();//防止修改数据文件中的编号导致错误 +} diff --git a/AddWorker.h b/AddWorker.h new file mode 100644 index 0000000..b64fa78 --- /dev/null +++ b/AddWorker.h @@ -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(); +}; + + diff --git a/Boss.h b/Boss.h deleted file mode 100644 index 2078bee..0000000 --- a/Boss.h +++ /dev/null @@ -1,12 +0,0 @@ -#pragma once -#include "Worker.h" -class Boss :public Worker -{ -public: - //캯 - Boss(int id, string name, int dID); - //ʾϢ - virtual void ShowInfo(); - //ȡλ - virtual string GetDeptName(); -}; \ No newline at end of file diff --git a/CDisplayView.cpp b/CDisplayView.cpp new file mode 100644 index 0000000..a1ed6a7 --- /dev/null +++ b/CDisplayView.cpp @@ -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 消息处理程序 diff --git a/CDisplayView.h b/CDisplayView.h new file mode 100644 index 0000000..9ff794e --- /dev/null +++ b/CDisplayView.h @@ -0,0 +1,32 @@ +#pragma once + + + +// CDisplayView 窗体视图 + +class CDisplayView : public CFormView +{ + DECLARE_DYNCREATE(CDisplayView) + +protected: + CDisplayView(); // 动态创建所使用的受保护的构造函数 + virtual ~CDisplayView(); + +public: +#ifdef AFX_DESIGN_TIME + enum { IDD = IDD_CDisplayView1 }; +#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() +}; + + diff --git a/CSelectView.cpp b/CSelectView.cpp new file mode 100644 index 0000000..225db83 --- /dev/null +++ b/CSelectView.cpp @@ -0,0 +1,128 @@ +// CSelectView.cpp: 实现文件 +// + +#include "pch.h" +#include "WorkerManager.h" +#include "CSelectView.h" +#include "MainFrm.h" + + +// CSelectView + +IMPLEMENT_DYNCREATE(CSelectView, CTreeView) + +CSelectView::CSelectView() +{ + +} + +CSelectView::~CSelectView() +{ +} + +BEGIN_MESSAGE_MAP(CSelectView, CTreeView) + ON_NOTIFY_REFLECT(TVN_SELCHANGED, &CSelectView::OnTvnSelchanged) +END_MESSAGE_MAP() + + +// CSelectView 诊断 + +#ifdef _DEBUG +void CSelectView::AssertValid() const +{ + CTreeView::AssertValid(); +} + +#ifndef _WIN32_WCE +void CSelectView::Dump(CDumpContext& dc) const +{ + CTreeView::Dump(dc); +} +#endif +#endif //_DEBUG + + +// CSelectView 消息处理程序 + + +void CSelectView::OnInitialUpdate() +{ + CTreeView::OnInitialUpdate(); + + // TODO: 在此添加专用代码和/或调用基类 + + //加载图标资源 IDI_ICON_RE + HICON icon = AfxGetApp()->LoadIconW(IDI_ICON_RE); + + //创建图标列表 + m_imageList.Create(30, 30, ILC_COLOR32, 1, 1); + + //图片列表追加图标 + m_imageList.Add(icon); + + //获取数视图中的树控件 + m_treeCtrl = &GetTreeCtrl(); + + //数控件设置图片列表 + m_treeCtrl->SetImageList(&m_imageList, TVSIL_NORMAL); + + //树控件设置节点 + m_treeCtrl->InsertItem(TEXT("主界面"), 0, 0, NULL); + m_treeCtrl->InsertItem(TEXT("添加职工信息"), 0, 0, NULL); + m_treeCtrl->InsertItem(TEXT("查看职工信息"), 0, 0, NULL); + m_treeCtrl->InsertItem(TEXT("修改职工信息"), 0, 0, NULL); + m_treeCtrl->InsertItem(TEXT("删除离职职工"), 0, 0, NULL); + m_treeCtrl->InsertItem(TEXT("查找指定职工"), 0, 0, NULL); + m_treeCtrl->InsertItem(TEXT("更新工资信息"), 0, 0, NULL); +} + + +void CSelectView::OnTvnSelchanged(NMHDR* pNMHDR, LRESULT* pResult) +{ + LPNMTREEVIEW pNMTreeView = reinterpret_cast(pNMHDR); + // TODO: 在此添加控件通知处理程序代码 + *pResult = 0; + + //获取当前节点选中项目 CTreeCtrl::GetSelectedItem + HTREEITEM item = m_treeCtrl->GetSelectedItem(); + + //获取选中项的文本内容 CTreeCtrl::GetItemText + CString str = m_treeCtrl->GetItemText(item); + + + if (str == TEXT("主界面")) + { + //CWnd::PostMessage 将一个消息放入窗口的消息队列 + //AfxGetMainWnd():框架窗口对象的指针 + //AfxGetMainWnd()->GetSafeHwnd():获取返回窗口的句柄,CWnd::GetSafeHwnd + //NM_A:发送自定义消息 + //(WPARAM)NM_A:指定了附加的消息信息 + //(LPARAM)0:指定了附加的消息信息,此参数这里没有意义 + ::PostMessage(AfxGetMainWnd()->GetSafeHwnd(), NM_A, (WPARAM)NM_A, (LPARAM)0); + } + else if (str == TEXT("添加职工信息")) + { + ::PostMessage(AfxGetMainWnd()->GetSafeHwnd(), NM_B, (WPARAM)NM_B, (LPARAM)0); + } + else if (str == TEXT("查看职工信息")) + { + ::PostMessage(AfxGetMainWnd()->GetSafeHwnd(), NM_C, (WPARAM)NM_C, (LPARAM)0); + } + else if (str == TEXT("修改职工信息")) + { + ::PostMessage(AfxGetMainWnd()->GetSafeHwnd(), NM_D, (WPARAM)NM_D, (LPARAM)0); + } + else if (str == TEXT("删除离职职工")) + { + ::PostMessage(AfxGetMainWnd()->GetSafeHwnd(), NM_E, (WPARAM)NM_E, (LPARAM)0); + } + else if (str == TEXT("查找指定职工")) + { + ::PostMessage(AfxGetMainWnd()->GetSafeHwnd(), NM_F, (WPARAM)NM_F, (LPARAM)0); + } + else if (str == TEXT("更新工资信息")) + { + ::PostMessage(AfxGetMainWnd()->GetSafeHwnd(), NM_G, (WPARAM)NM_G, (LPARAM)0); + } + +} diff --git a/CSelectView.h b/CSelectView.h new file mode 100644 index 0000000..c47f7d8 --- /dev/null +++ b/CSelectView.h @@ -0,0 +1,32 @@ +#pragma once + + +// CSelectView 视图 + +class CSelectView : public CTreeView +{ + DECLARE_DYNCREATE(CSelectView) + +protected: + CSelectView(); // 动态创建所使用的受保护的构造函数 + virtual ~CSelectView(); + +public: +#ifdef _DEBUG + virtual void AssertValid() const; +#ifndef _WIN32_WCE + virtual void Dump(CDumpContext& dc) const; +#endif +#endif + +protected: + DECLARE_MESSAGE_MAP() +private: + CTreeCtrl* m_treeCtrl;//树控件 + CImageList m_imageList;//图标列表 +public: + virtual void OnInitialUpdate(); + afx_msg void OnTvnSelchanged(NMHDR* pNMHDR, LRESULT* pResult); +}; + + diff --git a/ChangeConfirm.cpp b/ChangeConfirm.cpp new file mode 100644 index 0000000..a03ab06 --- /dev/null +++ b/ChangeConfirm.cpp @@ -0,0 +1,189 @@ +// ChangeConfirm.cpp: 实现文件 +// + +#include "pch.h" +#include "WorkerManager.h" +#include "afxdialogex.h" +#include "ChangeConfirm.h" + + +// ChangeConfirm 对话框 + +IMPLEMENT_DYNAMIC(ChangeConfirm, CDialogEx) + +ChangeConfirm::ChangeConfirm(CWnd* pParent /*=nullptr*/) + : CDialogEx(IDD_ChangeConfirm, pParent) + , c_name(_T("")) + , c_wage(0) +{ + +} + +ChangeConfirm::~ChangeConfirm() +{ +} + +void ChangeConfirm::DoDataExchange(CDataExchange* pDX) +{ + CDialogEx::DoDataExchange(pDX); + DDX_Control(pDX, IDC_LIST1, m_list); + DDX_Text(pDX, IDC_EDIT4, c_name); + DDX_Control(pDX, IDC_COMBO1, c_job); + DDX_Text(pDX, IDC_EDIT3, c_wage); +} + + +BEGIN_MESSAGE_MAP(ChangeConfirm, CDialogEx) + ON_BN_CLICKED(IDCANCEL, &ChangeConfirm::OnBnClickedCancel) + ON_BN_CLICKED(IDOK, &ChangeConfirm::OnBnClickedOk) +END_MESSAGE_MAP() + + +// ChangeConfirm 消息处理程序 + + +BOOL ChangeConfirm::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);//职工薪水 + + if (tmp.id == worker->m_id) + { + 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); + break; + } + } + ifs.close();//关闭文件 + + return TRUE; // return TRUE unless you set the focus to a control + // 异常: OCX 属性页应返回 FALSE +} + + +void ChangeConfirm::OnBnClickedCancel() +{ + // TODO: 在此添加控件通知处理程序代码 + CDialogEx::OnCancel(); +} + + +void ChangeConfirm::OnBnClickedOk() +{ + // TODO: 在此添加控件通知处理程序代码 + + UpdateData(TRUE); + ifstream ifs(FILENAME);//打开文件 + list ls;//数据容器 + char buf[1024] = { 0 };//初始化数组 + ls.clear(); + 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);//职工薪水 + + if (tmp.id == worker->m_id) + { + CStringA str1, str2; + str1 = c_name; + tmp.name = str1.GetBuffer(); + //获取职位名称 + int index = c_job.GetCurSel(); + //根据索引获取到具体内容 + CString job; + c_job.GetLBText(index, job); + str2 = job; + tmp.job = str2.GetBuffer(); + tmp.wage = c_wage; + } + ls.push_back(tmp);//放在列表后面 + } + ifs.close();//关闭文件 + + ofstream ofs(FILENAME);//打开文件 + + if (ls.size() > 0)//有内容 + { + ofs << "职工编号|职工姓名|职工级别|职工薪水" << endl;//表头 + + //写入文件 + for (list::iterator it = ls.begin(); it != ls.end(); it++) + { + ofs << it->id << "|"; + ofs << it->name << "|"; + ofs << it->job << "|"; + ofs << it->wage << endl; + } + } + + ofs.close();//关闭文件 + MessageBox(TEXT("修改成功")); + CDialogEx::OnOK(); +} diff --git a/ChangeConfirm.h b/ChangeConfirm.h new file mode 100644 index 0000000..e09b8b2 --- /dev/null +++ b/ChangeConfirm.h @@ -0,0 +1,40 @@ +#pragma once +#include "afxdialogex.h" +#include "ChangeWorker.h" + + +// ChangeConfirm 对话框 + +class ChangeConfirm : public CDialogEx +{ + DECLARE_DYNAMIC(ChangeConfirm) + friend class ChangeWorker; + +public: + ChangeConfirm(CWnd* pParent = nullptr); // 标准构造函数 + virtual ~ChangeConfirm(); + +// 对话框数据 +#ifdef AFX_DESIGN_TIME + enum { IDD = IDD_ChangeConfirm }; +#endif + +protected: + virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持 + + DECLARE_MESSAGE_MAP() +private: + CListCtrl m_list; +public: + virtual BOOL OnInitDialog(); +private: + ChangeWorker* worker; +public: + afx_msg void OnBnClickedCancel(); +private: + CString c_name; + CComboBox c_job; + int c_wage; +public: + afx_msg void OnBnClickedOk(); +}; diff --git a/ChangeWorker.cpp b/ChangeWorker.cpp new file mode 100644 index 0000000..0fb1bb7 --- /dev/null +++ b/ChangeWorker.cpp @@ -0,0 +1,184 @@ +// ChangeWorker.cpp: 实现文件 +// + +#include "pch.h" +#include "WorkerManager.h" +#include "ChangeWorker.h" +#include "ChangeConfirm.h" +#include "FindWorker.h" + + +// ChangeWorker + +IMPLEMENT_DYNCREATE(ChangeWorker, CFormView) + +ChangeWorker::ChangeWorker() + : CFormView(IDD_ChangeWorker) + , m_id(0) + , m_name(_T("")) +{ + +} + +ChangeWorker::~ChangeWorker() +{ +} + +void ChangeWorker::DoDataExchange(CDataExchange* pDX) +{ + CFormView::DoDataExchange(pDX); + DDX_Text(pDX, IDC_EDIT1, m_id); + DDX_Text(pDX, IDC_EDIT5, m_name); +} + +BEGIN_MESSAGE_MAP(ChangeWorker, CFormView) + ON_BN_CLICKED(IDC_BUTTON1, &ChangeWorker::OnBnClickedButton1) + ON_BN_CLICKED(IDC_BUTTON6, &ChangeWorker::OnBnClickedButton6) +END_MESSAGE_MAP() + + +// ChangeWorker 诊断 + +#ifdef _DEBUG +void ChangeWorker::AssertValid() const +{ + CFormView::AssertValid(); +} + +#ifndef _WIN32_WCE +void ChangeWorker::Dump(CDumpContext& dc) const +{ + CFormView::Dump(dc); +} +#endif +#endif //_DEBUG + + +// ChangeWorker 消息处理程序 + + +void ChangeWorker::OnBnClickedButton1() +{ + // TODO: 在此添加控件通知处理程序代码 + UpdateData(TRUE); + 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);//职工薪水 + + if (tmp.id == m_id) + { + ChangeConfirm m; + m.worker = this; + m.DoModal(); + break; + } + } + WorkerManager file; + file.Read(); + if (m_id > file.sum - 1) + { + MessageBox(TEXT("未找到该职工")); + } + UpdateData(FALSE); + ifs.close();//关闭文件 + m_id = 0; +} + + +void ChangeWorker::OnBnClickedButton6() +{ + // TODO: 在此添加控件通知处理程序代码 + + UpdateData(TRUE); + ifstream ifs(FILENAME);//打开文件 + char buf[1024] = { 0 };//初始化数组 + ifs.getline(buf, sizeof(buf));//取出表头 + int num = 0;//记录同名职工数量 + + 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 = m_name; + if (tmp.name == str.GetBuffer()) + { + num++; + } + } + if (num == 1) + { + ConfirmChange m; + m.worker = this; + m.DoModal(); + } + else if (num > 1) + { + SomeName s; + s.worker = this; + s.DoModal(); + } + else + { + MessageBox(TEXT("未找到该职工")); + } + UpdateData(FALSE); + ifs.close();//关闭文件 + m_name.Empty(); +} + + +void ChangeWorker::OnInitialUpdate() +{ + CFormView::OnInitialUpdate(); + + // TODO: 在此添加专用代码和/或调用基类 + + void InitData();//防止修改数据文件中的编号导致错误 +} diff --git a/ChangeWorker.h b/ChangeWorker.h new file mode 100644 index 0000000..1241832 --- /dev/null +++ b/ChangeWorker.h @@ -0,0 +1,45 @@ +#pragma once +#include "ChangeConfirm.h" +#include "ConfirmChange.h" +#include "SomeName.h" + + +// ChangeWorker 窗体视图 + +class ChangeWorker : public CFormView +{ + DECLARE_DYNCREATE(ChangeWorker) + friend class ChangeConfirm; + friend class ConfirmChange; + friend class SomeName; + +protected: + ChangeWorker(); // 动态创建所使用的受保护的构造函数 + virtual ~ChangeWorker(); + +public: +#ifdef AFX_DESIGN_TIME + enum { IDD = IDD_ChangeWorker }; +#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() +public: + afx_msg void OnBnClickedButton1(); +private: + int m_id; + CString m_name; +public: + afx_msg void OnBnClickedButton6(); + virtual void OnInitialUpdate(); +}; + + diff --git a/ConfirmChange.cpp b/ConfirmChange.cpp new file mode 100644 index 0000000..523c5e5 --- /dev/null +++ b/ConfirmChange.cpp @@ -0,0 +1,186 @@ +// ConfirmChange.cpp: 实现文件 +// + +#include "pch.h" +#include "WorkerManager.h" +#include "afxdialogex.h" +#include "ConfirmChange.h" + + +// ConfirmChange 对话框 + +IMPLEMENT_DYNAMIC(ConfirmChange, CDialogEx) + +ConfirmChange::ConfirmChange(CWnd* pParent /*=nullptr*/) + : CDialogEx(IDD_ConfirmChange, pParent) + , c_name(_T("")) + , c_wage(0) +{ + +} + +ConfirmChange::~ConfirmChange() +{ +} + +void ConfirmChange::DoDataExchange(CDataExchange* pDX) +{ + CDialogEx::DoDataExchange(pDX); + DDX_Control(pDX, IDC_LIST1, m_list); + DDX_Text(pDX, IDC_EDIT4, c_name); + DDX_Control(pDX, IDC_COMBO1, c_job); + DDX_Text(pDX, IDC_EDIT3, c_wage); +} + + +BEGIN_MESSAGE_MAP(ConfirmChange, CDialogEx) + ON_BN_CLICKED(IDOK, &ConfirmChange::OnBnClickedOk) +END_MESSAGE_MAP() + + +// ConfirmChange 消息处理程序 + + +BOOL ConfirmChange::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 ConfirmChange::OnBnClickedOk() +{ + // TODO: 在此添加控件通知处理程序代码 + + UpdateData(TRUE); + ifstream ifs(FILENAME);//打开文件 + list ls;//数据容器 + char buf[1024] = { 0 };//初始化数组 + ls.clear(); + 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()) + { + CStringA str1, str2; + str1 = c_name; + tmp.name = str1.GetBuffer(); + //获取职位名称 + int index = c_job.GetCurSel(); + //根据索引获取到具体内容 + CString job; + c_job.GetLBText(index, job); + str2 = job; + tmp.job = str2.GetBuffer(); + tmp.wage = c_wage; + } + ls.push_back(tmp);//放在列表后面 + } + ifs.close();//关闭文件 + + ofstream ofs(FILENAME);//打开文件 + + if (ls.size() > 0)//有内容 + { + ofs << "职工编号|职工姓名|职工级别|职工薪水" << endl;//表头 + + //写入文件 + for (list::iterator it = ls.begin(); it != ls.end(); it++) + { + ofs << it->id << "|"; + ofs << it->name << "|"; + ofs << it->job << "|"; + ofs << it->wage << endl; + } + } + + ofs.close();//关闭文件 + MessageBox(TEXT("修改成功")); + CDialogEx::OnOK(); +} diff --git a/ConfirmChange.h b/ConfirmChange.h new file mode 100644 index 0000000..029a152 --- /dev/null +++ b/ConfirmChange.h @@ -0,0 +1,36 @@ +#pragma once +#include "afxdialogex.h" +#include "ChangeWorker.h" + + +// ConfirmChange 对话框 + +class ConfirmChange : public CDialogEx +{ + DECLARE_DYNAMIC(ConfirmChange) + friend class ChangeWorker; + +public: + ConfirmChange(CWnd* pParent = nullptr); // 标准构造函数 + virtual ~ConfirmChange(); + +// 对话框数据 +#ifdef AFX_DESIGN_TIME + enum { IDD = IDD_ConfirmChange }; +#endif + +protected: + virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持 + + DECLARE_MESSAGE_MAP() +private: + CListCtrl m_list; + CString c_name; + CComboBox c_job; + int c_wage; + + ChangeWorker* worker; +public: + virtual BOOL OnInitDialog(); + afx_msg void OnBnClickedOk(); +}; diff --git a/ConfirmDelete.cpp b/ConfirmDelete.cpp new file mode 100644 index 0000000..a096713 --- /dev/null +++ b/ConfirmDelete.cpp @@ -0,0 +1,176 @@ +// ConfirmDelete.cpp: 实现文件 +// + +#include "pch.h" +#include "WorkerManager.h" +#include "afxdialogex.h" +#include "ConfirmDelete.h" + + +// ConfirmDelete 对话框 + +IMPLEMENT_DYNAMIC(ConfirmDelete, CDialogEx) + +ConfirmDelete::ConfirmDelete(CWnd* pParent /*=nullptr*/) + : CDialogEx(IDD_ConfirmDelete, pParent) +{ + +} + +ConfirmDelete::~ConfirmDelete() +{ +} + +void ConfirmDelete::DoDataExchange(CDataExchange* pDX) +{ + CDialogEx::DoDataExchange(pDX); + DDX_Control(pDX, IDC_LIST1, m_list); +} + + +BEGIN_MESSAGE_MAP(ConfirmDelete, CDialogEx) + ON_BN_CLICKED(IDOK, &ConfirmDelete::OnBnClickedOk) +END_MESSAGE_MAP() + + +// ConfirmDelete 消息处理程序 + + + + + +BOOL ConfirmDelete::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 ConfirmDelete::OnBnClickedOk() +{ + // TODO: 在此添加控件通知处理程序代码 + UpdateData(TRUE); + ifstream ifs(FILENAME);//打开文件 + list ls;//数据容器 + char buf[1024] = { 0 };//初始化数组 + ls.clear(); + ifs.getline(buf, sizeof(buf));//取出表头 + int index = 0;//记录编号 + 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()) + { + continue; + } + ++index; + tmp.id = index; + ls.push_back(tmp);//放在列表后面 + } + ifs.close();//关闭文件 + + ofstream ofs(FILENAME);//打开文件 + + if (ls.size() > 0)//有内容 + { + ofs << "职工编号|职工姓名|职工级别|职工薪水" << endl;//表头 + + //写入文件 + for (list::iterator it = ls.begin(); it != ls.end(); it++) + { + ofs << it->id << "|"; + ofs << it->name << "|"; + ofs << it->job << "|"; + ofs << it->wage << endl; + } + } + + ofs.close();//关闭文件 + MessageBox(TEXT("删除成功")); + CDialogEx::OnOK(); +} diff --git a/ConfirmDelete.h b/ConfirmDelete.h new file mode 100644 index 0000000..84a9761 --- /dev/null +++ b/ConfirmDelete.h @@ -0,0 +1,32 @@ +#pragma once +#include "afxdialogex.h" +#include "DeleteWorker.h" + +// ConfirmDelete 对话框 + +class ConfirmDelete : public CDialogEx +{ + DECLARE_DYNAMIC(ConfirmDelete) + friend class DeleteWorker; + +public: + ConfirmDelete(CWnd* pParent = nullptr); // 标准构造函数 + virtual ~ConfirmDelete(); + +// 对话框数据 +#ifdef AFX_DESIGN_TIME + enum { IDD = IDD_ConfirmDelete }; +#endif + +protected: + virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持 + + DECLARE_MESSAGE_MAP() +private: + CListCtrl m_list; + DeleteWorker* worker; +// virtual void PreInitDialog(); +public: + virtual BOOL OnInitDialog(); + afx_msg void OnBnClickedOk(); +}; diff --git a/DeleteConfirm.cpp b/DeleteConfirm.cpp new file mode 100644 index 0000000..d580184 --- /dev/null +++ b/DeleteConfirm.cpp @@ -0,0 +1,172 @@ +// DeleteConfirm.cpp: 实现文件 +// + +#include "pch.h" +#include "WorkerManager.h" +#include "afxdialogex.h" +#include "DeleteConfirm.h" + + +// DeleteConfirm 对话框 + +IMPLEMENT_DYNAMIC(DeleteConfirm, CDialogEx) + +DeleteConfirm::DeleteConfirm(CWnd* pParent /*=nullptr*/) + : CDialogEx(IDD_DeleteConfirm, pParent) +{ + +} + +DeleteConfirm::~DeleteConfirm() +{ +} + +void DeleteConfirm::DoDataExchange(CDataExchange* pDX) +{ + CDialogEx::DoDataExchange(pDX); + DDX_Control(pDX, IDC_LIST1, m_list); +} + + +BEGIN_MESSAGE_MAP(DeleteConfirm, CDialogEx) + ON_BN_CLICKED(IDOK, &DeleteConfirm::OnBnClickedOk) +END_MESSAGE_MAP() + + +// DeleteConfirm 消息处理程序 + + +void DeleteConfirm::OnBnClickedOk() +{ + + // TODO: 在此添加控件通知处理程序代码 + + UpdateData(TRUE); + ifstream ifs(FILENAME);//打开文件 + list ls;//数据容器 + char buf[1024] = { 0 };//初始化数组 + ls.clear(); + ifs.getline(buf, sizeof(buf));//取出表头 + int index = 0;//记录编号 + + 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);//职工薪水 + + if (tmp.id == worker->m_id) + { + continue; + } + ++index; + tmp.id = index; + ls.push_back(tmp);//放在列表后面 + } + ifs.close();//关闭文件 + + ofstream ofs(FILENAME);//打开文件 + + if (ls.size() > 0)//有内容 + { + ofs << "职工编号|职工姓名|职工级别|职工薪水" << endl;//表头 + + //写入文件 + for (list::iterator it = ls.begin(); it != ls.end(); it++) + { + ofs << it->id << "|"; + ofs << it->name << "|"; + ofs << it->job << "|"; + ofs << it->wage << endl; + } + } + + ofs.close();//关闭文件 + MessageBox(TEXT("删除成功")); + + CDialogEx::OnOK(); +} + + +BOOL DeleteConfirm::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);//职工薪水 + + if (tmp.id == worker->m_id) + { + 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); + break; + } + } + ifs.close();//关闭文件 + + return TRUE; // return TRUE unless you set the focus to a control + // 异常: OCX 属性页应返回 FALSE +} diff --git a/DeleteConfirm.h b/DeleteConfirm.h new file mode 100644 index 0000000..5e36c0a --- /dev/null +++ b/DeleteConfirm.h @@ -0,0 +1,32 @@ +#pragma once +#include "afxdialogex.h" +#include "DeleteWorker.h" + + +// DeleteConfirm 对话框 + +class DeleteConfirm : public CDialogEx +{ + DECLARE_DYNAMIC(DeleteConfirm) + friend class DeleteWorker; + +public: + DeleteConfirm(CWnd* pParent = nullptr); // 标准构造函数 + virtual ~DeleteConfirm(); + +// 对话框数据 +#ifdef AFX_DESIGN_TIME + enum { IDD = IDD_DeleteConfirm }; +#endif + +protected: + virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持 + + DECLARE_MESSAGE_MAP() +private: + CListCtrl m_list; + DeleteWorker* worker; +public: + afx_msg void OnBnClickedOk(); + virtual BOOL OnInitDialog(); +}; diff --git a/DeleteWorker.cpp b/DeleteWorker.cpp new file mode 100644 index 0000000..780a22f --- /dev/null +++ b/DeleteWorker.cpp @@ -0,0 +1,186 @@ +// DeleteWorker.cpp: 实现文件 +// + +#include "pch.h" +#include "WorkerManager.h" +#include "DeleteWorker.h" + + +// DeleteWorker + +IMPLEMENT_DYNCREATE(DeleteWorker, CFormView) + +DeleteWorker::DeleteWorker() + : CFormView(IDD_DeleteWorker) + , m_id(0) + , m_name(_T("")) +{ + +} + +DeleteWorker::~DeleteWorker() +{ +} + +void DeleteWorker::DoDataExchange(CDataExchange* pDX) +{ + CFormView::DoDataExchange(pDX); + DDX_Text(pDX, IDC_EDIT1, m_id); + DDX_Text(pDX, IDC_EDIT5, m_name); +} + +BEGIN_MESSAGE_MAP(DeleteWorker, CFormView) + ON_BN_CLICKED(IDC_BUTTON6, &DeleteWorker::OnBnClickedButton6) + ON_BN_CLICKED(IDC_BUTTON1, &DeleteWorker::OnBnClickedButton1) +END_MESSAGE_MAP() + + +// DeleteWorker 诊断 + +#ifdef _DEBUG +void DeleteWorker::AssertValid() const +{ + CFormView::AssertValid(); +} + +#ifndef _WIN32_WCE +void DeleteWorker::Dump(CDumpContext& dc) const +{ + CFormView::Dump(dc); +} +#endif +#endif //_DEBUG + + +// DeleteWorker 消息处理程序 + + +void DeleteWorker::OnBnClickedButton6() +{ + // TODO: 在此添加控件通知处理程序代码 + + UpdateData(TRUE); + ifstream ifs(FILENAME);//打开文件 + char buf[1024] = { 0 };//初始化数组 + ifs.getline(buf, sizeof(buf));//取出表头 + int num = 0;//记录同名职工数量 + + 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 = m_name; + if (tmp.name == str.GetBuffer()) + { + num++; + } + } + if (num == 1) + { + ConfirmDelete m; + m.worker = this; + m.DoModal(); + } + else if (num > 1) + { + AFewNames s; + s.worker = this; + s.DoModal(); + } + else + { + MessageBox(TEXT("未找到该职工")); + } + UpdateData(FALSE); + ifs.close();//关闭文件 + m_name.Empty(); +} + + +void DeleteWorker::OnBnClickedButton1() +{ + // TODO: 在此添加控件通知处理程序代码 + + UpdateData(TRUE); + ifstream ifs(FILENAME);//打开文件 + char buf[1024] = { 0 };//初始化数组 + ifs.getline(buf, sizeof(buf));//取出表头 + int num = 0;//记录出现次数,以提示未找到职工 + + 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);//职工薪水 + + if (tmp.id == m_id) + { + num++; + break; + } + } + if (num == 1) + { + DeleteConfirm m; + m.worker = this; + m.DoModal(); + } + else + { + MessageBox(TEXT("未找到该职工")); + } + UpdateData(FALSE); + ifs.close();//关闭文件 + m_id = 0; +} + + +void DeleteWorker::OnInitialUpdate() +{ + CFormView::OnInitialUpdate(); + + // TODO: 在此添加专用代码和/或调用基类 + + void InitData();//防止修改数据文件中的编号导致错误 +} diff --git a/DeleteWorker.h b/DeleteWorker.h new file mode 100644 index 0000000..ac817bf --- /dev/null +++ b/DeleteWorker.h @@ -0,0 +1,44 @@ +#pragma once +#include "AFewNames.h" +#include "ConfirmDelete.h" +#include "DeleteConfirm.h" + + +// DeleteWorker 窗体视图 + +class DeleteWorker : public CFormView +{ + DECLARE_DYNCREATE(DeleteWorker) + friend class AFewNames; + friend class ConfirmDelete; + friend class DeleteConfirm; + +protected: + DeleteWorker(); // 动态创建所使用的受保护的构造函数 + virtual ~DeleteWorker(); + +public: +#ifdef AFX_DESIGN_TIME + enum { IDD = IDD_DeleteWorker }; +#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; +public: + afx_msg void OnBnClickedButton6(); + afx_msg void OnBnClickedButton1(); + virtual void OnInitialUpdate(); +}; + + diff --git a/Employee.h b/Employee.h deleted file mode 100644 index daa69e7..0000000 --- a/Employee.h +++ /dev/null @@ -1,12 +0,0 @@ -#pragma once -#include "Worker.h" -class Employee :public Worker -{ -public: - //캯 - Employee(int id, string name, int dID); - //ʾϢ - virtual void ShowInfo(); - //ȡλ - virtual string GetDeptName(); -}; \ No newline at end of file diff --git a/FindWorker.cpp b/FindWorker.cpp new file mode 100644 index 0000000..951f612 --- /dev/null +++ b/FindWorker.cpp @@ -0,0 +1,220 @@ +// FindWorker.cpp: 实现文件 +// + +#include "pch.h" +#include "WorkerManager.h" +#include "FindWorker.h" + + +// FindWorker + +IMPLEMENT_DYNCREATE(FindWorker, CFormView) + +FindWorker::FindWorker() + : CFormView(IDD_FindWorker) + , m_id(0) + , m_name(_T("")) +{ + +} + +FindWorker::~FindWorker() +{ +} + +void FindWorker::DoDataExchange(CDataExchange* pDX) +{ + CFormView::DoDataExchange(pDX); + DDX_Control(pDX, IDC_LIST2, m_list); + DDX_Text(pDX, IDC_EDIT1, m_id); + DDX_Text(pDX, IDC_EDIT2, m_name); +} + +BEGIN_MESSAGE_MAP(FindWorker, CFormView) + ON_BN_CLICKED(IDC_BUTTON1, &FindWorker::OnBnClickedButton1) + ON_BN_CLICKED(IDC_BUTTON3, &FindWorker::OnBnClickedButton3) + ON_BN_CLICKED(IDC_BUTTON2, &FindWorker::OnBnClickedButton2) + ON_BN_CLICKED(IDC_BUTTON4, &FindWorker::OnBnClickedButton4) + ON_BN_CLICKED(IDC_BUTTON5, &FindWorker::OnBnClickedButton5) +END_MESSAGE_MAP() + + +// FindWorker 诊断 + +#ifdef _DEBUG +void FindWorker::AssertValid() const +{ + CFormView::AssertValid(); +} + +#ifndef _WIN32_WCE +void FindWorker::Dump(CDumpContext& dc) const +{ + CFormView::Dump(dc); +} +#endif +#endif //_DEBUG + + +// FindWorker 消息处理程序 + + + +void FindWorker::OnBnClickedButton1() +{ + // TODO: 在此添加控件通知处理程序代码 + m_id = 0; + UpdateData(FALSE); +} + + +void FindWorker::OnBnClickedButton3() +{ + // TODO: 在此添加控件通知处理程序代码 + m_name.Empty(); + UpdateData(FALSE); +} + + +void FindWorker::OnBnClickedButton2()//按编号查找 +{ + UpdateData(TRUE); + 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);//职工薪水 + + if (tmp.id == m_id) + { + 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); + break; + } + } + ifs.close();//关闭文件 + WorkerManager file; + file.Read(); + if (m_id > file.sum - 1) + { + MessageBox(TEXT("未找到该职工")); + } + UpdateData(FALSE); + m_id = 0; +} + + +void FindWorker::OnInitialUpdate() +{ + CFormView::OnInitialUpdate(); + + // TODO: 在此添加专用代码和/或调用基类 + + void InitData();//防止修改数据文件中的编号导致错误 + + // 设置扩展风格 + //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); + } +} + + +void FindWorker::OnBnClickedButton4() +{ + // TODO: 在此添加控件通知处理程序代码 + UpdateData(TRUE); + 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);//职工薪水 + + string str = CT2A(m_name.GetBuffer());//将CString类型转化为string类型 + + if (tmp.name == str)//输出到列表 + { + 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();//关闭文件 + FindWorker find; + if (find.FindName(m_name)) + { + MessageBox(TEXT("未找到该职工")); + } + UpdateData(FALSE); + m_name.Empty(); +} + + + +void FindWorker::OnBnClickedButton5()//清空 +{ + // TODO: 在此添加控件通知处理程序代码 + m_list.DeleteAllItems();//删除所有内容 +} diff --git a/FindWorker.h b/FindWorker.h new file mode 100644 index 0000000..130aebc --- /dev/null +++ b/FindWorker.h @@ -0,0 +1,92 @@ +#pragma once +#include + + +// FindWorker 窗体视图 + +class FindWorker : public CFormView +{ + DECLARE_DYNCREATE(FindWorker) + +protected: + FindWorker(); // 动态创建所使用的受保护的构造函数 + virtual ~FindWorker(); + +public: +#ifdef AFX_DESIGN_TIME + enum { IDD = IDD_FindWorker }; +#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: + CListCtrl m_list; +public: +// virtual void OnInitialUpdate(); +private: + int m_id; + CString m_name; +public: + afx_msg void OnBnClickedButton1(); + afx_msg void OnBnClickedButton3(); + afx_msg void OnBnClickedButton2(); + virtual void OnInitialUpdate(); + afx_msg void OnBnClickedButton4(); + + +private: + bool FindName(CString cstr)//构造判断职工是否存在函数 + { + 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);//职工薪水 + + string str = CT2A(cstr.GetBuffer()); + + if (tmp.name == str) + { + return FALSE; + break; + } + } + ifs.close();//关闭文件 + return TRUE; + } +public: + afx_msg void OnBnClickedButton5(); +}; + + diff --git a/Hour.cpp b/Hour.cpp new file mode 100644 index 0000000..aa60988 --- /dev/null +++ b/Hour.cpp @@ -0,0 +1,179 @@ +// Hour.cpp: 实现文件 +// + +#include "pch.h" +#include "WorkerManager.h" +#include "afxdialogex.h" +#include "Hour.h" + + +// Hour 对话框 + +IMPLEMENT_DYNAMIC(Hour, CDialogEx) + +Hour::Hour(CWnd* pParent /*=nullptr*/) + : CDialogEx(IDD_Hour, pParent) +{ + +} + +Hour::~Hour() +{ +} + +void Hour::DoDataExchange(CDataExchange* pDX) +{ + CDialogEx::DoDataExchange(pDX); + DDX_Control(pDX, IDC_LIST1, m_list1); + DDX_Control(pDX, IDC_LIST3, m_list2); +} + + +BEGIN_MESSAGE_MAP(Hour, CDialogEx) + ON_BN_CLICKED(IDOK, &Hour::OnBnClickedOk) +END_MESSAGE_MAP() + + +// Hour 消息处理程序 + + +BOOL Hour::OnInitDialog() +{ + CDialogEx::OnInitDialog(); + + // TODO: 在此添加额外的初始化 + + // 设置扩展风格 + //LVS_EX_FULLROWSELECT选中整行,LVS_EX_GRIDLINES网格 + m_list1.SetExtendedStyle(m_list1.GetExtendedStyle() | LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES); + m_list2.SetExtendedStyle(m_list2.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_list1.InsertColumn(i, field[i], LVCFMT_CENTER, 105); + m_list2.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);//职工薪水 + + int n_wage = 18 * wage->m_hour; + + if (tmp.id == wage->m_id1) + { + CString str1, str2, str3, str4, str5; + str1.Format(_T("%d"), tmp.id); + m_list1.InsertItem(0, str1); + int column = 1; + m_list1.SetItemText(0, column++, (CString)tmp.name.c_str()); + m_list1.SetItemText(0, column++, (CString)tmp.job.c_str()); + str4.Format(_T("%d"), tmp.wage); + m_list1.SetItemText(0, column++, str4); + m_list2.InsertItem(0, str1); + column = 1; + m_list2.SetItemText(0, column++, (CString)tmp.name.c_str()); + m_list2.SetItemText(0, column++, (CString)tmp.job.c_str()); + str5.Format(_T("%d"), n_wage); + m_list2.SetItemText(0, column++, str5); + break; + } + } + ifs.close();//关闭文件 + + return TRUE; // return TRUE unless you set the focus to a control + // 异常: OCX 属性页应返回 FALSE +} + + +void Hour::OnBnClickedOk() +{ + // TODO: 在此添加控件通知处理程序代码 + + UpdateData(TRUE); + ifstream ifs(FILENAME);//打开文件 + list ls;//数据容器 + char buf[1024] = { 0 };//初始化数组 + ls.clear(); + 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);//职工薪水 + + if (tmp.id == wage->m_id1) + { + tmp.wage = 18 * wage->m_hour; + } + ls.push_back(tmp);//放在列表后面 + } + ifs.close();//关闭文件 + + ofstream ofs(FILENAME);//打开文件 + + if (ls.size() > 0)//有内容 + { + ofs << "职工编号|职工姓名|职工级别|职工薪水" << endl;//表头 + + //写入文件 + for (list::iterator it = ls.begin(); it != ls.end(); it++) + { + ofs << it->id << "|"; + ofs << it->name << "|"; + ofs << it->job << "|"; + ofs << it->wage << endl; + } + } + + ofs.close();//关闭文件 + MessageBox(TEXT("更新成功")); + + CDialogEx::OnOK(); +} diff --git a/Hour.h b/Hour.h new file mode 100644 index 0000000..8b2ed0d --- /dev/null +++ b/Hour.h @@ -0,0 +1,32 @@ +#pragma once +#include "afxdialogex.h" +#include "Wage.h" + +// Hour 对话框 + +class Hour : public CDialogEx +{ + DECLARE_DYNAMIC(Hour) + friend class Wage; + +public: + Hour(CWnd* pParent = nullptr); // 标准构造函数 + virtual ~Hour(); + +// 对话框数据 +#ifdef AFX_DESIGN_TIME + enum { IDD = IDD_Hour }; +#endif + +protected: + virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持 + + DECLARE_MESSAGE_MAP() +private: + CListCtrl m_list1; + CListCtrl m_list2; + Wage* wage; +public: + virtual BOOL OnInitDialog(); + afx_msg void OnBnClickedOk(); +}; diff --git a/ListWorker.cpp b/ListWorker.cpp new file mode 100644 index 0000000..806a2fa --- /dev/null +++ b/ListWorker.cpp @@ -0,0 +1,92 @@ +// ListWorker.cpp: 实现文件 +// + +#include "pch.h" +#include "WorkerManager.h" +#include "ListWorker.h" + + +// ListWorker + +IMPLEMENT_DYNCREATE(ListWorker, CFormView) + +ListWorker::ListWorker() + : CFormView(IDD_ListWorker) +{ + +} + +ListWorker::~ListWorker() +{ +} + +void ListWorker::DoDataExchange(CDataExchange* pDX) +{ + CFormView::DoDataExchange(pDX); + DDX_Control(pDX, IDC_LIST1, m_list); +} + +BEGIN_MESSAGE_MAP(ListWorker, CFormView) +END_MESSAGE_MAP() + + +// ListWorker 诊断 + +#ifdef _DEBUG +void ListWorker::AssertValid() const +{ + CFormView::AssertValid(); +} + +#ifndef _WIN32_WCE +void ListWorker::Dump(CDumpContext& dc) const +{ + CFormView::Dump(dc); +} +#endif +#endif //_DEBUG + + +// ListWorker 消息处理程序 + + +void ListWorker::OnInitialUpdate() +{ + CFormView::OnInitialUpdate(); + + // TODO: 在此添加专用代码和/或调用基类 + + void InitData();//防止修改数据文件中的编号导致错误 + + // 设置扩展风格 + //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); + } + + WorkerManager file; + file.Read(); //读取商品信息 + + //添加数据 + int i = 0; + CString str1; + CString str2; + for (list::iterator it = file.ls.begin(); it != file.ls.end(); it++) + { + str1.Format(_T("%d"), it->id); + m_list.InsertItem(i, str1); + int column = 1; + m_list.SetItemText(i, column++, (CString)it->name.c_str()); + m_list.SetItemText(i, column++, (CString)it->job.c_str()); + str2.Format(_T("%d"), it->wage); + m_list.SetItemText(i, column++, str2); + str1.Format(_T("%d"), it->sum); + i++; + } + +} diff --git a/ListWorker.h b/ListWorker.h new file mode 100644 index 0000000..02a2466 --- /dev/null +++ b/ListWorker.h @@ -0,0 +1,36 @@ +#pragma once + + + +// ListWorker 窗体视图 + +class ListWorker : public CFormView +{ + DECLARE_DYNCREATE(ListWorker) + +protected: + ListWorker(); // 动态创建所使用的受保护的构造函数 + virtual ~ListWorker(); + +public: +#ifdef AFX_DESIGN_TIME + enum { IDD = IDD_ListWorker }; +#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: + CListCtrl m_list; +public: + virtual void OnInitialUpdate(); +}; + + diff --git a/MainFrm.cpp b/MainFrm.cpp new file mode 100644 index 0000000..f251af1 --- /dev/null +++ b/MainFrm.cpp @@ -0,0 +1,230 @@ + +// MainFrm.cpp: CMainFrame 类的实现 +// + +#include "pch.h" +#include "framework.h" +#include "WorkerManager.h" + +#include "MainFrm.h" + +#include "CDisplayView.h" +#include "CSelectView.h" + +#include "WelcomeDlg.h" +#include "AddWorker.h" +#include "ListWorker.h" +#include "ChangeWorker.h" +#include "DeleteWorker.h" +#include "FindWorker.h" +#include "Wage.h" + +#ifdef _DEBUG +#define new DEBUG_NEW +#endif + +// CMainFrame + +IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd) + +BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd) + ON_WM_CREATE() + + //ON_MESSAGE响应的是自定义消息 + //产生NM_X消息,自动调用OnMyChange函数 + ON_MESSAGE(NM_A, OnMyChange) + ON_MESSAGE(NM_B, OnMyChange) + ON_MESSAGE(NM_C, OnMyChange) + ON_MESSAGE(NM_D, OnMyChange) + ON_MESSAGE(NM_E, OnMyChange) + ON_MESSAGE(NM_F, OnMyChange) + ON_MESSAGE(NM_G, OnMyChange) + +END_MESSAGE_MAP() + +static UINT indicators[] = +{ + ID_SEPARATOR, // 状态行指示器 + ID_INDICATOR_CAPS, + ID_INDICATOR_NUM, + ID_INDICATOR_SCRL, +}; + +// CMainFrame 构造/析构 + +CMainFrame::CMainFrame() noexcept +{ + // TODO: 在此添加成员初始化代码 +} + +CMainFrame::~CMainFrame() +{ +} + +int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) +{ + if (CFrameWnd::OnCreate(lpCreateStruct) == -1) + return -1; + + if (!m_wndStatusBar.Create(this)) + { + TRACE0("未能创建状态栏\n"); + return -1; // 未能创建 + } + m_wndStatusBar.SetIndicators(indicators, sizeof(indicators)/sizeof(UINT)); + + //设置窗口位置和大小(起点坐标x,y,窗口宽度,高度) + MoveWindow(0, 0, 800, 600); + + return 0; +} + +BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs) +{ + if( !CFrameWnd::PreCreateWindow(cs) ) + return FALSE; + // TODO: 在此处通过修改 + // CREATESTRUCT cs 来修改窗口类或样式 + + return TRUE; +} + +// CMainFrame 诊断 + +#ifdef _DEBUG +void CMainFrame::AssertValid() const +{ + CFrameWnd::AssertValid(); +} + +void CMainFrame::Dump(CDumpContext& dc) const +{ + CFrameWnd::Dump(dc); +} +#endif //_DEBUG + + +// CMainFrame 消息处理程序 + + + +BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext) +{ + // TODO: 在此添加专用代码和/或调用基类 + + //静态拆分窗口,1行2列 + m_spliter.CreateStatic(this, 1, 2); + //创建视图,第0行,第0列 + //CSize()宽度200,高度500 + m_spliter.CreateView(0, 0, RUNTIME_CLASS(CSelectView), CSize(200, 500), pContext); + + m_spliter.CreateView(0, 1, RUNTIME_CLASS(CDisplayView), CSize(600, 500), pContext); + + //return CFrameWnd::OnCreateClient(lpcs, pContext); + return TRUE; +} + +LRESULT CMainFrame::OnMyChange(WPARAM wParam, LPARAM lParam) +{ + CCreateContext Context; + switch (wParam) + { + case NM_A: + { + Context.m_pNewViewClass = RUNTIME_CLASS(WelcomeDlg); + Context.m_pCurrentFrame = this; + Context.m_pLastView = (CFormView*)m_spliter.GetPane(0, 1); + m_spliter.DeleteView(0, 1); + m_spliter.CreateView(0, 1, RUNTIME_CLASS(WelcomeDlg), CSize(600, 0), &Context); + WelcomeDlg* pNewView = (WelcomeDlg*)m_spliter.GetPane(0, 1); + m_spliter.RecalcLayout(); + pNewView->OnInitialUpdate(); + m_spliter.SetActivePane(0, 1); + } + + break; + case NM_B: + { + Context.m_pNewViewClass = RUNTIME_CLASS(AddWorker); + Context.m_pCurrentFrame = this; + Context.m_pLastView = (CFormView*)m_spliter.GetPane(0, 1); + m_spliter.DeleteView(0, 1); + m_spliter.CreateView(0, 1, RUNTIME_CLASS(AddWorker), CSize(600, 500), &Context); + AddWorker* pNewView = (AddWorker*)m_spliter.GetPane(0, 1); + m_spliter.RecalcLayout(); + pNewView->OnInitialUpdate(); + m_spliter.SetActivePane(0, 1); + } + break; + case NM_C: + { + Context.m_pNewViewClass = RUNTIME_CLASS(ListWorker); + Context.m_pCurrentFrame = this; + Context.m_pLastView = (CFormView*)m_spliter.GetPane(0, 1); + m_spliter.DeleteView(0, 1); + m_spliter.CreateView(0, 1, RUNTIME_CLASS(ListWorker), CSize(600, 500), &Context); + ListWorker* pNewView = (ListWorker*)m_spliter.GetPane(0, 1); + m_spliter.RecalcLayout(); + pNewView->OnInitialUpdate(); + m_spliter.SetActivePane(0, 1); + } + break; + case NM_D: + { + Context.m_pNewViewClass = RUNTIME_CLASS(ChangeWorker); + Context.m_pCurrentFrame = this; + Context.m_pLastView = (CFormView*)m_spliter.GetPane(0, 1); + m_spliter.DeleteView(0, 1); + m_spliter.CreateView(0, 1, RUNTIME_CLASS(ChangeWorker), CSize(600, 500), &Context); + ChangeWorker* pNewView = (ChangeWorker*)m_spliter.GetPane(0, 1); + m_spliter.RecalcLayout(); + pNewView->OnInitialUpdate(); + m_spliter.SetActivePane(0, 1); + } + break; + case NM_E: + { + Context.m_pNewViewClass = RUNTIME_CLASS(DeleteWorker); + Context.m_pCurrentFrame = this; + Context.m_pLastView = (CFormView*)m_spliter.GetPane(0, 1); + m_spliter.DeleteView(0, 1); + m_spliter.CreateView(0, 1, RUNTIME_CLASS(DeleteWorker), CSize(600, 500), &Context); + DeleteWorker* pNewView = (DeleteWorker*)m_spliter.GetPane(0, 1); + m_spliter.RecalcLayout(); + pNewView->OnInitialUpdate(); + m_spliter.SetActivePane(0, 1); + } + break; + case NM_F: + { + Context.m_pNewViewClass = RUNTIME_CLASS(FindWorker); + Context.m_pCurrentFrame = this; + Context.m_pLastView = (CFormView*)m_spliter.GetPane(0, 1); + m_spliter.DeleteView(0, 1); + m_spliter.CreateView(0, 1, RUNTIME_CLASS(FindWorker), CSize(600, 500), &Context); + FindWorker* pNewView = (FindWorker*)m_spliter.GetPane(0, 1); + m_spliter.RecalcLayout(); + pNewView->OnInitialUpdate(); + m_spliter.SetActivePane(0, 1); + } + break; + case NM_G: + { + Context.m_pNewViewClass = RUNTIME_CLASS(Wage); + Context.m_pCurrentFrame = this; + Context.m_pLastView = (CFormView*)m_spliter.GetPane(0, 1); + m_spliter.DeleteView(0, 1); + m_spliter.CreateView(0, 1, RUNTIME_CLASS(Wage), CSize(600, 500), &Context); + Wage* pNewView = (Wage*)m_spliter.GetPane(0, 1); + m_spliter.RecalcLayout(); + pNewView->OnInitialUpdate(); + m_spliter.SetActivePane(0, 1); + } + break; + default: + MessageBox(_T("error")); + } + return 0; + +} + diff --git a/MainFrm.h b/MainFrm.h new file mode 100644 index 0000000..9207eba --- /dev/null +++ b/MainFrm.h @@ -0,0 +1,57 @@ + +// MainFrm.h: CMainFrame 类的接口 +// + +#pragma once +//WM_USER 是用户自定义消息的一个起始值 +//WM_USER+100是为了区分系统消息和用户消息,避免冲突 +#define NM_A (WM_USER + 100) +#define NM_B (WM_USER + 101) +#define NM_C (WM_USER + 102) +#define NM_D (WM_USER + 103) +#define NM_E (WM_USER + 104) +#define NM_F (WM_USER + 105) +#define NM_G (WM_USER + 106) + +class CMainFrame : public CFrameWnd +{ + +protected: // 仅从序列化创建 + CMainFrame() noexcept; + DECLARE_DYNCREATE(CMainFrame) + +// 特性 +public: + +// 操作 +public: + +// 重写 +public: + virtual BOOL PreCreateWindow(CREATESTRUCT& cs); + +// 实现 +public: + virtual ~CMainFrame(); +#ifdef _DEBUG + virtual void AssertValid() const; + virtual void Dump(CDumpContext& dc) const; +#endif + +protected: // 控件条嵌入成员 + CStatusBar m_wndStatusBar; + +// 生成的消息映射函数 +protected: + afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct); + DECLARE_MESSAGE_MAP() + +private: + CSplitterWnd m_spliter;//切分窗口类对象 + virtual BOOL OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext); + + //自定义消息处理函数 + afx_msg LRESULT OnMyChange(WPARAM wParam, LPARAM lParam); +}; + + diff --git a/Manager.h b/Manager.h deleted file mode 100644 index 3d65d25..0000000 --- a/Manager.h +++ /dev/null @@ -1,12 +0,0 @@ -#pragma once -#include "Worker.h" -class Manager :public Worker -{ -public: - //캯 - Manager(int id, string name, int dID); - //ʾϢ - virtual void ShowInfo(); - //ȡλ - virtual string GetDeptName(); -}; \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..b71998f --- /dev/null +++ b/README.md @@ -0,0 +1,14 @@ +# WorkerManager + +**请先在项目属性--》常规--》平台工具集选择已安装的工具链** + +由于微软在VS2013中不建议再使用C/C++的传统库函数scanf,strcpy,sprintf等,所以直接使用这些库函数会提示C4996错误。 + + + +VS建议采用带_s的函数,如scanf_s、strcpy_s,但这些并不是标准C/C++函数。要想继续使用此函数,需要添加 _CRT_SECURE_NO_WARNINGS这个预定义。 + + + +在项目 -> 属性 -> C/C++->预处理器 -> 预处理器定中添加 _CRT_SECURE_NO_WARNINGS: + diff --git a/SellManager.cpp b/SellManager.cpp new file mode 100644 index 0000000..068b4b3 --- /dev/null +++ b/SellManager.cpp @@ -0,0 +1,178 @@ +// SellManager.cpp: 实现文件 +// + +#include "pch.h" +#include "WorkerManager.h" +#include "afxdialogex.h" +#include "SellManager.h" + + +// SellManager 对话框 + +IMPLEMENT_DYNAMIC(SellManager, CDialogEx) + +SellManager::SellManager(CWnd* pParent /*=nullptr*/) + : CDialogEx(IDD_SellManager, pParent) +{ + +} + +SellManager::~SellManager() +{ +} + +void SellManager::DoDataExchange(CDataExchange* pDX) +{ + CDialogEx::DoDataExchange(pDX); + DDX_Control(pDX, IDC_LIST1, m_list1); + DDX_Control(pDX, IDC_LIST3, m_list2); +} + + +BEGIN_MESSAGE_MAP(SellManager, CDialogEx) + ON_BN_CLICKED(IDOK, &SellManager::OnBnClickedOk) +END_MESSAGE_MAP() + + +// SellManager 消息处理程序 + + + +BOOL SellManager::OnInitDialog() +{ + CDialogEx::OnInitDialog(); + + // TODO: 在此添加额外的初始化 + + // 设置扩展风格 + //LVS_EX_FULLROWSELECT选中整行,LVS_EX_GRIDLINES网格 + m_list1.SetExtendedStyle(m_list1.GetExtendedStyle() | LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES); + m_list2.SetExtendedStyle(m_list2.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_list1.InsertColumn(i, field[i], LVCFMT_CENTER, 105); + m_list2.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);//职工薪水 + + int sm_wage = wage->n_wage + tmp.wage; + + if (tmp.job == "销售经理") + { + CString str1, str2, str3, str4, str5; + str1.Format(_T("%d"), tmp.id); + m_list1.InsertItem(0, str1); + int column = 1; + m_list1.SetItemText(0, column++, (CString)tmp.name.c_str()); + m_list1.SetItemText(0, column++, (CString)tmp.job.c_str()); + str4.Format(_T("%d"), tmp.wage); + m_list1.SetItemText(0, column++, str4); + m_list2.InsertItem(0, str1); + column = 1; + m_list2.SetItemText(0, column++, (CString)tmp.name.c_str()); + m_list2.SetItemText(0, column++, (CString)tmp.job.c_str()); + str5.Format(_T("%d"), sm_wage); + m_list2.SetItemText(0, column++, str5); + } + } + ifs.close();//关闭文件 + + return TRUE; // return TRUE unless you set the focus to a control + // 异常: OCX 属性页应返回 FALSE +} + + +void SellManager::OnBnClickedOk() +{ + // TODO: 在此添加控件通知处理程序代码 + + ifstream ifs(FILENAME);//打开文件 + list ls;//数据容器 + char buf[1024] = { 0 };//初始化数组 + ls.clear(); + 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);//职工薪水 + + if (tmp.job == "销售经理") + { + tmp.wage += wage->n_wage; + } + ls.push_back(tmp);//放在列表后面 + } + ifs.close();//关闭文件 + + ofstream ofs(FILENAME);//打开文件 + + if (ls.size() > 0)//有内容 + { + ofs << "职工编号|职工姓名|职工级别|职工薪水" << endl;//表头 + + //写入文件 + for (list::iterator it = ls.begin(); it != ls.end(); it++) + { + ofs << it->id << "|"; + ofs << it->name << "|"; + ofs << it->job << "|"; + ofs << it->wage << endl; + } + } + + ofs.close();//关闭文件 + MessageBox(TEXT("更新成功")); + + CDialogEx::OnOK(); +} diff --git a/SellManager.h b/SellManager.h new file mode 100644 index 0000000..f9e722a --- /dev/null +++ b/SellManager.h @@ -0,0 +1,33 @@ +#pragma once +#include "afxdialogex.h" +#include "Wage.h" + +// SellManager 对话框 + +class SellManager : public CDialogEx +{ + DECLARE_DYNAMIC(SellManager) + friend class Wage; + +public: + SellManager(CWnd* pParent = nullptr); // 标准构造函数 + virtual ~SellManager(); + +// 对话框数据 +#ifdef AFX_DESIGN_TIME + enum { IDD = IDD_SellManager }; +#endif + +protected: + virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持 + + DECLARE_MESSAGE_MAP() +private: + CListCtrl m_list1; + CListCtrl m_list2; + Wage* wage; +// virtual void PreInitDialog(); +public: + virtual BOOL OnInitDialog(); + afx_msg void OnBnClickedOk(); +}; diff --git a/SomeName.cpp b/SomeName.cpp new file mode 100644 index 0000000..e9b7e00 --- /dev/null +++ b/SomeName.cpp @@ -0,0 +1,102 @@ +// SomeName.cpp: 实现文件 +// + +#include "pch.h" +#include "WorkerManager.h" +#include "afxdialogex.h" +#include "SomeName.h" + + +// SomeName 对话框 + +IMPLEMENT_DYNAMIC(SomeName, CDialogEx) + +SomeName::SomeName(CWnd* pParent /*=nullptr*/) + : CDialogEx(IDD_SomeNames, pParent) +{ + +} + +SomeName::~SomeName() +{ +} + +void SomeName::DoDataExchange(CDataExchange* pDX) +{ + CDialogEx::DoDataExchange(pDX); + DDX_Control(pDX, IDC_LIST2, m_list); +} + + +BEGIN_MESSAGE_MAP(SomeName, CDialogEx) +END_MESSAGE_MAP() + + +// SomeName 消息处理程序 + + +BOOL SomeName::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 +} diff --git a/SomeName.h b/SomeName.h new file mode 100644 index 0000000..6cf1701 --- /dev/null +++ b/SomeName.h @@ -0,0 +1,31 @@ +#pragma once +#include "afxdialogex.h" +#include "ChangeWorker.h" + + +// SomeName 对话框 + +class SomeName : public CDialogEx +{ + DECLARE_DYNAMIC(SomeName) + friend class ChangeWorker; + +public: + SomeName(CWnd* pParent = nullptr); // 标准构造函数 + virtual ~SomeName(); + +// 对话框数据 +#ifdef AFX_DESIGN_TIME + enum { IDD = IDD_SomeNames }; +#endif + +protected: + virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持 + + DECLARE_MESSAGE_MAP() +private: + CListCtrl m_list; + ChangeWorker* worker; +public: + virtual BOOL OnInitDialog(); +}; diff --git a/Wage.cpp b/Wage.cpp new file mode 100644 index 0000000..2cc34d1 --- /dev/null +++ b/Wage.cpp @@ -0,0 +1,251 @@ +// Wage.cpp: 实现文件 +// + +#include "pch.h" +#include "WorkerManager.h" +#include "Wage.h" + + +// Wage + +IMPLEMENT_DYNCREATE(Wage, CFormView) + +Wage::Wage() + : CFormView(IDD_Wage) + , m_id1(0) + , m_hour(0) + , m_id2(0) + , m_yuan(0) +{ + +} + +Wage::~Wage() +{ +} + +void Wage::DoDataExchange(CDataExchange* pDX) +{ + CFormView::DoDataExchange(pDX); + DDX_Text(pDX, IDC_EDIT1, m_id1); + DDX_Text(pDX, IDC_EDIT2, m_hour); + DDX_Text(pDX, IDC_EDIT6, m_id2); + DDX_Text(pDX, IDC_EDIT7, m_yuan); +} + +BEGIN_MESSAGE_MAP(Wage, CFormView) + ON_BN_CLICKED(IDC_BUTTON2, &Wage::OnBnClickedButton2) + ON_BN_CLICKED(IDC_BUTTON3, &Wage::OnBnClickedButton3) + ON_BN_CLICKED(IDC_BUTTON7, &Wage::OnBnClickedButton7) + ON_BN_CLICKED(IDC_BUTTON5, &Wage::OnBnClickedButton5) +END_MESSAGE_MAP() + + +// Wage 诊断 + +#ifdef _DEBUG +void Wage::AssertValid() const +{ + CFormView::AssertValid(); +} + +#ifndef _WIN32_WCE +void Wage::Dump(CDumpContext& dc) const +{ + CFormView::Dump(dc); +} +#endif +#endif //_DEBUG + + +// Wage 消息处理程序 + + +void Wage::OnBnClickedButton2() +{ + // TODO: 在此添加控件通知处理程序代码 + + MessageBox(TEXT("经理拿固定月薪\n兼职技术人员按工作小时数领取月薪(每小时18元)\n兼职推销员的报酬按该推销员当月销售额提成(85%)\n销售经理既拿固定月薪也领取销售提成(6%)")); +} + + +void Wage::OnBnClickedButton3() +{ + // TODO: 在此添加控件通知处理程序代码 + + UpdateData(TRUE); + 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);//职工薪水 + + if (tmp.id == m_id1) + { + if (tmp.job != "兼职技术人员") + { + MessageBox(TEXT("该职工不符合选定职工类型")); + break; + } + else + { + Hour h; + h.wage = this; + h.DoModal(); + } + break; + } + } + ifs.close();//关闭文件 + WorkerManager file; + file.Read(); + if (m_id1 > file.sum - 1) + { + MessageBox(TEXT("未找到该职工")); + } + UpdateData(FALSE); + m_id1 = 0; +} + + +void Wage::OnBnClickedButton7() +{ + // TODO: 在此添加控件通知处理程序代码 + UpdateData(TRUE); + 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);//职工薪水 + + if (tmp.id == m_id2) + { + if (tmp.job != "兼职推销员") + { + MessageBox(TEXT("该职工不符合选定职工类型")); + break; + } + else + { + Yuan y; + y.wage = this; + y.DoModal(); + } + break; + } + } + ifs.close();//关闭文件 + WorkerManager file; + file.Read(); + if (m_id2 > file.sum - 1) + { + MessageBox(TEXT("未找到该职工")); + } + UpdateData(FALSE); + m_id2 = 0; +} + + +void Wage::OnBnClickedButton5() +{ + // TODO: 在此添加控件通知处理程序代码 + + UpdateData(TRUE); + + ifstream ifs(FILENAME);//打开文件 + char buf[1024] = { 0 };//初始化数组 + ifs.getline(buf, sizeof(buf));//取出表头 + int i = 0;//推销员数组 + + 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);//职工薪水 + + if (tmp.job == "兼职推销员") + { + int a = tmp.wage / 0.85; + arr[i] = a; + length++; + i++; + } + } + ifs.close();//关闭文件 + + for (int j = 0; j < length; j++) + { + n_wage = n_wage + arr[j] * 0.06; + } + + SellManager s; + s.wage = this; + s.DoModal(); + + UpdateData(FALSE); +} diff --git a/Wage.h b/Wage.h new file mode 100644 index 0000000..d3ff536 --- /dev/null +++ b/Wage.h @@ -0,0 +1,50 @@ +#pragma once +#include "Hour.h" +#include "Yuan.h" +#include "SellManager.h" + +// Wage 窗体视图 + +class Wage : public CFormView +{ + DECLARE_DYNCREATE(Wage) + friend class Hour; + friend class Yuan; + friend class SellManager; + +protected: + Wage(); // 动态创建所使用的受保护的构造函数 + virtual ~Wage(); + +public: +#ifdef AFX_DESIGN_TIME + enum { IDD = IDD_Wage }; +#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() +public: + afx_msg void OnBnClickedButton2(); +private: + int arr[1024] = { 0 };//初始化数组,记录销售额 + int length = 0;//记录数组长度 + int m_id1; + int m_hour; + int m_id2; + int m_yuan; + int n_wage = 0; +public: + afx_msg void OnBnClickedButton3(); + afx_msg void OnBnClickedButton7(); + afx_msg void OnBnClickedButton5(); +}; + + diff --git a/WelcomeDlg.cpp b/WelcomeDlg.cpp new file mode 100644 index 0000000..97b94e7 --- /dev/null +++ b/WelcomeDlg.cpp @@ -0,0 +1,68 @@ +// WelcomeDlg.cpp: 实现文件 +// + +#include "pch.h" +#include "WorkerManager.h" +#include "WelcomeDlg.h" + + +// WelcomeDlg + +IMPLEMENT_DYNCREATE(WelcomeDlg, CFormView) + +WelcomeDlg::WelcomeDlg() + : CFormView(IDD_Welcome) +{ + +} + +WelcomeDlg::~WelcomeDlg() +{ +} + +void WelcomeDlg::DoDataExchange(CDataExchange* pDX) +{ + CFormView::DoDataExchange(pDX); +} + +BEGIN_MESSAGE_MAP(WelcomeDlg, CFormView) +END_MESSAGE_MAP() + + +// WelcomeDlg 诊断 + +#ifdef _DEBUG +void WelcomeDlg::AssertValid() const +{ + CFormView::AssertValid(); +} + +#ifndef _WIN32_WCE +void WelcomeDlg::Dump(CDumpContext& dc) const +{ + CFormView::Dump(dc); +} +#endif +#endif //_DEBUG + + +// WelcomeDlg 消息处理程序 + + +void WelcomeDlg::OnInitialUpdate() +{ + CFormView::OnInitialUpdate(); + + // TODO: 在此添加专用代码和/或调用基类 + ifstream ifs(FILENAME);//打开文件 + if (ifs.eof())//若文件为空加入表头 + { + ofstream ofs(FILENAME); + ofs << "职工编号|职工姓名|职工级别|职工薪水" << endl; + } + + else//防止修改文件编号发生错误 + { + InitData(); + } +} diff --git a/WelcomeDlg.h b/WelcomeDlg.h new file mode 100644 index 0000000..11a0574 --- /dev/null +++ b/WelcomeDlg.h @@ -0,0 +1,34 @@ +#pragma once + + + +// WelcomeDlg 窗体视图 + +class WelcomeDlg : public CFormView +{ + DECLARE_DYNCREATE(WelcomeDlg) + +protected: + WelcomeDlg(); // 动态创建所使用的受保护的构造函数 + virtual ~WelcomeDlg(); + +public: +#ifdef AFX_DESIGN_TIME + enum { IDD = IDD_Welcome }; +#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() +public: + virtual void OnInitialUpdate(); +}; + + diff --git a/Worker.h b/Worker.h deleted file mode 100644 index 20b43ac..0000000 --- a/Worker.h +++ /dev/null @@ -1,16 +0,0 @@ -#pragma once -#include -#include -using namespace std; -//ְ -class Worker -{ -public: - //ʾϢ - virtual void ShowInfo() = 0; - //ȡλ - virtual string GetDeptName() = 0; - int MID;//ְ - string MName;//ְ - int MDeptID;//ű -}; \ No newline at end of file diff --git a/WorkerManager.aps b/WorkerManager.aps new file mode 100644 index 0000000..78f93a0 Binary files /dev/null and b/WorkerManager.aps differ diff --git a/WorkerManager.cpp b/WorkerManager.cpp new file mode 100644 index 0000000..548e051 --- /dev/null +++ b/WorkerManager.cpp @@ -0,0 +1,333 @@ + +// WorkerManager.cpp: 定义应用程序的类行为。 +// + +#include "pch.h" +#include "framework.h" +#include "afxwinappex.h" +#include "afxdialogex.h" +#include "WorkerManager.h" +#include "MainFrm.h" + +#include "WorkerManagerDoc.h" +#include "WorkerManagerView.h" + +#ifdef _DEBUG +#define new DEBUG_NEW +#endif + + +// CWorkerManagerApp + +BEGIN_MESSAGE_MAP(CWorkerManagerApp, CWinApp) + ON_COMMAND(ID_APP_ABOUT, &CWorkerManagerApp::OnAppAbout) + // 基于文件的标准文档命令 + ON_COMMAND(ID_FILE_NEW, &CWinApp::OnFileNew) + ON_COMMAND(ID_FILE_OPEN, &CWinApp::OnFileOpen) + // 标准打印设置命令 + ON_COMMAND(ID_FILE_PRINT_SETUP, &CWinApp::OnFilePrintSetup) +END_MESSAGE_MAP() + + +// CWorkerManagerApp 构造 + +CWorkerManagerApp::CWorkerManagerApp() noexcept +{ + + // 支持重新启动管理器 + m_dwRestartManagerSupportFlags = AFX_RESTART_MANAGER_SUPPORT_ALL_ASPECTS; +#ifdef _MANAGED + // 如果应用程序是利用公共语言运行时支持(/clr)构建的,则: + // 1) 必须有此附加设置,“重新启动管理器”支持才能正常工作。 + // 2) 在您的项目中,您必须按照生成顺序向 System.Windows.Forms 添加引用。 + System::Windows::Forms::Application::SetUnhandledExceptionMode(System::Windows::Forms::UnhandledExceptionMode::ThrowException); +#endif + + // TODO: 将以下应用程序 ID 字符串替换为唯一的 ID 字符串;建议的字符串格式 + //为 CompanyName.ProductName.SubProduct.VersionInformation + SetAppID(_T("WorkerManager.AppID.NoVersion")); + + // TODO: 在此处添加构造代码, + // 将所有重要的初始化放置在 InitInstance 中 +} + +// 唯一的 CWorkerManagerApp 对象 + +CWorkerManagerApp theApp; + + +// CWorkerManagerApp 初始化 + +BOOL CWorkerManagerApp::InitInstance() +{ + // 如果一个运行在 Windows XP 上的应用程序清单指定要 + // 使用 ComCtl32.dll 版本 6 或更高版本来启用可视化方式, + //则需要 InitCommonControlsEx()。 否则,将无法创建窗口。 + INITCOMMONCONTROLSEX InitCtrls; + InitCtrls.dwSize = sizeof(InitCtrls); + // 将它设置为包括所有要在应用程序中使用的 + // 公共控件类。 + InitCtrls.dwICC = ICC_WIN95_CLASSES; + InitCommonControlsEx(&InitCtrls); + + CWinApp::InitInstance(); + + + // 初始化 OLE 库 + if (!AfxOleInit()) + { + AfxMessageBox(IDP_OLE_INIT_FAILED); + return FALSE; + } + + AfxEnableControlContainer(); + + EnableTaskbarInteraction(FALSE); + + // 使用 RichEdit 控件需要 AfxInitRichEdit2() + // AfxInitRichEdit2(); + + // 标准初始化 + // 如果未使用这些功能并希望减小 + // 最终可执行文件的大小,则应移除下列 + // 不需要的特定初始化例程 + // 更改用于存储设置的注册表项 + // TODO: 应适当修改该字符串, + // 例如修改为公司或组织名 + SetRegistryKey(_T("应用程序向导生成的本地应用程序")); + LoadStdProfileSettings(4); // 加载标准 INI 文件选项(包括 MRU) + + + // 注册应用程序的文档模板。 文档模板 + // 将用作文档、框架窗口和视图之间的连接 + CSingleDocTemplate* pDocTemplate; + pDocTemplate = new CSingleDocTemplate( + IDR_MAINFRAME, + RUNTIME_CLASS(CWorkerManagerDoc), + RUNTIME_CLASS(CMainFrame), // 主 SDI 框架窗口 + RUNTIME_CLASS(CWorkerManagerView)); + if (!pDocTemplate) + return FALSE; + AddDocTemplate(pDocTemplate); + + + // 分析标准 shell 命令、DDE、打开文件操作的命令行 + CCommandLineInfo cmdInfo; + ParseCommandLine(cmdInfo); + + + + // 调度在命令行中指定的命令。 如果 + // 用 /RegServer、/Register、/Unregserver 或 /Unregister 启动应用程序,则返回 FALSE。 + if (!ProcessShellCommand(cmdInfo)) + return FALSE; + + // 唯一的一个窗口已初始化,因此显示它并对其进行更新 + m_pMainWnd->ShowWindow(SW_SHOW); + m_pMainWnd->UpdateWindow(); + return TRUE; +} + +int CWorkerManagerApp::ExitInstance() +{ + //TODO: 处理可能已添加的附加资源 + AfxOleTerm(FALSE); + + return CWinApp::ExitInstance(); +} + +// CWorkerManagerApp 消息处理程序 + + +// 用于应用程序“关于”菜单项的 CAboutDlg 对话框 + +class CAboutDlg : public CDialogEx +{ +public: + CAboutDlg() noexcept; + +// 对话框数据 +#ifdef AFX_DESIGN_TIME + enum { IDD = IDD_ABOUTBOX }; +#endif + +protected: + virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持 + +// 实现 +protected: + DECLARE_MESSAGE_MAP() +}; + +CAboutDlg::CAboutDlg() noexcept : CDialogEx(IDD_ABOUTBOX) +{ +} + +void CAboutDlg::DoDataExchange(CDataExchange* pDX) +{ + CDialogEx::DoDataExchange(pDX); +} + +BEGIN_MESSAGE_MAP(CAboutDlg, CDialogEx) +END_MESSAGE_MAP() + +// 用于运行对话框的应用程序命令 +void CWorkerManagerApp::OnAppAbout() +{ + CAboutDlg aboutDlg; + aboutDlg.DoModal(); +} + +// CWorkerManagerApp 消息处理程序 + +WorkerManager::WorkerManager() +{ + +} + +WorkerManager::~WorkerManager() +{ + +} + +void WorkerManager::Read() +{ + ifstream ifs(FILENAME);//打开文件 + char buf[1024] = { 0 };//初始化数组 + sum = 0;//初始化职工数量 + ls.clear(); + ifs.getline(buf, sizeof(buf));//取出表头 + + + while (!ifs.eof())//未读取完毕 + { + msg tmp; + + ifs.getline(buf, sizeof(buf));//读取一行 + sum++;//员工总数+1 + + 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);//职工薪水 + + ls.push_back(tmp);//放在列表后面 + } + ifs.close();//关闭文件 +} + +void WorkerManager::Write() +{ + ofstream ofs(FILENAME);//打开文件 + + if (ls.size() > 0)//有内容 + { + ofs << "职工编号|职工姓名|职工级别|职工薪水" << endl;//表头 + + //写入文件 + for (list::iterator it = ls.begin(); it != ls.end(); it++) + { + ofs << it->id << "|"; + ofs << it->name << "|"; + ofs << it->job << "|"; + ofs << it->wage << endl; + } + } + + ofs.close();//关闭文件 +} + + + +void WorkerManager::Add(CString name, CString job, int wage) +{ + msg tmp; + + if (!name.IsEmpty() && !job.IsEmpty() && wage > 0) + { + tmp.id = ls.size() + 1;//编号+1 + CStringA str1; + str1 = name; + tmp.name = str1.GetBuffer(); + CStringA str2; + str2 = job; + tmp.job = str2.GetBuffer(); + tmp.wage = wage; + + ls.push_back(tmp);//放在后面 + } +} + +void InitData() +{ + ifstream ifs(FILENAME); + list ls;//数据容器 + char buf[1024] = { 0 };//初始化数组 + ls.clear(); + ifs.getline(buf, sizeof(buf));//取出表头 + int index = 0;//记录编号 + + 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);//职工薪水 + + ++index; + tmp.id = index; + ls.push_back(tmp);//放在列表后面 + } + ifs.close();//关闭文件 + + ofstream ofs(FILENAME);//打开文件 + + if (ls.size() > 0)//有内容 + { + ofs << "职工编号|职工姓名|职工级别|职工薪水" << endl;//表头 + + //写入文件 + for (list::iterator it = ls.begin(); it != ls.end(); it++) + { + ofs << it->id << "|"; + ofs << it->name << "|"; + ofs << it->job << "|"; + ofs << it->wage << endl; + } + } + + ofs.close();//关闭文件 +} + diff --git a/WorkerManager.h b/WorkerManager.h index 0373bdf..c42aeea 100644 --- a/WorkerManager.h +++ b/WorkerManager.h @@ -1,31 +1,65 @@ + +// WorkerManager.h: WorkerManager 应用程序的主头文件 +// #pragma once + +#ifndef __AFXWIN_H__ + #error "在包含此文件之前包含 'pch.h' 以生成 PCH" +#endif + +#include "resource.h" // 主符号 + #include -#include "Worker.h" -#include "Boss.h" -#include "Employee.h" -#include "Manager.h" #include -#define FILENAME "emp_file.txt" +#include +#include +#define FILENAME "file.txt" using namespace std; + + +// CWorkerManagerApp: +// 有关此类的实现,请参阅 WorkerManager.cpp +// + +class CWorkerManagerApp : public CWinApp +{ +public: + CWorkerManagerApp() noexcept; + + +// 重写 +public: + virtual BOOL InitInstance(); + virtual int ExitInstance(); + +// 实现 + afx_msg void OnAppAbout(); + DECLARE_MESSAGE_MAP() +}; + +extern CWorkerManagerApp theApp; + +struct msg +{ + int id;//职工编号 + string name;//姓名 + string job;//级别 + int wage;//薪水 + int sum;//职工总数 +}; + class WorkerManager { public: - WorkerManager(); - void ShowMenu(); - void ExitSystem(); - void AddEmploy(); - int MEmpNum;//ͳеְ - Worker** MEmpArr;//Աָ - void save();//ļ - bool FileEmpty;//жļǷΪ - int GetEmpSum();//ְļеְ - void InitEmp();//ʼְ - void ShowEmp();//ʾְ - void DelEmp();//ɾְ - int ExistOrNot(int id);//жְǷ - void ChaEmp();//޸ְ - void FindEmp();//ְ - void SortEmp();//ְ - void CleamFile();//ְ - ~WorkerManager(); -}; \ No newline at end of file + WorkerManager();//构造 + ~WorkerManager();//析构 + + void Read();//读取职工数据 + void Write();//导出职工数据 + void Add(CString name, CString job, int wage);//添加职工 + + list ls;//数据容器 + int sum;//记录员工数量 +}; + +void InitData(); diff --git a/WorkerManager.rc b/WorkerManager.rc new file mode 100644 index 0000000..9545658 Binary files /dev/null and b/WorkerManager.rc differ diff --git a/WorkerManager.vcxproj b/WorkerManager.vcxproj new file mode 100644 index 0000000..e3a62e5 --- /dev/null +++ b/WorkerManager.vcxproj @@ -0,0 +1,261 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 17.0 + {A42F27C6-83E6-4166-976E-9FA2071C4149} + MFCProj + WorkerManager + 10.0 + + + + + Application + true + v143 + Unicode + Dynamic + + + Application + false + v143 + true + Unicode + Dynamic + + + Application + true + v143 + Unicode + Dynamic + + + Application + false + v143 + true + Unicode + Dynamic + + + + + + + + + + + + + + + + + + + + + true + + + true + + + false + + + false + + + + Use + Level3 + true + _WINDOWS;_DEBUG;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + pch.h + + + Windows + + + false + true + _DEBUG;%(PreprocessorDefinitions) + + + 0x0804 + _DEBUG;%(PreprocessorDefinitions) + $(IntDir);%(AdditionalIncludeDirectories) + + + + + Use + Level3 + true + WIN32;_WINDOWS;_DEBUG;%(PreprocessorDefinitions) + pch.h + + + Windows + + + false + true + _DEBUG;%(PreprocessorDefinitions) + + + 0x0804 + _DEBUG;%(PreprocessorDefinitions) + $(IntDir);%(AdditionalIncludeDirectories) + + + + + Use + Level3 + true + true + true + WIN32;_WINDOWS;NDEBUG;%(PreprocessorDefinitions) + pch.h + + + Windows + true + true + + + false + true + NDEBUG;%(PreprocessorDefinitions) + + + 0x0804 + NDEBUG;%(PreprocessorDefinitions) + $(IntDir);%(AdditionalIncludeDirectories) + + + + + Use + Level3 + true + true + true + _WINDOWS;NDEBUG;%(PreprocessorDefinitions) + pch.h + + + Windows + true + true + + + false + true + NDEBUG;%(PreprocessorDefinitions) + + + 0x0804 + NDEBUG;%(PreprocessorDefinitions) + $(IntDir);%(AdditionalIncludeDirectories) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Create + Create + Create + Create + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/WorkerManager.vcxproj.filters b/WorkerManager.vcxproj.filters new file mode 100644 index 0000000..4593a22 --- /dev/null +++ b/WorkerManager.vcxproj.filters @@ -0,0 +1,196 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + 头文件 + + + 头文件 + + + 头文件 + + + 头文件 + + + 头文件 + + + 头文件 + + + 头文件 + + + 头文件 + + + 头文件 + + + 头文件 + + + 头文件 + + + 头文件 + + + 头文件 + + + 头文件 + + + 头文件 + + + 头文件 + + + 头文件 + + + 头文件 + + + 头文件 + + + 头文件 + + + 头文件 + + + 头文件 + + + 头文件 + + + 头文件 + + + 头文件 + + + 头文件 + + + + + 源文件 + + + 源文件 + + + 源文件 + + + 源文件 + + + 源文件 + + + 源文件 + + + 源文件 + + + 源文件 + + + 源文件 + + + 源文件 + + + 源文件 + + + 源文件 + + + 源文件 + + + 源文件 + + + 源文件 + + + 源文件 + + + 源文件 + + + 源文件 + + + 源文件 + + + 源文件 + + + 源文件 + + + 源文件 + + + 源文件 + + + + + 资源文件 + + + + + 资源文件 + + + + + + 资源文件 + + + 资源文件 + + + 资源文件 + + + 资源文件 + + + 资源文件 + + + \ No newline at end of file diff --git a/WorkerManager.vcxproj.user b/WorkerManager.vcxproj.user new file mode 100644 index 0000000..cd53297 --- /dev/null +++ b/WorkerManager.vcxproj.user @@ -0,0 +1,6 @@ + + + + WorkerManager.rc + + \ No newline at end of file diff --git a/WorkerManagerDoc.cpp b/WorkerManagerDoc.cpp new file mode 100644 index 0000000..4c218eb --- /dev/null +++ b/WorkerManagerDoc.cpp @@ -0,0 +1,141 @@ + +// WorkerManagerDoc.cpp: CWorkerManagerDoc 类的实现 +// + +#include "pch.h" +#include "framework.h" +// SHARED_HANDLERS 可以在实现预览、缩略图和搜索筛选器句柄的 +// ATL 项目中进行定义,并允许与该项目共享文档代码。 +#ifndef SHARED_HANDLERS +#include "WorkerManager.h" +#endif + +#include "WorkerManagerDoc.h" + +#include + +#ifdef _DEBUG +#define new DEBUG_NEW +#endif + +// CWorkerManagerDoc + +IMPLEMENT_DYNCREATE(CWorkerManagerDoc, CDocument) + +BEGIN_MESSAGE_MAP(CWorkerManagerDoc, CDocument) +END_MESSAGE_MAP() + + +// CWorkerManagerDoc 构造/析构 + +CWorkerManagerDoc::CWorkerManagerDoc() noexcept +{ + // TODO: 在此添加一次性构造代码 + +} + +CWorkerManagerDoc::~CWorkerManagerDoc() +{ +} + +BOOL CWorkerManagerDoc::OnNewDocument() +{ + if (!CDocument::OnNewDocument()) + return FALSE; + + // TODO: 在此添加重新初始化代码 + // (SDI 文档将重用该文档) + + //设置窗口标题 + SetTitle(TEXT("公司人事管理系统")); + + return TRUE; +} + + + + +// CWorkerManagerDoc 序列化 + +void CWorkerManagerDoc::Serialize(CArchive& ar) +{ + if (ar.IsStoring()) + { + // TODO: 在此添加存储代码 + } + else + { + // TODO: 在此添加加载代码 + } +} + +#ifdef SHARED_HANDLERS + +// 缩略图的支持 +void CWorkerManagerDoc::OnDrawThumbnail(CDC& dc, LPRECT lprcBounds) +{ + // 修改此代码以绘制文档数据 + dc.FillSolidRect(lprcBounds, RGB(255, 255, 255)); + + CString strText = _T("TODO: implement thumbnail drawing here"); + LOGFONT lf; + + CFont* pDefaultGUIFont = CFont::FromHandle((HFONT) GetStockObject(DEFAULT_GUI_FONT)); + pDefaultGUIFont->GetLogFont(&lf); + lf.lfHeight = 36; + + CFont fontDraw; + fontDraw.CreateFontIndirect(&lf); + + CFont* pOldFont = dc.SelectObject(&fontDraw); + dc.DrawText(strText, lprcBounds, DT_CENTER | DT_WORDBREAK); + dc.SelectObject(pOldFont); +} + +// 搜索处理程序的支持 +void CWorkerManagerDoc::InitializeSearchContent() +{ + CString strSearchContent; + // 从文档数据设置搜索内容。 + // 内容部分应由“;”分隔 + + // 例如: strSearchContent = _T("point;rectangle;circle;ole object;"); + SetSearchContent(strSearchContent); +} + +void CWorkerManagerDoc::SetSearchContent(const CString& value) +{ + if (value.IsEmpty()) + { + RemoveChunk(PKEY_Search_Contents.fmtid, PKEY_Search_Contents.pid); + } + else + { + CMFCFilterChunkValueImpl *pChunk = nullptr; + ATLTRY(pChunk = new CMFCFilterChunkValueImpl); + if (pChunk != nullptr) + { + pChunk->SetTextValue(PKEY_Search_Contents, value, CHUNK_TEXT); + SetChunkValue(pChunk); + } + } +} + +#endif // SHARED_HANDLERS + +// CWorkerManagerDoc 诊断 + +#ifdef _DEBUG +void CWorkerManagerDoc::AssertValid() const +{ + CDocument::AssertValid(); +} + +void CWorkerManagerDoc::Dump(CDumpContext& dc) const +{ + CDocument::Dump(dc); +} +#endif //_DEBUG + + +// CWorkerManagerDoc 命令 diff --git a/WorkerManagerDoc.h b/WorkerManagerDoc.h new file mode 100644 index 0000000..6518fb4 --- /dev/null +++ b/WorkerManagerDoc.h @@ -0,0 +1,48 @@ + +// WorkerManagerDoc.h: CWorkerManagerDoc 类的接口 +// + + +#pragma once + + +class CWorkerManagerDoc : public CDocument +{ +protected: // 仅从序列化创建 + CWorkerManagerDoc() noexcept; + DECLARE_DYNCREATE(CWorkerManagerDoc) + +// 特性 +public: + +// 操作 +public: + +// 重写 +public: + virtual BOOL OnNewDocument(); + virtual void Serialize(CArchive& ar); +#ifdef SHARED_HANDLERS + virtual void InitializeSearchContent(); + virtual void OnDrawThumbnail(CDC& dc, LPRECT lprcBounds); +#endif // SHARED_HANDLERS + +// 实现 +public: + virtual ~CWorkerManagerDoc(); +#ifdef _DEBUG + virtual void AssertValid() const; + virtual void Dump(CDumpContext& dc) const; +#endif + +protected: + +// 生成的消息映射函数 +protected: + DECLARE_MESSAGE_MAP() + +#ifdef SHARED_HANDLERS + // 用于为搜索处理程序设置搜索内容的 Helper 函数 + void SetSearchContent(const CString& value); +#endif // SHARED_HANDLERS +}; diff --git a/WorkerManagerText.sln b/WorkerManagerText.sln deleted file mode 100644 index acc0022..0000000 --- a/WorkerManagerText.sln +++ /dev/null @@ -1,31 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 17 -VisualStudioVersion = 17.0.31919.166 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "WorkerManagerText", "WorkerManagerText.vcxproj", "{2A35B649-AFFC-4F5A-99DA-1463D50E7D74}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|x64 = Debug|x64 - Debug|x86 = Debug|x86 - Release|x64 = Release|x64 - Release|x86 = Release|x86 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {2A35B649-AFFC-4F5A-99DA-1463D50E7D74}.Debug|x64.ActiveCfg = Debug|x64 - {2A35B649-AFFC-4F5A-99DA-1463D50E7D74}.Debug|x64.Build.0 = Debug|x64 - {2A35B649-AFFC-4F5A-99DA-1463D50E7D74}.Debug|x86.ActiveCfg = Debug|Win32 - {2A35B649-AFFC-4F5A-99DA-1463D50E7D74}.Debug|x86.Build.0 = Debug|Win32 - {2A35B649-AFFC-4F5A-99DA-1463D50E7D74}.Release|x64.ActiveCfg = Release|x64 - {2A35B649-AFFC-4F5A-99DA-1463D50E7D74}.Release|x64.Build.0 = Release|x64 - {2A35B649-AFFC-4F5A-99DA-1463D50E7D74}.Release|x86.ActiveCfg = Release|Win32 - {2A35B649-AFFC-4F5A-99DA-1463D50E7D74}.Release|x86.Build.0 = Release|Win32 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {56BB9E8A-D975-441E-8CD8-BE21726DFA5C} - EndGlobalSection -EndGlobal diff --git a/WorkerManagerText.vcxproj b/WorkerManagerText.vcxproj deleted file mode 100644 index 6f15fa3..0000000 --- a/WorkerManagerText.vcxproj +++ /dev/null @@ -1,171 +0,0 @@ - - - - - Debug - Win32 - - - Release - Win32 - - - Debug - x64 - - - Release - x64 - - - - 16.0 - Win32Proj - {2a35b649-affc-4f5a-99da-1463d50e7d74} - WorkerManagerText - 10.0 - - - - Application - true - v143 - Unicode - - - Application - false - v143 - true - Unicode - - - Application - true - v143 - Unicode - - - Application - false - v143 - true - Unicode - - - - - - - - - - - - - - - - - - - - - true - - - false - - - true - - - false - - - - Level3 - true - WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - - - - - Level3 - true - true - true - WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - true - true - - - - - Level3 - true - _DEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - - - - - Level3 - true - true - true - NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - true - true - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/WorkerManagerText.vcxproj.filters b/WorkerManagerText.vcxproj.filters deleted file mode 100644 index 9898afc..0000000 --- a/WorkerManagerText.vcxproj.filters +++ /dev/null @@ -1,102 +0,0 @@ - - - - - {4FC737F1-C7A5-4376-A066-2A32D752A2FF} - cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx - - - {93995380-89BD-4b04-88EB-625FBE52EBFB} - h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd - - - {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} - rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms - - - {b4af2dca-06e8-49ff-a538-2aaae1a94ce9} - - - {111e54e4-3fc4-4f19-972a-c2860e96d4b4} - - - {2e715784-749f-4998-a587-cc410586e6b3} - - - {77ffb609-fb3c-44f8-b88f-4191507205ac} - - - - - 头文件 - - - 头文件\subclass - - - 头文件\subclass - - - 头文件\subclass - - - 头文件\superclass - - - - - 源文件 - - - 源文件\defined_function - - - 源文件\defined_function - - - 源文件\defined_function - - - 源文件\defined_function - - - 源文件\defined_function - - - 源文件\defined_function - - - 源文件\class_function_definition - - - 源文件\class_function_definition - - - 源文件\class_function_definition - - - 源文件\defined_function - - - 源文件\defined_function - - - 源文件\defined_function - - - 源文件\defined_function - - - 源文件\defined_function - - - 源文件\defined_function - - - 源文件\defined_function - - - 源文件\defined_function - - - \ No newline at end of file diff --git a/WorkerManagerView.cpp b/WorkerManagerView.cpp new file mode 100644 index 0000000..44a7063 --- /dev/null +++ b/WorkerManagerView.cpp @@ -0,0 +1,105 @@ + +// WorkerManagerView.cpp: CWorkerManagerView 类的实现 +// + +#include "pch.h" +#include "framework.h" +// SHARED_HANDLERS 可以在实现预览、缩略图和搜索筛选器句柄的 +// ATL 项目中进行定义,并允许与该项目共享文档代码。 +#ifndef SHARED_HANDLERS +#include "WorkerManager.h" +#endif + +#include "WorkerManagerDoc.h" +#include "WorkerManagerView.h" + +#ifdef _DEBUG +#define new DEBUG_NEW +#endif + + +// CWorkerManagerView + +IMPLEMENT_DYNCREATE(CWorkerManagerView, CView) + +BEGIN_MESSAGE_MAP(CWorkerManagerView, CView) + // 标准打印命令 + ON_COMMAND(ID_FILE_PRINT, &CView::OnFilePrint) + ON_COMMAND(ID_FILE_PRINT_DIRECT, &CView::OnFilePrint) + ON_COMMAND(ID_FILE_PRINT_PREVIEW, &CView::OnFilePrintPreview) +END_MESSAGE_MAP() + +// CWorkerManagerView 构造/析构 + +CWorkerManagerView::CWorkerManagerView() noexcept +{ + // TODO: 在此处添加构造代码 + +} + +CWorkerManagerView::~CWorkerManagerView() +{ +} + +BOOL CWorkerManagerView::PreCreateWindow(CREATESTRUCT& cs) +{ + // TODO: 在此处通过修改 + // CREATESTRUCT cs 来修改窗口类或样式 + + return CView::PreCreateWindow(cs); +} + +// CWorkerManagerView 绘图 + +void CWorkerManagerView::OnDraw(CDC* /*pDC*/) +{ + CWorkerManagerDoc* pDoc = GetDocument(); + ASSERT_VALID(pDoc); + if (!pDoc) + return; + + // TODO: 在此处为本机数据添加绘制代码 +} + + +// CWorkerManagerView 打印 + +BOOL CWorkerManagerView::OnPreparePrinting(CPrintInfo* pInfo) +{ + // 默认准备 + return DoPreparePrinting(pInfo); +} + +void CWorkerManagerView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) +{ + // TODO: 添加额外的打印前进行的初始化过程 +} + +void CWorkerManagerView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) +{ + // TODO: 添加打印后进行的清理过程 +} + + +// CWorkerManagerView 诊断 + +#ifdef _DEBUG +void CWorkerManagerView::AssertValid() const +{ + CView::AssertValid(); +} + +void CWorkerManagerView::Dump(CDumpContext& dc) const +{ + CView::Dump(dc); +} + +CWorkerManagerDoc* CWorkerManagerView::GetDocument() const // 非调试版本是内联的 +{ + ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CWorkerManagerDoc))); + return (CWorkerManagerDoc*)m_pDocument; +} +#endif //_DEBUG + + +// CWorkerManagerView 消息处理程序 diff --git a/WorkerManagerView.h b/WorkerManagerView.h new file mode 100644 index 0000000..8252e80 --- /dev/null +++ b/WorkerManagerView.h @@ -0,0 +1,49 @@ + +// WorkerManagerView.h: CWorkerManagerView 类的接口 +// + +#pragma once + + +class CWorkerManagerView : public CView +{ +protected: // 仅从序列化创建 + CWorkerManagerView() noexcept; + DECLARE_DYNCREATE(CWorkerManagerView) + +// 特性 +public: + CWorkerManagerDoc* GetDocument() const; + +// 操作 +public: + +// 重写 +public: + virtual void OnDraw(CDC* pDC); // 重写以绘制该视图 + virtual BOOL PreCreateWindow(CREATESTRUCT& cs); +protected: + virtual BOOL OnPreparePrinting(CPrintInfo* pInfo); + virtual void OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo); + virtual void OnEndPrinting(CDC* pDC, CPrintInfo* pInfo); + +// 实现 +public: + virtual ~CWorkerManagerView(); +#ifdef _DEBUG + virtual void AssertValid() const; + virtual void Dump(CDumpContext& dc) const; +#endif + +protected: + +// 生成的消息映射函数 +protected: + DECLARE_MESSAGE_MAP() +}; + +#ifndef _DEBUG // WorkerManagerView.cpp 中的调试版本 +inline CWorkerManagerDoc* CWorkerManagerView::GetDocument() const + { return reinterpret_cast(m_pDocument); } +#endif + diff --git a/Yuan.cpp b/Yuan.cpp new file mode 100644 index 0000000..5453be5 --- /dev/null +++ b/Yuan.cpp @@ -0,0 +1,179 @@ +// Yuan.cpp: 实现文件 +// + +#include "pch.h" +#include "WorkerManager.h" +#include "afxdialogex.h" +#include "Yuan.h" + + +// Yuan 对话框 + +IMPLEMENT_DYNAMIC(Yuan, CDialogEx) + +Yuan::Yuan(CWnd* pParent /*=nullptr*/) + : CDialogEx(IDD_Yuan, pParent) +{ + +} + +Yuan::~Yuan() +{ +} + +void Yuan::DoDataExchange(CDataExchange* pDX) +{ + CDialogEx::DoDataExchange(pDX); + DDX_Control(pDX, IDC_LIST1, m_list1); + DDX_Control(pDX, IDC_LIST3, m_list2); +} + + +BEGIN_MESSAGE_MAP(Yuan, CDialogEx) + ON_BN_CLICKED(IDOK, &Yuan::OnBnClickedOk) +END_MESSAGE_MAP() + + +// Yuan 消息处理程序 + + +void Yuan::OnBnClickedOk() +{ + // TODO: 在此添加控件通知处理程序代码 + + UpdateData(TRUE); + ifstream ifs(FILENAME);//打开文件 + list ls;//数据容器 + char buf[1024] = { 0 };//初始化数组 + ls.clear(); + 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);//职工薪水 + + if (tmp.id == wage->m_id2) + { + tmp.wage = 0.85 * wage->m_yuan; + } + ls.push_back(tmp);//放在列表后面 + } + ifs.close();//关闭文件 + + ofstream ofs(FILENAME);//打开文件 + + if (ls.size() > 0)//有内容 + { + ofs << "职工编号|职工姓名|职工级别|职工薪水" << endl;//表头 + + //写入文件 + for (list::iterator it = ls.begin(); it != ls.end(); it++) + { + ofs << it->id << "|"; + ofs << it->name << "|"; + ofs << it->job << "|"; + ofs << it->wage << endl; + } + } + + ofs.close();//关闭文件 + MessageBox(TEXT("更新成功")); + + CDialogEx::OnOK(); +} + + +BOOL Yuan::OnInitDialog() +{ + CDialogEx::OnInitDialog(); + + // TODO: 在此添加额外的初始化 + + // 设置扩展风格 + //LVS_EX_FULLROWSELECT选中整行,LVS_EX_GRIDLINES网格 + m_list1.SetExtendedStyle(m_list1.GetExtendedStyle() | LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES); + m_list2.SetExtendedStyle(m_list2.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_list1.InsertColumn(i, field[i], LVCFMT_CENTER, 105); + m_list2.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);//职工薪水 + + int n_wage = 0.85 * wage->m_yuan; + + if (tmp.id == wage->m_id2) + { + CString str1, str2, str3, str4, str5; + str1.Format(_T("%d"), tmp.id); + m_list1.InsertItem(0, str1); + int column = 1; + m_list1.SetItemText(0, column++, (CString)tmp.name.c_str()); + m_list1.SetItemText(0, column++, (CString)tmp.job.c_str()); + str4.Format(_T("%d"), tmp.wage); + m_list1.SetItemText(0, column++, str4); + m_list2.InsertItem(0, str1); + column = 1; + m_list2.SetItemText(0, column++, (CString)tmp.name.c_str()); + m_list2.SetItemText(0, column++, (CString)tmp.job.c_str()); + str5.Format(_T("%d"), n_wage); + m_list2.SetItemText(0, column++, str5); + break; + } + } + ifs.close();//关闭文件 + + return TRUE; // return TRUE unless you set the focus to a control + // 异常: OCX 属性页应返回 FALSE +} diff --git a/Yuan.h b/Yuan.h new file mode 100644 index 0000000..9ac5cbd --- /dev/null +++ b/Yuan.h @@ -0,0 +1,34 @@ +#pragma once +#include "afxdialogex.h" +#include "Wage.h" + +// Yuan 对话框 + +class Yuan : public CDialogEx +{ + DECLARE_DYNAMIC(Yuan) + friend class Wage; + +public: + Yuan(CWnd* pParent = nullptr); // 标准构造函数 + virtual ~Yuan(); + +// 对话框数据 +#ifdef AFX_DESIGN_TIME + enum { IDD = IDD_Yuan }; +#endif + +protected: + virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持 + + DECLARE_MESSAGE_MAP() +private: + CListCtrl m_list1; + CListCtrl m_list2; +public: + afx_msg void OnBnClickedOk(); +private: + Wage* wage; +public: + virtual BOOL OnInitDialog(); +}; diff --git a/add_employee.cpp b/add_employee.cpp deleted file mode 100644 index 15e3842..0000000 --- a/add_employee.cpp +++ /dev/null @@ -1,66 +0,0 @@ -#include "WorkerManager.h" -#include "Employee.h" -void WorkerManager::AddEmploy() -{ - cout << "ְ" << endl; - int add_num = 0; - cin >> add_num; - if (add_num > 0) - { - //¿ռС - int new_size = this->MEmpNum + add_num; - //¿ռ - Worker** new_space = new Worker * [new_size]; - //žݵ¿ռ - if (this->MEmpArr != NULL) - { - for (int i = 0; i < this->MEmpNum; i++) - { - new_space[i] = this->MEmpArr[i]; - } - } - // - for (int i = 0; i < add_num; i++) - { - int id; - string name; - int selection; - cout << "" << i + 1 << "ְıţ"; cin >> id; - cout << "" << i + 1 << "ְ"; cin >> name; - cout << "ѡְĸλ" << endl << "1.ְͨ" << endl << "2." << endl << "3.ϰ" << endl; - cin >> selection; - Worker* worker = NULL; - switch (selection) - { - case 1: - worker = new Employee(id, name, selection); - break; - case 2: - worker = new Employee(id, name, selection); - break; - case 3: - worker = new Employee(id, name, selection); - break; - default: - break; - } - new_space[this->MEmpNum + i] = worker; - } - //ͷԭпռ - delete[] this->MEmpArr; - //¿ռָ - this->MEmpArr = new_space; - //ְ - this->MEmpNum = new_size; - //ļΪձ־ - this->FileEmpty = false; - cout << "ɹ" << add_num << "ְ" << endl; - this->save(); - } - else - { - cout << "" << endl; - } - system("pause"); - system("cls"); -} \ No newline at end of file diff --git a/boss.cpp b/boss.cpp deleted file mode 100644 index 7148f4b..0000000 --- a/boss.cpp +++ /dev/null @@ -1,15 +0,0 @@ -#include "Boss.h" -Boss::Boss(int id, string name, int dID) -{ - this->MID = id; - this->MName = name; - this->MDeptID = dID; -} -void Boss::ShowInfo() -{ - cout << "ְţ" << this->MID << "\tְ" << this->MName << "\tλ" << this->GetDeptName() << endl; -} -string Boss::GetDeptName() -{ - return string("ϰ"); -} \ No newline at end of file diff --git a/change_employee.cpp b/change_employee.cpp deleted file mode 100644 index 22623da..0000000 --- a/change_employee.cpp +++ /dev/null @@ -1,52 +0,0 @@ -#include "WorkerManager.h" -void WorkerManager::ChaEmp() -{ - if (this->FileEmpty) - { - cout << "ְļڻļΪ" << endl; - } - else - { - cout << "Ҫ޸ְıţ"; - int id; - cin >> id; - int ret = this->ExistOrNot(id); - if (ret != -1)//ְ - { - cout << "ѯ" << id << "ְ" << endl; - this->MEmpArr[ret]->ShowInfo(); - delete this->MEmpArr[ret]; - int new_id; - string new_name; - int new_dID; - cout << "ְţ"; cin >> new_id; - cout << ""; cin >> new_name; - cout << "λ\n1.ְͨ\n2.\n3.ϰ" << endl; cin >> new_dID; - Worker* worker = NULL; - switch (new_dID) - { - case 1: - worker = new Employee(new_id, new_name, new_dID); - break; - case 2: - worker = new Manager(new_id, new_name, new_dID); - break; - case 3: - worker = new Boss(new_id, new_name, new_dID); - break; - default: - break; - } - this->MEmpArr[ret] = worker;// - cout << "޸ijɹ" << endl; - this->MEmpArr[ret]->ShowInfo(); - this->save(); - } - else - { - cout << "δҵְ" << endl; - } - } - system("pasue"); - system("cls"); -} \ No newline at end of file diff --git a/clean_file.cpp b/clean_file.cpp deleted file mode 100644 index 0c37e85..0000000 --- a/clean_file.cpp +++ /dev/null @@ -1,27 +0,0 @@ -#include "WorkerManager.h" -void WorkerManager::CleamFile() -{ - cout << "Ƿȷգ\n1.\n2." << endl; - int sel; - cin >> sel; - if (sel == 1) - { - ofstream ofs(FILENAME, ios::trunc); - ofs.close(); - if (this->MEmpArr != NULL) - { - for (int i = 0; i < this->MEmpNum; i++) - { - if (this->MEmpArr[i] != NULL) - { - delete this->MEmpArr[i]; - } - } - this->MEmpNum = 0; - delete[] this->MEmpArr; - this->FileEmpty = true; - } - } - system("pause"); - system("cls"); -} \ No newline at end of file diff --git a/delete_employee.cpp b/delete_employee.cpp deleted file mode 100644 index ab585d4..0000000 --- a/delete_employee.cpp +++ /dev/null @@ -1,48 +0,0 @@ -#include "WorkerManager.h" -void WorkerManager::DelEmp() -{ - if (this->FileEmpty) - { - cout << "ְļڻļΪ" << endl; - } - else - { - cout << "Ҫɾְıţ"; - int id; - cin >> id; - int index = this->ExistOrNot(id); - if (index != -1)//ְڣɾְ - { - int ret = this->ExistOrNot(id); - cout << "ҵ" << endl; - this->MEmpArr[ret]->ShowInfo(); - cout << "Ƿȷϣ\n1.\n2." << endl; - int sel; - cin >> sel; - if (sel == 1) - { - for (int i = index; i < this->MEmpNum - 1; i++) - { - this->MEmpArr[i] = this->MEmpArr[i + 1];//ǰ - } - this->MEmpNum--;// - this->save(); - cout << "ɾɹ" << endl; - } - else if (sel == 2) - { - cout << "ȡ" << endl; - } - else - { - cout << "ѡ" << endl; - } - } - else - { - cout << "δҵְ" << endl; - } - } - system("pause"); - system("cls"); -} \ No newline at end of file diff --git a/emp_file.txt b/emp_file.txt deleted file mode 100644 index e69de29..0000000 diff --git a/employee.cpp b/employee.cpp deleted file mode 100644 index 32970be..0000000 --- a/employee.cpp +++ /dev/null @@ -1,15 +0,0 @@ -#include "Employee.h" -Employee::Employee(int id, string name, int dID) -{ - this->MID = id; - this->MName = name; - this->MDeptID = dID; -} -void Employee::ShowInfo() -{ - cout << "ְţ" << this->MID << "\tְ" << this->MName << "\tλ" << this->GetDeptName() << endl; -} -string Employee::GetDeptName() -{ - return string("Ա"); -} \ No newline at end of file diff --git a/exist_or_not.cpp b/exist_or_not.cpp deleted file mode 100644 index 5d6d8e4..0000000 --- a/exist_or_not.cpp +++ /dev/null @@ -1,14 +0,0 @@ -#include "WorkerManager.h" -int WorkerManager::ExistOrNot(int id) -{ - int index = -1; - for (int i = 0; i < this->MEmpNum; i++) - { - if (this->MEmpArr[i]->MID == id) - { - index = i; - break; - } - } - return index; -} \ No newline at end of file diff --git a/exit_system.cpp b/exit_system.cpp deleted file mode 100644 index bd28e85..0000000 --- a/exit_system.cpp +++ /dev/null @@ -1,7 +0,0 @@ -#include "WorkerManager.h" -void WorkerManager::ExitSystem() -{ - cout << "ӭ´ʹã" << endl; - system("pause"); - exit(0); -} \ No newline at end of file diff --git a/file.txt b/file.txt new file mode 100644 index 0000000..e78c484 --- /dev/null +++ b/file.txt @@ -0,0 +1,7 @@ +ְ|ְ|ְ|ְнˮ +1|||20000 +2||۾|18487 +3||ְԱ|3400 +4||ְԱ|5400 +5||ְԱ|3500 +6||۾|15487 diff --git a/find_employee.cpp b/find_employee.cpp deleted file mode 100644 index 54c2661..0000000 --- a/find_employee.cpp +++ /dev/null @@ -1,53 +0,0 @@ -#include "WorkerManager.h" -void WorkerManager::FindEmp() -{ - if (this->FileEmpty) - { - cout << "ְļڻļΪ" << endl; - } - else - { - cout << "ҷʽ\n1.Ų\n2." << endl; - int sel; - cin >> sel; - if (sel == 1) - { - int id; - cout << "ְţ"; cin >> id; - int ret = this->ExistOrNot(id); - if (ret != -1) - { - cout << "ҵ" << endl; - this->MEmpArr[ret]->ShowInfo(); - } - else - { - cout << "δҵְ" << endl; - } - } - else if (sel == 2) - { - string name; - cout << "ְ"; cin >> name; - bool flag = false; - for (int i = 0; i < this->MEmpNum; i++) - { - if (this->MEmpArr[i]->MName == name) - { - flag = true; - this->MEmpArr[i]->ShowInfo(); - } - } - if (flag == false) - { - cout << "δҵְ" << endl; - } - } - else - { - cout << "ѡ" << endl; - } - } - system("pause"); - system("cls"); -} \ No newline at end of file diff --git a/framework.h b/framework.h new file mode 100644 index 0000000..5672fb5 --- /dev/null +++ b/framework.h @@ -0,0 +1,49 @@ +#pragma once + +#ifndef VC_EXTRALEAN +#define VC_EXTRALEAN // 从 Windows 头中排除极少使用的资料 +#endif + +#include "targetver.h" + +#define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS // 某些 CString 构造函数将是显式的 + +// 关闭 MFC 的一些常见且经常可放心忽略的隐藏警告消息 +#define _AFX_ALL_WARNINGS + +#include // MFC 核心组件和标准组件 +#include // MFC 扩展 + + +#include // MFC 自动化类 + + + +#ifndef _AFX_NO_OLE_SUPPORT +#include // MFC 对 Internet Explorer 4 公共控件的支持 +#endif +#ifndef _AFX_NO_AFXCMN_SUPPORT +#include // MFC 对 Windows 公共控件的支持 +#endif // _AFX_NO_AFXCMN_SUPPORT + +#include // MFC 支持功能区和控制条 + + + + + + + + + +#ifdef _UNICODE +#if defined _M_IX86 +#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"") +#elif defined _M_X64 +#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='amd64' publicKeyToken='6595b64144ccf1df' language='*'\"") +#else +#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"") +#endif +#endif + + diff --git a/get_employee_sum.cpp b/get_employee_sum.cpp deleted file mode 100644 index 0055c86..0000000 --- a/get_employee_sum.cpp +++ /dev/null @@ -1,16 +0,0 @@ -#include "WorkerManager.h" -int WorkerManager::GetEmpSum() -{ - ifstream ifs; - ifs.open(FILENAME, ios::in); - int id; - string name; - int dID; - int sum = 0; - while (ifs >> id && ifs >> name && ifs >> dID) - { - sum++; - } - ifs.close(); - return sum; -} diff --git a/init_employee.cpp b/init_employee.cpp deleted file mode 100644 index 86be37f..0000000 --- a/init_employee.cpp +++ /dev/null @@ -1,31 +0,0 @@ -#include "WorkerManager.h" -void WorkerManager::InitEmp() -{ - ifstream ifs; - ifs.open(FILENAME, ios::in); - int id; - string name; - int dID; - int index = 0; - while (ifs >> id && ifs >> name && ifs >> dID) - { - Worker* worker = NULL; - //ݲͬŴͬ - if (dID == 1) - { - worker = new Employee(id, name, dID); - } - else if (dID == 2) - { - worker = new Manager(id, name, dID); - } - else if (dID == 3) - { - worker = new Boss(id, name, dID); - } - // - this->MEmpArr[index] = worker; - index++; - } - ifs.close(); -} \ No newline at end of file diff --git a/manager.cpp b/manager.cpp deleted file mode 100644 index c555cbd..0000000 --- a/manager.cpp +++ /dev/null @@ -1,15 +0,0 @@ -#include "Manager.h" -Manager::Manager(int id, string name, int dID) -{ - this->MID = id; - this->MName = name; - this->MDeptID = dID; -} -void Manager::ShowInfo() -{ - cout << "ְţ" << this->MID << "\tְ" << this->MName << "\tλ" << this->GetDeptName() << endl; -} -string Manager::GetDeptName() -{ - return string(""); -} \ No newline at end of file diff --git a/pch.cpp b/pch.cpp new file mode 100644 index 0000000..b6fb8f4 --- /dev/null +++ b/pch.cpp @@ -0,0 +1,5 @@ +// pch.cpp: 与预编译标头对应的源文件 + +#include "pch.h" + +// 当使用预编译的头时,需要使用此源文件,编译才能成功。 diff --git a/pch.h b/pch.h new file mode 100644 index 0000000..94bccb2 --- /dev/null +++ b/pch.h @@ -0,0 +1,14 @@ +// pch.h: 这是预编译标头文件。 +// 下方列出的文件仅编译一次,提高了将来生成的生成性能。 +// 这还将影响 IntelliSense 性能,包括代码完成和许多代码浏览功能。 +// 但是,如果此处列出的文件中的任何一个在生成之间有更新,它们全部都将被重新编译。 +// 请勿在此处添加要频繁更新的文件,这将使得性能优势无效。 + +#ifndef PCH_H +#define PCH_H + +// 添加要在此处预编译的标头 +#include "framework.h" +#include + +#endif //PCH_H diff --git a/res/WorkerManager.ico b/res/WorkerManager.ico new file mode 100644 index 0000000..11b8f6b Binary files /dev/null and b/res/WorkerManager.ico differ diff --git a/res/WorkerManager.rc2 b/res/WorkerManager.rc2 new file mode 100644 index 0000000..09e74cc Binary files /dev/null and b/res/WorkerManager.rc2 differ diff --git a/res/WorkerManagerDoc.ico b/res/WorkerManagerDoc.ico new file mode 100644 index 0000000..96365d4 Binary files /dev/null and b/res/WorkerManagerDoc.ico differ diff --git a/res/welcome.bmp b/res/welcome.bmp new file mode 100644 index 0000000..e0f12ef Binary files /dev/null and b/res/welcome.bmp differ diff --git a/res/worker.ico) b/res/worker.ico) new file mode 100644 index 0000000..7e903e5 Binary files /dev/null and b/res/worker.ico) differ diff --git a/resource.h b/resource.h new file mode 100644 index 0000000..1921ee0 --- /dev/null +++ b/resource.h @@ -0,0 +1,59 @@ +//{{NO_DEPENDENCIES}} +// Microsoft Visual C++ 生成的包含文件。 +// 供 WorkerManager.rc 使用 +// +#define IDOK2 3 +#define IDD_ABOUTBOX 100 +#define IDP_OLE_INIT_FAILED 100 +#define IDR_MAINFRAME 128 +#define IDR_WorkerManagerTYPE 130 +#define IDD_CDisplayView 310 +#define IDI_ICON_RE 310 +#define IDD_AddWorker 311 +#define IDD_CDisplayView1 312 +#define IDD_Welcome 314 +#define IDB_BITMAP1 325 +#define IDD_WorkerMessage 326 +#define IDD_ListWorker 328 +#define IDD_ChangeWorker 330 +#define IDD_FindWorker 332 +#define IDD_DeleteWorker 334 +#define IDD_ChangeConfirm 336 +#define IDD_ConfirmChange 339 +#define IDD_SomeNames 342 +#define IDD_AFewNames 344 +#define IDD_ConfirmDelete 346 +#define IDD_DeleteConfirm 348 +#define IDD_Wage 350 +#define IDD_Hour 353 +#define IDD_Yuan 355 +#define IDD_SellManager 357 +#define IDC_COMBO1 1002 +#define IDC_EDIT1 1003 +#define IDC_BUTTON1 1004 +#define IDC_EDIT6 1004 +#define IDC_BUTTON2 1005 +#define IDC_EDIT5 1005 +#define IDC_BUTTON6 1006 +#define IDC_EDIT3 1007 +#define IDC_EDIT4 1008 +#define IDC_LIST1 1009 +#define IDC_EDIT2 1009 +#define IDC_BUTTON3 1010 +#define IDC_LIST3 1010 +#define IDC_BUTTON4 1011 +#define IDC_EDIT7 1011 +#define IDC_LIST2 1012 +#define IDC_BUTTON7 1012 +#define IDC_BUTTON5 1013 + +// Next default values for new objects +// +#ifdef APSTUDIO_INVOKED +#ifndef APSTUDIO_READONLY_SYMBOLS +#define _APS_NEXT_RESOURCE_VALUE 359 +#define _APS_NEXT_COMMAND_VALUE 32771 +#define _APS_NEXT_CONTROL_VALUE 1015 +#define _APS_NEXT_SYMED_VALUE 313 +#endif +#endif diff --git a/save.cpp b/save.cpp deleted file mode 100644 index d67ea72..0000000 --- a/save.cpp +++ /dev/null @@ -1,11 +0,0 @@ -#include "WorkerManager.h" -void WorkerManager::save() -{ - ofstream ofs; - ofs.open(FILENAME, ios::out); - for (int i = 0; i < this->MEmpNum; i++) - { - ofs << this->MEmpArr[i]->MID << " " << this->MEmpArr[i]->MName << " " << this->MEmpArr[i]->MDeptID << endl; - } - ofs.close(); -} \ No newline at end of file diff --git a/show_employee.cpp b/show_employee.cpp deleted file mode 100644 index fe80674..0000000 --- a/show_employee.cpp +++ /dev/null @@ -1,17 +0,0 @@ -#include "WorkerManager.h" -void WorkerManager::ShowEmp() -{ - if (this->FileEmpty) - { - cout << "ְļڻļΪ" << endl; - } - else - { - for (int i = 0; i < this->MEmpNum; i++) - { - this->MEmpArr[i]->ShowInfo(); - } - } - system("pause"); - system("cls"); -} \ No newline at end of file diff --git a/show_menu.cpp b/show_menu.cpp deleted file mode 100644 index 7b0c103..0000000 --- a/show_menu.cpp +++ /dev/null @@ -1,16 +0,0 @@ -#include "workermanager.h" -void WorkerManager::ShowMenu() -{ - cout << "******************************" << endl; - cout << "****ӭʹְϵͳ****" << endl; - cout << "********0.˳********" << endl; - cout << "********1.ְϢ********" << endl; - cout << "********2.ʾְϢ********" << endl; - cout << "********3.ɾְְ********" << endl; - cout << "********4.޸ְϢ********" << endl; - cout << "********5.ְϢ********" << endl; - cout << "********6.ձ********" << endl; - cout << "********7.ĵ********" << endl; - cout << "******************************" << endl; - cout << endl; -} \ No newline at end of file diff --git a/sort_employee.cpp b/sort_employee.cpp deleted file mode 100644 index 9d905af..0000000 --- a/sort_employee.cpp +++ /dev/null @@ -1,47 +0,0 @@ -#include "WorkerManager.h" -void WorkerManager::SortEmp() -{ - if (this->FileEmpty) - { - cout << "ְļڻļΪ" << endl; - system("pause"); - system("cls"); - } - else - { - cout << "ѡʽ\n1.\n2." << endl; - int sel; - cin >> sel; - for (int i = 0; i < this->MEmpNum; i++) - { - int m = 1; - for (int j = i + 1; j < this->MEmpNum; j++) - { - if (sel == 1)// - { - if (this->MEmpArr[m]->MID > this->MEmpArr[j]->MID) - { - m = j; - } - } - else// - { - if (this->MEmpArr[m]->MID < this->MEmpArr[j]->MID) - { - m = j; - } - } - } - if (i != m) - { - Worker* temp = this->MEmpArr[i]; - this->MEmpArr[i] = this->MEmpArr[m]; - this->MEmpArr[m] = temp; - } - } - cout << "ɹ" << endl; - this->save(); - cout << "Ϊ" << endl; - this->ShowEmp(); - } -} \ No newline at end of file diff --git a/targetver.h b/targetver.h new file mode 100644 index 0000000..79934a3 --- /dev/null +++ b/targetver.h @@ -0,0 +1,8 @@ +#pragma once + +// 包括 SDKDDKVer.h 将定义可用的最高版本的 Windows 平台。 + +//如果要为以前的 Windows 平台生成应用程序,请包括 WinSDKVer.h,并 +// 将 _WIN32_WINNT 宏设置为要支持的平台,然后再包括 SDKDDKVer.h。 + +#include diff --git a/worker_manage.cpp b/worker_manage.cpp deleted file mode 100644 index 9fc82b0..0000000 --- a/worker_manage.cpp +++ /dev/null @@ -1,44 +0,0 @@ -#include "WorkerManager.h" -WorkerManager::WorkerManager() -{ - ifstream ifs; - ifs.open(FILENAME, ios::in); - //ļ - if (!ifs.is_open()) - { - cout << "ʾְļδ" << endl; - this->MEmpNum = 0; - this->FileEmpty = true; - this->MEmpArr = NULL; - ifs.close(); - return; - } - //ļΪ - char ch; - ifs >> ch; - if (ifs.eof()) - { - cout << "ʾְļΪ" << endl; - this->MEmpNum = 0; - this->MEmpArr = NULL; - this->FileEmpty = true; - ifs.close(); - return; - } - //ļڣ¼ - int sum = this->GetEmpSum(); - cout << "ʾǰְΪ" << sum << endl; - this->MEmpNum = sum; - //ٿռ - this->MEmpArr = new Worker * [this->MEmpNum]; - this->InitEmp(); -} - -WorkerManager::~WorkerManager() -{ - if (this->MEmpArr != NULL) - { - delete[] this->MEmpArr; - this->MEmpArr = NULL; - } -} \ No newline at end of file diff --git a/worker_manager_system.cpp b/worker_manager_system.cpp deleted file mode 100644 index 28fa877..0000000 --- a/worker_manager_system.cpp +++ /dev/null @@ -1,61 +0,0 @@ -#include "WorkerManager.h" -int main() -{ - WorkerManager wm; - int choice = 0; - while (1) - { - wm.ShowMenu(); - cout << "ѡ" << endl; - cin >> choice; - switch (choice) - { - case 0: - { - wm.ExitSystem(); - break; - } - case 1: - { - wm.AddEmploy(); - break; - } - case 2: - { - wm.ShowEmp(); - break; - } - case 3: - { - wm.DelEmp(); - break; - } - case 4: - { - wm.ChaEmp(); - break; - } - case 5: - { - wm.FindEmp(); - break; - } - case 6: - { - wm.SortEmp(); - break; - } - case 7: - { - wm.CleamFile(); - break; - } - default: - { - system("cls"); - break; - } - } - } - return 0; -} \ No newline at end of file