-- 作者:cnsjroom
-- 发布时间:2022/10/9 16:00:00
-- select生成二维码提示 指定的转换无效
--------------------------- 版本:2022.1.30.2 --------------------------- 代码执行出错,错误信息:
System.InvalidCastException: 指定的转换无效。
在 UserCode.Test() --------------------------- 确定 ---------------------------
代码如下:红色部分代码都是双精度小数型 出现这个错误 怎么修正呢?
Dim fl As String = ProjectPath & "Reports\\test.pdf" Dim cmd As new SQLCommand cmd.Con necti onN ame="主数据源" cmd.C ommandText = "se le ct * from {SYS_二维码参数及标签打印机设置} " Dim dt11 As DataTable = cmd.ExecuteReader() Dim dr11 As DataRow = dt11.DataRows(0) output.show(1) If dt11.datarows.count > 0 Then \'如果有数据,就操作,反之不操作 output.show(dr11("纸张宽度")) 这里可以输出值 Dim doc As New PrintDoc() \'定义一个报表 doc.PageSetting.Width = dr11("纸张宽度") \'纸张宽度 这里就开始提示错误 doc.PageSetting.Height = dr11("纸张高度") \'纸张高度 Doc.PrinterName = dr11("二维码打印机") \'设定打印机为当前选择的打印机\' output.show(dr11("二维码打印机")) Dim img As prt.RenderImage \'定义一个图像\' Dim Bar As New BarCodeBuilder Bar.Symbology = Barpro.Symbology.QRCode Bar.BarWidth = dr11("二维码宽度") Bar.BarHeight = dr11("二维码高度") Bar.QuietZoneWidth = dr11("二维码静区") Bar.QRCodeModuleSize = dr11("模组尺寸") Doc.Stacking = prt.StackingRulesEnum.InlineLeftToRight Bar.Code = dr11("二维码文本") img = new prt.RenderImage img.Image = bar.GetImage img.X=dr11("图片x") img.y=dr11("图片Y") img.Width = dr11("图片高度") \'宽度等于页面宽度 img.Height = dr11("图片宽度") \'\'高度由图片大小自动决定 Doc.Body.Children.Add(img) If dr11("打印或预览")="打印" Then doc.Print Else doc.Preview() End If End If
|
-- 作者:cnsjroom
-- 发布时间:2022/10/9 17:50:00
-- 回复:(有点蓝)doc.PageSetting.Width = cint(dr11(...
好的 谢谢老师
Doc.PrinterName 这个有时候指定的 dr("二维码打印机") 的值 可能在本机电脑上不存在
要怎么判断dr("二维码打印机") 在本地电脑中有 才执行报表打印呢?
当前代码:
Dim guid As String = Args(0) Dim cmd As new SQ LCommand cmd.Con nection Name="主数据源" cmd.Comman dText = "sel ect * from {SYS_二维码参数及标签打印机设置} " Dim dt11 As DataTable = cmd.ExecuteReader() Dim dr11 As DataRow = dt11.DataRows(0) output.show(1) Dim fl As String If dt11.datarows.count > 0 Then \'如果有数据,就操作,反之不操作 output.show(dr11("纸张宽度")) Dim doc As New PrintDoc() \'定义一个报表 doc.PageSetting.Width = cint(dr11("纸张宽度")) \'纸张宽度 doc.PageSetting.Height = cint(dr11("纸张高度")) \'纸张高度 Doc.PrinterName = dr11("二维码打印机") \'设定打印机为当前选择的打印机\' output.show(dr11("二维码打印机")) Dim img As prt.RenderImage \'定义一个图像\' Dim Bar As New BarCodeBuilder Bar.Symbology = Barpro.Symbology.QRCode Bar.BarWidth = cint(dr11("二维码宽度")) Bar.BarHeight = cint(dr11("二维码高度")) Bar.QuietZoneWidth = cint(dr11("二维码静区")) Bar.QRCodeModuleSize = dr11("模组尺寸") Doc.Stacking = prt.StackingRulesEnum.InlineLeftToRight For Each p As String In InstalledPrinters If dr11("二维码打印机")=p Then cmd.Comma ndText = "sel e ct * from {XX_设备台账} where guid=\'" & guid & "\' " Dim dt111 As DataTable = cmd.ExecuteReader() Dim dr111 As DataRow = dt111.DataRows(0) If dt111.datarows.count > 0 Then fl = ProjectPath & "Reports\\" & dr111("设备编号") & "二维码.jpg" Bar.Code = dr111("设备编号") img = new prt.RenderImage img.Image = bar.GetImage img.X=cint(dr11("图片x")) img.y=cint(dr11("图片Y")) img.Width = cint(dr11("图片高度")) \'宽度等于页面宽度 img.Height = cint(dr11("图片宽度"))\'\'高度由图片大小自动决定 Doc.Body.Children.Add(img) doc.Print End If End If Next End If
运行总提示:【有没有办法修正上述代码 当指定的二维码打印机在本地不存在的时候 让如下的两个提示都不再有呢】
此主题相关图片如下:123.png
|
-- 作者:cnsjroom
-- 发布时间:2022/10/9 23:58:00
-- 回复:(有点蓝)参考:http://www.foxtable.com/webh...
谢谢 按老师指导:如果当前二维码打印机不存在 还是会提示如图 开始打印……及对应错误代码
麻烦老师继续指导下 谢谢!不想弹出开始打印……
详细错误代码:
错误的事件名称自定义函数,二维码打印 System.Reflection.TargetInvocationException: 调用的目标发生了异常。 ---> System.ComponentModel.Win32Exception: 已删除指定的打印机。 在 System.Drawing.Printing.StandardPrintController.OnStartPrint(PrintDocument document, PrintEventArgs e) 在 System.Drawing.Printing.PrintController.Print(PrintDocument document) 在 System.Drawing.Printing.PrintDocument.Print() 在 C1.C1Preview.C1PrintManager.Print(PrinterSettings printerSettings, PageSettings defaultPageSettings) 在 Foxtable.PrintDoc.Print() 在 UserCode.Ame3oeOl4rui6jRif(Object[] Args) --- 内部异常堆栈跟踪的结尾 --- 在 System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor) 在 System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments) 在 System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) 在 Foxtable.UserFunctions.Execute(String Name, Object[] Args) 2022-10-10 00:09:39
当前代码如下:
Dim guid As String = Args(0) \'Dim erweimadayinji As String = Args(1) Dim cmd As new SQLCommand cmd.Conne ctionN ame="主数据源" cmd.Com mand Text = "sele ct * from {SYS_二维码参数及标签打印机设置} " \'where 二维码打印机=\'" & erweimadayinji & "\'" Dim dt11 As DataTable = cmd.ExecuteReader() Dim dr11 As DataRow = dt11.DataRows(0) output.show(1) Dim fl As String If dt11.datarows.count > 0 Then \'如果有数据,就操作,反之不操作 output.show(dr11("纸张宽度")) Dim doc As New PrintDoc() \'定义一个报表 doc.PageSetting.Width = cint(dr11("纸张宽度")) \'纸张宽度 doc.PageSetting.Height = cint(dr11("纸张高度")) \'纸张高度 Doc.PrinterName = dr11("二维码打印机") \'设定打印机为当前选择的打印机\' output.show(dr11("二维码打印机")) Dim img As prt.RenderImage \'定义一个图像\' Dim Bar As New BarCodeBuilder Bar.Symbology = Barpro.Symbology.QRCode Bar.BarWidth = cint(dr11("二维码宽度")) Bar.BarHeight = cint(dr11("二维码高度")) Bar.QuietZoneWidth = cint(dr11("二维码静区")) Bar.QRCodeModuleSize = dr11("模组尺寸") Doc.Stacking = prt.StackingRulesEnum.InlineLeftToRight \'For Each p As String In InstalledPrinters If InstalledPrinters.Contains(dr11("二维码打印机")) Then Output.Show(InstalledPrinters.Contains(dr11("二维码打印机"))) cmd.Comm andText = "sel ect * from {XX_设备台账} where guid=\'" & guid & "\' " Dim dt111 As DataTable = cmd.ExecuteReader() Dim dr111 As DataRow = dt111.DataRows(0) If dt111.datarows.count > 0 Then fl = ProjectPath & "Reports\\" & dr111("设备编号") & "二维码.jpg" Bar.Code = dr111("设备编号") img = new prt.RenderImage img.Image = bar.GetImage img.X=cint(dr11("图片x")) img.y=cint(dr11("图片Y")) img.Width = cint(dr11("图片高度")) \'宽度等于页面宽度 img.Height = cint(dr11("图片宽度"))\'\'高度由图片大小自动决定 Doc.Body.Children.Add(img) doc.Print End If End If \'Next End If
[此贴子已经被作者于2022/10/10 0:09:43编辑过]
|