Esempio n. 1
0
 internal PrinterFacade(
     IFiscalPrinter printer,
     PrinterConfiguration configuration,
     PrinterType type) : this(configuration, type)
 {
     _fiscalPrinter = printer;
 }
Esempio n. 2
0
        static void ShowFiscalPrinterInfo(IFiscalPrinter printer)
        {
            var info = printer.DeviceInfo;

            Console.WriteLine(
                $"{info.Company} {info.Model}, S/N: { info.SerialNumber}, FM S/N: { info.FiscalMemorySerialNumber}");
        }
Esempio n. 3
0
        public PrinterFacade(PrinterConfiguration configuration, PrinterType type)
        {
            var creator = Creator.Instance;

            _fiscalPrinter = creator.GetPrinter(type, configuration);
            _observers     = new HashSet <IObserver <PrinterInfo> >();
        }
Esempio n. 4
0
        public void AddPrinter(IFiscalPrinter printer)
        {
            // We use serial number of local connected fiscal printers as Printer ID
            var baseID = printer.DeviceInfo.SerialNumber.ToLowerInvariant();

            var printerID       = baseID;
            int duplicateNumber = 0;

            while (PrintersInfo.ContainsKey(printerID))
            {
                duplicateNumber++;
                printerID = $"{baseID}_{duplicateNumber}";
            }
            PrintersInfo.Add(printerID, printer.DeviceInfo);
            Printers.Add(printerID, printer);
            logger.LogInformation($"Found {printerID}: {printer.DeviceInfo.Uri}");
        }
        private void LoadFiscalPrinterHandlingPlugins()
        {
            var plugins = Directory.GetFiles(Constants.PluginsAssemblyDirectoryPath, "*FiscalPrinterSimulatorLibraries.dll", SearchOption.TopDirectoryOnly)
                          .Select(m => Path.GetFullPath(m))
                          .Where(m => !m.Contains("Base"))
                          .Select(m => Assembly.LoadFrom(m))
                          .Where(m => m != null)
                          .SelectMany(m => m.GetTypes())
                          .ToList()
                          .Where(m => !m.IsInterface && !m.IsAbstract && m.GetInterface(typeof(IFiscalPrinter).FullName) != null)
                          .Select(m => (IFiscalPrinter)Activator.CreateInstance(m))
                          .ToList();

            if (plugins.Count() == 1)
            {
                _printer = plugins.First();
            }
        }
Esempio n. 6
0
        private void btnGetSerial_Click(object sender, EventArgs e)
        {
            IFiscalPrinter fp = PrinterFactory.Create(Model);

            try
            {
                txtSerial.Text = fp.GetSerial(ComPort, Baud);
                if (txtSerial.Text.Length < 3 && !string.IsNullOrEmpty(txtSerial.Text))
                {
                    fp.getError(Convert.ToInt32(txtSerial.Text));
                }
                else
                {
                    savePrinterSettings();
                }
            }
            catch (Exception x) { MessageBox.Show(x.Message); }
            finally { fp.Dispose(); }
        }
Esempio n. 7
0
        //kjo eshte vetem per kasat e vjetra kur ngel tastiera e bllokuar
        private void button4_Click(object sender, EventArgs e)
        {
            if (Model.Contains("W"))
            {
                return;
            }

            IFiscalPrinter fp     = PrinterFactory.Create(Model);
            int            answer = fp.OpenPort(Model, Key, ComPort, Baud);

            if (answer == 1)
            {
                fp.WriteLine("T,1,______,_,__;");

                if (activeKeyb)
                {
                    fp.WriteLine("F,1,______,_,__;");
                }
            }

            fp.Dispose();
        }
Esempio n. 8
0
        private void btnCheckKey_Click(object sender, EventArgs e)
        {
            savePrinterSettings();
            loadPrinterSettings();

            IFiscalPrinter fp = PrinterFactory.Create(Model);

            try
            {
                int answer = fp.OpenPort(Model, Key, ComPort, Baud);
                if (answer == 1)
                {
                    MessageBox.Show("Key Registered Sucessfully");
                    savePrinterSettings();
                }
                else
                {
                    //MessageBox.Show(getError(answer), "Kujdes!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    MessageBox.Show(fp.getError(answer), "Cant Connect");
                }
            }
            catch { }
            finally { fp.Dispose(); }
        }
