我有两个按钮。一个用于登录,另一个用于注销。我需要输入名称和引脚。登录按钮有效,但退出按钮不起作用。我不确定是什么问题。
登录按钮:
public void button1_Click(object sender, EventArgs e)
{
int pin = int.Parse(textBox1.Text);
string name = textBox3.Text;
Employee Daniel = new Employee("Daniel", 5741);
if (name == "Daniel")
{
Daniel.OnSignIn(pin);
}
OnSignIn的方法
public void OnSignIn(int input_pin)
{
if (input_pin == pin)
{
this.start = DateTime.Now;
MessageBox.Show("You are logged in!");
}
else
{
Console.WriteLine("Incorrect Pin");
}
退出按钮:
public void button2_Click(object sender, EventArgs e)
{
int pin = int.Parse(textBox1.Text);
string name = textBox3.Text;
Employee Daniel = new Employee("Daniel", 5741);
if (name == "Danel")
{ Daniel.OnSignOut(pin); }
}
OnSignOut方法:
public void OnSignOut(int input_pin)
{
if (input_pin == pin)
{
this.end = DateTime.Now;
this.hours_worked = end.Subtract(this.start);
this.total_hours += this.hours_worked.Seconds;
MessageBox.Show("Logged Out! You have worked for" + this.hours_worked.Seconds + "for this session. " + "You have worked " + this.total_hours + "seconds in total.");
this.SignIn = false;
}
else
{
Console.WriteLine("Incorrect Pin");
}
答案 0 :(得分:1)
错误是什么?没有它,那很难。
无论如何,请检查您的条件是否正确:在登录中,您比较name == "Daniel"
,在 SignOut 中,您比较name == "Danel"
。