// option 1 output parameters
// called like
private void Validation_Click(object sender, EventArgs e)
{
string Total1, Total2;
if (ScheduleF.ValidatePropPlant(out Total1, out Total2) == false)
{
MessageBox.Show("Total" + Total1 + "should be equal to" + Total2);
}
}
public bool ValidatePropPlant(out string Total1, out string Total2)
{
bool RetVal = true;
Total1 = Total2 = string.Empty;
foreach (Control item in this.Controls)
{
ScheduleH = new SchedH();
if (curr_PropPlantEquipTextBox.Text != ScheduleH.landBuildText.Text)
{
Total1 = curr_PropPlantEquipTextBox.Text;
Total2 = ScheduleH.landBuildText.Text;
RetVal = false;
}
}
return RetVal;
}
// option 2 complex return type
// called like
public struct ReturnType
{
public bool Valid { get; set; }
public string Total1 { get; set; }
public string Total2 { get; set; }
}
private void Validation_Click(object sender, EventArgs e)
{
ReturnType RT = ScheduleF.ValidatePropPlant();
if (RT.Valid == false)
{
MessageBox.Show("Total" + RT.Total1 + "should be equal to" + RT.Total2);
}
}
public bool ValidatePropPlant()
{
ReturnType RT = new ReturnType();
RT.Valid = true;
foreach (Control item in this.Controls)
{
ScheduleH = new SchedH();
if (curr_PropPlantEquipTextBox.Text != ScheduleH.landBuildText.Text)
{
RT.Total1 = curr_PropPlantEquipTextBox.Text;
RT.Total2 = ScheduleH.landBuildText.Text;
RT.Valid = false;
}
}
return RT;
}
|