Esempio n. 9
0
        private void testInv()
        {
            int length = 2; //nr rreshtave test qe duam te printojme si test

            loadPrinterSettings();

            //nese nuk po punojme me active keyboard, checkstatus nuk ka kuptim
            if (!activeKeyb)
            {
                checkStatus = false;
            }

            IFiscalPrinter fp = PrinterFactory.Create(Model, checkStatus, activeKeyb);

            try
            {
                if (string.IsNullOrEmpty(txtKey.Text))
                {
                    MessageBox.Show("Ju lutemi te vendosni numrin e licences!", "Kujdes!");
                    return;
                }
                int answer = fp.OpenPort(Model, Key, ComPort, Baud); //nese ku ka lidhje me kasen kjo then NULL dhe nuk kemi fare objekt fiskal
                if (answer == 1)
                {
                    try
                    {
                        string[] inv = { };
                        //read
                        if (!File.Exists("sample.txt"))
                        {
                            MessageBox.Show("Mungon file me komandat");
                            return;
                        }
                        inv = File.ReadAllLines("sample.txt");
                        // check the length of the file
                        if (inv.Length == 0)
                        {
                            MessageBox.Show("Mungon sample.txt file qe ka komenadat e kases");
                            return;
                        }
                        //print
                        string line, nextline = "";
                        for (int i = 0; i < inv.Length; i++)
                        {
                            line = inv[i];
                            //check if next line is discount
                            if (i < inv.Length - 1) //nese ka akoma rreshta
                            {
                                nextline = inv[i + 1];
                            }

                            //nese kemi hapur nje fature jotatimore me komanden J atehere duhet mbyllyr me cript dhe jo tek per tek
                            //pra e mira eshte nese kemi file me info jotatimore i gjithe file te excecutohet si nje script dhe jo tek per tek
                            if (inv[0].StartsWith(("J,1,______,_,__;")))
                            {
                                fp.ExecuteScript(inv);
                                return;
                            }

                            //nese rreshti dyte eshte me C qe nenkupton zbritje dergo te dy rreshtat bashke qe te aplikohet zbritja
                            if (nextline.StartsWith("C,1,______,_,__;", StringComparison.Ordinal))
                            {
                                fp.ExecuteScript(new string[] { line, nextline });
                                i++;                                 //i should be increased as two lines have been printed by the script
                            }

                            else if (fp.WriteLine(inv[i]) == 0)
                            {
                                Console.WriteLine("err: " + inv[i]);
                                MessageBox.Show($"Gabim kominikim me kasen!\rRreshti: {inv[i]}"
                                                , "Konfirmo!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);

                                return;
                            } //end check if next line is discount
                        }     //end loop
                    }         //end try
                    catch (Exception err)
                    {
                        Console.WriteLine(err.Message);
                    }
                    finally
                    {
                        //fp.stopReading = true;
                        Console.WriteLine("Port disconnected!");
                    }
                }
                else
                {
                    //MessageBox.Show(getError(answer), "Kujdes!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    MessageBox.Show(fp.getError(answer), "Cant Connect");
                    return;
                }
            }
            catch (Exception ex) { MessageBox.Show("Nuk ka lidhje me kasen. Ose kasa fikur ose COM port jo i rregullt. Err: " + ex.ToString()); } //ne kete rast FP nuk eshte inicaizluar fare si objekt se nuk ka patur lidhje me kasen dhe kthen null error
            finally { fp.Dispose(); }
        }
Esempio n. 10
0
        static void TestAllMethods(IFiscalPrinter fp)
        {
            // Print a receipt.
            var doc = new Receipt()
            {
                UniqueSaleNumber = "DT279013-DD01-0000001",
                Items            = new Item[]
                {
                    new Item()
                    {
                        Text      = "Сирене",
                        Quantity  = 1,
                        UnitPrice = 12,
                        TaxGroup  = TaxGroup.TaxGroup2
                    },
                    new Item()
                    {
                        Text      = "Допълнителен коментар към сиренето...",
                        IsComment = true
                    },

                    new Item()
                    {
                        Text               = "Кашкавал",
                        Quantity           = 2,
                        UnitPrice          = 10,
                        TaxGroup           = TaxGroup.TaxGroup2,
                        PriceModifierValue = 10,
                        PriceModifierType  = PriceModifierType.DiscountPercent
                    }
                },
                Payments = new Payment[]
                {
                    new Payment()
                    {
                        Amount      = 30,
                        PaymentType = PaymentType.Cash
                    }
                }
            };

            //fp.PrintMoneyDeposit(123.4m);
            //fp.PrintMoneyWithdraw(43.21m);
            var(result, commandStatus) = fp.PrintReceipt(doc);
            ShowStatus(commandStatus);

            Console.WriteLine($"Receipt Number: {result.ReceiptNumber}, DateTime: {result.ReceiptDateTime}, Amount: {result.ReceiptAmount}");

            /*
             * var
             *
             * Doc = new ReversalReceipt
             * {
             *  Reason = ReversalReason.OperatorError,
             *  ReceiptNumber = result.ReceiptNumber,
             *  ReceiptDateTime = result.ReceiptDateTime,
             *  FiscalMemorySerialNumber = result.FiscalMemorySerialNumber
             * }.CloneReceipt(doc);
             * commandStatus = fp.PrintReversalReceipt(reverseDoc);
             * ShowStatus(commandStatus);
             */

            //fp.PrintZReport();
        }