Summary of integration between bargainand ASP. NET

Source: Internet
Author: User

Since the last time I posted an article on nhib.pdf, I haven't written anything for a long time. I have been busy with a project for six months. After finishing the project, I found that many things were done at the time and understood, but it will soon be blurred, so I think of the importance of summarization again ~~ There is no place for storing materials. It is also a good choice to store data in the blog garden ~~ I am also a newbie. I am not writing well. Please forgive me. If you find any errors, please note that I will change them. Thank you!

BarTender is an excellent bar code printing software, can support many types of bar code design and printing, specific you can refer to his official website (http://www.seagullscientific.com/aspx/products.aspx), here not much introduction.

I was working on SilverLight. Later, the project had a need to add the bar code design and printing functions to the system. PM proposed two solutions, one is to develop a bar code designer by yourself. The advantage is that it is easier to integrate with the system, but developing this designer is a relatively large Task; another solution is to use the customer's original BarTender software to integrate the software into the system, so the design part is still done by BarTender, and our system only needs to develop the integration part. After discussion, we decided to adopt the BarTender integration solution, so we had to find someone to do technical research and discuss it with the original Partner. He said that he would like to continue to study SilverLight in depth, I want to explore more things, so I just spoke to myself ~~

When I first came into contact with BarTender, I found that there was very little information on the Internet. I read all the information on their official website, what white papers, and guides. Our system is implemented by ASP. NET. After a period of learning, we know several integration modes of BarTender. ActiveX COM integration, Commander triggered integration, and. net sdk support after version 9.0. Let's briefly talk about these methods:

1. ActiveX COM: After BarTender is installed on your machine, a COM will be registered on the machine. You can call this COM in the program and use the methods and Attributes provided by it, program-level control of barrier. This integration method is more practical and has low requirements for the BarTender version. However, because it is a basic use of COM, you are required to be familiar with the COM interface, the calling process and details of the entire barrier are clear. For details about the COM interface, refer to Automation. chm help document (under the Seagull \ barw.suite \ barloud directory ).

2. Commander's trigger integration: In simple terms, this is to configure bargainer so that he can monitor a file. When the program generates this file, it will trigger the wake-up bargainer to print the file, I think this method is not easy to use, so I don't know much about it. You are welcome to discuss it.

3 ,.. net sdk: This is an application that is supported by version 9.0.. NET Framework SDK, which provides many classes for BarTender control, because this SDK is also used.. NET integration is very convenient, but because there are requirements for the version, you need to consider the cost of the customer to use.

I.. NET SDK

Our project was used at the beginning. net sdk, because at that time it was not clear whether the customer needs to print on the server or the client, the boss asked to start research first, this is very irritating! It took a long time to say that the customer was going to print everything he had done on the client ~~

. The. net sdk has two parts: one is standard and the other is Server. The standard is to simply enable the BarTender process to process print tasks, therefore, when multiple tasks are printed at the same time, you need to manage the task queue problem by yourself. The Server version has the task queue mechanism, it is very convenient to manage task queues and BarTender process resources. However, Server must be installed in the Enterprise version of barrack. ORZ ~~ What is money ~~

1. the SDK actually calls COM at the underlying layer, but it is encapsulated to allow developers to perform better operations. The standard SDK should look at the help documentation, and their methods and attributes. The following code represents the simplest typical use: <! -- [Endif] -->

First, add a reference. In the. net tab, you can find Seagull. barull. Print.

Then, add the namespace reference "using Seagull. barparts. Print;" to the program ;"

The simple use of the program is as follows:

// New an BarTender engine

Engine engine = new Engine (true );

// Use the engine to open a format document to return a LabelFormatDocument object

LabelFormatDocument format = engine. Documents. Open ("c: \ test. btw ");

// Use the LabelFormatDocument object to print

Format. Print ("Select printer", out messages );

After use, remember to recycle related resources.
2. For the Server version SDK, I will describe its queue management details here, but you do not need to know these things when using the SDK alone, the usage is as simple as the standard SDK. You only need to refer to the help documentation and Samples to understand it. Write out his queue management details for discussion only ~~ When you look at this part of the source code, you should first look at the thread-related knowledge. <! -- [Endif] -->

1) the core of the program process is: Put the task into the task queue. If the task queue detects that there is a task in the queue, it will throw the task to the engine management, select an idle engine to execute the task.

