博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
深入.NET平台和C#编程.第七章:深入理解多态-上机练习2-3
阅读量:6599 次
发布时间:2019-06-24

本文共 9763 字,大约阅读时间需要 32 分钟。

--------------------------------------------Job类--------------------------------------------

1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 using System.Threading.Tasks; 6  7 namespace Ygzxgzlb 8 { 9     /// 10     /// 父类:工作类11     /// 12     public abstract class Job13     {14         //工作类型15         public string Type { get; set; }16 17         //工作名称18         public string Name { get; set; }19 20         //描述21         public string Description { get; set; }22 23         //构造函数24         public Job(string type, string name, string description)25         {26             this.Type = type;27             this.Name = name;28             this.Description = description;29         }30 31         //方法32         public Job() { }33 34         //执行35         public abstract void Execute();36 37         //执行38         public abstract void show();39     }40 }
Job

--------------------------------------------TestJob类----------------------------------------

1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 using System.Threading.Tasks; 6 using System.Windows.Forms; 7  8 namespace Ygzxgzlb 9 {10     /// 11     /// 测试工作类12     /// 13     public class TestJob:Job14     {15         //编写的测试用例个数16         public int CaseNum { get; set; }17 18         //发现的Bugs19         public int FindBugs { get; set; }20 21         //用时22         public int WorkDay{ get; set; }23 24         //构造函数25         public TestJob(string type , string name , string desc):base(type,name,desc)26         {27         }28 29         //方法重写30         public TestJob() { }31 32         //实现父类Job的抽象方法Execute(),打开测试任务窗体33         public override void Execute()34         {35             formTestExe te = new formTestExe(this);36             te.ShowDialog();37         }38 39         //方法重写40         public override void show()41         {42             MessageBox.Show("测试用例个数:" + CaseNum + "\n" + "发现的Bug数量:" + FindBugs + "\n" + "工作日:" + WorkDay, "指标完成情况", MessageBoxButtons.OK);43         }44 45     }46 }
TestJob

--------------------------------------------CodeJob类---------------------------------------

1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 using System.Threading.Tasks; 6 using System.Windows.Forms; 7  8 namespace Ygzxgzlb 9 {10     /// 11     /// 编码工作类12     /// 13     public class CodeJob:Job14     {15         //有效编码行数16         public int CodingLines { get; set; }17 18         //目前没有解决的Bug个数19         public int Bug { get; set; }20 21         //用时-工作日22         public int WorkDay { get; set; }23 24          //构造函数25         public CodeJob(string type, string name, string description)26         {27             this.Type = type;28             this.Name = name;29             this.Description = description;30         }31 32         //方法重写33         public CodeJob() { }34 35         //实现父类Job的抽象方法Execute(),打开编码工作窗体36         public override void Execute()37         {38             formCodeExe ce = new formCodeExe(this);39             ce.ShowDialog();40         }41 42         //方法重写43         public override void show()44         {45             MessageBox.Show("有效编码行数:" + CodingLines + "\n" + "遗留问题:" + Bug + "\n" + "工作日:" + WorkDay, "指标完成情况", MessageBoxButtons.OK);46         }47 48     }49 }
CodeJob

--------------------------------------------Employee类--------------------------------------

1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 using System.Threading.Tasks; 6  7 namespace Ygzxgzlb 8 { 9     /// 10     /// 员工类11     /// 12     public  class Employee13     {14         //姓名15         public string Name { get; set; }16 17         //年龄18         public int Age { get; set; }19 20         //工号21         public string Gh { get; set; }22 23         //泛型集合24         public List
WorkList { get; set; }25 26 //构造函数27 public Employee(string name , int age , string gh , List
list )28 {29 this.Name = name;30 this.Gh = gh;31 this.Age = age;32 this.WorkList = list;33 }34 35 //方法重写36 public Employee() { }37 }38 }
Employee

--------------------------------------------formMyOffice主窗体-------------------------------

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 11 namespace Ygzxgzlb12 {13     public partial class formMyOffice : Form14     {15         /// 16         /// 主窗体17         /// 18         public formMyOffice()19         {20             InitializeComponent();21         }22 23         //定义员工对象24         Employee empl;25 26         //窗口加载27         private void formMyOffice_Load(object sender, EventArgs e)28         {29             Init();30             UpdateJob();31             this.groupBox1.Text = empl.Name;32         }33 34         /// 35         ///初始化某员工工作列表36         /// 37         public void Init()38         {39             List
joblist = new List
();40 joblist.Add(new CodeJob("编码", "编码", "实现购物车模块"));41 joblist.Add(new CodeJob("编码", "编码基类", "完成项目基类编码"));42 joblist.Add(new TestJob("测试", "压力测试", "测试项目已实现模块"));43 //实例化员工对象44 empl = new Employee("王小毛", 18, "10000", joblist);45 }46 47 //绑定工作列表48 public void UpdateJob()49 {50 this.dataGridView1.DataSource = empl.WorkList;51 }52 53 ///
54 /// 填写执行情况55 /// 56 ///
57 ///
58 private void 执行ToolStripMenuItem_Click(object sender, EventArgs e)59 {60 int index = this.dataGridView1.CurrentRow.Index;61 //打开对应窗口,填写完成指标-重写父类的抽象方法Execute()62 empl.WorkList[index].Execute();63 }64 65 ///
66 /// 完成情况67 /// 68 ///
69 ///
70 private void 完成情况ToolStripMenuItem_Click(object sender, EventArgs e)71 {72 int index = this.dataGridView1.CurrentRow.Index;73 empl.WorkList[index].show();74 }75 }76 }
formMyOffice

--------------------------------------------formTestExe测试窗体------------------------------

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 11 namespace Ygzxgzlb12 {13     /// 14     /// 测试窗口15     /// 16     public partial class formTestExe : Form17     {18         //测试工作对象19         TestJob job;20         public formTestExe(TestJob tj)21         {22             InitializeComponent();23             this.job = tj;24         }25 26         /// 27         /// 提交测试工作28         /// 29         /// 30         /// 31         private void button1_Click(object sender, EventArgs e)32         {33             bool isError = false;34 35             try36             {37                 job.CaseNum = int.Parse(this.txtcsgs.Text.ToString());38                 job.FindBugs = int.Parse(this.txtfxgs.Text.ToString());39                 job.WorkDay = int.Parse(this.txtgzr.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         /// 56         /// 57         /// 58         private void button2_Click(object sender, EventArgs e)59         {60             this.Close();61         }62     }63 }
formTestExe

--------------------------------------------formCodeExe编码窗体-----------------------------

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 11 namespace Ygzxgzlb12 {13     /// 14     /// 编码窗口15     /// 16     public partial class formCodeExe : Form17     {18         //编码工作对象19         CodeJob job;20         public formCodeExe(CodeJob cj)21         {22             InitializeComponent();23             this.job = cj;24         }25 26         /// 27         /// 提交编码工作28         /// 29         /// 30         /// 31         private void button1_Click(object sender, EventArgs e)32         {33             bool isError = false;34 35             try36             {37                 job.CodingLines = int.Parse(this.txtbmhs.Text.ToString());38                 job.Bug = int.Parse(this.txtwt.Text.ToString());39                 job.WorkDay = int.Parse(this.txtgzr.Text.ToString());40             }41             catch (Exception ex)42             {43 44                 MessageBox.Show(ex.Message);45                 isError = true;46             }47             if (!isError)48             {49                 MessageBox.Show("提交成功","提示");50                 this.Close();51             }52         }53 54         /// 55         /// 取消编码工作56         /// 57         /// 58         /// 59         private void button2_Click(object sender, EventArgs e)60         {61             this.Close();62         }63 64     }65 }
formCodeExe

--------------------------------------------运行结果-------------------------------------------

转载于:https://www.cnblogs.com/chenhui666/p/6700957.html

你可能感兴趣的文章
IOS上路_09-简单示例-视图管理
查看>>
android 工程实践中一些问题记录
查看>>
怎样治疗<a>标签不能触发onblur事件
查看>>
5.简单的输入
查看>>
multipart/form-data和application/x-www-form-urlenco
查看>>
VSCode配置python虚拟环境
查看>>
Zookeeper系列——通信模型
查看>>
IOS--GCD多线程分析
查看>>
用 Swift 实现通知推送的新手指南
查看>>
jQuery.data()为元素保存数据(性能上不错)
查看>>
eureka 高可用配置 unavailable-replicas 问题.
查看>>
android中Calendar与Date的区别 转自网络
查看>>
java异常体系---不要在finally块中使用return、throw
查看>>
Java NIO使用及原理分析 (四)
查看>>
表关联查询
查看>>
AJAX 数据库实例
查看>>
html 页面跳转 返回上一页 history 和 location
查看>>
Java 并发工具包 java.util.concurrent 用户指南
查看>>
Python小练习:猜数字
查看>>
windows下如何成功安装python scrapy
查看>>