c#中如何用codesoft来打印标签开发分享
以前使用过delphi和java开发过使用codesoft,最近因需要用c#开发了一个用codesoft来打印标签的程序。源代码分享给需要的人。
业务背景:
把datagridview中的数据打印 标签(需要对coesoft软件有一定的了解)。
操作方法:
1 使用codesoft制做一个打印模板(这里就不再讲了)
2 在c#项目中引用codesoft插件。
找到项目中的[引用],右击添加引用,找到浏览,选中c:\program files\cs6下的Lppx2.tlb,这样组件就安装完成。
安装完后,在引用下面会出现:
3 源代码及说明如下,下面是一个打印的画面和程序:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;namespace OPurchase
{public partial class frmJP_CODESOFT_PT : Form{public int ilableLx;//打印模板类型,目前这里仅一个模板public DataGridView dv;//定义公共变量,调用这个窗口时把datagridview传进来,public frmJP_CODESOFT_PT(){InitializeComponent();}protected override bool ProcessCmdKey(ref Message msg, Keys keyData){if (keyData == Keys.Escape){Close();}else if (keyData == Keys.Enter){SendKeys.Send("{tab}");return true;}return base.ProcessCmdKey(ref msg, keyData);}private void btnSet_Click(object sender, EventArgs e){}private void btnPrint_Click(object sender, EventArgs e){if (ilableLx == 0)//模板一{LabelManager2.ApplicationClass labApp = null;LabelManager2.Document doc = null;string labFileName=System.Windows.Forms.Application.StartupPath + @"\barJapLab.Lab"; try{if (!File.Exists(labFileName)){MessageBox.Show("沒有找到標簽模板文件:barJapLab.Lab,請聯系系統管理員", "溫馨提示");return;}labApp = new LabelManager2.ApplicationClass();labApp.Documents.Open(labFileName, false);// 调用设计好的label文件doc = labApp.ActiveDocument;if (dv.SelectedRows.Count > 0){progressBar1.Maximum = dv.SelectedRows.Count;progressBar1.Value = 0;for (int i = 0; i < dv.SelectedRows.Count; i++) //选中多行打印{ //下面这些是给模板的变量传值进去 doc.Variables.FormVariables.Item("barcode_no").Value = dv.SelectedRows[i].Cells["barcode_no"].Value.ToString();doc.Variables.FormVariables.Item("style_no").Value = dv.SelectedRows[i].Cells["style_no"].Value.ToString();doc.Variables.FormVariables.Item("upp_jp").Value = dv.SelectedRows[i].Cells["upp_jp"].Value.ToString();doc.Variables.FormVariables.Item("outsole_jp").Value = dv.SelectedRows[i].Cells["outsole_jp"].Value.ToString();doc.Variables.FormVariables.Item("col_jp").Value = dv.SelectedRows[i].Cells["col_jp"].Value.ToString();doc.Variables.FormVariables.Item("size_width").Value = dv.SelectedRows[i].Cells["size_width"].Value.ToString();doc.Variables.FormVariables.Item("price").Value = dv.SelectedRows[i].Cells["price"].Value.ToString();doc.Variables.FormVariables.Item("comp_jp").Value = dv.SelectedRows[i].Cells["comp_jp"].Value.ToString();doc.Variables.FormVariables.Item("address_jp").Value = dv.SelectedRows[i].Cells["address_jp"].Value.ToString();doc.Variables.FormVariables.Item("url").Value = dv.SelectedRows[i].Cells["url"].Value.ToString();//下面这行是打印份数的定义doc.PrintDocument(Convert.ToInt16(dv.SelectedRows[i].Cells["qty"].Value) + Convert.ToInt16(dv.SelectedRows[i].Cells["att_qty"].Value));progressBar1.Value++;progressBar1.Refresh();lbStatus.Text = "總共" + dv.SelectedRows.Count.ToString() + "行需要列印,已送出"+Convert.ToString (i+1)+"行";lbStatus.Refresh();this.Refresh();}}else //光标所在行打印{doc.Variables.FormVariables.Item("barcode_no").Value = dv.CurrentRow.Cells["barcode_no"].Value.ToString();doc.Variables.FormVariables.Item("style_no").Value = dv.CurrentRow.Cells["style_no"].Value.ToString();doc.Variables.FormVariables.Item("upp_jp").Value = dv.CurrentRow.Cells["upp_jp"].Value.ToString();doc.Variables.FormVariables.Item("outsole_jp").Value = dv.CurrentRow.Cells["outsole_jp"].Value.ToString();doc.Variables.FormVariables.Item("col_jp").Value = dv.CurrentRow.Cells["col_jp"].Value.ToString();doc.Variables.FormVariables.Item("size_width").Value = dv.CurrentRow.Cells["size_width"].Value.ToString();doc.Variables.FormVariables.Item("price").Value = dv.CurrentRow.Cells["price"].Value.ToString();doc.Variables.FormVariables.Item("comp_jp").Value = dv.CurrentRow.Cells["comp_jp"].Value.ToString();doc.Variables.FormVariables.Item("address_jp").Value = dv.CurrentRow.Cells["address_jp"].Value.ToString();doc.Variables.FormVariables.Item("url").Value = dv.CurrentRow.Cells["url"].Value.ToString(); doc.PrintDocument(Convert.ToInt16(dv.CurrentRow.Cells["qty"].Value));}}catch (Exception ex){MessageBox.Show("出錯啦,原因如下:\n\r"+ex.Message,"出錯啦");}finally{labApp.Documents.CloseAll(true);labApp.Quit();//退出labApp = null;doc = null;GC.Collect(0);}}}private void frmJP_CODESOFT_PT_Load(object sender, EventArgs e){if (dv.SelectedRows.Count >0)lbStatus.Text = "總共"+dv.SelectedRows .Count .ToString ()+"行需要列印";elselbStatus.Text = "總共1行需要列印";}private void btnClose_Click(object sender, EventArgs e){Close();}}
}
c#中如何用codesoft来打印标签开发分享相关推荐
- 一步一步学Silverlight 2系列(22):在Silverlight中如何用JavaScript调用.NET代码_转载...
概述 Silverlight 2 Beta 1版本发布了,无论从Runtime还是Tools都给我们带来了很多的惊喜,如支持框架语言Visual Basic, Visual C#, IronRuby, ...
- 一步一步学Silverlight 2系列(22):在Silverlight中如何用JavaScript调用.NET代码
概述 Silverlight 2 Beta 1版本发布了,无论从Runtime还是Tools都给我们带来了很多的惊喜,如支持框架语言Visual Basic, Visual C#, IronRuby, ...
- 【直播间】移动互联网产品中如何用好HTML5?
开发者福利来袭! 51CTO携手APICloud为正在做移动开发.即将转型做移动开发的小伙伴们分享移动开发最前沿技术,我们特此邀请到许志锋老师做直播分享课. 小板凳已备好,开始学习啦~ 分享主题 移动 ...
- Excel中如何用计算公式或表达式直接计算出结果?
Excel中如何用计算公式或表达式直接计算出结果? 目录 Excel中如何用计算公式或表达式直接计算出结果? 1.例如:我们需要用E列的计算公式(表达式),直接计算出结果填至F列 2.另一种方法:在菜 ...
- Excel中如何用身份证号提取计算年龄?
Excel中如何用身份证号提取计算年龄? 目录 Excel中如何用身份证号提取计算年龄? 1.在年龄D2单元格中输入公式[=DATEDIF(TEXT(MID(C2,7,8),"00-00-0 ...
- Android NDK开发之旅(2):一篇文章搞定Android Studio中使用CMake进行NDK/JNI开发
Android NDK开发之旅(2):一篇文章搞定android Studio中使用CMake进行NDK/JNI开发 (码字不易,转载请声明出处:http://blog.csdn.NET/andrex ...
- Linux中如何用命令打开文件夹
Linux中如何用命令打开文件夹 文章目录: 一.点击Linux桌面文件图标打不开 二.解决方式 三.杀死所有nautilus相关进程 你是否遇到过Linux桌面文件图标打不开,我就遇到过,此时我的眼 ...
- (转)MSSQL中如何用SQL清除所有表的数据(downmoon)?
有朋友问起:MSSQL中如何用SQL清除所有表的数据?这个需求分三种类型: 第一:只要数据库中表是空的: 第二:表是空的,并且自增长列可以从1开始增长. 第三:表是空的,并且自增长列可以从1开始增长, ...
- java transaction cn,JAVA中如何用TRANSACTION来对数据库进行
TRANSACTION的作用: 比如有 一般的格式. try { conn.setAutoCommit(false); http://www.gaodaima.com/41686.htmljava中如 ...
最新文章
- 通过公历年计算天干地支
- mysql12----explain
- hihocoder 1320 压缩字符串(字符串+dp)
- Xshell的安装和连接
- 一起来学习android自定义控件3——边缘凹凸的View
- MySQL优化系列_常见的sql使用-Mysql中的实践(Mysql优化系列8)
- 控制台启动jar包关闭控制台怎么关java程序_Jpom一款简而轻的低侵入式Java运维、监控软件...
- 计算机上的框英文,电脑打开steam平台弹出一个英文框的解决方法
- 微软发布Visual Studio 2010 SP1公测版
- Java 原生 JAXB 解析 XML 深入剖析
- vsftp客户连接常见故障现象
- Ubuntu下使用VI编辑文件必知的常用命令
- 物联网是自动化还是计算机,物联网:自动化家里的一切
- Java中native方法的使用
- 西门子uss通讯实例_西门子USS通信调试经历
- 网络模型|分割模型|Vnet
- 浅析CC2540的OSAL原理
- 关于Unity中天空盒的使用
- 微信公众号渠道二维码怎么生成?可以进行用户分组吗?
- JAVA 的性能优化
热门文章
- R语言并行计算spearman相关系数
- HTML5实现的树叶飘落动画特效
- 键盘定位板图纸_客制化键盘
- 协同过滤推荐之基于近邻协同过滤(一)
- 华为鸿蒙麒麟玉兔_华为“鸿蒙”实锤了!还有朱雀、麒麟、鲲鹏,网友:华为注册了一本《山海经》...
- 查看linux下oracle安装位置
- Web端实现邮件发送
- 福建食用菌产业博览会盛大开幕 谋定中国农民丰收节交易会
- PS 学习笔记 15-橡皮擦工具组
- 神舟战神 8/9 代同方机型黑苹果 (非本人原创) (本人已按照教程安装)