2) The management task queue mainly uses the BtPool class. The Consume function in this class constantly checks whether the queue is empty. If it is not empty, the task is submitted, first through the engine. status! = TaskEngineStatus. Busy to detect idle engines, and then submit the tasks to the Engine through engine. SubmitTask (this. m_masterTaskQueue.

In the SubmitTask function, we can see the sentence that pays the thrown task to the task corresponding to the current engine:

This. m_task = tasks. Dequeue ();

Then we can check the main class TaskEngine of the management engine. We can see that there is also a Consume function in it. It constantly checks whether the task corresponding to the current engine is empty, and starts to execute the task if it is not empty.

Therefore, when the SubmitTask function assigns the Task to the Task of the current engine through this. m_task = tasks. Dequeue (), the Task. Run () method of the Task is started.

In the Task. Run () method, when calling this. OnRun () according to the characteristics of polymorphism, The OnRun () method of the PrintLabelFormatTask class is called. In the OnRun () method of the PrintLabelFormatTask class, the task is sent to the printer or printed as a file.

BtPool manages task queues and engine pools. TaskEngine corresponds to an engine. TaskQueue is the queue-related operation class. TaskEngines is the class for operations related to TaskEngine.
3. You may see the web browser printing example, which is written to the client. The printing of this client is actually done on the server, but what the server does is output the printed result as a print file, and then transfer the file to the client. The client then calls the local printer through JaveScript to read the print file for printing. This requires that both the server and client have the same printer driver, and the printer driver used when the client is actually printing should be consistent with the printer driver used to generate the print file on the server. Here are some materials for this method, for your reference only: <! -- [Endif] -->

1) WebLabelPrint client Printing

// Print to a file

LabelFormat. PrintSetup. PrintToFile = true;

// Set the printer

LabelFormat. PrintSetup. PrinterName = compatibleServerPrinter;

// Set the License for the printer

LabelFormat. PrintSetup. PrintToFileLicense = Request. Form. Get (_ listPrinters. PrintLicenseUniqueID );

String tempFullPath = (string) Application ["TempFolderFullPath"];

// Set the path of the printed File

LabelFormat. PrintSetup. PrintToFileName = System. IO. Path. Combine (tempFullPath, Guid. NewGuid (). ToString () + ". prn ");

2) After setting the above items, send the task to the task queue just like printing on a normal server. When the printing is complete, call the TaskPrint_Succeeded function, which includes printTask. the PrintCode is read and sent to the local printer for printing.

3) ClientPrinting. js: The GetClientPrinters function is used on the PrintList. aspx page. The files BarTenderPrintClient. js and WebLabelPrintSample. js are used to print the client.

4) BarTenderPrintClient. the js file mainly contains some printer operations, such as obtaining the printer list, matching the printer on the server and client, obtaining the License of the printer, and sending the print code to the corresponding printer.

5) The WebLabelPrintSample. js file includes filling the Client Printer list into the DropDownList (PrintListControl. ascx) and filling the Client Printer list into the Table (Printers. aspx ). <! -- [Endif] -->
Ii. ActiveX COM

After I had read the SDK for a long time and decompiled his source code for a few weeks, the boss said that he would print it on the client ~~ In a short time, you can see that ~~ I told the boss about the printing method of the kind of students above and then sent to the client. The boss said no. It is best to communicate less with the server because their network environment is not very good ~~ Depressed ~~ With the Senior reminder, I started to study ActiveX ~~ The main idea is to create an ActiveX plug-in, install it on the client when entering the page, and then control BarTender on the client machine ~~ Since ActiveX is used, you can use the simplest COM provided by barrier ~

The main classes in COM are as follows: <! -- [Endif] -->
1) Application class: actually represents a BarTender process. When you create a new class object, a new BarTender process will appear.

2) Format class: actually represents a Format tag (BTW file). You can use Application. Formats. Open () to Open and return a Format object. This class contains printing settings, tag parameter settings, and a series of other settings, a very important class.

3) NamedSubString class: manage all SubString classes in the Tag file.

4) DataBase Class: manages all DataBase links set in the Tag file.

5) QueryPromts class: class used to manage database query parameters in tag files.

<! -- [Endif] --> since the Format class is an important class, the following describes its related attributes and Methods: <! -- [Endif] -->

1) Print method: This is the most common printing method. You can set the printed Task Name, whether to wait for the printing to complete, wait for the timeout time, and Print the output information.

2) PrintOut method: If you need to display the print Setting Dialog Box and status box during printing, you can select this method.

3) Save method: Save the changes to the Format.

4) SetNamedSubStringValue method: sets the value of a specific SubString. This method can be used to dynamically change the printed content.

