码迷,mamicode.com
首页 > 其他好文 > 详细

企业信息管理系统需求分析及要设计——程序的设计与实现①

时间:2019-03-26 13:28:29      阅读:104      评论:0      收藏:0      [点我收藏+]

标签:tools   Nid   color   pat   size   --   文件比较   tin   错误   

因为文件比较繁多,本设计使用Qt编写程序。

department.h

 1 #ifndef DEPARTMENT_H
 2 #define DEPARTMENT_H
 3 #include <iostream>
 4 #include "employee.h"
 5 using namespace std;
 6 class Department
 7 {
 8     int m_nid;
 9     char m_strName[20];
10     int m_num;
11     vector<Employee*> m_vesEmps;
12 public:    
13     //Department();
14     Department(int id = 100,const char *name="",int num=0);
15     bool deleteEmp(int id);
16     void listEmp(vector<Employee*>& m_vesEmps);
17     bool mondifyEmp(Employee& emp,vector<Employee*>& m_vesEmps);
18     int getnum(void);
19     void setnum(void);
20     void set_num(int num);
21     int getid(void);
22     char* getname(void);
23     void setname(const char *name);
24     void setid(int id);
25 
26     vector<Employee*>& getvector(void);
27 };
28 
29 #endif//DEPATRMENT_H

employee.h

 1 #ifndef EMPLOYEE_H
 2 #define EMPLOYEE_H
 3 class Employee
 4 {
 5 int m_nid;
 6 char m_strName[20];
 7 bool m_bGender;
 8 int m_nAge;
 9 public:
10     Employee(int id=100,const char* name="",bool sex=false,int age=18);
11     Employee(Employee& employee);
12     int getid(void);
13     char* getname(void);
14     bool getsex(void);
15     int getage(void);
16     void setid(int id);
17     void setname(char* name);
18     void setsex(bool sex);
19     void setage(int age);
20 };
21 #endif//EMPLOYEE_H

