Issue
This commit is contained in:
@@ -0,0 +1,25 @@
|
|||||||
|
|
||||||
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
|
# Visual Studio Version 17
|
||||||
|
VisualStudioVersion = 17.3.32929.385
|
||||||
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "console_lps", "console_lps\console_lps.csproj", "{35ADC8E8-A92B-42D3-9B04-CFF7B5A3F9D6}"
|
||||||
|
EndProject
|
||||||
|
Global
|
||||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
Release|Any CPU = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
|
{35ADC8E8-A92B-42D3-9B04-CFF7B5A3F9D6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{35ADC8E8-A92B-42D3-9B04-CFF7B5A3F9D6}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{35ADC8E8-A92B-42D3-9B04-CFF7B5A3F9D6}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{35ADC8E8-A92B-42D3-9B04-CFF7B5A3F9D6}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
|
HideSolutionNode = FALSE
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
|
SolutionGuid = {3AF84959-0FD9-499B-8D10-69A934AC2ABF}
|
||||||
|
EndGlobalSection
|
||||||
|
EndGlobal
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
using System.ComponentModel;
|
||||||
|
using console_lps.Services;
|
||||||
|
using System.Drawing.Printing;
|
||||||
|
using System.Globalization;
|
||||||
|
using DocumentFormat.OpenXml.Spreadsheet;
|
||||||
|
using console_lps.Repository;
|
||||||
|
|
||||||
|
namespace console_lps;
|
||||||
|
|
||||||
|
public class Program
|
||||||
|
{
|
||||||
|
private List<LabelItem> liToPrintList;
|
||||||
|
private int itemCount;
|
||||||
|
|
||||||
|
public static void Main()
|
||||||
|
{
|
||||||
|
Program p = new Program();
|
||||||
|
p.Print();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Print()
|
||||||
|
{
|
||||||
|
string[] dataToPrint =
|
||||||
|
{
|
||||||
|
"HELLO WORLD!",
|
||||||
|
"I WRITE SOME TEXT IN THIS SPACE TO CHECK HOW IT WAS PRINTED"
|
||||||
|
};
|
||||||
|
|
||||||
|
//DateTime delDate = new DateTime();
|
||||||
|
//DateTime.TryParse(dataToPrint[10], out delDate);
|
||||||
|
|
||||||
|
itemCount += 1;
|
||||||
|
|
||||||
|
liToPrintList = new List<LabelItem>();
|
||||||
|
|
||||||
|
liToPrintList.Add(new LabelItem()
|
||||||
|
{
|
||||||
|
ItemId = dataToPrint[0],
|
||||||
|
ItemDescription = dataToPrint[1],
|
||||||
|
});
|
||||||
|
|
||||||
|
// Definisce dove viene stampata l'etichetta
|
||||||
|
var printer = "\\\\PALAPPS03.PAL.LOCAL\\ETM03";
|
||||||
|
|
||||||
|
using (PrintDocument pdLabel = LabelPrinterService.PreparePrintDocument(printer, liToPrintList[0].TotalLabels))
|
||||||
|
{
|
||||||
|
pdLabel.PrintPage += (sender, evt) => LabelPrinterService.label_PrintWmsItems(sender, evt, itemCount, liToPrintList[0]);
|
||||||
|
pdLabel.Print();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
using DocumentFormat.OpenXml.Drawing;
|
||||||
|
|
||||||
|
namespace console_lps.Repository;
|
||||||
|
|
||||||
|
public class LabelItem
|
||||||
|
{
|
||||||
|
public short TotalLabels { get; set; }
|
||||||
|
public string ItemId { get; set; }
|
||||||
|
public string ItemDescription { get; set; }
|
||||||
|
List<QrValue> QrValues { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class QrValue
|
||||||
|
{
|
||||||
|
public string Value { get; set; }
|
||||||
|
public string Item { get; set; }
|
||||||
|
}
|
||||||
@@ -0,0 +1,118 @@
|
|||||||
|
using System.Diagnostics;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Drawing.Printing;
|
||||||
|
using System.Globalization;
|
||||||
|
using console_lps.Repository;
|
||||||
|
|
||||||
|
namespace console_lps.Services;
|
||||||
|
|
||||||
|
public class LabelPrinterService
|
||||||
|
{
|
||||||
|
//private string printer = "ETM03";
|
||||||
|
//private List<WmsLabelItem> wliToPrintList;
|
||||||
|
//private int itemCount;
|
||||||
|
|
||||||
|
|
||||||
|
internal static PrintDocument PreparePrintDocument(string printer, short numOfCopies = 1)
|
||||||
|
{
|
||||||
|
PaperSize paperSize = new PaperSize("Custom Size", 410, 158);
|
||||||
|
|
||||||
|
PrintDocument labelToPrint = new PrintDocument();
|
||||||
|
labelToPrint.DefaultPageSettings.PaperSize = paperSize;
|
||||||
|
labelToPrint.PrinterSettings.PrinterName = printer;
|
||||||
|
labelToPrint.PrinterSettings.DefaultPageSettings.PaperSize = paperSize;
|
||||||
|
labelToPrint.PrinterSettings.Copies = numOfCopies;
|
||||||
|
|
||||||
|
|
||||||
|
return labelToPrint;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void label_PrintWmsItems(object sender, PrintPageEventArgs e, int itemCount, LabelItem item)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
int offsetx = 8;
|
||||||
|
int offsety = 8;
|
||||||
|
|
||||||
|
|
||||||
|
offsety += -19;
|
||||||
|
|
||||||
|
SolidBrush brush = new SolidBrush(Color.Black);
|
||||||
|
|
||||||
|
/*Nuova etichetta con in QR*/
|
||||||
|
Font fnt = new Font("Bitstream Vera Sans Mono", 8.0F, FontStyle.Regular);
|
||||||
|
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 = ""
|
||||||
|
//}),
|
||||||
|
//135, 135), offsetx, offsety);
|
||||||
|
|
||||||
|
offsetx += 137;
|
||||||
|
|
||||||
|
Font fntItemId = new Font("Bitstream Vera Sans Mono", 20.0F, FontStyle.Bold);
|
||||||
|
|
||||||
|
if (item.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);
|
||||||
|
|
||||||
|
////Batch
|
||||||
|
//if (!string.IsNullOrEmpty(item.InventBatchId))
|
||||||
|
//{
|
||||||
|
// Font fntBatchId = new Font("Bitstream Vera Sans Mono", 14.0F, FontStyle.Regular);
|
||||||
|
// offsety += 24;
|
||||||
|
// e.Graphics.DrawString(item.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")
|
||||||
|
, fnt
|
||||||
|
, brush
|
||||||
|
, offsetx
|
||||||
|
, offsety);
|
||||||
|
|
||||||
|
//e.Graphics.DrawString("\r\n" + "\r\n" + "\r\n" + item.UoM + " " + Utils.ConvertDecimalInString_TwoDecimal(item.InventQty)
|
||||||
|
// , fnt
|
||||||
|
// , brush
|
||||||
|
// , offsetx + 226
|
||||||
|
// , offsety
|
||||||
|
// , new StringFormat() { Alignment = StringAlignment.Far });
|
||||||
|
|
||||||
|
//offsety += 50;
|
||||||
|
//e.Graphics.DrawString(item.PbmProjectInventId
|
||||||
|
// , fntBold
|
||||||
|
// , brush
|
||||||
|
// , offsetx
|
||||||
|
// , offsety);
|
||||||
|
|
||||||
|
//e.Graphics.DrawString(item.WmsLocationId
|
||||||
|
// , fntBold
|
||||||
|
// , brush
|
||||||
|
// , offsetx + 226
|
||||||
|
// , offsety
|
||||||
|
// , new StringFormat() { Alignment = StringAlignment.Far });
|
||||||
|
|
||||||
|
///*Nuova etichetta con in QR*/
|
||||||
|
//if (itemCount != wliToPrintList.Count - 1)
|
||||||
|
//{
|
||||||
|
// itemCount += 1;
|
||||||
|
// e.HasMorePages = true;
|
||||||
|
//}
|
||||||
|
Thread.Sleep(2000);
|
||||||
|
}
|
||||||
|
catch (Exception exc)
|
||||||
|
{
|
||||||
|
StackFrame callStack = new StackFrame(0, true);
|
||||||
|
Utils.TryCatchMessage(exc, callStack);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
using System.Diagnostics;
|
||||||
|
using System.Drawing;
|
||||||
|
using Serilog;
|
||||||
|
using ZXing.QrCode;
|
||||||
|
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
|
||||||
|
if (x != 0 || y != 0)
|
||||||
|
{
|
||||||
|
System.Drawing.Bitmap croppedImage = img.Clone(new System.Drawing.Rectangle(x, y, croppedHeight, croppedWidth), img.PixelFormat);
|
||||||
|
return croppedImage;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return img;
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static string ConvertDecimalInString_TwoDecimal(decimal dec, string culture = "it-IT")
|
||||||
|
{
|
||||||
|
string ret = "";
|
||||||
|
ret = dec.ToString("#,0.00", System.Globalization.CultureInfo.GetCultureInfo(culture));
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static void TryCatchMessage(Exception exc, StackFrame callStack)
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputType>Exe</OutputType>
|
||||||
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="BarcodeLib" Version="2.4.0" />
|
||||||
|
<PackageReference Include="DocumentFormat.OpenXml" Version="2.18.0" />
|
||||||
|
<PackageReference Include="Microsoft.Office.Interop.Excel" Version="15.0.4795.1001" />
|
||||||
|
<PackageReference Include="Microsoft.Office.Interop.Word" Version="15.0.4797.1004" />
|
||||||
|
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
|
||||||
|
<PackageReference Include="Serilog" Version="2.12.0" />
|
||||||
|
<PackageReference Include="System.Drawing.Common" Version="6.0.0" />
|
||||||
|
<PackageReference Include="ZXing.Net" Version="0.16.8" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
Reference in New Issue
Block a user