It happens frequently. A requirement comes up that must be satisfied quickly but completely. More often than not, whatever solution I come up with needs to look nice as well. I often turn to Microsoft Excel to create quick solutions. With Visual Basic for Applications, a fantastic calculation engine, and a highly configurable user interface--plus its near complete ubiquity in the enterprise--it is hard to beat Microsoft Excel in certain situations, although I must admit that sometimes I get a little Excel-happy, just because it is so familiar to me. In mid 1990's, I wrote some of the samples for Excel in the Microsoft Solutions Development Kit, a precursor to MSDN. I worked with Peter LaForte and Tom Risso back then... smart guys. Ken Inglis taught be Excel VBA--another smart guy.
Case in point yesterday and today. My product, the 360° Project Management Competency Framework (PMCA™), supports a variety of project management frameworks, each with a scale, a set of domains (groups of competencies), competency statements, and competency descriptions. New frameworks can be created through the system and served up by the assessment platform. We are getting ready to go public with the product, so a final review of our standard competency framework was scheduled. The challenge is the framework content exists in Microsoft SQL Server and is editable via the 360° Product Manager application, which is certainly not an application I want to deploy to a bunch of desktops. The product is a hosted solution and the Product Manager application is exactly what its name implies: a management tool.
So, how to get the framework content into the hands of the reviewers without requiring that they install the Product Manager Application, allow the reviewers the ability to make changes, and then update the changes back to the content repository?
In just a matter of hours, I was able to create an Excel workbook that does the following:
- If connected to the network and if the person opening the workbook has sufficient rights, ask the content repository for a list of frameworks
- When a framework is selected, generate a worksheet for each of the major framework components in which the reviewer can make changes
- Lock the workbook for review
- Send the review workbook to the SME or copy editor
- When the review is complete, provide for a mechanism to update the changes back to the content repository
See the following two screen shots to get a sense for what the workbook looks like.
The reviewer can make changes to the content, save it, and send it back to me.
Once I receive the updated work book, I point the 360° Product Manager application at the workbook through the "Synchronize Office Framework Editor Content" tool, which does the work of reading the data from Excel and updating the content repository. See the screen shot below.
Because this tool will never be used by anybody but myself or somebody on my staff, my primary design goals were simple:
- Come up with a solution quickly that is pleasant to use and look at
- Ensure data integrity during content update
- Write as little code as possible
We use strong typed datasets as part of our data access layer so I already had components lying around that know how to talk to the framework content repository. In most other places of the application, there is very little writing of data and most of that is done through stored procedures. Rather than writing a bunch of complicated data access code outside of our DAL to get the job done, I figured I would just use the strongly typed datasets directly, as is done throughout the application.
I knew that the only unknown was regarding using transactions in a strongly typed dataset. I had read something a while back but had no reason to apply the knowledge at the time, so I was going into it a little less informed than I prefer.
Wow. Strongly typed data sets are lacking in the area of transactions. I tried a variety of approaches (none of which could take more than I few minutes--my first and third design goals are about speed of development!).
I finally came across Ryan Whitaker's TableAdapterHelper class, which does the job nicely, albeit through reflection--I wouldn't recommend this for server-side applications or other performance-sensitive applications. Here is what Ryan has to say about it:
"If you've used TableAdapters, you'll know that their ability to deal with transactions leaves a little to be desired. Little? Did I say "little"? I mean "a lot".
Sahil Malik has a good slew of advice for people wanting to use transactions with TableAdapters. Most people will probably just wrap everything up in a TransactionScope and be done with it, which is fine if you're not running a high-traffic site. In doing this, you'll run into the annoyance of the transaction being promoted to the DTC, which is an expensive bit of "bling" to tango with.
For the people that don't like the whole promotion to DTC thing, they'll probably extend their TableAdapter's partial class and add a BeginTransaction method similar to what Sahil proposes.
For me, who's looking at a bajillion TableAdapters, with quite a few of those needing to operate within the scope of a transaction, I instead choose to play the Hacky card and just set the transaction on the TableAdapter's commands through a little bit of reflection. Some may throw your hands up in the air on this. I, however, love it, as it fits my purposes like a latex glove."
I agree with Ryan on all points. For a quick hit like I was looking for, this approach suited me just fine.
Here is a snippet contain two of the update methods: UpdateScale and UpdateDomains:
Kinda hacky but it got the job done in just a few hours total development time.