Пример #1
0
 public void Show(ISalesDocument doc)
 {
     if ((mode & Target.Customer) == Target.Customer || showCashierMessage)
     {
         customerForm.Show(doc);
     }
 }
Пример #2
0
        public void ChangeDocumentStatus(ISalesDocument doc, DisplayDocumentStatus de)
        {
            switch (de)
            {
            case DisplayDocumentStatus.OnStart:
                touchForm.SetDocumentInfos(doc);
                break;

            case DisplayDocumentStatus.OnChange:
                touchForm.ChangeDocument(doc);
                if (customerForm != null)
                {
                    customerForm.ChangeCurrentDocument(doc);
                }
                break;

            case DisplayDocumentStatus.OnUndoAdjustment:
                break;

            case DisplayDocumentStatus.OnClose:
                if (doc.Id == -1)
                {
                    break;
                }
                touchForm.DocumentClose(doc);
                if (customerForm != null)
                {
                    customerForm.DocumentClose(doc);
                }
                break;
            }
        }
Пример #3
0
        public static List <String> FormatHeader(ISalesDocument document)
        {
            currentLines = new List <string>();

            FormatLine(new Location(documentIdLocation.X, documentIdLocation.Y + 1), String.Format("{0} {1} : {2}", document.Name, PosMessage.DOCUMENT_FOLLOWING_ID, document.Id));

            FormatLine(new Location(dateLocation.X, dateLocation.Y + 1), String.Format("{0:dd/MM/yyyy}", DateTime.Now));
            FormatLine(new Location(timeLocation.X, timeLocation.Y + 1), String.Format("SAAT {0:t}", DateTime.Now));


            bool print = CurrentSettings.GetProgramOption(Setting.NotPrintCustomerLabels) == PosConfiguration.OFF;


            if (document.Customer != null)
            {
                //Musteri kimlik biligileri
                String[] identityItems = document.Customer.Identity;
                //Musteri adres biligileri
                String[] contactItems = document.Customer.Contact;
                FormatLine(new Location(customerLocation.X, customerLocation.Y + 1), (print ? String.Format("{0,-12}: ", PosMessage.CUSTOMER_CODE) : "") + identityItems[0]);
                FormatLine(new Location(customerLocation.X, customerLocation.Y + 2), (print ? String.Format("{0,-15}: ", PosMessage.NAME) : "") + identityItems[1]);
                FormatLine(new Location(customerLocation.X, customerLocation.Y + 3), (print ? String.Format("{0,-15}: ", PosMessage.ADDRESS) : "") + contactItems[0]);
                FormatLine(new Location(customerLocation.X, customerLocation.Y + 4), (print ? String.Format("{0,-15}: ", PosMessage.ADDRESS) : "") + contactItems[1]);
                FormatLine(new Location(customerLocation.X, customerLocation.Y + 5), (print ? String.Format("{0,-15}: ", PosMessage.ADDRESS) : "") + contactItems[2]);

                FormatLine(new Location(taxLocation.X, taxLocation.Y + 1), (print ? String.Format("{0,-15}: ", PosMessage.TAX_NUMBER) : "") + contactItems[4]);
                FormatLine(new Location(taxLocation.X, taxLocation.Y + 2), (print ? String.Format("{0,-15}: ", PosMessage.TAX_INSTITUTION) : "") + contactItems[3]);
            }
            FormatLine(productNameLocation, "");//set cursor


            return(currentLines);
        }
Пример #4
0
        public List <String> FormatTotals(ISalesDocument document)
        {
            int currentLine = GetCurrentLine(6);

            FormatLine(new Location(productNameLocation.X, CurrentPage.PageLines.Count + 1), String.Empty);
            FormatLine(new Location(productNameLocation.X, CurrentPage.PageLines.Count + 1), PosMessage.TAX_BOLD);

            FormatLine(new Location(productAmountLocation.X - maxAmountWidth - 2, CurrentPage.PageLines.Count),
                       String.Format("²{0," + maxAmountWidth + "}³", "*" + new Number(document.TotalVAT).ToString("C")));

            FormatLine(new Location(productNameLocation.X, CurrentPage.PageLines.Count + 1), PosMessage.SHORT_TOTAL_BOLD);
            FormatLine(new Location(productAmountLocation.X - maxAmountWidth - 2, CurrentPage.PageLines.Count),
                       String.Format("²{0," + maxAmountWidth + "}³", "*" + new Number(document.TotalAmount).ToString("C")));

            FormatLine(new Location(productNameLocation.X, CurrentPage.PageLines.Count + 1), String.Empty);

            String[] inWords = WordConversion.ConvertLetter(document.TotalAmount).Split(new char[] { '\n' }); //Empty entries!! TODO CF

            for (int i = 0; i < inWords.Length; i++)
            {
                FormatLine(new Location(productNameLocation.X, CurrentPage.PageLines.Count + 1), inWords[i]);
            }

            FormatLine(new Location(productNameLocation.X, CurrentPage.PageLines.Count + 1), String.Empty);

            return(CurrentPage.PageLines.GetRange(currentLine, CurrentPage.PageLines.Count - currentLine));
        }
