最近接了这样一个项目,要求使用c#编写经理评分系统,需求,要显示员工信息,实现项目经理给员工评分功能,今天小编分步骤给大家介绍,需要的的朋友参考下
先写需求:
01.显示员工信息
02.实现项目经理给员工评分的功能
第一步:
建立两个类,员工类和项目经理类
定义属性和方法
员工类:工号、年龄、姓名、人气值、项目经理年度评分、经理评价
项目经理类:ID、年龄、姓名、性别、资历,由于经理可以给员工评分,因此还有评分的方法
先上两张图再说:
查看窗体FrmShow
评分窗体FrmJudge
不说了,上代码
首先是员工类
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; } } }
然后是经理类
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; } } }
接下来是查看窗体中的代码
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(); } } }
最后是经理评分窗体中写的代码
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(); } } }
以上是基于C#编写经理评分系统的详解(图文)的详细内容。更多信息请关注PHP中文网其他相关文章!