[条形码] BarCodeToHTML条码生成类 (转载)
过多的我就不多说了大家直接看代码吧,这是一个帮助大家生成条码的类,大小大家可以自由的设定
/// <summary>
/// 类说明:条码生成类
/// 编 码 人:苏飞
/// 联系方式:361983679
/// 更新网站:[url=http://www.cckan.net/thread-655-1-1.html]http://www.cckan.net/thread-655-1-1.html[/url]
/// </summary>
using System.Collections;
using System.Text.RegularExpressions; public class BarCodeToHTML
{
public static string get39(string s, int width, int height)
{
Hashtable ht = new Hashtable(); #region 39码 12位
ht.Add('A', "");
ht.Add('B', "");
ht.Add('C', "");
ht.Add('D', "");
ht.Add('E', "");
ht.Add('F', "");
ht.Add('G', "");
ht.Add('H', "");
ht.Add('I', "");
ht.Add('J', "");
ht.Add('K', "");
ht.Add('L', "");
ht.Add('M', "");
ht.Add('N', "");
ht.Add('O', "");
ht.Add('P', "");
ht.Add('Q', "");
ht.Add('R', "");
ht.Add('S', "");
ht.Add('T', "");
ht.Add('U', "");
ht.Add('V', "");
ht.Add('W', "");
ht.Add('X', "");
ht.Add('Y', "");
ht.Add('Z', "");
ht.Add('', "");
ht.Add('', "");
ht.Add('', "");
ht.Add('', "");
ht.Add('', "");
ht.Add('', "");
ht.Add('', "");
ht.Add('', "");
ht.Add('', "");
ht.Add('', "");
ht.Add('+', "");
ht.Add('-', "");
ht.Add('*', "");
ht.Add('/', "");
ht.Add('%', "");
ht.Add('$', "");
ht.Add('.', "");
ht.Add(' ', "");
#endregion #region 39码 9位
//ht.Add('0', "000110100");
//ht.Add('1', "100100001");
//ht.Add('2', "001100001");
//ht.Add('3', "101100000");
//ht.Add('4', "000110001");
//ht.Add('5', "100110000");
//ht.Add('6', "001110000");
//ht.Add('7', "000100101");
//ht.Add('8', "100100100");
//ht.Add('9', "001100100");
//ht.Add('A', "100001001");
//ht.Add('B', "001001001");
//ht.Add('C', "101001000");
//ht.Add('D', "000011001");
//ht.Add('E', "100011000");
//ht.Add('F', "001011000");
//ht.Add('G', "000001101");
//ht.Add('H', "100001100");
//ht.Add('I', "001001100");
//ht.Add('J', "000011100");
//ht.Add('K', "100000011");
//ht.Add('L', "001000011");
//ht.Add('M', "101000010");
//ht.Add('N', "000010011");
//ht.Add('O', "100010010");
//ht.Add('P', "001010010");
//ht.Add('Q', "000000111");
//ht.Add('R', "100000110");
//ht.Add('S', "001000110");
//ht.Add('T', "000010110");
//ht.Add('U', "110000001");
//ht.Add('V', "011000001");
//ht.Add('W', "111000000");
//ht.Add('X', "010010001");
//ht.Add('Y', "110010000");
//ht.Add('Z', "011010000");
//ht.Add('-', "010000101");
//ht.Add('.', "110000100");
//ht.Add(' ', "011000100");
//ht.Add('*', "010010100");
//ht.Add('$', "010101000");
//ht.Add('/', "010100010");
//ht.Add('+', "010001010");
//ht.Add('%', "000101010");
#endregion s = "*" + s.ToUpper() + "*"; string result_bin = "";//二进制串 try
{
foreach (char ch in s)
{
result_bin += ht[ch].ToString();
result_bin += "";//间隔,与一个单位的线条宽度相等
}
}
catch { return "存在不允许的字符!"; } string result_html = ""; //HTML代码
string color = ""; //颜色
foreach (char c in result_bin)
{
color = c == '' ? "#FFFFFF" : "#000000";
result_html += "<div style=\"width:" + width + "px;height:" + height + "px;float:left;background:" + color + ";\"></div>";
}
result_html += "<div style=\"clear:both\"></div>"; int len = ht['*'].ToString().Length;
foreach (char c in s)
{
result_html += "<div style=\"width:" + (width * (len + )) + "px;float:left;color:#000000;text-align:center;\">" + c + "</div>";
}
result_html += "<div style=\"clear:both\"></div>"; return "<div style=\"background:#FFFFFF;padding:5px;font-size:" + (width * ) + "px;font-family:'楷体';\">" + result_html + "</div>";
} public static string getEAN13(string s, int width, int height)
{
int checkcode_input = -;//输入的校验码
if (!Regex.IsMatch(s, @"^\d{12}$"))
{
if (!Regex.IsMatch(s, @"^\d{13}$"))
{
return "存在不允许的字符!";
}
else
{
checkcode_input = int.Parse(s[].ToString());
s = s.Substring(, );
}
} int sum_even = ;//偶数位之和
int sum_odd = ; //奇数位之和 for (int i = ; i < ; i++)
{
if (i % == )
{
sum_odd += int.Parse(s.ToString());
}
else
{
sum_even += int.Parse(s.ToString());
}
} int checkcode = ( - (sum_even * + sum_odd) % ) % ;//校验码 if (checkcode_input > && checkcode_input != checkcode)
{
return "输入的校验码错误!";
} s += checkcode;//变成13位 // 000000000101左侧42个01010右侧35个校验7个101000000000
// 6 101左侧6位 01010右侧5位校验1位101000000000 string result_bin = "";//二进制串
result_bin += ""; string type = ean13type(s[]);
for (int i = ; i < ; i++)
{
result_bin += ean13(s, type[i - ]);
}
result_bin += "";
for (int i = ; i < ; i++)
{
result_bin += ean13(s, 'C');
}
result_bin += ""; string result_html = ""; //HTML代码
string color = ""; //颜色
int height_bottom = width * ;
foreach (char c in result_bin)
{
color = c == '' ? "#FFFFFF" : "#000000";
result_html += "<div style=\"width:" + width + "px;height:" + height + "px;float:left;background:" + color + ";\"></div>";
}
result_html += "<div style=\"clear:both\"></div>"; result_html += "<div style=\"float:left;color:#000000;width:" + (width * ) + "px;text-align:center;\">" + s[] + "</div>";
result_html += "<div style=\"float:left;width:" + width + "px;height:" + height_bottom + "px;background:#000000;\"></div>";
result_html += "<div style=\"float:left;width:" + width + "px;height:" + height_bottom + "px;background:#FFFFFF;\"></div>";
result_html += "<div style=\"float:left;width:" + width + "px;height:" + height_bottom + "px;background:#000000;\"></div>";
for (int i = ; i < ; i++)
{
result_html += "<div style=\"float:left;width:" + (width * ) + "px;color:#000000;text-align:center;\">" + s + "</div>";
}
result_html += "<div style=\"float:left;width:" + width + "px;height:" + height_bottom + "px;background:#FFFFFF;\"></div>";
result_html += "<div style=\"float:left;width:" + width + "px;height:" + height_bottom + "px;background:#000000;\"></div>";
result_html += "<div style=\"float:left;width:" + width + "px;height:" + height_bottom + "px;background:#FFFFFF;\"></div>";
result_html += "<div style=\"float:left;width:" + width + "px;height:" + height_bottom + "px;background:#000000;\"></div>";
result_html += "<div style=\"float:left;width:" + width + "px;height:" + height_bottom + "px;background:#FFFFFF;\"></div>";
for (int i = ; i < ; i++)
{
result_html += "<div style=\"float:left;width:" + (width * ) + "px;color:#000000;text-align:center;\">" + s + "</div>";
}
result_html += "<div style=\"float:left;width:" + width + "px;height:" + height_bottom + "px;background:#000000;\"></div>";
result_html += "<div style=\"float:left;width:" + width + "px;height:" + height_bottom + "px;background:#FFFFFF;\"></div>";
result_html += "<div style=\"float:left;width:" + width + "px;height:" + height_bottom + "px;background:#000000;\"></div>";
result_html += "<div style=\"float:left;color:#000000;width:" + (width * ) + "px;\"></div>";
result_html += "<div style=\"clear:both\"></div>"; return "<div style=\"background:#FFFFFF;padding:0px;font-size:" + (width * ) + "px;font-family:'楷体';\">" + result_html + "</div>";
} private static string ean13(char c, char type)
{
switch (type)
{
case 'A':
{
switch (c)
{
case '': return "";
case '': return "";
case '': return "";
case '': return "";//
case '': return "";
case '': return "";
case '': return "";
case '': return "";
case '': return "";
case '': return "";
default: return "Error!";
}
}
case 'B':
{
switch (c)
{
case '': return "";
case '': return "";
case '': return "";
case '': return "";
case '': return "";
case '': return "";
case '': return "";//
case '': return "";
case '': return "";
case '': return "";
default: return "Error!";
}
}
case 'C':
{
switch (c)
{
case '': return "";
case '': return "";
case '': return "";
case '': return "";
case '': return "";
case '': return "";
case '': return "";
case '': return "";
case '': return "";
case '': return "";
default: return "Error!";
}
}
default: return "Error!";
}
} private static string ean13type(char c)
{
switch (c)
{
case '': return "AAAAAA";
case '': return "AABABB";
case '': return "AABBAB";
case '': return "AABBBA";
case '': return "ABAABB";
case '': return "ABBAAB";
case '': return "ABBBAA";//中国
case '': return "ABABAB";
case '': return "ABABBA";
case '': return "ABBABA";
default: return "Error!";
}
}
}
使用方法
Response.Write( BarCodeToHTML.get39("cckan",,));
[条形码] BarCodeToHTML条码生成类 (转载)的更多相关文章
- C# BarCodeToHTML条码生成类
来自:http://www.sufeinet.com/forum.php?mod=viewthread&tid=656&extra=page%3D1%26filter%3Dtypeid ...
- C# 条码生成类
using System.Collections; using System.Text.RegularExpressions; namespace DotNet.Utilities { public ...
- Language Guide (proto3) | proto3 语言指南(十五)生成类
Generating Your Classes - 生成类 要生成Java.Python.C++.Go.Ruby.ObjuleC或C代码,需要使用.proto文件中定义的消息类型,还需要在.proto ...
- dagger2系列之生成类实例
上一节的最后,我讲到一次注入生成类实例的生成步骤.先来回顾一下: 1 Module中存在创建方法,则看此创建方法有没有参数 如果有参数,这些参数也是由Component提供的,返回步骤1逐一生成参数 ...
- 将Eclipse中现有的java类生成类图
需求:将Eclipse中现有的java类生成类图 一:什么是ModelGoon? 它是一个Eclipse插件,用于基于UML图的模型设计,以及逆向工程(即从已有源代码生成类图). 二:安装 下载Mod ...
- 用Enterprise Architect从源码自动生成类图
http://blog.csdn.net/zhouyong0/article/details/8281192 /*references:感谢资源分享者.info:简单记录如何通过工具从源码生成类图,便 ...
- Java 编程 订单、支付、退款、发货、退货等编号主动生成类
订单.支付.退款.发货.退货等编号主动生成类 在商城网站中,订单编号的自动生成,ERP中各个单据的编号自动生成,都可以按照一下的方式来自动生成. 第一步:定义常量订单编号前缀.订单编号起始数.订单编号 ...
- 【原】如何获取Java动态生成类?
写作目的:Java大部分框架,如Spring,Hibernate等都会利用动态代理在程序运行的时候生成新的类, 有的时候为了学习,或者深入了解动态代理,想查看动态生成类的源代码究竟长怎么个样子, 通过 ...
- IDEA设置生成类基本注释信息
在eclipse中我们按一下快捷键就会生成类的基本信息相关的注释,其实在IDEA中也是可以的,需要我们手动设置,之后再创建类的时候就会自动加上这些基本的信息. File-->Setting 在E ...
随机推荐
- Learing WCF Chapter1 Fundamental WCF Concepts
At its core,WCF is a development platform for service-oriented applications. As I mentioned earlier, ...
- 使用GDI+轻松创建缩略图
Gdi+ 还是相当好用的. 1> Image保存图像,需要一个CLSID的参数,它可以这样获得: int GetEncoderClsid(const WCHAR* format, ...
- 【转】virtualbox 4.08安装虚机Ubuntu11.04增强功能失败解决方法
原文网址:http://fuliang.iteye.com/blog/1102998 在笔记本安装Ubuntu11.04增强功能失败 引用 fuliang@fuliang-VirtualBox:~$ ...
- 【转】qtp安装时问题
1.安装qtp后要重启机器. 2.插件选择错误, 处理方式:重新启动QTP,勾选 WEB插件; 3.在安装QTP后,或者禁用IE浏览器里的一些ActiveX控件后,正常录制QTP时,对象识别不了;(保 ...
- 《C语言程序设计现代方法》第1章 C语言概述
C语言的特点:C语言是一种底层语言.C语言是一种小型语言.C语言是一种包容性语言. C语言的优点:高效.可移植.功能强大.灵活.标准库.与UNIX系统集成. C语言的缺点:C程序更容易隐藏错误.C程序 ...
- Python手动构造Cookie模拟登录后获取网站页面内容
最近有个好友让我帮忙爬取个小说,这个小说是前三十章直接可读,后面章节需要充值VIP可见.所以就需要利用VIP账户登录后,构造Cookie,再用Python的获取每章节的url,得到内容后再使用 PyQ ...
- Web---创建Servlet的3种方式、简单的用户注册功能
说明: 创建Servlet的方式,在上篇博客中,已经用了方式1(实现Servlet接口),接下来本节讲的是另外2种方式. 上篇博客地址:http://blog.csdn.net/qq_26525215 ...
- 一步一步写一个简单通用的makefile(四)--写一个通用的makefile编译android可执行文件
通常要把我们自己的的代码编译成在android里面编译的可执行文件,我们通常是建一个文件夹 . ├── Android.mk ├── Application.mk ├── convolve.cl ├─ ...
- 西安Uber优步司机奖励政策(2月1日~2月7日)
滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...
- UVA 10194 Football (aka Soccer)
Problem A: Football (aka Soccer) The Problem Football the most popular sport in the world (america ...