PC SOFT

FORUMS PROFESSIONNELS
WINDEVWEBDEV et WINDEV Mobile

Accueil → WINDEV 2024 → Print file .PRN to Label with Windev in Printer Zebra
Print file .PRN to Label with Windev in Printer Zebra
Débuté par BOLLER, 14 jan. 2020 21:24 - 13 réponses
Membre enregistré
3 651 messages
Popularité : +175 (223 votes)
Posté le 14 janvier 2020 - 21:24
Bonjour

Je viens ici pour demander de l'aide à de nobles collègues, ci-dessous j'ai un code en C # qui vous permet d'obtenir un fichier de type prn qui est décrit à la fin du post et ce code envoie à l'imprimante Zebra. Je me demande si quelqu'un ici dans le forum pourrait m'aider à convertir le code en C # en windev? J'ai l'imprimante ici pour tester, j'apprécie le support, si nous pouvons convertir j'irai au support en avant à l'équipe de développement créer une fonction avec ce code intégré.

Hi,

I come here to ask the noble colleagues for help, below I have a code in C # that allows you to get a file of type prn that is described at the end of the post and this code sends to the printer Zebra. I wonder if anyone here in the forum could help me convert the code in C # to windev? I have the printer here to test, I appreciate the support, if we can convert I will go to support forward to the development team create a function with this code embedded.

Olá

Venho aqui pedir ajuda aos nobres colegas, abaixo tenho um coódigo em c# que permite pegar um arquivo do tipo prn que esta descrito no final do post e esse codigo manda para a impressora Zebra. Gostaria de saber se alguem aqui no forum poderia me ajudar a converter o codigo em c# para windev? Tenho a impressora aqui para testar, agradeço o apoio, se conseguirmos converter vou passar para o suporte encaminhar para o time de desenvolvimento criar uma função com esse codigo embarcado.


CODE C# - Read File PRN Zebra and Print (Imprimir arquivo .PRN para etiquetar com Windev na impressora Zebra)
RawPrinterHelper.SendStringToPrinter(pd.PrinterSettings.PrinterName, sb.ToString());

