我的按鈕btnAction總是在第一個組合框cb1 textchanged事件後消失並且從不出現。當emp和tmp不同時,我想要這個按鈕可見,而當它們不是時不可見。基於選定員工的更改按鈕可見性
public class Employee
{
[Key]
public int EmployeeId { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public int Phone { get; set; }
public int? SalaryId { get; set; }
public virtual Salary Salary { get; set; }
public static bool operator ==(Employee le, Employee re)
{
if (le.FirstName != re.FirstName)
return false;
if (le.LastName != re.LastName)
return false;
if (le.Phone != re.Phone)
return false;
if (le.SalaryId != re.SalaryId)
return false;
if (le.Salary != re.Salary)
return false;
return true;
}
public static bool operator !=(Employee le, Employee re)
{
if (le.FirstName == re.FirstName)
return false;
if (le.LastName == re.LastName)
return false;
if (le.Phone == re.Phone)
return false;
if (le.SalaryId == re.SalaryId)
return false;
if (le.Salary == re.Salary)
return false;
return true;
}
}
public class Salary
{
[Key]
public int SalaryId { get; set; }
public string Name { get; set; }
public decimal? Amount { get; set; }
public static bool operator ==(Salary ls, Salary rs)
{
if (!ls.Name.Equals(rs.Name))
return false;
if (ls.Amount != rs.Amount)
return false;
return true;
}
public static bool operator !=(Salary ls, Salary rs)
{
if (ls.Name.Equals(rs.Name))
return false;
if (ls.Amount == rs.Amount)
return false;
return true;
}
}
和方法時,組合框CB1改變
public void cb1_OnTextUpdate(object sender, EventArgs e)
{
if(dataType == 1)
{
Employee tmp;
tmp = emp/*es*/;
tmp.FirstName = cb1.Text;
if (tmp == emp/*es*/)
this.btnAction.Visible = false;
if (tmp != emp/*es*/)
this.btnAction.Visible = true;
}
}