标签:
class PM { //定义一个经理类 public static SE[] se=new SE[50]; //评分的方法 public void pf(SE se, string pingjia, int pingfen) { se.Count = pingfen; se.PingJia = pingjia; } }
class SE { //员工类 public int Sid { get; set; } public string Name { get; set; } public int Age{ get; set; } public string PingJia{ get; set; } public int Count { get; set; } int id = 110; public SE() { } //员工的构造函数 public SE(string name,int age) { this.Sid = id++; this.Name = name; this.Age = age; this.PingJia = "未评价"; this.Count = 0; } }
ck窗体:
public partial class ck : Form { public ck() { InitializeComponent(); } private void listView1_DoubleClick(object sender, EventArgs e) { //查找到要修改的员工在数组中的位置通过构造函数传入pf窗体中 if (this.listView1.SelectedItems.Count > 0) { for (int i = 0; i < PM.se.Length; i++) { if (PM.se[i].Sid == Convert.ToInt32(listView1.SelectedItems[0].Text)) { pf pf = new pf(i,this); pf.Show(); break; } } } } private void ck_Load(object sender, EventArgs e) { //初始化员工对象 SE se1 = new SE("王小毛", 28); PM.se[0] = se1; SE se2 = new SE("周新宇", 18); PM.se[1] = se2; SE se3 = new SE("张华", 51); PM.se[2] = se3; info(); } //在listview中展示数组中的元素; public void info() { listView1.Items.Clear(); for (int i = 0; i < PM.se.Length; i++) { if (PM.se[i] == null) { break; } else { ListViewItem item = new ListViewItem(PM.se[i].Sid.ToString()); item.SubItems.Add(PM.se[i].Name); item.SubItems.Add(PM.se[i].Age.ToString()); item.SubItems.Add(PM.se[i].PingJia); item.SubItems.Add(PM.se[i].Count.ToString()); listView1.Items.Add(item); } } } }
pf窗体:
public partial class pf : Form { //定义查看Ck窗口类用于调用Ck窗体的方法实现动态更新 public ck ck; public pf() { InitializeComponent(); } public int Index { get; set; } //构造方法传递数组下标和窗体对象 public pf(int index,ck CK) { InitializeComponent(); this.Index = index; this.ck = CK; } //在打开该窗体时;把要评价的员工名字传入该窗体 private void pf_Load(object sender, EventArgs e) { txt1.Text = PM.se[Index].Name; } //点击按钮吧更改后的数据报道数组中 private void button1_Click(object sender, EventArgs e) { PM.se[Index].PingJia = txt2.Text; PM.se[Index].Count = Convert.ToInt32 (txt3.Text); ck.info(); } //退出的方法 private void button2_Click(object sender, EventArgs e) { this.Close(); } }
标签:
原文地址:http://www.cnblogs.com/www-datou-com/p/5811541.html