using System.Collections;
using System.Text.RegularExpressions; namespace DotNet.Utilities
{
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[i].ToString());
}
else
{
sum_even += int.Parse(s[i].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[i], type[i - ]);
}
result_bin += "";
for (int i = ; i < ; i++)
{
result_bin += ean13(s[i], '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[i] + "</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[i] + "</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 "";//011101
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 "";//000101
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!";
}
}
}
}

BarCodeToHTML

C# 条码生成类的更多相关文章

  1. [条形码] BarCodeToHTML条码生成类 (转载)

    点击下载 BarCodeToHTML.zip 过多的我就不多说了大家直接看代码吧,这是一个帮助大家生成条码的类,大小大家可以自由的设定 /// <summary> /// 类说明:条码生成 ...

  2. C# BarCodeToHTML条码生成类

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

  3. dagger2系列之生成类实例

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

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

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

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

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

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

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

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

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

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

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

  9. XML之自动生成类,添加,修改,删除类的属性

    1. class ClassHelperDemo { public static void Main() { #region 演示一:动态生成类. //生成一个类t. Type t = ClassHe ...

随机推荐

  1. Vue 框架 笔记

    1.兼容 2.性能优化   vuejs ******作者:尤雨溪 *** *******MVVM框架: M:model层 数据层 数据的增删改查 V:view视图层 类似于html的模板 vm:vie ...

  2. LOJ#2882. 「JOISC 2014 Day4」两个人的星座(计算几何)

    题面 传送门 题解 我们发现如果两个三角形相离,那么这两个三角形一定存在两条公切线 那么我们可以\(O(n^2)\)枚举其中一条公切线,然后可以暴力\(O(n^3)\)计算 怎么优化呢?我们可以枚举一 ...

  3. PHP开始1 php的命名规范

    常量 php 中有一些预定义常量,我们常常称他们为'魔术常量'. __LINE__          返回文件中的当前行号 __FILE__           返回该文件的完整路径和文件名 __DI ...

  4. [SQL] 简单新建(create)删除(drop\delete)权限(grant/revoke)修改(set\update)

    一.前言 说起来 数据库(Structured Query Language),本站写过很多类似文章. 如: Mysql创建.删除用户 phpMyAdmin 登陆需要密码 记一次裸迁 MySQL 经历 ...

  5. Flutter 1.0 正式版: Google 的便携 UI 工具包

    简评:所以 React-Native 和 Flutter 该怎么选? 在 10 个月前的 MWC 上,谷歌发布了 Flutter 的 Beta 版本,给跨平台应用开发带来了一种全新的选择,昨天谷歌正式 ...

  6. Java性能优化技巧及实战

    关于Java代码的性能优化,是每个javaer都渴望掌握的本领,进而晋升为大牛的必经之路,但是对java的调优需要了解整个java的运行机制及底层调用细节,需要多看多读多写多试,并非一朝一夕之功.本文 ...

  7. Tsung安装指南

    1. 所需要软件包unixODBC-2.2.14.tar.gzotp_src_R13B02-1.tar.gztsung-1.3.1.tar.gzTemplate-Toolkit-2.22.tar.gz ...

  8. [转]iOS:批量导入图片和视频到模拟器的相册

    IOS开发中我们经常会用到模拟器调试,模拟器有个主要的好处就是程序启动块,最重要的是如果没有证书的话,我们就只能在模拟器上调试了.使用模拟器调试时我们可能碰到需要从系统相册选择图片的情况,特别是做图片 ...

  9. docker微服务部署之:三,搭建Zuul微服务项目

    docker微服务部署之:二.搭建文章微服务项目 一.新增demo_eureka模块,并编写代码 右键demo_parent->new->Module->Maven,选择Module ...

  10. 编译原理(一)绪论概念&文法与语言

    绪论概念&文法与语言 以老师PPT为标准,借鉴部分教材内容,AlvinZH学习笔记. 绪论基本概念 1. 低级语言:字位码.机器语言.汇编语言.与特定的机器有关,功效高,但使用复杂.繁琐.费时 ...