[转][C#]BarCodeToHTML
/// <summary>
/// 类说明:Assistant
/// 编 码 人:苏飞
/// 联系方式:361983679
/// 更新网站:http://www.sufeinet.com/thread-655-1-1.html
/// </summary>
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 "";//
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!";
}
}
}
}
[转][C#]BarCodeToHTML的更多相关文章
- [条形码] BarCodeToHTML条码生成类 (转载)
点击下载 BarCodeToHTML.zip 过多的我就不多说了大家直接看代码吧,这是一个帮助大家生成条码的类,大小大家可以自由的设定 /// <summary> /// 类说明:条码生成 ...
- 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 ...
- Azylee.Utils 工具组
https://github.com/yuzhengyang/Fork Fork 是平时做 C# 软件的时候,整合各种轮子的一个工具项目,包括并不仅限于:各种常用数据处理方法,文件读写 加密 搜索,系 ...
随机推荐
- CH5701 开车旅行
题意 5701 开车旅行 0x50「动态规划」例题 描述 小A和小B决定利用假期外出旅行,他们将想去的城市从1到N编号,且编号较小的城市在编号较大的城市的西边,已知各个城市的海拔高度互不相同,记城市 ...
- oracle修改字符集方法
查看源数据库字符集 在sql命令行执行,即可查看 cat exp.dmp |od -x|head -1|awk '{print $2 $3}'|cut -c 3-6 例如我的返回结果为0362,对照以 ...
- CSV文件保存为utf8编码格式
csv格式文件经常用来批量导入数据到某些应用中,但是经常出现utf8乱码问题,那么该如何解决呢? WPS找不到编码格式设置,微软的office软件有,不过我使用的是libreoffice 步骤如下 1 ...
- Kafka Consumer API样例
Kafka Consumer API样例 1. 自动确认Offset 说明参照:http://blog.csdn.net/xianzhen376/article/details/51167333 Pr ...
- Gravitee.io docker-compose运行
Gravitee.io 是一个相对比较完整的api gateway 平台,包含了api 相对比较完整的生命周期管理 同时在访问控制以及日志监控上也做的比较好,是一款可以尝试试用的api gateway ...
- 【转载】Win10打开U盘提示“文件或目录损坏无法读取”怎么办?
以下文转载至系统之家 网址:http://www.xitongzhijia.net/xtjc/20190314/152334.html (PS:暂未亲测) Win10打开U盘提示“文件或目录损坏无法读 ...
- 机器学习 - 开发环境安装pycharm + pyspark + spark集成篇
AS WE ALL KNOW,学机器学习的一般都是从python+sklearn开始学,适用于数据量不大的场景(这里就别计较“不大”具体指标是啥了,哈哈) 数据量大了,就需要用到其他技术了,如:spa ...
- 使用InternalsVisibleToAttribute给assembly添加“友元assembly”特性遭遇"强签名"
一.如何让Intenal成员暴露给另一个程序集 我们知道Modifier为Internal的类型成员仅限于当前程序集能够访问,但是在某些情况下,我们希望将它们暴露给另一个程序集.比较典型的应用场景包括 ...
- 计算元素个数(count和count_if)
count 计算first和last之间与value相等于元素个数 template <class InputIterator,class EqualityComparable> type ...
- mvn+spring+webapp模板
idea新建项目,选择maven-archetype-webapp 在main目录下创建java resource 文件夹,赋予特殊文件夹 pom.xml 添加 <!--Spring框架核心库 ...