I am working on an import assistant (C# .NET 4) between 2 MS Access databases and I need to implement a mechanism to ensure data consistency.
Example:
Import persons.
Problem:
The columns from the person tables have different column sizes.
Source Table: Address column size = 50;
Destination Table: Address column size = 30;
When we try to import a person with a Address larger than 30 chars a problem appears.
Desired solution:
When the previous problem appears a dialog needs to be shown where the user can redefine or truncate the value to correspond to the require length.
Import function looks something like this
private static void ImportPerson()
{
var sourcePerson = sourcePerson.GetObject();
if (sourcePerson == null)
return;
var person = new MyPerson();
person.Address.Value = sourcePerson.Address;
person.Company.Value = sourcePerson.Company;
person.Save();
}
I have metadata information stored in my objects witch allows me to access the column size of my destination columns.
person.Address.ColumnSize
So I can do something like this after filling business objects with the new values.
if (person.Address.ColumnSize.CompareTo(person.Address.Value.Length)) < 0
// show dialog ...
Unfortunately this means checking all the properties (Address, Company… and other) individually.
I am looking for a more generic approach where I don’t need to check every property individually.
Any ideas, suggestions, thoughts would be highly appreciated.
Presumably, the members of your class (Adress, Company, etc) are all objects of the same type, since they seem to have consistent properties that you’re using for metadata. Add a method to your
MyPersonclass to provide access to its properties by iterating, e.g.Then
It would probably also make sense to collect all the failures in a list and just show a single dialog for the record, to make life easier for the user.