Skip to content

Instantly share code, notes, and snippets.

@errrzarrr
Created December 7, 2016 18:08
Show Gist options
  • Save errrzarrr/597bd9d1e3b0632d6c35c9539e5677ae to your computer and use it in GitHub Desktop.
Save errrzarrr/597bd9d1e3b0632d6c35c9539e5677ae to your computer and use it in GitHub Desktop.
// Esta clase genera instrucciones de control y formateo de texto
namespace Print {
class EscPosHandler {
private const string ESC = "\u001B";
private const string GS = "\u001D";
private const string LineFeed = "\u000A";
private const string CarriageReturn = "\u000D";
public const string CRLF = CarriageReturn + LineFeed;
public const string InitializePrinter = ESC + "@";
private const string LeftAlign = ESC + GS + "a" + "0";
private const string CenterAlign = ESC + GS + "a" + "1";
private const string RightAlign = ESC + GS + "a" + "2";
private const string BoldOn = ESC + "E";
private const string BoldOff = ESC + "F";
// ...
public static String generateCompanyHeader() {
return
CenterAlign +
Boldon + COMPANY_NAME + BoldOff;
// etc...
}
public static String generateBlankSpaces(short lines) {
// ...
}
public static String generateDetail(String Code, String Quantity, /* etc... */ ) {
// Uso campos traidos de la tabla y los formateo con las constantes generadas en esta clase
}
}
}
namespace Print {
class Program {
static void Main(string[] args) {
// Se conecta a la BD usando un objeto de DAO
// Obtiene lo que quiere imprimir
// Debe usar una instancia de la impresora
// Imprimir esos campos con el texto debidamente formateado.
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using System.Runtime.InteropServices;
using Microsoft.PointOfService;
namespace Print {
class PosForDotNetHandler {
private static string LOGICAL_NAME = "Nombre de la Impresora";
private static PosCommon posCommon;
private static PosPrinter posPrinter;
// y otros objetos de la API para el driver de la impresora
public static void getAllDevices() {
// logica de coneccion con la impresora
}
public static void connectPrinter() {
// logica de coneccion con la impresora
}
public static void print(String string) {
// ...
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment