




已阅读5页,还剩11页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
using System;using System.Collections.Generic;using System.ComponentModel;using System.Drawing;using System.Data;using System.Text;using System.Windows.Forms;using System.Drawing.Imaging;using System.Drawing.Printing;namespace DSBarCode public partial class BarCode_EAN13 : UserControl public BarCode_EAN13() InitializeComponent(); private int _barcodeheight = 30; public int BarCodeHeight get return _barcodeheight; set _barcodeheight = value; LoadBarCode(); private int SPACE_HEIGHT = 3; private string _Encoded_Value = ; private Bitmap _codeImage = null; private string _barcode = 1234567891231; public String BarCode get return _barcode; set _barcode = value.ToUpper(); _Encoded_Value = ; LoadBarCode(); private int leftMargin = 10; public int LeftMargin get return leftMargin; set leftMargin = value; LoadBarCode(); private int topMargin = 10; public int TopMargin get return topMargin; set topMargin = value; LoadBarCode(); private int rigthMargin = 10; public int RigthMargin get return rigthMargin; set rigthMargin = value; LoadBarCode(); private int bottomMargin = 10; public int BottomMargin get return bottomMargin; set bottomMargin = value; LoadBarCode(); private bool showHeader; public bool ShowHeader get return showHeader; set showHeader = value; LoadBarCode(); private bool showFooter; public bool ShowFooter get return showFooter; set showFooter = value; LoadBarCode(); private String headerText = ; public String HeaderText get return headerText; set headerText = value; LoadBarCode(); private Font headerFont = new Font(Courier, 8); public Font HeaderFont get return headerFont; set headerFont = value; LoadBarCode(); private Font footerFont = new Font(Courier, 8); public Font FooterFont get return footerFont; set footerFont = value; LoadBarCode(); private string EAN_CodeA = 0001101, 0011001, 0010011, 0111101, 0100011, 0110001, 0101111, 0111011, 0110111, 0001011 ; private string EAN_CodeB = 0100111, 0110011, 0011011, 0100001, 0011101, 0111001, 0000101, 0010001, 0001001, 0010111 ; private string EAN_CodeC = 1110010, 1100110, 1101100, 1000010, 1011100, 1001110, 1010000, 1000100, 1001000, 1110100 ; private string EAN_Pattern = aaaaaa, aababb, aabbab, aabbba, abaabb, abbaab, abbbaa, ababab, ababba, abbaba ; private string UPC_SUPP_5 = bbaaa, babaa, baaba, baaab, abbaa, aabba, aaabb, ababa, abaab, aabab ; public void Print() if (_codeImage = null) return; StandardPrintController controler = new StandardPrintController(); printDocument1.PrintController = controler; printDocument1.Print(); private Bitmap BlankBackImage get int barCodeWidth = leftMargin+rigthMargin, barCodeHeight = topMargin+bottomMargin; SizeF _size = SizeF.Empty; string barCode =_barcode; if (_Encoded_Value = ) if (_barcode.Length = 12) barCode = getENA13Code(_barcode); else if (_barcode.Length = 17) barCode = getENA13Code(_barcode.Substring(0, 12); char symbols = barCode.ToCharArray(); foreach (char c in symbols) if (!Char.IsDigit(c) return null; string patterncode = EAN_PatternInt32.Parse(barCode0.ToString(); string result = 101; int pos = 0; while (pos 6) if (patterncodepos = a) result += EAN_CodeAInt32.Parse(barCodepos + 1.ToString(); if (patterncodepos = b) result += EAN_CodeBInt32.Parse(barCodepos + 1.ToString(); pos+; /while result += 01010; pos = 1; while (pos 13) string Raw_Data = barCode.Substring(13); int even = 0; int odd = 0; /odd for (int i = 0; i = 4; i += 2) odd += Int32.Parse(Raw_Data.Substring(i, 1) * 3; /for /even for (int i = 1; i 13) barCodeWidth += 10; if (showHeader & !string.IsNullOrEmpty(headerText) _size = g.MeasureString(headerText, headerFont); barCodeHeight += (int)_size.Height + SPACE_HEIGHT; barCodeHeight += (int)_barcodeheight + SPACE_HEIGHT; if (showFooter) barCodeHeight += 12; barCodeHeight += 10; return new Bitmap(barCodeWidth, barCodeHeight, PixelFormat.Format32bppArgb); private void PaintEAN13(Graphics g, Rectangle drawBounds) g.Clear(Color.White); Font font = new Font(Microsoft Sans Serif, 8); int lineWidth = 1; int x = drawBounds.X; char symbols = _barcode.ToCharArray(); g.DrawString(symbols0.ToString(), font, new SolidBrush(Color.Black), x, drawBounds.Y + drawBounds.Height - 16); x += 10; g.DrawLine(new Pen(Brushes.Black, lineWidth), x, drawBounds.Y, x, drawBounds.Y + drawBounds.Height); x += lineWidth; g.DrawLine(new Pen(Brushes.White, lineWidth), x, drawBounds.Y, x, drawBounds.Y + drawBounds.Height); x += lineWidth; g.DrawLine(new Pen(Brushes.Black, lineWidth), x, drawBounds.Y, x, drawBounds.Y + drawBounds.Height); x += lineWidth; if (showFooter) g.DrawString(_barcode.Substring(1, 6), font, new SolidBrush(Color.Black), x, drawBounds.Y + drawBounds.Height - 12); char xxx = _Encoded_Value.Substring(3,42).ToCharArray(); for (int i = 0; i xxx.Length; i+) if (xxxi = 1) g.DrawLine(new Pen(Brushes.Black, lineWidth), x, drawBounds.Y, x, drawBounds.Y + drawBounds.Height - 12); else g.DrawLine(new Pen(Brushes.White, lineWidth), x, drawBounds.Y, x, drawBounds.Y + drawBounds.Height - 12); x += lineWidth; / Paint center guard bars, always same 01010 g.DrawLine(new Pen(Brushes.White, lineWidth), x, drawBounds.Y, x, drawBounds.Y + drawBounds.Height); x += lineWidth; g.DrawLine(new Pen(Brushes.Black, lineWidth), x, drawBounds.Y, x, drawBounds.Y + drawBounds.Height); x += lineWidth; g.DrawLine(new Pen(Brushes.White, lineWidth), x, drawBounds.Y, x, drawBounds.Y + drawBounds.Height); x += lineWidth; g.DrawLine(new Pen(Brushes.Black, lineWidth), x, drawBounds.Y, x, drawBounds.Y + drawBounds.Height); x += lineWidth; g.DrawLine(new Pen(Brushes.White, lineWidth), x, drawBounds.Y, x, drawBounds.Y + drawBounds.Height); x += lineWidth; if (showFooter) g.DrawString(_barcode.Substring(7, 6), font, new SolidBrush(Color.Black), x, drawBounds.Y + drawBounds.Height - 12); xxx = _Encoded_Value.Substring(50, 42).ToCharArray(); for (int i = 0; i 0 & showFooter) SizeF _size = g.MeasureString(_barcode.Substring(13), font); int span = (xxx.Length - (int)_size.Width) / 2; g.DrawString(_barcode.Substring(13), font, new SolidBrush(Color.Black), x + span, drawBounds.Y + drawBounds.Height - 12); for (int i = 0; i xxx.Length; i+) if (xxxi = 1) g.DrawLine(new Pen(Brushes.Black, lineWidth), x, drawBounds.Y , x, drawBounds.Y + drawBounds.Height - 12); else g.DrawLine(new Pen(Brushes.White, lineWidth), x, drawBounds.Y, x, drawBounds.Y + drawBounds.Height - 12); x += lineWidth; private void CreateBarCode() _codeImage = BlankBackImage; /_codeImage.SetResolution(96, 96); if (_codeImage != null) Graphics g = Graphics.FromImage(_codeImage); g.Clear(Color.White); /g.DrawImageUnscaled(_codeImage, recImg); PaintEAN13(g, new Rectangle(leftMargin, topMargin, _codeImage.Width-leftMargin-rigthMargin, _codeImage.Height-topMargin-bottomMargin); /Paint_EAN13(_barcode, g,new Rectangle(0,0,_codeImage.Width,_codeImage.Height); g.Dispose(); private void DrawBarCode(Graphics gprint) /_codeImage = BlankBackImage; /if (_codeImage != null) / / Graphics g = Graphics.FromImage(_codeImage); / g.Clear(Color.White); / /g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; / /g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias; / g.PageUnit = gprint.PageUnit; / Paint_EAN13(_barcode, g, new Rectangle(0, 0, _codeImage.Width, _codeImage.Height); / g.Dispose(); / private void LoadBarCode() CreateBarCode(); Graphics g = this.CreateGraphics(); g.Clear(this.BackColor); if (_codeImage != null) g.DrawImage(_codeImage, 0, 0); g.Dispose(); private void BarCode_EAN13_Paint(object sender, PaintEventArgs e) if (_codeImage = null) e.Graphics.Clear(this.BackColor); else e.Graphics.DrawImage(_codeImage, 0, 0); private string getENA13Code(string Numbers12bit) int c1 = 0; int c2 = 0; for (int i = 0; i 11; i = i + 2) c1 += int.Parse(Numbers12biti.ToString(); c2 += int.Parse(Numbers12biti + 1.ToString(); int c3 = c1 + c2 * 3; c3 = c3 - c3 / 10 * 10; if (c3 = 0) return Numbers12bit + 0; else int N = 10 - c3; return Numbers12bit + N; #region / / Paint EAN13 barcode to specified graphics into specified draw rectangle. / / BarCode value. / Graphics where to draw. / Draw bounds. /private void Paint_EAN13(string Numbers12bit, Graphics g, Rectangle drawBounds) / / string barCode = getENA13Code(Numbers12bit); / char symbols = barCode.ToCharArray(); / /- Validate barCode -/ / if (barCode.Length != 13) / / return; / / foreach (char c in symbols) / / if (!Char.IsDigit(c) / / return; / / / /- Check barcode checksum -/ / int checkSum = Convert.ToInt32(symbols12.ToString(); / int calcSum = 0; / bool one_three = true; / for (int i = 0; i 12; i+) / / if (one_three) / / calcSum += (Convert.ToInt32(symbolsi.ToString() * 1); / one_three = false; / / else / / calcSum += (Convert.ToInt32(symbolsi.ToString() * 3); / one_three = true; / / / char calcSumChar = calcSum.ToString().ToCharArray(); / if (checkSum != 0 & checkSum != (10 - Convert.ToInt32(calcSumCharcalcSumChar.Length - 1.ToString() / / return; / / /-/ / /-/ / Font font = new Font(Microsoft Sans Serif, 8); / / Fill backround with white color / / g.Clear(Color.White); / int lineWidth = 1; / int x = drawBounds.X; / / Paint human readable 1 system symbol code / g.DrawString(symbols0.ToString(), font, new SolidBrush(Color.Black), x, drawBounds.Y + drawBounds.Heig
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 浙江省桐乡市第一中学2026届化学高一第一学期期中统考试题含解析
- 2026届湖北省黄冈市晋梅中学化学高一上期中综合测试试题含解析
- 主题中秋节活动营销策划方案
- 乡卫生院工作方案
- 兴国县旅游试题及答案
- 3招增强孩子的社交信心
- 2026届湖北省黄冈市化学高二上期中考试试题含解析
- 2026届甘肃省永昌县第四中学化学高二上期末达标测试试题含答案
- 隐性性格测试题及答案
- 延禧攻略试题及答案
- 《基于单元的高中英语项目式学习设计研究》
- 应急救援互助合同协议书
- 2025年北京市海淀区高三二模英语试卷(含答案)
- 医院改建可行性研究报告
- 2025保定市涞水县涞水镇社区工作者考试真题
- 2025-2030中国芽孢杆菌行业市场现状供需分析及投资评估规划分析研究报告
- 人民警察职业道德教育
- 小学语文新课标跨学科学习任务群解读及教学建议
- 护士执业资格考试知识点大全2025
- 工厂合伙退股协议书模板
- 资料装订合同协议
评论
0/150
提交评论