增加id输入框,用来进行多人管理。增加了一个Person类,请假和加班可以视为该类的方法。多人用Person数组表示, id-1等于数组的索引。
csharp
class Person
{
public int id;
public int days;
public void qingjia(int qjDays)
{
this.days -= qjDays;
}
public void jiaban(int jbDays)
{
this.days += jbDays;
}
}
...
Person p1=new Person();
Person p2=new Person();
Person[] arr=new Person[2];
private void InitializeComponent()
{
this.p1.id = 1;
this.p1.days = 10;
this.p2.id=2;
this.p2.days = 20;
this.arr[0] = p1;
this.arr[1] = p2;
}
请假按钮点击事件处理方法:
csharp
private void button1_Click(object sender, EventArgs e)
{
//请假
if (String.IsNullOrEmpty(this.textBox1.Text))
{
MessageBox.Show("id不能为空");
return;
}
int holiday = int.Parse(this.textBox1.Text);
int id=int.Parse(this.textBox3.Text);
if (this.arr[id - 1].days - holiday < 0)
{
MessageBox.Show("假期余额不足");
return;
}
this.arr[id - 1].qingjia(holiday);
this.label4.Text = this.arr[id - 1].days.ToString() ;
}
开头判断id是否为空,this.arr[id-1]是id对应的Person对象。
加班按钮点击事件处理方法:
csharp
private void button2_Click(object sender, EventArgs e)
{
if (String.IsNullOrEmpty(this.textBox1.Text))
{
MessageBox.Show("id不能为空");
return;
}
//加班
int jiaban=int.Parse(this.textBox2.Text);
int id = int.Parse(this.textBox3.Text);
this.arr[id-1].jiaban(jiaban);
this.label4.Text = this.arr[id-1].days.ToString();
}