this is all code you will write. exactly how is up to you. if you are having trouble envisioning how this will work use each sentence as a bit of functionality and solve one piece at a time.
the parts I see are:
1. a user interface to save the data
2. a user interface to view the data
3. some logic to keep the database and file IO in sync
4. some logic to standardize naming conventions for files.
writing to the database and opening a file should be straightforward code, nothing fancy. For interface #1 (saving data) use a File Dialog box to select the file. For interface #2 use a link or button to allow the user to open the file.
I would treat the file directory similar to a database (hierachal, not relational). In that the identifier for the document shouldn't have business meaning, it should only be an identifier to relate the document to meta data in the database. (in other words, from a data POV, the document has no meaning by itself. it only has meaning when associated to the data record.) To that extent I would identify the file using a GUID, no the quote number.
hint: you should store the path to the file in the database. You quote table(s) will have a column named FileLocation, or something like that. Also by using an non-business defined naming scheme for the document you are free to refactor how the documents are stored, both IO and within the DB. (for example, the requirement may change to store revisions of all changes to the quote document. by using GUID you can change the database without needing a new naming schema for files.)
the "difficult" part is keeping the IO and database in sync. I would use the following code for that.
Code:
using(var connection = new SqlConnection(...))
using(var transaction = connection.BeginTransaction())
using(var command = connection.CreateCommand())
{
command.CommandText = "insert/update statement";
command.Paramaters.Add(...);
try
{
connection.Open();
command.ExecuteNonQuery();
File.Save(fullPathToFile);
transaction.Commit();
}
catch
{
if(File.Exists(fullPathToFile))
{
File.Delete(fullPathToFile);
}
transaction.Rollback();
throw; // this is critical to keep the stacktrace intact.
}
}
Jason Meckley
Programmer
Specialty Bakers, Inc.
faq855-7190