service_impl.cpp

  1 #include <iostream>
  2 #include "service_impl.h"
  3 #include "department.h"
  4 #include "employee.h"
  5 #include "tools.h"
  6 #include <vector>
  7 #include "servicedao_file_impl.h"
  8 
  9 using namespace std;
 10 
 11 vector<Department*> m_vecDepts;
 12 vector<Employee*> m_vesEmps;
 13 
 14 ServiceImpl::ServiceImpl()
 15 {
 16     m_pDao = new ServiceDaoFileImpl;
 17 }
 18 
 19 bool ServiceImpl::addDept(Department& dept)
 20 {
 21     m_pDao->load(m_vecDepts);
 22     m_vecDepts.push_back(&dept);
 23     m_pDao->save(m_vecDepts);
 24     return true;    
 25 }
 26 
 27 bool ServiceImpl::deleteDept(int deptid)
 28 {
 29     m_vecDepts.clear();
 30     m_pDao->load(m_vecDepts);
 31     vector<Department*>::iterator itor;
 32     for(itor = m_vecDepts.begin();itor !=m_vecDepts.end();itor++)
 33     {
 34         if((*itor)->getid() == deptid)
 35         {
 36             itor = m_vecDepts.erase(itor);
 37             m_pDao->save(m_vecDepts);
 38             return true;
 39         }
 40     }
 41     return false;
 42 }
 43 
 44 void ServiceImpl::listDept(void)
 45 {
 46     m_vecDepts.clear();
 47     m_pDao->load(m_vecDepts);
 48     cout << "部门ID" << " " << "部门名" << " " << "人数" << endl;
 49     for(unsigned int i=0;i<m_vecDepts.size();i++)
 50     {
 51         cout << m_vecDepts.at(i)->getid() << " " << m_vecDepts.at(i)->getname() << " " << m_vecDepts.at(i)->getnum() << endl;
 52     }
 53 } 
 54 
 55 bool ServiceImpl::addEmp(Employee& emp)
 56 {
 57     cout << "请输入添加的部门ID" << endl;
 58     int id = 0;
 59     cin >> id;
 60     for(unsigned int i=0;i<m_vecDepts.size();i++)
 61     {
 62          if(m_vecDepts.at(i)->getid() == id)
 63          {
 64             m_vecDepts.clear();
 65             m_pDao->load(m_vecDepts);
 66             m_vecDepts.at(i)->getvector().push_back(&emp);
 67             m_vecDepts.at(i)->setnum();
 68             m_pDao->save(m_vecDepts);
 69             return true;
 70          }
 71     }
 72     return false;
 73 }
 74 
 75 bool ServiceImpl::deleteEmp(int empid)
 76 {
 77     m_pDao->load(m_vecDepts);
 78     for(unsigned int i=0;i<m_vecDepts.size();i++)
 79     {
 80         unsigned int temp = m_vecDepts.at(i)->getnum();
 81         for(unsigned int j=0;j<temp;j++)
 82         {
 83             if(m_vecDepts.at(i)->getvector().at(j)->getid() == empid)
 84             {
 85                 m_vecDepts.at(i)->deleteEmp(empid);
 86                 m_pDao->save(m_vecDepts);
 87             }
 88         }
 89     }
 90     return false;
 91 }
 92 
 93 bool ServiceImpl::modifyEmp(Employee& emp)
 94 {
 95 
 96     m_pDao->load(m_vecDepts);
 97     for(unsigned int i=0;i<m_vecDepts.size();i++)
 98     {       
 99         m_vecDepts.at(i)->mondifyEmp(emp,m_vesEmps);
100         m_pDao->save(m_vecDepts);
101         return true;
102     }
103     return false;
104 }
105 
106 void ServiceImpl::listEmp(int deptid)
107 {
108     m_pDao->load(m_vecDepts);
109     for(unsigned int i=0;i<m_vecDepts.size();i++)
110     {
111          if(m_vecDepts.at(i)->getid() == deptid)
112          {
113             unsigned int temp = m_vecDepts.at(i)->getnum();
114             for(unsigned int j=0;j<temp;j++)
115             {
116             
117             cout << m_vecDepts.at(i)->getvector().at(j)->getid() << " " << m_vecDepts.at(i)->getvector().at(j)->getname() << " " << m_vecDepts.at(i)->getvector().at(j)->getsex() << " " << m_vecDepts.at(i)->getvector().at(j)->getage() << endl;
118             
119             }
120             return;
121          }
122     }
123 }
124 
125 void ServiceImpl::listAllEmp(void)
126 {
127     m_pDao->load(m_vecDepts);
128     for(unsigned int i=0;i<m_vecDepts.size();i++)
129     {
130         cout << m_vecDepts.at(i)->getid() << " " << m_vecDepts.at(i)->getname() << " " << m_vecDepts.at(i)->getnum() << endl;
131         unsigned int temp = m_vecDepts.at(i)->getnum();
132         for(unsigned int j=0;j<temp;j++)
133         {
134             
135             cout << m_vecDepts.at(i)->getvector().at(j)->getid() << " " << m_vecDepts.at(i)->getvector().at(j)->getname() << " " << m_vecDepts.at(i)->getvector().at(j)->getsex() << m_vecDepts.at(i)->getvector().at(j)->getage() << endl;    
136             
137         }
138     }
139 }
140 ServiceImpl::~ServiceImpl()
141 {
142     delete[]m_pDao;
143 }