Пример #5
0
        public static List <String> FormatTotals(ISalesDocument document, bool hardcopy)
        {
            currentLines = new List <string>();

            FormatLine(new Location(productNameLocation.X, currentLines.Count + 1), String.Empty);
            FormatLine(new Location(productNameLocation.X, currentLines.Count + 1), PosMessage.TOTALTAX);

            FormatLine(new Location(productAmountLocation.X - maxAmountWidth, currentLines.Count), String.Format("{0," + maxAmountWidth + "}", "*" + new Number(document.TotalVAT).ToString("C")));

            FormatLine(new Location(productNameLocation.X, currentLines.Count + 1), PosMessage.TOTAL);
            FormatLine(new Location(productAmountLocation.X - maxAmountWidth, currentLines.Count), String.Format("{0," + maxAmountWidth + "}", "*" + new Number(document.TotalAmount).ToString("C")));

            FormatLine(new Location(productNameLocation.X, currentLines.Count + 1), String.Empty);

            String[] inWords = WordConversion.ConvertLetter(document.TotalAmount).Split(new char[] { '\n' }); //Empty entries!! TODO CF

            for (int i = 0; i < inWords.Length; i++)
            {
                FormatLine(new Location(productNameLocation.X, currentLines.Count + 1), inWords[i]);
            }

            FormatLine(new Location(productNameLocation.X, currentLines.Count + 1), String.Empty);

            return(currentLines);
        }
Пример #6
0
        public IPrinterResponse PrintTotals(ISalesDocument document, bool hardcopy)
        {
            PrinterResponse response = new PrinterResponse();
            int             type     = GetDocumentType();

            if (type > 100)
            {
                throw new NoDocumentFoundException();
            }
            if (type != document.DocumentTypeId)
            {
                throw new DocumentTypeException();
            }

            decimal total = CalculateTotal();

            if (document.TotalAmount != total)
            {
                throw new SubtotalNotMatchException(Math.Abs(total - document.TotalAmount));
            }
            response.Data = "" + total;

            salesDocument = document;
            guiDocument.AddLines(Formatter.FormatTotals(document, hardcopy));
            WriteCurrentLog("Total=" + document.TotalAmount);
            return(response);
        }
Пример #7
0
 public void ChangeDocumentStatus(ISalesDocument doc, DisplayDocumentStatus de)
 {
     primaryDisplay.ChangeDocumentStatus(doc, de);
     foreach (IDisplay d in auxilaryDisplays)
     {
         d.ChangeDocumentStatus(doc, de);
     }
 }
Пример #8
0
 public void Show(ISalesDocument sd)
 {
     primaryDisplay.Show(sd);
     foreach (IDisplay d in auxilaryDisplays)
     {
         d.Show(sd);
     }
 }
Пример #9
0
 public IPrinterResponse PrintFooter(ISalesDocument document)
 {
     salesDocument = document;
     guiDocument.AddLines(Formatter.FormatFooter(document));
     documentSold++;
     totalSold += document.TotalAmount;
     MoveCurrentDocument(0);
     return(toResponse);
 }
Пример #10
0
        public static String DocumentFormat(ISalesDocument doc)
        {
            String format = "{0}{4} {1}\t{2:dd/MM/yy}\n{3:C}\t{2:H:mm}";

            return(String.Format(format, doc.Name.Substring(0, 3),
                                 doc.Id,
                                 doc.CreatedDate,
                                 new Number(doc.TotalAmount),
                                 (doc.Id > 999) ? ":" : " NO:"));
        }
Пример #11
0
        public List <String> FormatSubTotal(ISalesDocument document)
        {
            int currentLine = GetCurrentLine(1);

            FormatLine(new Location(productNameLocation.X, CurrentPage.PageLines.Count + 1), PosMessage.SUBTOTAL);
            FormatLine(new Location(productAmountLocation.X - maxAmountWidth, CurrentPage.PageLines.Count),
                       String.Format("{0," + maxAmountWidth + "}", "*" + new Number(document.TotalAmount).ToString("C")));

            return(CurrentPage.PageLines.GetRange(currentLine, CurrentPage.PageLines.Count - currentLine));
        }
