Exemple #1
0
        public void printReceipt(Invoice invoice, bool openDrawer = false)
        {
            // return;
            setupPrinter();
            try
            {
                m_Printer.Open();

                //Get the exclusive control right for the opened device.
                //Then the device is disable from other application.
                m_Printer.Claim(1000);


                //Enable the device.
                bool result = m_Printer.DeviceEnabled = true;

                // this call also causes the "It is not initialized" error
                //string health = m_Printer.CheckHealth(HealthCheckLevel.External);
            }
            catch (PosControlException)
            {
                //  ChangeButtonStatus();
            }
            string receiptString = Receipt40Col.GetStandardReceipt(invoice);
            string barcodeString = invoice.Id ?? "";

            while (barcodeString.Length < 8)
            {
                barcodeString = " " + barcodeString;
            }
            // int test = m_Printer.JrnLineChars


            //var file = Path.GetFullPath("Resources/logo.bmp");
            // m_Printer.PrintNormal(PrinterStation.Receipt,((char)27).ToString() + "|cA" + receiptString);
            //m_Printer.PrintBitmap(PrinterStation.Receipt, file, 300, PosPrinter.PrinterBitmapCenter);

            var headerImage = Receipt40Col.GetInvoiceHeaderBitmap();

            if (headerImage != null)
            {
                m_Printer.PrintBitmap(PrinterStation.Receipt, headerImage, 400, PosPrinter.PrinterBitmapCenter);
            }
            //m_Printer.PrintMemoryBitmap(new BitmapData());
            m_Printer.PrintNormal(PrinterStation.Receipt, receiptString);

            var footerImage = Receipt40Col.GetInvoiceFooterBitmap();

            if (footerImage != null)
            {
                m_Printer.PrintBitmap(PrinterStation.Receipt, footerImage, 400, PosPrinter.PrinterBitmapCenter);
            }
            m_Printer.PrintNormal(PrinterStation.Receipt, Receipt40Col.extraLines(8));
            if (openDrawer)
            {
                m_Printer.PrintNormal(PrinterStation.Receipt, ((char)27).ToString() + "|\x07");
            }
        }
Exemple #2
0
        private void btnPrintBitmap_Click(object sender, System.EventArgs e)
        {
            try
            {
                OpenFileDialog dlg = new OpenFileDialog();
                dlg.Filter = "Image files|*.bmp;*.gif;*.jpg";
                if (dlg.ShowDialog() == DialogResult.OK)
                {
                    int alignment;
                    if (cbAlignment.Text == "Left")
                    {
                        alignment = PosPrinter.PrinterBarCodeLeft;
                    }
                    else if (cbAlignment.Text == "Center")
                    {
                        alignment = PosPrinter.PrinterBarCodeCenter;
                    }
                    else if (cbAlignment.Text == "Right")
                    {
                        alignment = PosPrinter.PrinterBarCodeRight;
                    }
                    else
                    {
                        alignment = int.Parse(cbAlignment.Text);
                    }

                    _printer.PrintBitmap(CurrentStation, dlg.FileName, int.Parse(tbWidth.Text), alignment);
                }
            }
            catch (Exception ae)
            {
                ShowException(ae);
            }
        }
Exemple #3
0
        public void Execute(PosPrinter printer, PrinterStation station)
        {
            if (!printer.CapRecBitmap && station == PrinterStation.Receipt || !printer.CapSlpBitmap && station == PrinterStation.Slip)
            {
                return;
            }

            if (!File.Exists(FileName))
            {
                return;
            }

            var alignment = 0;

            switch (Alignment)
            {
            case Alignment.Center:
                alignment = PosPrinter.PrinterBitmapCenter;
                break;

            case Alignment.Left:
                alignment = PosPrinter.PrinterBitmapLeft;
                break;

            case Alignment.Right:
                alignment = PosPrinter.PrinterBitmapRight;
                break;
            }

            printer.PrintBitmap(PrinterStation.Receipt, FileName, PosPrinter.PrinterBitmapAsIs, alignment);
        }
