当前仓库属于关闭状态,部分功能使用受限,详情请查阅 仓库状态说明
1 Star 0 Fork 0

moe/emis
关闭

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
serviceview_console_impl.cpp 4.83 KB
一键复制 编辑 原始数据 按行查看 历史
moe 提交于 2014-03-14 00:45 . initial commit
#include "serviceview_console_impl.h"
#include "service_impl.h"
#include <string>
#include <sstream>
#include <iomanip>
#include <stdexcept>
#include <iostream>
using namespace std;
namespace emis {
ServiceViewConsoleImpl::ServiceViewConsoleImpl ():
m_service(new ServiceImpl){
} /* 整合业务逻辑模块 */
ServiceViewConsoleImpl::~ServiceViewConsoleImpl(){
delete m_service;
}
void ServiceViewConsoleImpl::menu()
{
while (true)
switch (showMenu()) {
case 1: addDept(); break;
case 2: deleteDept(); break;
case 3: listDept(); break;
case 4: addEmp(); break;
case 5: deleteEmp(); break;
case 6: modifyEmp(); break;
case 7: listEmp(); break;
case 8: listAllEmp(); break;
case 0: return;
default:cout << "Invalid Choice!!!" << endl;
}
}
void ServiceViewConsoleImpl::addDept()
{
string name;
cout << "请输入部门名称: " << flush; cin >> name;
Department d(name);
if (m_service->addDept(d))
cout << "增加部门成功!" << endl;
else
cout << "增加部门失败!" << endl;
}
void ServiceViewConsoleImpl::deleteDept()
{
int id;
cout << "请输入部门ID: " << flush; cin >> id;
if (m_service->deleteDept(id)) {
cout << "删除部门成功!" << endl;
} else {
cin.clear();
cin.ignore(1024,'\n');
cout << "删除部门失败,部门ID无效!" << endl;
}
}
void ServiceViewConsoleImpl::listDept()
{
int id; string name; int num;
const vector<Department>& ds = m_service->listDept();
vector<Department>::const_iterator it = ds.begin();
cout<<left<<setw(12)<<"部门ID"<<setw(16)<<"部门名称 "<<"员工人数"<<endl;
for (; it!=ds.end(); ++it) {
ostringstream oss; oss << *it;
istringstream iss(oss.str());
iss >> id >> name >> num;
cout<<left<<setw(12)<<id<<setw(16)<<name<<num<<endl;
}
}
void ServiceViewConsoleImpl::addEmp()
{
string name; bool gender; int age; int id;
cout << "请输入员工姓名: " << flush; cin >> name;
cout << "请输入员工性别: " << flush; cin >> gender;
cout << "请输入员工年龄: " << flush; cin >> age;
cout << "请输入部门ID: " << flush; cin >> id;
Employee e(name,gender,age);
if (m_service->addEmp(e,id)) {
cout << "增加员工成功!" << endl;
} else {
cin.clear();
cin.ignore(1024,'\n');
cout << "增加员工失败!" << endl;
}
}
void ServiceViewConsoleImpl::deleteEmp()
{
int id;
cout << "请输入员工ID: " << flush; cin >> id;
if (m_service->deleteEmp(id)) {
cout << "删除员工成功!" << endl;
} else {
cin.clear();
cin.ignore(1024,'\n');
cout << "员工ID无效,删除失败!" << endl;
}
}
void ServiceViewConsoleImpl::modifyEmp()
{
int id,age; bool gender; string name;
cout << "请输入员工ID: " << flush; cin >> id;
cout << "请输入员工姓名: "<< flush;cin >> name;
cout << "请输入员工性别: "<< flush;cin >> gender;
cout << "请输入员工年龄: "<< flush;cin >> age;
Employee e(id,name,gender,age);
if (m_service->modifyEmp(e)) {
cout << "修改员工信息成功!" << endl;
} else{
cin.clear();
cin.ignore(1024,'\n');
cout << "修改员工失败!" << endl;
}
}
void ServiceViewConsoleImpl::listEmp()
{
int id;
cout << "请输入部门ID: " << flush; cin >> id;
try {
const vector<Employee>& es = m_service->listEmp(id);
cout<<left<<setw(12)<<"员工ID"<<setw(18)<<"员工姓名"
<<setw(8)<<"性别"<<"年龄"<<endl;
vector<Employee>::const_iterator it = es.begin();
int age; bool gender; string name;
for (; it!=es.end(); ++it) {
ostringstream oss; oss << *it;
istringstream iss(oss.str());
iss >> id >> name >> gender >> age;
cout<<setw(12)<<id<<setw(18)<<name<<setw(8)<<gender<<age<<endl;
}
} catch (const out_of_range &e){
cout << e.what() << endl;
}
}
void ServiceViewConsoleImpl::listAllEmp()
{
const vector<Department>& ds = m_service->listDept();
cout<<left<<setw(12)<<"员工ID"<<setw(18)<<"员工姓名"
<<setw(8)<<"性别"<<"年龄"<<endl;
int id,age; bool gender; string name;
for (size_t i=0; i<ds.size(); i++) {
const vector<Employee>& es = m_service->listEmp(ds[i].getid());
for (size_t j=0; j<es.size(); ++j) {
ostringstream oss; oss << es[j];
istringstream iss(oss.str());
iss >> id >> name >> gender >> age;
cout<<setw(12)<<id<<setw(18)<<name<<setw(8)<<gender<<age<<endl;
}
}
}
int ServiceViewConsoleImpl::showMenu()
{
cout << "\n运营管理子系统" << endl;
cout << "--------------------"<<endl;
cout << "[1] 增加部门" << endl;
cout << "[2] 删除部门" << endl;
cout << "[3] 列出部门" << endl;
cout << "[4] 增加员工" << endl;
cout << "[5] 删除员工" << endl;
cout << "[6] 修该员工信息" << endl;
cout << "[7] 列出部门员工" << endl;
cout << "[8] 列出所有员工" << endl;
cout << "[0] 返回" << endl;
cout << "请选择: " << flush;
string c; cin >> c;
if (c[0]>'8' || c[0]<'0') {
cin.clear();
cin.ignore(1024,'\n');
return -1;
}
return c[0]-'0';
}
} /* namespace emis */
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/moe/emis.git
[email protected]:moe/emis.git
moe
emis
emis
master

搜索帮助