Realize work report

 1  public class SE:Employee
 2     {
 3         private int popularity;
 4         public int Popularity
 5         {
 6             get { return popularity; }
 7             set { popularity = value; }
 8         }
 9 
10         public string DoWork()
11         {
12             StringBuilder sb = new StringBuilder();
13             sb.Append(this.Name + ":\n");
14             for (int i = 0; i < this.workList.Count; i++)
15             {
16                 sb.Append((i + 1) + "" + workList[i].Name + ":" +
17                     workList[i].Description + "\n");
18 
19             }
20             return sb.ToString();
21         }
22         public SE(string id, string name, int age, Gender gender, int popularity,
23             List<Job>list):base(id,name,age,gender,list)
24         {
25             this.Popularity = popularity;
26         }
1    public  class PM:Employee
 2      {
 3         public  int YearOfExperience { get ; set ; }
 4         public  string Dowork()
 5         {
 6             string message = this .Name + " : Manage employees to complete work content! " ;
 7             return message;
 8         }
 9         public PM( string id, string name, int age, Gender gender, int yearOfExperience,
10            List<Job> list):base(id,name,age,gender,list)
11          
12         {
13             this.YearOfExperience = YearOfExperience;
14
1  public  class Job // Define work item 
2      {
 3          public  string Name { get ; set ; } // Job name 
4          public  string Description { get ; set ; } // Description
 5         // Constructor 
6          public Job( string name, string description)
 7          {
 8              this .Name = name;
 9              this .Description = description;
10         }
11     }
1   public  enum Gender // enumeration 
2      {
 3        male, female
 4       
5      }

public partial class Form1 : Form
    {
        List<Employee> empls = new List<Employee>();
        public Form1()
        {
            InitializeComponent();
            Init();
        }
        public void Init()
        {
            List<Job> list1 = new List<Job>();
            list1.Add( new Job( " coding " , " shopping cart module " ));
            list1.Add( new Job( " Test " , " Unit test the shopping cart module " ));
            SE ai = new SE("112", "艾边成", 25, Gender.male, 100, list1);

            List<Job> list2 = new List<Job>();
            list2.Add( new Job( " Design " , " Database Modeling " ));
            list2.Add( new Job( " Write Documentation " , " Detailed Design Instructions " ));
            SE job = new SE("113", "Joe", 24,Gender.female, 200, list2);

            PM pm = new PM("890", "比尔", 50, Gender.female, 30, null);
            empls.Add(ai);
            empls.Add(job);
            empls.Add(pm);


        }

 private void button1_Click(object sender, EventArgs e)
        {
            foreach (Employee emp in empls)
            {
                if (emp is PM)
                {
                    MessageBox.Show(((PM)emp).Dowork(), "汇报");

                }
                if (emp is SE)
                {
                    MessageBox.Show(((SE)emp).DoWork(), "汇报");
                }
            }
        }

 

1  public   class Employee
 2      {
 3          public  int Age { get ; set ; }
 4          public Gender Sex { get ; set ; }
 5          public  string ID { get ; set ; }
 6          public  string Name { get ; set ; }
 7         // give Employee adds worklist property 
8          protected List<Job> workList { get ; set ; }
 9        //构造
10         public Employee(string id, string name, int age, Gender gender, List<Job> list)
11         {
12             this.Age = age;
13             this.ID = id;
14             this.Name = name;
15             this.Sex = gender;
16             this.workList = list;
17 
18         }

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324606211&siteId=291194637