Skip to content

Commit

Permalink
add
Browse files Browse the repository at this point in the history
  • Loading branch information
850715177 committed Aug 7, 2019
1 parent 0a3979e commit bd42c5c
Show file tree
Hide file tree
Showing 18 changed files with 262 additions and 7 deletions.
Binary file modified Utility基础类大全/.vs/Common.Utility/v16/.suo
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
7 changes: 6 additions & 1 deletion Utility基础类大全/Common.Utility.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
<Reference Include="Microsoft.ReportViewer.WebDesign, Version=15.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91, processorArchitecture=MSIL">
<HintPath>packages\Microsoft.ReportingServices.ReportViewerControl.WebForms.150.1358.0\lib\net40\Microsoft.ReportViewer.WebDesign.dll</HintPath>
</Reference>
<Reference Include="Microsoft.ReportViewer.WebForms, Version=15.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91, processorArchitecture=MSIL">
<Reference Include="Microsoft.ReportViewer.WebForms">
<HintPath>packages\Microsoft.ReportingServices.ReportViewerControl.WebForms.150.1358.0\lib\net40\Microsoft.ReportViewer.WebForms.dll</HintPath>
</Reference>
<Reference Include="Microsoft.SqlServer.Types, Version=14.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91, processorArchitecture=MSIL">
Expand Down Expand Up @@ -117,6 +117,9 @@
<HintPath>packages\Quartz.2.4.1\lib\net40\Quartz.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Seagull.BarTender.Print">
<HintPath>packages\Microsoft.ReportingServices.ReportViewerControl.WebForms.150.1358.0\lib\net40\Seagull.BarTender.Print.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.configuration" />
<Reference Include="System.Core" />
Expand All @@ -135,6 +138,8 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="RDLC直接打印帮助类\BartenderHelper.cs" />
<Compile Include="RDLC直接打印帮助类\ConfigLoad.cs" />
<Compile Include="SqlServerTypes\Loader.cs" />
<Compile Include="其他\BasePage.cs">
<SubType>ASPXCodeBehind</SubType>
Expand Down
184 changes: 184 additions & 0 deletions Utility基础类大全/RDLC直接打印帮助类/BartenderHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Common.Utility;
using Seagull.BarTender.Print;