Пример #12
0
        public static List <String> FormatSubTotal(ISalesDocument document, bool hardcopy)
        {
            currentLines = new List <string>();

            if (hardcopy)
            {
                FormatLine(new Location(productNameLocation.X, currentLines.Count + 1), PosMessage.SUBTOTAL);
                FormatLine(new Location(productAmountLocation.X - maxAmountWidth, currentLines.Count), String.Format("{0," + maxAmountWidth + "}", "*" + new Number(document.TotalAmount).ToString("C")));
            }
            return(currentLines);
        }
Пример #13
0
 public void Show(ISalesDocument sd)
 {
     if ((mode & Target.Cashier) == Target.Cashier)
     {
         cashierDisplay.Show(sd);
     }
     if ((mode & Target.Customer) == Target.Customer)
     {
         customerDisplay.Show(sd);
     }
 }
Пример #14
0
        //when processing document is changed, what should be done on screen?
        private void ChangeDocument(ISalesDocument sDoc)
        {
            ClearDetails();

            foreach (IFiscalItem fi in sDoc.Items)
            {
                ShowItem(fi);
                if (fi.Quantity < 0)
                {
                    this.dgSales.Rows[0].DefaultCellStyle.ForeColor = Color.Red;
                }
            }

            if (sDoc.Items.Count > 0)
            {
                String path = PosConfiguration.ImagePath + sDoc.Items[sDoc.Items.Count - 1].Product.Barcode + ".jpg";
                if (!System.IO.File.Exists(path))
                {
                    path = PosConfiguration.ImagePath + "NoImage.jpg";
                }

                if (System.IO.File.Exists(path))
                {
                    SetItemImage(path);
                }
            }

            if (sDoc.Customer != null)
            {
                String customerInfo = "";
                if (sDoc.Customer.IsDiplomatic)
                {
                    customerInfo = FormatCustomerLine("Sn." + sDoc.Customer.Contact[0]) + " "
                                   + FormatCustomerLine(sDoc.Customer.Contact[1]) + " "
                                   + FormatCustomerLine(sDoc.Customer.Contact[2]);
                }
                else
                {
                    customerInfo = FormatCustomerLine("Sn." + sDoc.Customer.Identity[1]) + " "
                                   + FormatCustomerLine(sDoc.Customer.Contact[0]) + " "
                                   + FormatCustomerLine(sDoc.Customer.Contact[1]) + " "
                                   + FormatCustomerLine(sDoc.Customer.Contact[2]);
                }
                SetDocumentCustomer(customerInfo);
            }
            else
            {
                ChangeCustomer(null as ICustomer);
            }

            SetDocumentId(sDoc.Id);
            SetDocumentDate(sDoc.CreatedDate);
            SetDocumentTime(sDoc.CreatedDate);
        }
Пример #15
0
 public void Show(ISalesDocument doc)
 {
     try
     {
         Show("{0}\n{1}", (doc.IsEmpty) ? PosMessage.SELECT_DOCUMENT : PosMessage.TRANSFER_DOCUMENT, doc.Name);
     }
     catch (FormatException fex)
     {
         Display.Log.Error("FormatException occured. {0}", fex.Message);
     }
 }
Пример #16
0
        public void Show(ISalesDocument doc)
        {
            if ((mode & Target.Cashier) == Target.Cashier)
            {
                touchForm.Show(doc);
            }

            if (customerForm != null && (mode & Target.Customer) == Target.Customer)
            {
                customerForm.Show(doc);
            }
        }
Пример #17
0
        internal string OnDocumentVoided(ISalesDocument document, int voidedReason)
        {
            if (document.Id == 0 || document.IsEmpty)
            {
                return("");
            }

            StringWriter logWriter = logFormatter.LogItems(document, voidedReason, ref sequenceNumber);

            SaveLog(logWriter.ToString());

            return(logWriter.ToString());
        }
Пример #18
0
        internal void OnDocumentChanged(ISalesDocument document, int documentStatus)
        {
            if (document == null ||
                document.Id == 0 ||
                document.IsEmpty)
            {
                AppendDocumentLog("");
                return;
            }

            StringWriter logWriter = logFormatter.LogItems(document, documentStatus, ref sequenceNumber);

            AppendDocumentLog(logWriter.ToString());
        }
Пример #19
0
 public IPrinterResponse Suspend()
 {
     if (salesDocument == null && !File.Exists(currentLog))
     {
         throw new NoDocumentFoundException();
     }
     documentSuspended++;
     totalSuspended += PrinterSubTotal;
     guiDocument.AddLines(Formatter.FormatVoid(salesDocument));
     guiDocument.AddLines(Formatter.FormatEnd());
     MoveCurrentDocument(2);
     salesDocument = null;
     return(toResponse);
 }
