第六章,上机练习2(员工汇报工作)

 1 using SJ2.entity;
 2 using System;
 3 using System.Collections.Generic;
 4 using System.ComponentModel;
 5 using System.Data;
 6 using System.Drawing;
 7 using System.Linq;
 8 using System.Text;
 9 using System.Threading.Tasks;
10 using System.Windows.Forms;
11 
12 namespace SJ2
13 {
14     public partial class FrmMain : Form
15     {
16         public FrmMain()
17         {
18             InitializeComponent();
19         }
20 
21         List<Employee> empls = new List<Employee>();
22         /// <summary>
23         /// 单击事件
24         /// </summary>
25         /// <param name="sender"></param>
26         /// <param name="e"></param>
27         private void btnHuiBo_Click(object sender, EventArgs e)
28         {
29             foreach (Employee emp in empls)
30             {
31                 if (emp is PM)
32                 {
33                     MessageBox.Show(((PM)emp).DoWork());
34                 }
35                 if (emp is SE) 
36                 {
37                     MessageBox.Show(((SE)emp).DoWorK());
38                 }
39             }
40         }
41 
42         /// <summary>
43         /// 加载事件
44         /// </summary>
45         /// <param name="sender"></param>
46         /// <param name="e"></param>
47         private void FrmMain_Load(object sender, EventArgs e)
48         {
49             List<Job> list1 = new List<Job>();
50             list1.Add(new Job("编码", "购物车模块"));
51             list1.Add(new Job("测试", "给购物车模块做单元测试"));
52             SE ai = new SE("112", 25, "爱变成", "", list1, 200);//list1已经赋值给Job
53 
54             List<Job> list2 = new List<Job>();
55             list2.Add(new Job("设计", "数据库建模"));
56             list2.Add(new Job("编写文档", "详细设计说明书"));
57             SE Joe = new SE("113", 25, "Joe", "", list2, 200);//list1已经赋值给Job
58 
59             PM pm = new PM("890",20, "hh", "", null,30);
60             empls.Add(ai);
61             empls.Add(Joe);
62             empls.Add(pm);
63         }
64     }
65 }
 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 using System.Threading.Tasks;
 6 
 7 namespace SJ2.entity
 8 {
 9 
10     public class Employee
11     {
12         /// <summary>
13         /// 工作列表属性
14         /// </summary>
15         protected List<Job> WorkList { set; get; }
16         /// <summary>
17         /// 年龄
18         /// </summary>
19         public int Age { get; set; }
20         /// <summary>
21         /// 性别
22         /// </summary>
23         public string  Sex { get; set; }
24         /// <summary>
25         /// 工号
26         /// </summary>
27         public string ID { get; set; }
28         /// <summary>
29         /// 姓名
30         /// </summary>
31         public string Name { get; set; }
32 
33         /// <summary>
34         /// 构造函数
35         /// </summary>
36         public Employee(string id,int age,string name,string sex,List<Job>list) 
37         {
38             this.ID = id;
39             this.Age = age;
40             this.Name = name;
41             this.Sex = sex;
42             this.WorkList = list;
43 
44 
45         }
46     }
47 }
 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 using System.Threading.Tasks;
 6 
 7 namespace SJ2.entity
 8 {
 9     /// <summary>
10     /// jop类,定义工作项目
11     /// </summary>
12     public class Job
13     {
14         /// <summary>
15         /// 工作名称
16         /// </summary>
17         public string Name { get; set; }
18         /// <summary>
19         /// 描述
20         /// </summary>
21         public string Description { get; set; }
22 
23         /// <summary>
24         /// 结构函数
25         /// </summary>
26         /// <param name="name"></param>
27         /// <param name="description"></param>
28         public Job(string name, string description) 
29         {
30             this.Name = name;
31             this.Description = description;
32         }
33        
34     }
35 }
 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 using System.Threading.Tasks;
 6 
 7 namespace SJ2.entity
 8 {
 9     /// <summary>
10     /// 经理类
11     /// </summary>
12    public class PM:Employee
13     {
14        /// <summary>
15        /// 经验
16        /// </summary>
17         public int Yesar{ get; set; }
18       
19        //构造函数
20         public PM(string id, int age, string name, string sex, List<Job> list, int yesar):base( id,  age,  name,  sex,  list) 
21         {
22             this.Yesar = yesar;
23         }
24        /// <summary>
25        /// 添加工作方法
26        /// </summary>
27        /// <returns></returns>
28         public string DoWork() 
29         {
30             string message = this.Name + "管理员工完成工作内容!";
31             return message;
32         }
33     }
34 }
 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 using System.Threading.Tasks;
 6 
 7 namespace SJ2.entity
 8 {
 9     /// <summary>
10     /// 员工类
11     /// </summary>
12     public class SE:Employee
13     {
14         /// <summary>
15         /// 人气
16         /// </summary>
17         public int Popularity { get; set; }
18 
19         //构造函数
20         public SE(string id, int age, string name, string sex, List<Job> list, int popularity):base( id,  age,  name,  sex,  list) 
21         {
22             this.Popularity = popularity;
23         }
24 
25 
26         /// <summary>
27         /// 显示工作方法
28         /// </summary>
29         public string DoWorK() 
30         {
31             StringBuilder sb = new StringBuilder();
32             sb.Append(this.Name + ":\n");
33             for (int i = 0; i < this.WorkList.Count; i++)
34             {
35                 sb.Append((i + 1) + "," + WorkList[i].Name + ":" + WorkList[i].Description + "\n");
36             }
37             return sb.ToString();
38         }
39 
40     }
41 }

 

posted on 2017-04-11 01:06  yjh`  阅读(182)  评论(0编辑  收藏  举报

导航