5) SetPromt method: The SetNamedSubStringValue method is similar to the SetNamedSubStringValue method. However, it is set to print the prompt value. Some labels can pop up a dialog box when printing, enter the value of some variables to change the printed content. This method is to dynamically set these variables. However, it is rarely used in integration.

6) IdenticalCopiesOfLabel attribute: This attribute sets the number of identical tags to be printed during printing. The default setting is label.

7) NumberSerializedLabels attribute: This attribute is used for serialized printing. When your tag starts serialization, this attribute represents the number of printed copies. For example, if your initial serialization data is 1, if the increment value is 1 and the NumberSerializedLabels value is 5, the labels 1, 2, 3, 4, and 5 are printed.

8) Printer attribute: Specifies the Printer to be used. The default Printer is specified by the system by default.

9) PrintToFile attribute: Indicates whether to print the physical object with the printer immediately or generate a print file. <! -- [Endif] -->
Through the explanation of the above method, we can see that there are several ways to dynamically control the printed content. I used the above two methods in the project, one is to directly set the value of some variables through the SetNamedSubStringValue method, and then print them. This is suitable for a small amount of printing, because each time you call the Application and Format object for processing, therefore, it takes 100 calls to print one hundred copies, which is less efficient. However, you can flexibly set the content to be printed each time. Another method is to use serialized printing, which is more efficient, this is because he only calls the command to throw data to barriers once, and then generates printed content based on the serialization rules. However, this method lacks flexibility, only applicable to label content is a regular change of the large batch printing.

The DataBase and QueryPromts classes are also mentioned above. These two classes are used to print the connected DataBase. This is the third method I used to dynamically control the printed content. The main idea is to set the content in the tag, which corresponds to some fields of the database, and then set the query conditions to expose one or more query parameters, then, the QueryPromts class is used in the program to set these query parameters to query different database content, so as to dynamically change the printed content. Format. Databases. QueryPrompts. GetQueryPrompt () can be used to set specific query conditions, set the Value by setting the Value attribute, and print all query conditions.

The methods for dynamically controlling printed content are designed to work with Tag files and programs, but they are not flexible. In fact, they can be used for better dynamic configuration, but the boss said there was no need to give up. If a friend does not know the design of the Tag file, I have time to write an article dedicated to the design of the Tag file.

<! -- [Endif] -->

Iii. Integration

With the above introduction, you have a certain understanding of the Integration Information provided by barriers. I used ActiveX COM and printed it on the client. So I also made a pseudo ActiveX plug-in. Why is it "pseudo? It is called "pseudo" because it is not ActiveX in the traditional sense, but written in C # (regret that he didn't learn C ++ in the past ". On the production of pseudo ActiveX, there is a good tutorial on the internet, I am here to give a link to calculate (http://www.cnblogs.com/homer/archive/2005/01/04/86473.html ).

After ActiveX is deployed and determined, JavaScript is required to call ActiveX plug-in on the webpage. The following code is provided on the webpage where ActiveX is deployed:

<Object id = "BTDPrintClient" classid = "clsid: {0750A7B0-CF1E-4EAD-8C73-E0C8F6D9E890}" codebase = "CAB/BarTender_AX.cab"> </object>

Here, we also remind you that the name of the second attribute is classid, and the first character of the string set in it is clsid, which is different. I didn't pay attention to it at the time, it has been deployed for a long time.

Return to the JavaScript call. During the call, the following code is used:

PrintClient = new ActiveXObject ("BTDPrintClient. PrintClient ");

It should be well understood here, that is, to create the PrintClient object in the BTDPrintClient object. After this sentence is completed, printClient is equivalent to a PrintClient object. You can call various method attributes of PrintClient in JavaScript, so you can control the local BarTender.

Iv. Summary

To integrate things, I think you must first understand the software to be integrated. You can search for materials and official documents online, the most important thing is some help documents and API documents of the software. The basic software information is included. In addition, I also contacted the technical support of Barkley's Asia Pacific region for this integration, which also brought me a lot of help, although they only need to purchase products to provide support, however, the preliminary support is still available. You only need to tell them that you are using their trial version for integration testing and decide whether to purchase products if you want to see the effect. Haha ~~ Lure ~~

We also recommend that you do more work when creating a new item. Do some Demo to verify the idea and debug the tracing carefully. There is no way to understand one thing without doing IT. Therefore, IT is exhausted ~~ When can I get some money from God? Burn incense ~~~

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.