setted print space and argument to print on label
This commit is contained in:
+24
-5
@@ -10,6 +10,7 @@ namespace console_lps;
|
||||
public class Program
|
||||
{
|
||||
private List<LabelItem> liToPrintList;
|
||||
private List<QrValue> qrToPrintList;
|
||||
private int itemCount;
|
||||
|
||||
public static void Main()
|
||||
@@ -22,29 +23,47 @@ public class Program
|
||||
{
|
||||
string[] dataToPrint =
|
||||
{
|
||||
"4",
|
||||
"HELLO WORLD!",
|
||||
"I WRITE SOME TEXT IN THIS SPACE TO CHECK HOW IT WAS PRINTED"
|
||||
"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce interdum, tortor et aliquet pretium, ipsum nunc fringilla magna, mattis dictum orci nisi ut metus. Mauris malesuada et neque a feugiat. Integer sit amet posuere nisl, eu semper elit.",
|
||||
"F000705 Rif.8036664848 26/10/2022\n\rOA22-00294"
|
||||
};
|
||||
|
||||
string[] qrToPrint =
|
||||
{
|
||||
"ekloifneisofnewionf",
|
||||
"doiwbhdiuwhd"
|
||||
};
|
||||
|
||||
//DateTime delDate = new DateTime();
|
||||
//DateTime.TryParse(dataToPrint[10], out delDate);
|
||||
|
||||
itemCount += 1;
|
||||
itemCount += 4;
|
||||
|
||||
liToPrintList = new List<LabelItem>();
|
||||
|
||||
liToPrintList.Add(new LabelItem()
|
||||
{
|
||||
ItemId = dataToPrint[0],
|
||||
ItemDescription = dataToPrint[1],
|
||||
TotalLabels = short.Parse(dataToPrint[0], NumberStyles.Float),
|
||||
ItemId = dataToPrint[1],
|
||||
ItemDescription = dataToPrint[2],
|
||||
VendPackingSlipReference = dataToPrint[3]
|
||||
});
|
||||
|
||||
qrToPrintList = new List<QrValue>();
|
||||
qrToPrintList.Add(new QrValue()
|
||||
{
|
||||
Item = qrToPrint[0],
|
||||
Value = qrToPrint[1]
|
||||
});
|
||||
|
||||
// Definisce dove viene stampata l'etichetta
|
||||
var printer = "\\\\PALAPPS03.PAL.LOCAL\\ETM03";
|
||||
//var printer = "\\\\PALPRINTER02.PAL.LOCAL\\ST05_64";
|
||||
|
||||
using (PrintDocument pdLabel = LabelPrinterService.PreparePrintDocument(printer, liToPrintList[0].TotalLabels))
|
||||
{
|
||||
pdLabel.PrintPage += (sender, evt) => LabelPrinterService.label_PrintWmsItems(sender, evt, itemCount, liToPrintList[0]);
|
||||
pdLabel.PrintPage += (sender, evt) => LabelPrinterService.label_PrintWmsItems(sender, evt, itemCount, liToPrintList[0], qrToPrintList[0]);
|
||||
pdLabel.Print();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ public class LabelItem
|
||||
public short TotalLabels { get; set; }
|
||||
public string ItemId { get; set; }
|
||||
public string ItemDescription { get; set; }
|
||||
List<QrValue> QrValues { get; set; }
|
||||
public string VendPackingSlipReference { get; set; }
|
||||
}
|
||||
|
||||
public class QrValue
|
||||
|
||||
@@ -3,6 +3,7 @@ using System.Drawing;
|
||||
using System.Drawing.Printing;
|
||||
using System.Globalization;
|
||||
using console_lps.Repository;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace console_lps.Services;
|
||||
|
||||
@@ -15,27 +16,29 @@ public class LabelPrinterService
|
||||
|
||||
internal static PrintDocument PreparePrintDocument(string printer, short numOfCopies = 1)
|
||||
{
|
||||
PaperSize paperSize = new PaperSize("Custom Size", 410, 158);
|
||||
PaperSize paperSize = new PaperSize("Custom Size", 410, 168);
|
||||
Margins margins = new Margins(5, 5, 3, 3);
|
||||
|
||||
PrintDocument labelToPrint = new PrintDocument();
|
||||
labelToPrint.DefaultPageSettings.PaperSize = paperSize;
|
||||
labelToPrint.PrinterSettings.PrinterName = printer;
|
||||
labelToPrint.PrinterSettings.DefaultPageSettings.PaperSize = paperSize;
|
||||
labelToPrint.PrinterSettings.Copies = numOfCopies;
|
||||
labelToPrint.PrinterSettings.DefaultPageSettings.Margins = margins;
|
||||
|
||||
|
||||
|
||||
return labelToPrint;
|
||||
}
|
||||
|
||||
public static void label_PrintWmsItems(object sender, PrintPageEventArgs e, int itemCount, LabelItem item)
|
||||
public static void label_PrintWmsItems(object sender, PrintPageEventArgs e, int itemCount, LabelItem label, QrValue qr)
|
||||
{
|
||||
try
|
||||
{
|
||||
int offsetx = 8;
|
||||
int offsety = 8;
|
||||
int offsety = -13;
|
||||
|
||||
|
||||
offsety += -19;
|
||||
|
||||
SolidBrush brush = new SolidBrush(Color.Black);
|
||||
|
||||
@@ -44,43 +47,39 @@ public class LabelPrinterService
|
||||
Font fntBold = new Font("Bitstream Vera Sans Mono", 13.0F, FontStyle.Bold);
|
||||
|
||||
// Codice QR
|
||||
//e.Graphics.DrawImage(Utils.GenerateQRCode_Image(JsonConvert.SerializeObject(new QrValue()
|
||||
//{
|
||||
// Value = "Hello World! I'm a fucking QR CODE",
|
||||
// Item = ""
|
||||
//}),
|
||||
//e.Graphics.DrawImage(Utils.GenerateQRCode_Image(JsonConvert.SerializeObject(qr),
|
||||
//135, 135), offsetx, offsety);
|
||||
|
||||
offsetx += 137;
|
||||
|
||||
Font fntItemId = new Font("Bitstream Vera Sans Mono", 20.0F, FontStyle.Bold);
|
||||
|
||||
if (item.ItemId.Length > 14)
|
||||
if (label.ItemId.Length > 14)
|
||||
fntItemId = new Font("Bitstream Vera Sans Mono", 14.0F, FontStyle.Bold);
|
||||
|
||||
// Item Id
|
||||
offsety += 10;
|
||||
e.Graphics.DrawString(item.ItemId, fntItemId, brush, offsetx, offsety);
|
||||
e.Graphics.DrawString(label.ItemId, fntItemId, brush, offsetx, offsety);
|
||||
|
||||
////Batch
|
||||
//if (!string.IsNullOrEmpty(item.InventBatchId))
|
||||
//if (!string.IsNullOrEmpty(label.InventBatchId))
|
||||
//{
|
||||
// Font fntBatchId = new Font("Bitstream Vera Sans Mono", 14.0F, FontStyle.Regular);
|
||||
// offsety += 24;
|
||||
// e.Graphics.DrawString(item.InventBatchId, fntBatchId, brush, offsetx, offsety);
|
||||
// e.Graphics.DrawString(label.InventBatchId, fntBatchId, brush, offsetx, offsety);
|
||||
//}
|
||||
|
||||
offsetx += 4;
|
||||
offsety += 31;
|
||||
string format = CultureInfo.GetCultureInfo("IT-it").DateTimeFormat.ShortDatePattern;
|
||||
|
||||
e.Graphics.DrawString((item.ItemDescription.Length > 36 ? item.ItemDescription.Substring(0, 36) + "\r\n" + item.ItemDescription.Substring(36, item.ItemDescription.Length - 36) : item.ItemDescription + "\r\n")
|
||||
e.Graphics.DrawString( Utils.TextFormatter(label.ItemDescription, 35) + "\n\r" + label.VendPackingSlipReference
|
||||
, fnt
|
||||
, brush
|
||||
, offsetx
|
||||
, offsety);
|
||||
|
||||
//e.Graphics.DrawString("\r\n" + "\r\n" + "\r\n" + item.UoM + " " + Utils.ConvertDecimalInString_TwoDecimal(item.InventQty)
|
||||
//e.Graphics.DrawString("\r\n" + "\r\n" + "\r\n" + label.UoM + " " + Utils.ConvertDecimalInString_TwoDecimal(label.InventQty)
|
||||
// , fnt
|
||||
// , brush
|
||||
// , offsetx + 226
|
||||
@@ -88,13 +87,13 @@ public class LabelPrinterService
|
||||
// , new StringFormat() { Alignment = StringAlignment.Far });
|
||||
|
||||
//offsety += 50;
|
||||
//e.Graphics.DrawString(item.PbmProjectInventId
|
||||
//e.Graphics.DrawString(label.PbmProjectInventId
|
||||
// , fntBold
|
||||
// , brush
|
||||
// , offsetx
|
||||
// , offsety);
|
||||
|
||||
//e.Graphics.DrawString(item.WmsLocationId
|
||||
//e.Graphics.DrawString(label.WmsLocationId
|
||||
// , fntBold
|
||||
// , brush
|
||||
// , offsetx + 226
|
||||
|
||||
@@ -1,18 +1,27 @@
|
||||
using System.Diagnostics;
|
||||
using System.Collections;
|
||||
using System.Diagnostics;
|
||||
using System.Drawing;
|
||||
using Serilog;
|
||||
using ZXing;
|
||||
using ZXing.Common;
|
||||
using ZXing.QrCode;
|
||||
using ZXing.QrCode.Internal;
|
||||
using ZXing.Rendering;
|
||||
|
||||
namespace console_lps;
|
||||
|
||||
public class Utils
|
||||
{
|
||||
internal static Image GenerateQRCode_Image(string data, int width, int height, int x = 0, int y = 0, int croppedHeight = 0, int croppedWidth = 0)
|
||||
internal static Bitmap GenerateQRCode_Image(string data, int width, int height, int x = 0, int y = 0, int croppedHeight = 0, int croppedWidth = 0)
|
||||
{
|
||||
QRCodeWriter qr = new QRCodeWriter();
|
||||
var matrix = qr.encode(data, ZXing.BarcodeFormat.QR_CODE, width, height);
|
||||
ZXing.BarcodeWriter<Bitmap> w = new ZXing.BarcodeWriter<Bitmap> { Format = ZXing.BarcodeFormat.QR_CODE };
|
||||
System.Drawing.Bitmap img = w.Write(matrix);
|
||||
var matrix = qr.encode(data, ZXing.BarcodeFormat.QR_CODE, width, height, new Dictionary<EncodeHintType, object>());
|
||||
ZXing.BarcodeWriter<Bitmap> w = new ZXing.BarcodeWriter<Bitmap>
|
||||
{
|
||||
Format = ZXing.BarcodeFormat.QR_CODE
|
||||
};
|
||||
|
||||
Bitmap img = w.Write(matrix);
|
||||
|
||||
if (x != 0 || y != 0)
|
||||
{
|
||||
@@ -35,4 +44,17 @@ public class Utils
|
||||
var message = "ERRORE => " + exc.Message + "\r\n -> alla linea di codice " + callStack.GetFileLineNumber() + "\r\n -> nel metodo " + callStack.GetMethod() + "\r\n -> del file " + callStack.GetFileName() + "\r\n -> in data " + System.DateTime.Now + "\r\n";
|
||||
Log.Logger.Error(message);
|
||||
}
|
||||
|
||||
internal static string TextFormatter(string text, int interval)
|
||||
{
|
||||
if (text == null)
|
||||
return null;
|
||||
|
||||
if (text.Length > 210)
|
||||
text = text.Substring(0, 210);
|
||||
|
||||
string res = String.Concat(text.Select((c, i) => i > 0 && (i % interval) == 0 ? c.ToString() + Environment.NewLine : c.ToString()));
|
||||
|
||||
return res;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user