Пример #20
0
        internal string OnDocumentClosed(ISalesDocument document)
        {
            if (document.Id == 0 || document.IsEmpty)
            {
                return("");
            }

            //every document knows his sequence number, switch is not required
            int          docStatus = this.logType == LogType.Main ? 0 : 1;// 0 : Sale, 1: Void
            StringWriter logWriter = logFormatter.LogItems(document, docStatus, ref sequenceNumber);

            SaveLog(logWriter.ToString());

            return(logWriter.ToString());
        }
Пример #21
0
        public static List <String> FormatVoid(ISalesDocument sDoc)
        {
            currentLines = new List <string>();

            FormatLine(new Location(productQuantityLocation.X, currentLines.Count + 1), "           ");
            if (sDoc.DocumentTypeId < 0)
            {
                FormatLine(new Location(productQuantityLocation.X, currentLines.Count + 1), "BELGE ÝPTAL");
            }
            else
            {
                FormatLine(new Location(productQuantityLocation.X, currentLines.Count + 1), "*BÝLGÝ FÝÞÝ ÝPTAL*");
            }
            FormatLine(new Location(productQuantityLocation.X, currentLines.Count + 1), "           ");

            return(currentLines);
        }
Пример #22
0
        private IPrinterResponse PrintSubTotal(ISalesDocument document, bool hardcopy)
        {
            IPrinterResponse response = null;

            FiscalPrinter.Document = document;

            List <String> subtotalItems = Invoicepage.FormatSubTotal(document);

            if (hardcopy)
            {
                foreach (String s in subtotalItems)
                {
                    response = Send(SlipRequest.WriteLine(s));
                }
            }
            return(response);
        }
Пример #23
0
        public static String DocumentFormat(ISalesDocument doc)
        {
            //String format = "{0}{4} {1}\t{2:dd/MM/yy}\n{3:C}\t{2:H:mm}";

            //return String.Format(format, doc.Name.Substring(0, 3),
            //                              doc.Id,
            //                              doc.CreatedDate,
            //                              new Number(doc.TotalAmount),
            //                              (doc.Id > 999) ? ":" : " NO:");

            String format = "{0}{4} {1}\t{2:dd/MM/yy}\n{5}{3:C}\t{2:H:mm}";

            return(String.Format(format, (doc.Name.Substring(0, 3) + " NO"),
                                 doc.Id,
                                 doc.CreatedDate,
                                 new Number(doc.TotalAmount),
                                 ":",
                                 "TOPLAM :"));
        }
Пример #24
0
        private IPrinterResponse PrintTotals(ISalesDocument document, bool hardcopy)
        {
            SlipPrinter.Document = document;
            if (totalLines == null)
            {
                totalLines = SlipPrinter.Invoicepage.FormatTotals(document);
                line_index_of_totals_to_print = 0;
            }
            IPrinterResponse response = null;

            int start = line_index_of_totals_to_print;

            for (int i = start; i < totalLines.Count; i++)
            {
                response = Send(SlipRequest.WriteLine(totalLines[i]));
                line_index_of_totals_to_print++;
            }

            return(response);
        }
Пример #25
0
        public void ChangeDocumentStatus(ISalesDocument doc, DisplayDocumentStatus de)
        {
            switch (de)
            {
            case DisplayDocumentStatus.OnStart:
                customerForm.SetDocumentInfos(doc);
                break;

            case DisplayDocumentStatus.OnChange:
                customerForm.ChangeCurrentDocument(doc);
                break;

            case DisplayDocumentStatus.OnUndoAdjustment:
                customerForm.UndoAdjustment(doc);
                break;

            case DisplayDocumentStatus.OnClose:
                customerForm.DocumentClose(doc);
                break;
            }
        }
Пример #26
0
        internal void OnDocumentSuspended(ISalesDocument document, int zReportNo)
        {
            if (document.Id == 0 || document.IsEmpty)
            {
                return;
            }

            int refNum = 0;

            StringWriter logWriter = logFormatter.LogItems(document, 4, ref refNum);

            StreamWriter sw = null;

            String suspendLogPath = String.Format("{0}BEK{1:D4}{2:D4}{3}", PosConfiguration.ArchivePath, zReportNo, document.Id, suffix);

            // Art arta beklenen belge iþlemlerinde doc id ayný geleceði için (header basýlý doc ýd sabit) böyle bir yola gittik.
            // Üst üste append yapmamasý için
            int docId = document.Id;

            while (File.Exists(suspendLogPath))
            {
                docId++;
                suspendLogPath = String.Format("{0}BEK{1:D4}{2:D4}{3}", PosConfiguration.ArchivePath, zReportNo, docId, suffix);
            }

            try
            {
                using (sw = new StreamWriter(suspendLogPath, true, PosConfiguration.DefaultEncoding))
                {
                    sw.WriteLine(logWriter.ToString());
                }
            }
            finally
            {
                if (sw != null)
                {
                    sw.Close();
                }
            }
        }
