感谢博主:转自:http://xoyozo.eyuyao.com/blog/barcode.html

public partial class ReceivablesFormView : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string code = Get("", , ); this.barcode.InnerHtml = code;
} /// <summary>
/// 获取 EAN-13 条形码(HTML 版)
/// </summary>
/// <param name="s">欲编码的字符串</param>
/// <param name="width">单个条形宽(px)</param>
/// <param name="height">条形高(px)</param>
/// <returns></returns>
public static string Get(string s, int width, int height)
{
int checkcode_input = -;//输入的校验码
if (!Regex.IsMatch(s, @"^\d{12}$"))
{
if (s.Length != )
{
return "字符串长度不正确!";
}
else 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 "";//
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!";
}
}
}

在线生成条形码的解决方案(39码、EAN-13)的更多相关文章

  1. C# 利用ZXing.Net来生成条形码和二维码

    本文是利用ZXing.Net在WinForm中生成条形码,二维码的小例子,仅供学习分享使用,如有不足之处,还请指正. 什么是ZXing.Net? ZXing是一个开放源码的,用Java实现的多种格式的 ...

  2. 一维码EAN 13简介及其解码实现(zxing-cpp)

    一维码EAN 13:属于国际标准条码, 由13个数字组成,为EAN的标准编码型式(EAN标准码). 依结构的不同,EAN条码可区分为: 1.  EAN 13码: 由13个数字组成,为EAN的标准编码型 ...

  3. (zxing.net)一维码EAN 13的简介、实现与解码

    一维码EAN 13:属于国际标准条码, 由13个数字组成,为EAN的标准编码型式(EAN标准码). 依结构的不同,EAN条码可区分为: EAN 13码: 由13个数字组成,为EAN的标准编码型式(EA ...

  4. iOS开发——生成条形码,二维码

    - (void)viewDidLoad { [super viewDidLoad]; self.imageView.image = [self generateBarCode:@"15248 ...

  5. C#利用Zxing.net生成条形码和二维码并实现打印的功能

        开篇:zxing.net是.net平台下编解条形码和二维码的工具. 下载地址:http://pan.baidu.com/s/1kTr3Vuf Step1:使用VS2010新建一个窗体程序项目: ...

  6. 使用js生成条形码以及二维码

    一.用js生成条形码这种业务场景不是很常见的,最近刚好又接到这种需求 Google一下,发现github还真有这方面的轮子,感谢github,省去了我们很多造轮子的过程, 好了言归正传,首先引入jsb ...

  7. 使用谷歌Z生成条形码以及二维码

    下载地址:http://zxingnet.codeplex.com/ zxing.net是.net平台下编解条形码和二维码的工具,使用非常方便. 首先下载二进制dll文件,引入工程: using Sy ...

  8. 第二节 EAN 8 码 / EAN 13 码

    EAN码的全名为欧洲商品条码(European Article Number),源於西元1977年,由欧洲十二个工业国家所共同发展出来的一种条码.目前已成为一种国际性的条码系统.EAN条码系统的管理是 ...

  9. ZXing生成条形码、二维码、带logo二维码

    采用的是开源的ZXing,Maven配置如下,jar包下载地址,自己选择版本下载,顺便推荐下Maven Repository <!-- https://mvnrepository.com/art ...

随机推荐

  1. 病毒木马查杀实战第015篇:U盘病毒之脱壳研究

    前言 因为我们的终于目标是编写出针对于这次的U盘病毒的专杀工具.而通过上次的分析我们知道,病毒有可能在不同的计算机中会以不同的名称进行显示.假设真是如此,那么就有必要在此分析出病毒的命名规律等特征,然 ...

  2. 如何使用angularjs实现文本框设置值

    <!DOCTYPE html> <html ng-app="myApp"> <head> <title>angularjs-setV ...

  3. 11g OCM 考试感悟

    11g OCM 考试感悟 PrudentWoo 累,累.真的很累.考前每天全场景的刷两遍.三遍不觉得累.总感觉练习时间不够.考中尽管时间足够.可是压力很大.尤其看到一些和平时训练不一样题目的时候,那种 ...

  4. 也谈编译 VS 解释

    语言发展 计算机的硬件仅仅能识别0和1组成的机器指令,而机器指令是最主要的计算机语言,可是我们平时进行程序设计时肯定不会用机器语言来编程,由于用它的效率低.更让人难以理解. 因此聪明的人类发明了汇编语 ...

  5. nodejs之SVG转图片下载方案

    本文介绍在nodejs基础上.怎样实现将svg转为png并下载的功能. 所需Webkit和node module简单介绍: phantomjs:一个基于WebKit的server端JavaScript ...

  6. JavaScript/Jquery返回顶部代码

    <!DOCTYPE html> <html> <head> <title>返回顶部</title> <meta charset=&qu ...

  7. Git使用总结 Asp.net生命周期与Http协议 托管代码与非托管代码的区别 通过IEnumerable接口遍历数据 依赖注入与控制反转 C#多线程——优先级 AutoFac容器初步 C#特性详解 C#特性详解 WPF 可触摸移动的ScrollViewer控件 .NET(C#)能开发出什么样的APP?盘点那些通过Smobiler开发的移动应用

    一,原理 首先,我们要明白Git是什么,它是一个管理工具或软件,用来管理什么的呢?当然是在软件开发过程中管理软件或者文件的不同版本的工具,一些作家也可以用这个管理自己创作的文本文件,由Linus开发的 ...

  8. EF 表联合查询 join

    有两张表m_Dept.m_User,联合查询 linq方式.EF方式 private void Add() { List<m_Dept> lst = new List<m_Dept& ...

  9. codesmith 自动生成C# model 实体模板

    <%-- Name:自动生成 Author: 陈胜威 Description: 直接生成model类 --%> <%@ Template Language="C#" ...

  10. mongod启动时候几个参数说明

    1.--storageEngine从3.0开始,新增了一个存储引擎WT.老版本的存储引擎被称作mmapv1 2.--oplogSizeOplog是复制的主要组成部分,位于local数据库中.在初始化复 ...