COMPILE FUNCTION Print_Generic_Barcode(EntID,Event,Parm1,Parm2,Parm3,Parm4,Parm5)

/*
	Commuter module for PRINT_GENERIC_BARCODE collector window
	
	8/11/2009 - John C. Henry, J.C. Henry & Co., Inc.
*/

DECLARE SUBROUTINE Set_Property, End_Dialog, Send_Event, Set_Status, Center_Window, Post_Event
DECLARE SUBROUTINE ErrMsg, Send_Message, Set_Property, Send_Event, Btree.Extract, obj_AppWindow, 
DECLARE SUBROUTINE obj_Notes, Security_Err_Msg, End_Window, Forward_Event, Start_Window, Create_Note

DECLARE FUNCTION Get_Property, Get_Status, Dialog_Box, Utility, Popup, Collect.Ixvals, Direct_Print, Environment_Services
DECLARE FUNCTION Send_Message, Msg, Security_Check, obj_React_Run_CI, Set_Printer, Printer_Select

$INSERT MSG_EQUATES
$INSERT APPCOLORS
$INSERT LSL_USERS_EQU
$INSERT SECURITY_RIGHTS_EQU
$INSERT REACT_EVENT_EQUATES
$INSERT POPUP_EQUATES

EQU CRLF$	TO \0D0A\
EQU TAB$	TO \09\

EQU PI$LEFT		TO	1
EQU PI$TOP		TO  2
EQU PI$RIGHT	TO	3
EQU PI$BOTTOM	TO	4
EQU PI$WIDTH	TO 	5
EQU PI$HEIGHT	TO	6
EQU PI$SIZE		TO	7


ErrTitle = 'Error in Print_Generic_Barcode'
ErrorMsg = ''

Result = ''

BEGIN CASE
	CASE EntID = @WINDOW
	
		IF Event = 'CREATE'	THEN GOSUB Create

	CASE EntID = @WINDOW:'.BC_CONTENTS'	AND Event = 'CHANGED'	; GOSUB LabelChange
	CASE EntID = @WINDOW:'.DESCRIPTION'	AND Event = 'CHANGED'	; GOSUB DescChange
	CASE EntID = @WINDOW:'.PRINT'		AND Event = 'CLICK' 	; GOSUB PrintLabel
	
	CASE 1
		ErrorMsg = 'Unknown Parameters ':EntID:' - ':Event:' passed to commuter'
		ErrMsg(ErrorMsg)
		
END CASE

IF ErrorMsg NE '' THEN
	ErrMsg(ErrTitle:@SVM:ErrorMsg)
END

RETURN Result



* * * * * * *
Create:
* * * * * * *


obj_Appwindow('Create',@WINDOW)

RETURN

* * * * * * *
LabelChange:
* * * * * * *

LabelText = Get_Property(@WINDOW:'.BC_CONTENTS','TEXT')

SWAP '*' WITH '\J' IN LabelText

Set_Property(@WINDOW:'.BAR_CODE','TEXT',LabelText)


RETURN


* * * * * * *
DescChange:
* * * * * * *

DescText = Get_Property(@WINDOW:'.DESCRIPTION','TEXT')

Set_Property(@WINDOW:'.DESCRIPTION_LABEL','TEXT',DescText)


RETURN

* * * * * * *
PrintLabel:
* * * * * * *

BCString = Get_Property(@WINDOW:'.BC_CONTENTS','TEXT')
DescText = Get_Property(@WINDOW:'.DESCRIPTION','TEXT')

FileName 	= "Printing Label"
Title		= "Printing Label"

PageInfo	= ''
PageInfo<PI$LEFT>	= 0.1
PageInfo<PI$TOP>	= 0.1
PageInfo<PI$RIGHT>	= 0.1
PageInfo<PI$BOTTOM>	= 0.1

PageSetup	= '1'			;* Landscape
PrintSetup	= ''			;* Preview

PrinterID = '\\mesirwfp001\MESZBRPRT002'	;* This is the Zebra 105se 

PrintPath	= Printer_Select(PrinterID)		;* Popup is skipped IF Printer ID is passed

If Environment_Services('GetLabelPrintMethod') _EQC 'OIPI' then
    stat = Set_Printer("INIT",FileName,Title,PageInfo,PageSetup,PrintSetup,PrintPath)
end else
    stat = Direct_Print('START', PrintPath<1>, '', '')
end

IF stat < 0 THEN GOTO OIPrint_Error

Str = '^XA^CFD'
Str:= '^LH0,0'
Str:= '^PR2' 		;* PRINT SPEED 2 INCHES PER SECOND
Str:= '^LL325' 		;* LABEL LENGTH IN DOTS
Str:= '^MD15' 		 ;* MEDIA DARKNESS
Str:= '^MMT':CRLF$   ;* MEDIA MODE T=TEAR OFF MODE

CharCnt = LEN(DescText)
NameLength = CharCnt*36
WhiteSpace = INT(((2103 - NameLength)/2103) * 806)
StartingXPos = INT(WhiteSpace/2)

Str:= '^FO':StartingXPos:',60^A0,45,36^FD':DescText:'^FS':CRLF$

SWAP '*' WITH '/J' IN BCString

StartingXPos = 60 

BCLen = LEN(BCString)

IF BCLen > 12 THEN
	NarrowBarWidth = 2
END ELSE
	NarrowBarWidth = 3
END

Str := '^FO':StartingXPos:',180^BY':NarrowBarWidth:',,^B3,N,150,Y,^FD':BCString:'^FS':CRLF$	;* BarCode

Str:= '^XZ'

If Environment_Services('GetLabelPrintMethod') _EQC 'OIPI' then
    stat = Set_Printer('TEXT',Str)
end else
    stat = Direct_Print('PRINT', Str)
end

* * * * * *
OIPrint_Error:
* * * * * *

If Environment_Services('GetLabelPrintMethod') _EQC 'OIPI' then
    stat = Set_Printer("TERM")
end else
    stat = Direct_Print('STOP')
end

RETURN

* * * * * * *
Close:
* * * * * * *

obj_Notes('Inbox',@USER4)	;* Checks for any new messages
obj_Appwindow('DetailReturn',@WINDOW)

RETURN