Пример #27
0
        public IPrinterResponse Void()
        {
            if (salesDocument == null && !File.Exists(currentLog))
            {
                throw new NoDocumentFoundException();
            }
            documentVoided++;
            totalVoided += PrinterSubTotal;
            if (File.Exists(currentLog) && salesDocument == null)
            {
                guiDocument.AddLines(Formatter.FormatInfo("ELEKTRÝK KESÝNTÝSÝ"));
                guiDocument.AddLines(Formatter.FormatInfo("BELGE IPTAL"));
            }
            else
            {
                guiDocument.AddLines(Formatter.FormatVoid(salesDocument));
            }
            guiDocument.AddLines(Formatter.FormatEnd());
            MoveCurrentDocument(1);
            salesDocument = null;

            return(toResponse);
        }
Пример #28
0
        public IPrinterResponse PrintHeader(ISalesDocument document)
        {
            StartCurrentLog(document.DocumentTypeId);

            document.Id   = currentDocumentId;
            salesDocument = document;

            guiDocument.AddLine("");
            if (document.DocumentTypeId < 0)
            {
                guiDocument.AddLines(Logo);
            }

            if (document.DocumentTypeId < 0)
            {
                guiDocument.AddLines(Formatter.FormatReceiptHeader(document.Name, document.Id));
            }
            else
            {
                guiDocument.AddLines(Formatter.FormatHeader(salesDocument));
            }

            return(toResponse);
        }
Пример #29
0
        void SalesDocument_ItemSold(object sender, SaleEventArgs e)
        {
            ISalesDocument doc = sender as ISalesDocument;

            display.ChangeDocumentStatus(doc, DisplayDocumentStatus.OnStart);
        }
