Detailed explanation of writing a manager scoring system based on C# (pictures and text)

黄舟
Release: 2017-03-16 11:31:36
Original
2048 people have browsed it

Recently I took on such a project, which requires using c# to write a manager rating system. The requirement is to display employee information and implement the function of project managers to rate employees. Today I will introduce to you step by step what is needed. For reference, friends

Write the requirements first:

01. Display employee information

02. Implement project managers to employees Scoring function

Step one:

Create two classes, employee class and project manager class

DefinitionProperties and methods

Employee class: job number, age, name, popularity value, project manager annual rating, manager evaluation

Project manager class: ID, age, name, Gender, seniority, since managers can rate employees, there are also ways to rate them

Let’s take a look at the two pictures first:

View form FrmShow

Rating form FrmJudge

I won’t go into details anymore, here’s the code

The first is the employee class


using System.Text;
using System.Threading.Tasks;
namespace 经理评分系统
{
  public class SE
  {

    //员工工号
    public int EngineerId { get; set; }
    //员工年龄
    public int Age { get; set; }
    //员工性别
    public char Sex { get; set; }
    //员工姓名
    public string Name { get; set; }
    //员工人气值
    public int PopularValue { get; set; }
    //经理年度评分
    public int MScore { get; set; }
    //经理评价
    public string Assess { get; set; }
  }
}
Copy after login

Then the manager class


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace 经理评分系统
{
  class PM
  {
    //经理ID
    public int MId { get; set; }
    //经理年龄
    public int MAge{ get; set; }
    //经理姓名
    public string MName { get; set; }
    //经理性别
    public char MSex{get; set; }
    //定义评分方法
    public void Judge(SE se,String assess,int score)
    {
      se.Assess = assess;
      se.MScore = score;
    }
  }
}
Copy after login

Then the code in the view form


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 经理评分系统
{
  public partial class FrmShow : Form
  {
    //定义员工数组
    public SE[] engineer=new SE[3];
    public FrmShow()
    {
      InitializeComponent();
      Init();  //初始化SE集合信息
      UpdateView();
    }
    //初始化员工信息
    public void Init() 
    {
      SE s1 = new SE();
      s1.EngineerId = 111;
      s1.Age = 26;
      s1.Name = "王小毛";
      s1.Assess = "未评价";
      s1.MScore = 0;
      engineer[0]=s1;
      SE s2 = new SE();
      s2.EngineerId = 112;
      s2.Age = 22;
      s2.Name = "周新雨";
      s2.Assess = "未评价";
      s2.MScore = 0;
      engineer[1] = s2;
      SE s3 = new SE();
      s3.EngineerId = 113;
      s3.Age = 30;
      s3.Name = "张烨";
      s3.Assess = "未评价";
      s3.MScore = 0;
      engineer[2] = s3;
    }
    //将数据绑定到listview对象的lvAssess上
    public void UpdateView()
    {
      lvAssess.Items.Clear();//评价后对数据进行刷新
      for (int i = 0; i < engineer.Length;i++ ) 
      {
        ListViewItem item = new ListViewItem();
        //将员工信息绑定到listview中
        item.Text = engineer[i].EngineerId.ToString();
        item.SubItems.Add(engineer[i].Name);
        item.SubItems.Add(engineer[i].Age.ToString());
        item.SubItems.Add(engineer[i].MScore.ToString());
        item.SubItems.Add(engineer[i].Assess);
        this.lvAssess.Items.Add(item);
      }
    }
    //双击ListView
    private void lvAssess_DoubleClick(object sender, EventArgs e)
    {
      //获取当前选中的对象
      if(this .lvAssess.SelectedItems.Count==0)
      {
        return;//必须先选中一行
      }
      int index = 0;
      for (int i = 0; i < engineer.Length;i++)
      {
        if(engineer[i].EngineerId.ToString()==this.lvAssess.SelectedItems[0].Text.Trim())
        {
          index = i;
          break;
        }
      }
      //选中对象评分
      FrmJudge frm = new FrmJudge(this,index);
      frm.Show();
    }
  }
}
Copy after login

The last is the code written in the manager’s rating form


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 经理评分系统
{
  public partial class FrmJudge : Form
  {
    //保存父窗体的实例
    public FrmShow myParent;
    //要评价的员工对象
    private SE se;
    //参数:父窗体的实例、被评分的员工在员工数组中的位置
    public FrmJudge(FrmShow fparent,int index)
    {
      InitializeComponent();
      this.myParent = fparent;
      this.se = myParent.engineer[index];
    }
    private void FrmJudge_Load(object sender, EventArgs e)
    {
      //窗体加载,显示要评价的员工的姓名和得分等信息
      this.txtName.Text = se.Name;
      this.txtPingJia.Text = se.Assess;
      this.txtPingFen.Text = se.MScore.ToString();
    }
    //点击评分按钮响应事件
    private void btnPingFen_Click(object sender, EventArgs e)
    {
      try
      {
        PM pm = new PM();
        pm.Judge(se,this.txtPingJia.Text.Trim(),Int32.Parse(this.txtPingFen.Text.Trim()));
        //刷新主窗体
        this.myParent.UpdateView();
        this.Close();
      }
      catch (Exception ex)
      {
        MessageBox.Show("评分失败!"+ex.ToString());
      }
    }
    private void btnCancel_Click(object sender, EventArgs e)
    {
      this.Close();
    }
  }
}
Copy after login

The above is the detailed content of Detailed explanation of writing a manager scoring system based on C# (pictures and text). For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!