最近接了這樣一個項目,要求使用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中文網其他相關文章!