using System;
using System.Text;
using System.Runtime.InteropServices;

namespace LKCSharpSamplePrint
{
	#region LKPrint class declaration    
    public class LKPrint
    {
        public const string SEWOODIR = "P11CPCL.dll";

        private LKPrint() { }

        //LUKHAN print method define
        [DllImport(SEWOODIR, SetLastError = true, EntryPoint = "OpenPort")]
        public static extern Int32 OpenPort(string PortName, Int32 BaudRate);
         
        [DllImport(SEWOODIR, SetLastError = true, EntryPoint = "ClosePort")]
        public static extern Int32 ClosePort();
    
		[DllImport(SEWOODIR, SetLastError = true, EntryPoint = "PrinterCheck")]
		public static extern Int32 PrinterCheck();

		[DllImport(SEWOODIR, SetLastError = true, EntryPoint = "status")]
		public static extern Int32 status();

		[DllImport(SEWOODIR, SetLastError = true, EntryPoint = "SetForm")]
		public static extern Int32 SetForm(string HorizonOffset, Int32 XResol, Int32 YResol, string LabelHeight, Int32 Quantity);
		
		[DllImport(SEWOODIR, SetLastError = true, EntryPoint = "PrintForm")]
		public static extern Int32 PrintForm();

		[DllImport(SEWOODIR, SetLastError = true, EntryPoint = "SetMeasure")]
		public static extern Int32 SetMeasure(Int32 Measure);

		[DllImport(SEWOODIR, SetLastError = true, EntryPoint = "SetJustification")]
		public static extern Int32 SetJustification(Int32 Justify);

		[DllImport(SEWOODIR, SetLastError = true, EntryPoint = "CPCLPrintText")]
		public static extern Int32 CPCLPrintText(Int32 Rotation, Int32 FontType, Int32 FontSize, string PrintX, string PrintY, string Data, Int32 count);

		[DllImport(SEWOODIR, SetLastError = true, EntryPoint = "SetConcat")]
		public static extern Int32 SetConcat(Int32 ConcatMode, Int32 PrintX, Int32 PrintY);

		[DllImport(SEWOODIR, SetLastError = true, EntryPoint = "ConcatText")]
		public static extern Int32 ConcatText(Int32 FontType, Int32 FontSize, Int32 Offset, string Data);

		[DllImport(SEWOODIR, SetLastError = true, EntryPoint = "ResetConcat")]
		public static extern Int32 ResetConcat();

		[DllImport(SEWOODIR, SetLastError = true, EntryPoint = "SetMultiLine")]
		public static extern Int32 SetMultiLine(Int32 LineHeight);

		[DllImport(SEWOODIR, SetLastError = true, EntryPoint = "MultiLineText")]
		public static extern Int32 MultiLineText(Int32 Rotation, Int32 FontType, Int32 FontSize, Int32 PrintX, Int32 PrintY);

		[DllImport(SEWOODIR, SetLastError = true, EntryPoint = "MultiLineData")]
		public static extern Int32 MultiLineData(string Data);

		[DllImport(SEWOODIR, SetLastError = true, EntryPoint = "ResetMultiLine")]
		public static extern Int32 ResetMultiLine();

		[DllImport(SEWOODIR, SetLastError = true, EntryPoint = "SetMagnify")]
		public static extern Int32 SetMagnify(Int32 Width, Int32 Height);

		[DllImport(SEWOODIR, SetLastError = true, EntryPoint = "ResetMagnify")]
		public static extern Int32 ResetMagnify();

		[DllImport(SEWOODIR, SetLastError = true, EntryPoint = "SetFormMode")]
		public static extern Int32 SetFormMode();

		[DllImport(SEWOODIR, SetLastError = true, EntryPoint = "SetJournalMode")]
		public static extern Int32 SetJournalMode();

		[DllImport(SEWOODIR, SetLastError = true, EntryPoint = "CPCLPrintBarCode")]
		public static extern Int32 CPCLPrintBarCode(Int32 Rotation, Int32 BarCodeType, Int32 NB, Int32 Ratio, Int32 BarHeight, string PrintX, string PrintY, string Data, Int32 count);

