.net Sdk Textfile And .xls Datasource Issues 追蹤
I am in the processing of finishing a label printing application in C# using the bartender .net SDK and have run into a major issue with getting the data to my bartender templates. I am listing the application constraints below to limit suggestions that may not work this project.
- The data passed to bartender templates needs to be in some type of human readable form (.txt, csv, .xls, etc.) so that an end user can go into a file and edit for adhock printing.
- The data needs to have headers detailing what each field is because there are 60+ fields in each datafile.
- The data fields can't be guareanteed to be in the same order or always present in every datafile
- The system is constantly in use by multiple users possibly printing the same template with different data
We initially used the default doublequoted comma text file format which worked beatifully. The problem with this approach is that the templates don't appear to actually reference the fieldnames for data binding. It seems that bartender uses the index number of the fields rather than the actual names and they names are only there to aid in creating templates. You can see this behavior if you move field 1 (invoice#) to field 2 (purchase order#) and change the header names to match. When you print a lable after the fields have been moved with the correct header names PO will show up where invoice should.
To get around this problem we started outputing all data in a .xls file. This hard binds the data to the names of each field and works perfectly. The problem with this approach is that there is no way programmatically change the .xls file used for data at print time. The data files are created on the fly from multiple databases and many users may be printing the same label (with different data) at the same time. Because of this it isn't possible to simply overwrite one file and hope that no else is going to try to read data from that file with another print request.
The only solution that I have found which may possibly work is to use a DSN as the label template database and then programmatically change the DSN connection string to the data file for each print job. I am afraid this approach is going to have lots of issues. The first one I see is that users wanting to do an adhock print will have to either log into the server and manually change the DSN to their datafile or they will have to completely change the database connection in the template. The other issue is how the DSN is going to behave being rapidly changed in the background. I fear there will be times when a label prints completely different data than what the user intends because of the disconnected nature of this approach between the actual datafiles and the templates datasource.
Is there anyway to accomplish what I am trying to do?