• 第六章,上机练习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 + ":
    ");
    33             for (int i = 0; i < this.WorkList.Count; i++)
    34             {
    35                 sb.Append((i + 1) + "," + WorkList[i].Name + ":" + WorkList[i].Description + "
    ");
    36             }
    37             return sb.ToString();
    38         }
    39 
    40     }
    41 }
  • 相关阅读:
    链接服务器 "(null)" 的 OLE DB 访问接口 "Microsoft.Ace.OleDb.12.0" 报错。提供程序未给出有关错误的任何信息。
    iis应用程序池 内存溢出错误 System.OutOfMemoryException
    高性能JavaScript
    HTML5介绍
    Ubuntu 16.04安装Matlab 2016b教程
    C Standard Library: 9 Signals: <signal.h>
    C Standard Library:4 Mathematical Functions: <math.h>
    C Standard Library: File Positioning Functions
    C Standard Library: Formatted Input
    C Standard Library: 2 Character Class Tests: <ctype.h>
  • 原文地址:https://www.cnblogs.com/yjjh/p/6691739.html
Copyright © 2020-2023  润新知