		[DllImport(SEWOODIR, SetLastError = true, EntryPoint = "PrintBox")]
		public static extern Int32 PrintBox(Int32 xs, Int32 ys, Int32 xx, Int32 yx, Int32 Thickness);

		[DllImport(SEWOODIR, SetLastError = true, EntryPoint = "PrintLine")]
		public static extern Int32 PrintLine(Int32 xs, Int32 ys, Int32 xx, Int32 yx, Int32 Thickness);

		[DllImport(SEWOODIR, SetLastError = true, EntryPoint = "InverseLine")]
		public static extern Int32 InverseLine(Int32 xs, Int32 ys, Int32 xx, Int32 yx, Int32 Thickness);

		[DllImport(SEWOODIR, SetLastError = true, EntryPoint = "SetPattern")]
		public static extern Int32 SetPattern(Int32 PatternNum);

		[DllImport(SEWOODIR, SetLastError = true, EntryPoint = "PrintGraphic")]
		public static extern Int32 PrintGraphic(Int32 BytesWidth, Int32 DotHeight, Int32 PrintX, Int32 PrintY, byte [] Data);

		[DllImport(SEWOODIR, SetLastError = true, EntryPoint = "SetContrast")]
		public static extern Int32 SetContrast(Int32 Darkness);

		[DllImport(SEWOODIR, SetLastError = true, EntryPoint = "SetPageWidth")]
		public static extern Int32 SetPageWidth(Int32 PageWidth);

		[DllImport(SEWOODIR, SetLastError = true, EntryPoint = "CPCLPrintImage")]
		public static extern Int32 CPCLPrintImage(string ImageName, string PrintX, string PrintY);

		[DllImport(SEWOODIR, SetLastError = true, EntryPoint = "SetSpeed")]
		public static extern Int32 SetSpeed(Int32 Speed);

		[DllImport(SEWOODIR, SetLastError = true, EntryPoint = "SetTone")]
		public static extern Int32 SetTone(Int32 Tone);

		[DllImport(SEWOODIR, SetLastError = true, EntryPoint = "CPCLSetBarCode")]
		public static extern Int32 CPCLSetBarCode(Int32 FontNum, Int32 FontSize, string Offset);

		[DllImport(SEWOODIR, SetLastError = true, EntryPoint = "CPCL2DPrintBarCode")]
		public static extern Int32 CPCL2DPrintBarCode(Int32 Rotation, Int32 BarCodeType, string PrintX, string PrintY, Int32 UnitWidth, Int32 UnitHeight, Int32 Column, Int32 SecurityLevel, string Data);

		[DllImport(SEWOODIR, SetLastError = true, EntryPoint = "CPCLPrintBitmap")]
		public static extern Int32 CPCLPrintBitmap(string ImageName, string PrintX, string PrintY);

		[DllImport(SEWOODIR, SetLastError = true, EntryPoint = "PrintFile")]
		public static extern Int32 PrintFile(string PrintFileName);

		[DllImport(SEWOODIR, SetLastError = true, EntryPoint = "CPCLPrintText2Image")]
		public static extern Int32 CPCLPrintText2Image(Int32 Orientation, string PrintX, string PrintY, string FontFace, Int32 FontStyle, Int32 FontSize, string TextData, Int32 ReversePrint);

		//Method return value
		public const Int32 LK_SUCCESS = 		0;
		public const Int32 LK_CREATE_ERROR = 	1;
		public const Int32 LK_NOT_OPENED = 		2;
		public const Int32 LK_FAIL = 			-1;

		// Printer Status flag
		public const Int32 LK_STS_NORMAL  		= 0;
		public const Int32 LK_STS_BUSY	 		= 1;
		public const Int32 LK_STS_PAPER_EMPTY 	= 2;
		public const Int32 LK_STS_COVER_OPEN  	= 4;
		public const Int32 LK_STS_BATTERY_LOW  	= 8;

