Ejemplo n.º 1
0
        public static void Main(string[] args)
        {
            if (args.Length <= 0)
            {
                Console.Out.WriteLine("Command Line Error");
                return;
            }

            string path = args[0];
            Reciept reciept = getReciept(path);

            string printerPortName = getPrinterPort();
            SerialPort printerPort = new SerialPort(printerPortName);

            if (printerPort != null)
            {
                if (printerPort.IsOpen)
                {
                    printerPort.Close();
                }
            }

            try {
                printerPort.Open();
            } catch{
                Console.WriteLine ("I/O error");
                Environment.Exit(0);
            }

            //Printer init
            ThermalPrinter printer = new ThermalPrinter(printerPort,2,180,2);
            printer.WakeUp();

            printer.SetLineSpacing(0);
            printer.SetAlignCenter();
            printer.WriteLine("Mango Talaat",
                (byte)ThermalPrinter.PrintingStyle.Bold +
                (byte)ThermalPrinter.PrintingStyle.DoubleHeight
                + (byte)ThermalPrinter.PrintingStyle.DoubleWidth);

            printer.WriteLine("Riyadh, Gadheer Branch");
            printer.Reset();
            printer.LineFeed();

            // show header
            string header = "Qty".PadLeft(2) + " " + "Size".PadLeft(3) + " " + "Sugar".PadLeft(5)  + " " + "Item".PadLeft(10) + " " + "Price".PadLeft(15);
            printer.WriteLine(header);
            printer.HorizontalLine(40);

            ShowItems(printer, reciept);

            printer.HorizontalLine(40);

            printer.WriteLine("CASH" + reciept.cash.PadLeft(26));
            printer.WriteLine("Discount" + reciept.discount.PadLeft(22));
            printer.WriteLine("TOTAL" + reciept.total.PadLeft(10), ThermalPrinter.PrintingStyle.DoubleWidth);

            printer.LineFeed();
            printer.SetAlignCenter();
            printer.WriteLine("Have a good day.", ThermalPrinter.PrintingStyle.Bold);

            printer.LineFeed();
            printer.SetAlignLeft();
            printer.WriteLine(DateTime.Now.ToString());
            printer.LineFeed();

            printer.LineFeed(3);
            printer.cutPaper();
            printer.openCashDrawer();
            printer.Sleep();
            Console.WriteLine("Printer is now offline.");
            printerPort.Close();
        }