I am working on a project where the concerns are divided into 3 layers (Presentation, Business Logic and Data Access). Using exception bubbling, I am able to pass exceptions from one layer to another until I can finally catch it and display a message from the Presentation Layer. However, I have no clue how to do this whenever a cell is updated in the datagridview.
//Business entity:
class Clients : Person
{
public override string FirstName
{
set
{
try
{
fc.lettersOnlyUpcaseFirstChar(ref value, false);
dal.update(this.GetType().Name, "FirstName", value, "ClientID", clientID.ToString());
}
catch (Exception)
{
throw;
}
}
}
}
//Format checking helper class:
class formatChecks
{
public void lettersOnlyUpcaseFirstChar(ref string input, bool nullable)
{
input = Regex.Replace(input, @"\s+", "");
if (input == "" && !nullable)
throw new ArgumentOutOfRangeException("Value can not be null.");
if (!input.All(Char.IsLetter))
throw new FormatException("Value may only contain letters (a-z, A-Z).");
char[] letters = input.ToLower().ToCharArray();
letters[0] = char.ToUpper(letters[0]);
string outs = new string(letters);
}
}
//Business layer helper class:
class BLHandler
{
// initialize list of Clients by using a Data Access class...
ArrClients = dal.selectAll("Clients", typeof(Clients).AssemblyQualifiedName).Cast<Clients>().ToList();
}
//The list bound to a datagridview in the presentation layer:
public frmMain()
{
dgvCustomers.DataSource = BHandler.ArrClients;
}
I know I could do the format checking in the presentation layer, but I would prefer to do it this way. Is there any way I can make this work?