104 lines
2.6 KiB
C#
104 lines
2.6 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
|
|
namespace PrintDemo
|
|
{
|
|
public class EscCommand
|
|
{
|
|
ArrayList Command = null;
|
|
|
|
public EscCommand()
|
|
{
|
|
this.Command = new ArrayList();
|
|
}
|
|
|
|
public ArrayList GetCommand()
|
|
{
|
|
return this.Command;
|
|
}
|
|
|
|
private void AddArrayToCommand(byte[] array)
|
|
{
|
|
for (int i = 0; i < array.Length; i++)
|
|
{
|
|
this.Command.Add(array[i]);
|
|
}
|
|
}
|
|
|
|
public void AddSelectErrorCorrectionLevelForQRCode(byte n)
|
|
{
|
|
byte[] command = { 29, 40, 107, 3, 0, 49, 69, 3 };
|
|
command[7] = n;
|
|
AddArrayToCommand(command);
|
|
}
|
|
|
|
public void AddSelectSizeOfModuleForQRCode(byte n)
|
|
{
|
|
byte[] command = { 29, 40, 107, 3, 0, 49, 67, 3 };
|
|
command[7] = n;
|
|
AddArrayToCommand(command);
|
|
}
|
|
|
|
public void AddStoreQRCodeData(String content)
|
|
{
|
|
byte[] command = { 29, 40, 107, 0, 0, 49, 80, 48 };
|
|
command[3] = ((byte)((content.Length + 3) % 256));
|
|
command[4] = ((byte)((content.Length + 3) / 256));
|
|
AddArrayToCommand(command);
|
|
AddStrToCommand(content, content.Length);
|
|
}
|
|
|
|
private void AddStrToCommand(String str, int length)
|
|
{
|
|
byte[] bs = null;
|
|
if (!str.Equals(""))
|
|
{
|
|
try
|
|
{
|
|
bs = System.Text.Encoding.GetEncoding("GB2312").GetBytes(str);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
if (length > bs.Length)
|
|
{
|
|
length = bs.Length;
|
|
}
|
|
for (int i = 0; i < length; i++)
|
|
{
|
|
this.Command.Add(bs[i]);
|
|
}
|
|
}
|
|
}
|
|
|
|
public void AddPrintQRCode()
|
|
{
|
|
byte[] command = { 29, 40, 107, 3, 0, 49, 81, 48 };
|
|
AddArrayToCommand(command);
|
|
}
|
|
|
|
public static byte[] ToPrimitive(Byte[] array)
|
|
{
|
|
if (array == null)
|
|
{
|
|
return null;
|
|
}
|
|
if (array.Length == 0)
|
|
{
|
|
return new byte[] { };
|
|
}
|
|
byte[] result = new byte[array.Length];
|
|
for (int i = 0; i < array.Length; i++)
|
|
{
|
|
result[i] = array[i];
|
|
}
|
|
return result;
|
|
}
|
|
|
|
}
|
|
}
|