Go VS2010 with Crystal Report to do barcode label printing function

Source: Internet
Author: User

This article was reproduced from: http://blog.sina.com.cn/s/blog_552ca1400100y6dd.html

Let's start with a feature:

We all know that VS2005 and VS2008 software itself contains Crystal Report plug-in, and the new version of VS2010 removed the SAP Crystal Report plug-in, want to use the Crystal Report in VS2010 first to download the SAP plug-in Crforvs_13_0.exe, I downloaded the 13 version of this.

After the download is complete, it can now be used in the VS2010, haha.

1, the preparation work, the barcode realization

Specific how to implement bar code, here no longer repeat, for details please refer to: http://www.cnblogs.com/qidian10/archive/2011/07/16/2108144.html

I'm here ready to generate the image address: http://localhost:5950/codebar.aspx?code={0}

2. Create a crystal report in VS2010

FILE-New-project-crystalrepost application

You can add information such as the necessary data sources to the wizard yourself, or create a blank report, followed by the same.
  
My new Crystal report here is named: flcodebar.rpt

  Report Database field configuration, add a table that uses a simple 5 test field (just one sentence of SQL) select top Smsite,smitno,smalsu,smpupr,smremk from Psminf

3, set the page format in the Crystal Report, 5cm*5cm

Barcode Label size is 5cm*5cm, so first set the page: Right-click report blank Area---> Settings----> Page

4, drag into the Display field, hide the report header, header, report footer, footers from the node expert, keep only the detailed information
Drag from the database field into the field you want to display in the label, layout

5, Crystal Report display pictures, barcode pictures

First right-click the blank area of the report---> Insert----> Picture (Find a picture of this machine first)

Resize the picture to fit the size

Because our barcode is dynamic, so we also want to give the picture dynamic path

Right-click picture---> Format Object---> Picture label---> clicking the button to the right of the bottom, drawing position, pop-up formula studio

We enter the following "Http://localhost:5950/CodeBar.aspx?code=" &{psminf in the edit box in the lower right corner. Smitno}

This address is our first step to achieve the address of the barcode map, the last Psminf.smitno parameter represents the field that binds the database.

Another has to mention is that the picture path here can not be written dead, because after publishing to IIS, the domain name localhost:5950 will certainly change, so here need to use parameters instead (blue box), and then the parameters are provided by the caller.

How to create parameters, see below.

6, the Crystal Report set up parameters for the program to call
In field Explorer, the message parameter field, create a new static parameter, for example, then we can successfully save the picture path in the 5th step

7, everything has, only the east wind in the Web using our Crystal Report

We need to dynamically bind the data source of the report.

Create a new Web application to copy the good data report rpt files to the appropriate directory on your Web site.

After creating the Web, you need to refer to the DLL for the Crystal Report as follows:

We dragged the Crystalreportviewer control into the Default.aspx

and set the relevant properties, remove the need to display things.

<%@ page language= "C #" autoeventwireup= "true" codebehind= "Default.aspx.cs" inherits= "webapplication1._ Default "%>
<%@ Register assembly= "Crystaldecisions.web, version=13.0.2000.0, Culture=neutral, publickeytoken= 692fbea5521e1304 "namespace=" Crystaldecisions.web "tagprefix=" CR "%>
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">


<title></title>

<body>
<form id= "Form1" runat= "Server" >
<div>
<cr:crystalreportviewer id= "CrystalReportViewer1" runat= "Server "
Autodatabind= "true" hascrystallogo= "false" hassearchbutton= "false "
hastogglegrouptreebutton= "False" toolpanelview= "None"
hastoggleparameterpanelbutton= "False"/>
</div>
</form>
</body>
  
Copy Code


8. Default.aspx page write calling method on the Web

protected void Page_Load (objectsender, EventArgs e)
{
Cj. Cj_develophelper.sqlconn_str = "Server=localhost;uid=sa;pwd=ovenjackchain;database=plmass;";
Cj. CJ_DEVELOPHELPER.SQLSTR = "Select Top ten Smsite,smitno,smalsu,smpupr,smremk from Psminf";
DataTable dt = CJ. cj_develophelper.sql_returndatetable;//getting a data source
Reportdocument rpt = newreportdocument ();
Rpt. Load (Server.MapPath ("/flcodebar.rpt"));
Rpt. Setdatasource (DT);
Parameterfields t = newParameterfields ();
Addparameter ("Plmwebip", "localhost:5950", t); Plmwebip is the name of the parameter in the report, that is, the domain of the picture, which can be flexibly set (temporary write dead)
crystalreportviewer1.parameterfieldinfo = t;//Add parameter
Crystalreportviewer1.reportsource =rpt;
}
How MSDN adds parameters to a crystal report
Private Parameterfields Addparameter (string paramname, Stringparamvalue,parameterfields Paramfields)
{
Parameterfield Paramfield = newParameterfield ();
Parameterdiscretevalue paramdiscretevalue = newParameterdiscretevalue ();
ParameterValues paramvalues = newparametervalues ();
Paramfield.parameterfieldname =paramname;
Paramdiscretevalue.value =Paramvalue;
Paramvalues.add (Paramdiscretevalue);
Paramfield.currentvalues =paramvalues;
Paramfields.add (Paramfield);
ReturnParamfields;
}
Copy Code

  

9, the review

In the case of the main use of knowledge points:

1.VS2010 Integrated Crystal Report

2. Crystal Report Page Setup

3. Crystal Report Picture settings

4. Dynamic URL settings for Crystal Report pictures

5. Crystal Report parameter settings, and program dynamic assignment, etc.

6. Dynamic Data source bindings for Crystal Reports

PS: Barcode Generated program has been uploaded to my Micro Cloud demo program

Go VS2010 with Crystal Report to do barcode label printing function

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.