// Etiquetas
public class RawPrinterHelper
{
// Structure and API declarions:
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public class DOCINFOA
{
[MarshalAs(UnmanagedType.LPStr)]
public string pDocName;
[MarshalAs(UnmanagedType.LPStr)]
public string pOutputFile;
[MarshalAs(UnmanagedType.LPStr)]
public string pDataType;
}
[DllImport("winspool.Drv", EntryPoint = "OpenPrinterA", SetLastError = true, CharSet = CharSet.Ansi, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
public static extern bool OpenPrinter([MarshalAs(UnmanagedType.LPStr)] string szPrinter, out IntPtr hPrinter, IntPtr pd);

[DllImport("winspool.Drv", EntryPoint = "ClosePrinter", SetLastError = true, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
public static extern bool ClosePrinter(IntPtr hPrinter);

[DllImport("winspool.Drv", EntryPoint = "StartDocPrinterA", SetLastError = true, CharSet = CharSet.Ansi, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
public static extern bool StartDocPrinter(IntPtr hPrinter, Int32 level, [In, MarshalAs(UnmanagedType.LPStruct)] DOCINFOA di);

[DllImport("winspool.Drv", EntryPoint = "EndDocPrinter", SetLastError = true, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
public static extern bool EndDocPrinter(IntPtr hPrinter);

[DllImport("winspool.Drv", EntryPoint = "StartPagePrinter", SetLastError = true, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
public static extern bool StartPagePrinter(IntPtr hPrinter);

[DllImport("winspool.Drv", EntryPoint = "EndPagePrinter", SetLastError = true, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
public static extern bool EndPagePrinter(IntPtr hPrinter);

[DllImport("winspool.Drv", EntryPoint = "WritePrinter", SetLastError = true, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
public static extern bool WritePrinter(IntPtr hPrinter, IntPtr pBytes, Int32 dwCount, out Int32 dwWritten);

// SendBytesToPrinter()
// When the function is given a printer name and an unmanaged array
// of bytes, the function sends those bytes to the print queue.
// Returns true on success, false on failure.
public static bool SendBytesToPrinter(string szPrinterName, IntPtr pBytes, Int32 dwCount)
{
Int32 dwError = 0, dwWritten = 0;
IntPtr hPrinter = new IntPtr(0);
DOCINFOA di = new DOCINFOA();
bool bSuccess = false; // Assume failure unless you specifically succeed.

di.pDocName = "My C#.NET RAW Document";
di.pDataType = "RAW";

// Open the printer.
if (OpenPrinter(szPrinterName.Normalize(), out hPrinter, IntPtr.Zero))
{
// Start a document.
if (StartDocPrinter(hPrinter, 1, di))
{
// Start a page.
if (StartPagePrinter(hPrinter))
{
// Write your bytes.
bSuccess = WritePrinter(hPrinter, pBytes, dwCount, out dwWritten);
EndPagePrinter(hPrinter);
}
EndDocPrinter(hPrinter);
}
ClosePrinter(hPrinter);
}
// If you did not succeed, GetLastError may give more information
// about why not.
if (bSuccess == false)
{
dwError = Marshal.GetLastWin32Error();
}
return bSuccess;
}

public static bool SendFileToPrinter(string szPrinterName, string szFileName)
{
// Open the file.
FileStream fs = new FileStream(szFileName, FileMode.Open);
// Create a BinaryReader on the file.
BinaryReader br = new BinaryReader(fs);
// Dim an array of bytes big enough to hold the file's contents.
Byte[] bytes = new Byte[fs.Length];
bool bSuccess = false;
// Your unmanaged pointer.
IntPtr pUnmanagedBytes = new IntPtr(0);
int nLength;

nLength = Convert.ToInt32(fs.Length);
// Read the contents of the file into the array.
bytes = br.ReadBytes(nLength);
// Allocate some unmanaged memory for those bytes.
pUnmanagedBytes = Marshal.AllocCoTaskMem(nLength);
// Copy the managed byte array into the unmanaged array.
Marshal.Copy(bytes, 0, pUnmanagedBytes, nLength);
// Send the unmanaged bytes to the printer.
bSuccess = SendBytesToPrinter(szPrinterName, pUnmanagedBytes, nLength);
// Free the unmanaged memory that you allocated earlier.
Marshal.FreeCoTaskMem(pUnmanagedBytes);
return bSuccess;
}
public static bool SendStringToPrinter(string szPrinterName, string szString)
{
IntPtr pBytes;
Int32 dwCount;
// How many characters are in the string?
dwCount = szString.Length;
// Assume that the printer is expecting ANSI text, and then convert
// the string to ANSI text.
pBytes = Marshal.StringToCoTaskMemAnsi(szString);
// Send the converted ANSI string to the printer.
SendBytesToPrinter(szPrinterName, pBytes, dwCount);
Marshal.FreeCoTaskMem(pBytes);
return true;
}
}



Example file PRN Zebra 3 label

I8,A,001


Q152,024
q863
rN
S5
D10
ZT
JF
O
R6,0
f100
N
A19,8,0,1,1,2,N,"NOVALGINA 300MG/ML"
A19,32,0,1,1,2,N,"Lab: BAYER"
A19,56,0,1,1,2,N,"L:10000 - V:15/01/2020"
B18,90,0,1,2,6,40,N,"DXQZWVFJ"
A299,8,0,1,1,2,N,"NOVALGINA 300MG/ML"
A299,32,0,1,1,2,N,"Lab: BAYER"
A299,56,0,1,1,2,N,"L:10000 - V:15/01/2020"
B298,90,0,1,2,6,40,N,"DXQZWVFJ"
A578,8,0,1,1,2,N,"NOVALGINA 300MG/ML"
A578,32,0,1,1,2,N,"Lab: BAYER"
A578,56,0,1,1,2,N,"L:10000 - V:15/01/2020"
B577,90,0,1,2,6,40,N,"DXQZWVFJ"
P3


--
Adriano José Boller
______________________________________________
Consultor e Representante Oficial da
PcSoft no Brasil
+55 (41) 99949 1800
adrianoboller@gmail.com
skype: adrianoboller
http://wxinformatica.com.br/
Membre enregistré
3 651 messages
Popularité : +175 (223 votes)
Posté le 15 janvier 2020 - 12:09




--
Adriano José Boller
______________________________________________
Consultor e Representante Oficial da
PcSoft no Brasil
+55 (41) 99949 1800
adrianoboller@gmail.com
skype: adrianoboller
http://wxinformatica.com.br/
Membre enregistré
939 messages
Popularité : +66 (68 votes)
Posté le 15 janvier 2020 - 12:48
Hi Adriano,

you could try this code, it replace your C# function 'SendFileToPrinter(string szPrinterName, string szFileName)'

Procedure WD_SendFileToPrinter(printer_name,filename_to_print,verbose_mode est un booléen=True) : booléen

PRIVÉ
_result est un booléen=False
_buffer est un buffer

QUAND EXCEPTIONEXCEPTION DANS
SI iConfigure(printer_name) ALORS
_buffer=fChargeBuffer(filename_to_print)
iEscape(_buffer)
iFinImprime()
_result=True
SINON
SI verbose_mode ALORS
Erreur(ErreurInfo())
FIN
FIN
FAIRE
SI verbose_mode ALORS
Erreur("Fatal Error !",ExceptionInfo())
FIN
FIN

RENVOYER _result


good Dev ;)
Posté le 15 janvier 2020 - 15:10
No need to use DotNET to deal with the core win32 API, see the MSDN documentation there:
https://docs.microsoft.com/en-us/windows/win32/printdocs/writeprinter
Membre enregistré
3 651 messages
Popularité : +175 (223 votes)
Posté le 15 janvier 2020 - 15:15
:merci:

Procedure WD_SendFileToPrinter(filename_to_print, verbose_mode is boolean=True) : boolean

PRIVATE
_result is boolean=False
_buffer is Buffer

WHEN EXCEPTION IN
IF iConfigure() THEN
_buffer=fLoadBuffer(filename_to_print)
iEscape(_buffer)
iEndPrinting()
_result=True
ELSE
IF verbose_mode THEN
Error(ErrorInfo())
END
END
DO
IF verbose_mode THEN
Error("Fatal Error !",ExceptionInfo())
END
END

RESULT _result























--
Adriano José Boller
______________________________________________
Consultor e Representante Oficial da
PcSoft no Brasil
+55 (41) 99949 1800
adrianoboller@gmail.com
skype: adrianoboller
http://wxinformatica.com.br/
Membre enregistré
3 651 messages
Popularité : +175 (223 votes)
Posté le 15 janvier 2020 - 15:15
I8,A,001


Q152,024
q863
rN
S5
D10
ZT
JF
O
R6,0
f100
N
A19,8,0,1,1,2,N,"NOVALGINA 500MG/ML"
A19,32,0,1,1,2,N,"Lab: SANOFI"
A19,56,0,1,1,2,N,"L:317315 - V:28/02/2016"
B18,90,0,1,2,6,40,N,"DXQZWVFJ"
A299,8,0,1,1,2,N,"NOVALGINA 500MG/ML"
A299,32,0,1,1,2,N,"Lab: SANOFI"
A299,56,0,1,1,2,N,"L:317315 - V:28/02/2016"
B298,90,0,1,2,6,40,N,"DXQZWVFJ"
A578,8,0,1,1,2,N,"NOVALGINA 500MG/ML"
A578,32,0,1,1,2,N,"Lab: SANOFI"
A578,56,0,1,1,2,N,"L:317315 - V:28/02/2016"
B577,90,0,1,2,6,40,N,"DXQZWVFJ"
P3


--
Adriano José Boller
______________________________________________
Consultor e Representante Oficial da
PcSoft no Brasil
+55 (41) 99949 1800
adrianoboller@gmail.com
skype: adrianoboller
http://wxinformatica.com.br/
Membre enregistré
3 651 messages
Popularité : +175 (223 votes)
Posté le 15 janvier 2020 - 15:26
Solução final

Sobrecarga de método, passando ou nao o nome da impressora ou lendo de um arquivo ini.

Procedure WD_Printer_PRN_Etiqueta(bIniNamePrinter is boolean, filename_to_print is string, verbose_mode is boolean=True) : boolean

PRIVATE
_result is boolean=False
_buffer is Buffer

IF bIniNamePrinter = True THEN

sPrintnamefull is string = INIRead("CONFIG","ZEBRA","",fCurrentDir()+"\Zebra.ini")

WHEN EXCEPTION IN
IF iConfigure(sPrintnamefull) THEN
_buffer=fLoadBuffer(filename_to_print)
iEscape(_buffer)
iEndPrinting()
_result=True
ELSE
IF verbose_mode THEN
Error(ErrorInfo())
END
END
DO
IF verbose_mode THEN
Error("Fatal Error !",ExceptionInfo())
END
END

END

RESULT _result


Procedure WD_Printer_PRN_Etiqueta(sPrintnamefull is string, filename_to_print is string, verbose_mode is boolean=True) : boolean

PRIVATE
_result is boolean=False
_buffer is Buffer

WHEN EXCEPTION IN
IF iConfigure(sPrintnamefull) THEN
_buffer=fLoadBuffer(filename_to_print)
iEscape(_buffer)
iEndPrinting()
_result=True
ELSE
IF verbose_mode THEN
Error(ErrorInfo())
END
END
DO
IF verbose_mode THEN
Error("Fatal Error !",ExceptionInfo())
END
END

RESULT _result


Procedure WD_Printer_PRN_Etiqueta(filename_to_print is string, verbose_mode is boolean=True) : boolean

PRIVATE
_result is boolean=False
_buffer is Buffer

WHEN EXCEPTION IN
IF iConfigure() THEN
_buffer=fLoadBuffer(filename_to_print)
iEscape(_buffer)
iEndPrinting()
_result=True
ELSE
IF verbose_mode THEN
Error(ErrorInfo())
END
END
DO
IF verbose_mode THEN
Error("Fatal Error !",ExceptionInfo())
END
END

RESULT _result


--
Adriano José Boller
______________________________________________
Consultor e Representante Oficial da
PcSoft no Brasil
+55 (41) 99949 1800
adrianoboller@gmail.com
skype: adrianoboller
http://wxinformatica.com.br/
Membre enregistré
3 651 messages
Popularité : +175 (223 votes)
Posté le 15 janvier 2020 - 15:30




--
Adriano José Boller
______________________________________________
Consultor e Representante Oficial da
PcSoft no Brasil
+55 (41) 99949 1800
adrianoboller@gmail.com
skype: adrianoboller
http://wxinformatica.com.br/
Membre enregistré
3 651 messages
Popularité : +175 (223 votes)
Posté le 15 janvier 2020 - 15:32
FONTE DOWNLOAD

https://repository.windev.com/publish.awp…

--
Adriano José Boller
______________________________________________
Consultor e Representante Oficial da
PcSoft no Brasil
+55 (41) 99949 1800
adrianoboller@gmail.com
skype: adrianoboller
http://wxinformatica.com.br/
Membre enregistré
3 651 messages
Popularité : +175 (223 votes)
Posté le 15 janvier 2020 - 15:57
Procedure WD_Gera_Etiqueta_Zebra(LINHA_01,LINHA_02,LINHA_03,CODBAR,QtdeEtiquetas)

sEtiqueta_Zebra is string = [
I8,A,001


Q152,024
q863
rN
S5
D10
ZT
JF
O
R6,0
f100
N
A19,8,0,1,1,2,N,"@LINHA_01@"
A19,32,0,1,1,2,N,"@LINHA_02@"
A19,56,0,1,1,2,N,"@LINHA_03@"
B18,90,0,1,2,6,40,N,"@CODBAR@"
A299,8,0,1,1,2,N,"@LINHA_01@"
A299,32,0,1,1,2,N,"@LINHA_02@"
A299,56,0,1,1,2,N,"@LINHA_03@"
B298,90,0,1,2,6,40,N,"@CODBAR@"
A578,8,0,1,1,2,N,"@LINHA_01@"
A578,32,0,1,1,2,N,"@LINHA_02@"
A578,56,0,1,1,2,N,"@LINHA_03@"
B577,90,0,1,2,6,40,N,"@CODBAR@"
P@Qtde@

]

sEtiqueta_Zebra = Replace(sEtiqueta_Zebra,"@LINHA_01@",LINHA_01)
sEtiqueta_Zebra = Replace(sEtiqueta_Zebra,"@LINHA_02@",LINHA_02)
sEtiqueta_Zebra = Replace(sEtiqueta_Zebra,"@LINHA_03@",LINHA_03)
sEtiqueta_Zebra = Replace(sEtiqueta_Zebra,"@CODBAR@",CODBAR)
sEtiqueta_Zebra = Replace(sEtiqueta_Zebra,"@Qtde@",QtdeEtiquetas)

sEtiqueta_Zebra += CR //obrigatorio para ocorrer a impressao a impressora zebra espera por esse caracter

fSaveText("c:\Temp\Etiqueta.prn",sEtiqueta_Zebra)

WD_Printer_PRN_Etiqueta("c:\Temp\Etiqueta.prn",True)


--
Adriano José Boller
______________________________________________
Consultor e Representante Oficial da
PcSoft no Brasil
+55 (41) 99949 1800
adrianoboller@gmail.com
skype: adrianoboller
http://wxinformatica.com.br/
Membre enregistré
3 651 messages
Popularité : +175 (223 votes)
Posté le 15 janvier 2020 - 16:03
Patrice and Christophe!!!

:merci:

Thank you so much for helping me ok

--
Adriano José Boller
______________________________________________
Consultor e Representante Oficial da
PcSoft no Brasil
+55 (41) 99949 1800
adrianoboller@gmail.com
skype: adrianoboller
http://wxinformatica.com.br/
Membre enregistré
3 651 messages
Popularité : +175 (223 votes)
Posté le 15 janvier 2020 - 19:37
// Summary: <specify the procedure action>
// Syntax:
//Imprimir_Etiqueta_Zebra (<LINHA_01>, <LINHA_02>, <LINHA_03>, <CODBAR>, <QtdeEtxProd>, <QtdeCopias>)
//
// Parameters:
// LINHA_01:
// LINHA_02:
// LINHA_03: <specify the role of LINHA_03>
// CODBAR: <specify the role of CODBAR>
// QtdeEtxProd: <specify the role of Qtde>
// QtdeCopias: <specify the role of QtdeCopias>

Procedure Imprimir_Etiqueta_Zebra(LINHA_01,LINHA_02,LINHA_03,CODBAR,QtdeEtxProd,QtdeCopias)

//Tamanho max por linha
LINHA_01 = Middle(LINHA_01,1,25)
LINHA_02 = Middle(LINHA_02,1,25)
LINHA_03 = Middle(LINHA_03,1,25)

sEtiqueta_Cabecalho is string = [
I8,A,001


Q152,024
q863
rN
S5
D10
ZT
JF
O
R6,0
f100
N
]

sETIQUETA_01 is string = [
A16,7,0,1,1,2,N,"@LINHA_01@"
A16,31,0,1,1,2,N,"@LINHA_02@"
A16,55,0,1,1,2,N,"@LINHA_03@"
B30,84,0,E30,2,4,62,N,"@CODBAR@"
]

sETIQUETA_02 is string = [
A296,7,0,1,1,2,N,"@LINHA_01@"
A296,31,0,1,1,2,N,"@LINHA_02@"
A296,55,0,1,1,2,N,"@LINHA_03@"
B310,84,0,E30,2,4,62,N,"@CODBAR@"
]

sETIQUETA_03 is string = [
A575,7,0,1,1,2,N,"@LINHA_01@"
A575,31,0,1,1,2,N,"@LINHA_02@"
A575,55,0,1,1,2,N,"@LINHA_03@"
B589,84,0,E30,2,4,62,N,"@CODBAR@"
]

sEtiqueta_Rodape is string = [
P@Qtde@
]

sEtiqueta_Zebra is string = ""
IF QtdeEtxProd = 1 THEN
sEtiqueta_Zebra = sEtiqueta_Cabecalho +CR+ sETIQUETA_01 +CR+ sEtiqueta_Rodape +CR
ELSE IF QtdeEtxProd = 2 THEN
sEtiqueta_Zebra = sEtiqueta_Cabecalho +CR+ sETIQUETA_01 +CR+ sETIQUETA_02 +CR+ sEtiqueta_Rodape +CR
ELSE IF QtdeEtxProd = 3 THEN
sEtiqueta_Zebra = sEtiqueta_Cabecalho +CR+ sETIQUETA_01 +CR+ sETIQUETA_02 +CR+ sETIQUETA_03 +CR+ sEtiqueta_Rodape +CR
END

sEtiqueta_Zebra = Replace(sEtiqueta_Zebra,"@LINHA_01@",LINHA_01)
sEtiqueta_Zebra = Replace(sEtiqueta_Zebra,"@LINHA_02@",LINHA_02)
sEtiqueta_Zebra = Replace(sEtiqueta_Zebra,"@LINHA_03@",LINHA_03)
sEtiqueta_Zebra = Replace(sEtiqueta_Zebra,"@CODBAR@",CODBAR)
sEtiqueta_Zebra = Replace(sEtiqueta_Zebra,"@Qtde@",QtdeCopias)

sEtiqueta_Zebra += CR

fSaveText("c:\Temp\Etiqueta.prn",sEtiqueta_Zebra)

WD_Printer_PRN_Etiqueta("c:\Temp\Etiqueta.prn",True)


--
Adriano José Boller
______________________________________________
Consultor e Representante Oficial da
PcSoft no Brasil
+55 (41) 99949 1800
adrianoboller@gmail.com
skype: adrianoboller
http://wxinformatica.com.br/
Membre enregistré
3 651 messages
Popularité : +175 (223 votes)
Posté le 15 janvier 2020 - 21:37
Imprimindo diversas etiquetas

// Summary: <specify the procedure action>
// Syntax:
//Imprimir_Etiqueta_Zebra_Todas (<ID_NFE>)
//
// Parameters:
// ID_NFE: <specify the role of gID_NFE>

// QtdeEtqXlinhas: <specify the role of QtdeEtqXlinhas>
// QtdeCopias: <specify the role of QtdeCopias>
Procedure Imprimir_Etiqueta_Zebra_Todas(ID_NFE)

IF gs_CODEBAR <> "" OR TABLEGRID_Etiqueta.Count() > 0 THEN

QtdeEtqXlinhas is int = 0

SWITCH Input("Quantidade de Etiquetas por produto por linha?",QtdeEtqXlinhas)
// OK
CASE 1
//1 : OK
//2 : Cancelar
QtdeCopias is int = 0
SWITCH Input("Quantidade de Cópias?",QtdeCopias)
// OK
CASE 1


PRN_Gerado is string = ""

FOR EACH F027_APS_CODBAR
IF F027_APS_CODBAR.F027_ID_NFE = ID_NFE THEN
//Tamanho max por linha
PRN_Gerado += CR
PRN_Gerado += GeraPRN_Etiqueta_Zebra_01_CAB()
PRN_Gerado += CR
LINHA_01 is string = Middle(F027_APS_CODBAR.F027_DESCRICAO_PROD,1,25)
LINHA_02 is string = Middle(F027_APS_CODBAR.F027_LABORATORIO,1,25)
LINHA_03 is string = Middle("L:"+F027_APS_CODBAR.F027_LOTE_PROD +"-V:"+ DateToString(F027_APS_CODBAR.F027_VALIDADE_LOTE_PROD,"DD/MM/YYYY") ,1,25)
CODBARRA is string = F027_APS_CODBAR.F027_CODBAR_SEQ
PRN_Gerado += GeraPRN_Etiqueta_Zebra_02_LOOP(LINHA_01,LINHA_02,LINHA_03,CODBARRA,QtdeEtqXlinhas)
PRN_Gerado += GeraPRN_Etiqueta_Zebra_03_RODAPE(QtdeCopias)
PRN_Gerado += CR
END
END



fSaveText("c:\Temp\Etiqueta.prn",PRN_Gerado)

WD_Printer_PRN_Etiqueta("c:\Temp\Etiqueta.prn",True)

// Cancelar
CASE 2

END
// Cancelar
CASE 2

END

END



Procedure GeraPRN_Etiqueta_Zebra_01_CAB()

sEtiqueta_Cabecalho is string = [
I8,A,001


Q152,024
q863
rN
S5
D10
ZT
JF
O
R6,0
f100
N
]

RESULT sEtiqueta_Cabecalho



Procedure GeraPRN_Etiqueta_Zebra_02_LOOP(LINHA_01,LINHA_02,LINHA_03,CODBAR,QtdeEtxLinha)

//Tamanho max por linha
LINHA_01 = Middle(LINHA_01,1,25)
LINHA_02 = Middle(LINHA_02,1,25)
LINHA_03 = Middle(LINHA_03,1,25)

sETIQUETA_01 is string = [
A16,7,0,1,1,2,N,"@LINHA_01@"
A16,31,0,1,1,2,N,"@LINHA_02@"
A16,55,0,1,1,2,N,"@LINHA_03@"
B30,84,0,E30,2,4,62,N,"@CODBAR@"
]

sETIQUETA_02 is string = [
A296,7,0,1,1,2,N,"@LINHA_01@"
A296,31,0,1,1,2,N,"@LINHA_02@"
A296,55,0,1,1,2,N,"@LINHA_03@"
B310,84,0,E30,2,4,62,N,"@CODBAR@"
]

sETIQUETA_03 is string = [
A575,7,0,1,1,2,N,"@LINHA_01@"
A575,31,0,1,1,2,N,"@LINHA_02@"
A575,55,0,1,1,2,N,"@LINHA_03@"
B589,84,0,E30,2,4,62,N,"@CODBAR@"
]

sETIQUETAS is string = ""
IF QtdeEtxLinha = 1
sETIQUETAS = sETIQUETA_01 +CR
ELSE IF QtdeEtxLinha = 2
sETIQUETAS = sETIQUETA_01 +CR+ sETIQUETA_02 +CR
ELSE IF QtdeEtxLinha = 3
sETIQUETAS = sETIQUETA_01 +CR+ sETIQUETA_02 +CR+ sETIQUETA_03 + CR
END

sETIQUETAS = Replace(sETIQUETAS,"@LINHA_01@",LINHA_01)
sETIQUETAS = Replace(sETIQUETAS,"@LINHA_02@",LINHA_02)
sETIQUETAS = Replace(sETIQUETAS,"@LINHA_03@",LINHA_03)
sETIQUETAS = Replace(sETIQUETAS,"@CODBAR@",CODBAR)

RESULT sETIQUETAS



Procedure GeraPRN_Etiqueta_Zebra_03_RODAPE(QtdeCopias)

sEtiqueta_Rodape is string = [
P@Qtde@
]

sEtiqueta_Rodape = Replace(sEtiqueta_Rodape,"@Qtde@",QtdeCopias)

sEtiqueta_Rodape += CR

RESULT sEtiqueta_Rodape



Procedure ImprimirUmProduto()

//1 : OK
//2 : Cancelar
IF gs_CODEBAR <> ""

QtdeEtxProd is int = 0

SWITCH Input("Quantidade de Etiquetas por produto por linha?",QtdeEtxProd)
// OK
CASE 1
//1 : OK
//2 : Cancelar
qtdeCopias is int
SWITCH Input("Quantidade de Cópias?",qtdeCopias)
// OK
CASE 1
Imprimir_Etiqueta_Zebra(gs_Etiqueta,gs_Laboratorio,"L:"+gs_Lote+" - V:"+DateToString(gs_Validade,"DD/MM/YYYY"),gs_CODEBAR,QtdeEtxProd,qtdeCopias)
// Cancelar
CASE 2

END
// Cancelar
CASE 2

END

ELSE
Info("Selecione um registro!")
END



Procedure SelecionaRegistro()

nx is int = TableInfoXY(TABLEGRID_Etiqueta,tiLineNumber,MouseXPos(),MouseYPos())

IF nx > 0 THEN

gs_IDNFE = TABLEGRID_Etiqueta[nx].COL_ID_NFE
gs_Etiqueta = TABLEGRID_Etiqueta[nx].COL_Etiqueta
gs_CODEBAR = TABLEGRID_Etiqueta[nx].COL_BARCODE
gs_Laboratorio = TABLEGRID_Etiqueta[nx].COL_Laboratorio
gs_Lote = TABLEGRID_Etiqueta[nx].COL_Lote
gs_Validade = TABLEGRID_Etiqueta[nx].COL_Validade

BarCode = TABLEGRID_Etiqueta[nx].COL_BARCODE

END



Procedure MyWindow(gID_NFE)

//gID_NFE = 473

gs_IDNFE,gs_Etiqueta,gs_CODEBAR,gs_Laboratorio,gs_Lote,gs_Validade is string

FOR EACH F027_APS_CODBAR
IF F027_APS_CODBAR.F027_ID_NFE = gID_NFE
TableAdd(TABLEGRID_Etiqueta, F027_APS_CODBAR.F027_ID_NFE +TAB+
F027_APS_CODBAR.F027_DESCRICAO_PROD +TAB+
F027_APS_CODBAR.F027_CODBAR_SEQ +TAB+
F027_APS_CODBAR.F027_LABORATORIO +TAB+
F027_APS_CODBAR.F027_LOTE_PROD +TAB+
F027_APS_CODBAR.F027_VALIDADE_LOTE_PROD)
END
END


CODIGO PRN GERADO

I8,A,001


Q152,024
q863
rN
S5
D10
ZT
JF
O
R6,0
f100
N
A16,7,0,1,1,2,N,"EEE - ARTRINID 100 MG PO "
A16,31,0,1,1,2,N,""
A16,55,0,1,1,2,N,"L:25165-V:01/01/2020"
B30,84,0,E30,2,4,62,N,"175405525901"
A296,7,0,1,1,2,N,"EEE - ARTRINID 100 MG PO "
A296,31,0,1,1,2,N,""
A296,55,0,1,1,2,N,"L:25165-V:01/01/2020"
B310,84,0,E30,2,4,62,N,"175405525901"
A575,7,0,1,1,2,N,"EEE - ARTRINID 100 MG PO "
A575,31,0,1,1,2,N,""
A575,55,0,1,1,2,N,"L:25165-V:01/01/2020"
B589,84,0,E30,2,4,62,N,"175405525901"
P1


I8,A,001


Q152,024
q863
rN
S5
D10
ZT
JF
O
R6,0
f100
N
A16,7,0,1,1,2,N,"FFF - ARTRINID 100 MG PO "
A16,31,0,1,1,2,N,""
A16,55,0,1,1,2,N,"L:25165-V:01/01/2020"
B30,84,0,E30,2,4,62,N,"275405525902"
A296,7,0,1,1,2,N,"FFF - ARTRINID 100 MG PO "
A296,31,0,1,1,2,N,""
A296,55,0,1,1,2,N,"L:25165-V:01/01/2020"
B310,84,0,E30,2,4,62,N,"275405525902"
A575,7,0,1,1,2,N,"FFF - ARTRINID 100 MG PO "
A575,31,0,1,1,2,N,""
A575,55,0,1,1,2,N,"L:25165-V:01/01/2020"
B589,84,0,E30,2,4,62,N,"275405525902"
P1


I8,A,001


Q152,024
q863
rN
S5
D10
ZT
JF
O
R6,0
f100
N
A16,7,0,1,1,2,N,"AAA - ARTRINID 100 MG PO "
A16,31,0,1,1,2,N,""
A16,55,0,1,1,2,N,"L:25165-V:01/01/2020"
B30,84,0,E30,2,4,62,N,"375405525903"
A296,7,0,1,1,2,N,"AAA - ARTRINID 100 MG PO "
A296,31,0,1,1,2,N,""
A296,55,0,1,1,2,N,"L:25165-V:01/01/2020"
B310,84,0,E30,2,4,62,N,"375405525903"
A575,7,0,1,1,2,N,"AAA - ARTRINID 100 MG PO "
A575,31,0,1,1,2,N,""
A575,55,0,1,1,2,N,"L:25165-V:01/01/2020"
B589,84,0,E30,2,4,62,N,"375405525903"
P1


I8,A,001


Q152,024
q863
rN
S5
D10
ZT
JF
O
R6,0
f100
N
A16,7,0,1,1,2,N,"BBB - ARTRINID 100 MG PO "
A16,31,0,1,1,2,N,""
A16,55,0,1,1,2,N,"L:25165-V:01/01/2020"
B30,84,0,E30,2,4,62,N,"475405525904"
A296,7,0,1,1,2,N,"BBB - ARTRINID 100 MG PO "
A296,31,0,1,1,2,N,""
A296,55,0,1,1,2,N,"L:25165-V:01/01/2020"
B310,84,0,E30,2,4,62,N,"475405525904"
A575,7,0,1,1,2,N,"BBB - ARTRINID 100 MG PO "
A575,31,0,1,1,2,N,""
A575,55,0,1,1,2,N,"L:25165-V:01/01/2020"
B589,84,0,E30,2,4,62,N,"475405525904"
P1


I8,A,001


Q152,024
q863
rN
S5
D10
ZT
JF
O
R6,0
f100
N
A16,7,0,1,1,2,N,"CCC - ARTRINID 100 MG PO "
A16,31,0,1,1,2,N,""
A16,55,0,1,1,2,N,"L:25165-V:01/01/2020"
B30,84,0,E30,2,4,62,N,"575405525905"
A296,7,0,1,1,2,N,"CCC - ARTRINID 100 MG PO "
A296,31,0,1,1,2,N,""
A296,55,0,1,1,2,N,"L:25165-V:01/01/2020"
B310,84,0,E30,2,4,62,N,"575405525905"
A575,7,0,1,1,2,N,"CCC - ARTRINID 100 MG PO "
A575,31,0,1,1,2,N,""
A575,55,0,1,1,2,N,"L:25165-V:01/01/2020"
B589,84,0,E30,2,4,62,N,"575405525905"
P1


I8,A,001


Q152,024
q863
rN
S5
D10
ZT
JF
O
R6,0
f100
N
A16,7,0,1,1,2,N,"DDD - ARTRINID 100 MG PO "
A16,31,0,1,1,2,N,""
A16,55,0,1,1,2,N,"L:25165-V:01/01/2020"
B30,84,0,E30,2,4,62,N,"675405525906"
A296,7,0,1,1,2,N,"DDD - ARTRINID 100 MG PO "
A296,31,0,1,1,2,N,""
A296,55,0,1,1,2,N,"L:25165-V:01/01/2020"
B310,84,0,E30,2,4,62,N,"675405525906"
A575,7,0,1,1,2,N,"DDD - ARTRINID 100 MG PO "
A575,31,0,1,1,2,N,""
A575,55,0,1,1,2,N,"L:25165-V:01/01/2020"
B589,84,0,E30,2,4,62,N,"675405525906"
P1






--
Adriano José Boller
______________________________________________
Consultor e Representante Oficial da
PcSoft no Brasil
+55 (41) 99949 1800
adrianoboller@gmail.com
skype: adrianoboller
http://wxinformatica.com.br/
Message modifié, 15 janvier 2020 - 21:43
Membre enregistré
3 651 messages
Popularité : +175 (223 votes)
Posté le 16 janvier 2020 - 15:48
Versão final esta no repositório

https://repository.windev.com/resource.awp…

// Summary: <specify the procedure action>
// Syntax:
//Imprimir_Etiqueta_Zebra_Todas (<ID_NFE>)
//
// Parameters:
// ID_NFE:

// For instance:
Procedure Imprimir_Etiqueta_Zebra_Todas(ID_NFE)

IF gs_CODEBAR <> "" OR TABLEGRID_Etiqueta.Count() > 0 THEN

nQtdeEtqXlinhas is int = 0
nQtdeCopias is int = 0


SWITCH Input("Quantidade de Etiquetas por produto por linha? (1 A 3)",nQtdeEtqXlinhas)
// OK
CASE 1
//1 : OK
//2 : Cancelar

IF nQtdeEtqXlinhas > 3 THEN
Info("Quantidade Máxima é 3")
RETURN
END

SWITCH Input("Quantidade de Cópias? (1 A 3, PADRAO 1)",nQtdeCopias)
// OK
CASE 1

IF nQtdeCopias > 3 THEN
Info("Quantidade Máxima é 3, normal é 1")
RETURN
END


// Cancelar
CASE 2

END
// Cancelar
CASE 2

END

ImpressaoEtiquetas(ID_NFE,nQtdeEtqXlinhas,nQtdeCopias)

END


INTERNAL Procedure ImpressaoEtiquetas(IDNFE,QtdeEtqXlinhas,QtdeCopias)
contador is int = 0
PRN_Gerado is string = ""

//cabecalho
PRN_Gerado += GeraPRN_Etiqueta_Zebra_01_CAB()
PRN_Gerado += CR

FOR EACH F027_APS_CODBAR

IF F027_APS_CODBAR.F027_ID_NFE = IDNFE THEN

IF F027_APS_CODBAR.F027_LABORATORIO = "" THEN
F027_APS_CODBAR.F027_LABORATORIO = F027_APS_CODBAR.F027_CODBAR_SEQ
END

//Tamanho max por linha
LINHA_01 is string = Middle(F027_APS_CODBAR.F027_DESCRICAO_PROD,1,25)
LINHA_02 is string = Middle("L:"+F027_APS_CODBAR.F027_LOTE_PROD +"-V:"+ DateToString(F027_APS_CODBAR.F027_VALIDADE_LOTE_PROD,"DD/MM/YY") ,1,25)
LINHA_03 is string = Middle(F027_APS_CODBAR.F027_LABORATORIO,1,25)
CODBARRA is string = F027_APS_CODBAR.F027_CODBAR_SEQ

IF QtdeEtqXlinhas = 1 THEN

contador++
IF contador = 1 THEN
PRN_Gerado += GeraPRN_Etiqueta_Zebra_02_LOOP_Etiqueta01(LINHA_01,LINHA_02,LINHA_03,CODBARRA)
ELSE IF contador = 2
PRN_Gerado += GeraPRN_Etiqueta_Zebra_02_LOOP_Etiqueta02(LINHA_01,LINHA_02,LINHA_03,CODBARRA)
ELSE IF contador = 3
PRN_Gerado += GeraPRN_Etiqueta_Zebra_02_LOOP_Etiqueta03(LINHA_01,LINHA_02,LINHA_03,CODBARRA)
contador = 0
PRN_Gerado += GeraPRN_Etiqueta_Zebra_03_RODAPE(QtdeCopias)
END

ELSE IF QtdeEtqXlinhas = 2 THEN

contador++
IF contador = 1 THEN
PRN_Gerado += GeraPRN_Etiqueta_Zebra_02_LOOP_Etiqueta01(LINHA_01,LINHA_02,LINHA_03,CODBARRA)
PRN_Gerado += GeraPRN_Etiqueta_Zebra_02_LOOP_Etiqueta02(LINHA_01,LINHA_02,LINHA_03,CODBARRA)
ELSE IF contador = 2
PRN_Gerado += GeraPRN_Etiqueta_Zebra_02_LOOP_Etiqueta03(LINHA_01,LINHA_02,LINHA_03,CODBARRA)
PRN_Gerado += GeraPRN_Etiqueta_Zebra_02_LOOP_Etiqueta01(LINHA_01,LINHA_02,LINHA_03,CODBARRA)
ELSE IF contador = 3
PRN_Gerado += GeraPRN_Etiqueta_Zebra_02_LOOP_Etiqueta02(LINHA_01,LINHA_02,LINHA_03,CODBARRA)
PRN_Gerado += GeraPRN_Etiqueta_Zebra_02_LOOP_Etiqueta03(LINHA_01,LINHA_02,LINHA_03,CODBARRA)
contador = 0
PRN_Gerado += GeraPRN_Etiqueta_Zebra_03_RODAPE(QtdeCopias)
END

ELSE IF QtdeEtqXlinhas = 3 THEN

PRN_Gerado += GeraPRN_Etiqueta_Zebra_02_LOOP(LINHA_01,LINHA_02,LINHA_03,CODBARRA,QtdeEtqXlinhas)
PRN_Gerado += GeraPRN_Etiqueta_Zebra_03_RODAPE(QtdeCopias)

END

END

END
//COMPLETA FILA DE ETIQUETAS 3
IF contador = 1 THEN
PRN_Gerado += GeraPRN_Etiqueta_Zebra_02_LOOP_Etiqueta02("","","","")
PRN_Gerado += GeraPRN_Etiqueta_Zebra_02_LOOP_Etiqueta03("","","","")
ELSE IF contador = 2 THEN
PRN_Gerado += GeraPRN_Etiqueta_Zebra_02_LOOP_Etiqueta03("","","","")
END

PRN_Gerado += GeraPRN_Etiqueta_Zebra_03_RODAPE(QtdeCopias)

fSaveText("c:\Temp\Etiqueta.prn",PRN_Gerado)
WD_Printer_PRN_Etiqueta("c:\Temp\Etiqueta.prn",True)
END






BONS ESTUDOS!!!!

--
Adriano José Boller
______________________________________________
Consultor e Representante Oficial da
PcSoft no Brasil
+55 (41) 99949 1800
adrianoboller@gmail.com
skype: adrianoboller
http://wxinformatica.com.br/
Message modifié, 16 janvier 2020 - 15:54