第七章课后作业

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了第七章课后作业相关的知识,希望对你有一定的参考价值。

技术分享
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();
        }
    }
}
编码窗体

 

以上是关于第七章课后作业的主要内容,如果未能解决你的问题,请参考以下文章

数据库原理第七章课后作业

课程作业西瓜书 机器学习课后习题 : 第七章

07《JAVA从零到壹》第七讲:面向对象高级特性(文末有课后作业)

课后作业-阅读任务-任务阅读-2

2017-2018-2 1723《程序设计与数据结构》第七周作业 总结

读构建之法第十七章有感(作业四)