		public const Int32 LK_CPCL_DOTS		= 0;
		public const Int32 LK_CPCL_MILLI	= 1;
		public const Int32 LK_CPCL_CENTI	= 2;
		public const Int32 LK_CPCL_INCH		= 3;

		// Alignment Code
		public const Int32 LK_CPCL_LEFT =		0;
		public const Int32 LK_CPCL_CENTER = 	1;
		public const Int32 LK_CPCL_RIGHT =		2;

		// Rotation
		public const Int32 LK_CPCL_NO_ROTATION =		0;
		public const Int32 LK_CPCL_90_ROTATION =		1;
		public const Int32 LK_CPCL_180_ROTATION =		2;
		public const Int32 LK_CPCL_270_ROTATION =		3;

		// Concatenation
		public const Int32 LK_CPCL_CONCAT		= 0;
		public const Int32 LK_CPCL_VCONCAT		= 1;

		// Magnification(Width)
		public const Int32 LK_CPCL_TXT_1WIDTH =	0;
		public const Int32 LK_CPCL_TXT_2WIDTH =	1;
		public const Int32 LK_CPCL_TXT_3WIDTH =	2;
		public const Int32 LK_CPCL_TXT_4WIDTH =	3;
		public const Int32 LK_CPCL_TXT_5WIDTH =	4;
		public const Int32 LK_CPCL_TXT_6WIDTH =	5;
		public const Int32 LK_CPCL_TXT_7WIDTH =	6;
		public const Int32 LK_CPCL_TXT_8WIDTH =	7;
		public const Int32 LK_CPCL_TXT_9WIDTH =	8;
		public const Int32 LK_CPCL_TXT_10WIDTH =	9;
		public const Int32 LK_CPCL_TXT_11WIDTH =	10;
		public const Int32 LK_CPCL_TXT_12WIDTH =	11;
		public const Int32 LK_CPCL_TXT_13WIDTH =	12;
		public const Int32 LK_CPCL_TXT_14WIDTH =	13;
		public const Int32 LK_CPCL_TXT_15WIDTH =	14;
		public const Int32 LK_CPCL_TXT_16WIDTH =	15;

		// Magnification(Height)
		public const Int32 LK_CPCL_TXT_1HEIGHT = 0;
		public const Int32 LK_CPCL_TXT_2HEIGHT = 1;
		public const Int32 LK_CPCL_TXT_3HEIGHT = 2;
		public const Int32 LK_CPCL_TXT_4HEIGHT = 3;
		public const Int32 LK_CPCL_TXT_5HEIGHT = 4;
		public const Int32 LK_CPCL_TXT_6HEIGHT = 5;
		public const Int32 LK_CPCL_TXT_7HEIGHT = 6;
		public const Int32 LK_CPCL_TXT_8HEIGHT = 7;
		public const Int32 LK_CPCL_TXT_9HEIGHT = 8;
		public const Int32 LK_CPCL_TXT_10HEIGHT = 9;
		public const Int32 LK_CPCL_TXT_11HEIGHT = 10;
		public const Int32 LK_CPCL_TXT_12HEIGHT = 11;
		public const Int32 LK_CPCL_TXT_13HEIGHT = 12;
		public const Int32 LK_CPCL_TXT_14HEIGHT = 13;
		public const Int32 LK_CPCL_TXT_15HEIGHT = 14;
		public const Int32 LK_CPCL_TXT_16HEIGHT = 15;


