第七章,SJ练习4

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

 

 1 using Lessons7_SJ2_.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 Lessons7_SJ2_
13 {
14     public partial class FrmList : Form
15     {
16         public FrmList()
17         {
18             InitializeComponent();
19         }
20         //定义员工对象
21        public   Employee empl;
22 
23         public  List<Job> j = new List<Job>();
24         /// <summary>
25         /// 点击执行按钮
26         /// </summary>
27         /// <param name="sender"></param>
28         /// <param name="e"></param>
29         private void 执行ToolStripMenuItem_Click(object sender, EventArgs e)
30         {
31             int index = this.dataGridView1.CurrentRow.Index;
32             empl.Item[index].Execute(this, index); 
33         }
34 
35         /// <summary>
36         /// 加载事件
37         /// </summary>
38         /// <param name="sender"></param>
39         /// <param name="e"></param>
40         private void FrmList_Load(object sender, EventArgs e)
41         {
42             Init();
43            groupBox1.Text= empl.Name;
44         }
45         /// <summary>
46         /// 初始值方法
47         /// </summary>
48         public void Init() 
49         {
50             
51             j.Add(new CodeJob("编码", "编码", "实现购物车模块"));
52             j.Add(new CodeJob("编码", "编码基类", "完成项目类编码"));
53             j.Add(new TestJob("测试", "压力测试", "测试项目已实现模块"));
54             empl = new SE("1120", "王小毛", 25, "", 100,j);
55             UpdateJob();
56 
57            
58         }
59         /// <summary>
60         /// 绑定数据
61         /// </summary>
62         public void UpdateJob() 
63         {
64             dataGridView1.DataSource = empl.Item;
65         }
66 
67         /// <summary>
68         /// 完成情况
69         /// </summary>
70         /// <param name="sender"></param>
71         /// <param name="e"></param>
72         private void 完成情况ToolStripMenuItem_Click(object sender, EventArgs e)
73         {
74             int index = this.dataGridView1.CurrentRow.Index;
75             empl.Item[index].show();
76         }
77     }
78 }
主窗体代码

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

 1 using Lessons7_SJ2_.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 Lessons7_SJ2_
13 {
14     public partial class FrmCeSHi : Form
15     {
16         //编码工作对象
17         TestJob job = new TestJob();
18 
19         public FrmList fr;
20 
21         public int index;
22 
23         public FrmCeSHi()
24         {
25             InitializeComponent();
26         }
27 
28         /// <summary>
29         /// 点击事件提交
30         /// </summary>
31         /// <param name="sender"></param>
32         /// <param name="e"></param>
33         private void btnTiJiao_Click(object sender, EventArgs e)
34         {
35             bool iserror = false;
36             try
37             {
38                 var taet =(TestJob) fr.j[index];
39                 taet.CaseNum = int.Parse(txtCount.Text.Trim());
40                 taet.FindBugs = Int32.Parse(txtBug.Text.Trim());
41                 taet.WorkDay = Int32.Parse(txtGonZur.Text.Trim());
42             }
43             catch (Exception es)
44             {
45                 MessageBox.Show(es.Message);
46                 iserror = true;
47             }
48             if (!iserror) 
49             {
50                 MessageBox.Show("提交成功!");
51                 this.Close();
52             }
53 
54             
55             
56         }
57 
58         /// <summary>
59         /// 点击取消
60         /// </summary>
61         /// <param name="sender"></param>
62         /// <param name="e"></param>
63         private void btnQuXiAo_Click(object sender, EventArgs e)
64         {
65             this.Close();
66         }
67 
68        
69     }
70 }
测试窗体代码

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

 1 using Lessons7_SJ2_.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 Lessons7_SJ2_
13 {
14     public partial class FrmBiangMa : Form
15     {
16        
17 
18         //传窗体
19         public FrmList fr;
20 
21         //传要修改的窗体索引
22         public int  inbex;
23 
24         public FrmBiangMa()
25         {
26             InitializeComponent();
27         }
28 
29         private void btnTiJiao_Click(object sender, EventArgs e)
30         {
31             bool iserror = false;
32             try
33             {
34                 var taet = (CodeJob)fr.j[inbex];
35 
36                 ((CodeJob)fr.j[inbex]).WorkDay = int.Parse(txtCount.Text.Trim());
37                 taet.CodingLines = Int32.Parse(txtWenTI.Text.Trim());
38                 taet.Bugs = Int32.Parse(txtGonZhuoR.Text.Trim());
39                 
40                              
41             }
42             catch (Exception es)
43             {
44                 MessageBox.Show(es.Message);
45                 iserror = true;
46             }
47             if (!iserror)
48             {
49                 MessageBox.Show("提交成功!");
50                 this.Close();
51             }
52 
53         }
54 
55         /// <summary>
56         /// 取消
57         /// </summary>
58         /// <param name="sender"></param>
59         /// <param name="e"></param>
60         private void btnQuXiao_Click(object sender, EventArgs e)
61         {
62             this.Close();
63         }
64     }
65 }
编码窗体编码

