首先我们先需要建立窗体文件,构建结构,首先创建两个类,员工类(SE)和经理类(PM)。
在员工类里面封装属性:
代码:
//工号
public string ID { get; set; }
//姓名
public string Name { get; set; }
//年龄
public int Age { get; set; }
//性别
public char Sex { get; set; }
//人气值
private int popularity = 0;
public int Popularity
{
get { return popularity; }
set { popularity = value; }
}
//项目经理年度评分
private int score = 0;
public int Score
{
get { return score; }
set { score = value; }
}
// 经理评价
private String assess = "未评价";
public String Assess
{
get { return assess; }
set { assess = value; }
}
项目经理和员工类一样也是封装的属性(这里就不写了)
就多了个方法
代码:
public void Judge(SE se, string assess, int score)
{
se.Assess = assess;
se.Score = score;
}
属性写完了,接下来写评分窗体(frmShow)
实现思路:
首先添加定义员工数组,将员工数组绑定到frmShow窗体的ListView控件上,在Load事件中初始化3个员工信息
代码:
public SE[] engineers = new SE[3];
#region 窗体Load事件
private void FrmShow_Load(object sender, EventArgs e)
{
frmSe();
UpdataListView();
}
#endregion
#region 初始化
private void frmSe()
{
engineers[0] = new SE();
engineers[0].ID = "111";
engineers[0].Age = 26;
engineers[0].Name = "王小毛";
engineers[0].Sex = '男';
engineers[1] = new SE();
engineers[1].ID = "112";
engineers[1].Age = 22;
engineers[1].Name = "周新雨";
engineers[1].Sex = '男';
engineers[2] = new SE();
engineers[2].ID = "113";
engineers[2].Age = 30;
engineers[2].Name = "张桦";
engineers[2].Sex = '男';
}
#endregion
#region 添加数据
public void UpdataListView()
{
lvAssess.Items.Clear(); //清空ListView里面的数据信息
for (int i = 0; i < engineers.Length; i++)
{
ListViewItem item = new ListViewItem();
item.Text = engineers[i].ID;
item.SubItems.Add(engineers[i].Name);
item.SubItems.Add(engineers[i].Age.ToString());
item.SubItems.Add(engineers[i].Assess.ToString());
item.SubItems.Add(engineers[i].Score.ToString());
lvAssess.Items.Add(item);
}
}
#endregion
接下来就写评分了,
双击ListView的事件单出评分窗口
那么这里用到了数据传递,那么这么实现呢?
代码:
#region ListView的 双击事件
private void lvAssess_DoubleClick(object sender, EventArgs e)
{
FrmJudge frm = new FrmJudge(); //调用评分窗体
frm.name = lvAssess.SelectedItems[0].SubItems[1].Text;
ListViewItem item = lvAssess.SelectedItems[0];
frm.myitem = item;
frm.Show();
}
#endregion
思路:
首先在评分窗体里面声明俩个共有的变量
public string name;
public ListViewItem myitem;
在Load的事件中给文本框赋值
#region 窗体
private void FrmJudge_Load(object sender, EventArgs e)
{
txtName.Text = name;
txtAssess.Text = myitem.SubItems[3].Text;
txtScore.Text = myitem.SubItems[4].Text;
}
#endregion
在评分完毕后的事件里面,从新给评价和年度得分赋值
#region 评分响应事件
private void btnOK_Click(object sender, EventArgs e)
{
myitem.SubItems[3].Text = txtAssess.Text;
myitem.SubItems[4].Text = txtScore.Text;
this.Close(); //关闭窗体
}
#endregion
评完分以后