Patrick,
>Yikes, a new requirement.
>
>Each table needs columns:
>LastUpdatedBy (both domain users and web users (username in db))
>LastUpdatedDate
>
>Anyone implemented something like this, gathering user info in a business object save override?
The best place to put this code is in the data access layer where you know exactly which rows were updated. Here's what you can do:
- Create a subclass of mmDataAccessSql (if you're using SQL server, otherwise use the appropriate data access class). We'll call it myDataAccessSql
- Override the CreateDataAdapter() method of myDataAccessSql, and add code that registers your custom handler method. In your custom event handler method, update the columns with the current date time. For example:
public class myDataAccessSql : mmDataAccessSql
{
public override IDataAdapter CreateDataAdapter()
{
SqlDataAdapter DA = (SqlDataAdapter)base.CreateDataAdapter();
DA.RowUpdating += new SqlRowUpdatingEventHandler(this.RowUpdatingHandler);
return DA;
}
protected void RowUpdatingHandler(object sender, SqlRowUpdatingEventArgs e)
{
e.Row["LastUpdated"] = DateTime.Now;
}
}
- Your last step is to instantiate your custom data access class rather than the mmDataAccessSql class. To do this, you can just override the Factory.cs method CreateDataAccessSql(). For example:
public class Factory : mmFactoryDesktop
{
public override OakLeaf.MM.Main.Data.mmDataAccessSql CreateDataAccessSql()
{
return new myDataAccessSql();
}
}
Best Regards,
Kevin McNeish
Eight-Time .NET MVP
VFP and iOS Author, Speaker & Trainer
Oak Leaf Enterprises, Inc.
Chief Architect, MM Framework
http://www.oakleafsd.com