ASP.NET条形码

生成条形码:
 1  #region  asp.net的条形码
 2  public   string  bar_code( object  str,  int  ch,  int  cw,  int  type_code)
 3  {
 4       string  strTmp = str.ToString();
 5       string  code = strTmp;
 6      strTmp = strTmp.ToLower();
 7       int  height = ch;
 8        int  width = cw;
 9       strTmp = strTmp.Replace( " 0 " " _|_|__||_||_| " );
10       strTmp = strTmp.Replace( " 1 " " _||_|__|_|_|| " );
11      strTmp = strTmp.Replace( " 2 " " _|_||__|_|_|| " );
12      strTmp = strTmp.Replace( " 3 " " _||_||__|_|_| " );
13      strTmp = strTmp.Replace( " 4 " " _|_|__||_|_|| " );
14      strTmp = strTmp.Replace( " 5 " " _||_|__||_|_| " );
15      strTmp = strTmp.Replace( " 7 " " _|_|__|_||_|| " );
16      strTmp = strTmp.Replace( " 6 " " _|_||__||_|_| " );
17      strTmp = strTmp.Replace( " 8 " " _||_|__|_||_| " );
18      strTmp = strTmp.Replace( " 9 " " _|_||__|_||_| " );
19      strTmp = strTmp.Replace( " a " " _||_|_|__|_|| " );
20      strTmp = strTmp.Replace( " b " " _|_||_|__|_|| " );
21      strTmp = strTmp.Replace( " c " " _||_||_|__|_| " );
22      strTmp = strTmp.Replace( " d " " _|_|_||__|_|| " );
23      strTmp = strTmp.Replace( " e " " _||_|_||__|_| " );
24      strTmp = strTmp.Replace( " f " " _|_||_||__|_| " );
25      strTmp = strTmp.Replace( " g " " _|_|_|__||_|| " );
26      strTmp = strTmp.Replace( " h " " _||_|_|__||_| " );
27      strTmp = strTmp.Replace( " i " " _|_||_|__||_| " );
28      strTmp = strTmp.Replace( " j " " _|_|_||__||_| " );
29      strTmp = strTmp.Replace( " k " " _||_|_|_|__|| " );
30      strTmp = strTmp.Replace( " l " " _|_||_|_|__|| " );
31      strTmp = strTmp.Replace( " m " " _||_||_|_|__| " );
32      strTmp = strTmp.Replace( " n " " _|_|_||_|__|| " );
33      strTmp = strTmp.Replace( " o " " _||_|_||_|__| " );
34      strTmp = strTmp.Replace( " p " " _|_||_||_|__| " );
35      strTmp = strTmp.Replace( " r " " _||_|_|_||__| " );
36      strTmp = strTmp.Replace( " q " " _|_|_|_||__|| " );
37      strTmp = strTmp.Replace( " s " " _|_||_|_||__| " );
38      strTmp = strTmp.Replace( " t " " _|_|_||_||__| " );
39      strTmp = strTmp.Replace( " u " " _||__|_|_|_|| " );
40      strTmp = strTmp.Replace( " v " " _|__||_|_|_|| " );
41      strTmp = strTmp.Replace( " w " " _||__||_|_|_| " );
42      strTmp = strTmp.Replace( " x " " _|__|_||_|_|| " );
43      strTmp = strTmp.Replace( " y " " _||__|_||_|_| " );
44      strTmp = strTmp.Replace( " z " " _|__||_||_|_| " );
45      strTmp = strTmp.Replace( " - " " _|__|_|_||_|| " );
46      strTmp = strTmp.Replace( " * " " _|__|_||_||_| " );
47      strTmp = strTmp.Replace( " / " " _|__|__|_|__| " );
48      strTmp = strTmp.Replace( " % " " _|_|__|__|__| " );
49      strTmp = strTmp.Replace( " + " " _|__|_|__|__| " );
50      strTmp = strTmp.Replace( " . " " _||__|_|_||_| " );
51      strTmp = strTmp.Replace( " _ " " <span style='height: " + height + " ;width: " + width + " ;background:#FFFFFF;'></span> " );
52      strTmp = strTmp.Replace( " | " " <span style='height: " + height + " ;width: " + width + " ;background:#000000;'></span> " );
53       if (type_code == 1 )
54      {
55           return  strTmp + " <BR> " + code;
56      }
57       else
58      {
59           return  strTmp;
60      }
61  }
62  #endregion
63 

条形码打印:

下载这两种字体:v100010_.ttf 和 V100011_.TTF,把这种字体copy到系统字体里,在页面上这样调用

< asp:label  id ="lblBarcode"  runat ="server"  Font-Size ="XX-Large"  Height ="26px"  Width ="160px"  Font-Names ="C39HrP48DlTt" ></ asp:label

然后把值赋给lblBarcode.Text就行了 ,如:lblBarcode.Text=bar_code("978-7-302-16208-7", 100, 1, 1);

读取条形码:

直接用条型码器扫,结果就会自动保存为一个文本的方式。   
也就是说你在程序中加一个文本框,点选中这个文本框时,用条型码器扫数据,数据就可以直接录入到文本框里。
可以让页面开始就自动在某个文本框获得焦点,此时不做任何操作,直接扫描就录入到该文本框了
条形码机器其实就是个数字键盘,它处理完后,就直接将识别出的数字存储系统内存中的键盘区中
一般的条形码读取器除了读取数据外还有一个回车事件

你可能感兴趣的:(asp.net)