首页 > 代码库 > 第七章.上级练习2~3

第七章.上级练习2~3

技术分享
 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 using System.Threading.Tasks;
 6 
 7 namespace Lesson7_2.Entity
 8 {
 9     /// <summary>
10     /// 编码工作类
11     /// </summary>
12     public class CodeJob:Job
13     {
14         //测试用例个数
15         public int Bugs { get; set; }
16 
17         //发现的Bug数量
18         public int CodingLines { get; set; }
19 
20         //所需工作日
21         public int WorkDay { get; set; }
22 
23         /// <summary>
24         /// 重写方法
25         /// </summary>
26         public override void Execute(WorkList list,int index)
27         {
28             CodeFrm cf = new CodeFrm(this,list,index);
29             cf.ShowDialog();
30         }
31 
32         public override void Show()
33         {
34             ShowFrm show = new ShowFrm();
35             show.job = this;
36             show.Show();
37         }
38         /// <summary>
39         /// 无参构造函数
40         /// </summary>
41         public CodeJob()
42         {
43 
44         }
45 
46         /// <summary>
47         /// 有参构造函数
48         /// </summary>
49         public CodeJob(string name, string description, string type, int bugs, int codingLines, int workDay)
50             : base(name, description, type)
51         {
52             this.Bugs = bugs;
53             this.CodingLines = codingLines;
54             this.WorkDay = workDay;
55         }
56 
57     }
58 }
编码工作类
技术分享
 1 using Lesson7_2.Entity;
 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.Entity
 9 {
10     /// <summary>
11     /// 员工类
12     /// </summary>
13     public class Employee
14     {
15         //年龄
16         public int Age { get; set; }
17         //性别
18         public Gender Gender { get; set; }
19         //工号
20         public string ID { get; set; }
21         //姓名
22         public string Name { get; set; }
23         public List<Job> WorkList { get; set; }
24         //无参构造函数
25         public Employee()
26         {
27 
28         }
29         //有参构造函数
30         public Employee( string name, List<Job> workList)
31         {
32             this.Name = name;
33             this.WorkList = workList;
34         }
35     }
36 }
员工类
技术分享
 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 using System.Threading.Tasks;
 6 
 7 namespace Lesson7_2.Entity
 8 {
 9     /// <summary>
10     /// 工作类
11     /// </summary>
12     public abstract class Job
13     {      
14         // 工作描述
15         public string Description { get; set; }
16 
17         //工作名称
18         public string Name { get; set; }
19 
20         //工作类型
21         public string Type { get; set; }
22 
23         /// <summary>
24         /// 抽象方法
25         /// </summary>
26         public abstract void Execute(WorkList list,int index);
27 
28         public abstract void Show();
29         /// <summary>
30         /// 无参构造函数
31         /// </summary>
32         public Job()
33         {
34 
35         }
36 
37         /// <summary>
38         /// 有参构造函数
39         /// </summary>
40         public Job(string name, string description, string type)
41         {
42             this.Name = name;
43             this.Description = description;
44             this.Type = type;
45         }
46      
47     }
48 }
工作类
技术分享
 1 using Lesson7_2.Entity;
 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.Entity
 9 {
10     /// <summary>
11     /// 工程师类
12     /// </summary>
13     public class SE:Employee
14     {
15         //人气
16         private int _pupularity;
17 
18         public int Pupularity
19         {
20             get { return _pupularity; }
21             set { _pupularity = value; }
22         }
23         public SE(string name, List<Job> workList)
24             : base(name, workList)
25         {
26 
27         }
28     }
29 }
程序员类
技术分享
 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 using System.Threading.Tasks;
 6 
 7 namespace Lesson7_2.Entity
 8 {
 9     /// <summary>
10     /// 测试工作类
11     /// </summary>
12     public class TestJob:Job
13     {
14         //有效代码行数
15         public int CaseNum { get; set; }
16 
17         //遗留问题
18         public int FindBugs { get; set; }
19 
20         //所需工作日
21         public int WorkDay { get; set; }
22 
23         /// <summary>
24         /// 重写方法
25         /// </summary>
26         public override void Execute(WorkList list,int index)
27         {
28             TestFrm tj = new TestFrm(this,list,index);
29             tj.ShowDialog();
30         }
31         public override void Show()
32         {
33             ShowFrm show = new ShowFrm();
34             show.job = this;
35             show.Show();
36         
37         }
38         /// <summary>
39         /// 无参构造函数
40         /// </summary>
41         public TestJob()
42         {
43 
44         }
45 
46         /// <summary>
47         /// 有参构造函数
48         /// </summary>
49         public TestJob(string name, string description, string type, int caseNum, int findBugs, int workDay)
50             : base(name, description, type)
51         {
52             this.CaseNum = caseNum;
53             this.FindBugs = findBugs;
54             this.WorkDay = workDay;
55         }
56     }
57 }
测试工作类
技术分享
 1 using Lesson7_2.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 Lesson7_2
