/// <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的更多相关文章

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

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

  2. C# BarCodeToHTML条码生成类

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

  3. C# 条码生成类

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

  4. Azylee.Utils 工具组

    https://github.com/yuzhengyang/Fork Fork 是平时做 C# 软件的时候,整合各种轮子的一个工具项目,包括并不仅限于:各种常用数据处理方法,文件读写 加密 搜索,系 ...

随机推荐

  1. djkstra nlogn

    #include<bits/stdc++.h> #define fi first #define se second #define pii pair<int,int> usi ...

  2. dijksta 模板

    #include<bits/stdc++.h> using namespace std; #define INF 0x3f3f3f3f ]; ]; ][]; void dijkstra(i ...

  3. 走进 AQS 瞧一瞧看一看

    并发中有一块很重要的东西就是AQS.接下来一周的目标就是它. 看复杂源码时,一眼望过去,这是什么?不要慌,像剥洋葱一样,一层层剥开(哥,喜欢"扒开"这个词). 参考资源: http ...

  4. Linux 命令:文件目录操作与实例

    来源: http://blog.51cto.com/yuanzhitang/2056994 本文介绍基础的文件操作:创建,移动,编辑,删除 文件和文件夹   命令与案例:   mkdir 创建目录 - ...

  5. Python知识点整理,基础1 - 基本语法

  6. MVVM在WPF中应用(1)

    在软件行业浸润了这么多年,第一次在MES的工厂里从事软件开发. 在这里的感觉就是安静.宽松,比在那些专门以软件为主的企业中轻松自在.在这里的第一个项目是关于数据的导入和导出,还有数据的比较这些功能. ...

  7. MySQL Innodb Engine --独立表空间参数(innodb_file_per_table)

    MySQL中参数innodb_file_per_table决定将表存放于ibdata*的共享表空间还是独立的.ibd文件的独立表空间. ================================ ...

  8. 初始Openwrt

    系统结构 在上一章我们已经完成了刷机工作,这个时候系统进行了首次启动,并且格式化了它的"可写"分区.那么在设备里分区到底是怎么样进行的呢?我们首先需要知道:不同的处理器下OpenW ...

  9. C# string 转 bool

    bool _b = Convert.ToBoolean("False"); "_b => false" // // 摘要: //     将逻辑值的指定字 ...

  10. [转]分布式系统唯一ID生成方案汇总

    系统唯一ID是我们在设计一个系统的时候常常会遇见的问题,也常常为这个问题而纠结.生成ID的方法有很多,适应不同的场景.需求以及性能要求.所以有些比较复杂的系统会有多个ID生成的策略.下面就介绍一些常见 ...