OPAC升级,新功能增加了个二维码,正好Mc50别的部门用完还回来了,看看二维码里到底记录了些什么东西
简单点,就放个textbox来显示:
1
private
void
barcode1_OnRead
(
object
sender,
Symbol
.
Barcode
.
ReaderData
readerData
)
2 {
3 if ( readerData . Result = = Symbol . Results . SUCCESS )
4 {
5 textBox1 . Text = readerData . Text . ToString ( ) . Trim ( ) ;
6 }
7 else
8 {
9 MessageBox . Show ( " 读取错误 " ) ;
10 }
11 }
2 {
3 if ( readerData . Result = = Symbol . Results . SUCCESS )
4 {
5 textBox1 . Text = readerData . Text . ToString ( ) . Trim ( ) ;
6 }
7 else
8 {
9 MessageBox . Show ( " 读取错误 " ) ;
10 }
11 }
运行,直接部署到设备,读条码…
结果杯具了,中文全乱码…
难道编码有问题?
在程序里添加引用System.Web,用HttpUtility转下编码试试
再次杯具了…
.Net Compact Framework压根没有System.Web这个引用…
上网google吧,找到高手反编译出的System.Web.dll
需要两个文件:
HtmlEntities.cs
HttpUtility.cs
把这两个文件包含在项目里,然后就可以引用System.Web了
1
using
System
.
Web;
2 private void barcode1_OnRead ( object sender, Symbol . Barcode . ReaderData readerData )
3 {
4 if ( readerData . Result = = Symbol . Results . SUCCESS )
5 {
6 textBox1 . Text = HttpUtility . UrlDecode ( readerData . Text, Encoding . UTF8 ) ;
7 }
8 else
9 {
10 MessageBox . Show ( " 读取错误 " ) ;
11 }
12 }
2 private void barcode1_OnRead ( object sender, Symbol . Barcode . ReaderData readerData )
3 {
4 if ( readerData . Result = = Symbol . Results . SUCCESS )
5 {
6 textBox1 . Text = HttpUtility . UrlDecode ( readerData . Text, Encoding . UTF8 ) ;
7 }
8 else
9 {
10 MessageBox . Show ( " 读取错误 " ) ;
11 }
12 }
嗯,虽然能转码了
杯具的是读取结果依旧乱码…
本文转自 sun8134 博客园博客,原文链接: http://www.cnblogs.com/sun8134/archive/2011/01/12/1933921.html ,如需转载请自行联系原作者