首页 > 代码库 > (深入.Net平台和C#编程)第七章-深入理解多态.上机练习.20170412

(深入.Net平台和C#编程)第七章-深入理解多态.上机练习.20170412

技术分享
 1 //=================父类=================//
 2 using System;
 3 using System.Collections.Generic;
 4 using System.Linq;
 5 using System.Text;
 6 using System.Threading.Tasks;
 7 
 8 namespace Sj2.Entity
 9 {
10     /// <summary>
11     ///父类 :工作类
12     /// </summary>
13     public abstract class Job
14     {
15         public string Type { get; set; }    //工作类型
16 
17         public string Name { get; set; }   //工作名称
18 
19         public string Description { get; set; }   //工作描述
20 
21         /// <summary>
22         /// 构造函数
23         /// </summary>
24         public Job(string type, string name, string description)
25         {
26             this.Name = name;
27             this.Type = type;
28             this.Description = description;
29         }
30         /// <summary>
31         /// 构造函数
32         /// </summary>
33         public Job()
34         { }
35         /// <summary>
36         /// 执行抽象方法
37         /// </summary>
38         public abstract void Execute(FrmCells na, int index);
39       
40         /// <summary>
41         /// 抽象方法
42         /// </summary>
43         public abstract void Show();
44         
45     }
46 }
View Code
技术分享
 1 //=================员工类=================//
 2 using System;
 3 using System.Collections.Generic;
 4 using System.Linq;
 5 using System.Text;
 6 using System.Threading.Tasks;
 7 
 8 namespace Sj2.Entity
 9 {
10     /// <summary>
11     /// 员工类
12     /// </summary>
13     public class SE
14     {
15         /// <summary>
16         /// 名称
17         /// </summary>
18         public string Name { get; set; }
19         public List<Job> Lei { get; set; }
20         /// <summary>
21         /// 构造函数
22         /// </summary>
23         /// <param name="name"></param>
24         public SE(string name, List<Job> lei)
25         {
26             this.Name = name;
27             this.Lei = lei;
28         }
29     }
30 }
View Code
技术分享
 1 //=================编码类=================//
 2 using System;
 3 using System.Collections.Generic;
 4 using System.Linq;
 5 using System.Text;
 6 using System.Threading.Tasks;
 7 using System.Windows.Forms;
 8 
 9 namespace Sj2.Entity
10 {
11     /// <summary>
12     /// 编码工作类
13     /// </summary>
14     public class CodeJob : Job
15     {
16         /// <summary>
17         /// 构造函数
18         /// </summary>
19         /// <param name="name"></param>
20         /// <param name="type"></param>
21         /// <param name="description"></param>
22         public CodeJob(string name, string type, string description)
23             : base(name, type, description) { }
24 
25         /// <summary>
26         /// 构造函数
27         /// </summary>
28         public CodeJob() { }
29 
30         /// <summary>
31         /// 有效编码行数
32         /// </summary>
33         public int CodingLines { get; set; }
34         /// <summary>
35         /// 目前没有解决的BUG个数
36         /// </summary>
37         public int Bugs { get; set; }
38         /// <summary>
39         /// 用时——工作日
40         /// </summary>
41         public int WorkDay { get; set; }
42 
43         /// <summary>
44         /// 实现父类Job的抽象方法Execute(),打开编码工作窗体
45         /// </summary>
46         public override void Execute(FrmCells na, int index)
47         {
48 
49             FrmTypeBianma FrmBian = new FrmTypeBianma();
50             FrmBian.na = na;
51             FrmBian.index = index;
52             FrmBian.ShowDialog();
53         }
54         /// <summary>
55         /// Show()方法
56         /// </summary>
57         public override void Show()
58         {
59             MessageBox.Show("有效编码行数:" + CodingLines + "\n遗留问题:" + Bugs + "\n工作日:" + WorkDay, "指标完成情况");
60         }
61     }
62 }
View Code
技术分享
 1 //==========测试类===============//
 2 using System;
 3 using System.Collections.Generic;
 4 using System.Linq;
 5 using System.Text;
 6 using System.Threading.Tasks;
 7 using System.Windows.Forms;
 8 
 9 namespace Sj2.Entity
10 {
11     /// <summary>
12     /// 测试工作类
13     /// </summary>
14     public class TestJob : Job
15     {
16         public TestJob(string name, string type, string description)
17             : base(name, type, description)
18         { }
19         /// <summary>
20         /// 构造函数
21         /// </summary>
22         public TestJob() { }
23 
24         //编写的用例测试个数
25         public int CaseNum { get; set; }
26         //发现的Bug
27         public int FindBugs { get; set; }
28         /// <summary>
29         ///用时 
30         /// </summary>
31         public int WorkDay { get; set; }
32 
33         /// <summary>
34         ///实现父类Job的抽象方法 Execute(),打开测试任务窗体 
35         /// </summary>
36         public override void Execute(FrmCells na, int index)
37         {
38             FrmTypeTest frmtest = new FrmTypeTest();
39             frmtest.ns = na;
40             frmtest.index = index;
41             frmtest.ShowDialog();
42         }
43         /// <summary>
44         /// Show()方法
45         /// </summary>
46         public override void Show()
47         {
48             MessageBox.Show("测试用例个数:" + CaseNum + "\n发现Bug数量:" + FindBugs + "\n工作日:" + WorkDay, "指标完成情况");
49         }
50     }
51 }
View Code
技术分享
 1 using System;
 2 using System.Collections.Generic;
 3 using System.ComponentModel;
 4 using System.Data;
 5 using System.Drawing;
 6 using System.Linq;
 7 using System.Text;
 8 using System.Threading.Tasks;
 9 using System.Windows.Forms;
10 using Sj2.Entity;
11 
12 namespace Sj2
13 {
14     public partial class FrmCells : Form
15     {
16         SE se;
17         SE se1;
18         public List<Job> list = new List<Job>();
19         public FrmCells()
20         {
21 
22             InitializeComponent();
23             Init();
24             UpdateJob();
25             this.gbCells.Text = se.Name;
26             dgvInfo.AutoGenerateColumns = false;
27         }
28 
29         /// <summary>
30         /// 初始员工工作列表
31         /// </summary>
32         public void Init()
33         {
34             list.Add(new CodeJob("编码", "编码", "实现购物车列表"));
35             list.Add(new CodeJob("编码", "编码基类", "完成项目基类编码"));
36             list.Add(new TestJob("测试", "压力测试", "测试项目已实现莫模块"));
37 
38             //初始员工信息
39             se = new SE("王小毛", list);
40             se1 = new SE("李磊", list);
41         }
42         /// <summary>
43         /// 绑定工作列表
44         /// </summary>
45         public void UpdateJob()
46         {
47             this.dgvInfo.DataSource = se.Lei;
48         }
49         /// <summary>
50         /// 执行情况
51         /// </summary>
52         /// <param name="sender"></param>
53         /// <param name="e"></param>
54         private void tmisZhiXin_Click(object sender, EventArgs e)
55         {
56             //获取当前行
57             int index = this.dgvInfo.CurrentRow.Index;
58             //打开对应窗口,填写完成指标——重写父类的抽象方法Execute()
59             se.Lei[index].Execute(this, index);
60         }
61         /// <summary>
62         /// 执行完成情况
63         /// </summary>
64         /// <param name="sender"></param>
65         /// <param name="e"></param>
66         private void tmsiWanCheng_Click(object sender, EventArgs e)
67         {
68             //CodeJob co = new CodeJob();
69             //co.Show();
70             int index = this.dgvInfo.CurrentRow.Index;
71             list[index].Show();
72         }
73     }
74 }
主窗体

技术分享

技术分享
 1 using System;
 2 using System.Collections.Generic;
 3 using System.ComponentModel;
 4 using System.Data;
 5 using System.Drawing;
 6 using System.Linq;
 7 using System.Text;
 8 using System.Threading.Tasks;
 9 using System.Windows.Forms;
10 using Sj2.Entity;
11 
12 namespace Sj2
13 {
14     public partial class FrmTypeBianma : Form
15     {
16         /// <summary>
17         /// 编码窗体
18         /// </summary>
19         public FrmTypeBianma()
20         {
21             InitializeComponent();
22         }
23         CodeJob job = new CodeJob();
24         public FrmCells na;
25         public int index;
26         /// <summary>
27         /// 提交编码工作任务
28         /// </summary>
29         /// <param name="sender"></param>
30         /// <param name="e"></param>
31         private void btnTj_Click(object sender, EventArgs e)
32         {
33             bool isError = false;
34             try
35             {
36                 var d = (CodeJob)na.list[index];
37                 d.CodingLines = Int32.Parse(this.txtHangSu.Text.ToString());
38                 d.Bugs = Int32.Parse(this.txtWenti.Text.ToString());
39                 d.WorkDay = Int32.Parse(this.txtGongzr.Text.ToString());
40             }
41             catch (Exception ex)
42             {
43                 MessageBox.Show(ex.Message);
44                 isError = true;
45             }
46             if (!isError)
47             {
48                 MessageBox.Show("提交成功!", "提示");
49                 this.Close();
50             }
51         }
52 
53 
54     }
55 }
编码窗体

技术分享

技术分享
 1 using System;
 2 using System.Collections.Generic;
 3 using System.ComponentModel;
 4 using System.Data;
 5 using System.Drawing;
 6 using System.Linq;
 7 using System.Text;
 8 using System.Threading.Tasks;
 9 using System.Windows.Forms;
10 using Sj2.Entity;
11 
12 namespace Sj2
13 {
14     public partial class FrmTypeTest : Form
15     {
16         /// <summary>
17         /// 测试窗体
18         /// </summary>
19         public FrmTypeTest()
20         {
21             InitializeComponent();
22         }
23         TestJob job = new TestJob();
24         public FrmCells ns;
25         public int index;
26         //实例化对象
27 
28         /// <summary>
29         /// 提交测试工作
30         /// </summary>
31         /// <param name="sender"></param>
32         /// <param name="e"></param>
33         private void btnTjTest_Click(object sender, EventArgs e)
34         {
35             bool isError = false;
36             try
37             {
38                 var ds = (TestJob)ns.list[index];
39                 ds.CaseNum = Int32.Parse(txtHangSuTest.Text.ToString());
40                 ds.WorkDay = Int32.Parse(txtGongzrTest.Text.ToString());
41                 ds.FindBugs = Int32.Parse(txtWentiTest.Text.ToString());
42 
43             }
44             catch (Exception ex)
45             {
46                 MessageBox.Show(ex.Message);
47                 isError = true;
48             }
49             if (!isError)
50             {
51                 MessageBox.Show("提交成功!", "提示");
52                 this.Close();
53             }
54         }
55 
56     }
57 }
测试窗体

技术分享

 

(深入.Net平台和C#编程)第七章-深入理解多态.上机练习.20170412