PM类,几乎全是属性
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace 上机练习三
{
class PM
{
private string id; public string Id
{
get { return id; }
set { id = value; }
}
private int age; public int Age
{
get { return age; }
set { age = value; }
}
private string name; public string Name
{
get { return name; }
set { name = value; }
}
private string sex; public string Sex
{
get { return sex; }
set { sex = value; }
}
private string longevity; public string Longevity
{
get { return longevity; }
set { longevity = value; }
} public static void score(SE se,string judge,int score) {
se.Judge = judge;
se.Score = score; } //初始化 public static void IniaitlInfo()
{
SE s1 = new SE();
s1.Id = "";
s1.Name = "二狗子";
s1.Judge = "";
s1.Age = ;
s1.Score = ;
SE.se[] = s1; SE s2 = new SE();
s2.Id = "";
s2.Name = "三狗子";
s2.Judge = "";
s2.Age = ;
s2.Score = ;
SE.se[] = s2; SE s3 = new SE();
s3.Id = "";
s3.Name = "五狗子";
s3.Judge = "";
s3.Age = ;
s3.Score = ;
SE.se[] = s3;
} }
}
添加窗体上的代码
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 FrmAdd : Form
{
public FrmAdd()
{
InitializeComponent();
} public Form1 main;
private void button1_Click(object sender, EventArgs e)
{ string id = textBox1.Text.Trim();
string name = textBox2.Text.Trim();
string age = textBox3.Text.ToString().Trim();
string sex = comboBox1.Text.Trim(); SE pr = new SE(); sex = "男";
if (sex == "女") {
sex = "女";
} try
{ foreach (SE item in SE.list)
{
if (item.Id.ToString() == id)
{
MessageBox.Show("你所输入的工号已经存在!!"); return;
}
else
{
pr.Id = Convert.ToInt32(textBox1.Text);
break;
}
}
}
catch
{
MessageBox.Show("网络异常!!1");
}
finally
{
pr.Name = name;
pr.Age = Convert.ToInt32(age);
pr.Sex = sex; SE.list.Add(pr); this.Close(); main.BindGrid(SE.list);
} } private void FrmAdd_Load(object sender, EventArgs e)
{ comboBox1.Items.Add("男");
comboBox1.Items.Add("女");
} }
}
SE类中属性
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace 上机练习三
{
public class SE
{
private string id; public string Id
{
get { return id; }
set { id = value; }
}
private int age; public int Age
{
get { return age; }
set { age = value; }
}
private string name; public string Name
{
get { return name; }
set { name = value; }
}
private string sex; public string Sex
{
get { return sex; }
set { sex = value; }
}
private int score; public int Score
{
get { return score; }
set { score = value; }
} private int year; public int Year
{
get { return year; }
set { year = value; }
}
private string judge; public string Judge
{
get { return judge; }
set { judge = value; }
} public static SE[] se = new SE[]; public static int counter = ;
}
}
展示窗体的代码
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 FrmJudge()
{
InitializeComponent();
} public void FrmJudge_Load(object sender, EventArgs e)
{ if (SE.counter==)
{
PM.IniaitlInfo();
}
SE.counter++;
UpdateView(SE.se); } //绑定数据
public void UpdateView(SE[] se)
{
listView1.Items.Clear(); for (int i = ; i <se.Length; i++)
{
ListViewItem item = new ListViewItem(se[i].Id);
item.SubItems.Add(se[i].Name);
item.SubItems.Add(se[i].Age.ToString());
item.SubItems.Add(se[i].Judge);
item.SubItems.Add(se[i].Score.ToString());
listView1.Items.Add(item);
} } private void listView1_DoubleClick(object sender, EventArgs e)
{
if (this.listView1.SelectedItems.Count==)
{
return;
} string name= listView1.SelectedItems[].SubItems[].Text;
string judge = listView1.SelectedItems[].SubItems[].Text;
string score = listView1.SelectedItems[].SubItems[].Text;
string id = listView1.SelectedItems[].SubItems[].Text; ListViewItem lvlistitem = listView1.SelectedItems[]; Frm f = new Frm();
f.name = name;
f.judge = judge;
f.score = score;
f.id=id;
f.lv = lvlistitem;
f.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 Frm : Form
{
public Frm()
{
InitializeComponent();
} public ListViewItem lv;
public string name;
public string judge;
public string score;
public string id;
private void Frm_Load(object sender, EventArgs e)
{
textBox1.Text= name;
textBox2.Text= judge;
textBox3.Text = score;
} private void button1_Click(object sender, EventArgs e)
{
Stored(SE.se); } public void Stored(SE [] se) { if (textBox2.Text.Trim() == "" || textBox3.Text.Trim() == "")
{
MessageBox.Show("你的评价或者是得分还未更改!!!");
return;
} // MessageBox.Show(lv.SubItems[3].Text); for (int i = ; i < se.Length; i++)
{
if (se[i].Id==id)
{
se[i].Judge = textBox2.Text.Trim();
se[i].Name = textBox1.Text.Trim(); if (isNaN(textBox3.Text.Trim())==true)
{
se[i].Score = Convert.ToInt32(textBox3.Text.Trim());
}
else
{
MessageBox.Show("你评价的分数格式不对,请再次来评价员工分数!!!");
return;
}
lv.SubItems[].Text = textBox3.Text;
lv.SubItems[].Text = textBox2.Text;
lv.SubItems[].Text = textBox1.Text;
MessageBox.Show("评价成功!!!");
break;
}
} } public bool isNaN(string temp) { for (int i = ; i <temp.Length; i++)
{
byte tempByte = Convert.ToByte(temp[i]); //设置byte格式
if ((tempByte<) || (tempByte>)) //如果改tempByte不在范围内
{
return false;
} } return true;
} }
}
评分系统完成了,我们下回再见!!!!!!!