You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
739 lines
36 KiB
739 lines
36 KiB
using BarcodeLib;
|
|
using BBWY.Client.Extensions;
|
|
using BBWY.Client.Models;
|
|
using BBWY.Client.Models.FallWare;
|
|
using BBWY.Client.Models.PackTask;
|
|
using NPOI.XSSF.UserModel;
|
|
using Spire.Xls;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Drawing;
|
|
using System.Drawing.Imaging;
|
|
using System.Drawing.Printing;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
using System.Runtime.InteropServices;
|
|
using System.Text;
|
|
using System.Windows.Media.Imaging;
|
|
using WebSocketSharp;
|
|
|
|
namespace BBWY.Client.Helpers
|
|
{
|
|
public class MyPrintHelper
|
|
{
|
|
|
|
public static void PrintBarcode(ref PrintPageEventArgs args, BarCodeModel barCode, Font font)
|
|
{
|
|
args.Graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
|
|
args.Graphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
|
|
var sige = args.Graphics.VisibleClipBounds;// 宽:236 高:157 打印可视化区域
|
|
args.Graphics.TranslateTransform((sige.Width - 236) / 2, 0);//设置起始位置
|
|
//args.Graphics.DrawRectangle(new System.Drawing.Pen(System.Drawing.Brushes.Black), 0, 0, sige.Width, sige.Height);//画出条码编辑区域
|
|
args.Graphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
|
|
args.Graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
|
|
|
|
switch (barCode.LabelModel)
|
|
{
|
|
case BarcodeLabelModel.标准模板:
|
|
font = new Font("宋体", 8, System.Drawing.FontStyle.Regular);
|
|
SetBar(barCode, ref args, font, 5);
|
|
//SetBarStander(barCode, ref args, font);
|
|
break;
|
|
case BarcodeLabelModel.精简模板:
|
|
font = new Font("宋体", 10, System.Drawing.FontStyle.Regular);
|
|
//SetBar(barCode, ref args, font, 15);
|
|
|
|
SetBarSimplify(barCode, ref args, font);
|
|
break;
|
|
case BarcodeLabelModel.无型号模板:
|
|
font = new Font("宋体", 10, System.Drawing.FontStyle.Regular);
|
|
SetBar(barCode, ref args, font, 7);
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
private static void SetBar(BarCodeModel barCode, ref PrintPageEventArgs args, Font font, int heightSpace)
|
|
{
|
|
|
|
|
|
float topHeigth = 0;//与顶部的距离
|
|
string barcodeSku = $"POP{barCode.SkuId}";
|
|
Barcode barcode = new Barcode();
|
|
System.Drawing.Image img = barcode.Encode(TYPE.CODE128, barcodeSku, 500, 40);
|
|
SizeF size = args.Graphics.MeasureString(barCode.BrandName, font);
|
|
var sizeHeight = size.Height;//字体高度
|
|
topHeigth += 10;
|
|
|
|
switch (barCode.LabelModel)
|
|
{
|
|
case BarcodeLabelModel.无型号模板:
|
|
case BarcodeLabelModel.标准模板:
|
|
args.Graphics.DrawString($"品牌: {barCode.Brand}", font, System.Drawing.Brushes.Black, new PointF(10, topHeigth));
|
|
topHeigth += (heightSpace + sizeHeight);
|
|
break;
|
|
case BarcodeLabelModel.精简模板:
|
|
break;
|
|
}
|
|
|
|
|
|
|
|
|
|
args.Graphics.DrawString($"品名: {barCode.BrandName}", font, System.Drawing.Brushes.Black, new PointF(10, topHeigth));
|
|
topHeigth += (heightSpace + sizeHeight);
|
|
|
|
|
|
switch (barCode.LabelModel)
|
|
{
|
|
case BarcodeLabelModel.标准模板:
|
|
args.Graphics.DrawString($"型号: {barCode.ProductNo}", font, System.Drawing.Brushes.Black, new PointF(10, topHeigth));
|
|
topHeigth += (heightSpace + sizeHeight);
|
|
break;
|
|
case BarcodeLabelModel.无型号模板:
|
|
case BarcodeLabelModel.精简模板:
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
args.Graphics.DrawString($"规格: {barCode.SkuName}", font, System.Drawing.Brushes.Black, new PointF(10, topHeigth));
|
|
// g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
|
|
size = args.Graphics.MeasureString(barcodeSku, font);
|
|
topHeigth += (heightSpace + sizeHeight);
|
|
args.Graphics.DrawImage(img, 1, topHeigth, 234, 50);
|
|
topHeigth += (50 + 5);
|
|
args.Graphics.DrawString(barcodeSku, font, System.Drawing.Brushes.Black, new PointF((236 - size.Width) / 2, topHeigth));
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// 标准
|
|
/// </summary>
|
|
/// <param name="barCode"></param>
|
|
/// <param name="args"></param>
|
|
/// <param name="font"></param>
|
|
private static void SetBarStander(BarCodeModel barCode, ref PrintPageEventArgs args, Font font)
|
|
{
|
|
float topHeigth = 0;//与顶部的距离
|
|
string barcodeSku = $"POP{barCode.SkuId}";
|
|
Barcode barcode = new Barcode();
|
|
System.Drawing.Image img = barcode.Encode(TYPE.CODE128, barcodeSku, 500, 40);
|
|
SizeF size = args.Graphics.MeasureString(barCode.BrandName, font);
|
|
var sizeHeight = size.Height;//字体高度
|
|
var heightSpace = 5;//间隔高度
|
|
topHeigth += 10;
|
|
args.Graphics.DrawString($"品牌: {barCode.Brand}", font, System.Drawing.Brushes.Black, new PointF(10, topHeigth));
|
|
topHeigth += (heightSpace + sizeHeight);
|
|
args.Graphics.DrawString($"品名: {barCode.BrandName}", font, System.Drawing.Brushes.Black, new PointF(10, topHeigth));
|
|
topHeigth += (heightSpace + sizeHeight);
|
|
args.Graphics.DrawString($"型号: {barCode.ProductNo}", font, System.Drawing.Brushes.Black, new PointF(10, topHeigth));
|
|
topHeigth += (heightSpace + sizeHeight);
|
|
args.Graphics.DrawString($"规格: {barCode.SkuName}", font, System.Drawing.Brushes.Black, new PointF(10, topHeigth));
|
|
// g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
|
|
size = args.Graphics.MeasureString(barcodeSku, font);
|
|
topHeigth += (heightSpace + sizeHeight);
|
|
args.Graphics.DrawImage(img, 1, topHeigth, 234, 50);
|
|
topHeigth += (50 + 5);
|
|
args.Graphics.DrawString(barcodeSku, font, System.Drawing.Brushes.Black, new PointF((236 - size.Width) / 2, topHeigth));
|
|
|
|
}
|
|
/// <summary>
|
|
/// 精简
|
|
/// </summary>
|
|
/// <param name="barCode"></param>
|
|
/// <param name="args"></param>
|
|
/// <param name="font"></param>
|
|
private static void SetBarSimplify(BarCodeModel barCode, ref PrintPageEventArgs args, Font font)
|
|
{
|
|
string barcodeSku = $"POP{barCode.SkuId}";
|
|
Barcode barcode = new Barcode();
|
|
System.Drawing.Image img = barcode.Encode(TYPE.CODE128, barcodeSku, 500, 60);
|
|
args.Graphics.DrawString($"品名: {barCode.BrandName}", font, System.Drawing.Brushes.Black, new PointF(10, 10));
|
|
args.Graphics.DrawString($"规格: {barCode.SkuName}", font, System.Drawing.Brushes.Black, new PointF(10, 40));
|
|
// g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
|
|
SizeF size = args.Graphics.MeasureString(barcodeSku, font);
|
|
args.Graphics.DrawString(barcodeSku, font, System.Drawing.Brushes.Black, new PointF((236 - size.Width) / 2, 130));
|
|
args.Graphics.DrawImage(img, 1, 68, 234, 60);
|
|
}
|
|
|
|
public static void PrintCertificate(ref PrintPageEventArgs args, CertificateModel certificate, Font font)
|
|
{
|
|
|
|
|
|
|
|
args.Graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
|
|
args.Graphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
|
|
var sige = args.Graphics.VisibleClipBounds;// 宽:236 高:157 打印可视化区域
|
|
args.Graphics.TranslateTransform((sige.Width - 236) / 2, 0);//设置起始位置
|
|
args.Graphics.DrawRectangle(new System.Drawing.Pen(System.Drawing.Brushes.Black), 5, 5, sige.Width - 10, sige.Height - 10);//画出条码编辑区域
|
|
args.Graphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
|
|
args.Graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
|
|
|
|
font = new Font("宋体", 6, System.Drawing.FontStyle.Regular);
|
|
switch (certificate.LabelModel)
|
|
{
|
|
case CertificateLabelModel.标准无3c:
|
|
case CertificateLabelModel.标准有3c:
|
|
SetCerStander(ref args, certificate, font);
|
|
break;
|
|
case CertificateLabelModel.无型号:
|
|
SetCerNoXingHao(ref args, certificate, font);
|
|
break;
|
|
case CertificateLabelModel.适用年龄:
|
|
SetCerNoXingHao(ref args, certificate, font);
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
private static void SetCerStander(ref PrintPageEventArgs args, CertificateModel certificate, Font font)
|
|
{
|
|
|
|
//#if DEBUG
|
|
// Bitmap bitmap = new Bitmap(236, 157);
|
|
// // Bitmap bitmap = new Bitmap(500, 500);
|
|
// Graphics graphics = Graphics.FromImage(bitmap);
|
|
|
|
// var sige = graphics.VisibleClipBounds;// 宽:236 高:157 打印可视化区域
|
|
// graphics.TranslateTransform((sige.Width - 236) / 2, 0);//设置起始位置
|
|
// graphics.DrawRectangle(new System.Drawing.Pen(System.Drawing.Brushes.Black), 5, 5, sige.Width - 10, sige.Height - 10);//画出条码编辑区域
|
|
// int bigJiange = 20;//合格证与品牌的高度差
|
|
// var heightSpace = 4;//所有行间隔高度
|
|
// if (!string.IsNullOrEmpty(certificate.ProduceDate))
|
|
// {
|
|
// bigJiange = 10; heightSpace = 3;
|
|
// }
|
|
|
|
// int standerSpace = 1;//执行标准之间的
|
|
// if (certificate.IsLogo == 1)//含图标
|
|
// {
|
|
// string appPath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
|
|
// string path = appPath + $"/Resources/Images/3c.png";
|
|
// Image image = Image.FromFile(path);
|
|
// graphics.DrawImage(image, 190, 7, 28, 21);
|
|
// graphics.DrawString(certificate.FactoryNumber, font, System.Drawing.Brushes.Black, 188, 28);
|
|
// }
|
|
|
|
// var fontBig = new Font("宋体", 14, System.Drawing.FontStyle.Regular);
|
|
// string cerName = "合格证";
|
|
// SizeF bigSize = graphics.MeasureString(cerName, fontBig);
|
|
|
|
// float verHeight = bigJiange + bigSize.Height;
|
|
// graphics.DrawString(cerName, fontBig, System.Drawing.Brushes.Black, new PointF((236 - bigSize.Width) / 2, 10));
|
|
|
|
// graphics.DrawString($"品牌: {certificate.Brand}", font, System.Drawing.Brushes.Black, new PointF(10, verHeight));
|
|
// if (!string.IsNullOrEmpty(certificate.ProductNo))
|
|
// graphics.DrawString($"型号: {certificate.ProductNo}", font, System.Drawing.Brushes.Black, new PointF(122, verHeight));
|
|
// var smallSize = graphics.MeasureString(certificate.Brand, font);//小字体高度
|
|
|
|
// verHeight += (smallSize.Height + heightSpace);
|
|
// graphics.DrawString($"品名: {certificate.BrandName}", font, System.Drawing.Brushes.Black, new PointF(10, verHeight));
|
|
|
|
// graphics.DrawString($"材质: {certificate.Shader}", font, System.Drawing.Brushes.Black, new PointF(122, verHeight));
|
|
|
|
// StringBuilder sb = new StringBuilder();
|
|
// var excutes = certificate.ExcuteStander.Split(new string[] { ",", "," }, StringSplitOptions.RemoveEmptyEntries);
|
|
// int hangCount = excutes.Count() / 2 + excutes.Count() % 2;//获取行数
|
|
|
|
// for (int i = 0; i < excutes.Count(); i++)
|
|
// {
|
|
// if (i % 2 == 0 && i > 0)//间隔两个换行
|
|
// {
|
|
// sb.Append("\n");
|
|
// }
|
|
// sb.Append(excutes[i]).Append(" ");
|
|
// }
|
|
// sb.Remove(sb.Length - 3, 3);
|
|
// var rows = sb.ToString().Split('\n');
|
|
// string excuteStander = "执行标准: ";
|
|
// smallSize = graphics.MeasureString(excuteStander, font);
|
|
// verHeight += (smallSize.Height + heightSpace);
|
|
// graphics.DrawString($"执行标准: {rows[0]}", font, System.Drawing.Brushes.Black, new PointF(10, verHeight));
|
|
|
|
// for (int i = 1; i < rows.Count(); i++)
|
|
// {
|
|
// verHeight += (smallSize.Height + standerSpace);
|
|
// graphics.DrawString($"{rows[i]}", font, System.Drawing.Brushes.Black, new PointF(12 + smallSize.Width, verHeight));
|
|
// }
|
|
|
|
// if (!string.IsNullOrEmpty(certificate.ProduceDate))
|
|
// {
|
|
// verHeight += (smallSize.Height + heightSpace) - 3;
|
|
// graphics.DrawString($"生产日期: {certificate.ProduceDate}", font, System.Drawing.Brushes.Black, new PointF(10, verHeight));
|
|
// }
|
|
|
|
// verHeight += (smallSize.Height + heightSpace);
|
|
// RectangleF rect = new RectangleF(10, verHeight, 220, smallSize.Height * 2 + heightSpace);
|
|
// var productStr = $"生产商: {certificate.ProductShop}";
|
|
// if (graphics.MeasureString(productStr, font).Width <= 220)
|
|
// {
|
|
// graphics.DrawString(productStr, font, System.Drawing.Brushes.Black, 10, verHeight);
|
|
// verHeight += smallSize.Height + heightSpace;
|
|
// }
|
|
// else
|
|
// {
|
|
// graphics.DrawString(productStr, font, System.Drawing.Brushes.Black, rect);
|
|
// verHeight += 2 * smallSize.Height + heightSpace;
|
|
// }
|
|
// var productShop = graphics.MeasureString("生产商", font);
|
|
// var adress = graphics.MeasureString("地 址", font);
|
|
|
|
// var rect1 = new RectangleF(10 + productShop.Width - adress.Width, verHeight - 2, 220, smallSize.Height * 3 + heightSpace);
|
|
// graphics.DrawString($"地 址: {certificate.ProductAdress}", font, System.Drawing.Brushes.Black, rect1);
|
|
|
|
// var applicationPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
|
|
// bitmap.Save($"{applicationPath}/{certificate.LabelModel}-{certificate.GoodsNumber}.jpg", ImageFormat.Png);
|
|
|
|
|
|
int bigJiange = 20;//合格证与品牌的高度差
|
|
var heightSpace = 4;//所有行间隔高度
|
|
int standerSpace = 1;//执行标准之间的
|
|
|
|
if (!string.IsNullOrEmpty(certificate.ProduceDate))
|
|
{
|
|
bigJiange = 10; heightSpace = 3;
|
|
}
|
|
|
|
if (certificate.IsLogo == 1)//含图标
|
|
{
|
|
string appPath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
|
|
|
|
string path = appPath + $"/Resources/Images/3c.png";
|
|
Image image = Image.FromFile(path);
|
|
args.Graphics.DrawImage(image, 190, 7, 28, 21);
|
|
args.Graphics.DrawString(certificate.FactoryNumber, font, System.Drawing.Brushes.Black, 188, 28);
|
|
|
|
}
|
|
|
|
var fontBig = new Font("宋体", 14, System.Drawing.FontStyle.Regular);
|
|
string cerName = "合格证";
|
|
SizeF bigSize = args.Graphics.MeasureString(cerName, fontBig);
|
|
|
|
float verHeight = bigJiange + bigSize.Height;
|
|
args.Graphics.DrawString(cerName, fontBig, System.Drawing.Brushes.Black, new PointF((236 - bigSize.Width) / 2, 10));
|
|
|
|
args.Graphics.DrawString($"品牌: {certificate.Brand}", font, System.Drawing.Brushes.Black, new PointF(10, verHeight));
|
|
if (!string.IsNullOrEmpty(certificate.ProductNo))
|
|
args.Graphics.DrawString($"型号: {certificate.ProductNo}", font, System.Drawing.Brushes.Black, new PointF(122, verHeight));
|
|
var smallSize = args.Graphics.MeasureString(certificate.Brand, font);//小字体高度
|
|
|
|
verHeight += (smallSize.Height + heightSpace);
|
|
args.Graphics.DrawString($"品名: {certificate.BrandName}", font, System.Drawing.Brushes.Black, new PointF(10, verHeight));
|
|
|
|
args.Graphics.DrawString($"材质: {certificate.Shader}", font, System.Drawing.Brushes.Black, new PointF(122, verHeight));
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
var excutes = certificate.ExcuteStander.Split(new string[] { ",", "," }, StringSplitOptions.RemoveEmptyEntries);
|
|
int hangCount = excutes.Count() / 2 + excutes.Count() % 2;//获取行数
|
|
|
|
for (int i = 0; i < excutes.Count(); i++)
|
|
{
|
|
if (i % 2 == 0 && i > 0)//间隔两个换行
|
|
{
|
|
sb.Append("\n");
|
|
}
|
|
sb.Append(excutes[i]).Append(" ");
|
|
}
|
|
sb.Remove(sb.Length - 3, 3);
|
|
var rows = sb.ToString().Split('\n');
|
|
string excuteStander = "执行标准: ";
|
|
smallSize = args.Graphics.MeasureString(excuteStander, font);
|
|
verHeight += (smallSize.Height + heightSpace);
|
|
args.Graphics.DrawString($"执行标准: {rows[0]}", font, System.Drawing.Brushes.Black, new PointF(10, verHeight));
|
|
|
|
for (int i = 1; i < rows.Count(); i++)
|
|
{
|
|
verHeight += (smallSize.Height + standerSpace) - 3;
|
|
args.Graphics.DrawString($"{rows[i]}", font, System.Drawing.Brushes.Black, new PointF(10 + smallSize.Width, verHeight));
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(certificate.ProduceDate))
|
|
{
|
|
verHeight += (smallSize.Height + heightSpace);
|
|
args.Graphics.DrawString($"生产日期: {certificate.ProduceDate}", font, System.Drawing.Brushes.Black, new PointF(10, verHeight));
|
|
}
|
|
|
|
verHeight += (smallSize.Height + heightSpace);
|
|
RectangleF rect = new RectangleF(10, verHeight, 220, smallSize.Height * 2 + heightSpace);
|
|
var productStr = $"生产商: {certificate.ProductShop}";
|
|
if (args.Graphics.MeasureString(productStr, font).Width <= 220)
|
|
{
|
|
args.Graphics.DrawString(productStr, font, System.Drawing.Brushes.Black, 10, verHeight);
|
|
verHeight += smallSize.Height + heightSpace;
|
|
}
|
|
else
|
|
{
|
|
args.Graphics.DrawString(productStr, font, System.Drawing.Brushes.Black, rect);
|
|
verHeight += 2 * smallSize.Height + heightSpace;
|
|
}
|
|
var productShop = args.Graphics.MeasureString("生产商", font);
|
|
var adress = args.Graphics.MeasureString("地 址", font);
|
|
|
|
var rect1 = new RectangleF(10 + productShop.Width - adress.Width, verHeight - 2, 220, smallSize.Height * 3 + heightSpace);
|
|
args.Graphics.DrawString($"地 址: {certificate.ProductAdress}", font, System.Drawing.Brushes.Black, rect1);
|
|
|
|
|
|
|
|
|
|
}
|
|
private static void SetCerNoXingHao(ref PrintPageEventArgs args, CertificateModel certificate, Font font)
|
|
{
|
|
|
|
|
|
//Bitmap bitmap = new Bitmap(236, 157);
|
|
//Graphics graphics = Graphics.FromImage(bitmap);
|
|
//graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
|
|
//graphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
|
|
//var sige = graphics.VisibleClipBounds;// 宽:236 高:157 打印可视化区域
|
|
//graphics.TranslateTransform((sige.Width - 236) / 2, 0);//设置起始位置
|
|
//graphics.DrawRectangle(new System.Drawing.Pen(System.Drawing.Brushes.Black), 5, 5, sige.Width - 10, sige.Height - 10);//画出条码编辑区域
|
|
//graphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
|
|
//graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
|
|
//var twoWidth = graphics.MeasureString("适用", font);
|
|
//var oneWidth = graphics.MeasureString("适", font);
|
|
|
|
//int bigJiange = 20;//合格证与品牌的高度差
|
|
//if (!string.IsNullOrEmpty(certificate.ProduceDate)) bigJiange = 10;
|
|
//var heightSpace = 4;//所有行间隔高度
|
|
//int standerSpace = 1;//执行标准之间的
|
|
//var fontBig = new Font("宋体", 14, System.Drawing.FontStyle.Regular);
|
|
//string cerName = "合格证";
|
|
//SizeF bigSize = graphics.MeasureString(cerName, fontBig);
|
|
|
|
//float verHeight = bigJiange + bigSize.Height;
|
|
//graphics.DrawString(cerName, fontBig, System.Drawing.Brushes.Black, new PointF((236 - bigSize.Width) / 2, 10));
|
|
|
|
//graphics.DrawString($"品牌: {certificate.Brand}", font, System.Drawing.Brushes.Black, new PointF(10, verHeight));
|
|
//graphics.DrawString($"品名: {certificate.BrandName}", font, System.Drawing.Brushes.Black, new PointF(122, verHeight));
|
|
//var smallSize = graphics.MeasureString(certificate.BrandName, font);//小字体高度
|
|
|
|
//verHeight += (smallSize.Height + heightSpace);
|
|
//graphics.DrawString($"材质: {certificate.Shader}", font, System.Drawing.Brushes.Black, new PointF(10, verHeight));
|
|
|
|
//switch (certificate.LabelModel)
|
|
//{
|
|
// case CertificateLabelModel.标准无3c:
|
|
// break;
|
|
// case CertificateLabelModel.标准有3c:
|
|
// break;
|
|
// case CertificateLabelModel.无型号:
|
|
// break;
|
|
// case CertificateLabelModel.适用年龄:
|
|
|
|
|
|
// graphics.DrawString($"适用年龄: {certificate.ApplyAge}", font, System.Drawing.Brushes.Black, new PointF(125 - twoWidth.Width, verHeight));
|
|
// break;
|
|
// default:
|
|
// break;
|
|
//}
|
|
|
|
////graphics.DrawString($"材质: {certificate.Shader}", font, System.Drawing.Brushes.Black, new PointF(122, verHeight));
|
|
|
|
//StringBuilder sb = new StringBuilder();
|
|
//var excutes = certificate.ExcuteStander.Split(new string[] { ",", "," }, StringSplitOptions.RemoveEmptyEntries);
|
|
//int hangCount = excutes.Count() / 2 + excutes.Count() % 2;//获取行数
|
|
//for (int i = 0; i < excutes.Count(); i++)
|
|
//{
|
|
// if (i % 2 == 0 && i > 0)//间隔两个换行
|
|
// {
|
|
// sb.Append("\n");
|
|
// }
|
|
// sb.Append(excutes[i]).Append(" ");
|
|
//}
|
|
//sb.Remove(sb.Length - 3, 3);
|
|
//var rows = sb.ToString().Split('\n');
|
|
//string excuteStander = "执行标准: ";
|
|
//smallSize = graphics.MeasureString(excuteStander, font);
|
|
//verHeight += (smallSize.Height + heightSpace);
|
|
//graphics.DrawString($"执行标准: {rows[0]}", font, System.Drawing.Brushes.Black, new PointF(10, verHeight));
|
|
|
|
//for (int i = 1; i < rows.Count(); i++)
|
|
//{
|
|
// verHeight += (smallSize.Height + standerSpace);
|
|
// graphics.DrawString($"{rows[i]}", font, System.Drawing.Brushes.Black, new PointF(12 + smallSize.Width, verHeight));
|
|
//}
|
|
//if (!string.IsNullOrEmpty(certificate.ProduceDate))
|
|
//{
|
|
// verHeight += (smallSize.Height + heightSpace)-3;
|
|
// graphics.DrawString($"生产日期: {certificate.ProduceDate}", font, System.Drawing.Brushes.Black, new PointF(10, verHeight));
|
|
//}
|
|
//verHeight += (smallSize.Height + heightSpace);
|
|
|
|
//RectangleF rect = new RectangleF(10, verHeight, 220, smallSize.Height * 2 + heightSpace);
|
|
//var productStr = $"生产商: {certificate.ProductShop}";
|
|
//if (graphics.MeasureString(productStr, font).Width <= 220)
|
|
//{
|
|
// graphics.DrawString(productStr, font, System.Drawing.Brushes.Black, 10, verHeight);
|
|
// verHeight += smallSize.Height + heightSpace;
|
|
//}
|
|
//else
|
|
//{
|
|
// graphics.DrawString(productStr, font, System.Drawing.Brushes.Black, rect);
|
|
// verHeight += 2 * smallSize.Height + heightSpace;
|
|
//}
|
|
//var productShop = graphics.MeasureString("生产商", font);
|
|
//var adress = graphics.MeasureString("地 址", font);
|
|
|
|
//var rect1 = new RectangleF(10 + productShop.Width - adress.Width, verHeight - 2, 220, smallSize.Height * 3 + heightSpace);
|
|
//graphics.DrawString($"地 址: {certificate.ProductAdress}", font, System.Drawing.Brushes.Black, rect1);
|
|
|
|
//var applicationPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
|
|
//bitmap.Save($"{applicationPath}/{certificate.LabelModel}-{certificate.GoodsNumber}.jpg", ImageFormat.Png);
|
|
|
|
int bigJiange = 20;//合格证与品牌的高度差
|
|
var heightSpace = 4;//所有行间隔高度
|
|
int standerSpace = 1;//执行标准之间的
|
|
if (!string.IsNullOrEmpty(certificate.ProduceDate)) bigJiange = 10;
|
|
var fontBig = new Font("宋体", 14, System.Drawing.FontStyle.Regular);
|
|
string cerName = "合格证";
|
|
SizeF bigSize = args.Graphics.MeasureString(cerName, fontBig);
|
|
|
|
float verHeight = bigJiange + bigSize.Height;
|
|
args.Graphics.DrawString(cerName, fontBig, System.Drawing.Brushes.Black, new PointF((236 - bigSize.Width) / 2, 10));
|
|
|
|
args.Graphics.DrawString($"品牌: {certificate.Brand}", font, System.Drawing.Brushes.Black, new PointF(10, verHeight));
|
|
args.Graphics.DrawString($"品名: {certificate.BrandName}", font, System.Drawing.Brushes.Black, new PointF(122, verHeight));
|
|
var smallSize = args.Graphics.MeasureString(certificate.BrandName, font);//小字体高度
|
|
|
|
verHeight += (smallSize.Height + heightSpace);
|
|
args.Graphics.DrawString($"材质: {certificate.Shader}", font, System.Drawing.Brushes.Black, new PointF(10, verHeight));
|
|
|
|
switch (certificate.LabelModel)
|
|
{
|
|
case CertificateLabelModel.标准无3c:
|
|
break;
|
|
case CertificateLabelModel.标准有3c:
|
|
break;
|
|
case CertificateLabelModel.无型号:
|
|
break;
|
|
case CertificateLabelModel.适用年龄:
|
|
|
|
var twoWidth = args.Graphics.MeasureString("适用", font);
|
|
args.Graphics.DrawString($"适用年龄: {certificate.ApplyAge}", font, System.Drawing.Brushes.Black, new PointF(122 - twoWidth.Width, verHeight));
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
|
|
//args.Graphics.DrawString($"材质: {certificate.Shader}", font, System.Drawing.Brushes.Black, new PointF(122, verHeight));
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
var excutes = certificate.ExcuteStander.Split(new string[] { ",", "," }, StringSplitOptions.RemoveEmptyEntries);
|
|
int hangCount = excutes.Count() / 2 + excutes.Count() % 2;//获取行数
|
|
for (int i = 0; i < excutes.Count(); i++)
|
|
{
|
|
if (i % 2 == 0 && i > 0)//间隔两个换行
|
|
{
|
|
sb.Append("\n");
|
|
}
|
|
sb.Append(excutes[i]).Append(" ");
|
|
}
|
|
sb.Remove(sb.Length - 3, 3);
|
|
var rows = sb.ToString().Split('\n');
|
|
string excuteStander = "执行标准: ";
|
|
smallSize = args.Graphics.MeasureString(excuteStander, font);
|
|
verHeight += (smallSize.Height + heightSpace);
|
|
args.Graphics.DrawString($"执行标准: {rows[0]}", font, System.Drawing.Brushes.Black, new PointF(10, verHeight));
|
|
|
|
for (int i = 1; i < rows.Count(); i++)
|
|
{
|
|
verHeight += (smallSize.Height + standerSpace);
|
|
args.Graphics.DrawString($"{rows[i]}", font, System.Drawing.Brushes.Black, new PointF(10 + smallSize.Width, verHeight));
|
|
}
|
|
if (!string.IsNullOrEmpty(certificate.ProduceDate))
|
|
{
|
|
verHeight += (smallSize.Height + heightSpace) - 3;
|
|
args.Graphics.DrawString($"生产日期: {certificate.ProduceDate}", font, System.Drawing.Brushes.Black, new PointF(10, verHeight));
|
|
}
|
|
verHeight += (smallSize.Height + heightSpace);
|
|
|
|
RectangleF rect = new RectangleF(10, verHeight, 220, smallSize.Height * 2 + heightSpace);
|
|
var productStr = $"生产商: {certificate.ProductShop}";
|
|
if (args.Graphics.MeasureString(productStr, font).Width <= 220)
|
|
{
|
|
args.Graphics.DrawString(productStr, font, System.Drawing.Brushes.Black, 10, verHeight);
|
|
verHeight += smallSize.Height + heightSpace;
|
|
}
|
|
else
|
|
{
|
|
args.Graphics.DrawString(productStr, font, System.Drawing.Brushes.Black, rect);
|
|
verHeight += 2 * smallSize.Height + heightSpace;
|
|
}
|
|
var productShop = args.Graphics.MeasureString("生产商", font);
|
|
var adress = args.Graphics.MeasureString("地 址", font);
|
|
|
|
var rect1 = new RectangleF(10 + productShop.Width - adress.Width, verHeight - 2, 220, smallSize.Height * 3 + heightSpace);
|
|
args.Graphics.DrawString($"地 址: {certificate.ProductAdress}", font, System.Drawing.Brushes.Black, rect1);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
public static void SaveImage(PrintPageEventArgs args)
|
|
{
|
|
args.Graphics.Save();
|
|
// args.Graphics
|
|
|
|
//Bitmap bitmap2 = new Bitmap(236, 157);
|
|
//Graphics graphics2 = Graphics.FromImage(bitmap2);
|
|
//graphics2 = args.Graphics.Copy();
|
|
|
|
//bitmap2.Save("image.jpg", ImageFormat.Jpeg);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static BitmapImage GetBarcodeImage(string printStr, int width, int height)
|
|
{
|
|
Bitmap image = new Bitmap(width, height);
|
|
Graphics graphics2 = Graphics.FromImage(image);
|
|
Barcode barcode = new Barcode();
|
|
System.Drawing.Image img = barcode.Encode(TYPE.CODE128, printStr, 500, 60);
|
|
graphics2.DrawImage(img, 0, 0, width, height);
|
|
return bitmapToBitmapImage(image);
|
|
}
|
|
|
|
static BitmapImage bitmapToBitmapImage(Bitmap bitmap)
|
|
{
|
|
using (var stream = new MemoryStream())
|
|
{
|
|
bitmap.Save(stream, ImageFormat.Png);
|
|
stream.Position = 0;
|
|
BitmapImage reslut = new BitmapImage();
|
|
reslut.BeginInit();
|
|
reslut.CacheOption = BitmapCacheOption.OnLoad;
|
|
reslut.StreamSource = stream;
|
|
reslut.EndInit();
|
|
reslut.Freeze();
|
|
return reslut;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// 打印封箱
|
|
/// </summary>
|
|
/// <param name="sealBoxModel"></param>
|
|
/// <param name="printName"></param>
|
|
/// <param name="boxCount"></param>
|
|
/// <param name="printCount"></param>
|
|
public static void PrintSealBoxData(SealBoxModel sealBoxModel, string printName, int boxCount, int printCount)
|
|
{
|
|
// 100*180
|
|
|
|
UnitConverHelper unitConverHelper = new UnitConverHelper();
|
|
|
|
var data = unitConverHelper.MmToPx(100, 180);
|
|
var applicationPath = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
|
|
string printNamePath = $"{applicationPath}/printSealName.init";
|
|
if (File.Exists(printNamePath))
|
|
{
|
|
File.Delete(printNamePath);
|
|
}
|
|
File.WriteAllText(printNamePath, printName);
|
|
|
|
var excel = $"{applicationPath}/Resources/ExccelModel/sealbox.xlsx";
|
|
|
|
var newExccel = $"{applicationPath}/Resources/ExccelModel/newsealbox.xlsx";
|
|
if (File.Exists(newExccel))
|
|
{
|
|
File.Delete(newExccel);
|
|
}
|
|
FileStream fs = new FileStream(excel, FileMode.Open, FileAccess.Read);
|
|
XSSFWorkbook wb = new XSSFWorkbook(fs);
|
|
var sheet = wb.GetSheetAt(0); // 得到第一个sheet
|
|
|
|
var nameCell = sheet.GetRow(0).GetCell(0); // name列,第2行
|
|
var ageCell = sheet.GetRow(3).GetCell(0); // age列,第2行
|
|
|
|
|
|
XSSFWorkbook wb2 = new XSSFWorkbook();
|
|
sheet.CopyTo(wb2, "Sheet1", true, false);
|
|
var sheet2 = wb2.GetSheet("Sheet1");
|
|
var nameCell2 = sheet2.GetRow(0).GetCell(1);
|
|
nameCell2.SetCellValue(sealBoxModel.ShopName);
|
|
|
|
sheet2.GetRow(3).GetCell(1).SetCellValue(sealBoxModel.WareName);
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
int totalCount = 0;
|
|
for (int i = 0; i < sealBoxModel.SealBoxSkus.Count; i++)
|
|
{
|
|
var title = sealBoxModel.SealBoxSkus[i].SkuTitle;
|
|
//if (title.Length>5)
|
|
//{
|
|
// title = title.Substring(0,5);
|
|
//}
|
|
totalCount += sealBoxModel.SealBoxSkus[i].WareHourseSkuCount;
|
|
sheet2.GetRow(i + 6).GetCell(1).SetCellValue($"名称:{title}");
|
|
sheet2.GetRow(i + 6).GetCell(2).SetCellValue($"SKU:{sealBoxModel.SealBoxSkus[i].SkuId}");
|
|
sheet2.GetRow(i + 6).GetCell(3).SetCellValue($"数量:{sealBoxModel.SealBoxSkus[i].WareHourseSkuCount}");
|
|
|
|
}
|
|
sheet2.GetRow(25).GetCell(1).SetCellValue(totalCount);
|
|
sheet2.GetRow(28).GetCell(1).SetCellValue(boxCount);
|
|
FileStream fs1 = new FileStream(newExccel, FileMode.OpenOrCreate, FileAccess.ReadWrite);
|
|
wb2.Write(fs1);
|
|
fs1.Close();
|
|
fs1.Dispose();
|
|
Workbook workbook = new Workbook();
|
|
|
|
workbook.LoadFromFile(newExccel);
|
|
|
|
Worksheet wsheet = workbook.Worksheets[0];
|
|
|
|
wsheet.PageSetup.PaperSize = PaperSizeType.PaperA4;
|
|
wsheet.PageSetup.Orientation = PageOrientationType.Portrait;
|
|
wsheet.PageSetup.PrintArea = "A1:D31";
|
|
|
|
|
|
|
|
var print = workbook.PrintDocument;
|
|
print.PrinterSettings.PrinterName = printName;
|
|
print.PrinterSettings.Copies = (short)printCount;//打印份数
|
|
|
|
|
|
|
|
print.Print();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 打印京东箱唛
|
|
/// </summary>
|
|
public static void PrintJDBoxWareData(JDWareBoxModel jDWareBoxModel,string printName)
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void SetDefaultPrint(string printName)
|
|
{
|
|
SetDefaultPrinter(printName);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 调用win api将指定名称的打印机设置为默认打印机
|
|
/// </summary>
|
|
/// <param name="Name"></param>
|
|
/// <returns></returns>
|
|
[DllImport("winspool.drv")]
|
|
public static extern bool SetDefaultPrinter(string Name);
|
|
|
|
}
|
|
}
|
|
|