using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace lesson7_2 { /// <summary> /// 测试工作类 /// </summary> public class TestJob:Job { public TestJob(string type, string name, string description) : base(type, name, description) { } public TestJob() { } public int CaseNum { get; set; } public int FindBugs { get; set; } public int WorkDay { get; set; } //打开测试窗体 public override void Execute(Form1 f,int index) { FrmTestExe frmtestExe = new FrmTestExe(); frmtestExe.f = f; frmtestExe.index = index; frmtestExe.ShowDialog(); } public override void Show() { MessageBox.Show("测试用例个数:" + CaseNum + "\n发现的Bug数量:" + FindBugs + "\n工作日:" + WorkDay, "指标完成情况", MessageBoxButtons.OK); } } }
工作测试类
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace lesson7_2 { //编码类 public class CodeJob:Job { public int CodingLines { get; set; } public int Bugs { get; set; } public int WorkDay { get; set; } public CodeJob() { } public CodeJob(string type, string name, string description) : base(type, name,description) { } //打开编码窗体 public override void Execute(Form1 f, int index) { FrmCodeExe frmCodeExe = new FrmCodeExe(); frmCodeExe.f = f; frmCodeExe.index = index; frmCodeExe.ShowDialog(); } public override void Show() { MessageBox.Show("有效编码行数:"+CodingLines+"\n遗留问题:"+Bugs+"\n工作日:"+WorkDay,"指标完成情况",MessageBoxButtons.OK); } } }
编码类
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace lesson7_2 { //辅助类 public class Employee { public List<Job> Worklist { get; set; } public Employee(List<Job> worklist) { this.Worklist = worklist; } } }
辅助类
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace lesson7_2 { public abstract class Job { //工作类型 public string Type { get; set; } //工作名称 public string Name{ get; set; } //描述 public string Description { get; set; } public Job(string type, string name, string description) { this.Type = type; this.Name = name; this.Description = description; } public Job() { } //执行 public abstract void Execute(Form1 f, int index); public abstract void Show(); } }
Job类
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace lesson7_2 { public partial class Form1 : Form { public Employee emps; public Form1() { InitializeComponent(); Init(); } /// <summary> /// 绑定初始值 /// </summary> public void Init() { List<Job> joblist = new List<Job>(); joblist.Add(new CodeJob("编码","编码","实现购物车模块")); joblist.Add(new CodeJob("编码", "编码基类", "完成项目基类编码")); joblist.Add(new TestJob("测试", "压力测试", "测试项目实现模块")); emps = new Employee(joblist); this.dgvlist.AutoGenerateColumns = false; this.dgvlist.DataSource = emps.Worklist; } /// <summary> /// 绑定dgv /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void tmsiExecute_Click(object sender, EventArgs e) { int index = this.dgvlist.CurrentRow.Index; emps.Worklist[index].Execute(this,index); } /// <summary> /// 显示完成情况 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void 完成情况ToolStripMenuItem_Click(object sender, EventArgs e) { int index = this.dgvlist.CurrentRow.Index; emps.Worklist[index].Show(); } } }
主窗体
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace lesson7_2 { public partial class FrmTestExe : Form { TestJob testjob = new TestJob(); public FrmTestExe() { InitializeComponent(); } public int index; public Form1 f; //显示员工工作情况 private void btninsert_Click(object sender, EventArgs e) { bool isError = false; try { ((TestJob)f.emps.Worklist[index]).FindBugs = int.Parse(txtbugcount.Text); ((TestJob)f.emps.Worklist[index]).CaseNum = int.Parse(txtcecount.Text); ((TestJob)f.emps.Worklist[index]).WorkDay = int.Parse(txtday.Text); } catch (Exception ex) { MessageBox.Show(ex.Message); isError = true; } if (!isError) { MessageBox.Show("提交成功!", "提示"); this.Close(); } } /// <summary> /// 取消 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnclear_Click(object sender, EventArgs e) { this.Close(); } } }
测试窗体
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace lesson7_2 { public partial class FrmCodeExe : Form { CodeJob job = new CodeJob(); public FrmCodeExe() { InitializeComponent(); } public int index; public Form1 f; //显示员工工作情况 private void btninsert_Click(object sender, EventArgs e) { bool isError = false; try { ((CodeJob)f.emps.Worklist[index]).Bugs =int.Parse(txtquestion.Text); ((CodeJob)f.emps.Worklist[index]).CodingLines = int.Parse(txtrows.Text); ((CodeJob)f.emps.Worklist[index]).WorkDay = int.Parse(txtdays.Text); } catch (Exception ex) { MessageBox.Show(ex.Message); isError = true; } if (!isError) { MessageBox.Show("提交成功!", "提示"); this.Close(); } } /// <summary> /// 取消 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnclear_Click(object sender, EventArgs e) { this.Close(); } } }
编码窗体
时间: 2024-10-10 18:24:36