点击下载 BarCodeToHTML.zip

过多的我就不多说了大家直接看代码吧,这是一个帮助大家生成条码的类,大小大家可以自由的设定

/// <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条码生成类 (转载)的更多相关文章

  1. C# BarCodeToHTML条码生成类

    来自:http://www.sufeinet.com/forum.php?mod=viewthread&tid=656&extra=page%3D1%26filter%3Dtypeid ...

  2. C# 条码生成类

    using System.Collections; using System.Text.RegularExpressions; namespace DotNet.Utilities { public ...

  3. Language Guide (proto3) | proto3 语言指南(十五)生成类

    Generating Your Classes - 生成类 要生成Java.Python.C++.Go.Ruby.ObjuleC或C代码,需要使用.proto文件中定义的消息类型,还需要在.proto ...

  4. dagger2系列之生成类实例

    上一节的最后,我讲到一次注入生成类实例的生成步骤.先来回顾一下: 1  Module中存在创建方法,则看此创建方法有没有参数 如果有参数,这些参数也是由Component提供的,返回步骤1逐一生成参数 ...

  5. 将Eclipse中现有的java类生成类图

    需求:将Eclipse中现有的java类生成类图 一:什么是ModelGoon? 它是一个Eclipse插件,用于基于UML图的模型设计,以及逆向工程(即从已有源代码生成类图). 二:安装 下载Mod ...

  6. 用Enterprise Architect从源码自动生成类图

    http://blog.csdn.net/zhouyong0/article/details/8281192 /*references:感谢资源分享者.info:简单记录如何通过工具从源码生成类图,便 ...

  7. Java 编程 订单、支付、退款、发货、退货等编号主动生成类

    订单.支付.退款.发货.退货等编号主动生成类 在商城网站中,订单编号的自动生成,ERP中各个单据的编号自动生成,都可以按照一下的方式来自动生成. 第一步:定义常量订单编号前缀.订单编号起始数.订单编号 ...

  8. 【原】如何获取Java动态生成类?

    写作目的:Java大部分框架,如Spring,Hibernate等都会利用动态代理在程序运行的时候生成新的类, 有的时候为了学习,或者深入了解动态代理,想查看动态生成类的源代码究竟长怎么个样子, 通过 ...

  9. IDEA设置生成类基本注释信息

    在eclipse中我们按一下快捷键就会生成类的基本信息相关的注释,其实在IDEA中也是可以的,需要我们手动设置,之后再创建类的时候就会自动加上这些基本的信息. File-->Setting 在E ...

随机推荐

  1. CSS六大选择器(注释css表里不能加注释!!)

    @charset "utf-8"; /* CSS Document */ <!--标签控制器--> body{ background-color:#F00} <! ...

  2. 【转】windows7 64位系统认不出8g内存显示只有3G可用

    原文网址:http://www.jb51.neos/windows/93721.html   我的电脑安装的是Win7 64位系统,当时内存是用的8G的,系统里面显示出来只有3.00G可用,真是崩溃啊 ...

  3. android报错——findViewById报错

    通過ID找到Layout的 VIEW控件.,比如你的控件Button ID為"@+id/button01"   就可以通過這樣Button btn=(Button)findView ...

  4. linux下建立无线wifi------简单实用!

    一 安装必要软件安装hostapd :    sudo apt-get install hostapd安装DHCP:    sudo apt-get install dhcp3-server 二 配置 ...

  5. HDOJ/HDU 1372 Knight Moves(经典BFS)

    Problem Description A friend of you is doing research on the Traveling Knight Problem (TKP) where yo ...

  6. FZU 2212 Super Mobile Charger 第六届福建省赛

    题目链接:http://acm.fzu.edu.cn/problem.php?pid=2212 题目大意: 现在有n个手机,一个电量为m%(百分之m)的万能充电宝 然后输入n个手机的现有电量(百分之a ...

  7. JSP控制select不可再选择

    首先分析下disable ,display和readonly: 1,Readonly只针对input(text / password)和textarea有效,而disabled对于所有的表单元素都有效 ...

  8. 如何运用同余定理求余数【hdoj 1212 Big Number【大数求余数】】

    Big Number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total ...

  9. jQuery之前端国际化jQuery.i18n.properties

    jQuery.i18n.properties是一款轻量级的jQuery国际化插件,能实现Web前端的国际化. 国际化英文单词为:Internationalization,又称i18n,"i& ...

  10. 七周七语言——Prolog(二)

    1  递归 首先来看一个知识库: father(zeb,john_boy_sr). father(john_boy_sr,john_boy_jr). ancestor(X,Y):-father(X,Y ...