Exemple #4
0
        public bool PrintBitmap(string strFilePath)
        {
            bool bSetBitmapSuccess = false;

            for (int iRetryCount = 0; iRetryCount < 5; iRetryCount++)
            {
                m_Printer.PrintBitmap(PrinterStation.Receipt, strFilePath,
                                      m_Printer.RecLineWidth,
                                      PosPrinter.PrinterBitmapCenter);
                bSetBitmapSuccess = true;
                break;
            }
            return(bSetBitmapSuccess);
        }
        private void PrintChinese(string str)
        {
            if (str.Length > 13)
            {
                str = str.Substring(0, 13);
            }
            float oneChar    = 37.5f;
            int   printWidth = (int)oneChar * str.Length;

            Bitmap thing = TextBitmap.Convert(str, 20, 300, 20);

            //m_Printer.PrintMemoryBitmap(PrinterStation.Receipt, thing, PosPrinter.PrinterBitmapAsIs, PosPrinter.PrinterBarCodeLeft);
            m_Printer.PrintBitmap(PrinterStation.Receipt, "file.bmp", PosPrinter.PrinterBitmapAsIs, PosPrinter.PrinterBitmapLeft); //530 limit
        }
Exemple #6
0
        public void Execute(PosPrinter printer)
        {
            var alignment = 0;

            switch (Alignment)
            {
            case Alignment.Center:
                alignment = PosPrinter.PrinterBitmapCenter;
                break;

            case Alignment.Left:
                alignment = PosPrinter.PrinterBitmapLeft;
                break;

            case Alignment.Right:
                alignment = PosPrinter.PrinterBitmapRight;
                break;
            }

            printer.PrintBitmap(PrinterStation.Receipt, FileName, PosPrinter.PrinterBitmapAsIs, alignment);
        }
        private void PrintLocalDefaultImage(PosPrinter actualPrinter)
        {
            try
               {
                    Image Dummy = Image.FromFile(Properties.Settings.Default.DefaultAd);
                    string directory = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData);
                    string fileName = directory + @"/default.bmp";

                    Bitmap ADimg = Helpers.ConvertPNGToBitmap(Dummy);

                    ADimg.Save(fileName, ImageFormat.Bmp);

                    actualPrinter.PrintBitmap(PrinterStation.Receipt, fileName, PosPrinter.PrinterBitmapAsIs, PosPrinter.PrinterBitmapCenter);
               }
               catch (Exception ex)
               {
                    AddLog(ex.ToString(),true);
               }

            actualPrinter.PrintNormal(PrinterStation.Receipt, "\r\n\r\nPowered by www.docketplace.com.au");
            actualPrinter.PrintNormal(PrinterStation.Receipt, "\r\n\r\n\r\n\r\n");
            actualPrinter.CutPaper(10);
            AddLog("Local Image printed",false);
        }
