[C#]
public class TextBox
{
string dataSource;
string dataField;
bool active;
public string DataSource
{
get
{
return dataSource;
}
set
{
if (value != dataSource)
{
// Update active state.
SetActive(value != null && dataField != null);
dataSource = value;
}
}
}
public string DataField
{
get
{
return dataField;
}
set
{
if (value != dataField)
{
// Update active state.
SetActive(dataSource != null && dataField != null);
dataField = value;
}
}
}
void SetActive(Boolean value)
{
if (value != active)
{
if (value)
{
Activate();
Text = dataBase.Value(dataField);
}
else
{
Deactivate();
Text = "";
}
// Set active only if successful.
active = value;
}
}
void Activate()
{
// Open database.
}
void Deactivate()
{
// Close database.
}
}