13 {
14     public partial class CodeFrm : Form
15     {
16         public CodeFrm(Job job, WorkList list, int index)
17         {
18             InitializeComponent();
19             this.j = job;
20             this.w = list;
21             this.index = index;
22         }
23         public CodeFrm()
24         {
25 
26         }
27         public WorkList w;
28 
29         public Job j;
30         //接收索引
31         public int index;
32 
33         /// <summary>
34         /// 修改数据按钮
35         /// </summary>
36         /// <param name="sender"></param>
37         /// <param name="e"></param>
38         private void btnSubmit_Click(object sender, EventArgs e)
39         {
40             var t = ((CodeJob)j);
41             t.Bugs = int.Parse(txtBugs.Text.Trim());
42             t.CodingLines = int.Parse(txtCodingLines.Text.Trim());
43             t.WorkDay = int.Parse(txtWorkDay.Text.Trim()); ;
44             w.jobs.RemoveAt(index);
45             w.jobs.Insert(index, t);
46         }
47         /// <summary>
48         /// 展示数据
49         /// </summary>
50         public void show()
51         {
52             var t = ((CodeJob)j);
53             txtBugs.Text = t.Bugs.ToString();
54             txtCodingLines.Text = t.CodingLines.ToString();
55             txtWorkDay.Text = t.WorkDay.ToString();
56         }
57         /// <summary>
58         /// 窗体加载事件
59         /// </summary>
60         /// <param name="sender"></param>
61         /// <param name="e"></param>
62         private void CodeFrm_Load(object sender, EventArgs e)
63         {
64             show();
65         }
66 
67         /// <summary>
68         /// 关闭本窗体
69         /// </summary>
70         /// <param name="sender"></param>
71         /// <param name="e"></param>
72         private void btnCancel_Click(object sender, EventArgs e)
73         {
74             this.Close();
75         }
76     }
77 }
编码窗体
技术分享
 1 using Lesson7_2.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 Lesson7_2
13 {
14     public partial class ShowFrm : Form
15     {
16         public ShowFrm()
17         {
18             InitializeComponent();
19         }
20         public Job job;
21         /// <summary>
22         /// 退出当前窗口
23         /// </summary>
24         /// <param name="sender"></param>
25         /// <param name="e"></param>
26         private void btnSure_Click(object sender, EventArgs e)
27         {
28             this.Close();
29         }
30         /// <summary>
31         ///  窗体加载事件
32         /// </summary>
33         /// <param name="sender"></param>
34         /// <param name="e"></param>
35         private void ShowFrm_Load(object sender, EventArgs e)
36         {
37 
38             try
39             {
40                 var r = (CodeJob)(job);
41                 label1.Text = "测试用例个数:" + r.CodingLines;
42                 label2.Text = "发现的Bug数量:" + r.Bugs;
43                 label3.Text = "所需工作日:" + r.WorkDay;
44             }
45             catch (Exception)
46             {
47                 var r = (TestJob)(job);
48                 label1.Text = "邮箱编码行数:" + r.CaseNum;
49                 label2.Text = "遗留问题:" + r.FindBugs;
50                 label3.Text = "工作日:" + r.WorkDay;
51             }
52         }
53     }
54 }
指标完情况窗体
技术分享
 1 using Lesson7_2.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 Lesson7_2