Exemple #8
0
        private static void PrintHeaderInformation(PrintDestination printDestination,
                                                   PosPrinter printer, Ticket ticket, TicketItemPrintOptions printOptions)
        {
            // Print the receipt header image
            string filename = "receipt-header.gif";

            if (File.Exists(filename))
            {
                PrintToReceipt(printer, PrinterEscapeCodes.SetCenter);
                printer.PrintBitmap(PrinterStation.Receipt, filename, 200, PosPrinter.PrinterBitmapCenter);
            }

            // Occasion / Seating Information
            if (ConfigurationManager.UseSeating)
            {
                PrintLineToReceipt(printer,
                                   PrinterEscapeCodes.SetCenter + ticket.Type.GetFriendlyName());
            }

            // Print Ticket Number
            PrintLineToReceipt(printer, ((ticket.OrderId == null) ? "" : Strings.Order +
                                         ticket.OrderId.Value + ", ") + Strings.Ticket + ticket.PrimaryKey.Id);

            Person person = PersonManager.GetPersonByEmployeeId(ticket.EmployeeId);

            PrintLineToReceipt(printer, Strings.Employee + ": " + person.FirstName + " " +
                               person.LastName.Substring(0, 1));
            if (ticket.SeatingId > 0)
            {
                Seating seating = SeatingManager.GetSeating(ticket.SeatingId);
                PrintLineToReceipt(printer, Strings.Table + seating.Description);
            }

            // Print date and time (now, future time, or ticket close time)
            DateTime time     = DateTime.Now;
            int?     intValue = OrderEntryCommands.GetPrepTime().IntValue;

            if (printOptions == TicketItemPrintOptions.AllAsVoid)
            {
                PrintLineToReceipt(printer, PrinterEscapeCodes.SetCenter + Strings.TicketVoid);
            }
            else if (printOptions == TicketItemPrintOptions.TicketRefund)
            {
                PrintLineToReceipt(printer, PrinterEscapeCodes.SetCenter + Strings.TicketRefund);
            }
            else if (printOptions == TicketItemPrintOptions.AllAsCancelMade)
            {
                PrintLineToReceipt(printer, PrinterEscapeCodes.SetCenter + Strings.TicketCancelMade);
            }
            else if (printOptions == TicketItemPrintOptions.AllAsCancelUnmade)
            {
                PrintLineToReceipt(printer, PrinterEscapeCodes.SetCenter + Strings.TicketCancelUnmade);
            }
            else if (printOptions == TicketItemPrintOptions.TicketItemVoid)
            {
                PrintLineToReceipt(printer, PrinterEscapeCodes.SetCenter + Strings.TicketItemVoid);
            }
            else if (printOptions == TicketItemPrintOptions.TicketItemReturn)
            {
                PrintLineToReceipt(printer, PrinterEscapeCodes.SetCenter + Strings.TicketItemReturn);
            }
            else if (ticket.StartTime.HasValue && intValue.HasValue &&
                     ((ticket.StartTime.Value - new TimeSpan(0, 0, ticket.StartTime.Value.Second) -
                       new TimeSpan(0, intValue.Value, 0)) >= time) &&
                     !ticket.IsClosed)
            {
                PrintLineToReceipt(printer, PrinterEscapeCodes.SetCenter + Strings.FutureOrder);
                time = ticket.StartTime.Value;
            }
            else if (ticket.StartTime.HasValue && !ticket.IsClosed)
            {
                PrintLineToReceipt(printer, PrinterEscapeCodes.SetCenter + Strings.MakeNow);
                time = ticket.StartTime.Value;
            }
            if (ticket.IsClosed && ticket.CloseTime.HasValue)
            {
                time = ticket.CloseTime.Value;
            }
            PrintLineToReceipt(printer, time.ToShortDateString() +
                               PrinterEscapeCodes.SetRight + time.ToShortTimeString());

            // Newline
            PrintLineToReceipt(printer);

            // Customer's Information
            bool isKitchen = ((printDestination == PrintDestination.Kitchen1) ||
                              (printDestination == PrintDestination.Kitchen2) ||
                              (printDestination == PrintDestination.Kitchen3));

            if (!isKitchen && (ticket.CustomerId > 0))
            {
                person = PersonManager.GetPersonByCustomerId(ticket.CustomerId);
                PrintLineToReceipt(printer, person.FirstName + " " + person.LastName);
                if ((ticket.Type == TicketType.Delivery) ||
                    (ticket.Type == TicketType.Catering))
                {
                    ZipCode      zipCode      = ZipCode.Get(person.ZipCodeId);
                    ZipCodeCity  zipCodeCity  = ZipCodeCity.Get(zipCode.CityId);
                    ZipCodeState zipCodeState = ZipCodeState.Get(zipCodeCity.StateId);
                    PrintLineToReceipt(printer, person.AddressLine1);
                    if (!string.IsNullOrEmpty(person.AddressLine2))
                    {
                        PrintLineToReceipt(printer, person.AddressLine2);
                    }
                    PrintLineToReceipt(printer, zipCodeCity.City + ", " +
                                       zipCodeState.Abbreviation + " " +
                                       zipCode.PostalCode.ToString("D5"));
                }
                if (person.PhoneNumberId1 > 0)
                {
                    PhoneNumber phoneNumber = PhoneNumber.Get(person.PhoneNumberId1);
                    PrintLineToReceipt(printer, phoneNumber.GetFormattedPhoneNumber());
                }

                // Newline
                PrintLineToReceipt(printer);
            }
        }
