C# example
The C# example is based on a solution named Custom Label Generator.sln, which is used to create a simple web application able to handle Pierbridge Label Requests and generate custom labels accordingly. This solution can be modified to match the requirements of each project. The solution consists of following files:
- CustomLabelGenerator.aspx
- CustomLabelParameters.cs
- LogFile.cs
- Web.config
The CustomLabelGenerator.aspx.cs consists of the main logic of the custom label generator. Without any modifications the label generator will receive a request from the system, which includes the data from Pierbridge Label Request, append these to the appropriate thermal code and send back the custom label content. The label type is chosen based on the Format parameter, which is received with the label request.
Access request properties
TopThe Pierbridge Label Request data will be stored in a number of CustomLabelParameters which provide an easy access to each individual field through a property. If necessary, access to these parameters can be obtained by:
CustomLabelParameters parameters = new CustomLabelParameters(this.Request.Form);Parameters.PurchaseOrderNumber;
An exception to accessing label properties is the Field1 though to Field20 parameters. These can be obtained by using a GetField(‘fieldName’) method:.
string field = parameters.GetField("Field1");
The example below shows how a value passed in through the Pierbridge Label Request in Field1 is used as a condition to lookup a Record Key One value from Shipping Line Items table. ShipmentID and PackageID parameters are also available for CustomLabel types through Pierbridge Ship Request.
string filter = parameters.GetField("Field1"); string columnName = "Record Key One";
Required conditions or multiple return values should be added similarly to the sample below:
StringBuilder query = new StringBuilder(); query.Append("SELECT [Shipping Order Line Items].[" + columnName + "]"); query.Append("FROM [Shipping Order Line Items] "); query.Append("JOIN [Shipping Order Header] "); query.Append("ON [Shipping Order Line Items].[Shipping Order Header ID] = [Shipping Order Header].[ID] "); query.Append("WHERE [Shipping Order Header].ID = "); query.Append(filter);
Creating thermal labels
TopBased on the requested label format the required thermal label type is selected:
if (parameters.Format == ((int)CustomLabelParameters.OutputFormat.Eltron)) { label.Append("N"); ... } else if (parameters.Format == ((int)CustomLabelParameters.OutputFormat.Zebra)) { label.Append("f165"); ... } else if (parameters.Format == ((int)CustomLabelParameters.OutputFormat.Datamax)) { label.Append("~SD20"); ... } else { LogFile.WriteLogToFile("Label format is not supported by label generator"); }
Both Request and custom parameters are added to all labels using parameter properties:
label.Append("A85,240,0,4,1,1,N," + parameters.ReceiverName); label.Append("A85,270,0,4,1,1,N," + parameters.ReceiverCompany); label.Append("A85,300,0,4,1,1,N," + parameters.ReceiverAddress1); label.Append("A10,430,0,4,1,1,N," + "ADDITIONAL INFO"); label.Append("A85,430,0,4,1,1,N," + columnValue);
Multiple labels
TopIf a single custom label generator is used to produce multiple labels, these can be identified by using the available CustomLabelName parameter and configured in the Administration App Data > Reference Data > Custom Labels.
Multiple labels with a same CustomLabelName can also be added to a single thermal label by creating a number of labels one after another:
//label 1 label.Append("N"); label.Append("OD10"); label.Append("q812"); label.Append("Q1218,24"); label.Append("D15"); label.Append("ZB"); label.Append("A10,30,0,1,1,1,N," + "FROM"); label.Append("A85,30,0,1,1,1,N," + parameters.SenderName); label.Append("P1"); label.Append("N"); //label 2 label.Append("N"); label.Append("OD10"); label.Append("q812"); label.Append("Q1218,24"); label.Append("D15"); label.Append("ZB"); label.Append("A10,30,0,1,1,1,N," + "FROM"); label.Append("A85,30,0,1,1,1,N," + parameters.SenderName); label.Append("P1"); label.Append("N");
Error logging
TopThe label generator uses a log file for error logging in case any error occurs. The error messages are written in a log file. The error log path is configured in the Web.config file and should be modified to match the installation. Error messages are customizable and can be changed:
LogFile.WriteLogToFile("No Data returned with: filter: " + filter + ", column name: " + columnName + " ." + ex.Message);
- Custom Label Generator toolkit introduces the toolkit and the role of Custom Label Generators in Transtream. It also covers basic use of the toolkit.