步步为盈
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.

762 lines
38 KiB

2 years ago
using BarcodeLib;
2 years ago
using BBWY.Client.Extensions;
2 years ago
using BBWY.Client.Models;
2 years ago
using BBWY.Client.Models.FallWare;
2 years ago
using BBWY.Client.Models.PackTask;
using NPOI.XSSF.UserModel;
2 years ago
using System;
using System.Collections.Generic;
using System.Drawing;
2 years ago
using System.Drawing.Imaging;
2 years ago
using System.Drawing.Printing;
2 years ago
using System.IO;
2 years ago
using System.Linq;
2 years ago
using System.Reflection;
2 years ago
using System.Runtime.InteropServices;
2 years ago
using System.Text;
2 years ago
using System.Windows.Media.Imaging;
2 years ago
using WebSocketSharp;
2 years ago
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)
2 years ago
{
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);
2 years ago
SetBarSimplify(barCode, ref args, font);
break;
case BarcodeLabelModel.:
font = new Font("宋体", 10, System.Drawing.FontStyle.Regular);
2 years ago
SetBar(barCode, ref args, font, 7);
break;
default:
break;
2 years ago
}
}
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);
2 years ago
SizeF size = args.Graphics.MeasureString("品牌", font);
var sizeHeight = size.Height;//字体高度
topHeigth += 10;
switch (barCode.LabelModel)
2 years ago
{
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;
2 years ago
}
//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.DrawString($"店铺: {barCode.ShopName}", font, System.Drawing.Brushes.Black, new PointF(10, topHeigth));
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));
2 years ago
}
/// <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;//与顶部的距离
2 years ago
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));
2 years ago
// 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));
2 years ago
}
/// <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));
args.Graphics.DrawString($"规格: {barCode.SkuName}", font, System.Drawing.Brushes.Black, new PointF(10, 10));
args.Graphics.DrawString($"店铺: {barCode.ShopName}", font, System.Drawing.Brushes.Black, new PointF(10, 40));
2 years ago
// 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)
{
2 years ago
2 years ago
2 years ago
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;
2 years ago
case CertificateLabelModel.:
SetCerNoXingHao(ref args, certificate, font);
break;
default:
break;
}
2 years ago
2 years ago
}
private static void SetCerStander(ref PrintPageEventArgs args, CertificateModel certificate, Font font)
{
2 years ago
//#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);
2 years ago
2 years ago
int bigJiange = 20;//合格证与品牌的高度差
var heightSpace = 4;//所有行间隔高度
int standerSpace = 1;//执行标准之间的
2 years ago
if (!string.IsNullOrEmpty(certificate.ProduceDate))
{
bigJiange = 10; heightSpace = 3;
}
2 years ago
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);
2 years ago
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));
2 years ago
if (!string.IsNullOrEmpty(certificate.ProductNo))
args.Graphics.DrawString($"型号: {certificate.ProductNo}", font, System.Drawing.Brushes.Black, new PointF(122, verHeight));
2 years ago
var smallSize = args.Graphics.MeasureString(certificate.Brand, font);//小字体高度
2 years ago
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();
2 years ago
var excutes = certificate.ExcuteStander.Split(new string[] { ",", "," }, StringSplitOptions.RemoveEmptyEntries);
2 years ago
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++)
{
2 years ago
verHeight += (smallSize.Height + standerSpace) - 3;
2 years ago
args.Graphics.DrawString($"{rows[i]}", font, System.Drawing.Brushes.Black, new PointF(10 + smallSize.Width, verHeight));
}
2 years ago
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);
2 years ago
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;
}
2 years ago
var productShop = args.Graphics.MeasureString("生产商", font);
var adress = args.Graphics.MeasureString("地 址", font);
2 years ago
var rect1 = new RectangleF(10 + productShop.Width - adress.Width, verHeight - 2, 220, smallSize.Height * 3 + heightSpace);
2 years ago
args.Graphics.DrawString($"地 址: {certificate.ProductAdress}", font, System.Drawing.Brushes.Black, rect1);
2 years ago
}
private static void SetCerNoXingHao(ref PrintPageEventArgs args, CertificateModel certificate, Font font)
{
2 years ago
2 years ago
//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);
2 years ago
int bigJiange = 20;//合格证与品牌的高度差
var heightSpace = 4;//所有行间隔高度
int standerSpace = 1;//执行标准之间的
2 years ago
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));
2 years ago
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();
2 years ago
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));
}
2 years ago
if (!string.IsNullOrEmpty(certificate.ProduceDate))
{
2 years ago
verHeight += (smallSize.Height + heightSpace) - 3;
2 years ago
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;
2 years ago
}
else
{
args.Graphics.DrawString(productStr, font, System.Drawing.Brushes.Black, rect);
verHeight += 2 * smallSize.Height + heightSpace;
}
2 years ago
var productShop = args.Graphics.MeasureString("生产商", font);
var adress = args.Graphics.MeasureString("地 址", font);
2 years ago
var rect1 = new RectangleF(10 + productShop.Width - adress.Width, verHeight - 2, 220, smallSize.Height * 3 + heightSpace);
2 years ago
args.Graphics.DrawString($"地 址: {certificate.ProductAdress}", font, System.Drawing.Brushes.Black, rect1);
2 years ago
2 years ago
2 years ago
}
public static void SaveImage(PrintPageEventArgs args)
{
args.Graphics.Save();
2 years ago
// args.Graphics
2 years ago
2 years ago
//Bitmap bitmap2 = new Bitmap(236, 157);
//Graphics graphics2 = Graphics.FromImage(bitmap2);
//graphics2 = args.Graphics.Copy();
//bitmap2.Save("image.jpg", ImageFormat.Jpeg);
2 years ago
}
2 years ago
2 years ago
/// <summary>
/// 字符串生成条形码 图片
/// </summary>
/// <param name="printStr"></param>
/// <param name="width"></param>
/// <param name="height"></param>
/// <returns></returns>
2 years ago
public static BitmapImage GetBarcodeImage(string printStr, int width, int height)
2 years ago
{
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);
}
2 years ago
/// <summary>
/// 字符串生成条形码 图片
/// </summary>
/// <param name="printStr"></param>
/// <param name="width"></param>
/// <param name="height"></param>
/// <returns></returns>
public static BitmapImage GetBarcodeImageV2(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, width, height);
graphics2.DrawImage(img, 0, 0, width, height);
return bitmapToBitmapImage(image);
}
2 years ago
static BitmapImage bitmapToBitmapImage(Bitmap bitmap)
2 years ago
{
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;
}
}
2 years ago
2 years ago
2 years ago
///// <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
2 years ago
2 years ago
// UnitConverHelper unitConverHelper = new UnitConverHelper();
2 years ago
2 years ago
// 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);
2 years ago
2 years ago
// var excel = $"{applicationPath}/Resources/ExccelModel/sealbox.xlsx";
2 years ago
2 years ago
// 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
2 years ago
2 years ago
// var nameCell = sheet.GetRow(0).GetCell(0); // name列,第2行
// var ageCell = sheet.GetRow(3).GetCell(0); // age列,第2行
2 years ago
2 years ago
// 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);
2 years ago
2 years ago
// sheet2.GetRow(3).GetCell(1).SetCellValue(sealBoxModel.WareName);
2 years ago
2 years ago
// 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}");
2 years ago
2 years ago
// }
// 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();
2 years ago
2 years ago
// workbook.LoadFromFile(newExccel);
2 years ago
2 years ago
// Worksheet wsheet = workbook.Worksheets[0];
2 years ago
2 years ago
// wsheet.PageSetup.PaperSize = PaperSizeType.PaperA4;
// wsheet.PageSetup.Orientation = PageOrientationType.Portrait;
// wsheet.PageSetup.PrintArea = "A1:D31";
2 years ago
2 years ago
// var print = workbook.PrintDocument;
// print.PrinterSettings.PrinterName = printName;
// print.PrinterSettings.Copies = (short)printCount;//打印份数
2 years ago
2 years ago
// print.Print();
//}
2 years ago
2 years ago
/// <summary>
/// 打印京东箱唛
/// </summary>
public static void PrintJDBoxWareData(JDWareBoxModel jDWareBoxModel,string printName)
{
}
2 years ago
/// <summary>
///设置默认打印机
/// </summary>
/// <param name="printName"></param>
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);
2 years ago
}
}