namespace BartenderHelper
{
/// <summary>
/// bartender打印类,自带日志记录
/// * 注意:必须选择x86模式编译
/// * 使用此程序步骤如下:
/// * 1、新建类,默认构造函数会自动启动打印引擎;
/// * 2、指定标签模板和打印机,为空时获取默认值,默认标签=当前路径\BC_DEFAULT.btw,默认打印机=系统默认打印机
/// * 3、调用PrintStart。
/// * 4、设置标签:指定打印数量\打印内容,总打印次数为iQtyLabel*iQtyLot
/// iQtyLabel : 标签打印时,一个标签连续重复打印的次数
/// iQtyQty : 标签打印时,整个批次重复打印的次数
/// * lstSubStringName : 标签模板中的变量集合,至少1个
/// lstSubStringValue : 标签中的值,外层List表示不同标签的数量,内层List表示每个标签中各个SubStringName对应的值
/// * 5、调用PrintEnd,关闭标签模板。
/// * 6、关闭engine
/// * 使用建议:需要打印的程序加载时,同时新建该类,以减少engine启动的时间。关闭整个程序时再关闭engine。
/// </summary>
public class BartenderHelper
{
#region 构造方法
/// <summary>
/// 构造函数
/// </summary>
public BartenderHelper()
{

}
#endregion

#region 变量定义
/// <summary>
/// 打印引擎
/// </summary>
private Engine btEngine = new Engine(true);
/// <summary>
/// 标签文档
/// </summary>
private LabelFormatDocument btFormatDoc { get; set; }
/// <summary>
/// 标签模板路径
/// </summary>
public string sLabelNameFull { get; set; }
/// <summary>
/// 标签模板中的变量集合
/// </summary>
public List<string> lstSubStringName { get; set; }
/// <summary>
/// 需要打印的标签中的值,其中子项List<string/>需与lstSubStringName中的名称一一对应,否则数据会错位或报错
/// </summary>
public List<List<string>> lstSubStringValue { get; set; }
/// <summary>
/// 打印机名称
/// </summary>
public string sPrinterName { get; set; }
/// <summary>
/// 单个标签内容连续打印次数
/// </summary>
public int iQtyLabel { get; set; }
/// <summary>
/// 整体重复次数
/// </summary>
public int iQtyLot { get; set; }


#endregion

#region 打印方法

/// <summary>
/// 打印开始,公用程序,启动打印引擎,打开标签模板,指定打印机
/// </summary>
/// <param name="sLabel">标签名称,为空时获取默认值=当前路径\BC_DEFAULT.btw</param>
/// <param name="sPrinter">打印机名称,为空时获取系统默认打印机</param>
public void PrintStart(string sLabel, string sPrinter)
{
//启动打印引擎
btEngine.Start();
Log.Info("-- Print Engine Start OK --");
//获取默认标签完整路径
sLabelNameFull = ConfigLoad.GetLabelNameFull(sLabel);
Log.Info("-- Default label path : " + sLabelNameFull + " --");
//指定打印机名称
sPrinterName = string.IsNullOrEmpty(sPrinter) ? ConfigLoad.GetDefaultPrinterName() : sPrinter;
Log.Info("-- Default Printer : " + sPrinterName + " --");
//加载标签模板,指定打印机
btFormatDoc = btEngine.Documents.Open(sLabelNameFull, sPrinterName);
Log.Info("-- FormatDoc opened --");
}

/// <summary>
/// 打印结束,公用程序,关闭标签文档/停止打印引擎
/// </summary>
public void PrintEnd()
{
//关闭标签模板
btFormatDoc.Close(SaveOptions.DoNotSaveChanges);
Log.Info("--FormatDocument closed--");
//停止打印引擎
btEngine.Stop();
Log.Info("--Print Engine Stop--");
}

/// <summary>
/// 打印标签
/// </summary>
public void PrintLabel()
{
//设置参数
//更改单个标签打印数量,默认为1
try
{
iQtyLabel = iQtyLabel > 0 ? iQtyLabel : 1;
}
catch (Exception)
{
iQtyLabel = 1;
}
btFormatDoc.PrintSetup.IdenticalCopiesOfLabel = iQtyLabel;
Log.Info("-- Label repeat Qty = " + iQtyLabel + "; --");

//更改打印批次数量,默认为1
try
{
iQtyLot = iQtyLot > 0 ? iQtyLot : 1;
}
catch (Exception)
{
iQtyLot = 1;
}
Log.Info("-- Lot repeat qty = " + iQtyLot + "; --");

for (int iLot = 0; iLot < iQtyLot; iLot++)
{
//有标签内容时的打印
if (lstSubStringName != null && lstSubStringValue != null)
{
//更改标签内容并打印
for (int iValue = 0; iValue < lstSubStringValue.Count; iValue++)
{
string sLabelValue = "[";
for (int iName = 0; iName < lstSubStringName.Count; iName++)
{
btFormatDoc.SubStrings[lstSubStringName[iName]].Value = lstSubStringValue[iValue][iName];
sLabelValue += lstSubStringName[iName] + "=" + lstSubStringValue[iValue][iName] + ";";
}
sLabelValue += "]";
if (iLot == 0)
{
Log.Info("-- Label " + iValue + ":" + sLabelValue + " --");
Log.Info("-- PrintJob start : PrintJob" + iValue + " --");
}
btFormatDoc.Print("PrintJob" + iValue);
if (iLot == 0)
{
Log.Info("-- PrintJob finish : PrintJob" + iValue + " --");
}
}
}
//没有指定标签内容时,直接打印标签模板文件
else
{
if (iLot == 0)
{
Log.Info("-- Print default .btw file directly --");
Log.Info("-- PrintJob start : PrintJob1 --");
}
btFormatDoc.Print("PrintJob1");
if (iLot == 0) Log.Info("-- PrintJob finish : PrintJob1 --");
}
}
}

#endregion
}
}
63 changes: 63 additions & 0 deletions Utility基础类大全/RDLC直接打印帮助类/ConfigLoad.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
using System;
using System.Drawing.Printing;
using System.IO;
using System.Reflection;