13 {
14     public partial class TestFrm : Form
15     {
16         
17         public TestFrm(Job job,WorkList list,int index)
18         {
19             InitializeComponent();
20             this.j = job;
21             this.w = list;
22             this.index = index;
23         }
24         public TestFrm()
25         {
26 
27         }
28         //接收
29         public Job j;
30         //接收索引
31         public int index;
32         public WorkList w;
33         private void TestFrm_Load(object sender, EventArgs e)
34         {
35             show();
36         }
37         
38         /// <summary>
39         /// 展示数据
40         /// </summary>
41         public void show()
42         {
43             var t = ((TestJob)j);
44             txtCaseNum.Text = t.CaseNum.ToString();
45             txtFindBugs.Text = t.FindBugs.ToString();
46             txtWorkDay.Text = t.WorkDay.ToString();
47         }
48         /// <summary>
49         /// 修改数据
50         /// </summary>
51         /// <param name="sender"></param>
52         /// <param name="e"></param>
53         private void btnSubmit_Click(object sender, EventArgs e)
54         {
55             var t = ((TestJob)j);
56             t.CaseNum = int.Parse(txtCaseNum.Text.Trim());
57             t.FindBugs = int.Parse(txtFindBugs.Text.Trim());
58             t.WorkDay = int.Parse(txtWorkDay.Text.Trim()); ;
59             w.jobs.RemoveAt(index);
60             w.jobs.Insert(index,t);
61         }
62         /// <summary>
63         /// 关闭本窗口
64         /// </summary>
65         /// <param name="sender"></param>
66         /// <param name="e"></param>
67         private void btnCancel_Click(object sender, EventArgs e)
68         {
69             this.Close();
70         }
71     }
72 }
测试窗体
技术分享
 1 using lesson6_2.Entity;
 2 using Lesson7_2.Entity;
 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 Lesson7_2
14 {
15     public partial class WorkList : Form
16     {
17         public WorkList()
18         {
19             InitializeComponent();
20         }
21 
22         /// <summary>
23         /// 窗体加载事件
24         /// </summary>
25         /// <param name="sender"></param>
26         /// <param name="e"></param>
27         private void WorkList_Load(object sender, EventArgs e)
28         {
29             this.dgvWorkList.AutoGenerateColumns = false;
30             Ini();
31             gbWorkList.Text = se.Name;
32         }
33         public SE se;
34         public List<Job> jobs = new List<Job>();
35         /// <summary>
36         /// 初始化
37         /// </summary>
38         public void Ini()
39         {
40             
41             TestJob tj = new TestJob("编码", "编码", "实现购物车模块", 1000, 9, 5);
42             TestJob tj1 = new TestJob("编码", "编码基类", "完成项目基类", 555, 4, 3);
43             CodeJob cj = new CodeJob("测试", "压力测试", "测试自己", 5, 5, 5);
44             jobs.Add(tj);
45             jobs.Add(tj1);
46             jobs.Add(cj);
47             se = new SE("王小毛", jobs);
48             BindDgv();
49         }
50 
51         /// <summary>
52         /// 绑定dgv
53         /// </summary>
54         public void BindDgv()
55         {
56             this.dgvWorkList.DataSource = se.WorkList;
57         }
58         
59         /// <summary>
60         /// 执行按钮
61         /// </summary>
62         /// <param name="sender"></param>
63         /// <param name="e"></param>
64         private void tsmiDo_Click(object sender, EventArgs e)
65         {
66             if (dgvWorkList.SelectedRows.Count > 0)
67             {
68                 int index = dgvWorkList.CurrentRow.Index;
69                 se.WorkList[dgvWorkList.CurrentRow.Index].Execute(this, index);
70             }
71             else
72             {
73                 MessageBox.Show("请选中工作");
74             }
75         }
76 
77         /// <summary>
78         /// 显示指标完成情况
79         /// </summary>
80         /// <param name="sender"></param>
81         /// <param name="e"></param>
82         private void tsmiFinish_Click(object sender, EventArgs e)
83         {
84             if (dgvWorkList.SelectedRows.Count > 0)
85             {
86                 se.WorkList[dgvWorkList.CurrentRow.Index].Show();
87             }
88             else
89             {
90                 MessageBox.Show("请选中工作");
91             }
92         }
93     }
94 }
工作窗体

 

 

第七章.上级练习2~3