Пример #30
0
        public override void Process(PosKey key)
        {
            if (isProcessing)
            {
                return;               //occurs if pressed key when seral data is executing.
            }
            lock (serialLock)
            {
                lastKeyPressed = DateTime.Now;
                isProcessing   = true;

                #region parse user input
                try
                {
                    switch (key)
                    {
                    case PosKey.D0:
                    case PosKey.D1:
                    case PosKey.D2:
                    case PosKey.D3:
                    case PosKey.D4:
                    case PosKey.D5:
                    case PosKey.D6:
                    case PosKey.D7:
                    case PosKey.D8:
                    case PosKey.D9:
                        cr.State.Numeric((char)key);
                        break;

                    case PosKey.DoubleZero:
                        cr.State.Numeric((char)PosKey.D0);
                        cr.State.Numeric((char)PosKey.D0);
                        break;

                    case PosKey.Decimal:
                        cr.State.Seperator();
                        break;

                    case PosKey.Document:
                        cr.State.Document();
                        break;

                    case PosKey.Customer:
                        cr.State.Customer();
                        break;

                    case PosKey.Report:
                        cr.State.Report();
                        break;

                    case PosKey.Program:
                        cr.State.Program();
                        break;

                    case PosKey.Command:
                        ISalesDocument doc = cr.Document;
                        cr.State.Command();
                        break;

                    case PosKey.CashDrawer:
                        cr.State.CashDrawer();
                        break;

                    case PosKey.Void:
                        cr.State.Void();
                        break;

                    case PosKey.PercentDiscount:
                        cr.State.Adjust(AdjustmentType.PercentDiscount);
                        break;

                    case PosKey.Discount:
                        cr.State.Adjust(AdjustmentType.Discount);
                        break;

                    case PosKey.PercentFee:
                        cr.State.Adjust(AdjustmentType.PercentFee);
                        break;

                    case PosKey.Fee:
                        cr.State.Adjust(AdjustmentType.Fee);
                        break;

                    case PosKey.ReceiveOnAcct:
                        cr.State.ReceiveOnAcct();
                        break;

                    case PosKey.PayOut:
                        cr.State.PayOut();
                        break;

                    case PosKey.PriceLookup:
                        cr.State.PriceLookup();
                        break;

                    case PosKey.Price:
                        cr.State.Price();
                        break;

                    case PosKey.Total:
                        cr.State.TotalAmount();
                        break;

                    case PosKey.Repeat:
                        cr.State.Repeat();
                        break;

                    case PosKey.UpArrow:
                        cr.State.UpArrow();
                        break;

                    case PosKey.DownArrow:
                        cr.State.DownArrow();
                        break;

                    case PosKey.Escape:
                        cr.State.Escape();
                        break;

                    case PosKey.Quantity:
                        cr.State.Quantity();
                        break;

                    case PosKey.Cash:
                        cr.State.Pay(new CashPaymentInfo());
                        break;

                    case PosKey.Credit:
                        if (KeyMap.CreditBuffer == -1)
                        {
                            Thread.Sleep(20);    //wait some for Console.KeyAvailable
                            if (Console.In.Peek() > -1)
                            {
                                KeyMap.CreditBuffer = Console.In.Read() - 48;
                            }
                            else
                            {
                                cr.State.Alpha('C');
                                return;
                            }
                        }
                        try
                        {
                            if (KeyMap.CreditBuffer == 0)
                            {
                                cr.State.Pay(new CreditPaymentInfo());
                            }
                            else
                            {
                                Dictionary <int, ICredit> credits = cr.DataConnector.GetCredits();
                                if (credits.Count > (KeyMap.CreditBuffer - 1))    //?-1
                                {
                                    cr.State.Pay(new CreditPaymentInfo(credits[KeyMap.CreditBuffer]));
                                }
                            }
                        }
                        finally { KeyMap.CreditBuffer = -1; }
                        break;

                    case PosKey.Payment:
                        cr.State.ShowPaymentList();
                        break;

                    case PosKey.Check:
                        cr.State.Pay(new CheckPaymentInfo());
                        break;

                    case PosKey.ForeignCurrency:
                        cr.State.Pay(new CurrencyPaymentInfo());
                        break;

                    case PosKey.SubTotal:
                        cr.State.SubTotal();
                        break;

                    case PosKey.Enter:
                        cr.State.Enter();
                        break;

                    case PosKey.SalesPerson:
                        cr.State.SalesPerson();
                        break;

                    case PosKey.Correction:
                        cr.State.Correction();
                        break;

                    case PosKey.LabelStx:
                        if (KeyMap.LabelBuffer == -1)
                        {
                            Thread.Sleep(20);    //wait some for Console.KeyAvailable
                            //Console.In.ReadLine() is changed as Console.In.Read()
                            //because Readline command opens the text editor in WindowsCE
                            int label = Console.In.Read();
                            if (label == -1)
                            {
                                cr.State.Alpha('L');
                                break;
                            }
                            KeyMap.LabelBuffer = label;
                        }
                        try
                        {
                            cr.State.LabelKey(KeyMap.LabelBuffer);
                        }
                        finally { KeyMap.LabelBuffer = -1; }
                        break;

                    case PosKey.Help:
                        MessageBox.Show(cr.State.GetType().ToString());
                        break;

                    case PosKey.MagstripeStx:
                        cr.State.CardPrefix();
                        break;

                    case PosKey.KeyStx:
                        if (KeyMap.KeyLockBuffer == -1)
                        {
                            Thread.Sleep(20);    //wait some for Console.KeyAvailable
                            String label = Console.ReadLine();
                            KeyMap.KeyLockBuffer = int.Parse(label);
                        }
                        try
                        {
                            cr.State.End(KeyMap.KeyLockBuffer - 1);
                        }
                        finally
                        {
                            KeyMap.KeyLockBuffer = -1;
                        }
                        break;

                    case PosKey.BarcodePrefix:
                        cr.State.BarcodePrefix();
                        break;

                    case PosKey.UndefinedKey:
                        //do nothing
                        break;

                    case PosKey.SendOrder:
                        cr.State.SendOrder();
                        break;

                    default:
                        switch (key)
                        {
                        case (PosKey)17: cr.State.Alpha('|'); break;

                        case PosKey.MagstripeStx: cr.State.Alpha('\"'); break;

                        case (PosKey)214: cr.State.Alpha('ж'); break;

                        case (PosKey)286: cr.State.Alpha('а'); break;

                        case (PosKey)199: cr.State.Alpha('Ч'); break;

                        case (PosKey)220: cr.State.Alpha('м'); break;

                        case (PosKey)304: cr.State.Alpha('н'); break;

                        case (PosKey)350: cr.State.Alpha('о'); break;

                        case (PosKey)221: break;

                        case (PosKey)46: cr.State.Alpha('.'); break;

                        case (PosKey)47: cr.State.Alpha('/'); break;

                        default:
                            if (char.IsLetter((char)key) || key == (PosKey)ConsoleKey.Spacebar || char.IsPunctuation((char)key))
                            {
                                cr.State.Alpha((char)key);
                            }
                            else
                            {
                                cr.State.UndefinedKey();
                            }
                            break;
                        }
                        break;
                    }
                }
                #endregion

                #region handle errors

                catch (CmdSequenceException csex)
                {
                    SoundManager.Sound(SoundType.FAILED);
                    cr.State = States.AlertCashier.Instance(new Error(csex));
                    cr.Log.Error("CmdSequenceException occured. Last command: {0}", csex.LastCommand);
                    cr.Log.Error(csex);
                    //to do : cr.State = ex.Recover();
                }
                catch (PowerFailureException pfex)
                {
                    SoundManager.Sound(SoundType.FATAL_ERROR);
                    try
                    {
                        Recover.RecoverPowerFailure(pfex);
                    }
                    catch (EJException eje)
                    {
                        cr.State = States.ElectronicJournalError.Instance(eje);
                    }
                    cr.Log.Warning(pfex);
                }
                catch (UnfixedSlipException ex)
                {
                    try
                    {
                        cr.State = States.BlockOnPaper.Instance();
                        //Recover.RecoverUnfixedSlip(ex);
                    }
                    catch (EJException)
                    {
                        cr.State = States.ElectronicJournalError.Instance();
                    }
                    cr.Log.Warning(ex);
                }
                catch (EJException eje)
                {
                    SoundManager.Sound(SoundType.FATAL_ERROR);
                    cr.State = States.ElectronicJournalError.Instance(eje);
                    cr.Log.Warning(eje);
                }
                catch (SVCPasswordOrPointException ex)
                {
                    SoundManager.Sound(SoundType.FAILED);
                    //cr.State = States.ServiceMenu.Instance();
                    States.AlertCashier.Instance(new Confirm(ex.Message));
                    cr.Log.Warning(ex);
                }
                catch (FiscalIdException fie)
                {
                    SoundManager.Sound(SoundType.FATAL_ERROR);
                    cr.State = States.FiscalIdBlock.Instance();
                    cr.Log.Warning(fie);
                }
                catch (BlockingException bex)
                {
                    SoundManager.Sound(SoundType.FATAL_ERROR);
                    cr.State = States.PrinterBlockingError.Instance(new Error(bex));
                }
                catch (NoReceiptRollException nrre)
                {
                    SoundManager.Sound(SoundType.NEED_PROCESS);
                    cr.State = States.PrinterStatusError.Instance(new Error(nrre));
                    cr.Log.Error(nrre);
                }
                catch (PrinterStatusException pse)
                {
                    SoundManager.Sound(SoundType.FAILED);
                    cr.State = States.PrinterStatusError.Instance(pse);
                    cr.Log.Error(pse);
                }
                catch (MissingCashierException mcex)
                {
                    SoundManager.Sound(SoundType.FAILED);
                    cr.CurrentCashier = null;
                    cr.State          = States.AlertCashier.Instance(new Error(mcex, States.Login.Instance));
                    cr.Log.Warning(mcex);
                }
                catch (AssignedCashierLimitExeedException aclee)
                {
                    SoundManager.Sound(SoundType.FAILED);
                    cr.CurrentCashier = null;
                    cr.State          = States.AlertCashier.Instance(new Error(aclee, States.Login.Instance));
                    cr.Log.Warning(aclee);
                }
                catch (SlipRowCountExceedException srceex)
                {
                    SoundManager.Sound(SoundType.FAILED);
                    States.AlertCashier.Instance(new Error(srceex));
                    cr.State = States.ConfirmSlip.Instance(new Error(srceex));
                    cr.Log.Warning(srceex);
                }
                catch (CashierAlreadyAssignedException caaex)
                {
                    States.AlertCashier.Instance(new Error(caaex));
                    ICashier assignedCashier = cr.DataConnector.FindCashierById(caaex.CashierId);
                    if (assignedCashier != null)
                    {
                        cr.Log.Debug("Kasiyer zaten atanmis: {1} ({0})", assignedCashier.Id, assignedCashier.Name);
                    }
                    else
                    {
                        cr.Log.Error("Kasiyer girisi yapilmali");
                    }
                    States.Login.LoginCashier();
                }
                catch (ProductNotWeighableException pnwex)
                {
                    SoundManager.Sound(SoundType.FAILED);
                    cr.State = States.AlertCashier.Instance(new Error(pnwex));
                }
                catch (DirectoryNotFoundException dnfex)
                {
                    SoundManager.Sound(SoundType.FAILED);
                    cr.Log.Fatal(dnfex);
                    cr.State = States.AlertCashier.Instance(new Error(dnfex));
                }
                catch (InvalidOperationException ioex)
                {
                    SoundManager.Sound(SoundType.FAILED);
                    cr.State = States.AlertCashier.Instance(new Error(ioex));
                }
                catch (NegativeResultException nrex)
                {
                    SoundManager.Sound(SoundType.FAILED);
                    cr.State = States.AlertCashier.Instance(new Error(nrex));
                    cr.Log.Error(nrex);
                }
                catch (IncompleteXReportException ixrex)
                {
                    SoundManager.Sound(SoundType.FATAL_ERROR);
                    cr.State = States.XReportPE.Instance(ixrex);
                    cr.Log.Warning("Printer exception occured during the x report", ixrex.Message);
                }
                catch (IncompleteEJSummaryReportException iejsex)
                {
                    SoundManager.Sound(SoundType.FATAL_ERROR);
                    cr.State = States.EJSummaryReportPE.Instance(iejsex);
                    cr.Log.Warning("Printer exception occured during the ej summary report", iejsex.Message);
                }
                catch (IncompletePaymentException ipe)
                {
                    SoundManager.Sound(SoundType.NEED_PROCESS);
                    cr.State = States.PaymentAfterPE.Instance(ipe);
                    cr.Log.Warning(ipe.Message);
                }
                catch (PrintDocumentException pde)
                {
                    SoundManager.Sound(SoundType.FAILED);
                    cr.State = States.DocumentPE.Instance(pde);
                    cr.Log.Warning("Printer exception occured during the document printing ", pde.Message);
                }
                catch (FMFullException fmfe)
                {
                    SoundManager.Sound(SoundType.FATAL_ERROR);
                    cr.State = States.PrinterStatusError.Instance(new Error(fmfe));
                    cr.Log.Fatal(fmfe);
                }
                catch (FMLimitWarningException fmlwe)
                {
                    SoundManager.Sound(SoundType.FATAL_ERROR);
                    cr.State = States.PrinterStatusError.Instance(new Error(fmlwe));
                    cr.Log.Fatal(fmlwe);
                }
                catch (ZRequiredException zre)
                {
                    SoundManager.Sound(SoundType.NEED_PROCESS);
                    cr.State = States.PrinterStatusError.Instance(new Error(zre));
                    cr.Log.Error(zre);
                }
                catch (CashierAutorizeException cae)
                {
                    SoundManager.Sound(SoundType.FAILED);
                    cr.State = States.AlertCashier.Instance(new Error(cae));
                    cr.Log.Error(cae);
                }
                catch (FMNewException fmne)
                {
                    SoundManager.Sound(SoundType.NEED_PROCESS);
                    int fiscalId = int.Parse(PosConfiguration.Get("FiscalId").Substring(2, 8));
                    cr.State = States.EnterInteger.Instance(PosMessage.START_FM, fiscalId,
                                                            new StateInstance <int>(States.Login.AcceptFiscalId),
                                                            new StateInstance(Start.Instance));
                    cr.Log.Error(fmne);
                }
                catch (PrinterTimeoutException pte)
                {
                    SoundManager.Sound(SoundType.FAILED);
                    cr.State = States.PrinterConnectionError.Instance(pte);
                    cr.Log.Warning(pte);
                }
                catch (System.Net.Sockets.SocketException ex)
                {
                    SoundManager.Sound(SoundType.FAILED);
                    cr.State = States.PrinterConnectionError.Instance(new PrinterException(PosMessage.CANNOT_ACCESS_PRINTER, ex));
                    cr.Log.Warning(new PrinterException(PosMessage.CANNOT_ACCESS_PRINTER, ex));
                }
                catch (InvalidPaymentException ipe)
                {
                    SoundManager.Sound(SoundType.FAILED);
                    Confirm con = new Confirm(String.Format("{0}\n{1}", PosMessage.PAYMENT_INVALID, "жDEME нPTAL?(GнRно)"),
                                              new StateInstance(VoidPayment.Instance));
                    cr.State = States.ConfirmCashier.Instance(con);
                    cr.Log.Error(ipe);
                }
                catch (OperationCanceledException oce)
                {
                    SoundManager.Sound(SoundType.FAILED);
                    cr.State = States.PrinterConnectionError.Instance(new PrinterException(PosMessage.CANNOT_ACCESS_PRINTER, oce));
                    cr.Log.Warning(new PrinterException(PosMessage.CANNOT_ACCESS_PRINTER, oce));
                }
                catch (EftPosException epe)
                {
                    SoundManager.Sound(SoundType.FAILED);
                    cr.State = AlertCashier.Instance(new Error(epe));
                    cr.Log.Error(epe);
                }
                catch (Exception ex)
                {
                    SoundManager.Sound(SoundType.FAILED);
                    cr.State = States.AlertCashier.Instance(new Error(ex));
                    cr.Log.Error(ex);
                }
                finally
                {
                    isProcessing = false;
                }
                #endregion
            }
        }