namespace BartenderHelper
{
/// <summary>
/// 获取标签模板的完整路径
/// </summary>
public class ConfigLoad
{
/// <summary>
/// 获取标签模板的完整路径
/// </summary>
/// <param name="sLabelName">文件名,带后缀,如果不传则默认为"BC_DEFAULT.btw"</param>
/// <returns>返回标签的完整路径</returns>
public static string GetLabelNameFull(string sLabelName)
{
//获取当前程序集的路径
string sPathFolder = Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath);
string sLabel = string.Empty;
if (string.IsNullOrEmpty(sLabelName) && sLabelName.Substring(sLabelName.LastIndexOf(".") + 1) != "btw")
{
sLabel = sPathFolder + "\\" + "BC_DEFAULT.btw";
}
else
{
sLabel = (sPathFolder + "\\" + sLabelName);
}
if (string.IsNullOrEmpty(sLabel))
throw new Exception("LabelName is null");
if (!File.Exists(sLabel))
throw new Exception("LabelName not exists : " + sLabel);
return sLabel;
}

/// <summary>
/// 获取默认打印机名称
/// </summary>
/// <returns></returns>
public static string GetDefaultPrinterName()
{
PrintDocument fPrintDoc = new PrintDocument();
return fPrintDoc.PrinterSettings.PrinterName;
}

/// <summary>
/// 获取本地打印机列表
/// </summary>
/// <returns></returns>
public static string[] GetLocalPrinterList()
{
string[] ListPrinter = new string[PrinterSettings.InstalledPrinters.Count];
//获取当前打印机
for (int i = 0; i < PrinterSettings.InstalledPrinters.Count; i++)
{
ListPrinter[i] = (PrinterSettings.InstalledPrinters[i].ToString());
}
return ListPrinter;
}
}
}
11 changes: 6 additions & 5 deletions Utility基础类大全/RDLC直接打印帮助类/PrintHelper.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.IO;

using Microsoft.Reporting.WebForms;
using System.Drawing.Printing;
using System.Drawing.Imaging;
using System.Text;
using System.Data;
using Microsoft.Reporting.WinForms;
using Microsoft.Reporting.WebForms;





/// <summary>
/// 打印帮助类
/// </summary>
Expand Down
Binary file modified Utility基础类大全/bin/Debug/DotNet.Utilities.dll
Binary file not shown.
Binary file modified Utility基础类大全/bin/Debug/DotNet.Utilities.pdb
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
550ae6a88e6f04ccf93b21172339f3757ddede8e
5c8deb1898ad3aa3bcafc3f80aeed4defa7a7a9e
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,5 @@ C:\Users\Administrator\source\repos\Jimmey-Jiang\Common.Utility\Utility基础类
C:\Users\Administrator\source\repos\Jimmey-Jiang\Common.Utility\Utility基础类大全\obj\Debug\Common.Utility.csproj.CopyComplete
C:\Users\Administrator\source\repos\Jimmey-Jiang\Common.Utility\Utility基础类大全\obj\Debug\DotNet.Utilities.dll
C:\Users\Administrator\source\repos\Jimmey-Jiang\Common.Utility\Utility基础类大全\obj\Debug\DotNet.Utilities.pdb
C:\Users\Administrator\source\repos\Jimmey-Jiang\Common.Utility\Utility基础类大全\obj\Debug\Common.Utility.csprojAssemblyReference.cache
C:\Users\Administrator\source\repos\Jimmey-Jiang\Common.Utility\Utility基础类大全\bin\Debug\Seagull.BarTender.Print.dll
Binary file not shown.
Binary file not shown.
Binary file modified Utility基础类大全/obj/Debug/DotNet.Utilities.dll
Binary file not shown.
Binary file modified Utility基础类大全/obj/Debug/DotNet.Utilities.pdb
Binary file not shown.
Binary file not shown.

0 comments on commit bd42c5c

Please sign in to comment.