serviceview_console_impl.cpp

  1 #include <iostream>
  2 #include <string.h>
  3 #include <stdlib.h>
  4 #include <unistd.h>
  5 #include "serviceview_console_impl.h"
  6 #include "department.h"
  7 #include "employee.h"
  8 #include "tools.h"
  9 #include "service.h"
 10 #include "service_impl.h"
 11 
 12 
 13 using namespace std;
 14 extern vector<Manager*> managers;
 15 
 16 ServiceViewConsoleImpl::ServiceViewConsoleImpl()
 17 {
 18     m_pService = new ServiceImpl;
 19 }
 20 
 21 void ServiceViewConsoleImpl::menu(void)
 22 {
 23     system("clear");
 24     int id;
 25     char password[20] ={};
 26     cout << "请输入您的ID: " << endl;
 27     cin >> id;
 28     clear_stdin();
 29     cout << "请输入您的密码:" << endl;
 30     cin >> password;
 31     clear_stdin();
 32 
 33     bool flag=false;
 34     if(!managers.size()) return;
 35     vector<Manager*>::iterator itor;
 36     for (itor = managers.begin(); itor != managers.end(); itor++)
 37     {
 38         if((*itor)->getid() == id)
 39         {
 40 
 41             if (0 == strcmp((*itor)->getpassword(),password))
 42             flag = true;
 43         }
 44     }
 45 
 46     if(flag == false)
 47     {
 48         cout << "您的ID或密码错误" << endl;
 49         getch();
 50         return;
 51     }
 52 
 53     while(1)
 54     {
 55         system("clear");
 56         cout<<"----企业管理系统----"<<endl;
 57         cout<<"1、增加部门"<<endl;
 58         cout<<"2、删除部门"<<endl;
 59         cout<<"3、列出部门"<<endl;
 60         cout<<"4、增加员工"<<endl;
 61         cout<<"5、删除员工"<<endl;
 62         cout<<"6、修改员工信息"<<endl;
 63         cout<<"7、列出部门员工"<<endl;
 64         cout<<"8、列出所有部门员工"<<endl;
 65         cout<<"9、退出"<<endl;
 66         cout<<"------------------"<<endl;
 67         switch(get_cmd(1,9))
 68         {
 69             case 1:addDept();break;
 70             case 2:deleteDept();break;
 71             case 3:listDept();break;
 72             case 4:addEmp();break;
 73             case 5:deleteEmp();break;
 74             case 6:modifyEmp();break;
 75             case 7:listEmp();break;
 76             case 8:listAllEmp();break;
 77             case 9:return;
 78             default :cout << "请重新输入" << endl; continue;
 79         }
 80     }
 81 }
 82 
 83 void ServiceViewConsoleImpl::addDept(void)
 84 {
 85     cout << "请输入部门名称" << endl;
 86     char name[20];
 87     cin >> name;
 88     int id = generator_DeptId();
 89     Department dept(id,name,0);
 90     if(m_pService->addDept(dept))
 91     {
 92         cout << "添加部门成功!"<< endl;
 93     }
 94     anykey_continue();
 95 }
 96 
 97 void ServiceViewConsoleImpl::deleteDept(void)
 98 {
 99     int id = 0;
100     cout << "请输入要删除的部门id" << endl;
101     cin >> id;
102     if(m_pService->deleteDept(id))
103     {
104         cout << "删除部门成功!" << endl;
105     }
106     anykey_continue();
107 }
108 
109 void ServiceViewConsoleImpl::listDept(void)
110 {
111     m_pService->listDept();
112     anykey_continue();
113 }
114 
115 void ServiceViewConsoleImpl::addEmp(void)
116 {
117     cout << "请输入员工姓名" << endl;
118     char name[20]= {};
119     cin >> name;
120     clear_stdin();
121     cout << "请输入员工性别" << endl;
122     bool sex;
123     cin >> sex;
124     clear_stdin();
125     cout << "请输入员工年龄" << endl;
126     int age;
127     cin >> age;
128     clear_stdin();
129     int m_id = generator_EmpId();
130     Employee emp(m_id,name,sex,age);
131     if(m_pService->addEmp(emp))
132     {
133         cout << "添加员工成功!"<< endl;
134     }
135     
136     anykey_continue();    
137 }
138 
139 void ServiceViewConsoleImpl::deleteEmp(void)
140 {
141     int id = 0;
142     cout << "请输入要删除的员工id" << endl;
143     cin >> id;
144     clear_stdin();
145     if(m_pService->deleteEmp(id))
146     {
147         cout << "删除员工成功!" << endl;
148     }
149     anykey_continue();
150 }
151 
152 void ServiceViewConsoleImpl::modifyEmp(void)
153 {
154     cout << "请输入修改员工的部门ID" << endl;
155     int id = 0;
156     cin >> id;
157     cout << "请输入要修改员工的ID" << endl;
158     int m_id2;
159     cin >> m_id2;
160 
161     cout << "请输入要修改的员工姓名" << endl;
162     char name[20]= {};
163     cin >> name;
164     clear_stdin();
165     cout << "请输入要修改的员工性别" << endl;
166     bool sex;
167     cin >> sex;
168     clear_stdin();
169     cout << "请输入要修改的员工年龄" << endl;
170     int age = 0;
171     cin >> age;
172     clear_stdin();
173     int m_id = generator_EmpId();
174     Employee emp(m_id,name,sex,age);
175     if(m_pService->modifyEmp(emp))
176     {
177         cout << "修改员工成功!"<< endl;
178     }
179     anykey_continue();
180 }
181 void ServiceViewConsoleImpl::listEmp(void)
182 {
183     int id = 0;
184     cout << "请输入要列出的部门id" << endl;
185     cin >> id;
186     m_pService->listEmp(id);
187     anykey_continue();
188 }
189 void ServiceViewConsoleImpl::listAllEmp(void)
190 {
191     m_pService->listAllEmp();
192     anykey_continue();
193 }
194 ServiceViewConsoleImpl::~ServiceViewConsoleImpl(void)
195 {
196     delete []m_pService;
197 }

未完待续

企业信息管理系统需求分析及要设计——程序的设计与实现①

标签:tools   Nid   color   pat   size   --   文件比较   tin   错误   

原文地址:https://www.cnblogs.com/kid971220/p/10599215.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!