-------------------员工类(父类)-----------------------

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 using System.Threading.Tasks;
 6 
 7 namespace Lessons7_SJ2_.entity
 8 {
 9     /// <summary>
10     /// 员工类
11     /// </summary>
12     public class Employee
13     {
14         //姓名
15         public string Name { get; set; }
16         //工号
17         public string ID { get; set; }
18         //年龄
19         public int Age { get; set; }
20         //性别
21         public string Sex { get; set; }
22         //工作信息
23         public List<Job> Item { get; set; }
24         //构造函数
25         public Employee(string id, string name, int age, string sex, List<Job> item) 
26         {
27             this.ID = id;
28             this.Name = name;
29             this.Age = age;
30             this.Sex = sex;
31             this.Item = item;
32             
33         }
34         public Employee()
35         {
36         }
37 
38     }
39 }
员工类

 

------------------经理类(员工类的子类)----------------

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 using System.Threading.Tasks;
 6 
 7 namespace Lessons7_SJ2_.entity
 8 {
 9     /// <summary>
10     /// 经理类
11     /// </summary>
12     public class PM:Employee
13     {
14         //管理项目
15         public int Guangnian { get; set; }
16 
17         //构造函数
18         public PM(string id, string name, int age, string sex, int guangnian, List<Job> item)
19             : base(id, name, age, sex,item)  
20         {
21             this.Guangnian = guangnian;
22         }
23     }
24 }
经理类

 

-------------------程序员类(员工类的子类)--------------

 1 using Lessons7_SJ2_.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 Lessons7_SJ2_
 9 {
10     /// <summary>
11     /// 程序员类
12     /// </summary>
13     public class SE:Employee
14     {
15         //人气
16         public int RenQI { get; set; }
17 
18         
19 
20         //构造函数
21         public SE(string id, string name, int age, string sex, int renqi, List<Job> item)
22             : base(id, name, age, sex,item) 
23         {
24             this.RenQI = renqi;
25             
26         }
27         public SE() { }
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 Lessons7_SJ2_.entity
 8 {
 9     /// <summary>
10     /// 工作类
11     /// </summary>
12     public abstract class Job
13     {
14         //描述
15         public string Description { get; set; }
16         //工作名称
17         public string Name { get; set; }
18         //工作类型
19         public string Type { get; set; }
20         //构造函数
21         public Job(string description,string name,string type) 
22         {
23             this.Description = description;
24             this.Name = name;
25             this.Type = type;
26         }
27         
28         //构造函数
29         public Job() { }
30         
31         //执行
32         public abstract void Execute(FrmList f, int Inbex);
33 
34         public abstract void show();
35         
36       
37 
38         
39         
40     }
41 }
工作类

 

-------------------编码工作类(工作类的子类)-----------------

 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 Lessons7_SJ2_.entity
 9 {
10     /// <summary>
11     /// 编码工作类
12     /// </summary>
13     public class CodeJob:Job
14     {
15         //编写的测试用列的数
16         public int CodingLines { get; set; }
17         //发现Bugs
18         public int Bugs { get; set; }
19         //用时
20         public int WorkDay { get; set; }
21 
22          //构造函数
23         public CodeJob(string type, string name, string description)
24             : base(type, name, description) 
25         {
26             
27         }
28 
29         public CodeJob(int codingLines, int bug, int workDay) 
30         {
31             this.CodingLines = codingLines;
32             this.Bugs = bug;
33             this.WorkDay = workDay;
34 
35         }
36         public CodeJob() 
37         {
38         }
39        
40         //实现打开编码窗体
41         public override void Execute(FrmList f,int Inbex) 
42         {
43             FrmBiangMa cs = new FrmBiangMa();
44             cs.fr = f;
45             cs.inbex = Inbex;
46             cs.ShowDialog();
47         }
48         public override void show() 
49         {
50             StringBuilder st = new StringBuilder();
51             st.Append("有效编码行数:" + CodingLines);
52             st.Append("遗留问题:" + Bugs);
53             st.Append("工作日:" + WorkDay);
54             MessageBox.Show(st.ToString());
55             
56         }
57        
58     }
59 }
编码类

 

-------------------测试工作类(工作类的子类)-----------------

 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 Lessons7_SJ2_.entity
 9 {
10     /// <summary>
11     /// 测试工作类
12     /// </summary>
13     public class TestJob:Job
14     {
15         //构造函数
16         public TestJob(string type, string name, string description): base(type, name, description) 
17         {
18 
19         }
20         public TestJob() { }
21         //编写的测试用列的数
22         public int CaseNum { get; set; }
23         //发现Bugs
24         public int FindBugs { get; set; }
25         //用时
26         public int WorkDay { get; set; }
27 
28         //实现打开测试窗体
29         public override void Execute(FrmList f, int Inbex) 
30         {
31             FrmCeSHi cs = new FrmCeSHi();
32             cs.fr = f;
33             cs.index = Inbex;
34             cs.ShowDialog();
35         }
36         public override void show()
37         {
38             StringBuilder st = new StringBuilder();
39             st.Append("有效编码行数:" + CaseNum);
40             st.Append("遗留问题:" + FindBugs);
41             st.Append("工作日:" + WorkDay);
42             MessageBox.Show(st.ToString());
43             
44         }
45     }
46 }
测试类

 

posted on 2017-04-12 15:46  yjh`  阅读(138)  评论(0编辑  收藏  举报

导航