(深入.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 }

 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 }

 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 }

 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 }

 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 }

测试窗体

时间: 2024-08-26 09:22:14

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

第七章 深入理解多态

1.里氏替换原则: 在一个软件系统中,如果子类能替代父类出现的位置,而对整个软件的功能没有任何影响,那么就称为里氏替换原则 2.实现面向对象的多态性有哪几种方法? 总共有3种, 第一种,虚方法实现多态,  第二种:抽象方法实现多态  第三种:接口实现多态 目前为止,我们学了两种: 第一种:虚方法实现多态 通过在普通类Person中用Virtual关键字定义虚方法SayHello(),然后在子类Student中通过override关键字对父类的SayHello()方法进行重写. 第二种:抽象方法实

转自邓凡平 《深入理解Android:Wi-Fi,NFC和GPS》章节连载[节选]--第七章 深入理解Wi-Fi P2P部分节选

本章主要内容: 介绍Wi-Fi P2P相关知识: 介绍Android中WifiP2pService.wpa_supplicant的相关代码. 7.1  概述 承接第6章介绍的WSC,本章将继续介绍Wi-Fi Alliance(Wi-Fi联盟)推出的另外一项重要技术规范Wi-Fi P2P.该规范的商品名为Wi-Fi Direct,它支持多个Wi-Fi设备在没有AP的情况下相互连接. 在Android平台的Wi-Fi相关模块中,P2P的功能点主要集中在: Android Framework中的Wif

[深入理解Android卷一全文-第七章]深入理解Audio系统

由于<深入理解Android 卷一>和<深入理解Android卷二>不再出版,而知识的传播不应该由于纸质媒介的问题而中断,所以我将在CSDN博客中全文转发这两本书的全部内容. 第7章  深入理解Audio系统 本章主要内容 ·  具体分析AudioTrack. ·  具体分析AudioFlinger. ·  具体分析AudioPolicyService. 本章涉及的源代码文件名称及位置 以下是本章分析的源代码文件名称及其位置. ·  AudioTrack.java framewor

[深入理解Android卷二 全文-第七章]深入理解ContentProvider

由于<深入理解Android 卷一>和<深入理解Android卷二>不再出版,而知识的传播不应该因为纸质媒介的问题而中断,所以我将在CSDN博客中全文转发这两本书的全部内容 第7章  深入理解ContentProvider 本章主要内容: ·  深入分析ContentProvider的创建和启动,以及SQLite相关的知识点 ·  深入分析Cursor query和close函数的实现 ·  深入分析ContentResolver openAssetFileDescriptor函数

java面向对象编程— —第七章 继承

7.1继承的起源 继承(Inheritance),即在面向对象编程中,可以通过扩展(extends)一个已有的类,并继承该类的属性的行为,来创建一个新的类. 已有的类称为父类(也可以称为基类,超类),而新类称为子类(也可以称为派生类). 继承的优点:代码的可重用性:父类的属性和方法可用于子类:子类可以扩展父类的属性和方法:设计应用程序变得更加简单. 7.2 继承的使用原则 观察要使用的类,确定它们之间共同的和特有的属性和行为,将这些共性数据迁移到父类里,便于子类中进行方法和属性的重用. 对于不同

(深入.Net平台和C#编程)第六章.上机练习2.20170410

----------父类---------- 1 using Lesson6.上机练习2.enums; 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 9 { 10 /// <summary> 11 /// 父类 12 /// </

S2T40.(深入.Net平台和C#编程)第四章.简答题4.刁汉生.20170406

1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 using System.Threading.Tasks; 6 7 namespace 简答题.Entity 8 { 9 /// <summary> 10 /// 蚂蚁类 11 /// </summary> 12 public class Ant 13 { 14 //蚂蚁名字 15 publi

S2T40.(深入.Net平台和C#编程)第四章.简答题5.刁汉生.20170406

1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 using System.Threading.Tasks; 6 7 namespace 简答题5.Entity 8 { 9 /// <summary> 10 /// 巫师类 11 /// </summary> 12 public class Wizard 13 { 14 /// <sum

S2T40.(深入.Net平台和C#编程)第四章.简答题4.李向阳.20170406

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 KeHouZuYe.entity 9 { 10 /// <summary> 11 /// 蚂蚁类 12 /// </summary&