VB.net 2010 视频教程 VB.net 2010 视频教程 python基础视频教程
SQL Server 2008 视频教程 c#入门经典教程 Visual Basic从门到精通视频教程
当前位置:
首页 > Python基础教程 >
  • C#教程之用C#写经理评分系统

先写需求:

     01.显示员工信息

     02.实现项目经理给员工评分的功能

第一步:

     建立两个类,员工类和项目经理类

     定义属性和方法

    员工类:工号、年龄、姓名、人气值、项目经理年度评分、经理评价

    项目经理类:ID、年龄、姓名、性别、资历,由于经理可以给员工评分,因此还有评分的方法

先上两张图再说:

查看窗体FrmShow

 

 

评分窗体FrmJudge

 

不说了,上代码

首先是员工类

复制代码
 1 using System.Text;
 2 using System.Threading.Tasks;
 3 
 4 namespace 经理评分系统
 5 {
 6     public class SE
 7     {
 8 
 9         //员工工号
10         public int EngineerId { get; set; }
11         //员工年龄
12         public int Age { get; set; }
13         //员工性别
14         public char Sex { get; set; }
15         //员工姓名
16         public string Name { get; set; }
17         //员工人气值
18         public int PopularValue { get; set; }
19         //经理年度评分
20         public int MScore { get; set; }
21         //经理评价
22         public string Assess { get; set; }
23 
24     }
25 }
复制代码

然后是经理类

复制代码
 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 using System.Threading.Tasks;
 6 
 7 namespace 经理评分系统
 8 {
 9     class PM
10     {
11         //经理ID
12         public int MId { get; set; }
13         //经理年龄
14         public int MAge{ get; set; }
15         //经理姓名
16         public string MName { get; set; }
17         //经理性别
18         public char MSex{get; set; }
19 
20         //定义评分方法
21         public void Judge(SE se,String assess,int score)
22         {
23             se.Assess = assess;
24             se.MScore = score;
25         }
26     }
27 }
复制代码

接下来是查看窗体中的代码

复制代码
 1 using System;
 2 using System.Collections.Generic;
 3 using System.ComponentModel;
 4 using System.Data;
 5 using System.Drawing;
 6 using System.Linq;
 7 using System.Text;
 8 using System.Threading.Tasks;
 9 using System.Windows.Forms;
10 
11 namespace 经理评分系统
12 {
13     public partial class FrmShow : Form
14     {
15         //定义员工数组
16         public SE[] engineer=new SE[3];
17         public FrmShow()
18         {
19             InitializeComponent();
20             Init();    //初始化SE集合信息
21             UpdateView();
22         }
23 
24         //初始化员工信息
25         public void Init() 
26         {
27             SE s1 = new SE();
28             s1.EngineerId = 111;
29             s1.Age = 26;
30             s1.Name = "王小毛";
31             s1.Assess = "未评价";
32             s1.MScore = 0;
33             engineer[0]=s1;
34 
35             SE s2 = new SE();
36             s2.EngineerId = 112;
37             s2.Age = 22;
38             s2.Name = "周新雨";
39             s2.Assess = "未评价";
40             s2.MScore = 0;
41             engineer[1] = s2;
42 
43             SE s3 = new SE();
44            s3.EngineerId = 113;
45             s3.Age = 30;
46             s3.Name = "张烨";
47             s3.Assess = "未评价";
48             s3.MScore = 0;
49             engineer[2] = s3;
50             
51 
52         }
53 
54         //将数据绑定到listview对象的lvAssess上
55         public void UpdateView()
56         {
57             lvAssess.Items.Clear();//评价后对数据进行刷新
58             for (int i = 0; i < engineer.Length;i++ ) 
59             {
60                 ListViewItem item = new ListViewItem();
61                 //将员工信息绑定到listview中
62                 item.Text = engineer[i].EngineerId.ToString();
63                 item.SubItems.Add(engineer[i].Name);
64                 item.SubItems.Add(engineer[i].Age.ToString());
65                 item.SubItems.Add(engineer[i].MScore.ToString());
66                 item.SubItems.Add(engineer[i].Assess);
67                 this.lvAssess.Items.Add(item);
68             }
69         }
70         //双击ListView
71         private void lvAssess_DoubleClick(object sender, EventArgs e)
72         {
73             //获取当前选中的对象
74             if(this .lvAssess.SelectedItems.Count==0)
75             {
76                 return;//必须先选中一行
77             }
78             int index = 0;
79             for (int i = 0; i < engineer.Length;i++)
80             {
81                 if(engineer[i].EngineerId.ToString()==this.lvAssess.SelectedItems[0].Text.Trim())
82                 {
83                     index = i;
84                     break;
85                 }
86             }
87             //选中对象评分
88             FrmJudge frm = new FrmJudge(this,index);
89             frm.Show();
90         }
97     }
98 }
复制代码

最后是经理评分窗体中写的代码

复制代码
 1 using System;
 2 using System.Collections.Generic;
 3 using System.ComponentModel;
 4 using System.Data;
 5 using System.Drawing;
 6 using System.Linq;
 7 using System.Text;
 8 using System.Threading.Tasks;
 9 using System.Windows.Forms;
10 
11 namespace 经理评分系统
12 {
13     public partial class FrmJudge : Form
14     {
15         //保存父窗体的实例
16         public FrmShow myParent;
17         //要评价的员工对象
18         private SE se;
19 
20         //参数:父窗体的实例、被评分的员工在员工数组中的位置
21         public FrmJudge(FrmShow fparent,int index)
22         {
23             InitializeComponent();
24             this.myParent = fparent;
25             this.se = myParent.engineer[index];
26         }
27         private void FrmJudge_Load(object sender, EventArgs e)
28         {
29             //窗体加载,显示要评价的员工的姓名和得分等信息
30             this.txtName.Text = se.Name;
31             this.txtPingJia.Text = se.Assess;
32             this.txtPingFen.Text = se.MScore.ToString();
33 
34         }
35         //点击评分按钮响应事件
36         private void btnPingFen_Click(object sender, EventArgs e)
37         {
38             try
39             {
40                 PM pm = new PM();
41                 pm.Judge(se,this.txtPingJia.Text.Trim(),Int32.Parse(this.txtPingFen.Text.Trim()));
42                 //刷新主窗体
43                 this.myParent.UpdateView();
44                 this.Close();
45             }
46             catch (Exception ex)
47             {
48                 MessageBox.Show("评分失败!"+ex.ToString());
49             }
50         }
51 
52         private void btnCancel_Click(object sender, EventArgs e)
53         {
54             this.Close();
55         }
56 
57         
58     }
59 }
复制代码


相关教程