唯愛i

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

----------父类----------

 1 using Lesson6.上机练习2.enums;
 2 using System;
 3 using System.Collections.Generic;
 4 using System.Linq;
 5 using System.Text;
 6 using System.Threading.Tasks;
 7 
 8 namespace Lesson6.上机练习2
 9 {
10     /// <summary>
11     /// 父类
12     /// </summary>
13     public class Employee
14     {
15         /// <summary>
16         /// 工号
17         /// </summary>
18         public string ID { get; set; }
19 
20         /// <summary>
21         /// 年龄
22         /// </summary>
23         public int Age { get; set; }
24 
25         /// <summary>
26         /// 姓名
27         /// </summary>
28         public string Name { get; set; }
29 
30         /// <summary>
31         /// 性别
32         /// </summary>
33         public Gender Gender { get; set; }
34 
35         
36 
37         /// <summary>
38         /// 给Employee类添加工作列表属性
39         /// </summary>
40         protected List<Job> WorkList { get; set; }
41 
42         public Employee(string id, int age, string name, Gender gender, List<Job> list)
43         {
44             this.ID = id;
45             this.Age = age;
46             this.Name = name;
47             this.Gender = gender;
48             this.WorkList = list;
49         }
50     }
51 }
View Code

----------Job类----------

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 using System.Threading.Tasks;
 6 
 7 namespace Lesson6.上机练习2
 8 {
 9     /// <summary>
10     /// 定义工作项目
11     /// </summary>
12     public class Job
13     {
14         /// <summary>
15         /// 工作名称
16         /// </summary>
17         public string Name { get; set; }
18 
19         /// <summary>
20         /// 描述
21         /// </summary>
22         public string Description { get; set; }
23 
24         /// <summary>
25         /// 构造函数
26         /// </summary>
27         /// <param name="name"></param>
28         /// <param name="description"></param>
29         public Job(string name, string description)
30         {
31             this.Name = name;
32             this.Description = description;
33         }
34     }
35 }
View Code

----------PM类----------

 1 using Lesson6.上机练习2.enums;
 2 using System;
 3 using System.Collections.Generic;
 4 using System.Linq;
 5 using System.Text;
 6 using System.Threading.Tasks;
 7 
 8 namespace Lesson6.上机练习2
 9 {
10     /// <summary>
11     /// 项目经理
12     /// </summary>
13     class PM:Employee
14     {
15         /// <summary>
16         /// 给PM类添加DoWork()方法:工作
17         /// </summary>
18         /// <returns></returns>
19         public string DoWork()
20         {
21             string message = this.Name + ":管理员完成工作类容!";
22             return message;
23         }
24 
25         /// <summary>
26         /// 管理经验
27         /// </summary>
28         public int YearOfExperience { get; set; }
29 
30 
31         /// <summary>
32         /// 修改PM类的构造函数
33         /// </summary>
34         /// <param name="id"></param>
35         /// <param name="name"></param>
36         /// <param name="age"></param>
37         /// <param name="gender"></param>
38         /// <param name="yearOfExperience"></param>
39         /// <param name="list"></param>
40         public PM(string id,string name,int age,Gender gender,int yearOfExperience,List<Job> list):base(id,age,name,gender,list)
41         {
42             this.YearOfExperience = yearOfExperience;
43         }
44     }
45 }
View Code
 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 using System.Threading.Tasks;
 6 
 7 namespace Lesson6.上机练习2
 8 {
 9     /// <summary>
10     /// 定义工作项目
11     /// </summary>
12     public class Job
13     {
14         /// <summary>
15         /// 工作名称
16         /// </summary>
17         public string Name { get; set; }
18 
19         /// <summary>
20         /// 描述
21         /// </summary>
22         public string Description { get; set; }
23 
24         /// <summary>
25         /// 构造函数
26         /// </summary>
27         /// <param name="name"></param>
28         /// <param name="description"></param>
29         public Job(string name, string description)
30         {
31             this.Name = name;
32             this.Description = description;
33         }
34     }
35 }
View Code