Exemple #9
0
        public void Print(List <TicketBase> tickets, int issuingNumber, Action <int> onPrint, Action <Exception, int> onError)
        {
            string tempDirectoryPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());

            Directory.CreateDirectory(tempDirectoryPath);

            try
            {
                posPrinter.PrintNormal(PrinterStation.Receipt, $"{issuingNumber} {tickets.Count}枚");
            }
            catch (Exception ex)
            {
                onError(ex, 0);
                DeleteTempFiles();
                return;
            }

            List <(string, string)> bmpPaths = tickets.ConvertAll((t, i) =>
            {
                Bitmap sourceBmp = (Bitmap)t.Bitmap.Clone();
                sourceBmp.RotateFlip(RotateFlipType.Rotate270FlipNone);

                Bitmap bmp1 = sourceBmp.Clone(new Rectangle((sourceBmp.Width - 364) / 2, 0, 364, 90), PixelFormat.Format1bppIndexed);
                Bitmap bmp2 = sourceBmp.Clone(new Rectangle((sourceBmp.Width - 364) / 2, 90, 364, sourceBmp.Height - 90), PixelFormat.Format1bppIndexed);

                string bmp1Path = Path.Combine(tempDirectoryPath, $"{i}-1.bmp");
                string bmp2Path = Path.Combine(tempDirectoryPath, $"{i}-2.bmp");

                bmp1.Save(bmp1Path, ImageFormat.Bmp);
                bmp2.Save(bmp2Path, ImageFormat.Bmp);

                return(bmp1Path, bmp2Path);
            });

            bmpPaths.ForEach((b, i) =>
            {
                try
                {
                    posPrinter.PrintNormal(PrinterStation.Receipt, "\u001b|45uF");
                    posPrinter.PrintBitmap(PrinterStation.Receipt, b.Item1, PosPrinter.PrinterBitmapAsIs, (420 - 364) / 2);
                    posPrinter.PrintNormal(PrinterStation.Receipt, "\u001b|P");
                    posPrinter.PrintBitmap(PrinterStation.Receipt, b.Item2, PosPrinter.PrinterBitmapAsIs, (420 - 364) / 2);
                }
                catch (Exception ex)
                {
                    onError(ex, i);
                    DeleteTempFiles();
                    return;
                }

                if (i != tickets.Count - 1)
                {
                    onPrint(i);
                }
            });

            try
            {
                posPrinter.PrintNormal(PrinterStation.Receipt, "\u001b|135uF");
                posPrinter.PrintNormal(PrinterStation.Receipt, "\u001b|P");
            }
            catch (Exception ex)
            {
                onError(ex, tickets.Count - 1);
                DeleteTempFiles();
                return;
            }

            onPrint(tickets.Count - 1);
            DeleteTempFiles();


            void DeleteTempFiles()
            {
                Task.Run(() => Directory.Delete(tempDirectoryPath, true));
            }
        }
 private void PrintCopyrightSymbol()
 {
     _printer.PrintBitmap(PrinterStation.Receipt, @"C:\Program Files (x86)\infonet-pos\copyright.bmp",
                          PosPrinter.PrinterBitmapAsIs,
                          PosPrinter.PrinterBitmapLeft);
 }