		// one-dimension barcode
		public const Int32  LK_CPCL_BCS_39	 		= 0;
		public const Int32  LK_CPCL_BCS_39C 		= 1;
		public const Int32  LK_CPCL_BCS_39F 		= 2;
		public const Int32  LK_CPCL_BCS_39FC 		= 3;
		public const Int32  LK_CPCL_BCS_93	 		= 4;
		public const Int32  LK_CPCL_BCS_128 		= 5;
		public const Int32  LK_CPCL_BCS_EAN128 		= 6;
		public const Int32  LK_CPCL_BCS_CODABAR 	= 7;
		public const Int32  LK_CPCL_BCS_CODABARC 	= 8;
		public const Int32  LK_CPCL_BCS_EAN8 		= 9;
		public const Int32  LK_CPCL_BCS_EAN82 		= 10;
		public const Int32  LK_CPCL_BCS_EAN85 		= 11;
		public const Int32  LK_CPCL_BCS_EAN13 		= 12;
		public const Int32  LK_CPCL_BCS_EAN132 		= 13;
		public const Int32  LK_CPCL_BCS_EAN135 		= 14;
		public const Int32  LK_CPCL_BCS_I2OF5 		= 15;
		public const Int32  LK_CPCL_BCS_POSTNET 	= 16;
		public const Int32  LK_CPCL_BCS_UPCA 		= 17;
		public const Int32  LK_CPCL_BCS_UPCA2 		= 18;
		public const Int32  LK_CPCL_BCS_UPCA5 		= 19;
		public const Int32  LK_CPCL_BCS_UPCE 		= 20;
		public const Int32  LK_CPCL_BCS_UPCE2 		= 21;
		public const Int32  LK_CPCL_BCS_UPCE5 		= 22;
		public const Int32  LK_CPCL_BCS_MSI 		= 23;
		public const Int32  LK_CPCL_BCS_MSI1C 		= 24;
		public const Int32  LK_CPCL_BCS_MSI2C 		= 25;
		public const Int32  LK_CPCL_BCS_MSI11C 		= 26;
		public const Int32  LK_CPCL_BCS_PLUS2 		= 27;
		public const Int32  LK_CPCL_BCS_PLUS5 		= 28;

		// two-dimension barcode
		public const Int32  LK_CPCL_BCS_PDF417 		= 0;
		public const Int32  LK_CPCL_BCS_MAXICODE 	= 1;

		// Barcode Ratio.
		public const Int32  LK_CPCL_BCS_0RATIO 	= 1;
		public const Int32  LK_CPCL_BCS_1RATIO 	= 2;
		public const Int32  LK_CPCL_BCS_2RATIO 	= 3;
		public const Int32  LK_CPCL_BCS_3RATIO 	= 4;
		public const Int32  LK_CPCL_BCS_4RATIO 	= 5;
		public const Int32  LK_CPCL_BCS_20RATIO = 6;
		public const Int32  LK_CPCL_BCS_21RATIO = 7;
		public const Int32  LK_CPCL_BCS_22RATIO = 8;
		public const Int32  LK_CPCL_BCS_23RATIO = 9;
		public const Int32  LK_CPCL_BCS_24RATIO = 10;
		public const Int32  LK_CPCL_BCS_25RATIO = 11;
		public const Int32  LK_CPCL_BCS_26RATIO = 12;
		public const Int32  LK_CPCL_BCS_27RATIO = 13;
		public const Int32  LK_CPCL_BCS_28RATIO = 14;
		public const Int32  LK_CPCL_BCS_29RATIO = 15;
		public const Int32  LK_CPCL_BCS_30RATIO = 16;

		// pattern.
		public const Int32  LK_CPCL_DEFAULT_PATTERN 	= 1;
		public const Int32  LK_CPCL_HORIZON_PATTERN 	= 2;
		public const Int32  LK_CPCL_VERTICAL_PATTERN 	= 3;
		public const Int32  LK_CPCL_RDIAGON_PATTERN 	= 4;
		public const Int32  LK_CPCL_LDIAGON_PATTERN 	= 5;
		public const Int32  LK_CPCL_SQUARE_PATTERN 		= 6;
		public const Int32  LK_CPCL_CROSS_PATTERN 		= 7;

		// contrast.
		public const Int32  LK_CPCL_CONT_DEFAULT 	= 0;
		public const Int32  LK_CPCL_CONT_MEDIUM 	= 1;
		public const Int32  LK_CPCL_CONT_DARK 		= 2;
		public const Int32  LK_CPCL_CONT_VERY_DARK 	= 3;
	}
    #endregion

}