----------SE类----------

 1 using Lesson6.上机练习2.enums;
 2 using System;
 3 using System.Collections.Generic;
 4 using System.Linq;
 5 using System.Text;
 6 using System.Threading.Tasks;
 7 
 8 namespace Lesson6.上机练习2
 9 {
10     /// <summary>
11     /// 程序员
12     /// </summary>
13     public class SE:Employee
14     {
15         /// <summary>
16         /// 给SE类添加DoWorK()方法:工作
17         /// </summary>
18         /// <returns></returns>
19         public string DoWork()
20         {
21             StringBuilder sb = new StringBuilder();
22             sb.Append(this.Name + ":\n");
23             for (int i = 0; i < this.WorkList.Count; i++)
24             {
25                 sb.Append((i + 1) + "" + WorkList[i].Name + ":" + WorkList[i].Description + "\n");   
26             }
27             return sb.ToString();
28         }
29 
30         /// <summary>
31         /// 人气值
32         /// </summary>
33         public int Popularity { get; set; }
34         
35         /// <summary>
36         /// 修改SE类的构造函数
37         /// </summary>
38         /// <param name="id"></param>
39         /// <param name="name"></param>
40         /// <param name="age"></param>
41         /// <param name="gender"></param>
42         /// <param name="popularity"></param>
43         /// <param name="List"></param>
44         public SE(string id, string name, int age, Gender gender, int popularity, List<Job> List)
45             : base(id, age, name, gender, List)
46         {
47             this.Popularity = popularity;
48         }
49     }
50 }
View Code

----------窗体代码----------

 1 using Lesson6.上机练习2;
 2 using Lesson6.上机练习2.enums;
 3 using System;
 4 using System.Collections.Generic;
 5 using System.ComponentModel;
 6 using System.Data;
 7 using System.Drawing;
 8 using System.Linq;
 9 using System.Text;
10 using System.Threading.Tasks;
11 using System.Windows.Forms;
12 
13 namespace Lesson6_2
14 {
15     public partial class Form1 : Form
16     {
17         public Form1()
18         {
19             InitializeComponent();
20             Init();
21         }
22         List<Employee> empls = new List<Employee>();
23         
24         /// <summary>
25         ///汇报工作
26         /// </summary>
27         /// <param name="sender"></param>
28         /// <param name="e"></param>
29         private void button1_Click(object sender, EventArgs e)
30         {
31             foreach (Employee emp in empls)
32             {
33                 if(emp is PM)
34                 {
35                     MessageBox.Show(((PM)emp).DoWork(),"汇报");
36                 }
37                 if(emp is SE)
38                 {
39                     MessageBox.Show(((SE)emp).DoWork(),"汇报");                
40                 }
41             }
42 
43             
44         }
45 
46       
47         
48             
49     
50         /// <summary>
51         /// 员工信息初始化
52         /// </summary>
53         public void Init()
54         {
55             //实例化SE对象
56             List<Job> list1 = new List<Job>();
57             list1.Add(new Job("编码", "购物车模块"));
58             list1.Add(new Job("测试", "给购物车模块做单元测试"));
59             SE ai = new SE("112","爱编程",50,Gender.男,30,list1);
60 
61             List<Job> list2 = new List<Job>();
62             list2.Add(new Job("设计","数据库建模"));
63             list2.Add(new Job("编写文档","详细设计说明书"));
64             SE joe = new SE("113","joe",30,Gender.女,200,list2);
65 
66             //实例化PM对象
67             PM pm = new PM("890","盖茨",50,Gender.女,30,null);
68             empls.Add(ai);
69             empls.Add(joe);
70             empls.Add(pm);
71         }
72 
73 
74     }
75 }
View Code

 

posted on 2017-04-11 02:35  唯愛i  阅读(514)  评论(0编辑  收藏  举报